2022-04-30 10:07:26 +00:00
|
|
|
#include "ch32v30x_it.h"
|
|
|
|
|
2022-05-01 13:45:10 +00:00
|
|
|
#define __IRQ __attribute__((interrupt()))
|
|
|
|
#define __IRQ_WEAK __attribute__((interrupt(), weak))
|
|
|
|
#define __IRQ_NAKED __attribute__((naked))
|
2022-04-30 10:07:26 +00:00
|
|
|
|
2022-05-01 13:45:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* FreeRTOS supports both non-vectored and vectored exception model.
|
|
|
|
* For non-vectored exception, use `freertos_risc_v_trap_handler`,
|
|
|
|
* this function will determine the type of current exception.
|
|
|
|
* For vectored exception, use `freertos_risc_v_exception_handler`,
|
|
|
|
* and use `freertos_risc_v_mtimer_interrupt_handler` for timer interrupt.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief M mode ecall handler
|
|
|
|
*
|
|
|
|
*/
|
2024-03-12 14:49:13 +00:00
|
|
|
__IRQ_NAKED void Ecall_M_Mode_Handler(void) {
|
2022-05-01 13:45:10 +00:00
|
|
|
/* Use naked function to generate a short call, without saving stack. */
|
2024-03-12 14:49:13 +00:00
|
|
|
asm("j freertos_risc_v_trap_handler");
|
2022-04-30 10:07:26 +00:00
|
|
|
}
|
|
|
|
|
2022-05-01 13:45:10 +00:00
|
|
|
/**
|
|
|
|
* @brief SysTick interrupt handler
|
|
|
|
*
|
|
|
|
* @return __IRQ_NAKED
|
2022-04-30 10:07:26 +00:00
|
|
|
*/
|
2022-05-01 13:45:10 +00:00
|
|
|
__IRQ_NAKED void SysTick_Handler(void) {
|
|
|
|
/* Use naked function to generate a short call, without causing stack unbalance. */
|
|
|
|
asm volatile(
|
2022-05-02 14:28:13 +00:00
|
|
|
"addi sp, sp, -4\n" /* Push */
|
|
|
|
"sw t0, 4(sp)\n" /* Save t0 on stack */
|
|
|
|
"li t0, 0xE000F004\n" /* SysTick->SR */
|
|
|
|
"sw zero, 0(t0)\n" /* Write 0 to clear */
|
|
|
|
"lw t0, 4(sp)\n" /* Restore t0 from stack */
|
|
|
|
"addi sp, sp, 4\n" /* Pop */
|
2022-05-01 13:45:10 +00:00
|
|
|
"j freertos_risc_v_mtimer_interrupt_handler"
|
|
|
|
);
|
2022-04-30 10:07:26 +00:00
|
|
|
}
|