• 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_asm_cpu_external.h"
17 
18 OS_SEC_BSS struct TagOsTskSortedDelayList g_tskSortedDelay;
19 OS_SEC_BSS struct TagOsRunQue g_runQueue;  // 核的局部运行队列
20 
21 /*
22  * 描述:任务调度,切换到最高优先级任务
23  */
OsTskSchedule(void)24 OS_SEC_TEXT void OsTskSchedule(void)
25 {
26     /* 外层已经关中断 */
27     /* Find the highest task */
28     OsTskHighestSet();
29 
30     /* In case that running is not highest then reschedule */
31     if ((g_highestTask != RUNNING_TASK) && (g_uniTaskLock == 0)) {
32         UNI_FLAG |= OS_FLG_TSK_REQ;
33 
34         /* only if there is not HWI or TICK the trap */
35         if (OS_INT_INACTIVE) {
36             OsTaskTrap();
37             return;
38         }
39     }
40 
41     return;
42 }
43 
OsTskScheduleFast(void)44 OS_SEC_TEXT void OsTskScheduleFast(void)
45 {
46     /* Find the highest task */
47     OsTskHighestSet();
48 
49     /* In case that running is not highest then reschedule */
50     if ((g_highestTask != RUNNING_TASK) && (g_uniTaskLock == 0)) {
51         UNI_FLAG |= OS_FLG_TSK_REQ;
52 
53         /* only if there is not HWI or TICK the trap */
54         if (OS_INT_INACTIVE) {
55             OsTaskTrapFast();
56         }
57     }
58 }
59 
60 /*
61  * 描述:如果快速切换后只有中断恢复,使用此接口
62  */
OsTskScheduleFastPs(uintptr_t intSave)63 OS_SEC_TEXT void OsTskScheduleFastPs(uintptr_t intSave)
64 {
65     /* Find the highest task */
66     OsTskHighestSet();
67 
68     /* In case that running is not highest then reschedule */
69     if ((g_highestTask != RUNNING_TASK) && (g_uniTaskLock == 0)) {
70         UNI_FLAG |= OS_FLG_TSK_REQ;
71 
72         /* only if there is not HWI or TICK the trap */
73         if (OS_INT_INACTIVE) {
74             OsTaskTrapFastPs(intSave);
75         }
76     }
77 }
78 
OsTaskScan(void)79 OS_SEC_TEXT void OsTaskScan(void)
80 {
81     struct TagTskCb *taskCb = NULL;
82     bool needSchedule = FALSE;
83     struct TagListObject *tskSortedDelayList = &g_tskSortedDelay.tskList;
84 
85     LIST_FOR_EACH(taskCb, tskSortedDelayList, struct TagTskCb, timerList) {
86         if (taskCb->expirationTick > g_uniTicks) {
87             break;
88         }
89 
90         ListDelete(&taskCb->timerList);
91 
92         if ((OS_TSK_PEND & taskCb->taskStatus) != 0) {
93             TSK_STATUS_CLEAR(taskCb, OS_TSK_PEND);
94             ListDelete(&taskCb->pendList);
95             taskCb->taskSem = NULL;
96         } else if ((OS_TSK_EVENT_PEND & taskCb->taskStatus) != 0) {
97             TSK_STATUS_CLEAR(taskCb, OS_TSK_EVENT_PEND);
98         } else if ((OS_TSK_QUEUE_PEND & taskCb->taskStatus) != 0) {
99             ListDelete(&taskCb->pendList);
100             TSK_STATUS_CLEAR(taskCb, OS_TSK_QUEUE_PEND);
101         } else {
102             TSK_STATUS_CLEAR(taskCb, OS_TSK_DELAY);
103         }
104 
105         if ((OS_TSK_SUSPEND & taskCb->taskStatus) == 0) {
106             OsTskReadyAddBgd(taskCb);
107             needSchedule = TRUE;
108         }
109 
110         taskCb = LIST_COMPONENT(tskSortedDelayList, struct TagTskCb, timerList);
111     }
112 
113     if (needSchedule) {
114         OsTskScheduleFast();
115     }
116 }
117