sdk:examples: add int_preempt

Signed-off-by: liangkangnan <liangkangnan@163.com>
pull/4/head
liangkangnan 2021-09-07 09:46:09 +08:00
parent 57690b00bd
commit 4d0f63ef86
4 changed files with 95 additions and 0 deletions

8
sdk/examples/int_preempt/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
# Object files
*.o
*.ko
*.obj
*.bin
*.dump
*.mem
int_preempt

View File

@ -0,0 +1,20 @@
RISCV_ARCH := rv32im
RISCV_ABI := ilp32
RISCV_MCMODEL := medlow
TARGET = int_preempt
#CFLAGS += -DSIMULATION
#CFLAGS += -Os
#ASM_SRCS +=
#LDFLAGS +=
#INCLUDES += -I.
C_SRCS := \
main.c \
BSP_DIR = ../../bsp
include ../../bsp/bsp.mk

View File

@ -0,0 +1 @@
中断抢占例程。

View File

@ -0,0 +1,66 @@
#include <stdint.h>
#include "../../bsp/include/timer.h"
#include "../../bsp/include/utils.h"
#include "../../bsp/include/rvic.h"
#include "../../bsp/include/gpio.h"
#include "../../bsp/include/uart.h"
#include "../../bsp/include/xprintf.h"
static volatile uint32_t count;
int main()
{
count = 0;
uart0_init(uart0_putc);
timer0_set_div(25);
timer0_set_value(10000); // 10ms period
timer0_clear_int_pending();
timer0_set_int_enable(1);
timer0_set_mode_ontshot();
// timer0中断优先级为1
rvic_set_irq_prio_level(0, 1);
global_irq_enable();
rvic_irq_enable(0);
timer0_start(1);
// gpio0输出模式
gpio_set_mode(GPIO0, GPIO_MODE_OUTPUT);
// gpio1输入模式
gpio_set_mode(GPIO1, GPIO_MODE_INPUT);
// gpio1双沿中断
gpio_set_interrupt_mode(GPIO1, GPIO_INTR_DOUBLE_EDGE);
rvic_irq_enable(3);
// gpio1中断优先级为2
rvic_set_irq_prio_level(3, 2);
while (1) {
if (count == 3) {
gpio_set_output_toggle(GPIO0); // toggle led
busy_wait(500 * 1000);
}
}
}
void timer0_irq_handler()
{
timer0_clear_int_pending();
rvic_clear_irq_pending(0);
xprintf("timer0 isr\n");
// GPIO0对应LED为灭
gpio_set_output_data(GPIO0, 1);
while (count != 3);
}
void gpio1_irq_handler()
{
gpio_clear_intr_pending(GPIO1);
rvic_clear_irq_pending(3);
xprintf("gpio1 isr\n");
count++;
}