Chapter 2. API Reference
(continued from previous page)
* // If this callback has executed the required number of times, stop the
* // timer.
* if( *puxVariableToIncrement == 5 )
* {
* // This is called from a timer callback so must not block.
* xTimerStop( xExpiredTimer, staticDONT_BLOCK );
* }
* }
*
*
* void main( void )
* {
* // Create the software time. xTimerCreateStatic() has an extra parameter
* // than the normal xTimerCreate() API function. The parameter is a␣
,→pointer
* // to the StaticTimer_t structure that will hold the software timer
* // structure. If the parameter is passed as NULL then the structure␣
,→will be
* // allocated dynamically, just as if xTimerCreate() had been called.
* xTimer = xTimerCreateStatic( "T1", // Text name for the task.
,→ Helps debugging only. Not used by FreeRTOS.
* xTimerPeriod, // The period of the␣
,→timer in ticks.
* pdTRUE, // This is an auto-reload␣
,→timer.
* ( void * ) &uxVariableToIncrement, // A␣
,→variable incremented by the software timer's callback function
* prvTimerCallback, // The function to␣
,→execute when the timer expires.
* &xTimerBuffer ); // The buffer that will␣
,→hold the software timer structure.
*
* // The scheduler has not started yet so a block time is not used.
* xReturned = xTimerStart( xTimer, 0 );
*
* // ...
* // Create tasks here.
* // ...
*
* // Starting the scheduler will start the timers running as they have␣
,→already
* // been set into the active state.
* vTaskStartScheduler();
*
* // Should not reach here.
* for( ;; );
* }
*
Return If the timer is created then a handle to the created timer is returned. If pxTimerBuffer was NULL
then NULL is returned.
Parameters
• 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 con-
stant portTICK_PERIOD_MS can be used to convert a time that has been specified in millisec-
onds. 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_PERIOD_MS ) provided configTICK_RATE_HZ is less than or equal to 1000. The
timer period must be greater than 0.
• uxAutoReload: If uxAutoReload is set to pdTRUE then the timer will expire repeatedly with a
Espressif Systems 917
Submit Document Feedback
Release v4.4