12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127 |
- #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
- #define tmrSTATUS_IS_ACTIVE ( ( uint8_t ) 0x01 )
- #define tmrSTATUS_IS_STATICALLY_ALLOCATED ( ( uint8_t ) 0x02 )
- #define tmrSTATUS_IS_AUTORELOAD ( ( uint8_t ) 0x04 )
- typedef struct tmrTimerControl
- {
- const char *pcTimerName;
- ListItem_t xTimerListItem;
- TickType_t xTimerPeriodInTicks;
- void *pvTimerID;
- TimerCallbackFunction_t pxCallbackFunction;
- #if( configUSE_TRACE_FACILITY == 1 )
- UBaseType_t uxTimerNumber;
- #endif
- uint8_t ucStatus;
- } 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 portTASK_FUNCTION_PROTO( prvTimerTask, 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 )
- {
-
- pxNewTimer->ucStatus = 0x00;
- prvInitialiseNewTimer( pcTimerName, xTimerPeriodInTicks, uxAutoReload, pvTimerID, pxCallbackFunction, pxNewTimer );
- }
- 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 ) );
- ( void ) xSize;
- }
- #endif
-
- configASSERT( pxTimerBuffer );
- pxNewTimer = ( Timer_t * ) pxTimerBuffer;
- if( pxNewTimer != NULL )
- {
-
- pxNewTimer->ucStatus = tmrSTATUS_IS_STATICALLY_ALLOCATED;
- prvInitialiseNewTimer( pcTimerName, xTimerPeriodInTicks, uxAutoReload, pvTimerID, pxCallbackFunction, pxNewTimer );
- }
- 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->pvTimerID = pvTimerID;
- pxNewTimer->pxCallbackFunction = pxCallbackFunction;
- vListInitialiseItem( &( pxNewTimer->xTimerListItem ) );
- if( uxAutoReload != pdFALSE )
- {
- pxNewTimer->ucStatus |= tmrSTATUS_IS_AUTORELOAD;
- }
- 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 = 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 = xTimer;
- configASSERT( xTimer );
- return pxTimer->xTimerPeriodInTicks;
- }
- void vTimerSetReloadMode( TimerHandle_t xTimer, const UBaseType_t uxAutoReload )
- {
- Timer_t * pxTimer = xTimer;
- configASSERT( xTimer );
- taskENTER_CRITICAL();
- {
- if( uxAutoReload != pdFALSE )
- {
- pxTimer->ucStatus |= tmrSTATUS_IS_AUTORELOAD;
- }
- else
- {
- pxTimer->ucStatus &= ~tmrSTATUS_IS_AUTORELOAD;
- }
- }
- taskEXIT_CRITICAL();
- }
- UBaseType_t uxTimerGetReloadMode( TimerHandle_t xTimer )
- {
- Timer_t * pxTimer = xTimer;
- UBaseType_t uxReturn;
- configASSERT( xTimer );
- taskENTER_CRITICAL();
- {
- if( ( pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD ) == 0 )
- {
-
- uxReturn = ( UBaseType_t ) pdFALSE;
- }
- else
- {
-
- uxReturn = ( UBaseType_t ) pdTRUE;
- }
- }
- taskEXIT_CRITICAL();
- return uxReturn;
- }
- TickType_t xTimerGetExpiryTime( TimerHandle_t xTimer )
- {
- Timer_t * pxTimer = xTimer;
- TickType_t xReturn;
- configASSERT( xTimer );
- xReturn = listGET_LIST_ITEM_VALUE( &( pxTimer->xTimerListItem ) );
- return xReturn;
- }
- const char * pcTimerGetName( TimerHandle_t xTimer )
- {
- Timer_t *pxTimer = 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->ucStatus & tmrSTATUS_IS_AUTORELOAD ) != 0 )
- {
-
- 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
- {
- pxTimer->ucStatus &= ~tmrSTATUS_IS_ACTIVE;
- mtCOVERAGE_TEST_MARKER();
- }
-
- pxTimer->pxCallbackFunction( ( TimerHandle_t ) pxTimer );
- }
- static portTASK_FUNCTION( prvTimerTask, 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 :
-
- pxTimer->ucStatus |= tmrSTATUS_IS_ACTIVE;
- 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->ucStatus & tmrSTATUS_IS_AUTORELOAD ) != 0 )
- {
- 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 :
-
- pxTimer->ucStatus &= ~tmrSTATUS_IS_ACTIVE;
- break;
- case tmrCOMMAND_CHANGE_PERIOD :
- case tmrCOMMAND_CHANGE_PERIOD_FROM_ISR :
- pxTimer->ucStatus |= tmrSTATUS_IS_ACTIVE;
- 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 )
- {
-
- if( ( pxTimer->ucStatus & tmrSTATUS_IS_STATICALLY_ALLOCATED ) == ( uint8_t ) 0 )
- {
- vPortFree( pxTimer );
- }
- else
- {
- pxTimer->ucStatus &= ~tmrSTATUS_IS_ACTIVE;
- }
- }
- #else
- {
-
- pxTimer->ucStatus &= ~tmrSTATUS_IS_ACTIVE;
- }
- #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->ucStatus & tmrSTATUS_IS_AUTORELOAD ) != 0 )
- {
-
- 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 xReturn;
- Timer_t *pxTimer = xTimer;
- configASSERT( xTimer );
-
- taskENTER_CRITICAL();
- {
- if( ( pxTimer->ucStatus & tmrSTATUS_IS_ACTIVE ) == 0 )
- {
- xReturn = pdFALSE;
- }
- else
- {
- xReturn = pdTRUE;
- }
- }
- taskEXIT_CRITICAL();
- return xReturn;
- }
- void *pvTimerGetTimerID( const TimerHandle_t xTimer )
- {
- Timer_t * const pxTimer = 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 = 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
|