blob: 05eb90fc9f4d27a232eafc0a7626461d2fc7c4f9 [file] [log] [blame]
Qiufang Dai35c31332020-05-13 15:29:06 +08001/*
2 * FreeRTOS Kernel V10.0.1
3 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 * this software and associated documentation files (the "Software"), to deal in
7 * the Software without restriction, including without limitation the rights to
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 * the Software, and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in all
13 * copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * http://www.FreeRTOS.org
23 * http://aws.amazon.com/freertos
24 *
25 * 1 tab == 4 spaces!
26 */
27
28
29#ifndef TIMERS_H
30#define TIMERS_H
31
32#ifndef INC_FREERTOS_H
33 #error "include FreeRTOS.h must appear in source files before include timers.h"
34#endif
35
36/*lint -save -e537 This headers are only multiply included if the application code
37happens to also be including task.h. */
38#include "task.h"
39/*lint -restore */
40
41#ifdef __cplusplus
42extern "C" {
43#endif
44
45/*-----------------------------------------------------------
46 * MACROS AND DEFINITIONS
47 *----------------------------------------------------------*/
48
49/* IDs for commands that can be sent/received on the timer queue. These are to
50be used solely through the macros that make up the public software timer API,
51as defined below. The commands that are sent from interrupts must use the
52highest numbers as tmrFIRST_FROM_ISR_COMMAND is used to determine if the task
53or interrupt version of the queue send function should be used. */
54#define tmrCOMMAND_EXECUTE_CALLBACK_FROM_ISR ( ( BaseType_t ) -2 )
55#define tmrCOMMAND_EXECUTE_CALLBACK ( ( BaseType_t ) -1 )
56#define tmrCOMMAND_START_DONT_TRACE ( ( BaseType_t ) 0 )
57#define tmrCOMMAND_START ( ( BaseType_t ) 1 )
58#define tmrCOMMAND_RESET ( ( BaseType_t ) 2 )
59#define tmrCOMMAND_STOP ( ( BaseType_t ) 3 )
60#define tmrCOMMAND_CHANGE_PERIOD ( ( BaseType_t ) 4 )
61#define tmrCOMMAND_DELETE ( ( BaseType_t ) 5 )
62
63#define tmrFIRST_FROM_ISR_COMMAND ( ( BaseType_t ) 6 )
64#define tmrCOMMAND_START_FROM_ISR ( ( BaseType_t ) 6 )
65#define tmrCOMMAND_RESET_FROM_ISR ( ( BaseType_t ) 7 )
66#define tmrCOMMAND_STOP_FROM_ISR ( ( BaseType_t ) 8 )
67#define tmrCOMMAND_CHANGE_PERIOD_FROM_ISR ( ( BaseType_t ) 9 )
68
69
70/**
71 * Type by which software timers are referenced. For example, a call to
72 * xTimerCreate() returns an TimerHandle_t variable that can then be used to
73 * reference the subject timer in calls to other software timer API functions
74 * (for example, xTimerStart(), xTimerReset(), etc.).
75 */
76typedef void * TimerHandle_t;
77
78/*
79 * Defines the prototype to which timer callback functions must conform.
80 */
81typedef void (*TimerCallbackFunction_t)( TimerHandle_t xTimer );
82
83/*
84 * Defines the prototype to which functions used with the
85 * xTimerPendFunctionCallFromISR() function must conform.
86 */
87typedef void (*PendedFunction_t)( void *, uint32_t );
88
89/**
90 * TimerHandle_t xTimerCreate( const char * const pcTimerName,
91 * TickType_t xTimerPeriodInTicks,
92 * UBaseType_t uxAutoReload,
93 * void * pvTimerID,
94 * TimerCallbackFunction_t pxCallbackFunction );
95 *
96 * Creates a new software timer instance, and returns a handle by which the
97 * created software timer can be referenced.
98 *
99 * Internally, within the FreeRTOS implementation, software timers use a block
100 * of memory, in which the timer data structure is stored. If a software timer
101 * is created using xTimerCreate() then the required memory is automatically
102 * dynamically allocated inside the xTimerCreate() function. (see
103 * http://www.freertos.org/a00111.html). If a software timer is created using
104 * xTimerCreateStatic() then the application writer must provide the memory that
105 * will get used by the software timer. xTimerCreateStatic() therefore allows a
106 * software timer to be created without using any dynamic memory allocation.
107 *
108 * Timers are created in the dormant state. The xTimerStart(), xTimerReset(),
109 * xTimerStartFromISR(), xTimerResetFromISR(), xTimerChangePeriod() and
110 * xTimerChangePeriodFromISR() API functions can all be used to transition a
111 * timer into the active state.
112 *
113 * @param pcTimerName A text name that is assigned to the timer. This is done
114 * purely to assist debugging. The kernel itself only ever references a timer
115 * by its handle, and never by its name.
116 *
117 * @param xTimerPeriodInTicks The timer period. The time is defined in tick
118 * periods so the constant portTICK_PERIOD_MS can be used to convert a time that
119 * has been specified in milliseconds. For example, if the timer must expire
120 * after 100 ticks, then xTimerPeriodInTicks should be set to 100.
121 * Alternatively, if the timer must expire after 500ms, then xPeriod can be set
122 * to ( 500 / portTICK_PERIOD_MS ) provided configTICK_RATE_HZ is less than or
123 * equal to 1000.
124 *
125 * @param uxAutoReload If uxAutoReload is set to pdTRUE then the timer will
126 * expire repeatedly with a frequency set by the xTimerPeriodInTicks parameter.
127 * If uxAutoReload is set to pdFALSE then the timer will be a one-shot timer and
128 * enter the dormant state after it expires.
129 *
130 * @param pvTimerID An identifier that is assigned to the timer being created.
131 * Typically this would be used in the timer callback function to identify which
132 * timer expired when the same callback function is assigned to more than one
133 * timer.
134 *
135 * @param pxCallbackFunction The function to call when the timer expires.
136 * Callback functions must have the prototype defined by TimerCallbackFunction_t,
137 * which is "void vCallbackFunction( TimerHandle_t xTimer );".
138 *
139 * @return If the timer is successfully created then a handle to the newly
140 * created timer is returned. If the timer cannot be created (because either
141 * there is insufficient FreeRTOS heap remaining to allocate the timer
142 * structures, or the timer period was set to 0) then NULL is returned.
143 *
144 * Example usage:
145 * @verbatim
146 * #define NUM_TIMERS 5
147 *
148 * // An array to hold handles to the created timers.
149 * TimerHandle_t xTimers[ NUM_TIMERS ];
150 *
151 * // An array to hold a count of the number of times each timer expires.
152 * int32_t lExpireCounters[ NUM_TIMERS ] = { 0 };
153 *
154 * // Define a callback function that will be used by multiple timer instances.
155 * // The callback function does nothing but count the number of times the
156 * // associated timer expires, and stop the timer once the timer has expired
157 * // 10 times.
158 * void vTimerCallback( TimerHandle_t pxTimer )
159 * {
160 * int32_t lArrayIndex;
161 * const int32_t xMaxExpiryCountBeforeStopping = 10;
162 *
163 * // Optionally do something if the pxTimer parameter is NULL.
164 * configASSERT( pxTimer );
165 *
166 * // Which timer expired?
167 * lArrayIndex = ( int32_t ) pvTimerGetTimerID( pxTimer );
168 *
169 * // Increment the number of times that pxTimer has expired.
170 * lExpireCounters[ lArrayIndex ] += 1;
171 *
172 * // If the timer has expired 10 times then stop it from running.
173 * if( lExpireCounters[ lArrayIndex ] == xMaxExpiryCountBeforeStopping )
174 * {
175 * // Do not use a block time if calling a timer API function from a
176 * // timer callback function, as doing so could cause a deadlock!
177 * xTimerStop( pxTimer, 0 );
178 * }
179 * }
180 *
181 * void main( void )
182 * {
183 * int32_t x;
184 *
185 * // Create then start some timers. Starting the timers before the scheduler
186 * // has been started means the timers will start running immediately that
187 * // the scheduler starts.
188 * for( x = 0; x < NUM_TIMERS; x++ )
189 * {
190 * xTimers[ x ] = xTimerCreate( "Timer", // Just a text name, not used by the kernel.
191 * ( 100 * x ), // The timer period in ticks.
192 * pdTRUE, // The timers will auto-reload themselves when they expire.
193 * ( void * ) x, // Assign each timer a unique id equal to its array index.
194 * vTimerCallback // Each timer calls the same callback when it expires.
195 * );
196 *
197 * if( xTimers[ x ] == NULL )
198 * {
199 * // The timer was not created.
200 * }
201 * else
202 * {
203 * // Start the timer. No block time is specified, and even if one was
204 * // it would be ignored because the scheduler has not yet been
205 * // started.
206 * if( xTimerStart( xTimers[ x ], 0 ) != pdPASS )
207 * {
208 * // The timer could not be set into the Active state.
209 * }
210 * }
211 * }
212 *
213 * // ...
214 * // Create tasks here.
215 * // ...
216 *
217 * // Starting the scheduler will start the timers running as they have already
218 * // been set into the active state.
219 * vTaskStartScheduler();
220 *
221 * // Should not reach here.
222 * for( ;; );
223 * }
224 * @endverbatim
225 */
226#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
227 TimerHandle_t xTimerCreate( const char * const pcTimerName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
228 const TickType_t xTimerPeriodInTicks,
229 const UBaseType_t uxAutoReload,
230 void * const pvTimerID,
231 TimerCallbackFunction_t pxCallbackFunction ) PRIVILEGED_FUNCTION;
232#endif
233
234/**
235 * TimerHandle_t xTimerCreateStatic(const char * const pcTimerName,
236 * TickType_t xTimerPeriodInTicks,
237 * UBaseType_t uxAutoReload,
238 * void * pvTimerID,
239 * TimerCallbackFunction_t pxCallbackFunction,
240 * StaticTimer_t *pxTimerBuffer );
241 *
242 * Creates a new software timer instance, and returns a handle by which the
243 * created software timer can be referenced.
244 *
245 * Internally, within the FreeRTOS implementation, software timers use a block
246 * of memory, in which the timer data structure is stored. If a software timer
247 * is created using xTimerCreate() then the required memory is automatically
248 * dynamically allocated inside the xTimerCreate() function. (see
249 * http://www.freertos.org/a00111.html). If a software timer is created using
250 * xTimerCreateStatic() then the application writer must provide the memory that
251 * will get used by the software timer. xTimerCreateStatic() therefore allows a
252 * software timer to be created without using any dynamic memory allocation.
253 *
254 * Timers are created in the dormant state. The xTimerStart(), xTimerReset(),
255 * xTimerStartFromISR(), xTimerResetFromISR(), xTimerChangePeriod() and
256 * xTimerChangePeriodFromISR() API functions can all be used to transition a
257 * timer into the active state.
258 *
259 * @param pcTimerName A text name that is assigned to the timer. This is done
260 * purely to assist debugging. The kernel itself only ever references a timer
261 * by its handle, and never by its name.
262 *
263 * @param xTimerPeriodInTicks The timer period. The time is defined in tick
264 * periods so the constant portTICK_PERIOD_MS can be used to convert a time that
265 * has been specified in milliseconds. For example, if the timer must expire
266 * after 100 ticks, then xTimerPeriodInTicks should be set to 100.
267 * Alternatively, if the timer must expire after 500ms, then xPeriod can be set
268 * to ( 500 / portTICK_PERIOD_MS ) provided configTICK_RATE_HZ is less than or
269 * equal to 1000.
270 *
271 * @param uxAutoReload If uxAutoReload is set to pdTRUE then the timer will
272 * expire repeatedly with a frequency set by the xTimerPeriodInTicks parameter.
273 * If uxAutoReload is set to pdFALSE then the timer will be a one-shot timer and
274 * enter the dormant state after it expires.
275 *
276 * @param pvTimerID An identifier that is assigned to the timer being created.
277 * Typically this would be used in the timer callback function to identify which
278 * timer expired when the same callback function is assigned to more than one
279 * timer.
280 *
281 * @param pxCallbackFunction The function to call when the timer expires.
282 * Callback functions must have the prototype defined by TimerCallbackFunction_t,
283 * which is "void vCallbackFunction( TimerHandle_t xTimer );".
284 *
285 * @param pxTimerBuffer Must point to a variable of type StaticTimer_t, which
286 * will be then be used to hold the software timer's data structures, removing
287 * the need for the memory to be allocated dynamically.
288 *
289 * @return If the timer is created then a handle to the created timer is
290 * returned. If pxTimerBuffer was NULL then NULL is returned.
291 *
292 * Example usage:
293 * @verbatim
294 *
295 * // The buffer used to hold the software timer's data structure.
296 * static StaticTimer_t xTimerBuffer;
297 *
298 * // A variable that will be incremented by the software timer's callback
299 * // function.
300 * UBaseType_t uxVariableToIncrement = 0;
301 *
302 * // A software timer callback function that increments a variable passed to
303 * // it when the software timer was created. After the 5th increment the
304 * // callback function stops the software timer.
305 * static void prvTimerCallback( TimerHandle_t xExpiredTimer )
306 * {
307 * UBaseType_t *puxVariableToIncrement;
308 * BaseType_t xReturned;
309 *
310 * // Obtain the address of the variable to increment from the timer ID.
311 * puxVariableToIncrement = ( UBaseType_t * ) pvTimerGetTimerID( xExpiredTimer );
312 *
313 * // Increment the variable to show the timer callback has executed.
314 * ( *puxVariableToIncrement )++;
315 *
316 * // If this callback has executed the required number of times, stop the
317 * // timer.
318 * if( *puxVariableToIncrement == 5 )
319 * {
320 * // This is called from a timer callback so must not block.
321 * xTimerStop( xExpiredTimer, staticDONT_BLOCK );
322 * }
323 * }
324 *
325 *
326 * void main( void )
327 * {
328 * // Create the software time. xTimerCreateStatic() has an extra parameter
329 * // than the normal xTimerCreate() API function. The parameter is a pointer
330 * // to the StaticTimer_t structure that will hold the software timer
331 * // structure. If the parameter is passed as NULL then the structure will be
332 * // allocated dynamically, just as if xTimerCreate() had been called.
333 * xTimer = xTimerCreateStatic( "T1", // Text name for the task. Helps debugging only. Not used by FreeRTOS.
334 * xTimerPeriod, // The period of the timer in ticks.
335 * pdTRUE, // This is an auto-reload timer.
336 * ( void * ) &uxVariableToIncrement, // A variable incremented by the software timer's callback function
337 * prvTimerCallback, // The function to execute when the timer expires.
338 * &xTimerBuffer ); // The buffer that will hold the software timer structure.
339 *
340 * // The scheduler has not started yet so a block time is not used.
341 * xReturned = xTimerStart( xTimer, 0 );
342 *
343 * // ...
344 * // Create tasks here.
345 * // ...
346 *
347 * // Starting the scheduler will start the timers running as they have already
348 * // been set into the active state.
349 * vTaskStartScheduler();
350 *
351 * // Should not reach here.
352 * for( ;; );
353 * }
354 * @endverbatim
355 */
356#if( configSUPPORT_STATIC_ALLOCATION == 1 )
357 TimerHandle_t xTimerCreateStatic( const char * const pcTimerName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
358 const TickType_t xTimerPeriodInTicks,
359 const UBaseType_t uxAutoReload,
360 void * const pvTimerID,
361 TimerCallbackFunction_t pxCallbackFunction,
362 StaticTimer_t *pxTimerBuffer ) PRIVILEGED_FUNCTION;
363#endif /* configSUPPORT_STATIC_ALLOCATION */
364
365/**
366 * void *pvTimerGetTimerID( TimerHandle_t xTimer );
367 *
368 * Returns the ID assigned to the timer.
369 *
370 * IDs are assigned to timers using the pvTimerID parameter of the call to
371 * xTimerCreated() that was used to create the timer, and by calling the
372 * vTimerSetTimerID() API function.
373 *
374 * If the same callback function is assigned to multiple timers then the timer
375 * ID can be used as time specific (timer local) storage.
376 *
377 * @param xTimer The timer being queried.
378 *
379 * @return The ID assigned to the timer being queried.
380 *
381 * Example usage:
382 *
383 * See the xTimerCreate() API function example usage scenario.
384 */
385void *pvTimerGetTimerID( const TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
386
387/**
388 * void vTimerSetTimerID( TimerHandle_t xTimer, void *pvNewID );
389 *
390 * Sets the ID assigned to the timer.
391 *
392 * IDs are assigned to timers using the pvTimerID parameter of the call to
393 * xTimerCreated() that was used to create the timer.
394 *
395 * If the same callback function is assigned to multiple timers then the timer
396 * ID can be used as time specific (timer local) storage.
397 *
398 * @param xTimer The timer being updated.
399 *
400 * @param pvNewID The ID to assign to the timer.
401 *
402 * Example usage:
403 *
404 * See the xTimerCreate() API function example usage scenario.
405 */
406void vTimerSetTimerID( TimerHandle_t xTimer, void *pvNewID ) PRIVILEGED_FUNCTION;
407
408/**
409 * BaseType_t xTimerIsTimerActive( TimerHandle_t xTimer );
410 *
411 * Queries a timer to see if it is active or dormant.
412 *
413 * A timer will be dormant if:
414 * 1) It has been created but not started, or
415 * 2) It is an expired one-shot timer that has not been restarted.
416 *
417 * Timers are created in the dormant state. The xTimerStart(), xTimerReset(),
418 * xTimerStartFromISR(), xTimerResetFromISR(), xTimerChangePeriod() and
419 * xTimerChangePeriodFromISR() API functions can all be used to transition a timer into the
420 * active state.
421 *
422 * @param xTimer The timer being queried.
423 *
424 * @return pdFALSE will be returned if the timer is dormant. A value other than
425 * pdFALSE will be returned if the timer is active.
426 *
427 * Example usage:
428 * @verbatim
429 * // This function assumes xTimer has already been created.
430 * void vAFunction( TimerHandle_t xTimer )
431 * {
432 * if( xTimerIsTimerActive( xTimer ) != pdFALSE ) // or more simply and equivalently "if( xTimerIsTimerActive( xTimer ) )"
433 * {
434 * // xTimer is active, do something.
435 * }
436 * else
437 * {
438 * // xTimer is not active, do something else.
439 * }
440 * }
441 * @endverbatim
442 */
443BaseType_t xTimerIsTimerActive( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
444
445/**
446 * TaskHandle_t xTimerGetTimerDaemonTaskHandle( void );
447 *
448 * Simply returns the handle of the timer service/daemon task. It it not valid
449 * to call xTimerGetTimerDaemonTaskHandle() before the scheduler has been started.
450 */
451TaskHandle_t xTimerGetTimerDaemonTaskHandle( void ) PRIVILEGED_FUNCTION;
452
453/**
454 * BaseType_t xTimerStart( TimerHandle_t xTimer, TickType_t xTicksToWait );
455 *
456 * Timer functionality is provided by a timer service/daemon task. Many of the
457 * public FreeRTOS timer API functions send commands to the timer service task
458 * through a queue called the timer command queue. The timer command queue is
459 * private to the kernel itself and is not directly accessible to application
460 * code. The length of the timer command queue is set by the
461 * configTIMER_QUEUE_LENGTH configuration constant.
462 *
463 * xTimerStart() starts a timer that was previously created using the
464 * xTimerCreate() API function. If the timer had already been started and was
465 * already in the active state, then xTimerStart() has equivalent functionality
466 * to the xTimerReset() API function.
467 *
468 * Starting a timer ensures the timer is in the active state. If the timer
469 * is not stopped, deleted, or reset in the mean time, the callback function
470 * associated with the timer will get called 'n' ticks after xTimerStart() was
471 * called, where 'n' is the timers defined period.
472 *
473 * It is valid to call xTimerStart() before the scheduler has been started, but
474 * when this is done the timer will not actually start until the scheduler is
475 * started, and the timers expiry time will be relative to when the scheduler is
476 * started, not relative to when xTimerStart() was called.
477 *
478 * The configUSE_TIMERS configuration constant must be set to 1 for xTimerStart()
479 * to be available.
480 *
481 * @param xTimer The handle of the timer being started/restarted.
482 *
483 * @param xTicksToWait Specifies the time, in ticks, that the calling task should
484 * be held in the Blocked state to wait for the start command to be successfully
485 * sent to the timer command queue, should the queue already be full when
486 * xTimerStart() was called. xTicksToWait is ignored if xTimerStart() is called
487 * before the scheduler is started.
488 *
489 * @return pdFAIL will be returned if the start command could not be sent to
490 * the timer command queue even after xTicksToWait ticks had passed. pdPASS will
491 * be returned if the command was successfully sent to the timer command queue.
492 * When the command is actually processed will depend on the priority of the
493 * timer service/daemon task relative to other tasks in the system, although the
494 * timers expiry time is relative to when xTimerStart() is actually called. The
495 * timer service/daemon task priority is set by the configTIMER_TASK_PRIORITY
496 * configuration constant.
497 *
498 * Example usage:
499 *
500 * See the xTimerCreate() API function example usage scenario.
501 *
502 */
503#define xTimerStart( xTimer, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_START, ( xTaskGetTickCount() ), NULL, ( xTicksToWait ) )
504
505/**
506 * BaseType_t xTimerStop( TimerHandle_t xTimer, TickType_t xTicksToWait );
507 *
508 * Timer functionality is provided by a timer service/daemon task. Many of the
509 * public FreeRTOS timer API functions send commands to the timer service task
510 * through a queue called the timer command queue. The timer command queue is
511 * private to the kernel itself and is not directly accessible to application
512 * code. The length of the timer command queue is set by the
513 * configTIMER_QUEUE_LENGTH configuration constant.
514 *
515 * xTimerStop() stops a timer that was previously started using either of the
516 * The xTimerStart(), xTimerReset(), xTimerStartFromISR(), xTimerResetFromISR(),
517 * xTimerChangePeriod() or xTimerChangePeriodFromISR() API functions.
518 *
519 * Stopping a timer ensures the timer is not in the active state.
520 *
521 * The configUSE_TIMERS configuration constant must be set to 1 for xTimerStop()
522 * to be available.
523 *
524 * @param xTimer The handle of the timer being stopped.
525 *
526 * @param xTicksToWait Specifies the time, in ticks, that the calling task should
527 * be held in the Blocked state to wait for the stop command to be successfully
528 * sent to the timer command queue, should the queue already be full when
529 * xTimerStop() was called. xTicksToWait is ignored if xTimerStop() is called
530 * before the scheduler is started.
531 *
532 * @return pdFAIL will be returned if the stop command could not be sent to
533 * the timer command queue even after xTicksToWait ticks had passed. pdPASS will
534 * be returned if the command was successfully sent to the timer command queue.
535 * When the command is actually processed will depend on the priority of the
536 * timer service/daemon task relative to other tasks in the system. The timer
537 * service/daemon task priority is set by the configTIMER_TASK_PRIORITY
538 * configuration constant.
539 *
540 * Example usage:
541 *
542 * See the xTimerCreate() API function example usage scenario.
543 *
544 */
545#define xTimerStop( xTimer, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_STOP, 0U, NULL, ( xTicksToWait ) )
546
547/**
548 * BaseType_t xTimerChangePeriod( TimerHandle_t xTimer,
549 * TickType_t xNewPeriod,
550 * TickType_t xTicksToWait );
551 *
552 * Timer functionality is provided by a timer service/daemon task. Many of the
553 * public FreeRTOS timer API functions send commands to the timer service task
554 * through a queue called the timer command queue. The timer command queue is
555 * private to the kernel itself and is not directly accessible to application
556 * code. The length of the timer command queue is set by the
557 * configTIMER_QUEUE_LENGTH configuration constant.
558 *
559 * xTimerChangePeriod() changes the period of a timer that was previously
560 * created using the xTimerCreate() API function.
561 *
562 * xTimerChangePeriod() can be called to change the period of an active or
563 * dormant state timer.
564 *
565 * The configUSE_TIMERS configuration constant must be set to 1 for
566 * xTimerChangePeriod() to be available.
567 *
568 * @param xTimer The handle of the timer that is having its period changed.
569 *
570 * @param xNewPeriod The new period for xTimer. Timer periods are specified in
571 * tick periods, so the constant portTICK_PERIOD_MS can be used to convert a time
572 * that has been specified in milliseconds. For example, if the timer must
573 * expire after 100 ticks, then xNewPeriod should be set to 100. Alternatively,
574 * if the timer must expire after 500ms, then xNewPeriod can be set to
575 * ( 500 / portTICK_PERIOD_MS ) provided configTICK_RATE_HZ is less than
576 * or equal to 1000.
577 *
578 * @param xTicksToWait Specifies the time, in ticks, that the calling task should
579 * be held in the Blocked state to wait for the change period command to be
580 * successfully sent to the timer command queue, should the queue already be
581 * full when xTimerChangePeriod() was called. xTicksToWait is ignored if
582 * xTimerChangePeriod() is called before the scheduler is started.
583 *
584 * @return pdFAIL will be returned if the change period command could not be
585 * sent to the timer command queue even after xTicksToWait ticks had passed.
586 * pdPASS will be returned if the command was successfully sent to the timer
587 * command queue. When the command is actually processed will depend on the
588 * priority of the timer service/daemon task relative to other tasks in the
589 * system. The timer service/daemon task priority is set by the
590 * configTIMER_TASK_PRIORITY configuration constant.
591 *
592 * Example usage:
593 * @verbatim
594 * // This function assumes xTimer has already been created. If the timer
595 * // referenced by xTimer is already active when it is called, then the timer
596 * // is deleted. If the timer referenced by xTimer is not active when it is
597 * // called, then the period of the timer is set to 500ms and the timer is
598 * // started.
599 * void vAFunction( TimerHandle_t xTimer )
600 * {
601 * if( xTimerIsTimerActive( xTimer ) != pdFALSE ) // or more simply and equivalently "if( xTimerIsTimerActive( xTimer ) )"
602 * {
603 * // xTimer is already active - delete it.
604 * xTimerDelete( xTimer );
605 * }
606 * else
607 * {
608 * // xTimer is not active, change its period to 500ms. This will also
609 * // cause the timer to start. Block for a maximum of 100 ticks if the
610 * // change period command cannot immediately be sent to the timer
611 * // command queue.
612 * if( xTimerChangePeriod( xTimer, 500 / portTICK_PERIOD_MS, 100 ) == pdPASS )
613 * {
614 * // The command was successfully sent.
615 * }
616 * else
617 * {
618 * // The command could not be sent, even after waiting for 100 ticks
619 * // to pass. Take appropriate action here.
620 * }
621 * }
622 * }
623 * @endverbatim
624 */
625 #define xTimerChangePeriod( xTimer, xNewPeriod, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_CHANGE_PERIOD, ( xNewPeriod ), NULL, ( xTicksToWait ) )
626
627/**
628 * BaseType_t xTimerDelete( TimerHandle_t xTimer, TickType_t xTicksToWait );
629 *
630 * Timer functionality is provided by a timer service/daemon task. Many of the
631 * public FreeRTOS timer API functions send commands to the timer service task
632 * through a queue called the timer command queue. The timer command queue is
633 * private to the kernel itself and is not directly accessible to application
634 * code. The length of the timer command queue is set by the
635 * configTIMER_QUEUE_LENGTH configuration constant.
636 *
637 * xTimerDelete() deletes a timer that was previously created using the
638 * xTimerCreate() API function.
639 *
640 * The configUSE_TIMERS configuration constant must be set to 1 for
641 * xTimerDelete() to be available.
642 *
643 * @param xTimer The handle of the timer being deleted.
644 *
645 * @param xTicksToWait Specifies the time, in ticks, that the calling task should
646 * be held in the Blocked state to wait for the delete command to be
647 * successfully sent to the timer command queue, should the queue already be
648 * full when xTimerDelete() was called. xTicksToWait is ignored if xTimerDelete()
649 * is called before the scheduler is started.
650 *
651 * @return pdFAIL will be returned if the delete command could not be sent to
652 * the timer command queue even after xTicksToWait ticks had passed. pdPASS will
653 * be returned if the command was successfully sent to the timer command queue.
654 * When the command is actually processed will depend on the priority of the
655 * timer service/daemon task relative to other tasks in the system. The timer
656 * service/daemon task priority is set by the configTIMER_TASK_PRIORITY
657 * configuration constant.
658 *
659 * Example usage:
660 *
661 * See the xTimerChangePeriod() API function example usage scenario.
662 */
663#define xTimerDelete( xTimer, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_DELETE, 0U, NULL, ( xTicksToWait ) )
664
665/**
666 * BaseType_t xTimerReset( TimerHandle_t xTimer, TickType_t xTicksToWait );
667 *
668 * Timer functionality is provided by a timer service/daemon task. Many of the
669 * public FreeRTOS timer API functions send commands to the timer service task
670 * through a queue called the timer command queue. The timer command queue is
671 * private to the kernel itself and is not directly accessible to application
672 * code. The length of the timer command queue is set by the
673 * configTIMER_QUEUE_LENGTH configuration constant.
674 *
675 * xTimerReset() re-starts a timer that was previously created using the
676 * xTimerCreate() API function. If the timer had already been started and was
677 * already in the active state, then xTimerReset() will cause the timer to
678 * re-evaluate its expiry time so that it is relative to when xTimerReset() was
679 * called. If the timer was in the dormant state then xTimerReset() has
680 * equivalent functionality to the xTimerStart() API function.
681 *
682 * Resetting a timer ensures the timer is in the active state. If the timer
683 * is not stopped, deleted, or reset in the mean time, the callback function
684 * associated with the timer will get called 'n' ticks after xTimerReset() was
685 * called, where 'n' is the timers defined period.
686 *
687 * It is valid to call xTimerReset() before the scheduler has been started, but
688 * when this is done the timer will not actually start until the scheduler is
689 * started, and the timers expiry time will be relative to when the scheduler is
690 * started, not relative to when xTimerReset() was called.
691 *
692 * The configUSE_TIMERS configuration constant must be set to 1 for xTimerReset()
693 * to be available.
694 *
695 * @param xTimer The handle of the timer being reset/started/restarted.
696 *
697 * @param xTicksToWait Specifies the time, in ticks, that the calling task should
698 * be held in the Blocked state to wait for the reset command to be successfully
699 * sent to the timer command queue, should the queue already be full when
700 * xTimerReset() was called. xTicksToWait is ignored if xTimerReset() is called
701 * before the scheduler is started.
702 *
703 * @return pdFAIL will be returned if the reset command could not be sent to
704 * the timer command queue even after xTicksToWait ticks had passed. pdPASS will
705 * be returned if the command was successfully sent to the timer command queue.
706 * When the command is actually processed will depend on the priority of the
707 * timer service/daemon task relative to other tasks in the system, although the
708 * timers expiry time is relative to when xTimerStart() is actually called. The
709 * timer service/daemon task priority is set by the configTIMER_TASK_PRIORITY
710 * configuration constant.
711 *
712 * Example usage:
713 * @verbatim
714 * // When a key is pressed, an LCD back-light is switched on. If 5 seconds pass
715 * // without a key being pressed, then the LCD back-light is switched off. In
716 * // this case, the timer is a one-shot timer.
717 *
718 * TimerHandle_t xBacklightTimer = NULL;
719 *
720 * // The callback function assigned to the one-shot timer. In this case the
721 * // parameter is not used.
722 * void vBacklightTimerCallback( TimerHandle_t pxTimer )
723 * {
724 * // The timer expired, therefore 5 seconds must have passed since a key
725 * // was pressed. Switch off the LCD back-light.
726 * vSetBacklightState( BACKLIGHT_OFF );
727 * }
728 *
729 * // The key press event handler.
730 * void vKeyPressEventHandler( char cKey )
731 * {
732 * // Ensure the LCD back-light is on, then reset the timer that is
733 * // responsible for turning the back-light off after 5 seconds of
734 * // key inactivity. Wait 10 ticks for the command to be successfully sent
735 * // if it cannot be sent immediately.
736 * vSetBacklightState( BACKLIGHT_ON );
737 * if( xTimerReset( xBacklightTimer, 100 ) != pdPASS )
738 * {
739 * // The reset command was not executed successfully. Take appropriate
740 * // action here.
741 * }
742 *
743 * // Perform the rest of the key processing here.
744 * }
745 *
746 * void main( void )
747 * {
748 * int32_t x;
749 *
750 * // Create then start the one-shot timer that is responsible for turning
751 * // the back-light off if no keys are pressed within a 5 second period.
752 * xBacklightTimer = xTimerCreate( "BacklightTimer", // Just a text name, not used by the kernel.
753 * ( 5000 / portTICK_PERIOD_MS), // The timer period in ticks.
754 * pdFALSE, // The timer is a one-shot timer.
755 * 0, // The id is not used by the callback so can take any value.
756 * vBacklightTimerCallback // The callback function that switches the LCD back-light off.
757 * );
758 *
759 * if( xBacklightTimer == NULL )
760 * {
761 * // The timer was not created.
762 * }
763 * else
764 * {
765 * // Start the timer. No block time is specified, and even if one was
766 * // it would be ignored because the scheduler has not yet been
767 * // started.
768 * if( xTimerStart( xBacklightTimer, 0 ) != pdPASS )
769 * {
770 * // The timer could not be set into the Active state.
771 * }
772 * }
773 *
774 * // ...
775 * // Create tasks here.
776 * // ...
777 *
778 * // Starting the scheduler will start the timer running as it has already
779 * // been set into the active state.
780 * vTaskStartScheduler();
781 *
782 * // Should not reach here.
783 * for( ;; );
784 * }
785 * @endverbatim
786 */
787#define xTimerReset( xTimer, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_RESET, ( xTaskGetTickCount() ), NULL, ( xTicksToWait ) )
788
789/**
790 * BaseType_t xTimerStartFromISR( TimerHandle_t xTimer,
791 * BaseType_t *pxHigherPriorityTaskWoken );
792 *
793 * A version of xTimerStart() that can be called from an interrupt service
794 * routine.
795 *
796 * @param xTimer The handle of the timer being started/restarted.
797 *
798 * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most
799 * of its time in the Blocked state, waiting for messages to arrive on the timer
800 * command queue. Calling xTimerStartFromISR() writes a message to the timer
801 * command queue, so has the potential to transition the timer service/daemon
802 * task out of the Blocked state. If calling xTimerStartFromISR() causes the
803 * timer service/daemon task to leave the Blocked state, and the timer service/
804 * daemon task has a priority equal to or greater than the currently executing
805 * task (the task that was interrupted), then *pxHigherPriorityTaskWoken will
806 * get set to pdTRUE internally within the xTimerStartFromISR() function. If
807 * xTimerStartFromISR() sets this value to pdTRUE then a context switch should
808 * be performed before the interrupt exits.
809 *
810 * @return pdFAIL will be returned if the start command could not be sent to
811 * the timer command queue. pdPASS will be returned if the command was
812 * successfully sent to the timer command queue. When the command is actually
813 * processed will depend on the priority of the timer service/daemon task
814 * relative to other tasks in the system, although the timers expiry time is
815 * relative to when xTimerStartFromISR() is actually called. The timer
816 * service/daemon task priority is set by the configTIMER_TASK_PRIORITY
817 * configuration constant.
818 *
819 * Example usage:
820 * @verbatim
821 * // This scenario assumes xBacklightTimer has already been created. When a
822 * // key is pressed, an LCD back-light is switched on. If 5 seconds pass
823 * // without a key being pressed, then the LCD back-light is switched off. In
824 * // this case, the timer is a one-shot timer, and unlike the example given for
825 * // the xTimerReset() function, the key press event handler is an interrupt
826 * // service routine.
827 *
828 * // The callback function assigned to the one-shot timer. In this case the
829 * // parameter is not used.
830 * void vBacklightTimerCallback( TimerHandle_t pxTimer )
831 * {
832 * // The timer expired, therefore 5 seconds must have passed since a key
833 * // was pressed. Switch off the LCD back-light.
834 * vSetBacklightState( BACKLIGHT_OFF );
835 * }
836 *
837 * // The key press interrupt service routine.
838 * void vKeyPressEventInterruptHandler( void )
839 * {
840 * BaseType_t xHigherPriorityTaskWoken = pdFALSE;
841 *
842 * // Ensure the LCD back-light is on, then restart the timer that is
843 * // responsible for turning the back-light off after 5 seconds of
844 * // key inactivity. This is an interrupt service routine so can only
845 * // call FreeRTOS API functions that end in "FromISR".
846 * vSetBacklightState( BACKLIGHT_ON );
847 *
848 * // xTimerStartFromISR() or xTimerResetFromISR() could be called here
849 * // as both cause the timer to re-calculate its expiry time.
850 * // xHigherPriorityTaskWoken was initialised to pdFALSE when it was
851 * // declared (in this function).
852 * if( xTimerStartFromISR( xBacklightTimer, &xHigherPriorityTaskWoken ) != pdPASS )
853 * {
854 * // The start command was not executed successfully. Take appropriate
855 * // action here.
856 * }
857 *
858 * // Perform the rest of the key processing here.
859 *
860 * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch
861 * // should be performed. The syntax required to perform a context switch
862 * // from inside an ISR varies from port to port, and from compiler to
863 * // compiler. Inspect the demos for the port you are using to find the
864 * // actual syntax required.
865 * if( xHigherPriorityTaskWoken != pdFALSE )
866 * {
867 * // Call the interrupt safe yield function here (actual function
868 * // depends on the FreeRTOS port being used).
869 * }
870 * }
871 * @endverbatim
872 */
873#define xTimerStartFromISR( xTimer, pxHigherPriorityTaskWoken ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_START_FROM_ISR, ( xTaskGetTickCountFromISR() ), ( pxHigherPriorityTaskWoken ), 0U )
874
875/**
876 * BaseType_t xTimerStopFromISR( TimerHandle_t xTimer,
877 * BaseType_t *pxHigherPriorityTaskWoken );
878 *
879 * A version of xTimerStop() that can be called from an interrupt service
880 * routine.
881 *
882 * @param xTimer The handle of the timer being stopped.
883 *
884 * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most
885 * of its time in the Blocked state, waiting for messages to arrive on the timer
886 * command queue. Calling xTimerStopFromISR() writes a message to the timer
887 * command queue, so has the potential to transition the timer service/daemon
888 * task out of the Blocked state. If calling xTimerStopFromISR() causes the
889 * timer service/daemon task to leave the Blocked state, and the timer service/
890 * daemon task has a priority equal to or greater than the currently executing
891 * task (the task that was interrupted), then *pxHigherPriorityTaskWoken will
892 * get set to pdTRUE internally within the xTimerStopFromISR() function. If
893 * xTimerStopFromISR() sets this value to pdTRUE then a context switch should
894 * be performed before the interrupt exits.
895 *
896 * @return pdFAIL will be returned if the stop command could not be sent to
897 * the timer command queue. pdPASS will be returned if the command was
898 * successfully sent to the timer command queue. When the command is actually
899 * processed will depend on the priority of the timer service/daemon task
900 * relative to other tasks in the system. The timer service/daemon task
901 * priority is set by the configTIMER_TASK_PRIORITY configuration constant.
902 *
903 * Example usage:
904 * @verbatim
905 * // This scenario assumes xTimer has already been created and started. When
906 * // an interrupt occurs, the timer should be simply stopped.
907 *
908 * // The interrupt service routine that stops the timer.
909 * void vAnExampleInterruptServiceRoutine( void )
910 * {
911 * BaseType_t xHigherPriorityTaskWoken = pdFALSE;
912 *
913 * // The interrupt has occurred - simply stop the timer.
914 * // xHigherPriorityTaskWoken was set to pdFALSE where it was defined
915 * // (within this function). As this is an interrupt service routine, only
916 * // FreeRTOS API functions that end in "FromISR" can be used.
917 * if( xTimerStopFromISR( xTimer, &xHigherPriorityTaskWoken ) != pdPASS )
918 * {
919 * // The stop command was not executed successfully. Take appropriate
920 * // action here.
921 * }
922 *
923 * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch
924 * // should be performed. The syntax required to perform a context switch
925 * // from inside an ISR varies from port to port, and from compiler to
926 * // compiler. Inspect the demos for the port you are using to find the
927 * // actual syntax required.
928 * if( xHigherPriorityTaskWoken != pdFALSE )
929 * {
930 * // Call the interrupt safe yield function here (actual function
931 * // depends on the FreeRTOS port being used).
932 * }
933 * }
934 * @endverbatim
935 */
936#define xTimerStopFromISR( xTimer, pxHigherPriorityTaskWoken ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_STOP_FROM_ISR, 0, ( pxHigherPriorityTaskWoken ), 0U )
937
938/**
939 * BaseType_t xTimerChangePeriodFromISR( TimerHandle_t xTimer,
940 * TickType_t xNewPeriod,
941 * BaseType_t *pxHigherPriorityTaskWoken );
942 *
943 * A version of xTimerChangePeriod() that can be called from an interrupt
944 * service routine.
945 *
946 * @param xTimer The handle of the timer that is having its period changed.
947 *
948 * @param xNewPeriod The new period for xTimer. Timer periods are specified in
949 * tick periods, so the constant portTICK_PERIOD_MS can be used to convert a time
950 * that has been specified in milliseconds. For example, if the timer must
951 * expire after 100 ticks, then xNewPeriod should be set to 100. Alternatively,
952 * if the timer must expire after 500ms, then xNewPeriod can be set to
953 * ( 500 / portTICK_PERIOD_MS ) provided configTICK_RATE_HZ is less than
954 * or equal to 1000.
955 *
956 * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most
957 * of its time in the Blocked state, waiting for messages to arrive on the timer
958 * command queue. Calling xTimerChangePeriodFromISR() writes a message to the
959 * timer command queue, so has the potential to transition the timer service/
960 * daemon task out of the Blocked state. If calling xTimerChangePeriodFromISR()
961 * causes the timer service/daemon task to leave the Blocked state, and the
962 * timer service/daemon task has a priority equal to or greater than the
963 * currently executing task (the task that was interrupted), then
964 * *pxHigherPriorityTaskWoken will get set to pdTRUE internally within the
965 * xTimerChangePeriodFromISR() function. If xTimerChangePeriodFromISR() sets
966 * this value to pdTRUE then a context switch should be performed before the
967 * interrupt exits.
968 *
969 * @return pdFAIL will be returned if the command to change the timers period
970 * could not be sent to the timer command queue. pdPASS will be returned if the
971 * command was successfully sent to the timer command queue. When the command
972 * is actually processed will depend on the priority of the timer service/daemon
973 * task relative to other tasks in the system. The timer service/daemon task
974 * priority is set by the configTIMER_TASK_PRIORITY configuration constant.
975 *
976 * Example usage:
977 * @verbatim
978 * // This scenario assumes xTimer has already been created and started. When
979 * // an interrupt occurs, the period of xTimer should be changed to 500ms.
980 *
981 * // The interrupt service routine that changes the period of xTimer.
982 * void vAnExampleInterruptServiceRoutine( void )
983 * {
984 * BaseType_t xHigherPriorityTaskWoken = pdFALSE;
985 *
986 * // The interrupt has occurred - change the period of xTimer to 500ms.
987 * // xHigherPriorityTaskWoken was set to pdFALSE where it was defined
988 * // (within this function). As this is an interrupt service routine, only
989 * // FreeRTOS API functions that end in "FromISR" can be used.
990 * if( xTimerChangePeriodFromISR( xTimer, &xHigherPriorityTaskWoken ) != pdPASS )
991 * {
992 * // The command to change the timers period was not executed
993 * // successfully. Take appropriate action here.
994 * }
995 *
996 * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch
997 * // should be performed. The syntax required to perform a context switch
998 * // from inside an ISR varies from port to port, and from compiler to
999 * // compiler. Inspect the demos for the port you are using to find the
1000 * // actual syntax required.
1001 * if( xHigherPriorityTaskWoken != pdFALSE )
1002 * {
1003 * // Call the interrupt safe yield function here (actual function
1004 * // depends on the FreeRTOS port being used).
1005 * }
1006 * }
1007 * @endverbatim
1008 */
1009#define xTimerChangePeriodFromISR( xTimer, xNewPeriod, pxHigherPriorityTaskWoken ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_CHANGE_PERIOD_FROM_ISR, ( xNewPeriod ), ( pxHigherPriorityTaskWoken ), 0U )
1010
1011/**
1012 * BaseType_t xTimerResetFromISR( TimerHandle_t xTimer,
1013 * BaseType_t *pxHigherPriorityTaskWoken );
1014 *
1015 * A version of xTimerReset() that can be called from an interrupt service
1016 * routine.
1017 *
1018 * @param xTimer The handle of the timer that is to be started, reset, or
1019 * restarted.
1020 *
1021 * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most
1022 * of its time in the Blocked state, waiting for messages to arrive on the timer
1023 * command queue. Calling xTimerResetFromISR() writes a message to the timer
1024 * command queue, so has the potential to transition the timer service/daemon
1025 * task out of the Blocked state. If calling xTimerResetFromISR() causes the
1026 * timer service/daemon task to leave the Blocked state, and the timer service/
1027 * daemon task has a priority equal to or greater than the currently executing
1028 * task (the task that was interrupted), then *pxHigherPriorityTaskWoken will
1029 * get set to pdTRUE internally within the xTimerResetFromISR() function. If
1030 * xTimerResetFromISR() sets this value to pdTRUE then a context switch should
1031 * be performed before the interrupt exits.
1032 *
1033 * @return pdFAIL will be returned if the reset command could not be sent to
1034 * the timer command queue. pdPASS will be returned if the command was
1035 * successfully sent to the timer command queue. When the command is actually
1036 * processed will depend on the priority of the timer service/daemon task
1037 * relative to other tasks in the system, although the timers expiry time is
1038 * relative to when xTimerResetFromISR() is actually called. The timer service/daemon
1039 * task priority is set by the configTIMER_TASK_PRIORITY configuration constant.
1040 *
1041 * Example usage:
1042 * @verbatim
1043 * // This scenario assumes xBacklightTimer has already been created. When a
1044 * // key is pressed, an LCD back-light is switched on. If 5 seconds pass
1045 * // without a key being pressed, then the LCD back-light is switched off. In
1046 * // this case, the timer is a one-shot timer, and unlike the example given for
1047 * // the xTimerReset() function, the key press event handler is an interrupt
1048 * // service routine.
1049 *
1050 * // The callback function assigned to the one-shot timer. In this case the
1051 * // parameter is not used.
1052 * void vBacklightTimerCallback( TimerHandle_t pxTimer )
1053 * {
1054 * // The timer expired, therefore 5 seconds must have passed since a key
1055 * // was pressed. Switch off the LCD back-light.
1056 * vSetBacklightState( BACKLIGHT_OFF );
1057 * }
1058 *
1059 * // The key press interrupt service routine.
1060 * void vKeyPressEventInterruptHandler( void )
1061 * {
1062 * BaseType_t xHigherPriorityTaskWoken = pdFALSE;
1063 *
1064 * // Ensure the LCD back-light is on, then reset the timer that is
1065 * // responsible for turning the back-light off after 5 seconds of
1066 * // key inactivity. This is an interrupt service routine so can only
1067 * // call FreeRTOS API functions that end in "FromISR".
1068 * vSetBacklightState( BACKLIGHT_ON );
1069 *
1070 * // xTimerStartFromISR() or xTimerResetFromISR() could be called here
1071 * // as both cause the timer to re-calculate its expiry time.
1072 * // xHigherPriorityTaskWoken was initialised to pdFALSE when it was
1073 * // declared (in this function).
1074 * if( xTimerResetFromISR( xBacklightTimer, &xHigherPriorityTaskWoken ) != pdPASS )
1075 * {
1076 * // The reset command was not executed successfully. Take appropriate
1077 * // action here.
1078 * }
1079 *
1080 * // Perform the rest of the key processing here.
1081 *
1082 * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch
1083 * // should be performed. The syntax required to perform a context switch
1084 * // from inside an ISR varies from port to port, and from compiler to
1085 * // compiler. Inspect the demos for the port you are using to find the
1086 * // actual syntax required.
1087 * if( xHigherPriorityTaskWoken != pdFALSE )
1088 * {
1089 * // Call the interrupt safe yield function here (actual function
1090 * // depends on the FreeRTOS port being used).
1091 * }
1092 * }
1093 * @endverbatim
1094 */
1095#define xTimerResetFromISR( xTimer, pxHigherPriorityTaskWoken ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_RESET_FROM_ISR, ( xTaskGetTickCountFromISR() ), ( pxHigherPriorityTaskWoken ), 0U )
1096
1097
1098/**
1099 * BaseType_t xTimerPendFunctionCallFromISR( PendedFunction_t xFunctionToPend,
1100 * void *pvParameter1,
1101 * uint32_t ulParameter2,
1102 * BaseType_t *pxHigherPriorityTaskWoken );
1103 *
1104 *
1105 * Used from application interrupt service routines to defer the execution of a
1106 * function to the RTOS daemon task (the timer service task, hence this function
1107 * is implemented in timers.c and is prefixed with 'Timer').
1108 *
1109 * Ideally an interrupt service routine (ISR) is kept as short as possible, but
1110 * sometimes an ISR either has a lot of processing to do, or needs to perform
1111 * processing that is not deterministic. In these cases
1112 * xTimerPendFunctionCallFromISR() can be used to defer processing of a function
1113 * to the RTOS daemon task.
1114 *
1115 * A mechanism is provided that allows the interrupt to return directly to the
1116 * task that will subsequently execute the pended callback function. This
1117 * allows the callback function to execute contiguously in time with the
1118 * interrupt - just as if the callback had executed in the interrupt itself.
1119 *
1120 * @param xFunctionToPend The function to execute from the timer service/
1121 * daemon task. The function must conform to the PendedFunction_t
1122 * prototype.
1123 *
1124 * @param pvParameter1 The value of the callback function's first parameter.
1125 * The parameter has a void * type to allow it to be used to pass any type.
1126 * For example, unsigned longs can be cast to a void *, or the void * can be
1127 * used to point to a structure.
1128 *
1129 * @param ulParameter2 The value of the callback function's second parameter.
1130 *
1131 * @param pxHigherPriorityTaskWoken As mentioned above, calling this function
1132 * will result in a message being sent to the timer daemon task. If the
1133 * priority of the timer daemon task (which is set using
1134 * configTIMER_TASK_PRIORITY in FreeRTOSConfig.h) is higher than the priority of
1135 * the currently running task (the task the interrupt interrupted) then
1136 * *pxHigherPriorityTaskWoken will be set to pdTRUE within
1137 * xTimerPendFunctionCallFromISR(), indicating that a context switch should be
1138 * requested before the interrupt exits. For that reason
1139 * *pxHigherPriorityTaskWoken must be initialised to pdFALSE. See the
1140 * example code below.
1141 *
1142 * @return pdPASS is returned if the message was successfully sent to the
1143 * timer daemon task, otherwise pdFALSE is returned.
1144 *
1145 * Example usage:
1146 * @verbatim
1147 *
1148 * // The callback function that will execute in the context of the daemon task.
1149 * // Note callback functions must all use this same prototype.
1150 * void vProcessInterface( void *pvParameter1, uint32_t ulParameter2 )
1151 * {
1152 * BaseType_t xInterfaceToService;
1153 *
1154 * // The interface that requires servicing is passed in the second
1155 * // parameter. The first parameter is not used in this case.
1156 * xInterfaceToService = ( BaseType_t ) ulParameter2;
1157 *
1158 * // ...Perform the processing here...
1159 * }
1160 *
1161 * // An ISR that receives data packets from multiple interfaces
1162 * void vAnISR( void )
1163 * {
1164 * BaseType_t xInterfaceToService, xHigherPriorityTaskWoken;
1165 *
1166 * // Query the hardware to determine which interface needs processing.
1167 * xInterfaceToService = prvCheckInterfaces();
1168 *
1169 * // The actual processing is to be deferred to a task. Request the
1170 * // vProcessInterface() callback function is executed, passing in the
1171 * // number of the interface that needs processing. The interface to
1172 * // service is passed in the second parameter. The first parameter is
1173 * // not used in this case.
1174 * xHigherPriorityTaskWoken = pdFALSE;
1175 * xTimerPendFunctionCallFromISR( vProcessInterface, NULL, ( uint32_t ) xInterfaceToService, &xHigherPriorityTaskWoken );
1176 *
1177 * // If xHigherPriorityTaskWoken is now set to pdTRUE then a context
1178 * // switch should be requested. The macro used is port specific and will
1179 * // be either portYIELD_FROM_ISR() or portEND_SWITCHING_ISR() - refer to
1180 * // the documentation page for the port being used.
1181 * portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
1182 *
1183 * }
1184 * @endverbatim
1185 */
1186BaseType_t xTimerPendFunctionCallFromISR( PendedFunction_t xFunctionToPend, void *pvParameter1, uint32_t ulParameter2, BaseType_t *pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
1187
1188 /**
1189 * BaseType_t xTimerPendFunctionCall( PendedFunction_t xFunctionToPend,
1190 * void *pvParameter1,
1191 * uint32_t ulParameter2,
1192 * TickType_t xTicksToWait );
1193 *
1194 *
1195 * Used to defer the execution of a function to the RTOS daemon task (the timer
1196 * service task, hence this function is implemented in timers.c and is prefixed
1197 * with 'Timer').
1198 *
1199 * @param xFunctionToPend The function to execute from the timer service/
1200 * daemon task. The function must conform to the PendedFunction_t
1201 * prototype.
1202 *
1203 * @param pvParameter1 The value of the callback function's first parameter.
1204 * The parameter has a void * type to allow it to be used to pass any type.
1205 * For example, unsigned longs can be cast to a void *, or the void * can be
1206 * used to point to a structure.
1207 *
1208 * @param ulParameter2 The value of the callback function's second parameter.
1209 *
1210 * @param xTicksToWait Calling this function will result in a message being
1211 * sent to the timer daemon task on a queue. xTicksToWait is the amount of
1212 * time the calling task should remain in the Blocked state (so not using any
1213 * processing time) for space to become available on the timer queue if the
1214 * queue is found to be full.
1215 *
1216 * @return pdPASS is returned if the message was successfully sent to the
1217 * timer daemon task, otherwise pdFALSE is returned.
1218 *
1219 */
1220BaseType_t xTimerPendFunctionCall( PendedFunction_t xFunctionToPend, void *pvParameter1, uint32_t ulParameter2, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
1221
1222/**
1223 * const char * const pcTimerGetName( TimerHandle_t xTimer );
1224 *
1225 * Returns the name that was assigned to a timer when the timer was created.
1226 *
1227 * @param xTimer The handle of the timer being queried.
1228 *
1229 * @return The name assigned to the timer specified by the xTimer parameter.
1230 */
1231const char * pcTimerGetName( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
1232
1233/**
1234 * TickType_t xTimerGetPeriod( TimerHandle_t xTimer );
1235 *
1236 * Returns the period of a timer.
1237 *
1238 * @param xTimer The handle of the timer being queried.
1239 *
1240 * @return The period of the timer in ticks.
1241 */
1242TickType_t xTimerGetPeriod( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
1243
1244/**
1245* TickType_t xTimerGetExpiryTime( TimerHandle_t xTimer );
1246*
1247* Returns the time in ticks at which the timer will expire. If this is less
1248* than the current tick count then the expiry time has overflowed from the
1249* current time.
1250*
1251* @param xTimer The handle of the timer being queried.
1252*
1253* @return If the timer is running then the time in ticks at which the timer
1254* will next expire is returned. If the timer is not running then the return
1255* value is undefined.
1256*/
1257TickType_t xTimerGetExpiryTime( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
1258
1259/*
1260 * Functions beyond this part are not part of the public API and are intended
1261 * for use by the kernel only.
1262 */
1263BaseType_t xTimerCreateTimerTask( void ) PRIVILEGED_FUNCTION;
1264BaseType_t xTimerGenericCommand( TimerHandle_t xTimer, const BaseType_t xCommandID, const TickType_t xOptionalValue, BaseType_t * const pxHigherPriorityTaskWoken, const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
1265
1266#if( configUSE_TRACE_FACILITY == 1 )
1267 void vTimerSetTimerNumber( TimerHandle_t xTimer, UBaseType_t uxTimerNumber ) PRIVILEGED_FUNCTION;
1268 UBaseType_t uxTimerGetTimerNumber( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
1269#endif
1270
1271#ifdef __cplusplus
1272}
1273#endif
1274#endif /* TIMERS_H */
1275
1276
1277