VSF Documented
rv_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 __RV_GENERIC_H__
19#define __RV_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#ifdef __cplusplus
30extern "C" {
31#endif
32
33/*============================ MACROS ========================================*/
34
35#ifndef __LITTLE_ENDIAN
36# define __LITTLE_ENDIAN 1
37#endif
38#ifndef __BYTE_ORDER
39# define __BYTE_ORDER __LITTLE_ENDIAN
40#endif
41
42#ifndef __VSF_ARCH_SYSTIMER_BITS
43# define __VSF_ARCH_SYSTIMER_BITS 64
44#endif
45
46// software interrupt provided by arch
47#ifndef VSF_ARCH_SWI_NUM
48# define VSF_ARCH_SWI_NUM 0
49#endif
50
51// callstack trace is disabled on RiscV by default.
52// To use callstack trace, please add -fno-omit-frame-pointer to compile options
53#ifndef VSF_ARCH_CFG_CALLSTACK_TRACE
54# define VSF_ARCH_CFG_CALLSTACK_TRACE DISABLED
55#endif
56
57/*============================ MACROFIED FUNCTIONS ===========================*/
58
59#define vsf_arch_wakeup()
60
61/*============================ TYPES =========================================*/
62
63#if VSF_SYSTIMER_CFG_IMPL_MODE != VSF_SYSTIMER_CFG_IMPL_NONE
64# if VSF_SYSTIMER_CFG_IMPL_MODE == VSF_SYSTIMER_IMPL_TICK_MODE
67# else
69# endif
70#endif
72
73/*============================ GLOBAL VARIABLES ==============================*/
74/*============================ LOCAL VARIABLES ===============================*/
75/*============================ PROTOTYPES ====================================*/
76
77static VSF_CAL_ALWAYS_INLINE vsf_gint_state_t vsf_get_interrupt(void)
78{
79 vsf_gint_state_t result;
80 __asm volatile("csrr %0, mstatus" : "=r"(result) : );
81 return result;
82}
83
84static VSF_CAL_ALWAYS_INLINE vsf_gint_state_t vsf_set_interrupt(vsf_gint_state_t level)
85{
86 vsf_gint_state_t result;
87 __asm volatile("csrrs %0, mstatus, %1" : "=r"(result) : "r"(level));
88 return result & 8;
89}
90
91static VSF_CAL_ALWAYS_INLINE vsf_gint_state_t vsf_disable_interrupt(void)
92{
93 vsf_gint_state_t result;
94 __asm volatile("csrrci %0, mstatus, 8" : "=r"(result) :);
95 return result & 8;
96}
97
98static VSF_CAL_ALWAYS_INLINE vsf_gint_state_t vsf_enable_interrupt(void)
99{
100 vsf_gint_state_t result;
101 __asm volatile("csrrsi %0, mstatus, 8" : "=r"(result) :);
102 return result & 8;
103}
104
105static VSF_CAL_ALWAYS_INLINE void vsf_arch_sleep(uint_fast32_t mode)
106{
107 __asm volatile("wfi" : :);
108}
109
110static VSF_CAL_ALWAYS_INLINE void vsf_arch_set_stack(uintptr_t stack)
111{
112 __asm volatile("mv sp, %0" : : "r"(stack) : );
113}
114
115static VSF_CAL_ALWAYS_INLINE uintptr_t vsf_arch_get_stack(void)
116{
117 uintptr_t result;
118 __asm volatile("mv %0, sp" : "=r"(result) : );
119 return result;
120}
121
122#if VSF_ARCH_CFG_CALLSTACK_TRACE == ENABLED
124extern uint_fast16_t vsf_arch_get_callstack(uintptr_t sp, uintptr_t *callstack, uint_fast16_t callstack_num);
125#endif
126
127#ifdef __cplusplus
128}
129#endif
130
131#endif
132/* EOF */
133
vsf_gint_state_t vsf_disable_interrupt(void)
Definition arm9_generic.c:176
vsf_gint_state_t vsf_get_interrupt(void)
Definition arm9_generic.c:164
void vsf_arch_sleep(uint32_t mode)
Definition arm9_generic.c:193
vsf_gint_state_t vsf_enable_interrupt(void)
Definition arm9_generic.c:181
vsf_gint_state_t vsf_set_interrupt(vsf_gint_state_t level)
Definition arm9_generic.c:169
bool
Definition type.h:60
uint64_t vsf_systimer_tick_t
Definition cortex_a_generic.h:73
int32_t vsf_systimer_tick_signed_t
Definition mcs51_generic.h:58
uint32_t vsf_gint_state_t
Definition rv_generic.h:71
void vsf_arch_add_text_region(vsf_arch_text_region_t *region)
Definition cortex_m_generic.c:464
uint_fast16_t vsf_arch_get_callstack(uintptr_t sp, uintptr_t *callstack, uint_fast16_t callstack_num)
Definition cortex_m_generic.c:474
uint32_t uintptr_t
Definition stdint.h:38
unsigned uint32_t
Definition stdint.h:9
int int32_t
Definition stdint.h:8
unsigned int uint_fast32_t
Definition stdint.h:27
unsigned long long uint64_t
Definition stdint.h:11
unsigned short uint_fast16_t
Definition stdint.h:25
Definition vsf_arch_abstraction.h:60