Mistake on this page?
Report an issue in GitHub or email us
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-2019 Arm Ltd. All Rights Reserved.
8  *
9  * Copyright (c) 2019-2020 Packetcraft, Inc.
10  *
11  * Licensed under the Apache License, Version 2.0 (the "License");
12  * you may not use this file except in compliance with the License.
13  * You may obtain a copy of the License at
14  *
15  * http://www.apache.org/licenses/LICENSE-2.0
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  */
23 /*************************************************************************************************/
24 #ifndef WSF_TIMER_H
25 #define WSF_TIMER_H
26 
27 #include "wsf_os.h"
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 /*! \addtogroup WSF_TIMER_API
34  * \{ */
35 
36 /**************************************************************************************************
37  Macros
38 **************************************************************************************************/
39 
40 #ifndef WSF_MS_PER_TICK
41 /*! \brief Default milliseconds per tick rate */
42 #define WSF_MS_PER_TICK 10
43 #endif
44 
45 /**************************************************************************************************
46  Data Types
47 **************************************************************************************************/
48 
49 /*! \brief Timer ticks data type */
50 typedef uint32_t wsfTimerTicks_t;
51 
52 /*! \brief Timer structure */
53 typedef struct wsfTimer_tag
54 {
55  struct wsfTimer_tag *pNext; /*!< \brief pointer to next timer in queue */
56  wsfMsgHdr_t msg; /*!< \brief application-defined timer event parameters */
57  wsfTimerTicks_t ticks; /*!< \brief number of ticks until expiration */
58  wsfHandlerId_t handlerId; /*!< \brief event handler for this timer */
59  bool_t isStarted; /*!< \brief TRUE if timer has been started */
60 } wsfTimer_t;
61 
62 /**************************************************************************************************
63  Function Declarations
64 **************************************************************************************************/
65 
66 /*************************************************************************************************/
67 /*!
68  * \brief Initialize the timer service. This function should only be called once
69  * upon system initialization.
70  */
71 /*************************************************************************************************/
72 void WsfTimerInit(void);
73 
74 /*************************************************************************************************/
75 /*!
76  * \brief Start a timer in units of seconds. Before this function is called parameter
77  * pTimer->handlerId must be set to the event handler for this timer and parameter
78  * pTimer->msg must be set to any application-defined timer event parameters.
79  *
80  * \param pTimer Pointer to timer.
81  * \param sec Seconds until expiration.
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 /*************************************************************************************************/
94 void WsfTimerStartMs(wsfTimer_t *pTimer, wsfTimerTicks_t ms);
95 
96 /*************************************************************************************************/
97 /*!
98  * \brief Stop a timer.
99  *
100  * \param pTimer Pointer to timer.
101  */
102 /*************************************************************************************************/
103 void WsfTimerStop(wsfTimer_t *pTimer);
104 
105 /*************************************************************************************************/
106 /*!
107  * \brief Update the timer service with the number of elapsed ticks. This function is
108  * typically called only from timer porting code.
109  *
110  * \param ticks Number of ticks since last update.
111  */
112 /*************************************************************************************************/
113 void WsfTimerUpdate(wsfTimerTicks_t ticks);
114 
115 /*************************************************************************************************/
116 /*!
117  * \brief Return the number of ticks until the next timer expiration. Note that this
118  * function can return zero even if a timer is running, indicating the timer
119  * has expired but has not yet been serviced.
120  *
121  * \param pTimerRunning Returns TRUE if a timer is running, FALSE if no timers running.
122  *
123  * \return The number of ticks until the next timer expiration.
124  */
125 /*************************************************************************************************/
126 wsfTimerTicks_t WsfTimerNextExpiration(bool_t *pTimerRunning);
127 
128 /*************************************************************************************************/
129 /*!
130  * \brief Service expired timers for the given task. This function is typically called only
131  * WSF OS porting code.
132  *
133  * \param taskId OS Task ID of task servicing timers.
134  *
135  * \return Pointer to next expired timer or NULL if there are no expired timers.
136  */
137 /*************************************************************************************************/
139 
140 /*************************************************************************************************/
141 /*!
142  * \brief Check if there is an active timer and if there is enough time to
143  * go to sleep.
144  */
145 /*************************************************************************************************/
146 void WsfTimerSleep(void);
147 
148 /*************************************************************************************************/
149 /*!
150  * \brief Update WSF timer based on elapsed RTC ticks.
151  */
152 /*************************************************************************************************/
153 void WsfTimerSleepUpdate(void);
154 
155 /*! \} */ /* WSF_TIMER_API */
156 
157 #ifdef __cplusplus
158 };
159 #endif
160 
161 #endif /* WSF_TIMER_H */
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 wsfTimer_t
Timer structure.
void WsfTimerSleepUpdate(void)
Update WSF timer based on elapsed RTC ticks.
uint8_t isStarted
TRUE if timer has been started.
Definition: wsf_timer.h:59
void WsfTimerStop(wsfTimer_t *pTimer)
Stop a timer.
wsfTimerTicks_t WsfTimerNextExpiration(uint8_t *pTimerRunning)
Return the number of ticks until the next timer expiration. Note that this function can return zero e...
uint8_t wsfHandlerId_t
Event handler ID data type.
Definition: wsf_os.h:80
void WsfTimerSleep(void)
Check if there is an active timer and if there is enough time to go to sleep.
wsfMsgHdr_t msg
application-defined timer event parameters
Definition: wsf_timer.h:56
Timer structure.
Definition: wsf_timer.h:53
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:86
void WsfTimerStartMs(wsfTimer_t *pTimer, wsfTimerTicks_t ms)
Start a timer in units of milliseconds.
uint32_t wsfTimerTicks_t
Timer ticks data type.
Definition: wsf_timer.h:50
Software foundation OS API.
Common message structure passed to event handler.
Definition: wsf_os.h:106
wsfHandlerId_t handlerId
event handler for this timer
Definition: wsf_timer.h:58
void WsfTimerUpdate(wsfTimerTicks_t ticks)
Update the timer service with the number of elapsed ticks. This function is typically called only fro...
struct wsfTimer_tag * pNext
pointer to next timer in queue
Definition: wsf_timer.h:55
wsfTimerTicks_t ticks
number of ticks until expiration
Definition: wsf_timer.h:57
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.