timers.h
Go to the documentation of this file.
1 /*
2  FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.
3  All rights reserved
4 
5  VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
6 
7  This file is part of the FreeRTOS distribution.
8 
9  FreeRTOS is free software; you can redistribute it and/or modify it under
10  the terms of the GNU General Public License (version 2) as published by the
11  Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
12 
13  ***************************************************************************
14  >>! NOTE: The modification to the GPL is included to allow you to !<<
15  >>! distribute a combined work that includes FreeRTOS without being !<<
16  >>! obliged to provide the source code for proprietary components !<<
17  >>! outside of the FreeRTOS kernel. !<<
18  ***************************************************************************
19 
20  FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
21  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22  FOR A PARTICULAR PURPOSE. Full license text is available on the following
23  link: http://www.freertos.org/a00114.html
24 
25  ***************************************************************************
26  * *
27  * FreeRTOS provides completely free yet professionally developed, *
28  * robust, strictly quality controlled, supported, and cross *
29  * platform software that is more than just the market leader, it *
30  * is the industry's de facto standard. *
31  * *
32  * Help yourself get started quickly while simultaneously helping *
33  * to support the FreeRTOS project by purchasing a FreeRTOS *
34  * tutorial book, reference manual, or both: *
35  * http://www.FreeRTOS.org/Documentation *
36  * *
37  ***************************************************************************
38 
39  http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
40  the FAQ page "My application does not run, what could be wrong?". Have you
41  defined configASSERT()?
42 
43  http://www.FreeRTOS.org/support - In return for receiving this top quality
44  embedded software for free we request you assist our global community by
45  participating in the support forum.
46 
47  http://www.FreeRTOS.org/training - Investing in training allows your team to
48  be as productive as possible as early as possible. Now you can receive
49  FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
50  Ltd, and the world's leading authority on the world's leading RTOS.
51 
52  http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
53  including FreeRTOS+Trace - an indispensable productivity tool, a DOS
54  compatible FAT file system, and our tiny thread aware UDP/IP stack.
55 
56  http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
57  Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
58 
59  http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
60  Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
61  licenses offer ticketed support, indemnification and commercial middleware.
62 
63  http://www.SafeRTOS.com - High Integrity Systems also provide a safety
64  engineered and independently SIL3 certified version for use in safety and
65  mission critical applications that require provable dependability.
66 
67  1 tab == 4 spaces!
68 */
69 
70 
71 #ifndef TIMERS_H
72 #define TIMERS_H
73 
74 #ifndef INC_FREERTOS_H
75  #error "include FreeRTOS.h must appear in source files before include timers.h"
76 #endif
77 
78 /*lint -e537 This headers are only multiply included if the application code
79 happens to also be including task.h. */
80 #include "task.h"
81 /*lint +e537 */
82 
83 #ifdef __cplusplus
84 extern "C" {
85 #endif
86 
87 /*-----------------------------------------------------------
88  * MACROS AND DEFINITIONS
89  *----------------------------------------------------------*/
90 
91 /* IDs for commands that can be sent/received on the timer queue. These are to
92 be used solely through the macros that make up the public software timer API,
93 as defined below. The commands that are sent from interrupts must use the
94 highest numbers as tmrFIRST_FROM_ISR_COMMAND is used to determine if the task
95 or interrupt version of the queue send function should be used. */
96 #define tmrCOMMAND_EXECUTE_CALLBACK_FROM_ISR ( ( BaseType_t ) -2 )
97 #define tmrCOMMAND_EXECUTE_CALLBACK ( ( BaseType_t ) -1 )
98 #define tmrCOMMAND_START_DONT_TRACE ( ( BaseType_t ) 0 )
99 #define tmrCOMMAND_START ( ( BaseType_t ) 1 )
100 #define tmrCOMMAND_RESET ( ( BaseType_t ) 2 )
101 #define tmrCOMMAND_STOP ( ( BaseType_t ) 3 )
102 #define tmrCOMMAND_CHANGE_PERIOD ( ( BaseType_t ) 4 )
103 #define tmrCOMMAND_DELETE ( ( BaseType_t ) 5 )
104 
105 #define tmrFIRST_FROM_ISR_COMMAND ( ( BaseType_t ) 6 )
106 #define tmrCOMMAND_START_FROM_ISR ( ( BaseType_t ) 6 )
107 #define tmrCOMMAND_RESET_FROM_ISR ( ( BaseType_t ) 7 )
108 #define tmrCOMMAND_STOP_FROM_ISR ( ( BaseType_t ) 8 )
109 #define tmrCOMMAND_CHANGE_PERIOD_FROM_ISR ( ( BaseType_t ) 9 )
110 
111 
118 typedef void * TimerHandle_t;
119 
120 /*
121  * Defines the prototype to which timer callback functions must conform.
122  */
123 typedef void (*TimerCallbackFunction_t)( TimerHandle_t xTimer );
124 
125 /*
126  * Defines the prototype to which functions used with the
127  * xTimerPendFunctionCallFromISR() function must conform.
128  */
129 typedef void (*PendedFunction_t)( void *, uint32_t );
130 
268 #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
269  TimerHandle_t xTimerCreate( const char * const pcTimerName,
270  const TickType_t xTimerPeriodInTicks,
271  const UBaseType_t uxAutoReload,
272  void * const pvTimerID,
273  TimerCallbackFunction_t pxCallbackFunction ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
274 #endif
275 
398 #if( configSUPPORT_STATIC_ALLOCATION == 1 )
399  TimerHandle_t xTimerCreateStatic( const char * const pcTimerName,
400  const TickType_t xTimerPeriodInTicks,
401  const UBaseType_t uxAutoReload,
402  void * const pvTimerID,
403  TimerCallbackFunction_t pxCallbackFunction,
404  StaticTimer_t *pxTimerBuffer ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
405 #endif /* configSUPPORT_STATIC_ALLOCATION */
406 
427 void *pvTimerGetTimerID( const TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
428 
448 void vTimerSetTimerID( TimerHandle_t xTimer, void *pvNewID ) PRIVILEGED_FUNCTION;
449 
485 BaseType_t xTimerIsTimerActive( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
486 
493 TaskHandle_t xTimerGetTimerDaemonTaskHandle( void ) PRIVILEGED_FUNCTION;
494 
545 #define xTimerStart( xTimer, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_START, ( xTaskGetTickCount() ), NULL, ( xTicksToWait ) )
546 
587 #define xTimerStop( xTimer, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_STOP, 0U, NULL, ( xTicksToWait ) )
588 
667  #define xTimerChangePeriod( xTimer, xNewPeriod, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_CHANGE_PERIOD, ( xNewPeriod ), NULL, ( xTicksToWait ) )
668 
705 #define xTimerDelete( xTimer, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_DELETE, 0U, NULL, ( xTicksToWait ) )
706 
829 #define xTimerReset( xTimer, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_RESET, ( xTaskGetTickCount() ), NULL, ( xTicksToWait ) )
830 
915 #define xTimerStartFromISR( xTimer, pxHigherPriorityTaskWoken ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_START_FROM_ISR, ( xTaskGetTickCountFromISR() ), ( pxHigherPriorityTaskWoken ), 0U )
916 
978 #define xTimerStopFromISR( xTimer, pxHigherPriorityTaskWoken ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_STOP_FROM_ISR, 0, ( pxHigherPriorityTaskWoken ), 0U )
979 
1051 #define xTimerChangePeriodFromISR( xTimer, xNewPeriod, pxHigherPriorityTaskWoken ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_CHANGE_PERIOD_FROM_ISR, ( xNewPeriod ), ( pxHigherPriorityTaskWoken ), 0U )
1052 
1137 #define xTimerResetFromISR( xTimer, pxHigherPriorityTaskWoken ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_RESET_FROM_ISR, ( xTaskGetTickCountFromISR() ), ( pxHigherPriorityTaskWoken ), 0U )
1138 
1139 
1228 BaseType_t xTimerPendFunctionCallFromISR( PendedFunction_t xFunctionToPend, void *pvParameter1, uint32_t ulParameter2, BaseType_t *pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
1229 
1262 BaseType_t xTimerPendFunctionCall( PendedFunction_t xFunctionToPend, void *pvParameter1, uint32_t ulParameter2, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
1263 
1273 const char * pcTimerGetName( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
1274 
1284 TickType_t xTimerGetPeriod( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
1285 
1299 TickType_t xTimerGetExpiryTime( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
1300 
1301 /*
1302  * Functions beyond this part are not part of the public API and are intended
1303  * for use by the kernel only.
1304  */
1305 BaseType_t xTimerCreateTimerTask( void ) PRIVILEGED_FUNCTION;
1306 BaseType_t xTimerGenericCommand( TimerHandle_t xTimer, const BaseType_t xCommandID, const TickType_t xOptionalValue, BaseType_t * const pxHigherPriorityTaskWoken, const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
1307 
1308 #ifdef __cplusplus
1309 }
1310 #endif
1311 #endif /* TIMERS_H */
1312 
1313 
1314 
BaseType_t xTimerPendFunctionCallFromISR(PendedFunction_t xFunctionToPend, void *pvParameter1, uint32_t ulParameter2, BaseType_t *pxHigherPriorityTaskWoken) PRIVILEGED_FUNCTION
TaskHandle_t xTimerGetTimerDaemonTaskHandle(void) PRIVILEGED_FUNCTION
void(* PendedFunction_t)(void *, uint32_t)
Definition: timers.h:129
BaseType_t xTimerGenericCommand(TimerHandle_t xTimer, const BaseType_t xCommandID, const TickType_t xOptionalValue, BaseType_t *const pxHigherPriorityTaskWoken, const TickType_t xTicksToWait) PRIVILEGED_FUNCTION
unsigned long UBaseType_t
Definition: portmacro.h:99
uint32_t TickType_t
Definition: portmacro.h:105
void * pvTimerGetTimerID(const TimerHandle_t xTimer) PRIVILEGED_FUNCTION
void(* TimerCallbackFunction_t)(TimerHandle_t xTimer)
Definition: timers.h:123
BaseType_t xTimerPendFunctionCall(PendedFunction_t xFunctionToPend, void *pvParameter1, uint32_t ulParameter2, TickType_t xTicksToWait) PRIVILEGED_FUNCTION
long BaseType_t
Definition: portmacro.h:98
void * TaskHandle_t
Definition: task.h:103
TickType_t xTimerGetPeriod(TimerHandle_t xTimer) PRIVILEGED_FUNCTION
const char * pcTimerGetName(TimerHandle_t xTimer) PRIVILEGED_FUNCTION
#define PRIVILEGED_FUNCTION
Definition: mpu_wrappers.h:193
void vTimerSetTimerID(TimerHandle_t xTimer, void *pvNewID) PRIVILEGED_FUNCTION
BaseType_t xTimerCreateTimerTask(void) PRIVILEGED_FUNCTION
TickType_t xTimerGetExpiryTime(TimerHandle_t xTimer) PRIVILEGED_FUNCTION
BaseType_t xTimerIsTimerActive(TimerHandle_t xTimer) PRIVILEGED_FUNCTION
void * TimerHandle_t
Definition: timers.h:118
Definition: FreeRTOS.h:1041