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
138#define __VSF_ARCH_PRI_INDEX(__N, __UNUSED) \
139 __vsf_arch_prio_index_##__N = (__N),
140
141enum {
144};
145
146#define __VSF_ARCH_PRI(__N, __BIT) \
147 VSF_ARCH_PRIO_##__N = \
148 ((VSF_ARCH_PRI_NUM - 1 - __vsf_arch_prio_index_##__N)) & 0xFF, \
149 vsf_arch_prio_##__N = \
150 ((VSF_ARCH_PRI_NUM - 1 - __vsf_arch_prio_index_##__N)) & 0xFF,
151
152
153typedef enum vsf_arch_prio_t {
154 // avoid vsf_arch_prio_t to be optimized to 8bit
159
164
166
170
171#ifndef VSF_APPLET_USE_ARCH_ABI
172# define VSF_APPLET_USE_ARCH_ABI ENABLED
173#endif
174#if VSF_APPLET_USE_ARCH_ABI == ENABLED
175// functions in section 4 of "Run-Time ABI for the ARM Architecture"
176// refer to: https://github.com/ARM-software/abi-aa/releases/download/2023Q1/rtabi32.pdf
177typedef struct vsf_arch_abi_vplt_t {
179
243# ifndef __VSF_APPLET__
245# endif
246#endif
247
248/*============================ GLOBAL VARIABLES ==============================*/
249/*============================ LOCAL VARIABLES ===============================*/
250/*============================ PROTOTYPES ====================================*/
251
252static VSF_CAL_ALWAYS_INLINE void vsf_arch_set_stack(uintptr_t stack)
253{
254 __set_MSP(stack);
255}
256
257static VSF_CAL_ALWAYS_INLINE uintptr_t vsf_arch_get_stack(void)
258{
259 return __get_MSP();
260}
261
262#if VSF_ARCH_USE_THREAD_REG == ENABLED
263static VSF_CAL_ALWAYS_INLINE uintptr_t vsf_arch_set_thread_reg(uintptr_t value)
264{
265 register uintptr_t result;
266 __asm__ __volatile__ ("MOV %0, r9" : "=r"(result));
267 __asm__ __volatile__ ("MOV r9, %0" : : "r"(value));
268 return result;
269}
270#endif
271
272#if VSF_ARCH_CFG_CALLSTACK_TRACE == ENABLED
274extern uint_fast16_t vsf_arch_get_callstack(uintptr_t sp, uintptr_t *callstack, uint_fast16_t callstack_num);
275#endif
276
277#ifdef __cplusplus
278}
279#endif
280
281#endif
282/* EOF */
283
#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:155
@ VSF_ARCH_PRIO_ENABLE_ALL
Definition cortex_m_generic.h:160
@ vsf_arch_prio_enable_all
Definition cortex_m_generic.h:161
@ __VSF_ARCH_PRIO_LEAST_MIN
Definition cortex_m_generic.h:156
@ VSF_ARCH_PRIO_INVALID
Definition cortex_m_generic.h:157
@ vsf_arch_prio_highest
Definition cortex_m_generic.h:167
@ VSF_ARCH_PRIO_DISABLE_ALL
Definition cortex_m_generic.h:162
@ vsf_arch_prio_invalid
Definition cortex_m_generic.h:158
@ VSF_ARCH_PRIO_HIGHEST
Definition cortex_m_generic.h:168
@ vsf_arch_prio_disable_all
Definition cortex_m_generic.h:163
#define __VSF_ARCH_PRI(__N, __BIT)
Definition cortex_m_generic.h:146
void vsf_arch_add_text_region(vsf_arch_text_region_t *region)
Definition cortex_m_generic.c:464
@ __vsf_arch_prio_index_number
Definition cortex_m_generic.h:143
uint64_t vsf_systimer_tick_t
Definition cortex_m_generic.h:136
uint_fast16_t vsf_arch_get_callstack(uintptr_t sp, uintptr_t *callstack, uint_fast16_t callstack_num)
Definition cortex_m_generic.c:474
#define __VSF_ARCH_PRI_INDEX(__N, __UNUSED)
Definition cortex_m_generic.h:138
__VSF_VPLT_DECORATOR__ vsf_arch_abi_vplt_t vsf_arch_abi_vplt
Definition cortex_m_generic.c:616
#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:177
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:178
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
#define VSF_MREPEAT(__COUNT, __MACRO, __PARAM)
Definition vsf_repeat_macro.h:51