-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathos_task.h
332 lines (309 loc) · 12.4 KB
/
os_task.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
/**
* @file os_task.h
* @author TheSomeMan
* @date 2020-11-03
* @copyright Ruuvi Innovations Ltd, license BSD-3-Clause.
*/
#ifndef OS_TASK_H
#define OS_TASK_H
#include <stdbool.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "os_wrapper_types.h"
#include "attribs.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef ATTR_NORETURN void (*os_task_func_t)(void* p_param);
typedef ATTR_NORETURN void (*os_task_func_const_param_t)(const void* p_param);
typedef ATTR_NORETURN void (*os_task_func_without_param_t)(void);
typedef void (*os_task_finite_func_with_param_t)(void* p_param);
typedef void (*os_task_finite_func_with_const_param_t)(const void* p_param);
typedef void (*os_task_finite_func_without_param_t)(void);
typedef UBaseType_t os_task_priority_t;
typedef TaskHandle_t os_task_handle_t;
typedef StackType_t os_task_stack_type_t;
typedef StaticTask_t os_task_static_t;
/**
* Create a new task thread.
* @param p_func - pointer to the task function which never returns.
* @param p_name - pointer to the task name
* @param stack_depth - the size of the task stack (in bytes)
* @param p_param - pointer that will be passed as the parameter to the task function
* @param priority - task priority
* @param[out] ph_task - pointer to the variable to return task handle
* @return true if successful
*/
ATTR_NONNULL(1, 6)
ATTR_WARN_UNUSED_RESULT
bool
os_task_create(
const os_task_func_t p_func,
const char* const p_name,
const uint32_t stack_depth,
void* const p_param,
const os_task_priority_t priority,
os_task_handle_t* const ph_task);
/**
* Create a new task thread.
* @param p_func - pointer to the task function which never returns and takes pointer to 'const' as an argument.
* @param p_name - pointer to the task name
* @param stack_depth - the size of the task stack (in bytes)
* @param p_param - pointer that will be passed as the parameter to the task function
* @param priority - task priority
* @param[out] ph_task - pointer to the variable to return task handle
* @return true if successful
*/
ATTR_NONNULL(1, 4, 6)
ATTR_WARN_UNUSED_RESULT
bool
os_task_create_with_const_param(
const os_task_func_const_param_t p_func,
const char* const p_name,
const uint32_t stack_depth,
const void* const p_param,
const os_task_priority_t priority,
os_task_handle_t* const ph_task);
/**
* Create a new task thread.
* @param p_func - pointer to the task function which never returns and takes no param.
* @param p_name - pointer to the task name
* @param stack_depth - the size of the task stack (in bytes)
* @param priority - task priority
* @param[out] ph_task - pointer to the variable to return task handle
* @return true if successful
*/
ATTR_NONNULL(1, 5)
ATTR_WARN_UNUSED_RESULT
bool
os_task_create_without_param(
const os_task_func_without_param_t p_func,
const char* const p_name,
const uint32_t stack_depth,
const os_task_priority_t priority,
os_task_handle_t* const ph_task);
/**
* Create a new task thread.
* @param p_func - pointer to the task function which may return.
* @param p_name - pointer to the task name
* @param stack_depth - the size of the task stack (in bytes)
* @param p_param - pointer that will be passed as the parameter to the task function
* @param priority - task priority
* @return true if successful
*/
ATTR_NONNULL(1)
ATTR_WARN_UNUSED_RESULT
bool
os_task_create_finite(
const os_task_finite_func_with_param_t p_func,
const char* const p_name,
const uint32_t stack_depth,
void* const p_param,
const os_task_priority_t priority);
/**
* Create a new task thread.
* @param p_func - pointer to the task function which may return and takes pointer to 'const' as an argument.
* @param p_name - pointer to the task name
* @param stack_depth - the size of the task stack (in bytes)
* @param p_param - pointer that will be passed as the parameter to the task function
* @param priority - task priority
* @return true if successful
*/
ATTR_NONNULL(1)
ATTR_WARN_UNUSED_RESULT
bool
os_task_create_finite_with_const_param(
const os_task_finite_func_with_const_param_t p_func,
const char* const p_name,
const uint32_t stack_depth,
const void* const p_param,
const os_task_priority_t priority);
/**
* Create a new task thread.
* @param p_func - pointer to the task function which may return and takes no param.
* @param p_name - pointer to the task name
* @param stack_depth - the size of the task stack (in bytes)
* @param priority - task priority
* @return true if successful
*/
ATTR_NONNULL(1)
ATTR_WARN_UNUSED_RESULT
bool
os_task_create_finite_without_param(
const os_task_finite_func_without_param_t p_func,
const char* const p_name,
const uint32_t stack_depth,
const os_task_priority_t priority);
/**
* Create a new task thread without using memory allocation from the heap.
* @param p_func - pointer to the task function which never returns.
* @param p_name - pointer to the task name
* @param p_stack_mem - pointer to the statically allocated buffer for stack
* @param stack_depth - the size of the task stack (in bytes)
* @param p_param - pointer that will be passed as the parameter to the task function
* @param priority - task priority
* @param p_task_mem - pointer to the statically allocated buffer for @ref os_task_static_t
* @param[out] ph_task - pointer to the variable to return task handle
* @return true if successful
*/
ATTR_NONNULL(1, 3, 7, 8)
ATTR_WARN_UNUSED_RESULT
bool
os_task_create_static(
const os_task_func_t p_func,
const char* const p_name,
os_task_stack_type_t* const p_stack_mem,
const uint32_t stack_depth,
void* const p_param,
const os_task_priority_t priority,
os_task_static_t* const p_task_mem,
os_task_handle_t* const ph_task);
/**
* Create a new task thread without using memory allocation from the heap.
* @param p_func - pointer to the task function which never returns and takes pointer to 'const' as an argument.
* @param p_name - pointer to the task name
* @param p_stack_mem - pointer to the statically allocated buffer for stack
* @param stack_depth - the size of the task stack (in bytes)
* @param p_param - pointer that will be passed as the parameter to the task function
* @param priority - task priority
* @param p_task_mem - pointer to the statically allocated buffer for @ref os_task_static_t
* @param[out] ph_task - pointer to the variable to return task handle
* @return true if successful
*/
ATTR_NONNULL(1, 3, 7, 8)
ATTR_WARN_UNUSED_RESULT
bool
os_task_create_static_with_const_param(
const os_task_func_const_param_t p_func,
const char* const p_name,
os_task_stack_type_t* const p_stack_mem,
const uint32_t stack_depth,
const void* const p_param,
const os_task_priority_t priority,
os_task_static_t* const p_task_mem,
os_task_handle_t* const ph_task);
/**
* Create a new task thread without using memory allocation from the heap.
* @param p_func - pointer to the task function which never returns and takes no param.
* @param p_name - pointer to the task name
* @param p_stack_mem - pointer to the statically allocated buffer for stack
* @param stack_depth - the size of the task stack (in bytes)
* @param priority - task priority
* @param p_task_mem - pointer to the statically allocated buffer for @ref os_task_static_t
* @param[out] ph_task - pointer to the variable to return task handle
* @return true if successful
*/
ATTR_NONNULL(1, 3, 6, 7)
ATTR_WARN_UNUSED_RESULT
bool
os_task_create_static_without_param(
const os_task_func_without_param_t p_func,
const char* const p_name,
os_task_stack_type_t* const p_stack_mem,
const uint32_t stack_depth,
const os_task_priority_t priority,
os_task_static_t* const p_task_mem,
os_task_handle_t* const ph_task);
/**
* Create a new task thread without using memory allocation from the heap.
* @param p_func - pointer to the task function which may return.
* @param p_name - pointer to the task name
* @param p_stack_mem - pointer to the statically allocated buffer for stack
* @param stack_depth - the size of the task stack (in bytes)
* @param p_param - pointer that will be passed as the parameter to the task function
* @param priority - task priority
* @param p_task_mem - pointer to the statically allocated buffer for @ref os_task_static_t
* @return true if successful
*/
ATTR_NONNULL(1, 3, 7)
ATTR_WARN_UNUSED_RESULT
bool
os_task_create_static_finite(
const os_task_finite_func_with_param_t p_func,
const char* const p_name,
os_task_stack_type_t* const p_stack_mem,
const uint32_t stack_depth,
void* const p_param,
const os_task_priority_t priority,
os_task_static_t* const p_task_mem);
/**
* Create a new task thread without using memory allocation from the heap.
* @param p_func - pointer to the task function which may return and takes pointer to 'const' as an argument.
* @param p_name - pointer to the task name
* @param p_stack_mem - pointer to the statically allocated buffer for stack
* @param stack_depth - the size of the task stack (in bytes)
* @param p_param - pointer that will be passed as the parameter to the task function
* @param priority - task priority
* @param p_task_mem - pointer to the statically allocated buffer for @ref os_task_static_t
* @return true if successful
*/
ATTR_NONNULL(1, 3, 7)
ATTR_WARN_UNUSED_RESULT
bool
os_task_create_static_finite_with_const_param(
const os_task_finite_func_with_const_param_t p_func,
const char* const p_name,
os_task_stack_type_t* const p_stack_mem,
const uint32_t stack_depth,
const void* const p_param,
const os_task_priority_t priority,
os_task_static_t* const p_task_mem);
/**
* Create a new task thread without using memory allocation from the heap.
* @param p_func - pointer to the task function which may return and takes no param.
* @param p_name - pointer to the task name
* @param p_stack_mem - pointer to the statically allocated buffer for stack
* @param stack_depth - the size of the task stack (in bytes)
* @param priority - task priority
* @param p_task_mem - pointer to the statically allocated buffer for @ref os_task_static_t
* @return true if successful
*/
ATTR_NONNULL(1, 3, 6)
ATTR_WARN_UNUSED_RESULT
bool
os_task_create_static_finite_without_param(
const os_task_finite_func_without_param_t p_func,
const char* const p_name,
os_task_stack_type_t* const p_stack_mem,
const uint32_t stack_depth,
const os_task_priority_t priority,
os_task_static_t* const p_task_mem);
/**
* Remove the task from the RTOS kernel's scheduler.
* @note All resources (dynamic memory, sockets, file descriptors, ...) allocated by the task will remain allocated.
* @param ph_task - ptr to variable which contains the task handle, this variable will be automatically cleared.
*/
ATTR_NONNULL(1)
void
os_task_delete(os_task_handle_t* const ph_task);
/**
* Get task name for the current thread.
* @return pointer to the string with the current task name.
*/
ATTR_WARN_UNUSED_RESULT
const char*
os_task_get_name(void);
/**
* Get task priority for the current thread.
* @return task priority for the current task.
*/
ATTR_WARN_UNUSED_RESULT
os_task_priority_t
os_task_get_priority(void);
/**
* Delay a task for a given number of ticks.
* @param delay_ticks
*/
void
os_task_delay(const os_delta_ticks_t delay_ticks);
/**
* Get the handle of the current task.
* @return handle of the current task - @ref os_task_handle_t
*/
ATTR_WARN_UNUSED_RESULT
os_task_handle_t
os_task_get_cur_task_handle(void);
#ifdef __cplusplus
}
#endif
#endif // OS_TASK_H