Skip to content

Commit 8e62049

Browse files
committed
application: update rttthread demo_smode case to support SSTC extension
Signed-off-by: Huaqi Fang <[email protected]>
1 parent 09f7d3d commit 8e62049

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

application/rtthread/demo_smode/Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ NUCLEI_SDK_ROOT = ../../..
66
COMMON_FLAGS = -O3 -DSMODE_RTOS
77

88
XLCFG_TEE := 1
9+
# You can change to 0, if SSTC not present
10+
XLCFG_SSTC ?= 1
911

1012
SRCDIRS = .
1113
INCDIRS = .

application/rtthread/demo_smode/main.c

+21-3
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,15 @@ extern void entry(void);
8686
// Execute Hart ID
8787
#define EXECUTE_HARTID 0
8888

89+
#if defined(__SSTC_PRESENT) && __SSTC_PRESENT == 1
90+
#define SMODE_TIMER_IRQ SysTimer_S_IRQn
91+
#define SMODE_SWI_IRQ SysTimerSW_S_IRQn
92+
#else
93+
#define SMODE_TIMER_IRQ SysTimer_IRQn
94+
#define SMODE_SWI_IRQ SysTimerSW_IRQn
95+
#endif
96+
97+
8998
/* Create a stack for supervisor mode execution */
9099
uint8_t smode_stack[SMODE_STACK_SIZE] __attribute__((aligned(16)));
91100

@@ -112,10 +121,19 @@ int main_entry(void)
112121
};
113122

114123
__set_PMPENTRYx(0, &pmp_cfg);
115-
printf("Set ECLIC Timer Interrupt and Software Timer Interrupt to be executed in S-Mode\r\n");
116124
// before drop to S Mode, specifies in which privilege mode the interrupt should be taken
117-
ECLIC_SetModeIRQ(SysTimerSW_IRQn, PRV_S);
118-
ECLIC_SetModeIRQ(SysTimer_IRQn, PRV_S);
125+
ECLIC_SetModeIRQ(SMODE_TIMER_IRQ, PRV_S);
126+
ECLIC_SetModeIRQ(SMODE_SWI_IRQ, PRV_S);
127+
#if defined(__SSTC_PRESENT) && __SSTC_PRESENT == 1
128+
/* Disable S-mode access some system timer registers */
129+
SysTimer_DisableSAccess();
130+
/* Enable CY,TM,IR in CSR_MCOUNTEREN to allow S-mode access cycle,time,instret csr */
131+
SysTimer_EnableSSTC();
132+
printf("Set ECLIC Timer S-Mode Interrupt and Software Timer S-Mode Interrupt to be executed in S-Mode\r\n");
133+
#else
134+
printf("Set ECLIC Timer M-Mode Interrupt and Software Timer M-Mode Interrupt to be executed in S-Mode\r\n");
135+
SysTimer_EnableSAccess();
136+
#endif
119137

120138
printf("Drop to S-Mode to prepare RT-Thread Environment\r\n");
121139
/* Drop to S mode */

0 commit comments

Comments
 (0)