2 * FreeRTOS Kernel V10.3.1
\r
3 * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
\r
6 * this software and associated documentation files (the "Software"), to deal in
\r
7 * the Software without restriction, including without limitation the rights to
\r
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
\r
9 * the Software, and to permit persons to whom the Software is furnished to do so,
\r
10 * subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
25 * 1 tab == 4 spaces!
\r
32 #ifndef INC_FREERTOS_H
\r
33 #error "include FreeRTOS.h must appear in source files before include timers.h"
\r
36 /*lint -save -e537 This headers are only multiply included if the application code
\r
37 * happens to also be including task.h. */
\r
45 /*-----------------------------------------------------------
\r
46 * MACROS AND DEFINITIONS
\r
47 *----------------------------------------------------------*/
\r
49 /* IDs for commands that can be sent/received on the timer queue. These are to
\r
50 * be used solely through the macros that make up the public software timer API,
\r
51 * as defined below. The commands that are sent from interrupts must use the
\r
52 * highest numbers as tmrFIRST_FROM_ISR_COMMAND is used to determine if the task
\r
53 * or interrupt version of the queue send function should be used. */
\r
54 #define tmrCOMMAND_EXECUTE_CALLBACK_FROM_ISR ( ( BaseType_t ) -2 )
\r
55 #define tmrCOMMAND_EXECUTE_CALLBACK ( ( BaseType_t ) -1 )
\r
56 #define tmrCOMMAND_START_DONT_TRACE ( ( BaseType_t ) 0 )
\r
57 #define tmrCOMMAND_START ( ( BaseType_t ) 1 )
\r
58 #define tmrCOMMAND_RESET ( ( BaseType_t ) 2 )
\r
59 #define tmrCOMMAND_STOP ( ( BaseType_t ) 3 )
\r
60 #define tmrCOMMAND_CHANGE_PERIOD ( ( BaseType_t ) 4 )
\r
61 #define tmrCOMMAND_DELETE ( ( BaseType_t ) 5 )
\r
63 #define tmrFIRST_FROM_ISR_COMMAND ( ( BaseType_t ) 6 )
\r
64 #define tmrCOMMAND_START_FROM_ISR ( ( BaseType_t ) 6 )
\r
65 #define tmrCOMMAND_RESET_FROM_ISR ( ( BaseType_t ) 7 )
\r
66 #define tmrCOMMAND_STOP_FROM_ISR ( ( BaseType_t ) 8 )
\r
67 #define tmrCOMMAND_CHANGE_PERIOD_FROM_ISR ( ( BaseType_t ) 9 )
\r
71 * Type by which software timers are referenced. For example, a call to
\r
72 * xTimerCreate() returns an TimerHandle_t variable that can then be used to
\r
73 * reference the subject timer in calls to other software timer API functions
\r
74 * (for example, xTimerStart(), xTimerReset(), etc.).
\r
76 struct tmrTimerControl; /* The old naming convention is used to prevent breaking kernel aware debuggers. */
\r
77 typedef struct tmrTimerControl * TimerHandle_t;
\r
80 * Defines the prototype to which timer callback functions must conform.
\r
82 typedef void (* TimerCallbackFunction_t)( TimerHandle_t xTimer );
\r
85 * Defines the prototype to which functions used with the
\r
86 * xTimerPendFunctionCallFromISR() function must conform.
\r
88 typedef void (* PendedFunction_t)( void *,
\r
92 * TimerHandle_t xTimerCreate( const char * const pcTimerName,
\r
93 * TickType_t xTimerPeriodInTicks,
\r
94 * UBaseType_t uxAutoReload,
\r
96 * TimerCallbackFunction_t pxCallbackFunction );
\r
98 * Creates a new software timer instance, and returns a handle by which the
\r
99 * created software timer can be referenced.
\r
101 * Internally, within the FreeRTOS implementation, software timers use a block
\r
102 * of memory, in which the timer data structure is stored. If a software timer
\r
103 * is created using xTimerCreate() then the required memory is automatically
\r
104 * dynamically allocated inside the xTimerCreate() function. (see
\r
105 * http://www.freertos.org/a00111.html). If a software timer is created using
\r
106 * xTimerCreateStatic() then the application writer must provide the memory that
\r
107 * will get used by the software timer. xTimerCreateStatic() therefore allows a
\r
108 * software timer to be created without using any dynamic memory allocation.
\r
110 * Timers are created in the dormant state. The xTimerStart(), xTimerReset(),
\r
111 * xTimerStartFromISR(), xTimerResetFromISR(), xTimerChangePeriod() and
\r
112 * xTimerChangePeriodFromISR() API functions can all be used to transition a
\r
113 * timer into the active state.
\r
115 * @param pcTimerName A text name that is assigned to the timer. This is done
\r
116 * purely to assist debugging. The kernel itself only ever references a timer
\r
117 * by its handle, and never by its name.
\r
119 * @param xTimerPeriodInTicks The timer period. The time is defined in tick
\r
120 * periods so the constant portTICK_PERIOD_MS can be used to convert a time that
\r
121 * has been specified in milliseconds. For example, if the timer must expire
\r
122 * after 100 ticks, then xTimerPeriodInTicks should be set to 100.
\r
123 * Alternatively, if the timer must expire after 500ms, then xPeriod can be set
\r
124 * to ( 500 / portTICK_PERIOD_MS ) provided configTICK_RATE_HZ is less than or
\r
125 * equal to 1000. Time timer period must be greater than 0.
\r
127 * @param uxAutoReload If uxAutoReload is set to pdTRUE then the timer will
\r
128 * expire repeatedly with a frequency set by the xTimerPeriodInTicks parameter.
\r
129 * If uxAutoReload is set to pdFALSE then the timer will be a one-shot timer and
\r
130 * enter the dormant state after it expires.
\r
132 * @param pvTimerID An identifier that is assigned to the timer being created.
\r
133 * Typically this would be used in the timer callback function to identify which
\r
134 * timer expired when the same callback function is assigned to more than one
\r
137 * @param pxCallbackFunction The function to call when the timer expires.
\r
138 * Callback functions must have the prototype defined by TimerCallbackFunction_t,
\r
139 * which is "void vCallbackFunction( TimerHandle_t xTimer );".
\r
141 * @return If the timer is successfully created then a handle to the newly
\r
142 * created timer is returned. If the timer cannot be created because there is
\r
143 * insufficient FreeRTOS heap remaining to allocate the timer
\r
144 * structures then NULL is returned.
\r
148 * #define NUM_TIMERS 5
\r
150 * // An array to hold handles to the created timers.
\r
151 * TimerHandle_t xTimers[ NUM_TIMERS ];
\r
153 * // An array to hold a count of the number of times each timer expires.
\r
154 * int32_t lExpireCounters[ NUM_TIMERS ] = { 0 };
\r
156 * // Define a callback function that will be used by multiple timer instances.
\r
157 * // The callback function does nothing but count the number of times the
\r
158 * // associated timer expires, and stop the timer once the timer has expired
\r
160 * void vTimerCallback( TimerHandle_t pxTimer )
\r
162 * int32_t lArrayIndex;
\r
163 * const int32_t xMaxExpiryCountBeforeStopping = 10;
\r
165 * // Optionally do something if the pxTimer parameter is NULL.
\r
166 * configASSERT( pxTimer );
\r
168 * // Which timer expired?
\r
169 * lArrayIndex = ( int32_t ) pvTimerGetTimerID( pxTimer );
\r
171 * // Increment the number of times that pxTimer has expired.
\r
172 * lExpireCounters[ lArrayIndex ] += 1;
\r
174 * // If the timer has expired 10 times then stop it from running.
\r
175 * if( lExpireCounters[ lArrayIndex ] == xMaxExpiryCountBeforeStopping )
\r
177 * // Do not use a block time if calling a timer API function from a
\r
178 * // timer callback function, as doing so could cause a deadlock!
\r
179 * xTimerStop( pxTimer, 0 );
\r
183 * void main( void )
\r
187 * // Create then start some timers. Starting the timers before the scheduler
\r
188 * // has been started means the timers will start running immediately that
\r
189 * // the scheduler starts.
\r
190 * for( x = 0; x < NUM_TIMERS; x++ )
\r
192 * xTimers[ x ] = xTimerCreate( "Timer", // Just a text name, not used by the kernel.
\r
193 * ( 100 * x ), // The timer period in ticks.
\r
194 * pdTRUE, // The timers will auto-reload themselves when they expire.
\r
195 * ( void * ) x, // Assign each timer a unique id equal to its array index.
\r
196 * vTimerCallback // Each timer calls the same callback when it expires.
\r
199 * if( xTimers[ x ] == NULL )
\r
201 * // The timer was not created.
\r
205 * // Start the timer. No block time is specified, and even if one was
\r
206 * // it would be ignored because the scheduler has not yet been
\r
208 * if( xTimerStart( xTimers[ x ], 0 ) != pdPASS )
\r
210 * // The timer could not be set into the Active state.
\r
216 * // Create tasks here.
\r
219 * // Starting the scheduler will start the timers running as they have already
\r
220 * // been set into the active state.
\r
221 * vTaskStartScheduler();
\r
223 * // Should not reach here.
\r
228 #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
\r
229 TimerHandle_t xTimerCreate( const char * const pcTimerName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
\r
230 const TickType_t xTimerPeriodInTicks,
\r
231 const UBaseType_t uxAutoReload,
\r
232 void * const pvTimerID,
\r
233 TimerCallbackFunction_t pxCallbackFunction ) PRIVILEGED_FUNCTION;
\r
237 * TimerHandle_t xTimerCreateStatic(const char * const pcTimerName,
\r
238 * TickType_t xTimerPeriodInTicks,
\r
239 * UBaseType_t uxAutoReload,
\r
240 * void * pvTimerID,
\r
241 * TimerCallbackFunction_t pxCallbackFunction,
\r
242 * StaticTimer_t *pxTimerBuffer );
\r
244 * Creates a new software timer instance, and returns a handle by which the
\r
245 * created software timer can be referenced.
\r
247 * Internally, within the FreeRTOS implementation, software timers use a block
\r
248 * of memory, in which the timer data structure is stored. If a software timer
\r
249 * is created using xTimerCreate() then the required memory is automatically
\r
250 * dynamically allocated inside the xTimerCreate() function. (see
\r
251 * http://www.freertos.org/a00111.html). If a software timer is created using
\r
252 * xTimerCreateStatic() then the application writer must provide the memory that
\r
253 * will get used by the software timer. xTimerCreateStatic() therefore allows a
\r
254 * software timer to be created without using any dynamic memory allocation.
\r
256 * Timers are created in the dormant state. The xTimerStart(), xTimerReset(),
\r
257 * xTimerStartFromISR(), xTimerResetFromISR(), xTimerChangePeriod() and
\r
258 * xTimerChangePeriodFromISR() API functions can all be used to transition a
\r
259 * timer into the active state.
\r
261 * @param pcTimerName A text name that is assigned to the timer. This is done
\r
262 * purely to assist debugging. The kernel itself only ever references a timer
\r
263 * by its handle, and never by its name.
\r
265 * @param xTimerPeriodInTicks The timer period. The time is defined in tick
\r
266 * periods so the constant portTICK_PERIOD_MS can be used to convert a time that
\r
267 * has been specified in milliseconds. For example, if the timer must expire
\r
268 * after 100 ticks, then xTimerPeriodInTicks should be set to 100.
\r
269 * Alternatively, if the timer must expire after 500ms, then xPeriod can be set
\r
270 * to ( 500 / portTICK_PERIOD_MS ) provided configTICK_RATE_HZ is less than or
\r
271 * equal to 1000. The timer period must be greater than 0.
\r
273 * @param uxAutoReload If uxAutoReload is set to pdTRUE then the timer will
\r
274 * expire repeatedly with a frequency set by the xTimerPeriodInTicks parameter.
\r
275 * If uxAutoReload is set to pdFALSE then the timer will be a one-shot timer and
\r
276 * enter the dormant state after it expires.
\r
278 * @param pvTimerID An identifier that is assigned to the timer being created.
\r
279 * Typically this would be used in the timer callback function to identify which
\r
280 * timer expired when the same callback function is assigned to more than one
\r
283 * @param pxCallbackFunction The function to call when the timer expires.
\r
284 * Callback functions must have the prototype defined by TimerCallbackFunction_t,
\r
285 * which is "void vCallbackFunction( TimerHandle_t xTimer );".
\r
287 * @param pxTimerBuffer Must point to a variable of type StaticTimer_t, which
\r
288 * will be then be used to hold the software timer's data structures, removing
\r
289 * the need for the memory to be allocated dynamically.
\r
291 * @return If the timer is created then a handle to the created timer is
\r
292 * returned. If pxTimerBuffer was NULL then NULL is returned.
\r
297 * // The buffer used to hold the software timer's data structure.
\r
298 * static StaticTimer_t xTimerBuffer;
\r
300 * // A variable that will be incremented by the software timer's callback
\r
302 * UBaseType_t uxVariableToIncrement = 0;
\r
304 * // A software timer callback function that increments a variable passed to
\r
305 * // it when the software timer was created. After the 5th increment the
\r
306 * // callback function stops the software timer.
\r
307 * static void prvTimerCallback( TimerHandle_t xExpiredTimer )
\r
309 * UBaseType_t *puxVariableToIncrement;
\r
310 * BaseType_t xReturned;
\r
312 * // Obtain the address of the variable to increment from the timer ID.
\r
313 * puxVariableToIncrement = ( UBaseType_t * ) pvTimerGetTimerID( xExpiredTimer );
\r
315 * // Increment the variable to show the timer callback has executed.
\r
316 * ( *puxVariableToIncrement )++;
\r
318 * // If this callback has executed the required number of times, stop the
\r
320 * if( *puxVariableToIncrement == 5 )
\r
322 * // This is called from a timer callback so must not block.
\r
323 * xTimerStop( xExpiredTimer, staticDONT_BLOCK );
\r
328 * void main( void )
\r
330 * // Create the software time. xTimerCreateStatic() has an extra parameter
\r
331 * // than the normal xTimerCreate() API function. The parameter is a pointer
\r
332 * // to the StaticTimer_t structure that will hold the software timer
\r
333 * // structure. If the parameter is passed as NULL then the structure will be
\r
334 * // allocated dynamically, just as if xTimerCreate() had been called.
\r
335 * xTimer = xTimerCreateStatic( "T1", // Text name for the task. Helps debugging only. Not used by FreeRTOS.
\r
336 * xTimerPeriod, // The period of the timer in ticks.
\r
337 * pdTRUE, // This is an auto-reload timer.
\r
338 * ( void * ) &uxVariableToIncrement, // A variable incremented by the software timer's callback function
\r
339 * prvTimerCallback, // The function to execute when the timer expires.
\r
340 * &xTimerBuffer ); // The buffer that will hold the software timer structure.
\r
342 * // The scheduler has not started yet so a block time is not used.
\r
343 * xReturned = xTimerStart( xTimer, 0 );
\r
346 * // Create tasks here.
\r
349 * // Starting the scheduler will start the timers running as they have already
\r
350 * // been set into the active state.
\r
351 * vTaskStartScheduler();
\r
353 * // Should not reach here.
\r
358 #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
\r
359 TimerHandle_t xTimerCreateStatic( const char * const pcTimerName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
\r
360 const TickType_t xTimerPeriodInTicks,
\r
361 const UBaseType_t uxAutoReload,
\r
362 void * const pvTimerID,
\r
363 TimerCallbackFunction_t pxCallbackFunction,
\r
364 StaticTimer_t * pxTimerBuffer ) PRIVILEGED_FUNCTION;
\r
365 #endif /* configSUPPORT_STATIC_ALLOCATION */
\r
368 * void *pvTimerGetTimerID( TimerHandle_t xTimer );
\r
370 * Returns the ID assigned to the timer.
\r
372 * IDs are assigned to timers using the pvTimerID parameter of the call to
\r
373 * xTimerCreated() that was used to create the timer, and by calling the
\r
374 * vTimerSetTimerID() API function.
\r
376 * If the same callback function is assigned to multiple timers then the timer
\r
377 * ID can be used as time specific (timer local) storage.
\r
379 * @param xTimer The timer being queried.
\r
381 * @return The ID assigned to the timer being queried.
\r
385 * See the xTimerCreate() API function example usage scenario.
\r
387 void * pvTimerGetTimerID( const TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
\r
390 * void vTimerSetTimerID( TimerHandle_t xTimer, void *pvNewID );
\r
392 * Sets the ID assigned to the timer.
\r
394 * IDs are assigned to timers using the pvTimerID parameter of the call to
\r
395 * xTimerCreated() that was used to create the timer.
\r
397 * If the same callback function is assigned to multiple timers then the timer
\r
398 * ID can be used as time specific (timer local) storage.
\r
400 * @param xTimer The timer being updated.
\r
402 * @param pvNewID The ID to assign to the timer.
\r
406 * See the xTimerCreate() API function example usage scenario.
\r
408 void vTimerSetTimerID( TimerHandle_t xTimer,
\r
409 void * pvNewID ) PRIVILEGED_FUNCTION;
\r
412 * BaseType_t xTimerIsTimerActive( TimerHandle_t xTimer );
\r
414 * Queries a timer to see if it is active or dormant.
\r
416 * A timer will be dormant if:
\r
417 * 1) It has been created but not started, or
\r
418 * 2) It is an expired one-shot timer that has not been restarted.
\r
420 * Timers are created in the dormant state. The xTimerStart(), xTimerReset(),
\r
421 * xTimerStartFromISR(), xTimerResetFromISR(), xTimerChangePeriod() and
\r
422 * xTimerChangePeriodFromISR() API functions can all be used to transition a timer into the
\r
425 * @param xTimer The timer being queried.
\r
427 * @return pdFALSE will be returned if the timer is dormant. A value other than
\r
428 * pdFALSE will be returned if the timer is active.
\r
432 * // This function assumes xTimer has already been created.
\r
433 * void vAFunction( TimerHandle_t xTimer )
\r
435 * if( xTimerIsTimerActive( xTimer ) != pdFALSE ) // or more simply and equivalently "if( xTimerIsTimerActive( xTimer ) )"
\r
437 * // xTimer is active, do something.
\r
441 * // xTimer is not active, do something else.
\r
446 BaseType_t xTimerIsTimerActive( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
\r
449 * TaskHandle_t xTimerGetTimerDaemonTaskHandle( void );
\r
451 * Simply returns the handle of the timer service/daemon task. It it not valid
\r
452 * to call xTimerGetTimerDaemonTaskHandle() before the scheduler has been started.
\r
454 TaskHandle_t xTimerGetTimerDaemonTaskHandle( void ) PRIVILEGED_FUNCTION;
\r
457 * BaseType_t xTimerStart( TimerHandle_t xTimer, TickType_t xTicksToWait );
\r
459 * Timer functionality is provided by a timer service/daemon task. Many of the
\r
460 * public FreeRTOS timer API functions send commands to the timer service task
\r
461 * through a queue called the timer command queue. The timer command queue is
\r
462 * private to the kernel itself and is not directly accessible to application
\r
463 * code. The length of the timer command queue is set by the
\r
464 * configTIMER_QUEUE_LENGTH configuration constant.
\r
466 * xTimerStart() starts a timer that was previously created using the
\r
467 * xTimerCreate() API function. If the timer had already been started and was
\r
468 * already in the active state, then xTimerStart() has equivalent functionality
\r
469 * to the xTimerReset() API function.
\r
471 * Starting a timer ensures the timer is in the active state. If the timer
\r
472 * is not stopped, deleted, or reset in the mean time, the callback function
\r
473 * associated with the timer will get called 'n' ticks after xTimerStart() was
\r
474 * called, where 'n' is the timers defined period.
\r
476 * It is valid to call xTimerStart() before the scheduler has been started, but
\r
477 * when this is done the timer will not actually start until the scheduler is
\r
478 * started, and the timers expiry time will be relative to when the scheduler is
\r
479 * started, not relative to when xTimerStart() was called.
\r
481 * The configUSE_TIMERS configuration constant must be set to 1 for xTimerStart()
\r
484 * @param xTimer The handle of the timer being started/restarted.
\r
486 * @param xTicksToWait Specifies the time, in ticks, that the calling task should
\r
487 * be held in the Blocked state to wait for the start command to be successfully
\r
488 * sent to the timer command queue, should the queue already be full when
\r
489 * xTimerStart() was called. xTicksToWait is ignored if xTimerStart() is called
\r
490 * before the scheduler is started.
\r
492 * @return pdFAIL will be returned if the start command could not be sent to
\r
493 * the timer command queue even after xTicksToWait ticks had passed. pdPASS will
\r
494 * be returned if the command was successfully sent to the timer command queue.
\r
495 * When the command is actually processed will depend on the priority of the
\r
496 * timer service/daemon task relative to other tasks in the system, although the
\r
497 * timers expiry time is relative to when xTimerStart() is actually called. The
\r
498 * timer service/daemon task priority is set by the configTIMER_TASK_PRIORITY
\r
499 * configuration constant.
\r
503 * See the xTimerCreate() API function example usage scenario.
\r
506 #define xTimerStart( xTimer, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_START, ( xTaskGetTickCount() ), NULL, ( xTicksToWait ) )
\r
509 * BaseType_t xTimerStop( TimerHandle_t xTimer, TickType_t xTicksToWait );
\r
511 * Timer functionality is provided by a timer service/daemon task. Many of the
\r
512 * public FreeRTOS timer API functions send commands to the timer service task
\r
513 * through a queue called the timer command queue. The timer command queue is
\r
514 * private to the kernel itself and is not directly accessible to application
\r
515 * code. The length of the timer command queue is set by the
\r
516 * configTIMER_QUEUE_LENGTH configuration constant.
\r
518 * xTimerStop() stops a timer that was previously started using either of the
\r
519 * The xTimerStart(), xTimerReset(), xTimerStartFromISR(), xTimerResetFromISR(),
\r
520 * xTimerChangePeriod() or xTimerChangePeriodFromISR() API functions.
\r
522 * Stopping a timer ensures the timer is not in the active state.
\r
524 * The configUSE_TIMERS configuration constant must be set to 1 for xTimerStop()
\r
527 * @param xTimer The handle of the timer being stopped.
\r
529 * @param xTicksToWait Specifies the time, in ticks, that the calling task should
\r
530 * be held in the Blocked state to wait for the stop command to be successfully
\r
531 * sent to the timer command queue, should the queue already be full when
\r
532 * xTimerStop() was called. xTicksToWait is ignored if xTimerStop() is called
\r
533 * before the scheduler is started.
\r
535 * @return pdFAIL will be returned if the stop command could not be sent to
\r
536 * the timer command queue even after xTicksToWait ticks had passed. pdPASS will
\r
537 * be returned if the command was successfully sent to the timer command queue.
\r
538 * When the command is actually processed will depend on the priority of the
\r
539 * timer service/daemon task relative to other tasks in the system. The timer
\r
540 * service/daemon task priority is set by the configTIMER_TASK_PRIORITY
\r
541 * configuration constant.
\r
545 * See the xTimerCreate() API function example usage scenario.
\r
548 #define xTimerStop( xTimer, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_STOP, 0U, NULL, ( xTicksToWait ) )
\r
551 * BaseType_t xTimerChangePeriod( TimerHandle_t xTimer,
\r
552 * TickType_t xNewPeriod,
\r
553 * TickType_t xTicksToWait );
\r
555 * Timer functionality is provided by a timer service/daemon task. Many of the
\r
556 * public FreeRTOS timer API functions send commands to the timer service task
\r
557 * through a queue called the timer command queue. The timer command queue is
\r
558 * private to the kernel itself and is not directly accessible to application
\r
559 * code. The length of the timer command queue is set by the
\r
560 * configTIMER_QUEUE_LENGTH configuration constant.
\r
562 * xTimerChangePeriod() changes the period of a timer that was previously
\r
563 * created using the xTimerCreate() API function.
\r
565 * xTimerChangePeriod() can be called to change the period of an active or
\r
566 * dormant state timer.
\r
568 * The configUSE_TIMERS configuration constant must be set to 1 for
\r
569 * xTimerChangePeriod() to be available.
\r
571 * @param xTimer The handle of the timer that is having its period changed.
\r
573 * @param xNewPeriod The new period for xTimer. Timer periods are specified in
\r
574 * tick periods, so the constant portTICK_PERIOD_MS can be used to convert a time
\r
575 * that has been specified in milliseconds. For example, if the timer must
\r
576 * expire after 100 ticks, then xNewPeriod should be set to 100. Alternatively,
\r
577 * if the timer must expire after 500ms, then xNewPeriod can be set to
\r
578 * ( 500 / portTICK_PERIOD_MS ) provided configTICK_RATE_HZ is less than
\r
579 * or equal to 1000.
\r
581 * @param xTicksToWait Specifies the time, in ticks, that the calling task should
\r
582 * be held in the Blocked state to wait for the change period command to be
\r
583 * successfully sent to the timer command queue, should the queue already be
\r
584 * full when xTimerChangePeriod() was called. xTicksToWait is ignored if
\r
585 * xTimerChangePeriod() is called before the scheduler is started.
\r
587 * @return pdFAIL will be returned if the change period command could not be
\r
588 * sent to the timer command queue even after xTicksToWait ticks had passed.
\r
589 * pdPASS will be returned if the command was successfully sent to the timer
\r
590 * command queue. When the command is actually processed will depend on the
\r
591 * priority of the timer service/daemon task relative to other tasks in the
\r
592 * system. The timer service/daemon task priority is set by the
\r
593 * configTIMER_TASK_PRIORITY configuration constant.
\r
597 * // This function assumes xTimer has already been created. If the timer
\r
598 * // referenced by xTimer is already active when it is called, then the timer
\r
599 * // is deleted. If the timer referenced by xTimer is not active when it is
\r
600 * // called, then the period of the timer is set to 500ms and the timer is
\r
602 * void vAFunction( TimerHandle_t xTimer )
\r
604 * if( xTimerIsTimerActive( xTimer ) != pdFALSE ) // or more simply and equivalently "if( xTimerIsTimerActive( xTimer ) )"
\r
606 * // xTimer is already active - delete it.
\r
607 * xTimerDelete( xTimer );
\r
611 * // xTimer is not active, change its period to 500ms. This will also
\r
612 * // cause the timer to start. Block for a maximum of 100 ticks if the
\r
613 * // change period command cannot immediately be sent to the timer
\r
614 * // command queue.
\r
615 * if( xTimerChangePeriod( xTimer, 500 / portTICK_PERIOD_MS, 100 ) == pdPASS )
\r
617 * // The command was successfully sent.
\r
621 * // The command could not be sent, even after waiting for 100 ticks
\r
622 * // to pass. Take appropriate action here.
\r
628 #define xTimerChangePeriod( xTimer, xNewPeriod, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_CHANGE_PERIOD, ( xNewPeriod ), NULL, ( xTicksToWait ) )
\r
631 * BaseType_t xTimerDelete( TimerHandle_t xTimer, TickType_t xTicksToWait );
\r
633 * Timer functionality is provided by a timer service/daemon task. Many of the
\r
634 * public FreeRTOS timer API functions send commands to the timer service task
\r
635 * through a queue called the timer command queue. The timer command queue is
\r
636 * private to the kernel itself and is not directly accessible to application
\r
637 * code. The length of the timer command queue is set by the
\r
638 * configTIMER_QUEUE_LENGTH configuration constant.
\r
640 * xTimerDelete() deletes a timer that was previously created using the
\r
641 * xTimerCreate() API function.
\r
643 * The configUSE_TIMERS configuration constant must be set to 1 for
\r
644 * xTimerDelete() to be available.
\r
646 * @param xTimer The handle of the timer being deleted.
\r
648 * @param xTicksToWait Specifies the time, in ticks, that the calling task should
\r
649 * be held in the Blocked state to wait for the delete command to be
\r
650 * successfully sent to the timer command queue, should the queue already be
\r
651 * full when xTimerDelete() was called. xTicksToWait is ignored if xTimerDelete()
\r
652 * is called before the scheduler is started.
\r
654 * @return pdFAIL will be returned if the delete command could not be sent to
\r
655 * the timer command queue even after xTicksToWait ticks had passed. pdPASS will
\r
656 * be returned if the command was successfully sent to the timer command queue.
\r
657 * When the command is actually processed will depend on the priority of the
\r
658 * timer service/daemon task relative to other tasks in the system. The timer
\r
659 * service/daemon task priority is set by the configTIMER_TASK_PRIORITY
\r
660 * configuration constant.
\r
664 * See the xTimerChangePeriod() API function example usage scenario.
\r
666 #define xTimerDelete( xTimer, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_DELETE, 0U, NULL, ( xTicksToWait ) )
\r
669 * BaseType_t xTimerReset( TimerHandle_t xTimer, TickType_t xTicksToWait );
\r
671 * Timer functionality is provided by a timer service/daemon task. Many of the
\r
672 * public FreeRTOS timer API functions send commands to the timer service task
\r
673 * through a queue called the timer command queue. The timer command queue is
\r
674 * private to the kernel itself and is not directly accessible to application
\r
675 * code. The length of the timer command queue is set by the
\r
676 * configTIMER_QUEUE_LENGTH configuration constant.
\r
678 * xTimerReset() re-starts a timer that was previously created using the
\r
679 * xTimerCreate() API function. If the timer had already been started and was
\r
680 * already in the active state, then xTimerReset() will cause the timer to
\r
681 * re-evaluate its expiry time so that it is relative to when xTimerReset() was
\r
682 * called. If the timer was in the dormant state then xTimerReset() has
\r
683 * equivalent functionality to the xTimerStart() API function.
\r
685 * Resetting a timer ensures the timer is in the active state. If the timer
\r
686 * is not stopped, deleted, or reset in the mean time, the callback function
\r
687 * associated with the timer will get called 'n' ticks after xTimerReset() was
\r
688 * called, where 'n' is the timers defined period.
\r
690 * It is valid to call xTimerReset() before the scheduler has been started, but
\r
691 * when this is done the timer will not actually start until the scheduler is
\r
692 * started, and the timers expiry time will be relative to when the scheduler is
\r
693 * started, not relative to when xTimerReset() was called.
\r
695 * The configUSE_TIMERS configuration constant must be set to 1 for xTimerReset()
\r
698 * @param xTimer The handle of the timer being reset/started/restarted.
\r
700 * @param xTicksToWait Specifies the time, in ticks, that the calling task should
\r
701 * be held in the Blocked state to wait for the reset command to be successfully
\r
702 * sent to the timer command queue, should the queue already be full when
\r
703 * xTimerReset() was called. xTicksToWait is ignored if xTimerReset() is called
\r
704 * before the scheduler is started.
\r
706 * @return pdFAIL will be returned if the reset command could not be sent to
\r
707 * the timer command queue even after xTicksToWait ticks had passed. pdPASS will
\r
708 * be returned if the command was successfully sent to the timer command queue.
\r
709 * When the command is actually processed will depend on the priority of the
\r
710 * timer service/daemon task relative to other tasks in the system, although the
\r
711 * timers expiry time is relative to when xTimerStart() is actually called. The
\r
712 * timer service/daemon task priority is set by the configTIMER_TASK_PRIORITY
\r
713 * configuration constant.
\r
717 * // When a key is pressed, an LCD back-light is switched on. If 5 seconds pass
\r
718 * // without a key being pressed, then the LCD back-light is switched off. In
\r
719 * // this case, the timer is a one-shot timer.
\r
721 * TimerHandle_t xBacklightTimer = NULL;
\r
723 * // The callback function assigned to the one-shot timer. In this case the
\r
724 * // parameter is not used.
\r
725 * void vBacklightTimerCallback( TimerHandle_t pxTimer )
\r
727 * // The timer expired, therefore 5 seconds must have passed since a key
\r
728 * // was pressed. Switch off the LCD back-light.
\r
729 * vSetBacklightState( BACKLIGHT_OFF );
\r
732 * // The key press event handler.
\r
733 * void vKeyPressEventHandler( char cKey )
\r
735 * // Ensure the LCD back-light is on, then reset the timer that is
\r
736 * // responsible for turning the back-light off after 5 seconds of
\r
737 * // key inactivity. Wait 10 ticks for the command to be successfully sent
\r
738 * // if it cannot be sent immediately.
\r
739 * vSetBacklightState( BACKLIGHT_ON );
\r
740 * if( xTimerReset( xBacklightTimer, 100 ) != pdPASS )
\r
742 * // The reset command was not executed successfully. Take appropriate
\r
746 * // Perform the rest of the key processing here.
\r
749 * void main( void )
\r
753 * // Create then start the one-shot timer that is responsible for turning
\r
754 * // the back-light off if no keys are pressed within a 5 second period.
\r
755 * xBacklightTimer = xTimerCreate( "BacklightTimer", // Just a text name, not used by the kernel.
\r
756 * ( 5000 / portTICK_PERIOD_MS), // The timer period in ticks.
\r
757 * pdFALSE, // The timer is a one-shot timer.
\r
758 * 0, // The id is not used by the callback so can take any value.
\r
759 * vBacklightTimerCallback // The callback function that switches the LCD back-light off.
\r
762 * if( xBacklightTimer == NULL )
\r
764 * // The timer was not created.
\r
768 * // Start the timer. No block time is specified, and even if one was
\r
769 * // it would be ignored because the scheduler has not yet been
\r
771 * if( xTimerStart( xBacklightTimer, 0 ) != pdPASS )
\r
773 * // The timer could not be set into the Active state.
\r
778 * // Create tasks here.
\r
781 * // Starting the scheduler will start the timer running as it has already
\r
782 * // been set into the active state.
\r
783 * vTaskStartScheduler();
\r
785 * // Should not reach here.
\r
790 #define xTimerReset( xTimer, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_RESET, ( xTaskGetTickCount() ), NULL, ( xTicksToWait ) )
\r
793 * BaseType_t xTimerStartFromISR( TimerHandle_t xTimer,
\r
794 * BaseType_t *pxHigherPriorityTaskWoken );
\r
796 * A version of xTimerStart() that can be called from an interrupt service
\r
799 * @param xTimer The handle of the timer being started/restarted.
\r
801 * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most
\r
802 * of its time in the Blocked state, waiting for messages to arrive on the timer
\r
803 * command queue. Calling xTimerStartFromISR() writes a message to the timer
\r
804 * command queue, so has the potential to transition the timer service/daemon
\r
805 * task out of the Blocked state. If calling xTimerStartFromISR() causes the
\r
806 * timer service/daemon task to leave the Blocked state, and the timer service/
\r
807 * daemon task has a priority equal to or greater than the currently executing
\r
808 * task (the task that was interrupted), then *pxHigherPriorityTaskWoken will
\r
809 * get set to pdTRUE internally within the xTimerStartFromISR() function. If
\r
810 * xTimerStartFromISR() sets this value to pdTRUE then a context switch should
\r
811 * be performed before the interrupt exits.
\r
813 * @return pdFAIL will be returned if the start command could not be sent to
\r
814 * the timer command queue. pdPASS will be returned if the command was
\r
815 * successfully sent to the timer command queue. When the command is actually
\r
816 * processed will depend on the priority of the timer service/daemon task
\r
817 * relative to other tasks in the system, although the timers expiry time is
\r
818 * relative to when xTimerStartFromISR() is actually called. The timer
\r
819 * service/daemon task priority is set by the configTIMER_TASK_PRIORITY
\r
820 * configuration constant.
\r
824 * // This scenario assumes xBacklightTimer has already been created. When a
\r
825 * // key is pressed, an LCD back-light is switched on. If 5 seconds pass
\r
826 * // without a key being pressed, then the LCD back-light is switched off. In
\r
827 * // this case, the timer is a one-shot timer, and unlike the example given for
\r
828 * // the xTimerReset() function, the key press event handler is an interrupt
\r
829 * // service routine.
\r
831 * // The callback function assigned to the one-shot timer. In this case the
\r
832 * // parameter is not used.
\r
833 * void vBacklightTimerCallback( TimerHandle_t pxTimer )
\r
835 * // The timer expired, therefore 5 seconds must have passed since a key
\r
836 * // was pressed. Switch off the LCD back-light.
\r
837 * vSetBacklightState( BACKLIGHT_OFF );
\r
840 * // The key press interrupt service routine.
\r
841 * void vKeyPressEventInterruptHandler( void )
\r
843 * BaseType_t xHigherPriorityTaskWoken = pdFALSE;
\r
845 * // Ensure the LCD back-light is on, then restart the timer that is
\r
846 * // responsible for turning the back-light off after 5 seconds of
\r
847 * // key inactivity. This is an interrupt service routine so can only
\r
848 * // call FreeRTOS API functions that end in "FromISR".
\r
849 * vSetBacklightState( BACKLIGHT_ON );
\r
851 * // xTimerStartFromISR() or xTimerResetFromISR() could be called here
\r
852 * // as both cause the timer to re-calculate its expiry time.
\r
853 * // xHigherPriorityTaskWoken was initialised to pdFALSE when it was
\r
854 * // declared (in this function).
\r
855 * if( xTimerStartFromISR( xBacklightTimer, &xHigherPriorityTaskWoken ) != pdPASS )
\r
857 * // The start command was not executed successfully. Take appropriate
\r
861 * // Perform the rest of the key processing here.
\r
863 * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch
\r
864 * // should be performed. The syntax required to perform a context switch
\r
865 * // from inside an ISR varies from port to port, and from compiler to
\r
866 * // compiler. Inspect the demos for the port you are using to find the
\r
867 * // actual syntax required.
\r
868 * if( xHigherPriorityTaskWoken != pdFALSE )
\r
870 * // Call the interrupt safe yield function here (actual function
\r
871 * // depends on the FreeRTOS port being used).
\r
876 #define xTimerStartFromISR( xTimer, pxHigherPriorityTaskWoken ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_START_FROM_ISR, ( xTaskGetTickCountFromISR() ), ( pxHigherPriorityTaskWoken ), 0U )
\r
879 * BaseType_t xTimerStopFromISR( TimerHandle_t xTimer,
\r
880 * BaseType_t *pxHigherPriorityTaskWoken );
\r
882 * A version of xTimerStop() that can be called from an interrupt service
\r
885 * @param xTimer The handle of the timer being stopped.
\r
887 * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most
\r
888 * of its time in the Blocked state, waiting for messages to arrive on the timer
\r
889 * command queue. Calling xTimerStopFromISR() writes a message to the timer
\r
890 * command queue, so has the potential to transition the timer service/daemon
\r
891 * task out of the Blocked state. If calling xTimerStopFromISR() causes the
\r
892 * timer service/daemon task to leave the Blocked state, and the timer service/
\r
893 * daemon task has a priority equal to or greater than the currently executing
\r
894 * task (the task that was interrupted), then *pxHigherPriorityTaskWoken will
\r
895 * get set to pdTRUE internally within the xTimerStopFromISR() function. If
\r
896 * xTimerStopFromISR() sets this value to pdTRUE then a context switch should
\r
897 * be performed before the interrupt exits.
\r
899 * @return pdFAIL will be returned if the stop command could not be sent to
\r
900 * the timer command queue. pdPASS will be returned if the command was
\r
901 * successfully sent to the timer command queue. When the command is actually
\r
902 * processed will depend on the priority of the timer service/daemon task
\r
903 * relative to other tasks in the system. The timer service/daemon task
\r
904 * priority is set by the configTIMER_TASK_PRIORITY configuration constant.
\r
908 * // This scenario assumes xTimer has already been created and started. When
\r
909 * // an interrupt occurs, the timer should be simply stopped.
\r
911 * // The interrupt service routine that stops the timer.
\r
912 * void vAnExampleInterruptServiceRoutine( void )
\r
914 * BaseType_t xHigherPriorityTaskWoken = pdFALSE;
\r
916 * // The interrupt has occurred - simply stop the timer.
\r
917 * // xHigherPriorityTaskWoken was set to pdFALSE where it was defined
\r
918 * // (within this function). As this is an interrupt service routine, only
\r
919 * // FreeRTOS API functions that end in "FromISR" can be used.
\r
920 * if( xTimerStopFromISR( xTimer, &xHigherPriorityTaskWoken ) != pdPASS )
\r
922 * // The stop command was not executed successfully. Take appropriate
\r
926 * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch
\r
927 * // should be performed. The syntax required to perform a context switch
\r
928 * // from inside an ISR varies from port to port, and from compiler to
\r
929 * // compiler. Inspect the demos for the port you are using to find the
\r
930 * // actual syntax required.
\r
931 * if( xHigherPriorityTaskWoken != pdFALSE )
\r
933 * // Call the interrupt safe yield function here (actual function
\r
934 * // depends on the FreeRTOS port being used).
\r
939 #define xTimerStopFromISR( xTimer, pxHigherPriorityTaskWoken ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_STOP_FROM_ISR, 0, ( pxHigherPriorityTaskWoken ), 0U )
\r
942 * BaseType_t xTimerChangePeriodFromISR( TimerHandle_t xTimer,
\r
943 * TickType_t xNewPeriod,
\r
944 * BaseType_t *pxHigherPriorityTaskWoken );
\r
946 * A version of xTimerChangePeriod() that can be called from an interrupt
\r
949 * @param xTimer The handle of the timer that is having its period changed.
\r
951 * @param xNewPeriod The new period for xTimer. Timer periods are specified in
\r
952 * tick periods, so the constant portTICK_PERIOD_MS can be used to convert a time
\r
953 * that has been specified in milliseconds. For example, if the timer must
\r
954 * expire after 100 ticks, then xNewPeriod should be set to 100. Alternatively,
\r
955 * if the timer must expire after 500ms, then xNewPeriod can be set to
\r
956 * ( 500 / portTICK_PERIOD_MS ) provided configTICK_RATE_HZ is less than
\r
957 * or equal to 1000.
\r
959 * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most
\r
960 * of its time in the Blocked state, waiting for messages to arrive on the timer
\r
961 * command queue. Calling xTimerChangePeriodFromISR() writes a message to the
\r
962 * timer command queue, so has the potential to transition the timer service/
\r
963 * daemon task out of the Blocked state. If calling xTimerChangePeriodFromISR()
\r
964 * causes the timer service/daemon task to leave the Blocked state, and the
\r
965 * timer service/daemon task has a priority equal to or greater than the
\r
966 * currently executing task (the task that was interrupted), then
\r
967 * *pxHigherPriorityTaskWoken will get set to pdTRUE internally within the
\r
968 * xTimerChangePeriodFromISR() function. If xTimerChangePeriodFromISR() sets
\r
969 * this value to pdTRUE then a context switch should be performed before the
\r
972 * @return pdFAIL will be returned if the command to change the timers period
\r
973 * could not be sent to the timer command queue. pdPASS will be returned if the
\r
974 * command was successfully sent to the timer command queue. When the command
\r
975 * is actually processed will depend on the priority of the timer service/daemon
\r
976 * task relative to other tasks in the system. The timer service/daemon task
\r
977 * priority is set by the configTIMER_TASK_PRIORITY configuration constant.
\r
981 * // This scenario assumes xTimer has already been created and started. When
\r
982 * // an interrupt occurs, the period of xTimer should be changed to 500ms.
\r
984 * // The interrupt service routine that changes the period of xTimer.
\r
985 * void vAnExampleInterruptServiceRoutine( void )
\r
987 * BaseType_t xHigherPriorityTaskWoken = pdFALSE;
\r
989 * // The interrupt has occurred - change the period of xTimer to 500ms.
\r
990 * // xHigherPriorityTaskWoken was set to pdFALSE where it was defined
\r
991 * // (within this function). As this is an interrupt service routine, only
\r
992 * // FreeRTOS API functions that end in "FromISR" can be used.
\r
993 * if( xTimerChangePeriodFromISR( xTimer, &xHigherPriorityTaskWoken ) != pdPASS )
\r
995 * // The command to change the timers period was not executed
\r
996 * // successfully. Take appropriate action here.
\r
999 * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch
\r
1000 * // should be performed. The syntax required to perform a context switch
\r
1001 * // from inside an ISR varies from port to port, and from compiler to
\r
1002 * // compiler. Inspect the demos for the port you are using to find the
\r
1003 * // actual syntax required.
\r
1004 * if( xHigherPriorityTaskWoken != pdFALSE )
\r
1006 * // Call the interrupt safe yield function here (actual function
\r
1007 * // depends on the FreeRTOS port being used).
\r
1012 #define xTimerChangePeriodFromISR( xTimer, xNewPeriod, pxHigherPriorityTaskWoken ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_CHANGE_PERIOD_FROM_ISR, ( xNewPeriod ), ( pxHigherPriorityTaskWoken ), 0U )
\r
1015 * BaseType_t xTimerResetFromISR( TimerHandle_t xTimer,
\r
1016 * BaseType_t *pxHigherPriorityTaskWoken );
\r
1018 * A version of xTimerReset() that can be called from an interrupt service
\r
1021 * @param xTimer The handle of the timer that is to be started, reset, or
\r
1024 * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most
\r
1025 * of its time in the Blocked state, waiting for messages to arrive on the timer
\r
1026 * command queue. Calling xTimerResetFromISR() writes a message to the timer
\r
1027 * command queue, so has the potential to transition the timer service/daemon
\r
1028 * task out of the Blocked state. If calling xTimerResetFromISR() causes the
\r
1029 * timer service/daemon task to leave the Blocked state, and the timer service/
\r
1030 * daemon task has a priority equal to or greater than the currently executing
\r
1031 * task (the task that was interrupted), then *pxHigherPriorityTaskWoken will
\r
1032 * get set to pdTRUE internally within the xTimerResetFromISR() function. If
\r
1033 * xTimerResetFromISR() sets this value to pdTRUE then a context switch should
\r
1034 * be performed before the interrupt exits.
\r
1036 * @return pdFAIL will be returned if the reset command could not be sent to
\r
1037 * the timer command queue. pdPASS will be returned if the command was
\r
1038 * successfully sent to the timer command queue. When the command is actually
\r
1039 * processed will depend on the priority of the timer service/daemon task
\r
1040 * relative to other tasks in the system, although the timers expiry time is
\r
1041 * relative to when xTimerResetFromISR() is actually called. The timer service/daemon
\r
1042 * task priority is set by the configTIMER_TASK_PRIORITY configuration constant.
\r
1046 * // This scenario assumes xBacklightTimer has already been created. When a
\r
1047 * // key is pressed, an LCD back-light is switched on. If 5 seconds pass
\r
1048 * // without a key being pressed, then the LCD back-light is switched off. In
\r
1049 * // this case, the timer is a one-shot timer, and unlike the example given for
\r
1050 * // the xTimerReset() function, the key press event handler is an interrupt
\r
1051 * // service routine.
\r
1053 * // The callback function assigned to the one-shot timer. In this case the
\r
1054 * // parameter is not used.
\r
1055 * void vBacklightTimerCallback( TimerHandle_t pxTimer )
\r
1057 * // The timer expired, therefore 5 seconds must have passed since a key
\r
1058 * // was pressed. Switch off the LCD back-light.
\r
1059 * vSetBacklightState( BACKLIGHT_OFF );
\r
1062 * // The key press interrupt service routine.
\r
1063 * void vKeyPressEventInterruptHandler( void )
\r
1065 * BaseType_t xHigherPriorityTaskWoken = pdFALSE;
\r
1067 * // Ensure the LCD back-light is on, then reset the timer that is
\r
1068 * // responsible for turning the back-light off after 5 seconds of
\r
1069 * // key inactivity. This is an interrupt service routine so can only
\r
1070 * // call FreeRTOS API functions that end in "FromISR".
\r
1071 * vSetBacklightState( BACKLIGHT_ON );
\r
1073 * // xTimerStartFromISR() or xTimerResetFromISR() could be called here
\r
1074 * // as both cause the timer to re-calculate its expiry time.
\r
1075 * // xHigherPriorityTaskWoken was initialised to pdFALSE when it was
\r
1076 * // declared (in this function).
\r
1077 * if( xTimerResetFromISR( xBacklightTimer, &xHigherPriorityTaskWoken ) != pdPASS )
\r
1079 * // The reset command was not executed successfully. Take appropriate
\r
1083 * // Perform the rest of the key processing here.
\r
1085 * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch
\r
1086 * // should be performed. The syntax required to perform a context switch
\r
1087 * // from inside an ISR varies from port to port, and from compiler to
\r
1088 * // compiler. Inspect the demos for the port you are using to find the
\r
1089 * // actual syntax required.
\r
1090 * if( xHigherPriorityTaskWoken != pdFALSE )
\r
1092 * // Call the interrupt safe yield function here (actual function
\r
1093 * // depends on the FreeRTOS port being used).
\r
1098 #define xTimerResetFromISR( xTimer, pxHigherPriorityTaskWoken ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_RESET_FROM_ISR, ( xTaskGetTickCountFromISR() ), ( pxHigherPriorityTaskWoken ), 0U )
\r
1102 * BaseType_t xTimerPendFunctionCallFromISR( PendedFunction_t xFunctionToPend,
\r
1103 * void *pvParameter1,
\r
1104 * uint32_t ulParameter2,
\r
1105 * BaseType_t *pxHigherPriorityTaskWoken );
\r
1108 * Used from application interrupt service routines to defer the execution of a
\r
1109 * function to the RTOS daemon task (the timer service task, hence this function
\r
1110 * is implemented in timers.c and is prefixed with 'Timer').
\r
1112 * Ideally an interrupt service routine (ISR) is kept as short as possible, but
\r
1113 * sometimes an ISR either has a lot of processing to do, or needs to perform
\r
1114 * processing that is not deterministic. In these cases
\r
1115 * xTimerPendFunctionCallFromISR() can be used to defer processing of a function
\r
1116 * to the RTOS daemon task.
\r
1118 * A mechanism is provided that allows the interrupt to return directly to the
\r
1119 * task that will subsequently execute the pended callback function. This
\r
1120 * allows the callback function to execute contiguously in time with the
\r
1121 * interrupt - just as if the callback had executed in the interrupt itself.
\r
1123 * @param xFunctionToPend The function to execute from the timer service/
\r
1124 * daemon task. The function must conform to the PendedFunction_t
\r
1127 * @param pvParameter1 The value of the callback function's first parameter.
\r
1128 * The parameter has a void * type to allow it to be used to pass any type.
\r
1129 * For example, unsigned longs can be cast to a void *, or the void * can be
\r
1130 * used to point to a structure.
\r
1132 * @param ulParameter2 The value of the callback function's second parameter.
\r
1134 * @param pxHigherPriorityTaskWoken As mentioned above, calling this function
\r
1135 * will result in a message being sent to the timer daemon task. If the
\r
1136 * priority of the timer daemon task (which is set using
\r
1137 * configTIMER_TASK_PRIORITY in FreeRTOSConfig.h) is higher than the priority of
\r
1138 * the currently running task (the task the interrupt interrupted) then
\r
1139 * *pxHigherPriorityTaskWoken will be set to pdTRUE within
\r
1140 * xTimerPendFunctionCallFromISR(), indicating that a context switch should be
\r
1141 * requested before the interrupt exits. For that reason
\r
1142 * *pxHigherPriorityTaskWoken must be initialised to pdFALSE. See the
\r
1143 * example code below.
\r
1145 * @return pdPASS is returned if the message was successfully sent to the
\r
1146 * timer daemon task, otherwise pdFALSE is returned.
\r
1151 * // The callback function that will execute in the context of the daemon task.
\r
1152 * // Note callback functions must all use this same prototype.
\r
1153 * void vProcessInterface( void *pvParameter1, uint32_t ulParameter2 )
\r
1155 * BaseType_t xInterfaceToService;
\r
1157 * // The interface that requires servicing is passed in the second
\r
1158 * // parameter. The first parameter is not used in this case.
\r
1159 * xInterfaceToService = ( BaseType_t ) ulParameter2;
\r
1161 * // ...Perform the processing here...
\r
1164 * // An ISR that receives data packets from multiple interfaces
\r
1165 * void vAnISR( void )
\r
1167 * BaseType_t xInterfaceToService, xHigherPriorityTaskWoken;
\r
1169 * // Query the hardware to determine which interface needs processing.
\r
1170 * xInterfaceToService = prvCheckInterfaces();
\r
1172 * // The actual processing is to be deferred to a task. Request the
\r
1173 * // vProcessInterface() callback function is executed, passing in the
\r
1174 * // number of the interface that needs processing. The interface to
\r
1175 * // service is passed in the second parameter. The first parameter is
\r
1176 * // not used in this case.
\r
1177 * xHigherPriorityTaskWoken = pdFALSE;
\r
1178 * xTimerPendFunctionCallFromISR( vProcessInterface, NULL, ( uint32_t ) xInterfaceToService, &xHigherPriorityTaskWoken );
\r
1180 * // If xHigherPriorityTaskWoken is now set to pdTRUE then a context
\r
1181 * // switch should be requested. The macro used is port specific and will
\r
1182 * // be either portYIELD_FROM_ISR() or portEND_SWITCHING_ISR() - refer to
\r
1183 * // the documentation page for the port being used.
\r
1184 * portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
\r
1189 BaseType_t xTimerPendFunctionCallFromISR( PendedFunction_t xFunctionToPend,
\r
1190 void * pvParameter1,
\r
1191 uint32_t ulParameter2,
\r
1192 BaseType_t * pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
\r
1195 * BaseType_t xTimerPendFunctionCall( PendedFunction_t xFunctionToPend,
\r
1196 * void *pvParameter1,
\r
1197 * uint32_t ulParameter2,
\r
1198 * TickType_t xTicksToWait );
\r
1201 * Used to defer the execution of a function to the RTOS daemon task (the timer
\r
1202 * service task, hence this function is implemented in timers.c and is prefixed
\r
1205 * @param xFunctionToPend The function to execute from the timer service/
\r
1206 * daemon task. The function must conform to the PendedFunction_t
\r
1209 * @param pvParameter1 The value of the callback function's first parameter.
\r
1210 * The parameter has a void * type to allow it to be used to pass any type.
\r
1211 * For example, unsigned longs can be cast to a void *, or the void * can be
\r
1212 * used to point to a structure.
\r
1214 * @param ulParameter2 The value of the callback function's second parameter.
\r
1216 * @param xTicksToWait Calling this function will result in a message being
\r
1217 * sent to the timer daemon task on a queue. xTicksToWait is the amount of
\r
1218 * time the calling task should remain in the Blocked state (so not using any
\r
1219 * processing time) for space to become available on the timer queue if the
\r
1220 * queue is found to be full.
\r
1222 * @return pdPASS is returned if the message was successfully sent to the
\r
1223 * timer daemon task, otherwise pdFALSE is returned.
\r
1226 BaseType_t xTimerPendFunctionCall( PendedFunction_t xFunctionToPend,
\r
1227 void * pvParameter1,
\r
1228 uint32_t ulParameter2,
\r
1229 TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
\r
1232 * const char * const pcTimerGetName( TimerHandle_t xTimer );
\r
1234 * Returns the name that was assigned to a timer when the timer was created.
\r
1236 * @param xTimer The handle of the timer being queried.
\r
1238 * @return The name assigned to the timer specified by the xTimer parameter.
\r
1240 const char * pcTimerGetName( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
\r
1243 * void vTimerSetReloadMode( TimerHandle_t xTimer, const UBaseType_t uxAutoReload );
\r
1245 * Updates a timer to be either an auto-reload timer, in which case the timer
\r
1246 * automatically resets itself each time it expires, or a one-shot timer, in
\r
1247 * which case the timer will only expire once unless it is manually restarted.
\r
1249 * @param xTimer The handle of the timer being updated.
\r
1251 * @param uxAutoReload If uxAutoReload is set to pdTRUE then the timer will
\r
1252 * expire repeatedly with a frequency set by the timer's period (see the
\r
1253 * xTimerPeriodInTicks parameter of the xTimerCreate() API function). If
\r
1254 * uxAutoReload is set to pdFALSE then the timer will be a one-shot timer and
\r
1255 * enter the dormant state after it expires.
\r
1257 void vTimerSetReloadMode( TimerHandle_t xTimer,
\r
1258 const UBaseType_t uxAutoReload ) PRIVILEGED_FUNCTION;
\r
1261 * UBaseType_t uxTimerGetReloadMode( TimerHandle_t xTimer );
\r
1263 * Queries a timer to determine if it is an auto-reload timer, in which case the timer
\r
1264 * automatically resets itself each time it expires, or a one-shot timer, in
\r
1265 * which case the timer will only expire once unless it is manually restarted.
\r
1267 * @param xTimer The handle of the timer being queried.
\r
1269 * @return If the timer is an auto-reload timer then pdTRUE is returned, otherwise
\r
1270 * pdFALSE is returned.
\r
1272 UBaseType_t uxTimerGetReloadMode( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
\r
1275 * TickType_t xTimerGetPeriod( TimerHandle_t xTimer );
\r
1277 * Returns the period of a timer.
\r
1279 * @param xTimer The handle of the timer being queried.
\r
1281 * @return The period of the timer in ticks.
\r
1283 TickType_t xTimerGetPeriod( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
\r
1286 * TickType_t xTimerGetExpiryTime( TimerHandle_t xTimer );
\r
1288 * Returns the time in ticks at which the timer will expire. If this is less
\r
1289 * than the current tick count then the expiry time has overflowed from the
\r
1292 * @param xTimer The handle of the timer being queried.
\r
1294 * @return If the timer is running then the time in ticks at which the timer
\r
1295 * will next expire is returned. If the timer is not running then the return
\r
1296 * value is undefined.
\r
1298 TickType_t xTimerGetExpiryTime( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
\r
1301 * Functions beyond this part are not part of the public API and are intended
\r
1302 * for use by the kernel only.
\r
1304 BaseType_t xTimerCreateTimerTask( void ) PRIVILEGED_FUNCTION;
\r
1305 BaseType_t xTimerGenericCommand( TimerHandle_t xTimer,
\r
1306 const BaseType_t xCommandID,
\r
1307 const TickType_t xOptionalValue,
\r
1308 BaseType_t * const pxHigherPriorityTaskWoken,
\r
1309 const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
\r
1311 #if ( configUSE_TRACE_FACILITY == 1 )
\r
1312 void vTimerSetTimerNumber( TimerHandle_t xTimer,
\r
1313 UBaseType_t uxTimerNumber ) PRIVILEGED_FUNCTION;
\r
1314 UBaseType_t uxTimerGetTimerNumber( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
\r
1317 #ifdef __cplusplus
\r
1320 #endif /* TIMERS_H */
\r