• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
3  *
4  * UniProton is licensed under Mulan PSL v2.
5  * You can use this software according to the terms and conditions of the Mulan PSL v2.
6  * You may obtain a copy of Mulan PSL v2 at:
7  *          http://license.coscl.org.cn/MulanPSL2
8  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
9  * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
10  * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
11  * See the Mulan PSL v2 for more details.
12  * Create: 2009-12-22
13  * Description: Task模块
14  */
15 #include "prt_task_external.h"
16 #include "prt_task_internal.h"
17 #include "prt_amp_task_internal.h"
18 
19 /*
20  * 描述:Idle背景任务
21  */
OsTskIdleBgd(void)22 OS_SEC_TEXT void OsTskIdleBgd(void)
23 {
24     TskCoresleep coreSleep = NULL;
25     OS_SHOOK_ACTIVATE_PARA0(OS_HOOK_IDLE_PREFIX);
26 
27     while (TRUE) {
28         OS_MHOOK_ACTIVATE_PARA0(OS_HOOK_IDLE_PERIOD);
29 
30         /* 防止g_taskCoreSleep中间被修改后,判空无效 */
31         coreSleep = g_taskCoreSleep;
32         if (coreSleep != NULL) {
33             coreSleep();
34         }
35     }
36 }
37 
38 /*
39  * 描述:将任务添加到就绪队列, 调用者确保不会换核,并锁上rq
40  */
OsTskReadyAdd(struct TagTskCb * task)41 OS_SEC_L0_TEXT void OsTskReadyAdd(struct TagTskCb *task)
42 {
43     struct TagOsRunQue *rq = &g_runQueue;
44     TSK_STATUS_SET(task, OS_TSK_READY);
45 
46     OS_TSK_EN_QUE(rq, task, 0);
47     OsTskHighestSet();
48 
49     return;
50 }
51 
52 /*
53  * 描述:将任务添加到就绪链表头,关中断外部保证
54  */
OsTskReadyDel(struct TagTskCb * taskCb)55 OS_SEC_L0_TEXT void OsTskReadyDel(struct TagTskCb *taskCb)
56 {
57     struct TagOsRunQue *runQue = &g_runQueue;
58     TSK_STATUS_CLEAR(taskCb, OS_TSK_READY);
59 
60     OS_TSK_DE_QUE(runQue, taskCb, 0);
61     OsTskHighestSet();
62 
63     return;
64 }
65 
66 /*
67  * 描述:添加任务到超时链表
68  */
OsTskTimerAdd(struct TagTskCb * taskCb,uintptr_t timeout)69 OS_SEC_L0_TEXT void OsTskTimerAdd(struct TagTskCb *taskCb, uintptr_t timeout)
70 {
71     struct TagTskCb *tskDelay = NULL;
72     struct TagOsTskSortedDelayList *tskDlyBase = NULL;
73     struct TagListObject *taskList = NULL;
74 
75     tskDlyBase = &g_tskSortedDelay;
76 
77     taskCb->expirationTick = g_uniTicks + timeout;
78     taskList = &tskDlyBase->tskList;
79 
80     if (ListEmpty(taskList)) {
81         ListTailAdd(&taskCb->timerList, taskList);
82     } else {
83         /* Put the task to right location */
84         LIST_FOR_EACH(tskDelay, taskList, struct TagTskCb, timerList) {
85             if (tskDelay->expirationTick > taskCb->expirationTick) {
86                 break;
87             }
88         }
89 
90         ListTailAdd(&taskCb->timerList, &tskDelay->timerList);
91     }
92 
93     return;
94 }
95 
PRT_TaskDelSwitchHook(TskSwitchHook hook)96 OS_SEC_L4_TEXT U32 PRT_TaskDelSwitchHook(TskSwitchHook hook)
97 {
98     return OsHookDel(OS_HOOK_TSK_SWITCH, (OsVoidFunc)(uintptr_t)hook);
99 }
PRT_TaskAddSwitchHook(TskSwitchHook hook)100 OS_SEC_L4_TEXT U32 PRT_TaskAddSwitchHook(TskSwitchHook hook)
101 {
102     return OsHookAdd(OS_HOOK_TSK_SWITCH, (OsVoidFunc)(uintptr_t)hook);
103 }
104