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: mem模块的模块内头文件
14 */
15 #ifndef OS_CPU_ARMV7_M_EXTERNAL_H
16 #define OS_CPU_ARMV7_M_EXTERNAL_H
17
18 #include "prt_buildef.h"
19 #include "prt_hwi.h"
20 #include "prt_clk.h"
21
22 #define OS_MAX_CACHE_LINE_SIZE 4 /* 单核芯片定义为4 */
23 #define OS_MX_SYS_VECTOR_CNT 16 /* 系统向量个数 16 */
24 #define OS_HWI_PRI_INVALID_BYTE 4 /* 芯片优先级无效位数 */
25
26 /* M4支持中断嵌套,需要设置PRIGROUP = 0, 表达抢占优先级的位段[7:1],表达子优先级的位段[0:0] */
27 /* 初始化中断优先级组,[1,7]都为抢占优先级位断 */
28 #define OS_NVIC_AIRCR_PRIGROUP 6
29 /* 初始化中断优先级组 */
30 #define OS_HWI_MAX_PRI 0x8 /* 高抢占优先级留给SVC中断 */
31 #define OS_HWI_PRI_HIGHEST 0x00
32 #define OS_HWI_PRI_LOWEST 0xF0
33 #define OS_MX_VECTOR_CNT (OS_MX_SYS_VECTOR_CNT + OS_MX_IRQ_VECTOR_CNT) /* 系统向量16个 + 60(M3)/82(M4)个中断向量 */
34 #define OS_HWI_PRI_SHIELD_HIGH 0x80 /* 屏蔽高位 */
35 #define OS_HWI_SET_HOOK_ATTR(hwiNum, hwiPrio, hook)
36
37 #define OS_HWI_PRIO_CHECK(hwiPrio) ((hwiPrio) >= OS_HWI_MAX_PRI)
38 /* 为了保持对外接口统一(硬件中断号),mx的hwinum=irqnum=真实中断号-16(内部已处理, 见OsInterrupt) */
39 #define OS_IRQ2HWI(irqNum) (irqNum)
40 #define OS_HWI2IRQ(hwiNum) (hwiNum)
41 #define OS_HWI_GET_HWINUM(archNum) (archNum)
42 #define OS_HWI_GET_HWI_PRIO(hwiPrio) (((hwiPrio) << OS_HWI_PRI_INVALID_BYTE) | OS_HWI_PRI_SHIELD_HIGH)
43 #define OS_HWI_GET_USER_PRIO(hwiPrio) (((hwiPrio) & (~OS_HWI_PRI_SHIELD_HIGH)) >> OS_HWI_PRI_INVALID_BYTE)
44
45 #define OS_TICK_COUNT_UPDATE() \
46 do { \
47 (void)PRT_ClkGetCycleCount64(); \
48 } while (0)
49
50 extern U32 OsTickTimerStartMx(U32 cyclePerTick);
51 #define OS_HW_TICK_INIT() OsTickTimerStartMx(g_cyclePerTick)
52 /* 检查cyclepertick是否超出寄存器范围 */
53 #define OS_IS_TICK_PERIOD_INVALID(cyclePerTick) ((cyclePerTick) > 0x00FFFFFF || (cyclePerTick) == 0)
54
55 /*
56 * 模块间宏定义
57 */
58 #define OS_TSK_STACK_ADDR_ALIGN 16
59 #define OS_TSK_STACK_SIZE_ALIGN 16
60 #define OS_TSK_STACK_SIZE_ALLOC_ALIGN MEM_ADDR_ALIGN_016
61
62 /* 任务栈最小值 */
63 #define OS_TSK_MIN_STACK_SIZE (ALIGN((0x130), 16))
64
65 /* Idle任务的消息队列数 */
66 #define OS_IDLE_TASK_QUE_NUM 1
67
68 extern U64 OsU64DivGetQuotient(U64 dividend, U64 divisor);
69 extern U64 OsU64DivGetRemainder(U64 dividend, U64 divisor);
70 #define DIV64(a, b) OsU64DivGetQuotient((a), (b))
71 #define DIV64_REMAIN(a, b) OsU64DivGetRemainder((a), (b))
72
73 /*
74 * 任务上下文的结构体定义。
75 */
76 struct TagHwContext {
77 U32 r4;
78 U32 r5;
79 U32 r6;
80 U32 r7;
81 U32 r8;
82 U32 r9;
83 U32 r10;
84 U32 r11;
85 U32 basePri;
86 U32 excReturn;
87 U32 r0;
88 U32 r1;
89 U32 r2;
90 U32 r3;
91 U32 r12;
92 U32 lr;
93 U32 pc;
94 U32 psr;
95 };
96
97 #define OsIntUnLock() PRT_HwiUnLock()
98 #define OsIntLock() PRT_HwiLock()
99 #define OsIntRestore(intSave) PRT_HwiRestore(intSave)
100
101 #define OsTaskTrap() OsTaskSwitch()
102 #define OsHwiTrap() OsHwiSwitch()
103
104 /*
105 * 模块间内联函数定义
106 */
OsGetHwThreadId(void)107 OS_SEC_ALW_INLINE INLINE U32 OsGetHwThreadId(void)
108 {
109 return 0x0U;
110 }
111
OsMemAddrToUncache(uintptr_t addr)112 OS_SEC_ALW_INLINE INLINE uintptr_t OsMemAddrToUncache(uintptr_t addr)
113 {
114 return addr;
115 }
116
117 extern U32 OsGetSp(void);
118 extern U32 OsIntNumGet(void);
119 extern void OsTaskSwitch(void);
120 extern void OsHwiSwitch(void);
121 extern void OsTickIsr(void);
122
OsTaskTrapFast(void)123 OS_SEC_ALW_INLINE INLINE void OsTaskTrapFast(void)
124 {
125 OsTaskTrap();
126 }
127
OsTaskTrapFastPs(uintptr_t intSave)128 OS_SEC_ALW_INLINE INLINE void OsTaskTrapFastPs(uintptr_t intSave)
129 {
130 (void)intSave;
131 OsTaskTrap();
132 }
133
134 /* 传入任务切换时的栈地址 */
OsTskGetInstrAddr(uintptr_t addr)135 OS_SEC_ALW_INLINE INLINE uintptr_t OsTskGetInstrAddr(uintptr_t addr)
136 {
137 return ((struct TagHwContext *)addr)->pc;
138 }
139
140 #define OS_SPIN_LOCK_INIT(lockVar)
141
142 #if (OS_HARDWARE_PLATFORM == OS_CORTEX_M4)
143 #include "../cortex-m4/prt_cpu_m4_external.h"
144 #endif
145
146 #endif /* OS_CPU_ARMV7_M_EXTERNAL_H */
147