Cordio Stack and Cordio Profiles  r2p3-02rel0
wsf_timer.h
Go to the documentation of this file.
1 /*************************************************************************************************/
2 /*!
3  * \file wsf_timer.h
4  *
5  * \brief Timer service.
6  *
7  * Copyright (c) 2009-2018 Arm Ltd. All Rights Reserved.
8  * ARM Ltd. confidential and proprietary.
9  *
10  * IMPORTANT. Your use of this file is governed by a Software License Agreement
11  * ("Agreement") that must be accepted in order to download or otherwise receive a
12  * copy of this file. You may not use or copy this file for any purpose other than
13  * as described in the Agreement. If you do not agree to all of the terms of the
14  * Agreement do not use this file and delete all copies in your possession or control;
15  * if you do not have a copy of the Agreement, you must contact ARM Ltd. prior
16  * to any use, copying or further distribution of this software.
17  */
18 /*************************************************************************************************/
19 #ifndef WSF_TIMER_H
20 #define WSF_TIMER_H
21 
22 #include "wsf_os.h"
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 /*! \addtogroup WSF_TIMER_API
29  * \{ */
30 
31 /**************************************************************************************************
32  Macros
33 **************************************************************************************************/
34 
35 #ifndef WSF_MS_PER_TICK
36 /*! \brief Default milliseconds per tick rate */
37 #define WSF_MS_PER_TICK 10
38 #endif
39 
40 /**************************************************************************************************
41  Data Types
42 **************************************************************************************************/
43 
44 /*! \brief Timer ticks data type */
46 
47 /*! \brief Timer structure */
48 typedef struct wsfTimer_tag
49 {
50  struct wsfTimer_tag *pNext; /*!< \brief pointer to next timer in queue */
51  wsfTimerTicks_t ticks; /*!< \brief number of ticks until expiration */
52  wsfHandlerId_t handlerId; /*!< \brief event handler for this timer */
53  bool_t isStarted; /*!< \brief TRUE if timer has been started */
54  wsfMsgHdr_t msg; /*!< \brief application-defined timer event parameters */
55 } wsfTimer_t;
56 
57 
58 /**************************************************************************************************
59  Function Declarations
60 **************************************************************************************************/
61 
62 /*************************************************************************************************/
63 /*!
64  * \brief Initialize the timer service. This function should only be called once
65  * upon system initialization.
66  *
67  * \return None.
68  */
69 /*************************************************************************************************/
70 void WsfTimerInit(void);
71 
72 /*************************************************************************************************/
73 /*!
74  * \brief Start a timer in units of seconds. Before this function is called parameter
75  * pTimer->handlerId must be set to the event handler for this timer and parameter
76  * pTimer->msg must be set to any application-defined timer event parameters.
77  *
78  * \param pTimer Pointer to timer.
79  * \param sec Seconds until expiration.
80  *
81  * \return None.
82  */
83 /*************************************************************************************************/
84 void WsfTimerStartSec(wsfTimer_t *pTimer, wsfTimerTicks_t sec);
85 
86 /*************************************************************************************************/
87 /*!
88  * \brief Start a timer in units of milliseconds.
89  *
90  * \param pTimer Pointer to timer.
91  * \param ms Milliseconds until expiration.
92  *
93  * \return None.
94  */
95 /*************************************************************************************************/
96 void WsfTimerStartMs(wsfTimer_t *pTimer, wsfTimerTicks_t ms);
97 
98 /*************************************************************************************************/
99 /*!
100  * \brief Stop a timer.
101  *
102  * \param pTimer Pointer to timer.
103  *
104  * \return None.
105  */
106 /*************************************************************************************************/
107 void WsfTimerStop(wsfTimer_t *pTimer);
108 
109 /*************************************************************************************************/
110 /*!
111  * \brief Update the timer service with the number of elapsed ticks. This function is
112  * typically called only from timer porting code.
113  *
114  * \param ticks Number of ticks since last update.
115  *
116  * \return None.
117  */
118 /*************************************************************************************************/
119 void WsfTimerUpdate(wsfTimerTicks_t ticks);
120 
121 /*************************************************************************************************/
122 /*!
123  * \brief Return the number of ticks until the next timer expiration. Note that this
124  * function can return zero even if a timer is running, indicating the timer
125  * has expired but has not yet been serviced.
126  *
127  * \param pTimerRunning Returns TRUE if a timer is running, FALSE if no timers running.
128  *
129  * \return The number of ticks until the next timer expiration.
130  */
131 /*************************************************************************************************/
132 wsfTimerTicks_t WsfTimerNextExpiration(bool_t *pTimerRunning);
133 
134 /*************************************************************************************************/
135 /*!
136  * \brief Service expired timers for the given task. This function is typically called only
137  * WSF OS porting code.
138  *
139  * \param taskId OS Task ID of task servicing timers.
140  *
141  * \return Pointer to next expired timer or NULL if there are no expired timers.
142  */
143 /*************************************************************************************************/
145 
146 /*! \} */ /* WSF_TIMER_API */
147 
148 #ifdef __cplusplus
149 };
150 #endif
151 
152 #endif /* WSF_TIMER_H */
wsfTimerTicks_t ticks
number of ticks until expiration
Definition: wsf_timer.h:51
void WsfTimerStartSec(wsfTimer_t *pTimer, wsfTimerTicks_t sec)
Start a timer in units of seconds. Before this function is called parameter pTimer->handlerId must be...
struct wsfTimer_tag * pNext
pointer to next timer in queue
Definition: wsf_timer.h:50
Timer structure.
Definition: wsf_timer.h:48
uint8_t bool_t
Boolean data type.
Definition: wsf_types.h:78
void WsfTimerStop(wsfTimer_t *pTimer)
Stop a timer.
unsigned long uint32_t
Unsigned 32-bit value.
Definition: wsf_types.h:71
uint8_t wsfHandlerId_t
Event handler ID data type.
Definition: wsf_os.h:74
wsfMsgHdr_t msg
application-defined timer event parameters
Definition: wsf_timer.h:54
wsfHandlerId_t handlerId
event handler for this timer
Definition: wsf_timer.h:52
wsfTimer_t * WsfTimerServiceExpired(wsfTaskId_t taskId)
Service expired timers for the given task. This function is typically called only WSF OS porting code...
void WsfTimerInit(void)
Initialize the timer service. This function should only be called once upon system initialization...
wsfHandlerId_t wsfTaskId_t
Task ID data type.
Definition: wsf_os.h:80
void WsfTimerStartMs(wsfTimer_t *pTimer, wsfTimerTicks_t ms)
Start a timer in units of milliseconds.
bool_t isStarted
TRUE if timer has been started.
Definition: wsf_timer.h:53
uint32_t wsfTimerTicks_t
Timer ticks data type.
Definition: wsf_timer.h:45
wsfTimerTicks_t WsfTimerNextExpiration(bool_t *pTimerRunning)
Return the number of ticks until the next timer expiration. Note that this function can return zero e...
Software foundation OS API.
Common message structure passed to event handler.
Definition: wsf_os.h:97
void WsfTimerUpdate(wsfTimerTicks_t ticks)
Update the timer service with the number of elapsed ticks. This function is typically called only fro...