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 #ifndef PRT_AMP_TASK_INTERNAL_H
16 #define PRT_AMP_TASK_INTERNAL_H
17
18 #include "prt_task_external.h"
19
20 #define OS_TSK_EN_QUE(runQue, tsk, flags) OsEnqueueTaskAmp((runQue), (tsk))
21 #define OS_TSK_EN_QUE_HEAD(runQue, tsk, flags) OsEnqueueTaskHeadAmp((runQue), (tsk))
22 #define OS_TSK_DE_QUE(runQue, tsk, flags) OsDequeueTaskAmp((runQue), (tsk))
23
24 extern U32 OsTskAMPInit(void);
25 extern U32 OsIdleTskAMPCreate(void);
26
OsGetReadyList(struct TagOsRunQue * runQue,struct TagTskCb * tsk)27 OS_SEC_ALW_INLINE INLINE struct TagListObject *OsGetReadyList(struct TagOsRunQue *runQue, struct TagTskCb *tsk)
28 {
29 TskPrior priority;
30 struct TagListObject *readyList = NULL;
31 U32 *tskReadyListBitMap = NULL;
32 U32 *tskChildBitMap = NULL;
33
34 priority = tsk->priority;
35
36 readyList = &runQue->readyList[priority];
37 tskReadyListBitMap = &runQue->taskReadyListBitMap;
38 tskChildBitMap = &runQue->tskChildBitMap[0];
39
40 /* if first task that is added then update */
41 /* toggle the corresponing bit in g_readyPrioritiesBitMap */
42 if (ListEmpty(readyList)) {
43 /* 设置当前优先级所在的任务就绪链表子主BitMap表对应位 */
44 *tskReadyListBitMap |= OS_SET_RDY_TSK_BIT_MAP(priority);
45
46 /* 设置当前优先级所在的子BitMap对应位 */
47 tskChildBitMap[priority >> OS_TSK_PRIO_BIT_MAP_POW] |= OS_SET_CHILD_BIT_MAP(priority);
48 }
49
50 return readyList;
51 }
52
OsEnqueueTaskAmp(struct TagOsRunQue * runQue,struct TagTskCb * tsk)53 OS_SEC_ALW_INLINE INLINE void OsEnqueueTaskAmp(struct TagOsRunQue *runQue, struct TagTskCb *tsk)
54 {
55 struct TagListObject *readyList = NULL;
56
57 readyList = OsGetReadyList(runQue, tsk);
58 ListTailAdd(&tsk->pendList, readyList);
59 return;
60 }
61
OsEnqueueTaskHeadAmp(struct TagOsRunQue * runQue,struct TagTskCb * tsk)62 OS_SEC_ALW_INLINE INLINE void OsEnqueueTaskHeadAmp(struct TagOsRunQue *runQue, struct TagTskCb *tsk)
63 {
64 struct TagListObject *readyList = NULL;
65
66 readyList = OsGetReadyList(runQue, tsk);
67 ListAdd(&tsk->pendList, readyList);
68 return;
69 }
70
OsDequeueTaskAmp(struct TagOsRunQue * runQue,struct TagTskCb * tsk)71 OS_SEC_ALW_INLINE INLINE void OsDequeueTaskAmp(struct TagOsRunQue *runQue, struct TagTskCb *tsk)
72 {
73 TskPrior priority;
74 struct TagListObject *readyList = NULL;
75 U32 *tskReadyListBitMap = NULL;
76 U32 *tskChildBitMap = NULL;
77
78 priority = tsk->priority;
79 readyList = &runQue->readyList[priority];
80
81 ListDelete(&tsk->pendList);
82
83 tskReadyListBitMap = &runQue->taskReadyListBitMap;
84 tskChildBitMap = &runQue->tskChildBitMap[0];
85
86 /* if first task that is added then update */
87 /* toggle the corresponing bit in g_readyPrioritiesBitMap */
88 if (ListEmpty(readyList)) {
89 /* 清除当前优先级所在的子BitMap对应位 */
90 tskChildBitMap[priority >> OS_TSK_PRIO_BIT_MAP_POW] &= OS_CLR_CHILD_BIT_MAP(priority);
91
92 /* 当前优先级所在的任务就绪链表子BitMap全为0需要清除主BitMap表对应位 */
93 if (tskChildBitMap[priority >> OS_TSK_PRIO_BIT_MAP_POW] == 0) {
94 *tskReadyListBitMap &= OS_CLR_RDY_TSK_BIT_MAP(priority);
95 }
96 }
97
98 return;
99 }
100
101 #endif /* PRT_AMP_TASK_INTERNAL_H */
102