FreeRTOS Tetris
timers.h
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 // Doxygen Groups ***********************************************************************
120 /*-----------------------------------------------------------
121  * MACROS AND DEFINITIONS
122  *----------------------------------------------------------*/
123 
124 /* IDs for commands that can be sent/received on the timer queue. These are to
125 be used solely through the macros that make up the public software timer API,
126 as defined below. The commands that are sent from interrupts must use the
127 highest numbers as tmrFIRST_FROM_ISR_COMMAND is used to determine if the task
128 or interrupt version of the queue send function should be used. */
129 #define tmrCOMMAND_EXECUTE_CALLBACK_FROM_ISR ( ( BaseType_t ) -2 )
130 #define tmrCOMMAND_EXECUTE_CALLBACK ( ( BaseType_t ) -1 )
131 #define tmrCOMMAND_START_DONT_TRACE ( ( BaseType_t ) 0 )
132 #define tmrCOMMAND_START ( ( BaseType_t ) 1 )
133 #define tmrCOMMAND_RESET ( ( BaseType_t ) 2 )
134 #define tmrCOMMAND_STOP ( ( BaseType_t ) 3 )
135 #define tmrCOMMAND_CHANGE_PERIOD ( ( BaseType_t ) 4 )
136 #define tmrCOMMAND_DELETE ( ( BaseType_t ) 5 )
137 
138 #define tmrFIRST_FROM_ISR_COMMAND ( ( BaseType_t ) 6 )
139 #define tmrCOMMAND_START_FROM_ISR ( ( BaseType_t ) 6 )
140 #define tmrCOMMAND_RESET_FROM_ISR ( ( BaseType_t ) 7 )
141 #define tmrCOMMAND_STOP_FROM_ISR ( ( BaseType_t ) 8 )
142 #define tmrCOMMAND_CHANGE_PERIOD_FROM_ISR ( ( BaseType_t ) 9 )
143 
144 // **************************************************************************************
145 // Timer Handles ************************************************************************
146 // **************************************************************************************
154 typedef void *TimerHandle_t;
155 
160 typedef void (*TimerCallbackFunction_t)(TimerHandle_t xTimer);
161 
167 typedef void (*PendedFunction_t)(void *, uint32_t);
168 
169 // **************************************************************************************
170 // Timer Handles ************************************************************************
171 // **************************************************************************************
292 #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
293 TimerHandle_t xTimerCreate(const char *const pcTimerName,
294  const TickType_t xTimerPeriodInTicks,
295  const UBaseType_t uxAutoReload,
296  void *const pvTimerID,
297  TimerCallbackFunction_t pxCallbackFunction) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
298 #endif
299 
407 #if( configSUPPORT_STATIC_ALLOCATION == 1 )
408 TimerHandle_t xTimerCreateStatic(const char *const pcTimerName,
409  const TickType_t xTimerPeriodInTicks,
410  const UBaseType_t uxAutoReload,
411  void *const pvTimerID,
412  TimerCallbackFunction_t pxCallbackFunction,
413  StaticTimer_t *pxTimerBuffer) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
414 #endif /* configSUPPORT_STATIC_ALLOCATION */
415 
416 // **************************************************************************************
417 // Timer Deletion ***********************************************************************
418 // **************************************************************************************
454 #define xTimerDelete( xTimer, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_DELETE, 0U, NULL, ( xTicksToWait ) )
455 
456 // **************************************************************************************
457 // Timer Control ************************************************************************
458 // **************************************************************************************
508 #define xTimerStart( xTimer, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_START, ( xTaskGetTickCount() ), NULL, ( xTicksToWait ) )
509 
548 #define xTimerStop( xTimer, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_STOP, 0U, NULL, ( xTicksToWait ) )
549 
671 #define xTimerReset( xTimer, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_RESET, ( xTaskGetTickCount() ), NULL, ( xTicksToWait ) )
672 
748 #define xTimerChangePeriod( xTimer, xNewPeriod, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_CHANGE_PERIOD, ( xNewPeriod ), NULL, ( xTicksToWait ) )
749 
750 // **************************************************************************************
751 // Timer Control From ISR ***************************************************************
752 // **************************************************************************************
828 #define xTimerStartFromISR( xTimer, pxHigherPriorityTaskWoken ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_START_FROM_ISR, ( xTaskGetTickCountFromISR() ), ( pxHigherPriorityTaskWoken ), 0U )
829 
888 #define xTimerStopFromISR( xTimer, pxHigherPriorityTaskWoken ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_STOP_FROM_ISR, 0, ( pxHigherPriorityTaskWoken ), 0U )
889 
957 #define xTimerChangePeriodFromISR( xTimer, xNewPeriod, pxHigherPriorityTaskWoken ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_CHANGE_PERIOD_FROM_ISR, ( xNewPeriod ), ( pxHigherPriorityTaskWoken ), 0U )
958 
1040 #define xTimerResetFromISR( xTimer, pxHigherPriorityTaskWoken ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_RESET_FROM_ISR, ( xTaskGetTickCountFromISR() ), ( pxHigherPriorityTaskWoken ), 0U )
1041 
1042 // **************************************************************************************
1043 // Timer Utility Functions **************************************************************
1044 // **************************************************************************************
1065 void *pvTimerGetTimerID(const TimerHandle_t xTimer) PRIVILEGED_FUNCTION;
1066 
1086 void vTimerSetTimerID(TimerHandle_t xTimer, void *pvNewID) PRIVILEGED_FUNCTION;
1087 
1123 BaseType_t xTimerIsTimerActive(TimerHandle_t xTimer) PRIVILEGED_FUNCTION;
1124 
1130 TaskHandle_t xTimerGetTimerDaemonTaskHandle(void) PRIVILEGED_FUNCTION;
1131 
1140 const char *pcTimerGetName(TimerHandle_t xTimer) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
1141 
1151 TickType_t xTimerGetPeriod(TimerHandle_t xTimer) PRIVILEGED_FUNCTION;
1152 
1166 TickType_t xTimerGetExpiryTime(TimerHandle_t xTimer) PRIVILEGED_FUNCTION;
1167 
1168 // **************************************************************************************
1169 // Timer Deference **********************************************************************
1170 // **************************************************************************************
1254 BaseType_t xTimerPendFunctionCallFromISR(PendedFunction_t xFunctionToPend, void *pvParameter1, uint32_t ulParameter2, BaseType_t *pxHigherPriorityTaskWoken) PRIVILEGED_FUNCTION;
1255 
1282 BaseType_t xTimerPendFunctionCall(PendedFunction_t xFunctionToPend, void *pvParameter1, uint32_t ulParameter2, TickType_t xTicksToWait) PRIVILEGED_FUNCTION;
1283 
1284 /*
1285  * Functions beyond this part are not part of the public API and are intended
1286  * for use by the kernel only.
1287  */
1288 BaseType_t xTimerCreateTimerTask(void) PRIVILEGED_FUNCTION;
1289 BaseType_t xTimerGenericCommand(TimerHandle_t xTimer, const BaseType_t xCommandID, const TickType_t xOptionalValue, BaseType_t *const pxHigherPriorityTaskWoken, const TickType_t xTicksToWait) PRIVILEGED_FUNCTION;
1290 
1291 #ifdef __cplusplus
1292 }
1293 #endif
1294 #endif /* TIMERS_H */
1295 
1296 
1297 
xTimerGetTimerDaemonTaskHandle
TaskHandle_t xTimerGetTimerDaemonTaskHandle(void) PRIVILEGED_FUNCTION
Simply returns the handle of the timer service/daemon task. It it not valid to call xTimerGetTimerDae...
TaskHandle_t
void * TaskHandle_t
Type by which tasks are referenced.
Definition: task.h:132
xTimerPendFunctionCallFromISR
BaseType_t xTimerPendFunctionCallFromISR(PendedFunction_t xFunctionToPend, void *pvParameter1, uint32_t ulParameter2, BaseType_t *pxHigherPriorityTaskWoken) PRIVILEGED_FUNCTION
Used from application interrupt service routines to defer the execution of a function to the RTOS dae...
xSTATIC_TIMER
Definition: FreeRTOS.h:1035
TickType_t
uint32_t TickType_t
FreeRTOS definition for a single tick.
Definition: portmacro.h:98
xTimerCreateStatic
TimerHandle_t xTimerCreateStatic(const char *const pcTimerName, const TickType_t xTimerPeriodInTicks, const UBaseType_t uxAutoReload, void *const pvTimerID, TimerCallbackFunction_t pxCallbackFunction, StaticTimer_t *pxTimerBuffer) PRIVILEGED_FUNCTION
Creates a new software timer instance, and returns a handle by which the created software timer can b...
UBaseType_t
unsigned long UBaseType_t
FreeRTOS definition for unsigned long ints.
Definition: portmacro.h:92
TimerHandle_t
void * TimerHandle_t
Type by which software timers are referenced. For example, a call to xTimerCreate() returns an TimerH...
Definition: timers.h:154
BaseType_t
long BaseType_t
FreeRTOS definition for long ints.
Definition: portmacro.h:91
vTimerSetTimerID
void vTimerSetTimerID(TimerHandle_t xTimer, void *pvNewID) PRIVILEGED_FUNCTION
Sets the ID assigned to the timer.
xTimerGetPeriod
TickType_t xTimerGetPeriod(TimerHandle_t xTimer) PRIVILEGED_FUNCTION
Returns the period of a timer.
xTimerPendFunctionCall
BaseType_t xTimerPendFunctionCall(PendedFunction_t xFunctionToPend, void *pvParameter1, uint32_t ulParameter2, TickType_t xTicksToWait) PRIVILEGED_FUNCTION
Used to defer the execution of a function to the RTOS daemon task (the timer service task,...
xTimerCreate
TimerHandle_t xTimerCreate(const char *const pcTimerName, const TickType_t xTimerPeriodInTicks, const UBaseType_t uxAutoReload, void *const pvTimerID, TimerCallbackFunction_t pxCallbackFunction) PRIVILEGED_FUNCTION
Creates a new software timer instance, and returns a handle by which the created software timer can b...
pcTimerGetName
const char * pcTimerGetName(TimerHandle_t xTimer) PRIVILEGED_FUNCTION
Returns the name that was assigned to a timer when the timer was created.
xTimerGetExpiryTime
TickType_t xTimerGetExpiryTime(TimerHandle_t xTimer) PRIVILEGED_FUNCTION
Returns the time in ticks at which the timer will expire. If this is less than the current tick count...
PendedFunction_t
void(* PendedFunction_t)(void *, uint32_t)
Definition: timers.h:167
pvTimerGetTimerID
void * pvTimerGetTimerID(const TimerHandle_t xTimer) PRIVILEGED_FUNCTION
Returns the ID assigned to the timer.
TimerCallbackFunction_t
void(* TimerCallbackFunction_t)(TimerHandle_t xTimer)
Definition: timers.h:160
xTimerIsTimerActive
BaseType_t xTimerIsTimerActive(TimerHandle_t xTimer) PRIVILEGED_FUNCTION
Queries a timer to see if it is active or dormant.