VSF Documented
cortex_m_generic.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2022 by VSF Team *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 ****************************************************************************/
17
18#ifndef __CORTEX_M_GENERIC_H__
19#define __CORTEX_M_GENERIC_H__
20
21/*============================ INCLUDES ======================================*/
22
23#include "hal/vsf_hal_cfg.h"
24
25#define __VSF_HEADER_ONLY_SHOW_ARCH_INFO__
26#include "hal/driver/driver.h"
27#undef __VSF_HEADER_ONLY_SHOW_ARCH_INFO__
28
29#include "./SysTick/systick.h"
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
35/*============================ MACROS ========================================*/
36
37#ifndef __LITTLE_ENDIAN
38# define __LITTLE_ENDIAN 1
39#endif
40#ifndef __BYTE_ORDER
41# define __BYTE_ORDER __LITTLE_ENDIAN
42#endif
43
44#if __ARM_ARCH == 6 || __TARGET_ARCH_6_M == 1 || __TARGET_ARCH_6S_M == 1
45# ifndef VSF_ARCH_PRI_NUM
46# define VSF_ARCH_PRI_NUM 4
47# undef VSF_ARCH_PRI_BIT
48# define VSF_ARCH_PRI_BIT 2
49# endif
50
51# ifndef VSF_ARCH_PRI_BIT
52# define VSF_ARCH_PRI_BIT 2
53# endif
54#elif __ARM_ARCH >= 7 || __TARGET_ARCH_7_M == 1 || __TARGET_ARCH_7E_M == 1
55# ifndef VSF_ARCH_PRI_NUM
56# define VSF_ARCH_PRI_NUM 16
57# undef VSF_ARCH_PRI_BIT
58# define VSF_ARCH_PRI_BIT 4
59# endif
60
61# ifndef VSF_ARCH_PRI_BIT
62# define VSF_ARCH_PRI_BIT 4
63# endif
64#endif
65
66#ifndef VSF_ARCH_CFG_CALLSTACK_TRACE
67# define VSF_ARCH_CFG_CALLSTACK_TRACE ENABLED
68#endif
69
70// software interrupt provided by arch
71#define VSF_ARCH_SWI_NUM 1
72
73#ifndef VSF_SYSTIMER_CFG_IMPL_MODE
75# define VSF_SYSTIMER_CFG_IMPL_MODE VSF_SYSTIMER_IMPL_WITH_NORMAL_TIMER
76#endif
77#define __VSF_ARCH_SYSTIMER_BITS 24
78
79/*============================ MACROFIED FUNCTIONS ===========================*/
80
81#define vsf_arch_wakeup()
82
83#if (__ARM_ARCH >= 7) || (__TARGET_ARCH_7_M == 1) || (__TARGET_ARCH_7E_M == 1)
84
85# define vsf_atom32_op(__ptr, ...) \
86 ({ \
87 int32_t _; \
88 do { \
89 _ = (int32_t)__LDREXW((volatile uint32_t *)(__ptr)); \
90 } while ((__STREXW((uint32_t)(__VA_ARGS__), (volatile uint32_t *)(__ptr))) != 0U);\
91 _; \
92 })
93
94# define vsf_atom16_op(__ptr, ...) \
95 ({ \
96 int16_t _; \
97 do { \
98 _ = (int16_t)__LDREXH((volatile uint16_t *)(__ptr)); \
99 } while ((__STREXH((uint16_t)(__VA_ARGS__), (volatile uint16_t *)(__ptr))) != 0U);\
100 _; \
101 })
102
103# define vsf_atom8_op(__ptr, ...) \
104 ({ \
105 int8_t _; \
106 do { \
107 _ = (int8_t)__LDREXB((volatile uint8_t *)(__ptr)); \
108 } while ((__STREXB((uint8_t)(__VA_ARGS__), (volatile uint8_t *)(__ptr))) != 0U);\
109 _; \
110 })
111
112# define vsf_spinlock_t uint32_t
113# define vsf_spinlock_init(__plock) \
114 do { \
115 *(__plock) = 0; \
116 } while (0)
117# define vsf_spin_lock(__plock) \
118 do { \
119 vsf_spinlock_t VSF_MACRO_SAFE_NAME(value) = __LDREXW((volatile vsf_spinlock_t *)(__plock));\
120 if (VSF_MACRO_SAFE_NAME(value) != 0) { \
121 __WFE(); \
122 } else if ((__STREXW(1, (volatile vsf_spinlock_t *)(__plock))) == 0U) {\
123 break; \
124 } \
125 } while (1)
126# define vsf_spin_unlock(__plock) \
127 do { \
128 *(__plock) = 0; \
129 __SEV(); \
130 } while (0)
131# define vsf_spin_trylock(__plock) (vsf_spin_lock(__plock), 1)
132#endif
133
134/*============================ TYPES =========================================*/
135
137
139 // compatible with MPU_RASR definitation
140 // MPU_RASR.S
143
144 // MPU_RASR.XN
147
148 // access permission
149 // MPU_RASR.AP
153
154 // MPU_RASR.C | MPU_RASR.B | MPU_RASR.TEX
155 VSF_ARCH_MPU_CACHABLE_WRITE_THROUGH_NOALLOC = (1ul << 17) | (0ul << 16) | (0ul << 19),
156 VSF_ARCH_MPU_CACHABLE_WRITE_BACK_NOALLOC = (1ul << 17) | (1ul << 16) | (0ul << 19),
157 VSF_ARCH_MPU_CACHABLE_WRITE_BACK_ALLOC = (1ul << 17) | (1ul << 16) | (1ul << 19),
160
161#define __VSF_ARCH_PRI_INDEX(__N, __UNUSED) \
162 __vsf_arch_prio_index_##__N = (__N),
163
164enum {
167};
168
169#define __VSF_ARCH_PRI(__N, __BIT) \
170 VSF_ARCH_PRIO_##__N = \
171 ((VSF_ARCH_PRI_NUM - 1 - __vsf_arch_prio_index_##__N)) & 0xFF, \
172 vsf_arch_prio_##__N = \
173 ((VSF_ARCH_PRI_NUM - 1 - __vsf_arch_prio_index_##__N)) & 0xFF,
174
175
176typedef enum vsf_arch_prio_t {
177 // avoid vsf_arch_prio_t to be optimized to 8bit
182
187
189
193
194#ifndef VSF_APPLET_USE_ARCH_ABI
195# define VSF_APPLET_USE_ARCH_ABI ENABLED
196#endif
197#if VSF_APPLET_USE_ARCH_ABI == ENABLED
198// functions in section 4 of "Run-Time ABI for the ARM Architecture"
199// refer to: https://github.com/ARM-software/abi-aa/releases/download/2023Q1/rtabi32.pdf
200typedef struct vsf_arch_abi_vplt_t {
202
266# ifndef __VSF_APPLET__
268# endif
269#endif
270
271/*============================ GLOBAL VARIABLES ==============================*/
272/*============================ LOCAL VARIABLES ===============================*/
273/*============================ PROTOTYPES ====================================*/
274
275static VSF_CAL_ALWAYS_INLINE void vsf_arch_set_stack(uintptr_t stack)
276{
277 __set_MSP(stack);
278}
279
280static VSF_CAL_ALWAYS_INLINE uintptr_t vsf_arch_get_stack(void)
281{
282 return __get_MSP();
283}
284
285#if VSF_ARCH_USE_THREAD_REG == ENABLED
286static VSF_CAL_ALWAYS_INLINE uintptr_t vsf_arch_set_thread_reg(uintptr_t value)
287{
288 register uintptr_t result;
289 __asm__ __volatile__ ("MOV %0, r9" : "=r"(result));
290 __asm__ __volatile__ ("MOV r9, %0" : : "r"(value));
291 return result;
292}
293#endif
294
295#if VSF_ARCH_CFG_CALLSTACK_TRACE == ENABLED
297extern uint_fast16_t vsf_arch_get_callstack(uintptr_t sp, uintptr_t *callstack, uint_fast16_t callstack_num);
298#endif
299
300// __MPU_PRESENT is maybe not available here
301//#if __MPU_PRESENT
302// if size is 0, means 4G
303extern void vsf_arch_mpu_disable(void);
304extern void vsf_arch_mpu_enable(void);
307
308// the region added later will have higher priority
309// if size is 0, means 4G
311//#endif
312
313#ifdef __cplusplus
314}
315#endif
316
317#endif
318/* EOF */
319
#define __volatile__
Definition __compiler.h:56
#define VSF_ARCH_PRI_NUM
Definition arm9_generic.h:46
vsf_arch_prio_t
Definition cortex_a_generic.h:88
int __aeabi_d2iz(double)
double __aeabi_l2d(long long)
long long __aeabi_llsr(long long, int)
int __aeabi_fcmpun(float, float)
long long __aeabi_f2lz(float)
int __aeabi_dcmpun(double, double)
long long __aeabi_uread8(void *)
void __aeabi_cdcmple(double, double)
double __aeabi_dmul(double, double)
unsigned long long __aeabi_d2ulz(double)
float __aeabi_fdiv(float, float)
lldiv_t __aeabi_ldivmod(long long, long long)
int __aeabi_fcmpgt(float, float)
unsigned __aeabi_f2uiz(float)
uidiv_return __aeabi_uidivmod(unsigned, unsigned)
int __aeabi_fcmplt(float, float)
float __aeabi_i2f(int)
double __aeabi_f2d(float)
unsigned __aeabi_d2uiz(double)
void __aeabi_cfrcmple(float, float)
int __aeabi_dcmpge(double, double)
long long __aeabi_llsl(long long, int)
float __aeabi_ui2f(unsigned)
float __aeabi_fadd(float, float)
int __aeabi_dcmpgt(double, double)
double __aeabi_i2d(int)
float __aeabi_ul2f(unsigned long long)
void __aeabi_cdrcmple(double, double)
double __aeabi_dadd(double, double)
int __aeabi_dcmpeq(double, double)
void __aeabi_cdcmpeq(double, double)
long long __aeabi_lmul(long long, long long)
double __aeabi_drsub(double, double)
double __aeabi_ddiv(double, double)
int __aeabi_dcmplt(double, double)
long long __aeabi_d2lz(double)
void __aeabi_cfcmple(float, float)
unsigned __aeabi_uidiv(unsigned, unsigned)
float __aeabi_fsub(float, float)
unsigned long long __aeabi_f2ulz(float)
double __aeabi_ui2d(unsigned)
int __aeabi_uread4(void *)
int __aeabi_fcmple(float, float)
double __aeabi_dsub(double, double)
float __aeabi_l2f(long long)
int __aeabi_idiv(int, int)
int __aeabi_fcmpeq(float, float)
double __aeabi_ul2d(unsigned long long)
int __aeabi_ulcmp(unsigned long long, unsigned long long)
float __aeabi_fmul(float, float)
long long __aeabi_lasr(long long, int)
int __aeabi_dcmple(double, double)
div_t __aeabi_idivmod(int, int)
float __aeabi_frsub(float, float)
int __aeabi_f2iz(float)
void __aeabi_cfcmpeq(float, float)
ulldiv_t __aeabi_uldivmod(unsigned long long, unsigned long long)
long long __aeabi_uwrite8(long long, void *)
int __aeabi_lcmp(long long, long long)
int __aeabi_uwrite4(int, void *)
int __aeabi_fcmpge(float, float)
float __aeabi_d2f(double)
@ __VSF_ARCH_PRIO_LEAST_MAX
Definition cortex_m_generic.h:178
@ VSF_ARCH_PRIO_ENABLE_ALL
Definition cortex_m_generic.h:183
@ vsf_arch_prio_enable_all
Definition cortex_m_generic.h:184
@ __VSF_ARCH_PRIO_LEAST_MIN
Definition cortex_m_generic.h:179
@ VSF_ARCH_PRIO_INVALID
Definition cortex_m_generic.h:180
@ vsf_arch_prio_highest
Definition cortex_m_generic.h:190
@ VSF_ARCH_PRIO_DISABLE_ALL
Definition cortex_m_generic.h:185
@ vsf_arch_prio_invalid
Definition cortex_m_generic.h:181
@ VSF_ARCH_PRIO_HIGHEST
Definition cortex_m_generic.h:191
@ vsf_arch_prio_disable_all
Definition cortex_m_generic.h:186
void vsf_arch_mpu_config_region(uint32_t idx, uint32_t baseaddr, uint32_t size, vsf_arch_mpu_feature_t feature)
#define __VSF_ARCH_PRI(__N, __BIT)
Definition cortex_m_generic.h:169
void vsf_arch_add_text_region(vsf_arch_text_region_t *region)
Definition cortex_m_generic.c:523
vsf_arch_mpu_feature_t
Definition cortex_m_generic.h:138
@ VSF_ARCH_MPU_CACHABLE_WRITE_THROUGH_NOALLOC
Definition cortex_m_generic.h:155
@ VSF_ARCH_MPU_ACCESS_NO
Definition cortex_m_generic.h:150
@ VSF_ARCH_MPU_NON_SHARABLE
Definition cortex_m_generic.h:142
@ VSF_ARCH_MPU_CACHABLE_WRITE_BACK_NOALLOC
Definition cortex_m_generic.h:156
@ VSF_ARCH_MPU_EXECUTABLE
Definition cortex_m_generic.h:145
@ VSF_ARCH_MPU_CACHABLE_WRITE_BACK_ALLOC
Definition cortex_m_generic.h:157
@ VSF_ARCH_MPU_NON_EXECUTABLE
Definition cortex_m_generic.h:146
@ VSF_ARCH_MPU_ACCESS_FULL
Definition cortex_m_generic.h:151
@ VSF_ARCH_MPU_ACCESS_READONLY
Definition cortex_m_generic.h:152
@ VSF_ARCH_MPU_SHARABLE
Definition cortex_m_generic.h:141
@ VSF_ARCH_MPU_NON_CACHABLE
Definition cortex_m_generic.h:158
void vsf_arch_mpu_clear_region(uint32_t idx)
uint64_t vsf_systimer_tick_t
Definition cortex_m_generic.h:136
void vsf_arch_mpu_add_region(uint32_t baseaddr, uint32_t size, vsf_arch_mpu_feature_t feature)
uint_fast16_t vsf_arch_get_callstack(uintptr_t sp, uintptr_t *callstack, uint_fast16_t callstack_num)
Definition cortex_m_generic.c:533
#define __VSF_ARCH_PRI_INDEX(__N, __UNUSED)
Definition cortex_m_generic.h:161
void vsf_arch_mpu_disable(void)
@ __vsf_arch_prio_index_number
Definition cortex_m_generic.h:166
__VSF_VPLT_DECORATOR__ vsf_arch_abi_vplt_t vsf_arch_abi_vplt
Definition cortex_m_generic.c:675
void vsf_arch_mpu_enable(void)
unsigned int uint32_t
Definition lvgl.h:43
#define VSF_ARCH_PRI_BIT
Definition mcs51_generic.h:42
uint32_t uintptr_t
Definition stdint.h:38
unsigned long long uint64_t
Definition stdint.h:11
unsigned short uint_fast16_t
Definition stdint.h:25
#define INT16_MAX
Definition stdint.h:50
#define INT16_MIN
Definition stdint.h:45
Definition cortex_m_generic.h:200
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_ui2d)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_f2lz)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_idiv)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_i2d)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_ul2f)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_dcmpgt)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_lmul)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_l2d)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_fcmple)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_lasr)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_uwrite8)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_dmul)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_d2f)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_dadd)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_dcmplt)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_uread4)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_fcmplt)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_fcmpeq)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_dsub)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_uldivmod)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_f2d)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_fcmpgt)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_dcmpun)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_i2f)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_dcmpge)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_drsub)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_idivmod)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_uread8)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_d2lz)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_fdiv)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_llsr)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_cdcmple)
vsf_vplt_info_t info
Definition cortex_m_generic.h:201
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_fcmpge)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_ldivmod)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_d2uiz)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_f2ulz)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_ulcmp)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_ui2f)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_dcmple)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_cdcmpeq)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_cfcmple)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_ul2d)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_uidiv)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_cfrcmple)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_fsub)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_f2uiz)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_fmul)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_d2ulz)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_frsub)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_ddiv)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_cfcmpeq)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_uwrite4)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_f2iz)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_cdrcmple)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_d2iz)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_uidivmod)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_fcmpun)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_llsl)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_lcmp)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_fadd)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_dcmpeq)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__aeabi_l2f)
Definition vsf_arch_abstraction.h:60
Definition vsf_cfg.h:95
vk_av_control_value_t value
Definition vsf_audio.h:171
#define __VSF_VPLT_DECORATOR__
Definition vsf_cfg.h:93
uint32_t size
Definition vsf_memfs.h:50
#define VSF_MREPEAT(__COUNT, __MACRO, __PARAM)
Definition vsf_repeat_macro.h:51