35 #define MPU_WRAPPERS_INCLUDED_FROM_API_FILE 42 #if ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 0 ) 43 #error configUSE_TIMERS must be set to 1 to make the xTimerPendFunctionCall() function available. 50 #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE 57 #if ( configUSE_TIMERS == 1 ) 60 #define tmrNO_DELAY ( TickType_t ) 0U 64 #ifndef configTIMER_SERVICE_TASK_NAME 65 #define configTIMER_SERVICE_TASK_NAME "Tmr Svc" 69 typedef struct tmrTimerControl
71 const char *pcTimerName;
77 #if( configUSE_TRACE_FACILITY == 1 ) 81 #if( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) 82 uint8_t ucStaticallyAllocated;
88 typedef xTIMER Timer_t;
95 typedef struct tmrTimerParameters
102 typedef struct tmrCallbackParameters
106 uint32_t ulParameter2;
107 } CallbackParameters_t;
111 typedef struct tmrTimerQueueMessage
116 TimerParameter_t xTimerParameters;
120 #if ( INCLUDE_xTimerPendFunctionCall == 1 ) 121 CallbackParameters_t xCallbackParameters;
124 } DaemonTaskMessage_t;
145 #if( configSUPPORT_STATIC_ALLOCATION == 1 ) 151 extern void vApplicationGetTimerTaskMemory(
StaticTask_t **ppxTimerTaskTCBBuffer,
StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize );
216 static void prvInitialiseNewTimer(
const char *
const pcTimerName,
219 void *
const pvTimerID,
232 prvCheckForValidListAndQueue();
234 if( xTimerQueue !=
NULL )
236 #if( configSUPPORT_STATIC_ALLOCATION == 1 ) 240 uint32_t ulTimerTaskStackSize;
242 vApplicationGetTimerTaskMemory( &pxTimerTaskTCBBuffer, &pxTimerTaskStackBuffer, &ulTimerTaskStackSize );
243 xTimerTaskHandle = xTaskCreateStatic( prvTimerTask,
244 configTIMER_SERVICE_TASK_NAME,
245 ulTimerTaskStackSize,
248 pxTimerTaskStackBuffer,
249 pxTimerTaskTCBBuffer );
250 if( xTimerTaskHandle !=
NULL )
257 xReturn = xTaskCreate( prvTimerTask,
258 configTIMER_SERVICE_TASK_NAME,
264 *timerTaskHandle = xTimerTaskHandle;
277 #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) 282 void *
const pvTimerID,
287 pxNewTimer = ( Timer_t * )
pvPortMalloc(
sizeof( Timer_t ) );
289 if( pxNewTimer !=
NULL )
291 prvInitialiseNewTimer( pcTimerName, xTimerPeriodInTicks, uxAutoReload, pvTimerID, pxCallbackFunction, pxNewTimer );
293 #if( configSUPPORT_STATIC_ALLOCATION == 1 ) 298 pxNewTimer->ucStaticallyAllocated =
pdFALSE;
309 #if( configSUPPORT_STATIC_ALLOCATION == 1 ) 311 TimerHandle_t xTimerCreateStatic(
const char *
const pcTimerName,
314 void *
const pvTimerID,
320 #if( configASSERT_DEFINED == 1 ) 332 pxNewTimer = ( Timer_t * ) pxTimerBuffer;
334 if( pxNewTimer !=
NULL )
336 prvInitialiseNewTimer( pcTimerName, xTimerPeriodInTicks, uxAutoReload, pvTimerID, pxCallbackFunction, pxNewTimer );
338 #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) 342 pxNewTimer->ucStaticallyAllocated =
pdTRUE;
353 static void prvInitialiseNewTimer(
const char *
const pcTimerName,
356 void *
const pvTimerID,
358 Timer_t *pxNewTimer )
363 if( pxNewTimer !=
NULL )
367 prvCheckForValidListAndQueue();
371 pxNewTimer->pcTimerName = pcTimerName;
372 pxNewTimer->xTimerPeriodInTicks = xTimerPeriodInTicks;
373 pxNewTimer->uxAutoReload = uxAutoReload;
374 pxNewTimer->pvTimerID = pvTimerID;
375 pxNewTimer->pxCallbackFunction = pxCallbackFunction;
385 DaemonTaskMessage_t xMessage;
391 if( xTimerQueue !=
NULL )
394 xMessage.xMessageID = xCommandID;
395 xMessage.u.xTimerParameters.xMessageValue = xOptionalValue;
396 xMessage.u.xTimerParameters.pxTimer = ( Timer_t * ) xTimer;
430 return xTimerTaskHandle;
436 Timer_t *pxTimer = ( Timer_t * ) xTimer;
439 return pxTimer->xTimerPeriodInTicks;
445 Timer_t * pxTimer = ( Timer_t * ) xTimer;
456 Timer_t *pxTimer = ( Timer_t * ) xTimer;
459 return pxTimer->pcTimerName;
463 static void prvProcessExpiredTimer(
const TickType_t xNextExpireTime,
const TickType_t xTimeNow )
480 if( prvInsertTimerInActiveList( pxTimer, ( xNextExpireTime + pxTimer->xTimerPeriodInTicks ), xTimeNow, xNextExpireTime ) !=
pdFALSE )
503 static void prvTimerTask(
void *pvParameters )
509 ( void ) pvParameters;
511 #if( configUSE_DAEMON_TASK_STARTUP_HOOK == 1 ) 513 extern void vApplicationDaemonTaskStartupHook(
void );
519 vApplicationDaemonTaskStartupHook();
527 xNextExpireTime = prvGetNextExpireTime( &xListWasEmpty );
531 prvProcessTimerOrBlockTask( xNextExpireTime, xListWasEmpty );
534 prvProcessReceivedCommands();
539 static void prvProcessTimerOrBlockTask(
const TickType_t xNextExpireTime,
BaseType_t xListWasEmpty )
551 xTimeNow = prvSampleTimeNow( &xTimerListsWereSwitched );
552 if( xTimerListsWereSwitched ==
pdFALSE )
555 if( ( xListWasEmpty ==
pdFALSE ) && ( xNextExpireTime <= xTimeNow ) )
558 prvProcessExpiredTimer( xNextExpireTime, xTimeNow );
611 if( *pxListWasEmpty ==
pdFALSE )
621 return xNextExpireTime;
632 if( xTimeNow < xLastTime )
634 prvSwitchTimerLists();
635 *pxTimerListsWereSwitched =
pdTRUE;
639 *pxTimerListsWereSwitched =
pdFALSE;
642 xLastTime = xTimeNow;
655 if( xNextExpiryTime <= xTimeNow )
659 if( ( (
TickType_t ) ( xTimeNow - xCommandTime ) ) >= pxTimer->xTimerPeriodInTicks )
663 xProcessTimerNow =
pdTRUE;
667 vListInsert( pxOverflowTimerList, &( pxTimer->xTimerListItem ) );
672 if( ( xTimeNow < xCommandTime ) && ( xNextExpiryTime >= xCommandTime ) )
677 xProcessTimerNow =
pdTRUE;
681 vListInsert( pxCurrentTimerList, &( pxTimer->xTimerListItem ) );
685 return xProcessTimerNow;
689 static void prvProcessReceivedCommands(
void )
691 DaemonTaskMessage_t xMessage;
698 #if ( INCLUDE_xTimerPendFunctionCall == 1 ) 704 const CallbackParameters_t *
const pxCallback = &( xMessage.u.xCallbackParameters );
711 pxCallback->pxCallbackFunction( pxCallback->pvParameter1, pxCallback->ulParameter2 );
726 pxTimer = xMessage.u.xTimerParameters.pxTimer;
746 xTimeNow = prvSampleTimeNow( &xTimerListsWereSwitched );
748 switch( xMessage.xMessageID )
756 if( prvInsertTimerInActiveList( pxTimer, xMessage.u.xTimerParameters.xMessageValue + pxTimer->xTimerPeriodInTicks, xTimeNow, xMessage.u.xTimerParameters.xMessageValue ) !=
pdFALSE )
788 pxTimer->xTimerPeriodInTicks = xMessage.u.xTimerParameters.xMessageValue;
797 ( void ) prvInsertTimerInActiveList( pxTimer, ( xTimeNow + pxTimer->xTimerPeriodInTicks ), xTimeNow, xTimeNow );
804 #if( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 0 ) ) 810 #elif( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) ) 815 if( pxTimer->ucStaticallyAllocated == ( uint8_t )
pdFALSE )
836 static void prvSwitchTimerLists(
void )
869 xReloadTime = ( xNextExpireTime + pxTimer->xTimerPeriodInTicks );
870 if( xReloadTime > xNextExpireTime )
874 vListInsert( pxCurrentTimerList, &( pxTimer->xTimerListItem ) );
889 pxTemp = pxCurrentTimerList;
890 pxCurrentTimerList = pxOverflowTimerList;
891 pxOverflowTimerList = pxTemp;
895 static void prvCheckForValidListAndQueue(
void )
902 if( xTimerQueue ==
NULL )
906 pxCurrentTimerList = &xActiveTimerList1;
907 pxOverflowTimerList = &xActiveTimerList2;
909 #if( configSUPPORT_STATIC_ALLOCATION == 1 ) 924 #if ( configQUEUE_REGISTRY_SIZE > 0 ) 926 if( xTimerQueue !=
NULL )
949 Timer_t *pxTimer = ( Timer_t * ) xTimer;
963 return xTimerIsInActiveList;
969 Timer_t *
const pxTimer = ( Timer_t * ) xTimer;
976 pvReturn = pxTimer->pvTimerID;
986 Timer_t *
const pxTimer = ( Timer_t * ) xTimer;
992 pxTimer->pvTimerID = pvNewID;
998 #if( INCLUDE_xTimerPendFunctionCall == 1 ) 1002 DaemonTaskMessage_t xMessage;
1008 xMessage.u.xCallbackParameters.pxCallbackFunction = xFunctionToPend;
1009 xMessage.u.xCallbackParameters.pvParameter1 = pvParameter1;
1010 xMessage.u.xCallbackParameters.ulParameter2 = ulParameter2;
1012 xReturn =
xQueueSendFromISR( xTimerQueue, &xMessage, pxHigherPriorityTaskWoken );
1022 #if( INCLUDE_xTimerPendFunctionCall == 1 ) 1026 DaemonTaskMessage_t xMessage;
1037 xMessage.u.xCallbackParameters.pxCallbackFunction = xFunctionToPend;
1038 xMessage.u.xCallbackParameters.pvParameter1 = pvParameter1;
1039 xMessage.u.xCallbackParameters.ulParameter2 = ulParameter2;
1051 #if ( configUSE_TRACE_FACILITY == 1 ) 1055 return ( ( Timer_t * ) xTimer )->uxTimerNumber;
1061 #if ( configUSE_TRACE_FACILITY == 1 ) 1065 ( ( Timer_t * ) xTimer )->uxTimerNumber = uxTimerNumber;
#define configTIMER_TASK_PRIORITY
#define tmrCOMMAND_RESET_FROM_ISR
void vPortFree(void *pv) PRIVILEGED_FUNCTION
#define listGET_LIST_ITEM_VALUE(pxListItem)
#define tracePEND_FUNC_CALL(xFunctionToPend, pvParameter1, ulParameter2, ret)
BaseType_t xTimerPendFunctionCallFromISR(PendedFunction_t xFunctionToPend, void *pvParameter1, uint32_t ulParameter2, BaseType_t *pxHigherPriorityTaskWoken) PRIVILEGED_FUNCTION
TaskHandle_t xTimerGetTimerDaemonTaskHandle(void) PRIVILEGED_FUNCTION
#define configTIMER_QUEUE_LENGTH
#define listIS_CONTAINED_WITHIN(pxList, pxListItem)
UBaseType_t uxListRemove(ListItem_t *const pxItemToRemove) PRIVILEGED_FUNCTION
#define listGET_ITEM_VALUE_OF_HEAD_ENTRY(pxList)
#define tmrCOMMAND_STOP_FROM_ISR
#define taskEXIT_CRITICAL()
void vTaskSuspendAll(void) PRIVILEGED_FUNCTION
#define tmrCOMMAND_CHANGE_PERIOD
#define taskSCHEDULER_RUNNING
void * pvPortMalloc(size_t xSize) PRIVILEGED_FUNCTION
#define listSET_LIST_ITEM_VALUE(pxListItem, xValue)
void(* PendedFunction_t)(void *, uint32_t)
#define tmrCOMMAND_DELETE
#define listLIST_IS_EMPTY(pxList)
BaseType_t xTimerCreateTimerTask(TaskHandle_t *) PRIVILEGED_FUNCTION
BaseType_t xTimerGenericCommand(TimerHandle_t xTimer, const BaseType_t xCommandID, const TickType_t xOptionalValue, BaseType_t *const pxHigherPriorityTaskWoken, const TickType_t xTicksToWait) PRIVILEGED_FUNCTION
unsigned long UBaseType_t
void * pvTimerGetTimerID(const TimerHandle_t xTimer) PRIVILEGED_FUNCTION
BaseType_t xQueueReceive(QueueHandle_t xQueue, void *const pvBuffer, TickType_t xTicksToWait) PRIVILEGED_FUNCTION
#define xQueueSendToBackFromISR(xQueue, pvItemToQueue, pxHigherPriorityTaskWoken)
#define traceTIMER_COMMAND_RECEIVED(pxTimer, xMessageID, xMessageValue)
#define listSET_LIST_ITEM_OWNER(pxListItem, pxOwner)
#define vQueueAddToRegistry(xQueue, pcName)
TickType_t xTaskGetTickCount(void) PRIVILEGED_FUNCTION
#define tmrCOMMAND_START_DONT_TRACE
void vQueueWaitForMessageRestricted(QueueHandle_t xQueue, TickType_t xTicksToWait, const BaseType_t xWaitIndefinitely) PRIVILEGED_FUNCTION
void(* TimerCallbackFunction_t)(TimerHandle_t xTimer)
#define portPRIVILEGE_BIT
#define traceTIMER_COMMAND_SEND(xTimer, xMessageID, xMessageValueValue, xReturn)
BaseType_t xTimerPendFunctionCall(PendedFunction_t xFunctionToPend, void *pvParameter1, uint32_t ulParameter2, TickType_t xTicksToWait) PRIVILEGED_FUNCTION
#define tmrCOMMAND_CHANGE_PERIOD_FROM_ISR
#define listGET_OWNER_OF_HEAD_ENTRY(pxList)
#define configTIMER_TASK_STACK_DEPTH
#define tmrCOMMAND_START_FROM_ISR
TickType_t xTimerGetPeriod(TimerHandle_t xTimer) PRIVILEGED_FUNCTION
struct xSTATIC_TIMER StaticTimer_t
void vListInsert(List_t *const pxList, ListItem_t *const pxNewListItem) PRIVILEGED_FUNCTION
#define portYIELD_WITHIN_API
#define tmrCOMMAND_EXECUTE_CALLBACK
#define tmrFIRST_FROM_ISR_COMMAND
BaseType_t xTaskResumeAll(void) PRIVILEGED_FUNCTION
BaseType_t xTaskGetSchedulerState(void) PRIVILEGED_FUNCTION
#define taskENTER_CRITICAL()
const char * pcTimerGetName(TimerHandle_t xTimer) PRIVILEGED_FUNCTION
#define PRIVILEGED_FUNCTION
void vTimerSetTimerID(TimerHandle_t xTimer, void *pvNewID) PRIVILEGED_FUNCTION
#define mtCOVERAGE_TEST_MARKER()
#define tmrCOMMAND_EXECUTE_CALLBACK_FROM_ISR
TickType_t xTimerGetExpiryTime(TimerHandle_t xTimer) PRIVILEGED_FUNCTION
#define tracePEND_FUNC_CALL_FROM_ISR(xFunctionToPend, pvParameter1, ulParameter2, ret)
#define traceTIMER_EXPIRED(pxTimer)
BaseType_t xTimerIsTimerActive(TimerHandle_t xTimer) PRIVILEGED_FUNCTION
#define traceTIMER_CREATE(pxNewTimer)
#define xQueueSendFromISR(xQueue, pvItemToQueue, pxHigherPriorityTaskWoken)
void vListInitialise(List_t *const pxList) PRIVILEGED_FUNCTION
void vListInitialiseItem(ListItem_t *const pxItem) PRIVILEGED_FUNCTION
#define xQueueSendToBack(xQueue, pvItemToQueue, xTicksToWait)
portSTACK_TYPE StackType_t