firmware
IEM Firmware Documentation
Loading...
Searching...
No Matches
timers.h
Go to the documentation of this file.
1/*
2 * FreeRTOS Kernel V11.1.0
3 * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4 *
5 * SPDX-License-Identifier: MIT
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 * this software and associated documentation files (the "Software"), to deal in
9 * the Software without restriction, including without limitation the rights to
10 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 * the Software, and to permit persons to whom the Software is furnished to do so,
12 * subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 *
24 * https://www.FreeRTOS.org
25 * https://github.com/FreeRTOS
26 *
27 */
28
29
30#ifndef TIMERS_H
31#define TIMERS_H
32
33#ifndef INC_FREERTOS_H
34 #error "include FreeRTOS.h must appear in source files before include timers.h"
35#endif
36
37#include "task.h"
38
39
40/* *INDENT-OFF* */
41#ifdef __cplusplus
42 extern "C" {
43#endif
44/* *INDENT-ON* */
45
46/*-----------------------------------------------------------
47* MACROS AND DEFINITIONS
48*----------------------------------------------------------*/
49
50/* IDs for commands that can be sent/received on the timer queue. These are to
51 * be used solely through the macros that make up the public software timer API,
52 * as defined below. The commands that are sent from interrupts must use the
53 * highest numbers as tmrFIRST_FROM_ISR_COMMAND is used to determine if the task
54 * or interrupt version of the queue send function should be used. */
55#define tmrCOMMAND_EXECUTE_CALLBACK_FROM_ISR ( ( BaseType_t ) -2 )
56#define tmrCOMMAND_EXECUTE_CALLBACK ( ( BaseType_t ) -1 )
57#define tmrCOMMAND_START_DONT_TRACE ( ( BaseType_t ) 0 )
58#define tmrCOMMAND_START ( ( BaseType_t ) 1 )
59#define tmrCOMMAND_RESET ( ( BaseType_t ) 2 )
60#define tmrCOMMAND_STOP ( ( BaseType_t ) 3 )
61#define tmrCOMMAND_CHANGE_PERIOD ( ( BaseType_t ) 4 )
62#define tmrCOMMAND_DELETE ( ( BaseType_t ) 5 )
63
64#define tmrFIRST_FROM_ISR_COMMAND ( ( BaseType_t ) 6 )
65#define tmrCOMMAND_START_FROM_ISR ( ( BaseType_t ) 6 )
66#define tmrCOMMAND_RESET_FROM_ISR ( ( BaseType_t ) 7 )
67#define tmrCOMMAND_STOP_FROM_ISR ( ( BaseType_t ) 8 )
68#define tmrCOMMAND_CHANGE_PERIOD_FROM_ISR ( ( BaseType_t ) 9 )
69
70
77struct tmrTimerControl; /* The old naming convention is used to prevent breaking kernel aware debuggers. */
78typedef struct tmrTimerControl * TimerHandle_t;
79
80/*
81 * Defines the prototype to which timer callback functions must conform.
82 */
83typedef void (* TimerCallbackFunction_t)( TimerHandle_t xTimer );
84
85/*
86 * Defines the prototype to which functions used with the
87 * xTimerPendFunctionCallFromISR() function must conform.
88 */
89typedef void (* PendedFunction_t)( void * arg1,
90 uint32_t arg2 );
91
229#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
230 TimerHandle_t xTimerCreate( const char * const pcTimerName,
231 const TickType_t xTimerPeriodInTicks,
232 const BaseType_t xAutoReload,
233 void * const pvTimerID,
234 TimerCallbackFunction_t pxCallbackFunction ) PRIVILEGED_FUNCTION;
235#endif
236
359#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
360 TimerHandle_t xTimerCreateStatic( const char * const pcTimerName,
361 const TickType_t xTimerPeriodInTicks,
362 const BaseType_t xAutoReload,
363 void * const pvTimerID,
364 TimerCallbackFunction_t pxCallbackFunction,
365 StaticTimer_t * pxTimerBuffer ) PRIVILEGED_FUNCTION;
366#endif /* configSUPPORT_STATIC_ALLOCATION */
367
389
410 void * pvNewID ) PRIVILEGED_FUNCTION;
411
448
456
507#define xTimerStart( xTimer, xTicksToWait ) \
508 xTimerGenericCommand( ( xTimer ), tmrCOMMAND_START, ( xTaskGetTickCount() ), NULL, ( xTicksToWait ) )
509
550#define xTimerStop( xTimer, xTicksToWait ) \
551 xTimerGenericCommand( ( xTimer ), tmrCOMMAND_STOP, 0U, NULL, ( xTicksToWait ) )
552
631#define xTimerChangePeriod( xTimer, xNewPeriod, xTicksToWait ) \
632 xTimerGenericCommand( ( xTimer ), tmrCOMMAND_CHANGE_PERIOD, ( xNewPeriod ), NULL, ( xTicksToWait ) )
633
670#define xTimerDelete( xTimer, xTicksToWait ) \
671 xTimerGenericCommand( ( xTimer ), tmrCOMMAND_DELETE, 0U, NULL, ( xTicksToWait ) )
672
795#define xTimerReset( xTimer, xTicksToWait ) \
796 xTimerGenericCommand( ( xTimer ), tmrCOMMAND_RESET, ( xTaskGetTickCount() ), NULL, ( xTicksToWait ) )
797
882#define xTimerStartFromISR( xTimer, pxHigherPriorityTaskWoken ) \
883 xTimerGenericCommand( ( xTimer ), tmrCOMMAND_START_FROM_ISR, ( xTaskGetTickCountFromISR() ), ( pxHigherPriorityTaskWoken ), 0U )
884
946#define xTimerStopFromISR( xTimer, pxHigherPriorityTaskWoken ) \
947 xTimerGenericCommand( ( xTimer ), tmrCOMMAND_STOP_FROM_ISR, 0, ( pxHigherPriorityTaskWoken ), 0U )
948
1020#define xTimerChangePeriodFromISR( xTimer, xNewPeriod, pxHigherPriorityTaskWoken ) \
1021 xTimerGenericCommand( ( xTimer ), tmrCOMMAND_CHANGE_PERIOD_FROM_ISR, ( xNewPeriod ), ( pxHigherPriorityTaskWoken ), 0U )
1022
1107#define xTimerResetFromISR( xTimer, pxHigherPriorityTaskWoken ) \
1108 xTimerGenericCommand( ( xTimer ), tmrCOMMAND_RESET_FROM_ISR, ( xTaskGetTickCountFromISR() ), ( pxHigherPriorityTaskWoken ), 0U )
1109
1110
1199#if ( INCLUDE_xTimerPendFunctionCall == 1 )
1200 BaseType_t xTimerPendFunctionCallFromISR( PendedFunction_t xFunctionToPend,
1201 void * pvParameter1,
1202 uint32_t ulParameter2,
1203 BaseType_t * pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
1204#endif
1205
1238#if ( INCLUDE_xTimerPendFunctionCall == 1 )
1239 BaseType_t xTimerPendFunctionCall( PendedFunction_t xFunctionToPend,
1240 void * pvParameter1,
1241 uint32_t ulParameter2,
1242 TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
1243#endif
1244
1255
1272 const BaseType_t xAutoReload ) PRIVILEGED_FUNCTION;
1273
1287
1301
1312
1327
1343#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
1344 BaseType_t xTimerGetStaticBuffer( TimerHandle_t xTimer,
1345 StaticTimer_t ** ppxTimerBuffer ) PRIVILEGED_FUNCTION;
1346#endif /* configSUPPORT_STATIC_ALLOCATION */
1347
1348/*
1349 * Functions beyond this part are not part of the public API and are intended
1350 * for use by the kernel only.
1351 */
1353
1354/*
1355 * Splitting the xTimerGenericCommand into two sub functions and making it a macro
1356 * removes a recursion path when called from ISRs. This is primarily for the XCore
1357 * XCC port which detects the recursion path and throws an error during compilation
1358 * when this is not split.
1359 */
1361 const BaseType_t xCommandID,
1362 const TickType_t xOptionalValue,
1363 BaseType_t * const pxHigherPriorityTaskWoken,
1364 const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
1365
1367 const BaseType_t xCommandID,
1368 const TickType_t xOptionalValue,
1369 BaseType_t * const pxHigherPriorityTaskWoken,
1370 const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
1371
1372#define xTimerGenericCommand( xTimer, xCommandID, xOptionalValue, pxHigherPriorityTaskWoken, xTicksToWait ) \
1373 ( ( xCommandID ) < tmrFIRST_FROM_ISR_COMMAND ? \
1374 xTimerGenericCommandFromTask( xTimer, xCommandID, xOptionalValue, pxHigherPriorityTaskWoken, xTicksToWait ) : \
1375 xTimerGenericCommandFromISR( xTimer, xCommandID, xOptionalValue, pxHigherPriorityTaskWoken, xTicksToWait ) )
1376#if ( configUSE_TRACE_FACILITY == 1 )
1377 void vTimerSetTimerNumber( TimerHandle_t xTimer,
1378 UBaseType_t uxTimerNumber ) PRIVILEGED_FUNCTION;
1379 UBaseType_t uxTimerGetTimerNumber( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
1380#endif
1381
1382#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
1383
1397 void vApplicationGetTimerTaskMemory( StaticTask_t ** ppxTimerTaskTCBBuffer,
1398 StackType_t ** ppxTimerTaskStackBuffer,
1399 configSTACK_DEPTH_TYPE * puxTimerTaskStackSize );
1400
1401#endif
1402
1403#if ( configUSE_DAEMON_TASK_STARTUP_HOOK != 0 )
1404
1413 /* MISRA Ref 8.6.1 [External linkage] */
1414 /* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-86 */
1415 /* coverity[misra_c_2012_rule_8_6_violation] */
1416 void vApplicationDaemonTaskStartupHook( void );
1417
1418#endif
1419
1420/*
1421 * This function resets the internal state of the timer module. It must be called
1422 * by the application before restarting the scheduler.
1423 */
1425
1426/* *INDENT-OFF* */
1427#ifdef __cplusplus
1428 }
1429#endif
1430/* *INDENT-ON* */
1431#endif /* TIMERS_H */
struct xSTATIC_TIMER StaticTimer_t
struct xSTATIC_TCB StaticTask_t
#define configSTACK_DEPTH_TYPE
Definition FreeRTOSConfig.h:107
#define PRIVILEGED_FUNCTION
Definition mpu_wrappers.h:269
long BaseType_t
Definition portmacro.h:59
unsigned long UBaseType_t
Definition portmacro.h:60
uint16_t TickType_t
Definition portmacro.h:63
portSTACK_TYPE StackType_t
Definition portmacro.h:58
struct tskTaskControlBlock * TaskHandle_t
Definition task.h:92
TickType_t xTimerGetExpiryTime(TimerHandle_t xTimer) PRIVILEGED_FUNCTION
UBaseType_t uxTimerGetReloadMode(TimerHandle_t xTimer) PRIVILEGED_FUNCTION
void * pvTimerGetTimerID(const TimerHandle_t xTimer) PRIVILEGED_FUNCTION
BaseType_t xTimerGetReloadMode(TimerHandle_t xTimer) PRIVILEGED_FUNCTION
void vTimerSetTimerID(TimerHandle_t xTimer, void *pvNewID) PRIVILEGED_FUNCTION
TickType_t xTimerGetPeriod(TimerHandle_t xTimer) PRIVILEGED_FUNCTION
BaseType_t xTimerIsTimerActive(TimerHandle_t xTimer) PRIVILEGED_FUNCTION
const char * pcTimerGetName(TimerHandle_t xTimer) PRIVILEGED_FUNCTION
void vTimerSetReloadMode(TimerHandle_t xTimer, const BaseType_t xAutoReload) PRIVILEGED_FUNCTION
BaseType_t xTimerGenericCommandFromISR(TimerHandle_t xTimer, const BaseType_t xCommandID, const TickType_t xOptionalValue, BaseType_t *const pxHigherPriorityTaskWoken, const TickType_t xTicksToWait) PRIVILEGED_FUNCTION
void(* TimerCallbackFunction_t)(TimerHandle_t xTimer)
Definition timers.h:83
BaseType_t xTimerGenericCommandFromTask(TimerHandle_t xTimer, const BaseType_t xCommandID, const TickType_t xOptionalValue, BaseType_t *const pxHigherPriorityTaskWoken, const TickType_t xTicksToWait) PRIVILEGED_FUNCTION
void vTimerResetState(void) PRIVILEGED_FUNCTION
void(* PendedFunction_t)(void *arg1, uint32_t arg2)
Definition timers.h:89
TaskHandle_t xTimerGetTimerDaemonTaskHandle(void) PRIVILEGED_FUNCTION
struct tmrTimerControl * TimerHandle_t
Definition timers.h:78
BaseType_t xTimerCreateTimerTask(void) PRIVILEGED_FUNCTION