1 /*
2 * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
3 * Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice, this list of
9 * conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
12 * of conditions and the following disclaimer in the documentation and/or other materials
13 * provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its contributors may be used
16 * to endorse or promote products derived from this software without specific prior written
17 * permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 /**
33 * @defgroup los_task Task
34 * @ingroup kernel
35 */
36
37 #ifndef _LOS_TASK_H
38 #define _LOS_TASK_H
39
40 #include "los_config.h"
41 #include "los_context.h"
42 #include "los_event.h"
43 #include "los_tick.h"
44 #include "los_sortlink.h"
45
46 #ifdef __cplusplus
47 #if __cplusplus
48 extern "C" {
49 #endif /* __cplusplus */
50 #endif /* __cplusplus */
51
52 /**
53 * @ingroup los_task
54 * Task error code: Insufficient memory for task creation.
55 *
56 * Value: 0x03000200
57 *
58 * Solution: Allocate bigger memory partition to task creation.
59 */
60 #define LOS_ERRNO_TSK_NO_MEMORY LOS_ERRNO_OS_FATAL(LOS_MOD_TSK, 0x00)
61
62 /**
63 * @ingroup los_task
64 * Task error code: Null parameter.
65 *
66 * Value: 0x02000201
67 *
68 * Solution: Check the parameter.
69 */
70 #define LOS_ERRNO_TSK_PTR_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x01)
71
72 /**
73 * @ingroup los_task
74 * Task error code: The task stack is not aligned.
75 *
76 * Value: 0x02000202
77 *
78 * Solution: Align the task stack.
79 */
80 #define LOS_ERRNO_TSK_STKSZ_NOT_ALIGN LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x02)
81
82 /**
83 * @ingroup los_task
84 * Task error code: Incorrect task priority.
85 *
86 * Value: 0x02000203
87 *
88 * Solution: Re-configure the task priority by referring to the priority range.
89 */
90 #define LOS_ERRNO_TSK_PRIOR_ERROR LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x03)
91
92 /**
93 * @ingroup los_task
94 * Task error code: The task entrance is NULL.
95 *
96 * Value: 0x02000204
97 *
98 * Solution: Define the task entrance function.
99 */
100 #define LOS_ERRNO_TSK_ENTRY_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x04)
101
102 /**
103 * @ingroup los_task
104 * Task error code: The task name is NULL.
105 *
106 * Value: 0x02000205
107 *
108 * Solution: Set the task name.
109 */
110 #define LOS_ERRNO_TSK_NAME_EMPTY LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x05)
111
112 /**
113 * @ingroup los_task
114 * Task error code: The task stack size is too small.
115 *
116 * Value: 0x02000206
117 *
118 * Solution: Expand the task stack.
119 */
120 #define LOS_ERRNO_TSK_STKSZ_TOO_SMALL LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x06)
121
122 /**
123 * @ingroup los_task
124 * Task error code: Invalid task ID.
125 *
126 * Value: 0x02000207
127 *
128 * Solution: Check the task ID.
129 */
130 #define LOS_ERRNO_TSK_ID_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x07)
131
132 /**
133 * @ingroup los_task
134 * Task error code: The task is already suspended.
135 *
136 * Value: 0x02000208
137 *
138 * Solution: Suspend the task after it is resumed.
139 */
140 #define LOS_ERRNO_TSK_ALREADY_SUSPENDED LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x08)
141
142 /**
143 * @ingroup los_task
144 * Task error code: The task is not suspended.
145 *
146 * Value: 0x02000209
147 *
148 * Solution: Suspend the task.
149 */
150 #define LOS_ERRNO_TSK_NOT_SUSPENDED LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x09)
151
152 /**
153 * @ingroup los_task
154 * Task error code: The task is not created.
155 *
156 * Value: 0x0200020a
157 *
158 * Solution: Create the task.
159 */
160 #define LOS_ERRNO_TSK_NOT_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x0a)
161
162 /**
163 * @ingroup los_task
164 * Task error code: The task message is nonzero.
165 *
166 * Value: 0x0200020c
167 *
168 * Solution: This error code is not in use temporarily.
169 */
170 #define LOS_ERRNO_TSK_MSG_NONZERO LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x0c)
171
172 /**
173 * @ingroup los_task
174 * Task error code: The task delay occurs during an interrupt.
175 *
176 * Value: 0x0300020d
177 *
178 * Solution: Perform this operation after exiting from the interrupt.
179 */
180 #define LOS_ERRNO_TSK_DELAY_IN_INT LOS_ERRNO_OS_FATAL(LOS_MOD_TSK, 0x0d)
181
182 /**
183 * @ingroup los_task
184 * Task error code: The task delay occurs when the task is locked.
185 *
186 * Value: 0x0200020e
187 *
188 * Solution: Perform this operation after unlocking the task.
189 */
190 #define LOS_ERRNO_TSK_DELAY_IN_LOCK LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x0e)
191
192 /**
193 * @ingroup los_task
194 * Task error code: The task that is being scheduled is invalid.
195 *
196 * Value: 0x0200020f
197 *
198 * Solution: Check the task.
199 */
200 #define LOS_ERRNO_TSK_YIELD_INVALID_TASK LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x0f)
201
202 /**
203 * @ingroup los_task
204 * Task error code: Only one task or no task is available for scheduling.
205 *
206 * Value: 0x02000210
207 *
208 * Solution: Increase the number of tasks.
209 */
210 #define LOS_ERRNO_TSK_YIELD_NOT_ENOUGH_TASK LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x10)
211
212 /**
213 * @ingroup los_task
214 * Task error code: No free task control block is available.
215 *
216 * Value: 0x02000211
217 *
218 * Solution: Increase the number of task control blocks.
219 */
220 #define LOS_ERRNO_TSK_TCB_UNAVAILABLE LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x11)
221
222 /**
223 * @ingroup los_task
224 * Task error code: The task hook function is not matchable.
225 *
226 * Value: 0x02000212
227 *
228 * Solution: This error code is not in use temporarily.
229 */
230 #define LOS_ERRNO_TSK_HOOK_NOT_MATCH LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x12)
231
232 /**
233 * @ingroup los_task
234 * Task error code: The number of task hook functions exceeds the permitted upper limit.
235 *
236 * Value: 0x02000213
237 *
238 * Solution: This error code is not in use temporarily.
239 */
240 #define LOS_ERRNO_TSK_HOOK_IS_FULL LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x13)
241
242 /**
243 * @ingroup los_task
244 * Task error code: The operation is performed on the system-level task.
245 *
246 * Value: 0x02000214
247 *
248 * Solution: Check the task ID and do not operate on the system-level task.
249 */
250 #define LOS_ERRNO_TSK_OPERATE_SYSTEM_TASK LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x14)
251 #define LOS_ERRNO_TSK_OPERATE_IDLE LOS_ERRNO_TSK_OPERATE_SYSTEM_TASK
252
253 /**
254 * @ingroup los_task
255 * Task error code: The task that is being suspended is locked.
256 *
257 * Value: 0x03000215
258 *
259 * Solution: Suspend the task after unlocking the task.
260 */
261 #define LOS_ERRNO_TSK_SUSPEND_LOCKED LOS_ERRNO_OS_FATAL(LOS_MOD_TSK, 0x15)
262
263 /**
264 * @ingroup los_task
265 * Task error code: The task stack fails to be freed.
266 *
267 * Value: 0x02000217
268 *
269 * Solution: This error code is not in use temporarily.
270 */
271 #define LOS_ERRNO_TSK_FREE_STACK_FAILED LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x17)
272
273 /**
274 * @ingroup los_task
275 * Task error code: The task stack area is too small.
276 *
277 * Value: 0x02000218
278 *
279 * Solution: This error code is not in use temporarily.
280 */
281 #define LOS_ERRNO_TSK_STKAREA_TOO_SMALL LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x18)
282
283 /**
284 * @ingroup los_task
285 * Task error code: The task fails to be activated.
286 *
287 * Value: 0x03000219
288 *
289 * Solution: Perform task switching after creating an idle task.
290 */
291 #define LOS_ERRNO_TSK_ACTIVE_FAILED LOS_ERRNO_OS_FATAL(LOS_MOD_TSK, 0x19)
292
293 /**
294 * @ingroup los_task
295 * Task error code: Too many task configuration items.
296 *
297 * Value: 0x0200021a
298 *
299 * Solution: This error code is not in use temporarily.
300 */
301 #define LOS_ERRNO_TSK_CONFIG_TOO_MANY LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x1a)
302
303 /**
304 * @ingroup los_task
305 * Task error code:
306 *
307 * Value: 0x0200021b
308 *
309 * Solution: This error code is not in use temporarily.
310 */
311 #define LOS_ERRNO_TSK_CP_SAVE_AREA_NOT_ALIGN LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x1b)
312
313 /**
314 * @ingroup los_task
315 * Task error code:
316 *
317 * Value: 0x0200021d
318 *
319 * Solution: This error code is not in use temporarily.
320 */
321 #define LOS_ERRNO_TSK_MSG_Q_TOO_MANY LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x1d)
322
323 /**
324 * @ingroup los_task
325 * Task error code:
326 *
327 * Value: 0x0200021e
328 *
329 * Solution: This error code is not in use temporarily.
330 */
331 #define LOS_ERRNO_TSK_CP_SAVE_AREA_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x1e)
332
333 /**
334 * @ingroup los_task
335 * Task error code:
336 *
337 * Value: 0x0200021f
338 *
339 * Solution: This error code is not in use temporarily.
340 */
341 #define LOS_ERRNO_TSK_SELF_DELETE_ERR LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x1f)
342
343 /**
344 * @ingroup los_task
345 * Task error code: The task stack size is too large.
346 *
347 * Value: 0x02000220
348 *
349 * Solution: shrink the task stack size parameter.
350 */
351 #define LOS_ERRNO_TSK_STKSZ_TOO_LARGE LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x20)
352
353 /**
354 * @ingroup los_task
355 * Task error code: Suspending software timer task is not allowed.
356 *
357 * Value: 0x02000221
358 *
359 * Solution: Check the task ID and do not suspend software timer task.
360 */
361 #define LOS_ERRNO_TSK_SUSPEND_SWTMR_NOT_ALLOWED LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x21)
362
363 /**
364 * @ingroup los_task
365 * Task error code: The operation is performed on the software timer task.
366 *
367 * Value: 0x02000222
368 *
369 * Solution: Check the task ID and do not operate on the software timer task.
370 */
371 #define LOS_ERRNO_TSK_OPERATE_SWTMR LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x22)
372
373 /**
374 * @ingroup los_task
375 * Task error code: Task timeout.
376 *
377 * Value: 0x02000223
378 *
379 * Solution: Check whether the waiting time and timeout are reasonable.
380 */
381 #define LOS_ERRNO_TSK_TIMEOUT LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x23)
382
383 /**
384 * @ingroup los_task
385 * Task error code: This task cannot wait for other tasks to finish.
386 *
387 * Value: 0x02000224
388 *
389 * Solution: Check the task properties and whether it is waiting for other tasks to finish.
390 */
391 #define LOS_ERRNO_TSK_NOT_JOIN LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x24)
392
393 /**
394 * @ingroup los_task
395 * Task error code: Tasks can't join himself.
396 *
397 * Value: 0x02000225
398 *
399 * Solution: Check whether the task ID is the current running task.
400 */
401 #define LOS_ERRNO_TSK_NOT_JOIN_SELF LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x25)
402
403 /**
404 * @ingroup los_task
405 * Task error code: This task operation is not allowed to be performed in an interrupt.
406 *
407 * Value: 0x02000226
408 *
409 * Solution: Check whether the interface is used in interrupts.
410 */
411 #define LOS_ERRNO_TSK_NOT_ALLOW_IN_INT LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x26)
412
413 /**
414 * @ingroup los_task
415 * Task error code: An exited task cannot be deleted.
416 *
417 * Value: 0x02000227
418 *
419 * Solution: Check whether a Joinable task exists. If so, call LOS_TaskJoin to reclaim resources.
420 */
421 #define LOS_ERRNO_TSK_ALREADY_EXIT LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x27)
422
423 /**
424 * @ingroup los_task
425 * Task error code: Locked scheduling does not allow tasks to be blocked.
426 *
427 * Value: 0x02000228
428 *
429 * Solution: Check for faulty lock scheduling logic.
430 */
431 #define LOS_ERRNO_TSK_SCHED_LOCKED LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x28)
432
433 /**
434 * @ingroup los_task
435 * Task error code: The task is processing signals.
436 *
437 * Value: 0x02000229
438 *
439 * Solution: Check and Stop the trigger signal so that the task is not processing the signal.
440 */
441 #define LOS_ERRNO_TSK_PROCESS_SIGNAL LOS_ERRNO_OS_ERROR(LOS_MOD_TSK, 0x29)
442
443 /**
444 * @ingroup los_task
445 * Define the type of the task entry function.
446 *
447 */
448 typedef VOID *(*TSK_ENTRY_FUNC)(UINT32 arg);
449
450 /**
451 * @ingroup los_task
452 * Define the structure of the parameters used for task creation.
453 *
454 * Information of specified parameters passed in during task creation.
455 */
456 typedef struct tagTskInitParam {
457 TSK_ENTRY_FUNC pfnTaskEntry; /**< Task entrance function */
458 UINT16 usTaskPrio; /**< Task priority */
459 UINT32 uwArg; /**< Task parameters */
460 UINTPTR stackAddr; /**< Task stack memory */
461 UINT32 uwStackSize; /**< Task stack size */
462 CHAR *pcName; /**< Task name */
463 UINT32 uwResved; /**< Reserved */
464 } TSK_INIT_PARAM_S;
465
466 /**
467 * @ingroup los_task
468 * Task detach attribute.
469 */
470 #define LOS_TASK_ATTR_JOINABLE 0x80000000
471
472 /**
473 * @ingroup los_task
474 * Task name length
475 */
476 #define LOS_TASK_NAMELEN 32
477
478 /**
479 * @ingroup los_task
480 * Task information structure.
481 */
482 typedef struct tagTskInfo {
483 CHAR acName[LOS_TASK_NAMELEN]; /**< Task entrance function */
484 UINT32 uwTaskID; /**< Task ID */
485 UINT16 usTaskStatus; /**< Task status */
486 UINT16 usTaskPrio; /**< Task priority */
487 VOID *pTaskSem; /**< Semaphore pointer */
488 VOID *pTaskMux; /**< Mutex pointer */
489 UINT32 uwSemID; /**< Sem ID */
490 UINT32 uwMuxID; /**< Mux ID */
491 EVENT_CB_S uwEvent; /**< Event */
492 UINT32 uwEventMask; /**< Event mask */
493 UINT32 uwStackSize; /**< Task stack size */
494 UINT32 uwTopOfStack; /**< Task stack top */
495 UINT32 uwBottomOfStack; /**< Task stack bottom */
496 UINT32 uwSP; /**< Task SP pointer */
497 UINT32 uwCurrUsed; /**< Current task stack usage */
498 UINT32 uwPeakUsed; /**< Task stack usage peak */
499 BOOL bOvf; /**< Flag that indicates whether a task stack overflow occurs */
500 } TSK_INFO_S;
501
502 /**
503 * @ingroup los_task
504 * Define the timeout interval as LOS_NO_WAIT.
505 */
506 #define LOS_NO_WAIT 0
507
508 /**
509 * @ingroup los_task
510 * Define the timeout interval as LOS_WAIT_FOREVER.
511 */
512 #define LOS_WAIT_FOREVER 0xFFFFFFFF
513
514 /**
515 * @ingroup los_task
516 * @brief Sleep the current task.
517 *
518 * @par Description:
519 * This API is used to delay the execution of the current task. The task is able to be scheduled
520 * after it is delayed for a specified number of Ticks.
521 *
522 * @attention
523 * <ul>
524 * <li>The task fails to be delayed if it is being delayed during interrupt processing or it is locked.</li>
525 * <li>If 0 is passed in and the task scheduling is not locked,
526 * execute the next task in the queue of tasks with the priority of the current task.
527 * If no ready task with the priority of the current task is available,
528 * the task scheduling will not occur, and the current task continues to be executed.</li>
529 * <li>The parameter passed in can not be equal to LOS_WAIT_FOREVER(0xFFFFFFFF).
530 * If that happens, the task will not sleep 0xFFFFFFFF milliseconds or sleep forever but sleep 0xFFFFFFFF Ticks.</li>
531 * </ul>
532 *
533 * @param mSecs [IN] Type #UINT32 Number of MS for which the task is delayed.
534 *
535 * @retval None
536 * @par Dependency:
537 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
538 * @see None
539 */
540 extern VOID LOS_Msleep(UINT32 mSecs);
541
542 /**
543 * @ingroup los_task
544 * @brief System kernel initialization function.
545 *
546 * @par Description:
547 * This API is used to start liteOS .
548 *
549 * @attention
550 * <ul>
551 * <li>None.</li>
552 * </ul>
553 *
554 * @param: None.
555 *
556 * @retval #LOS_OK 0:LiteOS start success.
557 *
558 * @par Dependency:
559 * <ul><li>los_config.h: the header file that contains the API declaration.</li></ul>
560 * @see
561 */
562 extern UINT32 LOS_Start(VOID);
563 extern NORETURN VOID LOS_Reboot(VOID);
564 extern NORETURN VOID LOS_Panic(const CHAR *fmt, ...);
565
566 /**
567 * @ingroup los_task
568 * @brief System kernel initialization function.
569 *
570 * @par Description:
571 * This API is used to Initialize kernel ,configure all system modules.
572 *
573 * @attention
574 * <ul>
575 * <li>None.</li>
576 * </ul>
577 *
578 * @param: None.
579 *
580 * @retval #LOS_OK 0:System kernel initialization success.
581 *
582 * @par Dependency:
583 * <ul><li>los_config.h: the header file that contains the API declaration.</li></ul>
584 * @see
585 */
586 extern UINT32 LOS_KernelInit(VOID);
587
588 /**
589 * @ingroup los_task
590 * @brief Create a task and suspend.
591 *
592 * @par Description:
593 * This API is used to create a task and suspend it. This task will not be added to the queue of ready tasks before
594 * resume it.
595 *
596 * @attention
597 * <ul>
598 * <li>During task creation, the task control block and task stack of the task that is previously automatically deleted
599 * are deallocated.</li>
600 * <li>The task name is a pointer and is not allocated memory.</li>
601 * <li>If the size of the task stack of the task to be created is 0, configure #LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE
602 * to specify the default task stack size. The stack size should be a reasonable value, if the size is too large, may
603 * cause memory exhaustion.</li>
604 * <li>The task stack size must be aligned on the boundary of 8 bytes. The size is determined by whether it is big
605 * enough to avoid task stack overflow.</li>
606 * <li>Less parameter value indicates higher task priority.</li>
607 * <li>The task name cannot be null.</li>
608 * <li>The pointer to the task executing function cannot be null.</li>
609 * <li>The two parameters of this interface is pointer, it should be a correct value, otherwise, the system may be
610 * abnormal.</li>
611 * <li>If user mode is enabled, user should input user stack pointer and size, the size must fit the stack pointer,
612 * uwStackSize remain as the kernel stack size.</li>
613 * </ul>
614 *
615 * @param taskID [OUT] Type #UINT32 * Task ID.
616 * @param taskInitParam [IN] Type #TSK_INIT_PARAM_S * Parameter for task creation.
617 *
618 * @retval #LOS_ERRNO_TSK_ID_INVALID Invalid Task ID, param puwTaskID is NULL.
619 * @retval #LOS_ERRNO_TSK_PTR_NULL Param pstInitParam is NULL.
620 * @retval #LOS_ERRNO_TSK_NAME_EMPTY The task name is NULL.
621 * @retval #LOS_ERRNO_TSK_ENTRY_NULL The task entrance is NULL.
622 * @retval #LOS_ERRNO_TSK_PRIOR_ERROR Incorrect task priority.
623 * @retval #LOS_ERRNO_TSK_STKSZ_TOO_LARGE The task stack size is too large.
624 * @retval #LOS_ERRNO_TSK_STKSZ_TOO_SMALL The task stack size is too small.
625 * @retval #LOS_ERRNO_TSK_TCB_UNAVAILABLE No free task control block is available.
626 * @retval #LOS_ERRNO_TSK_NO_MEMORY Insufficient memory for task creation.
627 * @retval #LOS_OK The task is successfully created.
628 * @par Dependency:
629 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
630 * <ul><li>los_config.h: the header file that contains system configuration items.</li></ul>
631 * @see LOS_TaskDelete
632 */
633 extern UINT32 LOS_TaskCreateOnly(UINT32 *taskID, TSK_INIT_PARAM_S *taskInitParam);
634
635 /**
636 * @ingroup los_task
637 * @brief Create a task.
638 *
639 * @par Description:
640 * This API is used to create a task. If the priority of the task created after system initialized is higher than
641 * the current task and task scheduling is not locked, it is scheduled for running.
642 * If not, the created task is added to the queue of ready tasks.
643 *
644 * @attention
645 * <ul>
646 * <li>During task creation, the task control block and task stack of the task that is previously automatically
647 * deleted are deallocated.</li>
648 * <li>The task name is a pointer and is not allocated memory.</li>
649 * <li>If the size of the task stack of the task to be created is 0, configure #LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE
650 * to specify the default task stack size.</li>
651 * <li>The task stack size must be aligned on the boundary of 8 bytes. The size is determined by whether it is big
652 * enough to avoid task stack overflow.</li>
653 * <li>Less parameter value indicates higher task priority.</li>
654 * <li>The task name cannot be null.</li>
655 * <li>The pointer to the task executing function cannot be null.</li>
656 * <li>The two parameters of this interface is pointer, it should be a correct value, otherwise, the system may be
657 * abnormal.</li>
658 * <li>If user mode is enabled, user should input user stack pointer and size, the size must fit the stack pointer,
659 * uwStackSize remain as the kernel stack size.</li>
660 * </ul>
661 *
662 * @param taskID [OUT] Type #UINT32 * Task ID.
663 * @param taskInitParam [IN] Type #TSK_INIT_PARAM_S * Parameter for task creation.
664 *
665 * @retval #LOS_ERRNO_TSK_ID_INVALID Invalid Task ID, param puwTaskID is NULL.
666 * @retval #LOS_ERRNO_TSK_PTR_NULL Param pstInitParam is NULL.
667 * @retval #LOS_ERRNO_TSK_NAME_EMPTY The task name is NULL.
668 * @retval #LOS_ERRNO_TSK_ENTRY_NULL The task entrance is NULL.
669 * @retval #LOS_ERRNO_TSK_PRIOR_ERROR Incorrect task priority.
670 * @retval #LOS_ERRNO_TSK_STKSZ_TOO_LARGE The task stack size is too large.
671 * @retval #LOS_ERRNO_TSK_STKSZ_TOO_SMALL The task stack size is too small.
672 * @retval #LOS_ERRNO_TSK_TCB_UNAVAILABLE No free task control block is available.
673 * @retval #LOS_ERRNO_TSK_NO_MEMORY Insufficient memory for task creation.
674 * @retval #LOS_OK The task is successfully created.
675 * @par Dependency:
676 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
677 * <ul><li>los_config.h: the header file that contains system configuration items.</li></ul>
678 * @see LOS_TaskDelete
679 */
680 extern UINT32 LOS_TaskCreate(UINT32 *taskID, TSK_INIT_PARAM_S *taskInitParam);
681
682 /**
683 * @ingroup los_task
684 * @brief Resume a task.
685 *
686 * @par Description:
687 * This API is used to resume a suspended task.
688 *
689 * @attention
690 * <ul>
691 * <li>If the task is delayed or blocked, resume the task without adding it to the queue of ready tasks.</li>
692 * <li>If the priority of the task resumed after system initialized is higher than the current task and task scheduling
693 * is not locked, it is scheduled for running.</li>
694 * </ul>
695 *
696 * @param taskID [IN] Type #UINT32 Task ID. The task id value is obtained from task creation.
697 *
698 * @retval #LOS_ERRNO_TSK_ID_INVALID Invalid Task ID
699 * @retval #LOS_ERRNO_TSK_NOT_CREATED The task is not created.
700 * @retval #LOS_ERRNO_TSK_NOT_SUSPENDED The task is not suspended.
701 * @retval #LOS_OK The task is successfully resumed.
702 * @par Dependency:
703 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
704 * @see LOS_TaskSuspend
705 */
706 extern UINT32 LOS_TaskResume(UINT32 taskID);
707
708 /**
709 * @ingroup los_task
710 * @brief Suspend a task.
711 *
712 * @par Description:
713 * This API is used to suspend a specified task, and the task will be removed from the queue of ready tasks.
714 *
715 * @attention
716 * <ul>
717 * <li>The task that is running and locked cannot be suspended.</li>
718 * <li>The idle task and swtmr task cannot be suspended.</li>
719 * </ul>
720 *
721 * @param taskID [IN] Type #UINT32 Task ID. The task id value is obtained from task creation.
722 *
723 * @retval #LOS_ERRNO_TSK_OPERATE_IDLE Check the task ID and do not operate on the idle task.
724 * @retval #LOS_ERRNO_TSK_SUSPEND_SWTMR_NOT_ALLOWED Check the task ID and do not operate on the swtmr task.
725 * @retval #LOS_ERRNO_TSK_ID_INVALID Invalid Task ID
726 * @retval #LOS_ERRNO_TSK_NOT_CREATED The task is not created.
727 * @retval #LOS_ERRNO_TSK_ALREADY_SUSPENDED The task is already suspended.
728 * @retval #LOS_ERRNO_TSK_SUSPEND_LOCKED The task being suspended is current task and task scheduling
729 * is locked.
730 * @retval #LOS_OK The task is successfully suspended.
731 * @par Dependency:
732 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
733 * @see LOS_TaskResume
734 */
735 extern UINT32 LOS_TaskSuspend(UINT32 taskID);
736
737 /**
738 * @ingroup los_task
739 * @brief Delete a task.
740 *
741 * @par Description:
742 * This API is used to delete a specified task and release the resources for its task stack and task control block.
743 *
744 * @attention
745 * <ul>
746 * <li>The idle task and swtmr task cannot be deleted.</li>
747 * <li>If delete current task maybe cause unexpected error.</li>
748 * <li>If a task get a mutex is deleted or automatically deleted before release this mutex, other tasks pended
749 * this mutex maybe never be scheduled.</li>
750 * </ul>
751 *
752 * @param taskID [IN] Type #UINT32 Task ID. The task id value is obtained from task creation.
753 *
754 * @retval #LOS_ERRNO_TSK_OPERATE_IDLE Check the task ID and do not operate on the idle task.
755 * @retval #LOS_ERRNO_TSK_SUSPEND_SWTMR_NOT_ALLOWED Check the task ID and do not operate on the swtmr task.
756 * @retval #LOS_ERRNO_TSK_ID_INVALID Invalid Task ID
757 * @retval #LOS_ERRNO_TSK_NOT_CREATED The task is not created.
758 * @retval #LOS_OK The task is successfully deleted.
759 * @par Dependency:
760 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
761 * @see LOS_TaskCreate | LOS_TaskCreateOnly
762 */
763 extern UINT32 LOS_TaskDelete(UINT32 taskID);
764
765 /**
766 * @ingroup los_task
767 * @brief Delay a task.
768 *
769 * @par Description:
770 * This API is used to delay the execution of the current task. The task is able to be scheduled after it is delayed
771 * for a specified number of Ticks.
772 *
773 * @attention
774 * <ul>
775 * <li>The task fails to be delayed if it is being delayed during interrupt processing or it is locked.</li>
776 * <li>If 0 is passed in and the task scheduling is not locked, execute the next task in the queue of tasks with
777 * the same priority of the current task.
778 * If no ready task with the priority of the current task is available, the task scheduling will not occur, and the
779 * current task continues to be executed.</li>
780 * <li>Using the interface before system initialized is not allowed.</li>
781 * </ul>
782 *
783 * @param tick [IN] Type #UINT32 Number of Ticks for which the task is delayed.
784 *
785 * @retval #LOS_ERRNO_TSK_DELAY_IN_INT The task delay occurs during an interrupt.
786 * @retval #LOS_ERRNO_TSK_DELAY_IN_LOCK The task delay occurs when the task scheduling is locked.
787 * @retval #LOS_ERRNO_TSK_ID_INVALID Invalid Task ID
788 * @retval #LOS_ERRNO_TSK_YIELD_NOT_ENOUGH_TASK No tasks with the same priority is available for scheduling.
789 * @retval #LOS_OK The task is successfully delayed.
790 * @par Dependency:
791 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
792 * @see
793 */
794 extern UINT32 LOS_TaskDelay(UINT32 tick);
795
796 /**
797 * @ingroup los_task
798 * @brief Lock the task scheduling.
799 *
800 * @par Description:
801 * This API is used to lock the task scheduling. Task switching will not occur if the task scheduling is locked.
802 *
803 * @attention
804 * <ul>
805 * <li>If the task scheduling is locked, but interrupts are not disabled, tasks are still able to be interrupted.</li>
806 * <li>One is added to the number of task scheduling locks if this API is called. The number of locks is decreased by
807 * one if the task scheduling is unlocked. Therefore, this API should be used together with LOS_TaskUnlock.</li>
808 * </ul>
809 *
810 * @param None.
811 *
812 * @retval None.
813 * @par Dependency:
814 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
815 * @see LOS_TaskUnlock
816 */
817 extern VOID LOS_TaskLock(VOID);
818
819 /**
820 * @ingroup los_task
821 * @brief Unlock the task scheduling.
822 *
823 * @par Description:
824 * This API is used to unlock the task scheduling. Calling this API will decrease the number of task locks by one.
825 * If a task is locked more than once, the task scheduling will be unlocked only when the number of locks becomes zero.
826 *
827 * @attention
828 * <ul>
829 * <li>The number of locks is decreased by one if this API is called. One is added to the number of task scheduling
830 * locks if the task scheduling is locked. Therefore, this API should be used together with LOS_TaskLock.</li>
831 * </ul>
832 *
833 * @param None.
834 *
835 * @retval None.
836 * @par Dependency:
837 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
838 * @see LOS_TaskLock
839 */
840 extern VOID LOS_TaskUnlock(VOID);
841
842 /**
843 * @ingroup los_task
844 * @brief Set a task priority.
845 *
846 * @par Description:
847 * This API is used to set the priority of a specified task.
848 *
849 * @attention
850 * <ul>
851 * <li>If the set priority is higher than the priority of the current running task, task scheduling probably occurs.
852 * </li>
853 * <li>Changing the priority of the current running task also probably causes task scheduling.</li>
854 * <li>Using the interface to change the priority of software timer task and idle task is not allowed.</li>
855 * <li>Using the interface in the interrupt is not allowed.</li>
856 * </ul>
857 *
858 * @param taskID [IN] Type #UINT32 Task ID. The task id value is obtained from task creation.
859 * @param taskPrio [IN] Type #UINT16 Task priority.
860 *
861 * @retval #LOS_ERRNO_TSK_PRIOR_ERROR Incorrect task priority.Re-configure the task priority
862 * @retval #LOS_ERRNO_TSK_OPERATE_IDLE Check the task ID and do not operate on the idle task.
863 * @retval #LOS_ERRNO_TSK_ID_INVALID Invalid Task ID
864 * @retval #LOS_ERRNO_TSK_NOT_CREATED The task is not created.
865 * @retval #LOS_OK The task priority is successfully set to a specified priority.
866 * @par Dependency:
867 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
868 * @see LOS_TaskPriSet
869 */
870 extern UINT32 LOS_TaskPriSet(UINT32 taskID, UINT16 taskPrio);
871
872 /**
873 * @ingroup los_task
874 * @brief Set the priority of the current running task to a specified priority.
875 *
876 * @par Description:
877 * This API is used to set the priority of the current running task to a specified priority.
878 *
879 * @attention
880 * <ul>
881 * <li>Changing the priority of the current running task probably causes task scheduling.</li>
882 * <li>Using the interface to change the priority of software timer task and idle task is not allowed.</li>
883 * <li>Using the interface in the interrupt is not allowed.</li>
884 * </ul>
885 *
886 * @param taskPrio [IN] Type #UINT16 Task priority.
887 *
888 * @retval #LOS_ERRNO_TSK_PRIOR_ERROR Incorrect task priority.Re-configure the task priority
889 * @retval #LOS_ERRNO_TSK_OPERATE_IDLE Check the task ID and do not operate on the idle task.
890 * @retval #LOS_ERRNO_TSK_ID_INVALID Invalid Task ID
891 * @retval #LOS_ERRNO_TSK_NOT_CREATED The task is not created.
892 * @retval #LOS_OK The priority of the current running task is successfully set to a specified
893 * priority.
894 * @par Dependency:
895 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
896 * @see LOS_TaskPriGet
897 */
898 extern UINT32 LOS_CurTaskPriSet(UINT16 taskPrio);
899
900 /**
901 * @ingroup los_task
902 * @brief Change the scheduling sequence of tasks with the same priority.
903 *
904 * @par Description:
905 * This API is used to move current task in a queue of tasks with the same priority to the tail of the queue of ready
906 * tasks.
907 *
908 * @attention
909 * <ul>
910 * <li>At least two ready tasks need to be included in the queue of ready tasks with the same priority. If the
911 * less than two ready tasks are included in the queue, an error is reported.</li>
912 * </ul>
913 *
914 * @param None.
915 *
916 * @retval #LOS_ERRNO_TSK_ID_INVALID Invalid Task ID
917 * @retval #LOS_ERRNO_TSK_YIELD_NOT_ENOUGH_TASK No tasks with the same priority is available for scheduling.
918 * @retval #LOS_OK The scheduling sequence of tasks with same priority is
919 * successfully changed.
920 * @par Dependency:
921 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
922 * @see
923 */
924 extern UINT32 LOS_TaskYield(VOID);
925
926 /**
927 * @ingroup los_task
928 * @brief Obtain a task priority.
929 *
930 * @par Description:
931 * This API is used to obtain the priority of a specified task.
932 *
933 * @attention None.
934 *
935 * @param taskID [IN] Type #UINT32 Task ID. The task id value is obtained from task creation.
936 *
937 * @retval #OS_INVALID The task priority fails to be obtained.
938 * @retval #UINT16 The task priority.
939 * @par Dependency:
940 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
941 * @see LOS_TaskPriSet
942 */
943 extern UINT16 LOS_TaskPriGet(UINT32 taskID);
944
945 /**
946 * @ingroup los_task
947 * @brief Obtain current running task ID.
948 *
949 * @par Description:
950 * This API is used to obtain the ID of current running task.
951 *
952 * @attention
953 * <ul>
954 * <li> This interface should not be called before system initialized.</li>
955 * </ul>
956 *
957 * @retval #LOS_ERRNO_TSK_ID_INVALID Invalid Task ID.
958 * @retval #UINT32 Task ID.
959 * @par Dependency:
960 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
961 * @see
962 */
963 extern UINT32 LOS_CurTaskIDGet(VOID);
964
965 /**
966 * @ingroup los_task
967 * @brief Obtain next running task ID.
968 *
969 * @par Description:
970 * This API is used to obtain the ID of next running task.
971 *
972 * @attention None.
973 *
974 *
975 * @retval #LOS_ERRNO_TSK_ID_INVALID invalid Task ID.
976 * @retval #UINT32 task id.
977 * @par Dependency:
978 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
979 * @see
980 */
981 extern UINT32 LOS_NextTaskIDGet(VOID);
982
983 /**
984 * @ingroup los_task
985 * @brief Obtain next running task ID.
986 *
987 * @par Description:
988 * This API is used to obtain the ID of next running task.
989 *
990 * @attention None.
991 *
992 *
993 * @retval #NULL invalid Task name.
994 * @retval #CHAR* task name.
995 * @par Dependency:
996 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
997 * @see
998 */
999 extern CHAR *LOS_CurTaskNameGet(VOID);
1000
1001 /**
1002 * @ingroup los_task
1003 * @brief Obtain a task information structure.
1004 *
1005 * @par Description:
1006 * This API is used to obtain a task information structure.
1007 *
1008 * @attention
1009 * <ul>
1010 * <li>One parameter of this interface is a pointer, it should be a correct value, otherwise, the system may be
1011 * abnormal.</li>
1012 * </ul>
1013 *
1014 * @param taskID [IN] Type #UINT32 Task ID. The task id value is obtained from task creation.
1015 * @param taskInfo [OUT] Type #TSK_INFO_S* Pointer to the task information structure to be obtained.
1016 *
1017 * @retval #LOS_ERRNO_TSK_PTR_NULL Null parameter.
1018 * @retval #LOS_ERRNO_TSK_ID_INVALID Invalid task ID.
1019 * @retval #LOS_ERRNO_TSK_NOT_CREATED The task is not created.
1020 * @retval #LOS_OK The task information structure is successfully obtained.
1021 * @par Dependency:
1022 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
1023 * @see
1024 */
1025 extern UINT32 LOS_TaskInfoGet(UINT32 taskID, TSK_INFO_S *taskInfo);
1026
1027 /**
1028 * @ingroup los_task
1029 * @brief Obtain the task status.
1030 *
1031 * @par Description:
1032 * This API is used to obtain the task status.
1033 *
1034 * @attention None.
1035 *
1036 * @param taskID [IN] Type #TSK_HANDLE_T Task ID.
1037 * @param taskStatus [OUT] Type #UINT32 Pointer to the task status to be obtained.
1038 *
1039 * @retval #LOS_ERRNO_TSK_PTR_NULL 0x02000201: Null parameter.
1040 * @retval #LOS_ERRNO_TSK_ID_INVALID 0x02000207: Invalid task ID.
1041 * @retval #LOS_ERRNO_TSK_NOT_CREATED 0x0200020a: The task is not created.
1042 * @retval #LOS_OK 0: The task information structure is successfully obtained.
1043 * @par Dependency:
1044 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
1045 * @see
1046 */
1047 extern UINT32 LOS_TaskStatusGet(UINT32 taskID, UINT32* taskStatus);
1048
1049 /**
1050 * @ingroup los_monitor
1051 * @brief Obtain all tasks info.
1052 *
1053 * @par Description:
1054 * This API is used to obtain all tasks info.
1055 * @attention
1056 * <ul>
1057 * <li>This API can be called only after the CPU usage is initialized. Otherwise, -1 will be returned.</li>
1058 * </ul>
1059 *
1060 * @param None.
1061 *
1062 * @retval #OS_ERROR -1:all tasks info obtain failed.
1063 * @retval #LOS_OK 0:all tasks info is successfully obtained.
1064 * @par Dependency:
1065 * <ul><li>los_monitor.h: the header file that contains the API declaration.</li></ul>
1066 * @see LOS_TaskInfoMonitor
1067 */
1068 extern UINT32 LOS_TaskInfoMonitor(VOID);
1069
1070 /**
1071 * @ingroup los_task
1072 * @brief Obtain tasks switch info.
1073 *
1074 * @par Description:
1075 * This API is used to obtain tasks switch info.
1076 *
1077 * @attention None.
1078 *
1079 * @param index [IN] Type #UINT32 Switch info array index.
1080 * @param taskSwitchInfo [OUT] Type #UINT32* First 4 bytes is task id, and then is task name, name len is
1081 * OS_TSK_NAME_LEN.
1082 *
1083 * @retval #LOS_ERRNO_TSK_PTR_NULL 0x02000201: Null parameter.
1084 * @retval #LOS_OK 0: The task switch information is successfully obtained.
1085 * @par Dependency:
1086 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
1087 * @see
1088 */
1089 extern UINT32 LOS_TaskSwitchInfoGet(UINT32 index, UINT32 *taskSwitchInfo);
1090
1091 /**
1092 * @ingroup los_task
1093 * @brief Obtain tasks schduling info.
1094 *
1095 * @par Description:
1096 * This API is used to obtain task is scheduled.
1097 *
1098 * @attention None.
1099 *
1100 * @param None.
1101 *
1102 * @retval #TRUE Tasks is scheduled.
1103 * @retval #FALSE Tasks not scheduling yet.
1104 * @par Dependency:
1105 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
1106 * @see
1107 */
1108 extern BOOL LOS_TaskIsRunning(VOID);
1109
1110 /**
1111 * @ingroup los_task
1112 * @brief Obtain current new task ID.
1113 *
1114 * @par Description:
1115 * This API is used to obtain the ID of new task.
1116 *
1117 * @attention None.
1118 *
1119 *
1120 * @retval #LOS_ERRNO_TSK_ID_INVALID 0x02000207: invalid Task ID.
1121 * @retval # Task ID.
1122 * @par Dependency:
1123 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
1124 * @see
1125 */
1126 extern UINT32 LOS_NewTaskIDGet(VOID);
1127 /**
1128 * @ingroup los_task
1129 * @brief Obtain the task name.
1130 *
1131 * @par Description:
1132 * This API is used to obtain the task name.
1133 *
1134 * @attention None.
1135 *
1136 * @param taskID [IN] Task ID.
1137 *
1138 * @retval #NULL: invalid Task name.
1139 * @retval # Task name.
1140 * @par Dependency:
1141 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
1142 * @see
1143 */
1144 extern CHAR* LOS_TaskNameGet(UINT32 taskID);
1145
1146 /* *
1147 * @ingroup los_task
1148 * @brief: cpu delay.
1149 *
1150 * @par Description:
1151 * This API is used to wait for the subtask to finish and reclaim the resource.
1152 *
1153 * @attention:
1154 * <ul><li>None.</li></ul>
1155 *
1156 * @param taskID [IN] task ID.
1157 * @param retval [IN] Value returned when the task is complete.
1158 *
1159 * @retval: None.
1160 * @par Dependency:
1161 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
1162 * @see LOS_TaskDetach.
1163 */
1164 extern UINT32 LOS_TaskJoin(UINT32 taskID, UINTPTR *retval);
1165
1166 /* *
1167 * @ingroup los_task
1168 * @brief: Modify the task attributes to detach.
1169 *
1170 * @par Description:
1171 * This API is used to modify the attribute of the specified task to detach.
1172 *
1173 * @attention:
1174 * <ul><li>None.</li></ul>
1175 *
1176 * @param taskID [IN] task ID.
1177 *
1178 * @retval: None.
1179 * @par Dependency:
1180 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
1181 * @see LOS_TaskJoin.
1182 */
1183 extern UINT32 LOS_TaskDetach(UINT32 taskID);
1184
1185 /**
1186 * @ingroup los_task
1187 * Null task ID
1188 *
1189 */
1190 #define OS_TASK_ERRORID 0xFFFFFFFF
1191
1192 /**
1193 * @ingroup los_task
1194 * Define a usable task priority.
1195 *
1196 * Highest task priority.
1197 */
1198 #define OS_TASK_PRIORITY_HIGHEST 0
1199
1200 /**
1201 * @ingroup los_task
1202 * Define a usable task priority.
1203 *
1204 * Lowest task priority.
1205 */
1206 #define OS_TASK_PRIORITY_LOWEST 31
1207
1208 /**
1209 * @ingroup los_task
1210 * Flag that indicates the task or task control block status.
1211 *
1212 * The task control block is unused.
1213 */
1214 #define OS_TASK_STATUS_UNUSED 0x0001
1215
1216 /**
1217 * @ingroup los_task
1218 * Flag that indicates the task or task control block status.
1219 *
1220 * The task is suspended.
1221 */
1222 #define OS_TASK_STATUS_SUSPEND 0x0002
1223
1224 /**
1225 * @ingroup los_task
1226 * Flag that indicates the task or task control block status.
1227 *
1228 * The task is ready.
1229 */
1230 #define OS_TASK_STATUS_READY 0x0004
1231
1232 /**
1233 * @ingroup los_task
1234 * Flag that indicates the task or task control block status.
1235 *
1236 * The task is blocked.
1237 */
1238 #define OS_TASK_STATUS_PEND 0x0008
1239
1240 /**
1241 * @ingroup los_task
1242 * Flag that indicates the task or task control block status.
1243 *
1244 * The task is running.
1245 */
1246 #define OS_TASK_STATUS_RUNNING 0x0010
1247
1248 /**
1249 * @ingroup los_task
1250 * Flag that indicates the task or task control block status.
1251 *
1252 * The task is delayed.
1253 */
1254 #define OS_TASK_STATUS_DELAY 0x0020
1255
1256 /**
1257 * @ingroup los_task
1258 * Flag that indicates the task or task control block status.
1259 *
1260 * The time for waiting for an event to occur expires.
1261 */
1262 #define OS_TASK_STATUS_TIMEOUT 0x0040
1263
1264 /**
1265 * @ingroup los_task
1266 * Flag that indicates the task or task control block status.
1267 *
1268 * The task is blocked on a time.
1269 */
1270 #define OS_TASK_STATUS_PEND_TIME 0x0080
1271
1272 /**
1273 * @ingroup los_task
1274 * Flag that indicates the task or task control block status.
1275 *
1276 * The task exits and waits for the parent thread to reclaim the resource.
1277 */
1278 #define OS_TASK_STATUS_EXIT 0x0100
1279
1280 #if (LOSCFG_SECURE == 1)
1281 /**
1282 * @ingroup los_task
1283 * Flag that indicates the task or task control block status.
1284 *
1285 * This task is a user mode task.
1286 */
1287 #define OS_TASK_FLAG_USER_TASK 0x0200
1288 #endif
1289
1290 /**
1291 * @ingroup los_task
1292 * Flag that indicates the task or task control block status.
1293 *
1294 * Task stack allocated by the system.
1295 */
1296 #define OS_TASK_FLAG_STACK_FREE 0x0800
1297
1298 /**
1299 * @ingroup los_task
1300 * Flag that indicates the task property.
1301 *
1302 * The task is system-level task, like idle, swtmr and etc.
1303 */
1304 #define OS_TASK_FLAG_SYSTEM_TASK 0x1000U
1305
1306 /**
1307 * @ingroup los_task
1308 * Flag that indicates the task is processing signal.
1309 *
1310 */
1311 #define OS_TASK_FLAG_SIGNAL 0x2000
1312
1313 /**
1314 * @ingroup los_task
1315 * Flag that indicates the task or task control block status.
1316 *
1317 * The delayed operation of this task is frozen.
1318 */
1319 #define OS_TASK_FLAG_FREEZE 0x4000
1320
1321 /**
1322 * @ingroup los_task
1323 * Flag that indicates the task or task control block status.
1324 *
1325 * Task join properties, The parent thread needs to reclaim
1326 * the resource after the task ends.
1327 */
1328 #define OS_TASK_FLAG_JOINABLE 0x8000
1329
1330 /**
1331 * @ingroup los_task
1332 * Boundary on which the stack size is aligned.
1333 *
1334 */
1335 #define OS_TASK_STACK_SIZE_ALIGN 16
1336
1337 /**
1338 * @ingroup los_task
1339 * Boundary on which the stack address is aligned.
1340 *
1341 */
1342 #define OS_TASK_STACK_ADDR_ALIGN 8
1343
1344 /**
1345 * @ingroup los_task
1346 * Task stack top magic number.
1347 *
1348 */
1349 #define OS_TASK_MAGIC_WORD 0xCCCCCCCC
1350
1351 /**
1352 * @ingroup los_task
1353 * Initial task stack value.
1354 *
1355 */
1356 #define OS_TASK_STACK_INIT 0xCACACACA
1357
1358 /**
1359 * @ingroup los_task
1360 * Number of usable task priorities.
1361 */
1362 #define OS_TSK_PRINUM ((OS_TASK_PRIORITY_LOWEST - OS_TASK_PRIORITY_HIGHEST) + 1)
1363
1364 /**
1365 * @ingroup los_task
1366 * @brief the num of delayed tasks bucket
1367 */
1368 #define OS_TSK_SORTLINK_LEN 32
1369
1370 /**
1371 * @ingroup los_task
1372 * @brief the num of high-order bit
1373 */
1374 #define OS_TSK_HIGH_BITS 5U
1375
1376 /**
1377 * @ingroup los_task
1378 * @brief the num of low-order bit
1379 */
1380 #define OS_TSK_LOW_BITS (32U - OS_TSK_HIGH_BITS)
1381
1382 /**
1383 * @ingroup los_task
1384 * @brief the max num of roll
1385 */
1386 #define OS_TSK_MAX_ROLLNUM (0xFFFFFFFFU - OS_TSK_SORTLINK_LEN)
1387
1388 /**
1389 * @ingroup los_task
1390 * @brief the bit width occupied by the delayed ticks of task
1391 */
1392 #define OS_TSK_SORTLINK_LOGLEN 5
1393
1394 /**
1395 * @ingroup los_task
1396 * @brief the mask of delayed tasks bucket id.
1397 */
1398 #define OS_TSK_SORTLINK_MASK (OS_TSK_SORTLINK_LEN - 1U)
1399
1400 /**
1401 * @ingroup los_task
1402 * @brief the high-order mask of roll num.
1403 */
1404 #define OS_TSK_HIGH_BITS_MASK (OS_TSK_SORTLINK_MASK << OS_TSK_LOW_BITS)
1405
1406 /**
1407 * @ingroup los_task
1408 * @brief the low-order mask of roll num.
1409 */
1410 #define OS_TSK_LOW_BITS_MASK (~OS_TSK_HIGH_BITS_MASK)
1411
1412 /**
1413 * @ingroup los_task
1414 * @brief the max task count for switch.
1415 */
1416 #define OS_TASK_SWITCH_INFO_COUNT 0xA
1417
1418 /**
1419 * @ingroup los_task
1420 * @brief Get the real task ID.
1421 *
1422 * @par Description:
1423 * This API is used to get the real task ID.
1424 * @attention None.
1425 *
1426 * @param taskID [IN] Task ID.
1427 *
1428 * @retval real task ID.
1429 * @par Dependency:
1430 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
1431 * @see
1432 */
1433 #define OS_TSK_GET_INDEX(taskID) (taskID)
1434
1435 /**
1436 * @ingroup los_task
1437 * @brief Obtain the pointer to a task control block.
1438 *
1439 * @par Description:
1440 * This API is used to obtain the pointer to a task control block using a corresponding parameter.
1441 * @attention None.
1442 *
1443 * @param ptr [IN] Parameter used for obtaining the task control block.
1444 *
1445 * @retval Pointer to the task control block.
1446 * @par Dependency:
1447 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
1448 * @see
1449 */
1450 #define OS_TCB_FROM_PENDLIST(ptr) LOS_DL_LIST_ENTRY(ptr, LosTaskCB, pendList)
1451
1452 /**
1453 * @ingroup los_task
1454 * @brief Obtain the pointer to a task control block.
1455 *
1456 * @par Description:
1457 * This API is used to obtain the pointer to a task control block that has a specified task ID.
1458 * @attention None.
1459 *
1460 * @param taskID [IN] task ID.
1461 *
1462 * @retval Pointer to the task control block.
1463 * @par Dependency:
1464 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
1465 * @see
1466 */
1467 #define OS_TCB_FROM_TID(taskID) (((LosTaskCB *)g_taskCBArray) + (taskID))
1468 #define OS_IDLE_TASK_ENTRY ((TSK_ENTRY_FUNC)OsIdleTask)
1469
1470
1471 /**
1472 * @ingroup los_task
1473 * Define the task control block structure.
1474 */
1475 typedef struct {
1476 VOID *stackPointer; /**< Task stack pointer */
1477 UINT16 taskStatus;
1478 UINT16 priority;
1479 INT32 timeSlice;
1480 UINT32 waitTimes;
1481 SortLinkList sortList;
1482 UINT64 startTime;
1483 UINT32 stackSize; /**< Task stack size */
1484 UINT32 topOfStack; /**< Task stack top */
1485 UINT32 taskID; /**< Task ID */
1486 TSK_ENTRY_FUNC taskEntry; /**< Task entrance function */
1487 VOID *taskSem; /**< Task-held semaphore */
1488 VOID *taskMux; /**< Task-held mutex */
1489 UINT32 arg; /**< Parameter */
1490 CHAR *taskName; /**< Task name */
1491 LOS_DL_LIST pendList;
1492 LOS_DL_LIST timerList;
1493 LOS_DL_LIST joinList;
1494 UINTPTR joinRetval; /**< Return value of the end of the task, If the task does not exit by itself, the ID of the task that killed the task is recorded. */
1495 EVENT_CB_S event;
1496 UINT32 eventMask; /**< Event mask */
1497 UINT32 eventMode; /**< Event mode */
1498 VOID *msg; /**< Memory allocated to queues */
1499 INT32 errorNo;
1500 #if (LOSCFG_KERNEL_SIGNAL == 1)
1501 VOID *sig; /**< Task signal */
1502 #endif
1503 #ifdef LOSCFG_TASK_STRUCT_EXTENSION
1504 LOSCFG_TASK_STRUCT_EXTENSION; /**< Task extension field */
1505 #endif
1506 } LosTaskCB;
1507
OsTaskIsExit(const LosTaskCB * taskCB)1508 STATIC INLINE BOOL OsTaskIsExit(const LosTaskCB *taskCB)
1509 {
1510 return ((taskCB->taskStatus & OS_TASK_STATUS_EXIT) != 0);
1511 }
1512
1513 typedef struct {
1514 LosTaskCB *runTask;
1515 LosTaskCB *newTask;
1516 } LosTask;
1517
1518 typedef struct {
1519 LOS_DL_LIST *sortLink;
1520 UINT16 cursor;
1521 UINT16 reserved;
1522 } TaskSortLinkAttr;
1523
1524 /**
1525 * @ingroup los_task
1526 * Time slice structure.
1527 */
1528 typedef struct TaskTimeSlice {
1529 LosTaskCB *task; /**< Current running task */
1530 UINT16 time; /**< Expiration time point */
1531 UINT16 tout; /**< Expiration duration */
1532 } OsTaskRobin;
1533
1534 typedef struct {
1535 UINT8 maxCnt : 7; // bits [6:0] store count of task switch info
1536 UINT8 isFull : 1; // bit [7] store isfull status
1537 } TaskCountInfo;
1538
1539 /**
1540 * @ingroup los_task
1541 * Task switch information structure.
1542 *
1543 */
1544 typedef struct {
1545 UINT8 idx;
1546 TaskCountInfo cntInfo;
1547 UINT16 pid[OS_TASK_SWITCH_INFO_COUNT];
1548 CHAR name[OS_TASK_SWITCH_INFO_COUNT][LOS_TASK_NAMELEN];
1549 } TaskSwitchInfo;
1550
1551 #if (LOSCFG_BASE_CORE_EXC_TSK_SWITCH == 1)
1552 extern TaskSwitchInfo g_taskSwitchInfo;
1553 #endif
1554
1555 extern LosTask g_losTask;
1556
1557 /**
1558 * @ingroup los_task
1559 * Task lock flag.
1560 *
1561 */
1562 extern UINT16 g_losTaskLock;
1563
1564 /* *
1565 * @ingroup los_hw
1566 * Check task schedule.
1567 */
1568 #define LOS_CHECK_SCHEDULE (!g_losTaskLock)
1569
1570 /**
1571 * @ingroup los_task
1572 * Maximum number of tasks.
1573 *
1574 */
1575 extern UINT32 g_taskMaxNum;
1576
1577 /**
1578 * @ingroup los_task
1579 * Idle task ID.
1580 *
1581 */
1582 extern UINT32 g_idleTaskID;
1583
1584 /**
1585 * @ingroup los_task
1586 * Software timer task ID.
1587 *
1588 */
1589 #if (LOSCFG_BASE_CORE_SWTMR == 1)
1590 extern UINT32 g_swtmrTaskID;
1591 #endif
1592
1593 /**
1594 * @ingroup los_task
1595 * Starting address of a task.
1596 *
1597 */
1598 extern LosTaskCB *g_taskCBArray;
1599
1600 /**
1601 * @ingroup los_task
1602 * Free task linked list.
1603 *
1604 */
1605 extern LOS_DL_LIST g_losFreeTask;
1606
1607 /**
1608 * @ingroup los_task
1609 * Circular linked list that stores tasks that are deleted automatically.
1610 *
1611 */
1612 extern LOS_DL_LIST g_taskRecycleList;
1613
1614 /**
1615 * @ingroup los_task
1616 * @brief Initialization a task.
1617 *
1618 * @par Description:
1619 * This API is used to initialization a task.
1620 *
1621 * @attention
1622 * <ul>
1623 * <li>None.</li>
1624 * </ul>
1625 *
1626 * @param None.
1627 *
1628 * @retval UINT32 Initialization result.
1629 * @par Dependency:
1630 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
1631 * @see
1632 */
1633 extern UINT32 OsTaskInit(VOID);
1634
1635 /**
1636 * @ingroup los_task
1637 * @brief Create idle task.
1638 *
1639 * @par Description:
1640 * This API is used to create idle task.
1641 *
1642 * @attention
1643 * <ul>
1644 * <li>None.</li>
1645 * </ul>
1646 *
1647 * @param None.
1648 *
1649 * @retval UINT32 Create result.
1650 * @par Dependency:
1651 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
1652 * @see
1653 */
1654 extern UINT32 OsIdleTaskCreate(VOID);
1655
1656 /**
1657 * @ingroup los_task
1658 * @brief Check task switch.
1659 *
1660 * @par Description:
1661 * This API is used to check task switch.
1662 *
1663 * @attention
1664 * <ul>
1665 * <li>None.</li>
1666 * </ul>
1667 *
1668 * @param None.
1669 *
1670 * @retval None.
1671 * @par Dependency:
1672 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
1673 * @see
1674 */
1675 extern VOID OsTaskSwitchCheck(VOID);
1676
1677 /**
1678 * @ingroup los_task
1679 * @brief TaskMonInit.
1680 *
1681 * @par Description:
1682 * This API is used to taskMonInit.
1683 *
1684 * @attention
1685 * <ul>
1686 * <li>None.</li>
1687 * </ul>
1688 *
1689 * @param None.
1690 *
1691 * @retval None.
1692 * @par Dependency:
1693 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
1694 * @see
1695 */
1696 extern VOID OsTaskMonInit(VOID);
1697
1698 /**
1699 * @ingroup los_task
1700 * @brief Task entry.
1701 *
1702 * @par Description:
1703 * This API is used to task entry.
1704 *
1705 * @attention
1706 * <ul>
1707 * <li>None.</li>
1708 * </ul>
1709 *
1710 * @param taskID [IN] Type #UINT32 task id.
1711 *
1712 * @retval None.
1713 * @par Dependency:
1714 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
1715 * @see
1716 */
1717 extern VOID OsTaskEntry(UINT32 taskID);
1718
1719 /**
1720 * @ingroup los_task
1721 * @brief Get the task water line.
1722 *
1723 * @par Description:
1724 * This API is used to get the task water line.
1725 *
1726 * @attention
1727 * <ul>
1728 * <li>None.</li>
1729 * </ul>
1730 *
1731 * @param taskID [IN] Type #UINT32 task id.
1732 *
1733 * @retval UINT32 Task water line.
1734 * @par Dependency:
1735 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
1736 * @see None.
1737 */
1738 extern UINT32 OsGetTaskWaterLine(UINT32 taskID);
1739
1740 /**
1741 * @ingroup los_task
1742 * @brief Convert task status to string.
1743 *
1744 * @par Description:
1745 * This API is used to convert task status to string.
1746 *
1747 * @attention
1748 * <ul>
1749 * <li>None.</li>
1750 * </ul>
1751 *
1752 * @param taskStatus [IN] Type #UINT16 task status.
1753 *
1754 * @retval UINT8 * String.
1755 * @par Dependency:
1756 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
1757 * @see None.
1758 */
1759 extern UINT8 *OsConvertTskStatus(UINT16 taskStatus);
1760
1761 /**
1762 * @ingroup los_task
1763 * @brief Get all task information.
1764 *
1765 * @par Description:
1766 * This API is used to get all task information.
1767 *
1768 * @attention
1769 * <ul>
1770 * <li>None.</li>
1771 * </ul>
1772 *
1773 * @param None.
1774 *
1775 * @retval UINT32 All task information.
1776 * @par Dependency:
1777 * <ul><li>los_task.h: the header file that contains the API declaration.</li></ul>
1778 * @see None.
1779 */
1780 extern UINT32 OsGetAllTskInfo(VOID);
1781
1782 extern VOID *OsTskUserStackInit(VOID* stackPtr, VOID* userSP, UINT32 userStackSize);
1783
1784 extern UINT32 OsPmEnterHandlerSet(VOID (*func)(VOID));
1785
OsCurrTaskGet(VOID)1786 STATIC INLINE LosTaskCB *OsCurrTaskGet(VOID)
1787 {
1788 return g_losTask.runTask;
1789 }
1790
1791 extern VOID LOS_TaskResRecycle(VOID);
1792
1793 #ifdef __cplusplus
1794 #if __cplusplus
1795 }
1796 #endif /* __cplusplus */
1797 #endif /* __cplusplus */
1798
1799 #endif /* _LOS_TASK_H */
1800