Mistake on this page?
Report an issue in GitHub or email us
wsf_os.h
Go to the documentation of this file.
1 /*************************************************************************************************/
2 /*!
3  * \file wsf_os.h
4  *
5  * \brief Software foundation OS API.
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_OS_H
25 #define WSF_OS_H
26 
27 #include "wsf_types.h"
28 #include "wsf_queue.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 /*! \addtogroup WSF_OS_API
35  * \{ */
36 
37 /**************************************************************************************************
38  Configuration
39 **************************************************************************************************/
40 
41 /*! \brief OS Diagnostics */
42 #ifndef WSF_OS_DIAG
43 #define WSF_OS_DIAG FALSE
44 #endif
45 
46 /**************************************************************************************************
47  Macros
48 **************************************************************************************************/
49 
50 /*! \brief Derive task from handler ID */
51 #define WSF_TASK_FROM_ID(handlerID) (((handlerID) >> 4) & 0x0F)
52 
53 /*! \brief Derive handler from handler ID */
54 #define WSF_HANDLER_FROM_ID(handlerID) ((handlerID) & 0x0F)
55 
56 /*! \brief Invalid Task Identifier */
57 #define WSF_INVALID_TASK_ID 0xFF
58 
59 /*! \brief Get Diagnostic Task Identifier */
60 #if WSF_OS_DIAG == TRUE
61 #define WSF_OS_GET_ACTIVE_HANDLER_ID() WsfActiveHandler
62 #else
63 #define WSF_OS_GET_ACTIVE_HANDLER_ID() WSF_INVALID_TASK_ID
64 #endif /* WSF_OS_DIAG */
65 
66 /** @name WSF Task Events
67  *
68  */
69 /**@{*/
70 #define WSF_MSG_QUEUE_EVENT 0x01 /*!< \brief Message queued for event handler */
71 #define WSF_TIMER_EVENT 0x02 /*!< \brief Timer expired for event handler */
72 #define WSF_HANDLER_EVENT 0x04 /*!< \brief Event set for event handler */
73 /**@}*/
74 
75 /**************************************************************************************************
76  Data Types
77 **************************************************************************************************/
78 
79 /*! \brief Event handler ID data type */
80 typedef uint8_t wsfHandlerId_t;
81 
82 /*! \brief Event handler event mask data type */
83 typedef uint16_t wsfEventMask_t;
84 
85 /*! \brief Task ID data type */
86 typedef wsfHandlerId_t wsfTaskId_t;
87 
88 /*! \brief Task event mask data type */
89 typedef uint8_t wsfTaskEvent_t;
90 
91 /*! \brief Idle check function. */
92 typedef bool_t (*WsfOsIdleCheckFunc_t)(void);
93 
94 /**************************************************************************************************
95  External Variables
96 **************************************************************************************************/
97 
98 /*! \brief Diagnostic Task Identifier */
99 extern wsfHandlerId_t WsfActiveHandler;
100 
101 /**************************************************************************************************
102  Data Types
103 **************************************************************************************************/
104 
105 /*! \brief Common message structure passed to event handler */
106 typedef struct
107 {
108  uint16_t param; /*!< \brief General purpose parameter passed to event handler */
109  uint8_t event; /*!< \brief General purpose event value passed to event handler */
110  uint8_t status; /*!< \brief General purpose status value passed to event handler */
111 } wsfMsgHdr_t;
112 
113 /**************************************************************************************************
114  Callback Function Types
115 **************************************************************************************************/
116 
117 /*************************************************************************************************/
118 /*!
119  * \brief Event handler callback function.
120  *
121  * \param event Mask of events set for the event handler.
122  * \param pMsg Pointer to message for the event handler.
123  */
124 /*************************************************************************************************/
125 typedef void (*wsfEventHandler_t)(wsfEventMask_t event, wsfMsgHdr_t *pMsg);
126 
127 /**************************************************************************************************
128  Function Declarations
129 **************************************************************************************************/
130 
131 /*************************************************************************************************/
132 /*!
133  * \brief Set an event for an event handler.
134  *
135  * \param handlerId Handler ID.
136  * \param event Event or events to set.
137  */
138 /*************************************************************************************************/
139 void WsfSetEvent(wsfHandlerId_t handlerId, wsfEventMask_t event);
140 
141 /*************************************************************************************************/
142 /*!
143  * \brief Lock task scheduling.
144  */
145 /*************************************************************************************************/
146 void WsfTaskLock(void);
147 
148 /*************************************************************************************************/
149 /*!
150  * \brief Unlock task scheduling.
151  */
152 /*************************************************************************************************/
153 void WsfTaskUnlock(void);
154 
155 /*************************************************************************************************/
156 /*!
157  * \brief Set the task used by the given handler as ready to run.
158  *
159  * \param handlerId Event handler ID.
160  * \param event Task event mask.
161  */
162 /*************************************************************************************************/
163 void WsfTaskSetReady(wsfHandlerId_t handlerId, wsfTaskEvent_t event);
164 
165 /*************************************************************************************************/
166 /*!
167  * \brief Return the task message queue used by the given handler.
168  *
169  * \param handlerId Event handler ID.
170  *
171  * \return Task message queue.
172  */
173 /*************************************************************************************************/
174 wsfQueue_t *WsfTaskMsgQueue(wsfHandlerId_t handlerId);
175 
176 /*************************************************************************************************/
177 /*!
178  * \brief Set the next WSF handler function in the WSF OS handler array. This function
179  * should only be called as part of the OS initialization procedure.
180  *
181  * \param handler WSF handler function.
182  *
183  * \return WSF handler ID for this handler.
184  */
185 /*************************************************************************************************/
186 wsfHandlerId_t WsfOsSetNextHandler(wsfEventHandler_t handler);
187 
188 /*************************************************************************************************/
189 /*!
190  * \brief Check if WSF is ready to sleep.
191  *
192  * \return Return TRUE if there are no pending WSF task events set, FALSE otherwise.
193  */
194 /*************************************************************************************************/
195 bool_t wsfOsReadyToSleep(void);
196 
197 /*************************************************************************************************/
198 /*!
199  * \brief Event dispatched. Designed to be called repeatedly from infinite loop.
200  */
201 /*************************************************************************************************/
202 void wsfOsDispatcher(void);
203 
204 /*************************************************************************************************/
205 /*!
206 * \brief Initialize OS control structure.
207 *
208 * \return None.
209 */
210 /*************************************************************************************************/
211 void WsfOsInit(void);
212 
213 /*************************************************************************************************/
214 /*!
215  * \brief OS starts main loop
216  */
217 /*************************************************************************************************/
218 void WsfOsEnterMainLoop(void);
219 
220 /*************************************************************************************************/
221 /*!
222  * \brief Register service check functions.
223  *
224  * \param func Service function.
225  */
226 /*************************************************************************************************/
228 
229 /*! \} */ /* WSF_OS_API */
230 
231 #ifdef __cplusplus
232 };
233 #endif
234 
235 #endif /* WSF_OS_H */
void WsfOsRegisterSleepCheckFunc(WsfOsIdleCheckFunc_t func)
Register service check functions.
uint16_t param
General purpose parameter passed to event handler.
Definition: wsf_os.h:108
void WsfSetEvent(wsfHandlerId_t handlerId, wsfEventMask_t event)
Set an event for an event handler.
uint8_t wsfTaskEvent_t
Task event mask data type.
Definition: wsf_os.h:89
uint16_t wsfEventMask_t
Event handler event mask data type.
Definition: wsf_os.h:83
void WsfTaskUnlock(void)
Unlock task scheduling.
uint8_t(* WsfOsIdleCheckFunc_t)(void)
Idle check function.
Definition: wsf_os.h:92
wsfQueue_t * WsfTaskMsgQueue(wsfHandlerId_t handlerId)
Return the task message queue used by the given handler.
void(* wsfEventHandler_t)(wsfEventMask_t event, wsfMsgHdr_t *pMsg)
Event handler callback function.
Definition: wsf_os.h:125
void WsfTaskSetReady(wsfHandlerId_t handlerId, wsfTaskEvent_t event)
Set the task used by the given handler as ready to run.
Platform-independent data types.
uint8_t wsfHandlerId_t
Event handler ID data type.
Definition: wsf_os.h:80
Queue structure.
Definition: wsf_queue.h:46
uint8_t event
General purpose event value passed to event handler.
Definition: wsf_os.h:109
void WsfOsInit(void)
Initialize OS control structure.
void wsfOsDispatcher(void)
Event dispatched. Designed to be called repeatedly from infinite loop.
void WsfTaskLock(void)
Lock task scheduling.
uint8_t status
General purpose status value passed to event handler.
Definition: wsf_os.h:110
uint8_t wsfOsReadyToSleep(void)
Check if WSF is ready to sleep.
wsfHandlerId_t WsfOsSetNextHandler(wsfEventHandler_t handler)
Set the next WSF handler function in the WSF OS handler array. This function should only be called as...
General purpose queue service.
wsfHandlerId_t wsfTaskId_t
Task ID data type.
Definition: wsf_os.h:86
wsfHandlerId_t WsfActiveHandler
Diagnostic Task Identifier.
Common message structure passed to event handler.
Definition: wsf_os.h:106
void WsfOsEnterMainLoop(void)
OS starts main loop.
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.