]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Source/tasks.c
Add event_groups.c and associated functions in other core files.
[freertos] / FreeRTOS / Source / tasks.c
index c0f151958926c4113b3895785a1fcb776f288a30..f231432717d056e9ffc1811b1cab87754c818845 100644 (file)
@@ -169,7 +169,6 @@ typedef struct tskTaskControlBlock
 \r
 } tskTCB;\r
 \r
-\r
 /*\r
  * Some kernel aware debuggers require the data the debugger needs access to to\r
  * be global, rather than file scope.\r
@@ -1327,7 +1326,9 @@ void vTaskEndScheduler( void )
 void vTaskSuspendAll( void )\r
 {\r
        /* A critical section is not required as the variable is of type\r
-       portBASE_TYPE. */\r
+       portBASE_TYPE.  Please read Richard Barry's reply in the following link to a\r
+       post in the FreeRTOS support forum before reporting this as a bug! -\r
+       http://goo.gl/wu4acr */\r
        ++uxSchedulerSuspended;\r
 }\r
 /*----------------------------------------------------------*/\r
@@ -1938,6 +1939,60 @@ portTickType xTimeToWake;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
+void vTaskPlaceOnUnorderedEventList( xList * pxEventList, portTickType xItemValue, portTickType xTicksToWait )\r
+{\r
+portTickType xTimeToWake;\r
+\r
+       configASSERT( pxEventList );\r
+\r
+       /* THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED OR THE\r
+       SCHEDULER SUSPENDED. */\r
+\r
+       /* Store the item value in the event list item. */\r
+       listSET_LIST_ITEM_VALUE( &( pxCurrentTCB->xEventListItem ), xItemValue );\r
+\r
+       /* Place the event list item of the TCB at the end of the appropriate event \r
+       list. */\r
+       vListInsertEnd( pxEventList, &( pxCurrentTCB->xEventListItem ) );\r
+\r
+       /* The task must be removed from the ready list before it is added to the\r
+       blocked list.  Exclusive access can be assured to the ready list as the\r
+       scheduler is locked. */\r
+       if( uxListRemove( &( pxCurrentTCB->xGenericListItem ) ) == ( unsigned portBASE_TYPE ) 0 )\r
+       {\r
+               /* The current task must be in a ready list, so there is no need to\r
+               check, and the port reset macro can be called directly. */\r
+               portRESET_READY_PRIORITY( pxCurrentTCB->uxPriority, uxTopReadyPriority );\r
+       }\r
+\r
+       #if ( INCLUDE_vTaskSuspend == 1 )\r
+       {\r
+               if( xTicksToWait == portMAX_DELAY )\r
+               {\r
+                       /* Add the task to the suspended task list instead of a delayed task\r
+                       list to ensure it is not woken by a timing event.  It will block\r
+                       indefinitely. */\r
+                       vListInsertEnd( &xSuspendedTaskList, &( pxCurrentTCB->xGenericListItem ) );\r
+               }\r
+               else\r
+               {\r
+                       /* Calculate the time at which the task should be woken if the event does\r
+                       not occur.  This may overflow but this doesn't matter. */\r
+                       xTimeToWake = xTickCount + xTicksToWait;\r
+                       prvAddCurrentTaskToDelayedList( xTimeToWake );\r
+               }\r
+       }\r
+       #else /* INCLUDE_vTaskSuspend */\r
+       {\r
+                       /* Calculate the time at which the task should be woken if the event does\r
+                       not occur.  This may overflow but this doesn't matter. */\r
+                       xTimeToWake = xTickCount + xTicksToWait;\r
+                       prvAddCurrentTaskToDelayedList( xTimeToWake );\r
+       }\r
+       #endif /* INCLUDE_vTaskSuspend */\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
 #if configUSE_TIMERS == 1\r
 \r
        void vTaskPlaceOnEventListRestricted( xList * const pxEventList, portTickType xTicksToWait )\r
@@ -2034,6 +2089,56 @@ portBASE_TYPE xReturn;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
+signed portBASE_TYPE xTaskRemoveFromUnorderedEventList( xListItem * pxEventListItem, portTickType xItemValue )\r
+{\r
+tskTCB *pxUnblockedTCB;\r
+portBASE_TYPE xReturn;\r
+\r
+       /* THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED OR THE\r
+       SCHEDULER SUSPENDED.  It can also be called from within an ISR. */\r
+\r
+       /* Store the new item value in the event list. */\r
+       listSET_LIST_ITEM_VALUE( pxEventListItem, xItemValue );\r
+\r
+       /* Remove the TCB from the delayed list, and add it to the ready list. */\r
+\r
+       pxUnblockedTCB = ( tskTCB * ) listGET_LIST_ITEM_OWNER( pxEventListItem );\r
+       configASSERT( pxUnblockedTCB );\r
+       ( void ) uxListRemove( pxEventListItem );\r
+\r
+       if( uxSchedulerSuspended == ( unsigned portBASE_TYPE ) pdFALSE )\r
+       {\r
+               ( void ) uxListRemove( &( pxUnblockedTCB->xGenericListItem ) );\r
+               prvAddTaskToReadyList( pxUnblockedTCB );\r
+       }\r
+       else\r
+       {\r
+               /* Cannot access the delayed or ready lists, so will hold this task \r
+               pending until the scheduler is resumed. */\r
+               vListInsertEnd( &( xPendingReadyList ), pxEventListItem );\r
+       }\r
+\r
+       if( pxUnblockedTCB->uxPriority >= pxCurrentTCB->uxPriority )\r
+       {\r
+               /* Return true if the task removed from the event list has\r
+               a higher priority than the calling task.  This allows\r
+               the calling task to know if it should force a context\r
+               switch now. */\r
+               xReturn = pdTRUE;\r
+\r
+               /* Mark that a yield is pending in case the user is not using the\r
+               "xHigherPriorityTaskWoken" parameter to an ISR safe FreeRTOS function. */\r
+               xYieldPending = pdTRUE;\r
+       }\r
+       else\r
+       {\r
+               xReturn = pdFALSE;\r
+       }\r
+\r
+       return xReturn;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
 void vTaskSetTimeOutState( xTimeOutType * const pxTimeOut )\r
 {\r
        configASSERT( pxTimeOut );\r
@@ -2973,6 +3078,20 @@ tskTCB *pxNewTCB;
        }\r
 \r
 #endif /* configGENERATE_RUN_TIME_STATS */\r
+/*-----------------------------------------------------------*/\r
 \r
+portTickType uxTaskResetEventItemValue( void )\r
+{\r
+portTickType uxReturn;\r
+\r
+       uxReturn = listGET_LIST_ITEM_VALUE( &( pxCurrentTCB->xEventListItem ) );\r
+\r
+       /* Reset the event list item to its normal value - so it can be used with\r
+       queues and semaphores. */\r
+       listSET_LIST_ITEM_VALUE( &( pxCurrentTCB->xEventListItem ), ( ( portTickType ) configMAX_PRIORITIES - ( portTickType ) pxCurrentTCB->uxPriority ) ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\r
+\r
+       return uxReturn;\r
+}\r
+/*-----------------------------------------------------------*/\r
 \r
 \r