croutine.h
Go to the documentation of this file.
1 /*
2  FreeRTOS V9.0.0rc2 - Copyright (C) 2016 Real Time Engineers Ltd.
3  All rights reserved
4 
5  VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
6 
7  This file is part of the FreeRTOS distribution.
8 
9  FreeRTOS is free software; you can redistribute it and/or modify it under
10  the terms of the GNU General Public License (version 2) as published by the
11  Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
12 
13  ***************************************************************************
14  >>! NOTE: The modification to the GPL is included to allow you to !<<
15  >>! distribute a combined work that includes FreeRTOS without being !<<
16  >>! obliged to provide the source code for proprietary components !<<
17  >>! outside of the FreeRTOS kernel. !<<
18  ***************************************************************************
19 
20  FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
21  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22  FOR A PARTICULAR PURPOSE. Full license text is available on the following
23  link: http://www.freertos.org/a00114.html
24 
25  ***************************************************************************
26  * *
27  * FreeRTOS provides completely free yet professionally developed, *
28  * robust, strictly quality controlled, supported, and cross *
29  * platform software that is more than just the market leader, it *
30  * is the industry's de facto standard. *
31  * *
32  * Help yourself get started quickly while simultaneously helping *
33  * to support the FreeRTOS project by purchasing a FreeRTOS *
34  * tutorial book, reference manual, or both: *
35  * http://www.FreeRTOS.org/Documentation *
36  * *
37  ***************************************************************************
38 
39  http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
40  the FAQ page "My application does not run, what could be wrong?". Have you
41  defined configASSERT()?
42 
43  http://www.FreeRTOS.org/support - In return for receiving this top quality
44  embedded software for free we request you assist our global community by
45  participating in the support forum.
46 
47  http://www.FreeRTOS.org/training - Investing in training allows your team to
48  be as productive as possible as early as possible. Now you can receive
49  FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
50  Ltd, and the world's leading authority on the world's leading RTOS.
51 
52  http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
53  including FreeRTOS+Trace - an indispensable productivity tool, a DOS
54  compatible FAT file system, and our tiny thread aware UDP/IP stack.
55 
56  http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
57  Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
58 
59  http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
60  Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
61  licenses offer ticketed support, indemnification and commercial middleware.
62 
63  http://www.SafeRTOS.com - High Integrity Systems also provide a safety
64  engineered and independently SIL3 certified version for use in safety and
65  mission critical applications that require provable dependability.
66 
67  1 tab == 4 spaces!
68 */
69 
70 #ifndef CO_ROUTINE_H
71 #define CO_ROUTINE_H
72 
73 #ifndef INC_FREERTOS_H
74  #error "include FreeRTOS.h must appear in source files before include croutine.h"
75 #endif
76 
77 #include "list.h"
78 
79 #ifdef __cplusplus
80 extern "C" {
81 #endif
82 
83 /* Used to hide the implementation of the co-routine control block. The
84 control block structure however has to be included in the header due to
85 the macro implementation of the co-routine functionality. */
86 typedef void * CoRoutineHandle_t;
87 
88 /* Defines the prototype to which co-routine functions must conform. */
89 typedef void (*crCOROUTINE_CODE)( CoRoutineHandle_t, UBaseType_t );
90 
92 {
94  ListItem_t xGenericListItem; /*< List item used to place the CRCB in ready and blocked queues. */
95  ListItem_t xEventListItem; /*< List item used to place the CRCB in event lists. */
96  UBaseType_t uxPriority; /*< The priority of the co-routine in relation to other co-routines. */
97  UBaseType_t uxIndex; /*< Used to distinguish between co-routines when multiple co-routines use the same co-routine function. */
98  uint16_t uxState; /*< Used internally by the co-routine implementation. */
99 } CRCB_t; /* Co-routine control block. Note must be identical in size down to uxPriority with TCB_t. */
100 
173 BaseType_t xCoRoutineCreate( crCOROUTINE_CODE pxCoRoutineCode, UBaseType_t uxPriority, UBaseType_t uxIndex );
174 
175 
215 void vCoRoutineSchedule( void );
216 
246 #define crSTART( pxCRCB ) switch( ( ( CRCB_t * )( pxCRCB ) )->uxState ) { case 0:
247 
277 #define crEND() }
278 
279 /*
280  * These macros are intended for internal use by the co-routine implementation
281  * only. The macros should not be used directly by application writers.
282  */
283 #define crSET_STATE0( xHandle ) ( ( CRCB_t * )( xHandle ) )->uxState = (__LINE__ * 2); return; case (__LINE__ * 2):
284 #define crSET_STATE1( xHandle ) ( ( CRCB_t * )( xHandle ) )->uxState = ((__LINE__ * 2)+1); return; case ((__LINE__ * 2)+1):
285 
332 #define crDELAY( xHandle, xTicksToDelay ) \
333  if( ( xTicksToDelay ) > 0 ) \
334  { \
335  vCoRoutineAddToDelayedList( ( xTicksToDelay ), NULL ); \
336  } \
337  crSET_STATE0( ( xHandle ) );
338 
422 #define crQUEUE_SEND( xHandle, pxQueue, pvItemToQueue, xTicksToWait, pxResult ) \
423 { \
424  *( pxResult ) = xQueueCRSend( ( pxQueue) , ( pvItemToQueue) , ( xTicksToWait ) ); \
425  if( *( pxResult ) == errQUEUE_BLOCKED ) \
426  { \
427  crSET_STATE0( ( xHandle ) ); \
428  *pxResult = xQueueCRSend( ( pxQueue ), ( pvItemToQueue ), 0 ); \
429  } \
430  if( *pxResult == errQUEUE_YIELD ) \
431  { \
432  crSET_STATE1( ( xHandle ) ); \
433  *pxResult = pdPASS; \
434  } \
435 }
436 
514 #define crQUEUE_RECEIVE( xHandle, pxQueue, pvBuffer, xTicksToWait, pxResult ) \
515 { \
516  *( pxResult ) = xQueueCRReceive( ( pxQueue) , ( pvBuffer ), ( xTicksToWait ) ); \
517  if( *( pxResult ) == errQUEUE_BLOCKED ) \
518  { \
519  crSET_STATE0( ( xHandle ) ); \
520  *( pxResult ) = xQueueCRReceive( ( pxQueue) , ( pvBuffer ), 0 ); \
521  } \
522  if( *( pxResult ) == errQUEUE_YIELD ) \
523  { \
524  crSET_STATE1( ( xHandle ) ); \
525  *( pxResult ) = pdPASS; \
526  } \
527 }
528 
623 #define crQUEUE_SEND_FROM_ISR( pxQueue, pvItemToQueue, xCoRoutinePreviouslyWoken ) xQueueCRSendFromISR( ( pxQueue ), ( pvItemToQueue ), ( xCoRoutinePreviouslyWoken ) )
624 
625 
736 #define crQUEUE_RECEIVE_FROM_ISR( pxQueue, pvBuffer, pxCoRoutineWoken ) xQueueCRReceiveFromISR( ( pxQueue ), ( pvBuffer ), ( pxCoRoutineWoken ) )
737 
738 /*
739  * This function is intended for internal use by the co-routine macros only.
740  * The macro nature of the co-routine implementation requires that the
741  * prototype appears here. The function should not be used by application
742  * writers.
743  *
744  * Removes the current co-routine from its ready list and places it in the
745  * appropriate delayed list.
746  */
747 void vCoRoutineAddToDelayedList( TickType_t xTicksToDelay, List_t *pxEventList );
748 
749 /*
750  * This function is intended for internal use by the queue implementation only.
751  * The function should not be used by application writers.
752  *
753  * Removes the highest priority co-routine from the event list and places it in
754  * the pending ready list.
755  */
756 BaseType_t xCoRoutineRemoveFromEventList( const List_t *pxEventList );
757 
758 #ifdef __cplusplus
759 }
760 #endif
761 
762 #endif /* CO_ROUTINE_H */
Definition: list.h:181
Definition: croutine.h:91
Definition: list.h:205
ListItem_t xEventListItem
Definition: croutine.h:95
BaseType_t xCoRoutineCreate(crCOROUTINE_CODE pxCoRoutineCode, UBaseType_t uxPriority, UBaseType_t uxIndex)
uint16_t uxState
Definition: croutine.h:98
void vCoRoutineSchedule(void)
void vCoRoutineAddToDelayedList(TickType_t xTicksToDelay, List_t *pxEventList)
void * CoRoutineHandle_t
Definition: croutine.h:86
UBaseType_t uxIndex
Definition: croutine.h:97
BaseType_t xCoRoutineRemoveFromEventList(const List_t *pxEventList)
crCOROUTINE_CODE pxCoRoutineFunction
Definition: croutine.h:93
ListItem_t xGenericListItem
Definition: croutine.h:94
void(* crCOROUTINE_CODE)(CoRoutineHandle_t, UBaseType_t)
Definition: croutine.h:89
struct corCoRoutineControlBlock CRCB_t
UBaseType_t uxPriority
Definition: croutine.h:96