123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077 |
- #include <stdlib.h>
- #define MPU_WRAPPERS_INCLUDED_FROM_API_FILE
- #include "FreeRTOS.h"
- #include "task.h"
- #include "queue.h"
- #include "timers.h"
- #if ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 0 )
- #error configUSE_TIMERS must be set to 1 to make the xTimerPendFunctionCall() function available.
- #endif
- #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE
- #if ( configUSE_TIMERS == 1 )
- #define tmrNO_DELAY ( TickType_t ) 0U
- #ifndef configTIMER_SERVICE_TASK_NAME
- #define configTIMER_SERVICE_TASK_NAME "Tmr Svc"
- #endif
- typedef struct tmrTimerControl
- {
- const char *pcTimerName;
- ListItem_t xTimerListItem;
- TickType_t xTimerPeriodInTicks;
- UBaseType_t uxAutoReload;
- void *pvTimerID;
- TimerCallbackFunction_t pxCallbackFunction;
- #if( configUSE_TRACE_FACILITY == 1 )
- UBaseType_t uxTimerNumber;
- #endif
- #if( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )
- uint8_t ucStaticallyAllocated;
- #endif
- } xTIMER;
- typedef xTIMER Timer_t;
- typedef struct tmrTimerParameters
- {
- TickType_t xMessageValue;
- Timer_t * pxTimer;
- } TimerParameter_t;
- typedef struct tmrCallbackParameters
- {
- PendedFunction_t pxCallbackFunction;
- void *pvParameter1;
- uint32_t ulParameter2;
- } CallbackParameters_t;
- typedef struct tmrTimerQueueMessage
- {
- BaseType_t xMessageID;
- union
- {
- TimerParameter_t xTimerParameters;
-
- #if ( INCLUDE_xTimerPendFunctionCall == 1 )
- CallbackParameters_t xCallbackParameters;
- #endif
- } u;
- } DaemonTaskMessage_t;
- PRIVILEGED_DATA static List_t xActiveTimerList1;
- PRIVILEGED_DATA static List_t xActiveTimerList2;
- PRIVILEGED_DATA static List_t *pxCurrentTimerList;
- PRIVILEGED_DATA static List_t *pxOverflowTimerList;
- PRIVILEGED_DATA static QueueHandle_t xTimerQueue = NULL;
- PRIVILEGED_DATA static TaskHandle_t xTimerTaskHandle = NULL;
- #if( configSUPPORT_STATIC_ALLOCATION == 1 )
-
- extern void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize );
- #endif
- static void prvCheckForValidListAndQueue( void ) PRIVILEGED_FUNCTION;
- static void prvTimerTask( void *pvParameters ) PRIVILEGED_FUNCTION;
- static void prvProcessReceivedCommands( void ) PRIVILEGED_FUNCTION;
- static BaseType_t prvInsertTimerInActiveList( Timer_t * const pxTimer, const TickType_t xNextExpiryTime, const TickType_t xTimeNow, const TickType_t xCommandTime ) PRIVILEGED_FUNCTION;
- static void prvProcessExpiredTimer( const TickType_t xNextExpireTime, const TickType_t xTimeNow ) PRIVILEGED_FUNCTION;
- static void prvSwitchTimerLists( void ) PRIVILEGED_FUNCTION;
- static TickType_t prvSampleTimeNow( BaseType_t * const pxTimerListsWereSwitched ) PRIVILEGED_FUNCTION;
- static TickType_t prvGetNextExpireTime( BaseType_t * const pxListWasEmpty ) PRIVILEGED_FUNCTION;
- static void prvProcessTimerOrBlockTask( const TickType_t xNextExpireTime, BaseType_t xListWasEmpty ) PRIVILEGED_FUNCTION;
- static void prvInitialiseNewTimer( const char * const pcTimerName,
- const TickType_t xTimerPeriodInTicks,
- const UBaseType_t uxAutoReload,
- void * const pvTimerID,
- TimerCallbackFunction_t pxCallbackFunction,
- Timer_t *pxNewTimer ) PRIVILEGED_FUNCTION;
- BaseType_t xTimerCreateTimerTask( void )
- {
- BaseType_t xReturn = pdFAIL;
-
- prvCheckForValidListAndQueue();
- if( xTimerQueue != NULL )
- {
- #if( configSUPPORT_STATIC_ALLOCATION == 1 )
- {
- StaticTask_t *pxTimerTaskTCBBuffer = NULL;
- StackType_t *pxTimerTaskStackBuffer = NULL;
- uint32_t ulTimerTaskStackSize;
- vApplicationGetTimerTaskMemory( &pxTimerTaskTCBBuffer, &pxTimerTaskStackBuffer, &ulTimerTaskStackSize );
- xTimerTaskHandle = xTaskCreateStatic( prvTimerTask,
- configTIMER_SERVICE_TASK_NAME,
- ulTimerTaskStackSize,
- NULL,
- ( ( UBaseType_t ) configTIMER_TASK_PRIORITY ) | portPRIVILEGE_BIT,
- pxTimerTaskStackBuffer,
- pxTimerTaskTCBBuffer );
- if( xTimerTaskHandle != NULL )
- {
- xReturn = pdPASS;
- }
- }
- #else
- {
- xReturn = xTaskCreate( prvTimerTask,
- configTIMER_SERVICE_TASK_NAME,
- configTIMER_TASK_STACK_DEPTH,
- NULL,
- ( ( UBaseType_t ) configTIMER_TASK_PRIORITY ) | portPRIVILEGE_BIT,
- &xTimerTaskHandle );
- }
- #endif
- }
- else
- {
- mtCOVERAGE_TEST_MARKER();
- }
- configASSERT( xReturn );
- return xReturn;
- }
- #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
- TimerHandle_t xTimerCreate( const char * const pcTimerName,
- const TickType_t xTimerPeriodInTicks,
- const UBaseType_t uxAutoReload,
- void * const pvTimerID,
- TimerCallbackFunction_t pxCallbackFunction )
- {
- Timer_t *pxNewTimer;
- pxNewTimer = ( Timer_t * ) pvPortMalloc( sizeof( Timer_t ) );
- if( pxNewTimer != NULL )
- {
- prvInitialiseNewTimer( pcTimerName, xTimerPeriodInTicks, uxAutoReload, pvTimerID, pxCallbackFunction, pxNewTimer );
- #if( configSUPPORT_STATIC_ALLOCATION == 1 )
- {
-
- pxNewTimer->ucStaticallyAllocated = pdFALSE;
- }
- #endif
- }
- return pxNewTimer;
- }
- #endif
- #if( configSUPPORT_STATIC_ALLOCATION == 1 )
- TimerHandle_t xTimerCreateStatic( const char * const pcTimerName,
- const TickType_t xTimerPeriodInTicks,
- const UBaseType_t uxAutoReload,
- void * const pvTimerID,
- TimerCallbackFunction_t pxCallbackFunction,
- StaticTimer_t *pxTimerBuffer )
- {
- Timer_t *pxNewTimer;
- #if( configASSERT_DEFINED == 1 )
- {
-
- volatile size_t xSize = sizeof( StaticTimer_t );
- configASSERT( xSize == sizeof( Timer_t ) );
- }
- #endif
-
- configASSERT( pxTimerBuffer );
- pxNewTimer = ( Timer_t * ) pxTimerBuffer;
- if( pxNewTimer != NULL )
- {
- prvInitialiseNewTimer( pcTimerName, xTimerPeriodInTicks, uxAutoReload, pvTimerID, pxCallbackFunction, pxNewTimer );
- #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
- {
-
- pxNewTimer->ucStaticallyAllocated = pdTRUE;
- }
- #endif
- }
- return pxNewTimer;
- }
- #endif
- static void prvInitialiseNewTimer( const char * const pcTimerName,
- const TickType_t xTimerPeriodInTicks,
- const UBaseType_t uxAutoReload,
- void * const pvTimerID,
- TimerCallbackFunction_t pxCallbackFunction,
- Timer_t *pxNewTimer )
- {
-
- configASSERT( ( xTimerPeriodInTicks > 0 ) );
- if( pxNewTimer != NULL )
- {
-
- prvCheckForValidListAndQueue();
-
- pxNewTimer->pcTimerName = pcTimerName;
- pxNewTimer->xTimerPeriodInTicks = xTimerPeriodInTicks;
- pxNewTimer->uxAutoReload = uxAutoReload;
- pxNewTimer->pvTimerID = pvTimerID;
- pxNewTimer->pxCallbackFunction = pxCallbackFunction;
- vListInitialiseItem( &( pxNewTimer->xTimerListItem ) );
- traceTIMER_CREATE( pxNewTimer );
- }
- }
- BaseType_t xTimerGenericCommand( TimerHandle_t xTimer, const BaseType_t xCommandID, const TickType_t xOptionalValue, BaseType_t * const pxHigherPriorityTaskWoken, const TickType_t xTicksToWait )
- {
- BaseType_t xReturn = pdFAIL;
- DaemonTaskMessage_t xMessage;
- configASSERT( xTimer );
-
- if( xTimerQueue != NULL )
- {
-
- xMessage.xMessageID = xCommandID;
- xMessage.u.xTimerParameters.xMessageValue = xOptionalValue;
- xMessage.u.xTimerParameters.pxTimer = ( Timer_t * ) xTimer;
- if( xCommandID < tmrFIRST_FROM_ISR_COMMAND )
- {
- if( xTaskGetSchedulerState() == taskSCHEDULER_RUNNING )
- {
- xReturn = xQueueSendToBack( xTimerQueue, &xMessage, xTicksToWait );
- }
- else
- {
- xReturn = xQueueSendToBack( xTimerQueue, &xMessage, tmrNO_DELAY );
- }
- }
- else
- {
- xReturn = xQueueSendToBackFromISR( xTimerQueue, &xMessage, pxHigherPriorityTaskWoken );
- }
- traceTIMER_COMMAND_SEND( xTimer, xCommandID, xOptionalValue, xReturn );
- }
- else
- {
- mtCOVERAGE_TEST_MARKER();
- }
- return xReturn;
- }
- TaskHandle_t xTimerGetTimerDaemonTaskHandle( void )
- {
-
- configASSERT( ( xTimerTaskHandle != NULL ) );
- return xTimerTaskHandle;
- }
- TickType_t xTimerGetPeriod( TimerHandle_t xTimer )
- {
- Timer_t *pxTimer = ( Timer_t * ) xTimer;
- configASSERT( xTimer );
- return pxTimer->xTimerPeriodInTicks;
- }
- TickType_t xTimerGetExpiryTime( TimerHandle_t xTimer )
- {
- Timer_t * pxTimer = ( Timer_t * ) xTimer;
- TickType_t xReturn;
- configASSERT( xTimer );
- xReturn = listGET_LIST_ITEM_VALUE( &( pxTimer->xTimerListItem ) );
- return xReturn;
- }
- const char * pcTimerGetName( TimerHandle_t xTimer )
- {
- Timer_t *pxTimer = ( Timer_t * ) xTimer;
- configASSERT( xTimer );
- return pxTimer->pcTimerName;
- }
- static void prvProcessExpiredTimer( const TickType_t xNextExpireTime, const TickType_t xTimeNow )
- {
- BaseType_t xResult;
- Timer_t * const pxTimer = ( Timer_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxCurrentTimerList );
-
- ( void ) uxListRemove( &( pxTimer->xTimerListItem ) );
- traceTIMER_EXPIRED( pxTimer );
-
- if( pxTimer->uxAutoReload == ( UBaseType_t ) pdTRUE )
- {
-
- if( prvInsertTimerInActiveList( pxTimer, ( xNextExpireTime + pxTimer->xTimerPeriodInTicks ), xTimeNow, xNextExpireTime ) != pdFALSE )
- {
-
- xResult = xTimerGenericCommand( pxTimer, tmrCOMMAND_START_DONT_TRACE, xNextExpireTime, NULL, tmrNO_DELAY );
- configASSERT( xResult );
- ( void ) xResult;
- }
- else
- {
- mtCOVERAGE_TEST_MARKER();
- }
- }
- else
- {
- mtCOVERAGE_TEST_MARKER();
- }
-
- pxTimer->pxCallbackFunction( ( TimerHandle_t ) pxTimer );
- }
- static void prvTimerTask( void *pvParameters )
- {
- TickType_t xNextExpireTime;
- BaseType_t xListWasEmpty;
-
- ( void ) pvParameters;
- #if( configUSE_DAEMON_TASK_STARTUP_HOOK == 1 )
- {
- extern void vApplicationDaemonTaskStartupHook( void );
-
- vApplicationDaemonTaskStartupHook();
- }
- #endif
- for( ;; )
- {
-
- xNextExpireTime = prvGetNextExpireTime( &xListWasEmpty );
-
- prvProcessTimerOrBlockTask( xNextExpireTime, xListWasEmpty );
-
- prvProcessReceivedCommands();
- }
- }
- static void prvProcessTimerOrBlockTask( const TickType_t xNextExpireTime, BaseType_t xListWasEmpty )
- {
- TickType_t xTimeNow;
- BaseType_t xTimerListsWereSwitched;
- vTaskSuspendAll();
- {
-
- xTimeNow = prvSampleTimeNow( &xTimerListsWereSwitched );
- if( xTimerListsWereSwitched == pdFALSE )
- {
-
- if( ( xListWasEmpty == pdFALSE ) && ( xNextExpireTime <= xTimeNow ) )
- {
- ( void ) xTaskResumeAll();
- prvProcessExpiredTimer( xNextExpireTime, xTimeNow );
- }
- else
- {
-
- if( xListWasEmpty != pdFALSE )
- {
-
- xListWasEmpty = listLIST_IS_EMPTY( pxOverflowTimerList );
- }
- vQueueWaitForMessageRestricted( xTimerQueue, ( xNextExpireTime - xTimeNow ), xListWasEmpty );
- if( xTaskResumeAll() == pdFALSE )
- {
-
- portYIELD_WITHIN_API();
- }
- else
- {
- mtCOVERAGE_TEST_MARKER();
- }
- }
- }
- else
- {
- ( void ) xTaskResumeAll();
- }
- }
- }
- static TickType_t prvGetNextExpireTime( BaseType_t * const pxListWasEmpty )
- {
- TickType_t xNextExpireTime;
-
- *pxListWasEmpty = listLIST_IS_EMPTY( pxCurrentTimerList );
- if( *pxListWasEmpty == pdFALSE )
- {
- xNextExpireTime = listGET_ITEM_VALUE_OF_HEAD_ENTRY( pxCurrentTimerList );
- }
- else
- {
-
- xNextExpireTime = ( TickType_t ) 0U;
- }
- return xNextExpireTime;
- }
- static TickType_t prvSampleTimeNow( BaseType_t * const pxTimerListsWereSwitched )
- {
- TickType_t xTimeNow;
- PRIVILEGED_DATA static TickType_t xLastTime = ( TickType_t ) 0U;
- xTimeNow = xTaskGetTickCount();
- if( xTimeNow < xLastTime )
- {
- prvSwitchTimerLists();
- *pxTimerListsWereSwitched = pdTRUE;
- }
- else
- {
- *pxTimerListsWereSwitched = pdFALSE;
- }
- xLastTime = xTimeNow;
- return xTimeNow;
- }
- static BaseType_t prvInsertTimerInActiveList( Timer_t * const pxTimer, const TickType_t xNextExpiryTime, const TickType_t xTimeNow, const TickType_t xCommandTime )
- {
- BaseType_t xProcessTimerNow = pdFALSE;
- listSET_LIST_ITEM_VALUE( &( pxTimer->xTimerListItem ), xNextExpiryTime );
- listSET_LIST_ITEM_OWNER( &( pxTimer->xTimerListItem ), pxTimer );
- if( xNextExpiryTime <= xTimeNow )
- {
-
- if( ( ( TickType_t ) ( xTimeNow - xCommandTime ) ) >= pxTimer->xTimerPeriodInTicks )
- {
-
- xProcessTimerNow = pdTRUE;
- }
- else
- {
- vListInsert( pxOverflowTimerList, &( pxTimer->xTimerListItem ) );
- }
- }
- else
- {
- if( ( xTimeNow < xCommandTime ) && ( xNextExpiryTime >= xCommandTime ) )
- {
-
- xProcessTimerNow = pdTRUE;
- }
- else
- {
- vListInsert( pxCurrentTimerList, &( pxTimer->xTimerListItem ) );
- }
- }
- return xProcessTimerNow;
- }
- static void prvProcessReceivedCommands( void )
- {
- DaemonTaskMessage_t xMessage;
- Timer_t *pxTimer;
- BaseType_t xTimerListsWereSwitched, xResult;
- TickType_t xTimeNow;
- while( xQueueReceive( xTimerQueue, &xMessage, tmrNO_DELAY ) != pdFAIL )
- {
- #if ( INCLUDE_xTimerPendFunctionCall == 1 )
- {
-
- if( xMessage.xMessageID < ( BaseType_t ) 0 )
- {
- const CallbackParameters_t * const pxCallback = &( xMessage.u.xCallbackParameters );
-
- configASSERT( pxCallback );
-
- pxCallback->pxCallbackFunction( pxCallback->pvParameter1, pxCallback->ulParameter2 );
- }
- else
- {
- mtCOVERAGE_TEST_MARKER();
- }
- }
- #endif
-
- if( xMessage.xMessageID >= ( BaseType_t ) 0 )
- {
-
- pxTimer = xMessage.u.xTimerParameters.pxTimer;
- if( listIS_CONTAINED_WITHIN( NULL, &( pxTimer->xTimerListItem ) ) == pdFALSE )
- {
-
- ( void ) uxListRemove( &( pxTimer->xTimerListItem ) );
- }
- else
- {
- mtCOVERAGE_TEST_MARKER();
- }
- traceTIMER_COMMAND_RECEIVED( pxTimer, xMessage.xMessageID, xMessage.u.xTimerParameters.xMessageValue );
-
- xTimeNow = prvSampleTimeNow( &xTimerListsWereSwitched );
- switch( xMessage.xMessageID )
- {
- case tmrCOMMAND_START :
- case tmrCOMMAND_START_FROM_ISR :
- case tmrCOMMAND_RESET :
- case tmrCOMMAND_RESET_FROM_ISR :
- case tmrCOMMAND_START_DONT_TRACE :
-
- if( prvInsertTimerInActiveList( pxTimer, xMessage.u.xTimerParameters.xMessageValue + pxTimer->xTimerPeriodInTicks, xTimeNow, xMessage.u.xTimerParameters.xMessageValue ) != pdFALSE )
- {
-
- pxTimer->pxCallbackFunction( ( TimerHandle_t ) pxTimer );
- traceTIMER_EXPIRED( pxTimer );
- if( pxTimer->uxAutoReload == ( UBaseType_t ) pdTRUE )
- {
- xResult = xTimerGenericCommand( pxTimer, tmrCOMMAND_START_DONT_TRACE, xMessage.u.xTimerParameters.xMessageValue + pxTimer->xTimerPeriodInTicks, NULL, tmrNO_DELAY );
- configASSERT( xResult );
- ( void ) xResult;
- }
- else
- {
- mtCOVERAGE_TEST_MARKER();
- }
- }
- else
- {
- mtCOVERAGE_TEST_MARKER();
- }
- break;
- case tmrCOMMAND_STOP :
- case tmrCOMMAND_STOP_FROM_ISR :
-
- break;
- case tmrCOMMAND_CHANGE_PERIOD :
- case tmrCOMMAND_CHANGE_PERIOD_FROM_ISR :
- pxTimer->xTimerPeriodInTicks = xMessage.u.xTimerParameters.xMessageValue;
- configASSERT( ( pxTimer->xTimerPeriodInTicks > 0 ) );
-
- ( void ) prvInsertTimerInActiveList( pxTimer, ( xTimeNow + pxTimer->xTimerPeriodInTicks ), xTimeNow, xTimeNow );
- break;
- case tmrCOMMAND_DELETE :
-
- #if( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 0 ) )
- {
-
- vPortFree( pxTimer );
- }
- #elif( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
- {
-
- if( pxTimer->ucStaticallyAllocated == ( uint8_t ) pdFALSE )
- {
- vPortFree( pxTimer );
- }
- else
- {
- mtCOVERAGE_TEST_MARKER();
- }
- }
- #endif
- break;
- default :
-
- break;
- }
- }
- }
- }
- static void prvSwitchTimerLists( void )
- {
- TickType_t xNextExpireTime, xReloadTime;
- List_t *pxTemp;
- Timer_t *pxTimer;
- BaseType_t xResult;
-
- while( listLIST_IS_EMPTY( pxCurrentTimerList ) == pdFALSE )
- {
- xNextExpireTime = listGET_ITEM_VALUE_OF_HEAD_ENTRY( pxCurrentTimerList );
-
- pxTimer = ( Timer_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxCurrentTimerList );
- ( void ) uxListRemove( &( pxTimer->xTimerListItem ) );
- traceTIMER_EXPIRED( pxTimer );
-
- pxTimer->pxCallbackFunction( ( TimerHandle_t ) pxTimer );
- if( pxTimer->uxAutoReload == ( UBaseType_t ) pdTRUE )
- {
-
- xReloadTime = ( xNextExpireTime + pxTimer->xTimerPeriodInTicks );
- if( xReloadTime > xNextExpireTime )
- {
- listSET_LIST_ITEM_VALUE( &( pxTimer->xTimerListItem ), xReloadTime );
- listSET_LIST_ITEM_OWNER( &( pxTimer->xTimerListItem ), pxTimer );
- vListInsert( pxCurrentTimerList, &( pxTimer->xTimerListItem ) );
- }
- else
- {
- xResult = xTimerGenericCommand( pxTimer, tmrCOMMAND_START_DONT_TRACE, xNextExpireTime, NULL, tmrNO_DELAY );
- configASSERT( xResult );
- ( void ) xResult;
- }
- }
- else
- {
- mtCOVERAGE_TEST_MARKER();
- }
- }
- pxTemp = pxCurrentTimerList;
- pxCurrentTimerList = pxOverflowTimerList;
- pxOverflowTimerList = pxTemp;
- }
- static void prvCheckForValidListAndQueue( void )
- {
-
- taskENTER_CRITICAL();
- {
- if( xTimerQueue == NULL )
- {
- vListInitialise( &xActiveTimerList1 );
- vListInitialise( &xActiveTimerList2 );
- pxCurrentTimerList = &xActiveTimerList1;
- pxOverflowTimerList = &xActiveTimerList2;
- #if( configSUPPORT_STATIC_ALLOCATION == 1 )
- {
-
- static StaticQueue_t xStaticTimerQueue;
- static uint8_t ucStaticTimerQueueStorage[ ( size_t ) configTIMER_QUEUE_LENGTH * sizeof( DaemonTaskMessage_t ) ];
- xTimerQueue = xQueueCreateStatic( ( UBaseType_t ) configTIMER_QUEUE_LENGTH, ( UBaseType_t ) sizeof( DaemonTaskMessage_t ), &( ucStaticTimerQueueStorage[ 0 ] ), &xStaticTimerQueue );
- }
- #else
- {
- xTimerQueue = xQueueCreate( ( UBaseType_t ) configTIMER_QUEUE_LENGTH, sizeof( DaemonTaskMessage_t ) );
- }
- #endif
- #if ( configQUEUE_REGISTRY_SIZE > 0 )
- {
- if( xTimerQueue != NULL )
- {
- vQueueAddToRegistry( xTimerQueue, "TmrQ" );
- }
- else
- {
- mtCOVERAGE_TEST_MARKER();
- }
- }
- #endif
- }
- else
- {
- mtCOVERAGE_TEST_MARKER();
- }
- }
- taskEXIT_CRITICAL();
- }
- BaseType_t xTimerIsTimerActive( TimerHandle_t xTimer )
- {
- BaseType_t xTimerIsInActiveList;
- Timer_t *pxTimer = ( Timer_t * ) xTimer;
- configASSERT( xTimer );
-
- taskENTER_CRITICAL();
- {
-
- xTimerIsInActiveList = ( BaseType_t ) !( listIS_CONTAINED_WITHIN( NULL, &( pxTimer->xTimerListItem ) ) );
- }
- taskEXIT_CRITICAL();
- return xTimerIsInActiveList;
- }
- void *pvTimerGetTimerID( const TimerHandle_t xTimer )
- {
- Timer_t * const pxTimer = ( Timer_t * ) xTimer;
- void *pvReturn;
- configASSERT( xTimer );
- taskENTER_CRITICAL();
- {
- pvReturn = pxTimer->pvTimerID;
- }
- taskEXIT_CRITICAL();
- return pvReturn;
- }
- void vTimerSetTimerID( TimerHandle_t xTimer, void *pvNewID )
- {
- Timer_t * const pxTimer = ( Timer_t * ) xTimer;
- configASSERT( xTimer );
- taskENTER_CRITICAL();
- {
- pxTimer->pvTimerID = pvNewID;
- }
- taskEXIT_CRITICAL();
- }
- #if( INCLUDE_xTimerPendFunctionCall == 1 )
- BaseType_t xTimerPendFunctionCallFromISR( PendedFunction_t xFunctionToPend, void *pvParameter1, uint32_t ulParameter2, BaseType_t *pxHigherPriorityTaskWoken )
- {
- DaemonTaskMessage_t xMessage;
- BaseType_t xReturn;
-
- xMessage.xMessageID = tmrCOMMAND_EXECUTE_CALLBACK_FROM_ISR;
- xMessage.u.xCallbackParameters.pxCallbackFunction = xFunctionToPend;
- xMessage.u.xCallbackParameters.pvParameter1 = pvParameter1;
- xMessage.u.xCallbackParameters.ulParameter2 = ulParameter2;
- xReturn = xQueueSendFromISR( xTimerQueue, &xMessage, pxHigherPriorityTaskWoken );
- tracePEND_FUNC_CALL_FROM_ISR( xFunctionToPend, pvParameter1, ulParameter2, xReturn );
- return xReturn;
- }
- #endif
- #if( INCLUDE_xTimerPendFunctionCall == 1 )
- BaseType_t xTimerPendFunctionCall( PendedFunction_t xFunctionToPend, void *pvParameter1, uint32_t ulParameter2, TickType_t xTicksToWait )
- {
- DaemonTaskMessage_t xMessage;
- BaseType_t xReturn;
-
- configASSERT( xTimerQueue );
-
- xMessage.xMessageID = tmrCOMMAND_EXECUTE_CALLBACK;
- xMessage.u.xCallbackParameters.pxCallbackFunction = xFunctionToPend;
- xMessage.u.xCallbackParameters.pvParameter1 = pvParameter1;
- xMessage.u.xCallbackParameters.ulParameter2 = ulParameter2;
- xReturn = xQueueSendToBack( xTimerQueue, &xMessage, xTicksToWait );
- tracePEND_FUNC_CALL( xFunctionToPend, pvParameter1, ulParameter2, xReturn );
- return xReturn;
- }
- #endif
- #if ( configUSE_TRACE_FACILITY == 1 )
- UBaseType_t uxTimerGetTimerNumber( TimerHandle_t xTimer )
- {
- return ( ( Timer_t * ) xTimer )->uxTimerNumber;
- }
- #endif
- #if ( configUSE_TRACE_FACILITY == 1 )
- void vTimerSetTimerNumber( TimerHandle_t xTimer, UBaseType_t uxTimerNumber )
- {
- ( ( Timer_t * ) xTimer )->uxTimerNumber = uxTimerNumber;
- }
- #endif
- #endif
|