Merge pull request #48 from acevest/riscv_irq
riscv support all irq handler
This commit is contained in:
@@ -36,10 +36,4 @@
|
|||||||
// EXCCODE 11:0 exception code
|
// EXCCODE 11:0 exception code
|
||||||
#define MCAUSE_EXP_CODE_MASK 0x00000FFF
|
#define MCAUSE_EXP_CODE_MASK 0x00000FFF
|
||||||
|
|
||||||
#ifndef __ASSEMBLER__
|
|
||||||
void port_cpu_init();
|
|
||||||
|
|
||||||
void port_systick_priority_set(uint32_t priority);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // _RISCV_PORT_H_
|
#endif // _RISCV_PORT_H_
|
||||||
|
@@ -108,8 +108,15 @@ static void eclic_set_irq_priority(uint32_t source, uint8_t priority) {
|
|||||||
eclic_set_intctrl(CLIC_INT_TMR, intctrl_val);
|
eclic_set_intctrl(CLIC_INT_TMR, intctrl_val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void rv32_exception_entry();
|
||||||
__PORT__ void port_cpu_init() {
|
__PORT__ void port_cpu_init() {
|
||||||
|
|
||||||
|
__ASM__ __VOLATILE__("csrw mtvec, %0"::"r"(rv32_exception_entry));
|
||||||
|
|
||||||
|
// MTVT2: 0x7EC
|
||||||
|
// use mtvec as entry of irq and other trap
|
||||||
|
__ASM__ __VOLATILE__("csrc 0x7EC, 0x1");
|
||||||
|
|
||||||
eclic_enable_interrupt(CLIC_INT_TMR);
|
eclic_enable_interrupt(CLIC_INT_TMR);
|
||||||
|
|
||||||
eclic_set_irq_level(CLIC_INT_TMR, 0);
|
eclic_set_irq_level(CLIC_INT_TMR, 0);
|
||||||
@@ -119,3 +126,13 @@ __PORT__ void port_cpu_init() {
|
|||||||
__PORT__ void port_systick_priority_set(uint32_t priority) {
|
__PORT__ void port_systick_priority_set(uint32_t priority) {
|
||||||
eclic_set_irq_priority(CLIC_INT_TMR, priority);
|
eclic_set_irq_priority(CLIC_INT_TMR, priority);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
__PORT__ void *port_get_irq_vector_table() {
|
||||||
|
void *base = 0;
|
||||||
|
|
||||||
|
// MTVT: 0x307
|
||||||
|
__ASM__ __VOLATILE__("csrr %0, 0x307":"=r"(base));
|
||||||
|
|
||||||
|
return base;
|
||||||
|
}
|
||||||
|
@@ -15,15 +15,15 @@
|
|||||||
* within TencentOS.
|
* within TencentOS.
|
||||||
*---------------------------------------------------------------------------*/
|
*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
.global eclic_mtip_handler
|
||||||
.global irq_entry
|
.global irq_entry
|
||||||
.global trap_entry
|
.global trap_entry
|
||||||
|
|
||||||
.extern rv32_exception_entry
|
|
||||||
|
|
||||||
.align 2
|
.align 2
|
||||||
irq_entry:
|
irq_entry:
|
||||||
j rv32_exception_entry
|
j irq_entry
|
||||||
|
|
||||||
.align 2
|
.align 2
|
||||||
trap_entry:
|
trap_entry:
|
||||||
j rv32_exception_entry
|
j trap_entry
|
||||||
|
|
||||||
|
@@ -126,10 +126,8 @@ __KERNEL__ k_stack_t *cpu_task_stk_init(void *entry,
|
|||||||
|
|
||||||
regs = (cpu_context_t*) sp;
|
regs = (cpu_context_t*) sp;
|
||||||
|
|
||||||
for(int i=1; i<(sizeof(cpu_context_t)/sizeof(cpu_data_t)); i+=2) {
|
for(int i=1; i<(sizeof(cpu_context_t)/sizeof(cpu_data_t)); i++) {
|
||||||
// every task begin with "Tencent"
|
*(sp + i) = 0xACEADD00 | ((i / 10) << 4) | (i % 10);
|
||||||
*(sp + i - 1) = 0x0054656E;
|
|
||||||
*(sp + i - 0) = 0x63656E74;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cpu_data_t gp = 0;
|
cpu_data_t gp = 0;
|
||||||
@@ -137,7 +135,7 @@ __KERNEL__ k_stack_t *cpu_task_stk_init(void *entry,
|
|||||||
|
|
||||||
regs->gp = (cpu_data_t)gp; // global pointer
|
regs->gp = (cpu_data_t)gp; // global pointer
|
||||||
regs->a0 = (cpu_data_t)arg; // argument
|
regs->a0 = (cpu_data_t)arg; // argument
|
||||||
regs->ra = (cpu_data_t)0xACE00ACE; // return address
|
regs->ra = (cpu_data_t)exit; // return address
|
||||||
regs->mstatus = (cpu_data_t)0x00001880; // return to machine mode and enable interrupt
|
regs->mstatus = (cpu_data_t)0x00001880; // return to machine mode and enable interrupt
|
||||||
regs->mepc = (cpu_data_t)entry; // task entry
|
regs->mepc = (cpu_data_t)entry; // task entry
|
||||||
|
|
||||||
@@ -151,22 +149,16 @@ void cpu_trap_entry(cpu_data_t cause, cpu_context_t *regs)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SysTick_IRQHandler() {
|
|
||||||
port_systick_config((uint32_t)k_cpu_cycle_per_tick);
|
|
||||||
if (tos_knl_is_running()) {
|
|
||||||
tos_knl_irq_enter();
|
|
||||||
tos_tick_handler();
|
|
||||||
tos_knl_irq_leave();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void cpu_irq_entry(cpu_data_t irq)
|
void cpu_irq_entry(cpu_data_t irq)
|
||||||
{
|
{
|
||||||
if (irq != 7) {
|
void (*irq_handler)();
|
||||||
|
|
||||||
|
irq_handler = *((void (**)())(port_get_irq_vector_table() + irq*sizeof(cpu_addr_t)));
|
||||||
|
if((*irq_handler) == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SysTick_IRQHandler();
|
(*irq_handler)();
|
||||||
}
|
}
|
||||||
|
|
||||||
__API__ uint32_t tos_cpu_clz(uint32_t val)
|
__API__ uint32_t tos_cpu_clz(uint32_t val)
|
||||||
|
@@ -40,6 +40,14 @@ __PORT__ void port_systick_config(uint32_t cycle_per_tick);
|
|||||||
|
|
||||||
__PORT__ void port_systick_priority_set(uint32_t prio);
|
__PORT__ void port_systick_priority_set(uint32_t prio);
|
||||||
|
|
||||||
|
|
||||||
|
__PORT__ void port_cpu_init();
|
||||||
|
|
||||||
|
__PORT__ void port_systick_priority_set(uint32_t priority);
|
||||||
|
|
||||||
|
__PORT__ void* port_get_irq_vector_table();
|
||||||
|
|
||||||
|
|
||||||
#if TOS_CFG_TICKLESS_EN > 0u
|
#if TOS_CFG_TICKLESS_EN > 0u
|
||||||
|
|
||||||
__PORT__ void port_systick_resume(void);
|
__PORT__ void port_systick_resume(void);
|
||||||
|
@@ -25,10 +25,4 @@
|
|||||||
|
|
||||||
#define MCAUSE_EXP_CODE_MASK 0x7FFFFFFF
|
#define MCAUSE_EXP_CODE_MASK 0x7FFFFFFF
|
||||||
|
|
||||||
#ifndef __ASSEMBLER__
|
|
||||||
void port_cpu_init();
|
|
||||||
|
|
||||||
void port_systick_priority_set(uint32_t priority);
|
|
||||||
#endif /* __ASSEMBLER__ */
|
|
||||||
|
|
||||||
#endif /* _RISCV_PORT_H_ */
|
#endif /* _RISCV_PORT_H_ */
|
||||||
|
@@ -24,3 +24,10 @@ __PORT__ void port_cpu_init() {
|
|||||||
__PORT__ void port_systick_priority_set(uint32_t priority) {
|
__PORT__ void port_systick_priority_set(uint32_t priority) {
|
||||||
// DO NOTHING
|
// DO NOTHING
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
extern cpu_data_t irq_vector_table_base;
|
||||||
|
__PORT__ void* port_get_irq_vector_table() {
|
||||||
|
void *base = (void *) &irq_vector_table_base;
|
||||||
|
return base;
|
||||||
|
}
|
||||||
|
32
arch/risc-v/spike/gcc/riscv_port_s.S
Normal file
32
arch/risc-v/spike/gcc/riscv_port_s.S
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
/*----------------------------------------------------------------------------
|
||||||
|
* Tencent is pleased to support the open source community by making TencentOS
|
||||||
|
* available.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
|
||||||
|
* If you have downloaded a copy of the TencentOS binary from Tencent, please
|
||||||
|
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
|
||||||
|
*
|
||||||
|
* If you have downloaded a copy of the TencentOS source code from Tencent,
|
||||||
|
* please note that TencentOS source code is licensed under the BSD 3-Clause
|
||||||
|
* License, except for the third-party components listed below which are
|
||||||
|
* subject to different license terms. Your integration of TencentOS into your
|
||||||
|
* own projects may require compliance with the BSD 3-Clause License, as well
|
||||||
|
* as the other licenses applicable to the third-party components included
|
||||||
|
* within TencentOS.
|
||||||
|
*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
.global irq_vector_table_base
|
||||||
|
|
||||||
|
.extern SysTick_IRQHandler
|
||||||
|
|
||||||
|
.section .text
|
||||||
|
.align 2
|
||||||
|
irq_vector_table_base:
|
||||||
|
.word 0xACEACEAC
|
||||||
|
.word 0
|
||||||
|
.word 0
|
||||||
|
.word 0
|
||||||
|
.word 0
|
||||||
|
.word 0
|
||||||
|
.word 0
|
||||||
|
.word SysTick_IRQHandler
|
11
board/GigaDevice_GD32VF103C_START/BSP/Src/gd32vf103_it.c
Normal file
11
board/GigaDevice_GD32VF103C_START/BSP/Src/gd32vf103_it.c
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#include "tos.h"
|
||||||
|
|
||||||
|
// systick handler
|
||||||
|
void eclic_mtip_handler() {
|
||||||
|
port_systick_config((uint32_t)k_cpu_cycle_per_tick);
|
||||||
|
if (tos_knl_is_running()) {
|
||||||
|
tos_knl_irq_enter();
|
||||||
|
tos_tick_handler();
|
||||||
|
tos_knl_irq_leave();
|
||||||
|
}
|
||||||
|
}
|
@@ -46,7 +46,8 @@ ARCH_SRC = \
|
|||||||
C_SOURCES += $(ARCH_SRC)
|
C_SOURCES += $(ARCH_SRC)
|
||||||
|
|
||||||
HAL_DRIVER_SRC = \
|
HAL_DRIVER_SRC = \
|
||||||
$(TOP_DIR)/board/QEMU_Spike/Src/main.c
|
$(TOP_DIR)/board/QEMU_Spike/Src/main.c \
|
||||||
|
$(TOP_DIR)/board/QEMU_Spike/Src/gd32vf103_it.c
|
||||||
C_SOURCES += $(HAL_DRIVER_SRC)
|
C_SOURCES += $(HAL_DRIVER_SRC)
|
||||||
|
|
||||||
# ASM sources
|
# ASM sources
|
||||||
@@ -54,6 +55,7 @@ ASM_SOURCES =
|
|||||||
|
|
||||||
ASM_SOURCES_S = \
|
ASM_SOURCES_S = \
|
||||||
$(TOP_DIR)/arch/risc-v/rv32i/gcc/port_s.S \
|
$(TOP_DIR)/arch/risc-v/rv32i/gcc/port_s.S \
|
||||||
|
$(TOP_DIR)/arch/risc-v/spike/gcc/riscv_port_s.S \
|
||||||
start.S
|
start.S
|
||||||
|
|
||||||
|
|
||||||
|
9
board/QEMU_Spike/Src/gd32vf103_it.c
Normal file
9
board/QEMU_Spike/Src/gd32vf103_it.c
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#include "tos.h"
|
||||||
|
void SysTick_IRQHandler() {
|
||||||
|
port_systick_config((uint32_t)k_cpu_cycle_per_tick);
|
||||||
|
if (tos_knl_is_running()) {
|
||||||
|
tos_knl_irq_enter();
|
||||||
|
tos_tick_handler();
|
||||||
|
tos_knl_irq_leave();
|
||||||
|
}
|
||||||
|
}
|
@@ -137,12 +137,12 @@
|
|||||||
|
|
||||||
<listOptionValue builtIn="false" value=""${workspace_loc:/demo/TOS-CONFIG}""/>
|
<listOptionValue builtIn="false" value=""${workspace_loc:/demo/TOS-CONFIG}""/>
|
||||||
|
|
||||||
<listOptionValue builtIn="false" value=""${workspace_loc:/demo/TencentOS_tiny/arch/risc-v/rv32i}""/>
|
|
||||||
|
|
||||||
<listOptionValue builtIn="false" value=""${workspace_loc:/demo/TencentOS_tiny/arch/risc-v/spike}""/>
|
<listOptionValue builtIn="false" value=""${workspace_loc:/demo/TencentOS_tiny/arch/risc-v/spike}""/>
|
||||||
|
|
||||||
<listOptionValue builtIn="false" value=""${workspace_loc:/demo/TencentOS_tiny/kernel/evtdrv/include}""/>
|
<listOptionValue builtIn="false" value=""${workspace_loc:/demo/TencentOS_tiny/kernel/evtdrv/include}""/>
|
||||||
|
|
||||||
|
<listOptionValue builtIn="false" value=""${workspace_loc:/demo/TencentOS_tiny/arch/risc-v/rv32i/gcc/}""/>
|
||||||
|
|
||||||
</option>
|
</option>
|
||||||
|
|
||||||
<inputType id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.compiler.input.905374687" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.compiler.input"/>
|
<inputType id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.compiler.input.905374687" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.compiler.input"/>
|
||||||
|
@@ -57,12 +57,12 @@
|
|||||||
<link>
|
<link>
|
||||||
<name>TencentOS_tiny/arch/risc-v/common</name>
|
<name>TencentOS_tiny/arch/risc-v/common</name>
|
||||||
<type>2</type>
|
<type>2</type>
|
||||||
<locationURI>TOP_DIR/arch/risc-v/common</locationURI>
|
<locationURI>$%7BPARENT-4-PROJECT_LOC%7D/arch/risc-v/common</locationURI>
|
||||||
</link>
|
</link>
|
||||||
<link>
|
<link>
|
||||||
<name>TencentOS_tiny/arch/risc-v/rv32i</name>
|
<name>TencentOS_tiny/arch/risc-v/rv32i</name>
|
||||||
<type>2</type>
|
<type>2</type>
|
||||||
<locationURI>TOP_DIR/arch/risc-v/rv32i/gcc</locationURI>
|
<locationURI>$%7BPARENT-4-PROJECT_LOC%7D/arch/risc-v/rv32i</locationURI>
|
||||||
</link>
|
</link>
|
||||||
<link>
|
<link>
|
||||||
<name>TencentOS_tiny/arch/risc-v/spike</name>
|
<name>TencentOS_tiny/arch/risc-v/spike</name>
|
||||||
|
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
|
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
|
||||||
|
|
||||||
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1303215729854698371" id="ilg.gnumcueclipse.managedbuild.cross.riscv.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT RISC-V Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1292200280605858179" id="ilg.gnumcueclipse.managedbuild.cross.riscv.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT RISC-V Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||||
|
|
||||||
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
||||||
|
|
||||||
|
11
board/Sipeed_LonganNano/BSP/Src/gd32vf103_it.c
Normal file
11
board/Sipeed_LonganNano/BSP/Src/gd32vf103_it.c
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#include "tos.h"
|
||||||
|
|
||||||
|
// systick handler
|
||||||
|
void eclic_mtip_handler() {
|
||||||
|
port_systick_config((uint32_t)k_cpu_cycle_per_tick);
|
||||||
|
if (tos_knl_is_running()) {
|
||||||
|
tos_knl_irq_enter();
|
||||||
|
tos_tick_handler();
|
||||||
|
tos_knl_irq_leave();
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user