#include "include/FreeRTOS.h"
#include "include/task.h"
#include "include/queue.h"
#include "include/timers.h"
Data Structures | |
struct | tmrTimerControl |
struct | tmrTimerQueueMessage |
Macros | |
#define | MPU_WRAPPERS_INCLUDED_FROM_API_FILE |
#define | tmrNO_DELAY ( portTickType ) 0U |
Typedefs | |
typedef struct tmrTimerControl | xTIMER |
typedef struct tmrTimerQueueMessage | xTIMER_MESSAGE |
Functions | |
static void | prvCheckForValidListAndQueue (static void prvTimerTask void) |
static void | prvCheckForValidListAndQueue (void) |
static portTickType | prvGetNextExpireTime (portBASE_TYPE *pxListWasEmpty) |
static portBASE_TYPE | prvInsertTimerInActiveList (xTIMER *pxTimer, portTickType xNextExpiryTime, portTickType xTimeNow, portTickType xCommandTime) |
static void | prvProcessExpiredTimer (portTickType xNextExpireTime, portTickType xTimeNow) |
static void | prvProcessReceivedCommands (void) |
static void | prvProcessTimerOrBlockTask (portTickType xNextExpireTime, portBASE_TYPE xListWasEmpty) |
static portTickType | prvSampleTimeNow (portBASE_TYPE *pxTimerListsWereSwitched) |
static void | prvSwitchTimerLists (portTickType xLastTime) |
static void | prvTimerTask (void *pvParameters) |
void * | pvTimerGetTimerID (xTimerHandle xTimer) |
void *pvTimerGetTimerID( xTimerHandle xTimer ); More... | |
xTimerHandle | xTimerCreate (const signed char *pcTimerName, portTickType xTimerPeriodInTicks, unsigned portBASE_TYPE uxAutoReload, void *pvTimerID, tmrTIMER_CALLBACK pxCallbackFunction) |
xTimerHandle xTimerCreate( const signed char *pcTimerName, portTickType xTimerPeriodInTicks, unsigned portBASE_TYPE uxAutoReload, void * pvTimerID, tmrTIMER_CALLBACK pxCallbackFunction ); More... | |
portBASE_TYPE | xTimerGenericCommand (xTimerHandle xTimer, portBASE_TYPE xCommandID, portTickType xOptionalValue, signed portBASE_TYPE *pxHigherPriorityTaskWoken, portTickType xBlockTime) |
portBASE_TYPE | xTimerIsTimerActive (xTimerHandle xTimer) |
portBASE_TYPE xTimerIsTimerActive( xTimerHandle xTimer ); More... | |
Variables | |
static PRIVILEGED_DATA xList * | pxCurrentTimerList |
static PRIVILEGED_DATA xList * | pxOverflowTimerList |
static PRIVILEGED_DATA xList | xActiveTimerList1 |
static PRIVILEGED_DATA xList | xActiveTimerList2 |
static PRIVILEGED_DATA xQueueHandle | xTimerQueue = NULL |
#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE |
#define tmrNO_DELAY ( portTickType ) 0U |
Referenced by prvProcessExpiredTimer(), prvProcessReceivedCommands(), prvSwitchTimerLists(), and xTimerGenericCommand().
typedef struct tmrTimerControl xTIMER |
typedef struct tmrTimerQueueMessage xTIMER_MESSAGE |
|
static |
References configASSERT, configTIMER_TASK_PRIORITY, configTIMER_TASK_STACK_DEPTH, pdFAIL, portPRIVILEGE_BIT, prvTimerTask(), xTaskCreate, and xTimerQueue.
Referenced by xTimerCreate().
|
static |
|
static |
References listGET_ITEM_VALUE_OF_HEAD_ENTRY, listLIST_IS_EMPTY, pdFALSE, and pxCurrentTimerList.
Referenced by prvTimerTask().
|
static |
|
static |
References configASSERT, listGET_OWNER_OF_HEAD_ENTRY, pdTRUE, prvInsertTimerInActiveList(), tmrTimerControl::pxCallbackFunction, pxCurrentTimerList, tmrCOMMAND_START, tmrNO_DELAY, traceTIMER_EXPIRED, tmrTimerControl::uxAutoReload, uxListRemove(), xTimerGenericCommand(), tmrTimerControl::xTimerListItem, and tmrTimerControl::xTimerPeriodInTicks.
Referenced by prvProcessTimerOrBlockTask().
|
static |
References configASSERT, listIS_CONTAINED_WITHIN, pdFAIL, pdFALSE, pdTRUE, prvInsertTimerInActiveList(), prvSampleTimeNow(), tmrTimerControl::pxCallbackFunction, tmrTimerQueueMessage::pxTimer, tmrCOMMAND_CHANGE_PERIOD, tmrCOMMAND_DELETE, tmrCOMMAND_START, tmrCOMMAND_STOP, tmrNO_DELAY, traceTIMER_COMMAND_RECEIVED, uxListRemove(), vPortFree(), tmrTimerQueueMessage::xMessageID, tmrTimerQueueMessage::xMessageValue, xQueueReceive, xTimerGenericCommand(), tmrTimerControl::xTimerListItem, tmrTimerControl::xTimerPeriodInTicks, and xTimerQueue.
Referenced by prvTimerTask().
|
static |
References pdFALSE, portYIELD_WITHIN_API, prvProcessExpiredTimer(), prvSampleTimeNow(), vQueueWaitForMessageRestricted(), vTaskSuspendAll(), xTaskResumeAll(), and xTimerQueue.
Referenced by prvTimerTask().
|
static |
References pdFALSE, pdTRUE, PRIVILEGED_DATA, prvSwitchTimerLists(), and xTaskGetTickCount().
Referenced by prvProcessReceivedCommands(), and prvProcessTimerOrBlockTask().
|
static |
References configASSERT, listGET_ITEM_VALUE_OF_HEAD_ENTRY, listGET_OWNER_OF_HEAD_ENTRY, listLIST_IS_EMPTY, listSET_LIST_ITEM_OWNER, listSET_LIST_ITEM_VALUE, pdFALSE, pdTRUE, tmrTimerControl::pxCallbackFunction, pxCurrentTimerList, pxOverflowTimerList, tmrCOMMAND_START, tmrNO_DELAY, uxListRemove(), vListInsert(), xTimerGenericCommand(), and tmrTimerControl::xTimerListItem.
Referenced by prvSampleTimeNow().
|
static |
References prvGetNextExpireTime(), prvProcessReceivedCommands(), and prvProcessTimerOrBlockTask().
Referenced by prvCheckForValidListAndQueue().
void* pvTimerGetTimerID | ( | xTimerHandle | xTimer | ) |
void *pvTimerGetTimerID( xTimerHandle xTimer );
Returns the ID assigned to the timer.
IDs are assigned to timers using the pvTimerID parameter of the call to xTimerCreated() that was used to create the timer.
If the same callback function is assigned to multiple timers then the timer ID can be used within the callback function to identify which timer actually expired.
xTimer | The timer being queried. |
Example usage:
See the xTimerCreate() API function example usage scenario.
References tmrTimerControl::pvTimerID.
xTimerHandle xTimerCreate | ( | const signed char * | pcTimerName, |
portTickType | xTimerPeriodInTicks, | ||
unsigned portBASE_TYPE | uxAutoReload, | ||
void * | pvTimerID, | ||
tmrTIMER_CALLBACK | pxCallbackFunction | ||
) |
xTimerHandle xTimerCreate( const signed char *pcTimerName, portTickType xTimerPeriodInTicks, unsigned portBASE_TYPE uxAutoReload, void * pvTimerID, tmrTIMER_CALLBACK pxCallbackFunction );
Creates a new software timer instance. This allocates the storage required by the new timer, initialises the new timers internal state, and returns a handle by which the new timer can be referenced.
Timers are created in the dormant state. The xTimerStart(), xTimerReset(), xTimerStartFromISR(), xTimerResetFromISR(), xTimerChangePeriod() and xTimerChangePeriodFromISR() API functions can all be used to transition a timer into the active state.
pcTimerName | A text name that is assigned to the timer. This is done purely to assist debugging. The kernel itself only ever references a timer by its handle, and never by its name. |
xTimerPeriodInTicks | The timer period. The time is defined in tick periods so the constant portTICK_RATE_MS can be used to convert a time that has been specified in milliseconds. For example, if the timer must expire after 100 ticks, then xTimerPeriodInTicks should be set to 100. Alternatively, if the timer must expire after 500ms, then xPeriod can be set to ( 500 / portTICK_RATE_MS ) provided configTICK_RATE_HZ is less than or equal to 1000. |
uxAutoReload | If uxAutoReload is set to pdTRUE then the timer will expire repeatedly with a frequency set by the xTimerPeriodInTicks parameter. If uxAutoReload is set to pdFALSE then the timer will be a one-shot timer and enter the dormant state after it expires. |
pvTimerID | An identifier that is assigned to the timer being created. Typically this would be used in the timer callback function to identify which timer expired when the same callback function is assigned to more than one timer. |
pxCallbackFunction | The function to call when the timer expires. Callback functions must have the prototype defined by tmrTIMER_CALLBACK, which is "void vCallbackFunction( xTimerHandle xTimer );". |
Example usage:
#define NUM_TIMERS 5
// An array to hold handles to the created timers. xTimerHandle xTimers[ NUM_TIMERS ];
// An array to hold a count of the number of times each timer expires. long lExpireCounters[ NUM_TIMERS ] = { 0 };
// Define a callback function that will be used by multiple timer instances. // The callback function does nothing but count the number of times the // associated timer expires, and stop the timer once the timer has expired // 10 times. void vTimerCallback( xTimerHandle pxTimer ) { long lArrayIndex; const long xMaxExpiryCountBeforeStopping = 10;
// Optionally do something if the pxTimer parameter is NULL. configASSERT( pxTimer ); // Which timer expired? lArrayIndex = ( long ) pvTimerGetTimerID( pxTimer ); // Increment the number of times that pxTimer has expired. lExpireCounters[ lArrayIndex ] += 1; // If the timer has expired 10 times then stop it from running. if( lExpireCounters[ lArrayIndex ] == xMaxExpiryCountBeforeStopping ) { // Do not use a block time if calling a timer API function from a // timer callback function, as doing so could cause a deadlock! xTimerStop( pxTimer, 0 ); }
}
void main( void ) { long x;
// Create then start some timers. Starting the timers before the scheduler // has been started means the timers will start running immediately that // the scheduler starts. for( x = 0; x < NUM_TIMERS; x++ ) { xTimers[ x ] = xTimerCreate( "Timer", // Just a text name, not used by the kernel. ( 100 * x ), // The timer period in ticks. pdTRUE, // The timers will auto-reload themselves when they expire. ( void * ) x, // Assign each timer a unique id equal to its array index. vTimerCallback // Each timer calls the same callback when it expires. ); if( xTimers[ x ] == NULL ) { // The timer was not created. } else { // Start the timer. No block time is specified, and even if one was // it would be ignored because the scheduler has not yet been // started. if( xTimerStart( xTimers[ x ], 0 ) != pdPASS ) { // The timer could not be set into the Active state. } } } // ... // Create tasks here. // ... // Starting the scheduler will start the timers running as they have already // been set into the active state. xTaskStartScheduler(); // Should not reach here. for( ;; );
References configASSERT, tmrTimerControl::pcTimerName, prvCheckForValidListAndQueue(), pvPortMalloc(), tmrTimerControl::pvTimerID, tmrTimerControl::pxCallbackFunction, traceTIMER_CREATE, traceTIMER_CREATE_FAILED, tmrTimerControl::uxAutoReload, vListInitialiseItem(), tmrTimerControl::xTimerListItem, and tmrTimerControl::xTimerPeriodInTicks.
Referenced by main().
portBASE_TYPE xTimerGenericCommand | ( | xTimerHandle | xTimer, |
portBASE_TYPE | xCommandID, | ||
portTickType | xOptionalValue, | ||
signed portBASE_TYPE * | pxHigherPriorityTaskWoken, | ||
portTickType | xBlockTime | ||
) |
References pdFAIL, tmrTimerQueueMessage::pxTimer, taskSCHEDULER_RUNNING, tmrNO_DELAY, traceTIMER_COMMAND_SEND, tmrTimerQueueMessage::xMessageID, tmrTimerQueueMessage::xMessageValue, xQueueSendToBack, xQueueSendToBackFromISR, xTaskGetSchedulerState(), and xTimerQueue.
Referenced by prvProcessExpiredTimer(), prvProcessReceivedCommands(), and prvSwitchTimerLists().
portBASE_TYPE xTimerIsTimerActive | ( | xTimerHandle | xTimer | ) |
portBASE_TYPE xTimerIsTimerActive( xTimerHandle xTimer );
Queries a timer to see if it is active or dormant.
A timer will be dormant if: 1) It has been created but not started, or 2) It is an expired on-shot timer that has not been restarted.
Timers are created in the dormant state. The xTimerStart(), xTimerReset(), xTimerStartFromISR(), xTimerResetFromISR(), xTimerChangePeriod() and xTimerChangePeriodFromISR() API functions can all be used to transition a timer into the active state.
xTimer | The timer being queried. |
Example usage:
// This function assumes xTimer has already been created. void vAFunction( xTimerHandle xTimer ) { if( xTimerIsTimerActive( xTimer ) != pdFALSE ) // or more simply and equivalently "if( xTimerIsTimerActive( xTimer ) )" { // xTimer is active, do something. } else { // xTimer is not active, do something else. } }
References listIS_CONTAINED_WITHIN, taskENTER_CRITICAL, taskEXIT_CRITICAL, and tmrTimerControl::xTimerListItem.
|
static |
|
static |
Referenced by prvCheckForValidListAndQueue(), prvInsertTimerInActiveList(), and prvSwitchTimerLists().
|
static |
Referenced by prvCheckForValidListAndQueue().
|
static |
Referenced by prvCheckForValidListAndQueue().
|
static |