2 FreeRTOS V7.5.1 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
6 ***************************************************************************
\r
8 * FreeRTOS provides completely free yet professionally developed, *
\r
9 * robust, strictly quality controlled, supported, and cross *
\r
10 * platform software that has become a de facto standard. *
\r
12 * Help yourself get started quickly and support the FreeRTOS *
\r
13 * project by purchasing a FreeRTOS tutorial book, reference *
\r
14 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
18 ***************************************************************************
\r
20 This file is part of the FreeRTOS distribution.
\r
22 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
23 the terms of the GNU General Public License (version 2) as published by the
\r
24 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
26 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
27 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
28 >>! the source code for proprietary components outside of the FreeRTOS
\r
31 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
32 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
33 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
34 link: http://www.freertos.org/a00114.html
\r
38 ***************************************************************************
\r
40 * Having a problem? Start by reading the FAQ "My application does *
\r
41 * not run, what could be wrong?" *
\r
43 * http://www.FreeRTOS.org/FAQHelp.html *
\r
45 ***************************************************************************
\r
47 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
48 license and Real Time Engineers Ltd. contact details.
\r
50 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
51 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
52 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
54 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
55 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
56 licenses offer ticketed support, indemnification and middleware.
\r
58 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
59 engineered and independently SIL3 certified version for use in safety and
\r
60 mission critical applications that require provable dependability.
\r
69 #ifndef INC_FREERTOS_H
\r
70 #error "include FreeRTOS.h must appear in source files before include timers.h"
\r
73 /*lint -e537 This headers are only multiply included if the application code
\r
74 happens to also be including task.h. */
\r
82 /* IDs for commands that can be sent/received on the timer queue. These are to
\r
83 be used solely through the macros that make up the public software timer API,
\r
84 as defined below. */
\r
85 #define tmrCOMMAND_START ( ( portBASE_TYPE ) 0 )
\r
86 #define tmrCOMMAND_STOP ( ( portBASE_TYPE ) 1 )
\r
87 #define tmrCOMMAND_CHANGE_PERIOD ( ( portBASE_TYPE ) 2 )
\r
88 #define tmrCOMMAND_DELETE ( ( portBASE_TYPE ) 3 )
\r
90 /*-----------------------------------------------------------
\r
91 * MACROS AND DEFINITIONS
\r
92 *----------------------------------------------------------*/
\r
95 * Type by which software timers are referenced. For example, a call to
\r
96 * xTimerCreate() returns an xTimerHandle variable that can then be used to
\r
97 * reference the subject timer in calls to other software timer API functions
\r
98 * (for example, xTimerStart(), xTimerReset(), etc.).
\r
100 typedef void * xTimerHandle;
\r
102 /* Define the prototype to which timer callback functions must conform. */
\r
103 typedef void (*tmrTIMER_CALLBACK)( xTimerHandle xTimer );
\r
106 * xTimerHandle xTimerCreate( const signed char *pcTimerName,
\r
107 * portTickType xTimerPeriodInTicks,
\r
108 * unsigned portBASE_TYPE uxAutoReload,
\r
109 * void * pvTimerID,
\r
110 * tmrTIMER_CALLBACK pxCallbackFunction );
\r
112 * Creates a new software timer instance. This allocates the storage required
\r
113 * by the new timer, initialises the new timers internal state, and returns a
\r
114 * handle by which the new timer can be referenced.
\r
116 * Timers are created in the dormant state. The xTimerStart(), xTimerReset(),
\r
117 * xTimerStartFromISR(), xTimerResetFromISR(), xTimerChangePeriod() and
\r
118 * xTimerChangePeriodFromISR() API functions can all be used to transition a timer into the
\r
121 * @param pcTimerName A text name that is assigned to the timer. This is done
\r
122 * purely to assist debugging. The kernel itself only ever references a timer by
\r
123 * its handle, and never by its name.
\r
125 * @param xTimerPeriodInTicks The timer period. The time is defined in tick periods so
\r
126 * the constant portTICK_RATE_MS can be used to convert a time that has been
\r
127 * specified in milliseconds. For example, if the timer must expire after 100
\r
128 * ticks, then xTimerPeriodInTicks should be set to 100. Alternatively, if the timer
\r
129 * must expire after 500ms, then xPeriod can be set to ( 500 / portTICK_RATE_MS )
\r
130 * provided configTICK_RATE_HZ is less than or equal to 1000.
\r
132 * @param uxAutoReload If uxAutoReload is set to pdTRUE then the timer will
\r
133 * expire repeatedly with a frequency set by the xTimerPeriodInTicks parameter. If
\r
134 * uxAutoReload is set to pdFALSE then the timer will be a one-shot timer and
\r
135 * enter the dormant state after it expires.
\r
137 * @param pvTimerID An identifier that is assigned to the timer being created.
\r
138 * Typically this would be used in the timer callback function to identify which
\r
139 * timer expired when the same callback function is assigned to more than one
\r
142 * @param pxCallbackFunction The function to call when the timer expires.
\r
143 * Callback functions must have the prototype defined by tmrTIMER_CALLBACK,
\r
144 * which is "void vCallbackFunction( xTimerHandle xTimer );".
\r
146 * @return If the timer is successfully create then a handle to the newly
\r
147 * created timer is returned. If the timer cannot be created (because either
\r
148 * there is insufficient FreeRTOS heap remaining to allocate the timer
\r
149 * structures, or the timer period was set to 0) then 0 is returned.
\r
153 * #define NUM_TIMERS 5
\r
155 * // An array to hold handles to the created timers.
\r
156 * xTimerHandle xTimers[ NUM_TIMERS ];
\r
158 * // An array to hold a count of the number of times each timer expires.
\r
159 * long lExpireCounters[ NUM_TIMERS ] = { 0 };
\r
161 * // Define a callback function that will be used by multiple timer instances.
\r
162 * // The callback function does nothing but count the number of times the
\r
163 * // associated timer expires, and stop the timer once the timer has expired
\r
165 * void vTimerCallback( xTimerHandle pxTimer )
\r
167 * long lArrayIndex;
\r
168 * const long xMaxExpiryCountBeforeStopping = 10;
\r
170 * // Optionally do something if the pxTimer parameter is NULL.
\r
171 * configASSERT( pxTimer );
\r
173 * // Which timer expired?
\r
174 * lArrayIndex = ( long ) pvTimerGetTimerID( pxTimer );
\r
176 * // Increment the number of times that pxTimer has expired.
\r
177 * lExpireCounters[ lArrayIndex ] += 1;
\r
179 * // If the timer has expired 10 times then stop it from running.
\r
180 * if( lExpireCounters[ lArrayIndex ] == xMaxExpiryCountBeforeStopping )
\r
182 * // Do not use a block time if calling a timer API function from a
\r
183 * // timer callback function, as doing so could cause a deadlock!
\r
184 * xTimerStop( pxTimer, 0 );
\r
188 * void main( void )
\r
192 * // Create then start some timers. Starting the timers before the scheduler
\r
193 * // has been started means the timers will start running immediately that
\r
194 * // the scheduler starts.
\r
195 * for( x = 0; x < NUM_TIMERS; x++ )
\r
197 * xTimers[ x ] = xTimerCreate( "Timer", // Just a text name, not used by the kernel.
\r
198 * ( 100 * x ), // The timer period in ticks.
\r
199 * pdTRUE, // The timers will auto-reload themselves when they expire.
\r
200 * ( void * ) x, // Assign each timer a unique id equal to its array index.
\r
201 * vTimerCallback // Each timer calls the same callback when it expires.
\r
204 * if( xTimers[ x ] == NULL )
\r
206 * // The timer was not created.
\r
210 * // Start the timer. No block time is specified, and even if one was
\r
211 * // it would be ignored because the scheduler has not yet been
\r
213 * if( xTimerStart( xTimers[ x ], 0 ) != pdPASS )
\r
215 * // The timer could not be set into the Active state.
\r
221 * // Create tasks here.
\r
224 * // Starting the scheduler will start the timers running as they have already
\r
225 * // been set into the active state.
\r
226 * xTaskStartScheduler();
\r
228 * // Should not reach here.
\r
233 xTimerHandle xTimerCreate( const signed char * const pcTimerName, portTickType xTimerPeriodInTicks, unsigned portBASE_TYPE uxAutoReload, void * pvTimerID, tmrTIMER_CALLBACK pxCallbackFunction ) PRIVILEGED_FUNCTION;
\r
236 * void *pvTimerGetTimerID( xTimerHandle xTimer );
\r
238 * Returns the ID assigned to the timer.
\r
240 * IDs are assigned to timers using the pvTimerID parameter of the call to
\r
241 * xTimerCreated() that was used to create the timer.
\r
243 * If the same callback function is assigned to multiple timers then the timer
\r
244 * ID can be used within the callback function to identify which timer actually
\r
247 * @param xTimer The timer being queried.
\r
249 * @return The ID assigned to the timer being queried.
\r
253 * See the xTimerCreate() API function example usage scenario.
\r
255 void *pvTimerGetTimerID( xTimerHandle xTimer ) PRIVILEGED_FUNCTION;
\r
258 * portBASE_TYPE xTimerIsTimerActive( xTimerHandle xTimer );
\r
260 * Queries a timer to see if it is active or dormant.
\r
262 * A timer will be dormant if:
\r
263 * 1) It has been created but not started, or
\r
264 * 2) It is an expired on-shot timer that has not been restarted.
\r
266 * Timers are created in the dormant state. The xTimerStart(), xTimerReset(),
\r
267 * xTimerStartFromISR(), xTimerResetFromISR(), xTimerChangePeriod() and
\r
268 * xTimerChangePeriodFromISR() API functions can all be used to transition a timer into the
\r
271 * @param xTimer The timer being queried.
\r
273 * @return pdFALSE will be returned if the timer is dormant. A value other than
\r
274 * pdFALSE will be returned if the timer is active.
\r
278 * // This function assumes xTimer has already been created.
\r
279 * void vAFunction( xTimerHandle xTimer )
\r
281 * if( xTimerIsTimerActive( xTimer ) != pdFALSE ) // or more simply and equivalently "if( xTimerIsTimerActive( xTimer ) )"
\r
283 * // xTimer is active, do something.
\r
287 * // xTimer is not active, do something else.
\r
292 portBASE_TYPE xTimerIsTimerActive( xTimerHandle xTimer ) PRIVILEGED_FUNCTION;
\r
295 * xTimerGetTimerDaemonTaskHandle() is only available if
\r
296 * INCLUDE_xTimerGetTimerDaemonTaskHandle is set to 1 in FreeRTOSConfig.h.
\r
298 * Simply returns the handle of the timer service/daemon task. It it not valid
\r
299 * to call xTimerGetTimerDaemonTaskHandle() before the scheduler has been started.
\r
301 xTaskHandle xTimerGetTimerDaemonTaskHandle( void );
\r
304 * portBASE_TYPE xTimerStart( xTimerHandle xTimer, portTickType xBlockTime );
\r
306 * Timer functionality is provided by a timer service/daemon task. Many of the
\r
307 * public FreeRTOS timer API functions send commands to the timer service task
\r
308 * though a queue called the timer command queue. The timer command queue is
\r
309 * private to the kernel itself and is not directly accessible to application
\r
310 * code. The length of the timer command queue is set by the
\r
311 * configTIMER_QUEUE_LENGTH configuration constant.
\r
313 * xTimerStart() starts a timer that was previously created using the
\r
314 * xTimerCreate() API function. If the timer had already been started and was
\r
315 * already in the active state, then xTimerStart() has equivalent functionality
\r
316 * to the xTimerReset() API function.
\r
318 * Starting a timer ensures the timer is in the active state. If the timer
\r
319 * is not stopped, deleted, or reset in the mean time, the callback function
\r
320 * associated with the timer will get called 'n' ticks after xTimerStart() was
\r
321 * called, where 'n' is the timers defined period.
\r
323 * It is valid to call xTimerStart() before the scheduler has been started, but
\r
324 * when this is done the timer will not actually start until the scheduler is
\r
325 * started, and the timers expiry time will be relative to when the scheduler is
\r
326 * started, not relative to when xTimerStart() was called.
\r
328 * The configUSE_TIMERS configuration constant must be set to 1 for xTimerStart()
\r
331 * @param xTimer The handle of the timer being started/restarted.
\r
333 * @param xBlockTime Specifies the time, in ticks, that the calling task should
\r
334 * be held in the Blocked state to wait for the start command to be successfully
\r
335 * sent to the timer command queue, should the queue already be full when
\r
336 * xTimerStart() was called. xBlockTime is ignored if xTimerStart() is called
\r
337 * before the scheduler is started.
\r
339 * @return pdFAIL will be returned if the start command could not be sent to
\r
340 * the timer command queue even after xBlockTime ticks had passed. pdPASS will
\r
341 * be returned if the command was successfully sent to the timer command queue.
\r
342 * When the command is actually processed will depend on the priority of the
\r
343 * timer service/daemon task relative to other tasks in the system, although the
\r
344 * timers expiry time is relative to when xTimerStart() is actually called. The
\r
345 * timer service/daemon task priority is set by the configTIMER_TASK_PRIORITY
\r
346 * configuration constant.
\r
350 * See the xTimerCreate() API function example usage scenario.
\r
353 #define xTimerStart( xTimer, xBlockTime ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_START, ( xTaskGetTickCount() ), NULL, ( xBlockTime ) )
\r
356 * portBASE_TYPE xTimerStop( xTimerHandle xTimer, portTickType xBlockTime );
\r
358 * Timer functionality is provided by a timer service/daemon task. Many of the
\r
359 * public FreeRTOS timer API functions send commands to the timer service task
\r
360 * though a queue called the timer command queue. The timer command queue is
\r
361 * private to the kernel itself and is not directly accessible to application
\r
362 * code. The length of the timer command queue is set by the
\r
363 * configTIMER_QUEUE_LENGTH configuration constant.
\r
365 * xTimerStop() stops a timer that was previously started using either of the
\r
366 * The xTimerStart(), xTimerReset(), xTimerStartFromISR(), xTimerResetFromISR(),
\r
367 * xTimerChangePeriod() or xTimerChangePeriodFromISR() API functions.
\r
369 * Stopping a timer ensures the timer is not in the active state.
\r
371 * The configUSE_TIMERS configuration constant must be set to 1 for xTimerStop()
\r
374 * @param xTimer The handle of the timer being stopped.
\r
376 * @param xBlockTime Specifies the time, in ticks, that the calling task should
\r
377 * be held in the Blocked state to wait for the stop command to be successfully
\r
378 * sent to the timer command queue, should the queue already be full when
\r
379 * xTimerStop() was called. xBlockTime is ignored if xTimerStop() is called
\r
380 * before the scheduler is started.
\r
382 * @return pdFAIL will be returned if the stop command could not be sent to
\r
383 * the timer command queue even after xBlockTime ticks had passed. pdPASS will
\r
384 * be returned if the command was successfully sent to the timer command queue.
\r
385 * When the command is actually processed will depend on the priority of the
\r
386 * timer service/daemon task relative to other tasks in the system. The timer
\r
387 * service/daemon task priority is set by the configTIMER_TASK_PRIORITY
\r
388 * configuration constant.
\r
392 * See the xTimerCreate() API function example usage scenario.
\r
395 #define xTimerStop( xTimer, xBlockTime ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_STOP, 0U, NULL, ( xBlockTime ) )
\r
398 * portBASE_TYPE xTimerChangePeriod( xTimerHandle xTimer,
\r
399 * portTickType xNewPeriod,
\r
400 * portTickType xBlockTime );
\r
402 * Timer functionality is provided by a timer service/daemon task. Many of the
\r
403 * public FreeRTOS timer API functions send commands to the timer service task
\r
404 * though a queue called the timer command queue. The timer command queue is
\r
405 * private to the kernel itself and is not directly accessible to application
\r
406 * code. The length of the timer command queue is set by the
\r
407 * configTIMER_QUEUE_LENGTH configuration constant.
\r
409 * xTimerChangePeriod() changes the period of a timer that was previously
\r
410 * created using the xTimerCreate() API function.
\r
412 * xTimerChangePeriod() can be called to change the period of an active or
\r
413 * dormant state timer.
\r
415 * The configUSE_TIMERS configuration constant must be set to 1 for
\r
416 * xTimerChangePeriod() to be available.
\r
418 * @param xTimer The handle of the timer that is having its period changed.
\r
420 * @param xNewPeriod The new period for xTimer. Timer periods are specified in
\r
421 * tick periods, so the constant portTICK_RATE_MS can be used to convert a time
\r
422 * that has been specified in milliseconds. For example, if the timer must
\r
423 * expire after 100 ticks, then xNewPeriod should be set to 100. Alternatively,
\r
424 * if the timer must expire after 500ms, then xNewPeriod can be set to
\r
425 * ( 500 / portTICK_RATE_MS ) provided configTICK_RATE_HZ is less than
\r
426 * or equal to 1000.
\r
428 * @param xBlockTime Specifies the time, in ticks, that the calling task should
\r
429 * be held in the Blocked state to wait for the change period command to be
\r
430 * successfully sent to the timer command queue, should the queue already be
\r
431 * full when xTimerChangePeriod() was called. xBlockTime is ignored if
\r
432 * xTimerChangePeriod() is called before the scheduler is started.
\r
434 * @return pdFAIL will be returned if the change period command could not be
\r
435 * sent to the timer command queue even after xBlockTime ticks had passed.
\r
436 * pdPASS will be returned if the command was successfully sent to the timer
\r
437 * command queue. When the command is actually processed will depend on the
\r
438 * priority of the timer service/daemon task relative to other tasks in the
\r
439 * system. The timer service/daemon task priority is set by the
\r
440 * configTIMER_TASK_PRIORITY configuration constant.
\r
444 * // This function assumes xTimer has already been created. If the timer
\r
445 * // referenced by xTimer is already active when it is called, then the timer
\r
446 * // is deleted. If the timer referenced by xTimer is not active when it is
\r
447 * // called, then the period of the timer is set to 500ms and the timer is
\r
449 * void vAFunction( xTimerHandle xTimer )
\r
451 * if( xTimerIsTimerActive( xTimer ) != pdFALSE ) // or more simply and equivalently "if( xTimerIsTimerActive( xTimer ) )"
\r
453 * // xTimer is already active - delete it.
\r
454 * xTimerDelete( xTimer );
\r
458 * // xTimer is not active, change its period to 500ms. This will also
\r
459 * // cause the timer to start. Block for a maximum of 100 ticks if the
\r
460 * // change period command cannot immediately be sent to the timer
\r
461 * // command queue.
\r
462 * if( xTimerChangePeriod( xTimer, 500 / portTICK_RATE_MS, 100 ) == pdPASS )
\r
464 * // The command was successfully sent.
\r
468 * // The command could not be sent, even after waiting for 100 ticks
\r
469 * // to pass. Take appropriate action here.
\r
475 #define xTimerChangePeriod( xTimer, xNewPeriod, xBlockTime ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_CHANGE_PERIOD, ( xNewPeriod ), NULL, ( xBlockTime ) )
\r
478 * portBASE_TYPE xTimerDelete( xTimerHandle xTimer, portTickType xBlockTime );
\r
480 * Timer functionality is provided by a timer service/daemon task. Many of the
\r
481 * public FreeRTOS timer API functions send commands to the timer service task
\r
482 * though a queue called the timer command queue. The timer command queue is
\r
483 * private to the kernel itself and is not directly accessible to application
\r
484 * code. The length of the timer command queue is set by the
\r
485 * configTIMER_QUEUE_LENGTH configuration constant.
\r
487 * xTimerDelete() deletes a timer that was previously created using the
\r
488 * xTimerCreate() API function.
\r
490 * The configUSE_TIMERS configuration constant must be set to 1 for
\r
491 * xTimerDelete() to be available.
\r
493 * @param xTimer The handle of the timer being deleted.
\r
495 * @param xBlockTime Specifies the time, in ticks, that the calling task should
\r
496 * be held in the Blocked state to wait for the delete command to be
\r
497 * successfully sent to the timer command queue, should the queue already be
\r
498 * full when xTimerDelete() was called. xBlockTime is ignored if xTimerDelete()
\r
499 * is called before the scheduler is started.
\r
501 * @return pdFAIL will be returned if the delete command could not be sent to
\r
502 * the timer command queue even after xBlockTime ticks had passed. pdPASS will
\r
503 * be returned if the command was successfully sent to the timer command queue.
\r
504 * When the command is actually processed will depend on the priority of the
\r
505 * timer service/daemon task relative to other tasks in the system. The timer
\r
506 * service/daemon task priority is set by the configTIMER_TASK_PRIORITY
\r
507 * configuration constant.
\r
511 * See the xTimerChangePeriod() API function example usage scenario.
\r
513 #define xTimerDelete( xTimer, xBlockTime ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_DELETE, 0U, NULL, ( xBlockTime ) )
\r
516 * portBASE_TYPE xTimerReset( xTimerHandle xTimer, portTickType xBlockTime );
\r
518 * Timer functionality is provided by a timer service/daemon task. Many of the
\r
519 * public FreeRTOS timer API functions send commands to the timer service task
\r
520 * though a queue called the timer command queue. The timer command queue is
\r
521 * private to the kernel itself and is not directly accessible to application
\r
522 * code. The length of the timer command queue is set by the
\r
523 * configTIMER_QUEUE_LENGTH configuration constant.
\r
525 * xTimerReset() re-starts a timer that was previously created using the
\r
526 * xTimerCreate() API function. If the timer had already been started and was
\r
527 * already in the active state, then xTimerReset() will cause the timer to
\r
528 * re-evaluate its expiry time so that it is relative to when xTimerReset() was
\r
529 * called. If the timer was in the dormant state then xTimerReset() has
\r
530 * equivalent functionality to the xTimerStart() API function.
\r
532 * Resetting a timer ensures the timer is in the active state. If the timer
\r
533 * is not stopped, deleted, or reset in the mean time, the callback function
\r
534 * associated with the timer will get called 'n' ticks after xTimerReset() was
\r
535 * called, where 'n' is the timers defined period.
\r
537 * It is valid to call xTimerReset() before the scheduler has been started, but
\r
538 * when this is done the timer will not actually start until the scheduler is
\r
539 * started, and the timers expiry time will be relative to when the scheduler is
\r
540 * started, not relative to when xTimerReset() was called.
\r
542 * The configUSE_TIMERS configuration constant must be set to 1 for xTimerReset()
\r
545 * @param xTimer The handle of the timer being reset/started/restarted.
\r
547 * @param xBlockTime Specifies the time, in ticks, that the calling task should
\r
548 * be held in the Blocked state to wait for the reset command to be successfully
\r
549 * sent to the timer command queue, should the queue already be full when
\r
550 * xTimerReset() was called. xBlockTime is ignored if xTimerReset() is called
\r
551 * before the scheduler is started.
\r
553 * @return pdFAIL will be returned if the reset command could not be sent to
\r
554 * the timer command queue even after xBlockTime ticks had passed. pdPASS will
\r
555 * be returned if the command was successfully sent to the timer command queue.
\r
556 * When the command is actually processed will depend on the priority of the
\r
557 * timer service/daemon task relative to other tasks in the system, although the
\r
558 * timers expiry time is relative to when xTimerStart() is actually called. The
\r
559 * timer service/daemon task priority is set by the configTIMER_TASK_PRIORITY
\r
560 * configuration constant.
\r
564 * // When a key is pressed, an LCD back-light is switched on. If 5 seconds pass
\r
565 * // without a key being pressed, then the LCD back-light is switched off. In
\r
566 * // this case, the timer is a one-shot timer.
\r
568 * xTimerHandle xBacklightTimer = NULL;
\r
570 * // The callback function assigned to the one-shot timer. In this case the
\r
571 * // parameter is not used.
\r
572 * void vBacklightTimerCallback( xTimerHandle pxTimer )
\r
574 * // The timer expired, therefore 5 seconds must have passed since a key
\r
575 * // was pressed. Switch off the LCD back-light.
\r
576 * vSetBacklightState( BACKLIGHT_OFF );
\r
579 * // The key press event handler.
\r
580 * void vKeyPressEventHandler( char cKey )
\r
582 * // Ensure the LCD back-light is on, then reset the timer that is
\r
583 * // responsible for turning the back-light off after 5 seconds of
\r
584 * // key inactivity. Wait 10 ticks for the command to be successfully sent
\r
585 * // if it cannot be sent immediately.
\r
586 * vSetBacklightState( BACKLIGHT_ON );
\r
587 * if( xTimerReset( xBacklightTimer, 100 ) != pdPASS )
\r
589 * // The reset command was not executed successfully. Take appropriate
\r
593 * // Perform the rest of the key processing here.
\r
596 * void main( void )
\r
600 * // Create then start the one-shot timer that is responsible for turning
\r
601 * // the back-light off if no keys are pressed within a 5 second period.
\r
602 * xBacklightTimer = xTimerCreate( "BacklightTimer", // Just a text name, not used by the kernel.
\r
603 * ( 5000 / portTICK_RATE_MS), // The timer period in ticks.
\r
604 * pdFALSE, // The timer is a one-shot timer.
\r
605 * 0, // The id is not used by the callback so can take any value.
\r
606 * vBacklightTimerCallback // The callback function that switches the LCD back-light off.
\r
609 * if( xBacklightTimer == NULL )
\r
611 * // The timer was not created.
\r
615 * // Start the timer. No block time is specified, and even if one was
\r
616 * // it would be ignored because the scheduler has not yet been
\r
618 * if( xTimerStart( xBacklightTimer, 0 ) != pdPASS )
\r
620 * // The timer could not be set into the Active state.
\r
625 * // Create tasks here.
\r
628 * // Starting the scheduler will start the timer running as it has already
\r
629 * // been set into the active state.
\r
630 * xTaskStartScheduler();
\r
632 * // Should not reach here.
\r
637 #define xTimerReset( xTimer, xBlockTime ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_START, ( xTaskGetTickCount() ), NULL, ( xBlockTime ) )
\r
640 * portBASE_TYPE xTimerStartFromISR( xTimerHandle xTimer,
\r
641 * portBASE_TYPE *pxHigherPriorityTaskWoken );
\r
643 * A version of xTimerStart() that can be called from an interrupt service
\r
646 * @param xTimer The handle of the timer being started/restarted.
\r
648 * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most
\r
649 * of its time in the Blocked state, waiting for messages to arrive on the timer
\r
650 * command queue. Calling xTimerStartFromISR() writes a message to the timer
\r
651 * command queue, so has the potential to transition the timer service/daemon
\r
652 * task out of the Blocked state. If calling xTimerStartFromISR() causes the
\r
653 * timer service/daemon task to leave the Blocked state, and the timer service/
\r
654 * daemon task has a priority equal to or greater than the currently executing
\r
655 * task (the task that was interrupted), then *pxHigherPriorityTaskWoken will
\r
656 * get set to pdTRUE internally within the xTimerStartFromISR() function. If
\r
657 * xTimerStartFromISR() sets this value to pdTRUE then a context switch should
\r
658 * be performed before the interrupt exits.
\r
660 * @return pdFAIL will be returned if the start command could not be sent to
\r
661 * the timer command queue. pdPASS will be returned if the command was
\r
662 * successfully sent to the timer command queue. When the command is actually
\r
663 * processed will depend on the priority of the timer service/daemon task
\r
664 * relative to other tasks in the system, although the timers expiry time is
\r
665 * relative to when xTimerStartFromISR() is actually called. The timer service/daemon
\r
666 * task priority is set by the configTIMER_TASK_PRIORITY configuration constant.
\r
670 * // This scenario assumes xBacklightTimer has already been created. When a
\r
671 * // key is pressed, an LCD back-light is switched on. If 5 seconds pass
\r
672 * // without a key being pressed, then the LCD back-light is switched off. In
\r
673 * // this case, the timer is a one-shot timer, and unlike the example given for
\r
674 * // the xTimerReset() function, the key press event handler is an interrupt
\r
675 * // service routine.
\r
677 * // The callback function assigned to the one-shot timer. In this case the
\r
678 * // parameter is not used.
\r
679 * void vBacklightTimerCallback( xTimerHandle pxTimer )
\r
681 * // The timer expired, therefore 5 seconds must have passed since a key
\r
682 * // was pressed. Switch off the LCD back-light.
\r
683 * vSetBacklightState( BACKLIGHT_OFF );
\r
686 * // The key press interrupt service routine.
\r
687 * void vKeyPressEventInterruptHandler( void )
\r
689 * portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
691 * // Ensure the LCD back-light is on, then restart the timer that is
\r
692 * // responsible for turning the back-light off after 5 seconds of
\r
693 * // key inactivity. This is an interrupt service routine so can only
\r
694 * // call FreeRTOS API functions that end in "FromISR".
\r
695 * vSetBacklightState( BACKLIGHT_ON );
\r
697 * // xTimerStartFromISR() or xTimerResetFromISR() could be called here
\r
698 * // as both cause the timer to re-calculate its expiry time.
\r
699 * // xHigherPriorityTaskWoken was initialised to pdFALSE when it was
\r
700 * // declared (in this function).
\r
701 * if( xTimerStartFromISR( xBacklightTimer, &xHigherPriorityTaskWoken ) != pdPASS )
\r
703 * // The start command was not executed successfully. Take appropriate
\r
707 * // Perform the rest of the key processing here.
\r
709 * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch
\r
710 * // should be performed. The syntax required to perform a context switch
\r
711 * // from inside an ISR varies from port to port, and from compiler to
\r
712 * // compiler. Inspect the demos for the port you are using to find the
\r
713 * // actual syntax required.
\r
714 * if( xHigherPriorityTaskWoken != pdFALSE )
\r
716 * // Call the interrupt safe yield function here (actual function
\r
717 * // depends on the FreeRTOS port being used.
\r
722 #define xTimerStartFromISR( xTimer, pxHigherPriorityTaskWoken ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_START, ( xTaskGetTickCountFromISR() ), ( pxHigherPriorityTaskWoken ), 0U )
\r
725 * portBASE_TYPE xTimerStopFromISR( xTimerHandle xTimer,
\r
726 * portBASE_TYPE *pxHigherPriorityTaskWoken );
\r
728 * A version of xTimerStop() that can be called from an interrupt service
\r
731 * @param xTimer The handle of the timer being stopped.
\r
733 * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most
\r
734 * of its time in the Blocked state, waiting for messages to arrive on the timer
\r
735 * command queue. Calling xTimerStopFromISR() writes a message to the timer
\r
736 * command queue, so has the potential to transition the timer service/daemon
\r
737 * task out of the Blocked state. If calling xTimerStopFromISR() causes the
\r
738 * timer service/daemon task to leave the Blocked state, and the timer service/
\r
739 * daemon task has a priority equal to or greater than the currently executing
\r
740 * task (the task that was interrupted), then *pxHigherPriorityTaskWoken will
\r
741 * get set to pdTRUE internally within the xTimerStopFromISR() function. If
\r
742 * xTimerStopFromISR() sets this value to pdTRUE then a context switch should
\r
743 * be performed before the interrupt exits.
\r
745 * @return pdFAIL will be returned if the stop command could not be sent to
\r
746 * the timer command queue. pdPASS will be returned if the command was
\r
747 * successfully sent to the timer command queue. When the command is actually
\r
748 * processed will depend on the priority of the timer service/daemon task
\r
749 * relative to other tasks in the system. The timer service/daemon task
\r
750 * priority is set by the configTIMER_TASK_PRIORITY configuration constant.
\r
754 * // This scenario assumes xTimer has already been created and started. When
\r
755 * // an interrupt occurs, the timer should be simply stopped.
\r
757 * // The interrupt service routine that stops the timer.
\r
758 * void vAnExampleInterruptServiceRoutine( void )
\r
760 * portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
762 * // The interrupt has occurred - simply stop the timer.
\r
763 * // xHigherPriorityTaskWoken was set to pdFALSE where it was defined
\r
764 * // (within this function). As this is an interrupt service routine, only
\r
765 * // FreeRTOS API functions that end in "FromISR" can be used.
\r
766 * if( xTimerStopFromISR( xTimer, &xHigherPriorityTaskWoken ) != pdPASS )
\r
768 * // The stop command was not executed successfully. Take appropriate
\r
772 * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch
\r
773 * // should be performed. The syntax required to perform a context switch
\r
774 * // from inside an ISR varies from port to port, and from compiler to
\r
775 * // compiler. Inspect the demos for the port you are using to find the
\r
776 * // actual syntax required.
\r
777 * if( xHigherPriorityTaskWoken != pdFALSE )
\r
779 * // Call the interrupt safe yield function here (actual function
\r
780 * // depends on the FreeRTOS port being used.
\r
785 #define xTimerStopFromISR( xTimer, pxHigherPriorityTaskWoken ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_STOP, 0, ( pxHigherPriorityTaskWoken ), 0U )
\r
788 * portBASE_TYPE xTimerChangePeriodFromISR( xTimerHandle xTimer,
\r
789 * portTickType xNewPeriod,
\r
790 * portBASE_TYPE *pxHigherPriorityTaskWoken );
\r
792 * A version of xTimerChangePeriod() that can be called from an interrupt
\r
795 * @param xTimer The handle of the timer that is having its period changed.
\r
797 * @param xNewPeriod The new period for xTimer. Timer periods are specified in
\r
798 * tick periods, so the constant portTICK_RATE_MS can be used to convert a time
\r
799 * that has been specified in milliseconds. For example, if the timer must
\r
800 * expire after 100 ticks, then xNewPeriod should be set to 100. Alternatively,
\r
801 * if the timer must expire after 500ms, then xNewPeriod can be set to
\r
802 * ( 500 / portTICK_RATE_MS ) provided configTICK_RATE_HZ is less than
\r
803 * or equal to 1000.
\r
805 * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most
\r
806 * of its time in the Blocked state, waiting for messages to arrive on the timer
\r
807 * command queue. Calling xTimerChangePeriodFromISR() writes a message to the
\r
808 * timer command queue, so has the potential to transition the timer service/
\r
809 * daemon task out of the Blocked state. If calling xTimerChangePeriodFromISR()
\r
810 * causes the timer service/daemon task to leave the Blocked state, and the
\r
811 * timer service/daemon task has a priority equal to or greater than the
\r
812 * currently executing task (the task that was interrupted), then
\r
813 * *pxHigherPriorityTaskWoken will get set to pdTRUE internally within the
\r
814 * xTimerChangePeriodFromISR() function. If xTimerChangePeriodFromISR() sets
\r
815 * this value to pdTRUE then a context switch should be performed before the
\r
818 * @return pdFAIL will be returned if the command to change the timers period
\r
819 * could not be sent to the timer command queue. pdPASS will be returned if the
\r
820 * command was successfully sent to the timer command queue. When the command
\r
821 * is actually processed will depend on the priority of the timer service/daemon
\r
822 * task relative to other tasks in the system. The timer service/daemon task
\r
823 * priority is set by the configTIMER_TASK_PRIORITY configuration constant.
\r
827 * // This scenario assumes xTimer has already been created and started. When
\r
828 * // an interrupt occurs, the period of xTimer should be changed to 500ms.
\r
830 * // The interrupt service routine that changes the period of xTimer.
\r
831 * void vAnExampleInterruptServiceRoutine( void )
\r
833 * portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
835 * // The interrupt has occurred - change the period of xTimer to 500ms.
\r
836 * // xHigherPriorityTaskWoken was set to pdFALSE where it was defined
\r
837 * // (within this function). As this is an interrupt service routine, only
\r
838 * // FreeRTOS API functions that end in "FromISR" can be used.
\r
839 * if( xTimerChangePeriodFromISR( xTimer, &xHigherPriorityTaskWoken ) != pdPASS )
\r
841 * // The command to change the timers period was not executed
\r
842 * // successfully. Take appropriate action here.
\r
845 * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch
\r
846 * // should be performed. The syntax required to perform a context switch
\r
847 * // from inside an ISR varies from port to port, and from compiler to
\r
848 * // compiler. Inspect the demos for the port you are using to find the
\r
849 * // actual syntax required.
\r
850 * if( xHigherPriorityTaskWoken != pdFALSE )
\r
852 * // Call the interrupt safe yield function here (actual function
\r
853 * // depends on the FreeRTOS port being used.
\r
858 #define xTimerChangePeriodFromISR( xTimer, xNewPeriod, pxHigherPriorityTaskWoken ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_CHANGE_PERIOD, ( xNewPeriod ), ( pxHigherPriorityTaskWoken ), 0U )
\r
861 * portBASE_TYPE xTimerResetFromISR( xTimerHandle xTimer,
\r
862 * portBASE_TYPE *pxHigherPriorityTaskWoken );
\r
864 * A version of xTimerReset() that can be called from an interrupt service
\r
867 * @param xTimer The handle of the timer that is to be started, reset, or
\r
870 * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most
\r
871 * of its time in the Blocked state, waiting for messages to arrive on the timer
\r
872 * command queue. Calling xTimerResetFromISR() writes a message to the timer
\r
873 * command queue, so has the potential to transition the timer service/daemon
\r
874 * task out of the Blocked state. If calling xTimerResetFromISR() causes the
\r
875 * timer service/daemon task to leave the Blocked state, and the timer service/
\r
876 * daemon task has a priority equal to or greater than the currently executing
\r
877 * task (the task that was interrupted), then *pxHigherPriorityTaskWoken will
\r
878 * get set to pdTRUE internally within the xTimerResetFromISR() function. If
\r
879 * xTimerResetFromISR() sets this value to pdTRUE then a context switch should
\r
880 * be performed before the interrupt exits.
\r
882 * @return pdFAIL will be returned if the reset command could not be sent to
\r
883 * the timer command queue. pdPASS will be returned if the command was
\r
884 * successfully sent to the timer command queue. When the command is actually
\r
885 * processed will depend on the priority of the timer service/daemon task
\r
886 * relative to other tasks in the system, although the timers expiry time is
\r
887 * relative to when xTimerResetFromISR() is actually called. The timer service/daemon
\r
888 * task priority is set by the configTIMER_TASK_PRIORITY configuration constant.
\r
892 * // This scenario assumes xBacklightTimer has already been created. When a
\r
893 * // key is pressed, an LCD back-light is switched on. If 5 seconds pass
\r
894 * // without a key being pressed, then the LCD back-light is switched off. In
\r
895 * // this case, the timer is a one-shot timer, and unlike the example given for
\r
896 * // the xTimerReset() function, the key press event handler is an interrupt
\r
897 * // service routine.
\r
899 * // The callback function assigned to the one-shot timer. In this case the
\r
900 * // parameter is not used.
\r
901 * void vBacklightTimerCallback( xTimerHandle pxTimer )
\r
903 * // The timer expired, therefore 5 seconds must have passed since a key
\r
904 * // was pressed. Switch off the LCD back-light.
\r
905 * vSetBacklightState( BACKLIGHT_OFF );
\r
908 * // The key press interrupt service routine.
\r
909 * void vKeyPressEventInterruptHandler( void )
\r
911 * portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
913 * // Ensure the LCD back-light is on, then reset the timer that is
\r
914 * // responsible for turning the back-light off after 5 seconds of
\r
915 * // key inactivity. This is an interrupt service routine so can only
\r
916 * // call FreeRTOS API functions that end in "FromISR".
\r
917 * vSetBacklightState( BACKLIGHT_ON );
\r
919 * // xTimerStartFromISR() or xTimerResetFromISR() could be called here
\r
920 * // as both cause the timer to re-calculate its expiry time.
\r
921 * // xHigherPriorityTaskWoken was initialised to pdFALSE when it was
\r
922 * // declared (in this function).
\r
923 * if( xTimerResetFromISR( xBacklightTimer, &xHigherPriorityTaskWoken ) != pdPASS )
\r
925 * // The reset command was not executed successfully. Take appropriate
\r
929 * // Perform the rest of the key processing here.
\r
931 * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch
\r
932 * // should be performed. The syntax required to perform a context switch
\r
933 * // from inside an ISR varies from port to port, and from compiler to
\r
934 * // compiler. Inspect the demos for the port you are using to find the
\r
935 * // actual syntax required.
\r
936 * if( xHigherPriorityTaskWoken != pdFALSE )
\r
938 * // Call the interrupt safe yield function here (actual function
\r
939 * // depends on the FreeRTOS port being used.
\r
944 #define xTimerResetFromISR( xTimer, pxHigherPriorityTaskWoken ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_START, ( xTaskGetTickCountFromISR() ), ( pxHigherPriorityTaskWoken ), 0U )
\r
947 * Functions beyond this part are not part of the public API and are intended
\r
948 * for use by the kernel only.
\r
950 portBASE_TYPE xTimerCreateTimerTask( void ) PRIVILEGED_FUNCTION;
\r
951 portBASE_TYPE xTimerGenericCommand( xTimerHandle xTimer, portBASE_TYPE xCommandID, portTickType xOptionalValue, signed portBASE_TYPE *pxHigherPriorityTaskWoken, portTickType xBlockTime ) PRIVILEGED_FUNCTION;
\r
956 #endif /* TIMERS_H */
\r