34#if ( configUSE_CO_ROUTINES != 0 )
40 #ifdef portREMOVE_STATIC_QUALIFIER
47 static List_t xDelayedCoRoutineList1;
48 static List_t xDelayedCoRoutineList2;
50 static List_t * pxOverflowDelayedCoRoutineList =
NULL;
51 static List_t xPendingReadyCoRoutineList;
56 static TickType_t xCoRoutineTickCount = 0, xLastTickCount = 0, xPassedTicks = 0;
59 #define corINITIAL_STATE ( 0 )
68 #define prvAddCoRoutineToReadyQueue( pxCRCB ) \
70 if( ( pxCRCB )->uxPriority > uxTopCoRoutineReadyPriority ) \
72 uxTopCoRoutineReadyPriority = ( pxCRCB )->uxPriority; \
74 vListInsertEnd( ( List_t * ) &( pxReadyCoRoutineLists[ ( pxCRCB )->uxPriority ] ), &( ( pxCRCB )->xGenericListItem ) ); \
81 static void prvInitialiseCoRoutineLists(
void );
89 static void prvCheckPendingReadyList(
void );
99 static void prvCheckDelayedList(
void );
117 if( pxCurrentCoRoutine ==
NULL )
119 pxCurrentCoRoutine = pxCoRoutine;
120 prvInitialiseCoRoutineLists();
130 pxCoRoutine->
uxState = corINITIAL_STATE;
132 pxCoRoutine->
uxIndex = uxIndex;
150 prvAddCoRoutineToReadyQueue( pxCoRoutine );
170 xTimeToWake = xCoRoutineTickCount + xTicksToDelay;
180 if( xTimeToWake < xCoRoutineTickCount )
202 static void prvCheckPendingReadyList(
void )
220 prvAddCoRoutineToReadyQueue( pxUnblockedCRCB );
225 static void prvCheckDelayedList(
void )
231 while( xPassedTicks )
233 xCoRoutineTickCount++;
237 if( xCoRoutineTickCount == 0 )
243 pxTemp = pxDelayedCoRoutineList;
244 pxDelayedCoRoutineList = pxOverflowDelayedCoRoutineList;
245 pxOverflowDelayedCoRoutineList = pxTemp;
276 prvAddCoRoutineToReadyQueue( pxCRCB );
280 xLastTickCount = xCoRoutineTickCount;
289 if( pxDelayedCoRoutineList !=
NULL )
292 prvCheckPendingReadyList();
295 prvCheckDelayedList();
298 while(
listLIST_IS_EMPTY( &( pxReadyCoRoutineLists[ uxTopCoRoutineReadyPriority ] ) ) )
300 if( uxTopCoRoutineReadyPriority == 0 )
306 --uxTopCoRoutineReadyPriority;
319 static void prvInitialiseCoRoutineLists(
void )
334 pxDelayedCoRoutineList = &xDelayedCoRoutineList1;
335 pxOverflowDelayedCoRoutineList = &xDelayedCoRoutineList2;
#define configMAX_CO_ROUTINE_PRIORITIES
struct corCoRoutineControlBlock CRCB_t
void(* crCOROUTINE_CODE)(CoRoutineHandle_t, UBaseType_t)
void vCoRoutineSchedule(void)
void vCoRoutineAddToDelayedList(TickType_t xTicksToDelay, List_t *pxEventList)
BaseType_t xCoRoutineCreate(crCOROUTINE_CODE pxCoRoutineCode, UBaseType_t uxPriority, UBaseType_t uxIndex)
BaseType_t xCoRoutineRemoveFromEventList(const List_t *pxEventList)
struct xLIST_ITEM ListItem_t
#define listGET_OWNER_OF_NEXT_ENTRY(pxTCB, pxList)
UBaseType_t uxListRemove(ListItem_t *const pxItemToRemove) PRIVILEGED_FUNCTION
#define listGET_OWNER_OF_HEAD_ENTRY(pxList)
void vListInsertEnd(List_t *const pxList, ListItem_t *const pxNewListItem) PRIVILEGED_FUNCTION
#define listSET_LIST_ITEM_VALUE(pxListItem, xValue)
void vListInsert(List_t *const pxList, ListItem_t *const pxNewListItem) PRIVILEGED_FUNCTION
#define listGET_LIST_ITEM_VALUE(pxListItem)
#define listLIST_IS_EMPTY(pxList)
void vListInitialiseItem(ListItem_t *const pxItem) PRIVILEGED_FUNCTION
#define listSET_LIST_ITEM_OWNER(pxListItem, pxOwner)
void vListInitialise(List_t *const pxList) PRIVILEGED_FUNCTION
void * pvPortMalloc(size_t xSize) PRIVILEGED_FUNCTION
unsigned long UBaseType_t
#define portDISABLE_INTERRUPTS()
#define portENABLE_INTERRUPTS()
#define errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY
ListItem_t xEventListItem
List item used to place the CRCB in event lists.
UBaseType_t uxIndex
Used to distinguish between co-routines when multiple co-routines use the same co-routine function.
UBaseType_t uxPriority
The priority of the co-routine in relation to other co-routines.
uint16_t uxState
Used internally by the co-routine implementation.
ListItem_t xGenericListItem
List item used to place the CRCB in ready and blocked queues.
crCOROUTINE_CODE pxCoRoutineFunction
struct xLIST *configLIST_VOLATILE pxContainer
Pointer to the list in which this list item is placed (if any).
TickType_t xTaskGetTickCount(void) PRIVILEGED_FUNCTION