test:example: move C examples to sdk directory
Signed-off-by: liangkangnan <liangkangnan@163.com>bram
parent
5c9f1a140e
commit
ceddc1af24
|
@ -0,0 +1,4 @@
|
|||
**bsp**:板级支持包,是所有C语言程序的基础(公共部分代码)。
|
||||
|
||||
**examples**:一些C语言程序例程。
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
**include**: 公共头文件目录。
|
||||
|
||||
**lib**: 公共函数目录。
|
|
@ -1,14 +1,15 @@
|
|||
|
||||
RISCV_PATH := $(TOOLCHAIN_DIR)/tools/gnu-mcu-eclipse-riscv-none-gcc-8.2.0-2.2-20190521-0004-win64/
|
||||
RISCV_TOOLS_PATH := $(TOOLCHAIN_DIR)/tools/gnu-mcu-eclipse-riscv-none-gcc-8.2.0-2.2-20190521-0004-win64/bin
|
||||
RISCV_TOOLS_PREFIX := riscv-none-embed-
|
||||
|
||||
RISCV_GCC := $(abspath $(RISCV_PATH)/bin/riscv-none-embed-gcc)
|
||||
RISCV_AS := $(abspath $(RISCV_PATH)/bin/riscv-none-embed-as)
|
||||
RISCV_GXX := $(abspath $(RISCV_PATH)/bin/riscv-none-embed-g++)
|
||||
RISCV_OBJDUMP := $(abspath $(RISCV_PATH)/bin/riscv-none-embed-objdump)
|
||||
RISCV_GDB := $(abspath $(RISCV_PATH)/bin/riscv-none-embed-gdb)
|
||||
RISCV_AR := $(abspath $(RISCV_PATH)/bin/riscv-none-embed-ar)
|
||||
RISCV_OBJCOPY := $(abspath $(RISCV_PATH)/bin/riscv-none-embed-objcopy)
|
||||
RISCV_READELF := $(abspath $(RISCV_PATH)/bin/riscv-none-embed-readelf)
|
||||
RISCV_GCC := $(abspath $(RISCV_TOOLS_PATH)/$(RISCV_TOOLS_PREFIX)gcc)
|
||||
RISCV_AS := $(abspath $(RISCV_TOOLS_PATH)/$(RISCV_TOOLS_PREFIX)as)
|
||||
RISCV_GXX := $(abspath $(RISCV_TOOLS_PATH)/$(RISCV_TOOLS_PREFIX)g++)
|
||||
RISCV_OBJDUMP := $(abspath $(RISCV_TOOLS_PATH)/$(RISCV_TOOLS_PREFIX)objdump)
|
||||
RISCV_GDB := $(abspath $(RISCV_TOOLS_PATH)/$(RISCV_TOOLS_PREFIX)gdb)
|
||||
RISCV_AR := $(abspath $(RISCV_TOOLS_PATH)/$(RISCV_TOOLS_PREFIX)ar)
|
||||
RISCV_OBJCOPY := $(abspath $(RISCV_TOOLS_PATH)/$(RISCV_TOOLS_PREFIX)objcopy)
|
||||
RISCV_READELF := $(abspath $(RISCV_TOOLS_PATH)/$(RISCV_TOOLS_PREFIX)readelf)
|
||||
|
||||
.PHONY: all
|
||||
all: $(TARGET)
|
|
@ -0,0 +1,19 @@
|
|||
#ifndef _TRAP_CODE_H_
|
||||
#define _TRAP_CODE_H_
|
||||
|
||||
#define TRAP_USER_SW (0x80000000)
|
||||
#define TRAP_MACH_SW (0x80000003)
|
||||
#define TRAP_USER_TIMER (0x80000004)
|
||||
#define TRAP_MACH_TIMER (0x80000007)
|
||||
#define TRAP_USER_EXT (0x80000008)
|
||||
#define TRAP_MACH_EXT (0x8000000B)
|
||||
#define TRAP_INST_ADDR_MISA (0x00000000)
|
||||
#define TRAP_ILLEGAL_INST (0x00000002)
|
||||
#define TRAP_BREAKPOINT (0x00000003)
|
||||
#define TRAP_LOAD_ADDR_MISA (0x00000004)
|
||||
#define TRAP_STORE_ADDR_MISA (0x00000006)
|
||||
#define TRAP_ECALL_U (0x00000008)
|
||||
#define TRAP_ECALL_S (0x00000009)
|
||||
#define TRAP_ECALL_M (0x0000000B)
|
||||
|
||||
#endif
|
|
@ -50,10 +50,11 @@ test_if_asynchronous:
|
|||
srli a2, a0, 31 /* MSB of mcause is 1 if handing an asynchronous interrupt - shift to LSB to clear other bits. */
|
||||
beq a2, x0, handle_synchronous /* Branch past interrupt handing if not asynchronous. */
|
||||
|
||||
call trap_handler
|
||||
call interrupt_handler
|
||||
j asynchronous_return
|
||||
|
||||
handle_synchronous:
|
||||
call exception_handler
|
||||
addi a1, a1, 4
|
||||
csrw mepc, a1
|
||||
|
||||
|
@ -97,7 +98,12 @@ asynchronous_return:
|
|||
mret
|
||||
|
||||
|
||||
.weak trap_handler
|
||||
trap_handler:
|
||||
.weak interrupt_handler
|
||||
interrupt_handler:
|
||||
1:
|
||||
j 1b
|
||||
|
||||
.weak exception_handler
|
||||
exception_handler:
|
||||
2:
|
||||
j 2b
|
|
@ -0,0 +1,18 @@
|
|||
#include <stdint.h>
|
||||
|
||||
#include "./include/trap_code.h"
|
||||
|
||||
extern void timer0_irq_handler() __attribute__((weak));
|
||||
|
||||
|
||||
void interrupt_handler(uint32_t mcause, uint32_t mepc)
|
||||
{
|
||||
// we have only timer0 interrupt here
|
||||
timer0_irq_handler();
|
||||
}
|
||||
|
||||
void exception_handler(uint32_t mcause, uint32_t mepc)
|
||||
{
|
||||
if ((mcause != TRAP_BREAKPOINT) && (mcause != TRAP_ECALL_M))
|
||||
while (1);
|
||||
}
|
|
@ -11,7 +11,7 @@ TARGET = freertos
|
|||
CFLAGS += -Os
|
||||
ASM_SRCS := ../../Source/portable/RISC-V/portASM.S
|
||||
#LDFLAGS +=
|
||||
INCLUDES += -I. -I../../Source/portable/RISC-V -I../../Source/include -I../../../
|
||||
INCLUDES += -I. -I../../Source/portable/RISC-V -I../../Source/include -I../../../../bsp
|
||||
|
||||
C_SRCS := \
|
||||
main.c \
|
||||
|
@ -23,6 +23,6 @@ C_SRCS := \
|
|||
../../Source/portable/RISC-V/port.c \
|
||||
|
||||
|
||||
COMMON_DIR = ../../..
|
||||
COMMON_DIR = ../../../../bsp
|
||||
TOOLCHAIN_DIR = ../../../../..
|
||||
include ../../../common.mk
|
||||
include ../../../../bsp/common.mk
|
|
@ -0,0 +1,6 @@
|
|||
# Object files
|
||||
*.o
|
||||
*.ko
|
||||
*.obj
|
||||
*.bin
|
||||
*.dump
|
|
@ -4,10 +4,6 @@
|
|||
|
||||
**gpio**: 两个GPIO,一个作为输入、一个作为输出,输出的电平等于输入的电平。
|
||||
|
||||
**include**: 公共头文件目录。
|
||||
|
||||
**lib**: 公共函数目录。
|
||||
|
||||
**simple**: 简单的加、减、乘、除运算测试例程。
|
||||
|
||||
**timer_int**: 定时器中断测试例程,每500ms翻转一下IO口的电平。在FPGA上运行时需要将其Makefile里的CFLAGS += -DSIMULATION这一行注释掉。
|
||||
|
@ -19,5 +15,3 @@
|
|||
**coremark:**已经移植好的coremark跑分测试例程。
|
||||
|
||||
**FreeRTOS:**FreeRTOS嵌入式操作系统测试例程,效果:每1s翻转一下IO口的电平。
|
||||
|
||||
本目录下所有的.c和.S文件是所有例程的公共文件,每一个例程都需要用到它们。
|
|
@ -16,6 +16,6 @@ CFLAGS := -O2 -fno-common -funroll-loops -finline-functions --param max-inline-i
|
|||
CFLAGS += -DFLAGS_STR=\""$(CFLAGS)"\"
|
||||
CFLAGS += -DITERATIONS=10000 -DPERFORMANCE_RUN=1
|
||||
|
||||
COMMON_DIR = ..
|
||||
COMMON_DIR = ../../bsp
|
||||
TOOLCHAIN_DIR = ../../..
|
||||
include ../common.mk
|
||||
include ../../bsp/common.mk
|
|
@ -1,9 +1,9 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "coremark.h"
|
||||
#include "../include/utils.h"
|
||||
#include "../include/uart.h"
|
||||
#include "../include/xprintf.h"
|
||||
#include "../../bsp/include/utils.h"
|
||||
#include "../../bsp/include/uart.h"
|
||||
#include "../../bsp/include/xprintf.h"
|
||||
|
||||
#if VALIDATION_RUN
|
||||
volatile ee_s32 seed1_volatile=0x3415;
|
|
@ -9,7 +9,7 @@
|
|||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "../include/xprintf.h"
|
||||
#include "../../bsp/include/xprintf.h"
|
||||
|
||||
#define HAS_FLOAT 0
|
||||
#define HAS_TIME_H 1
|
|
@ -16,6 +16,6 @@ C_SRCS := \
|
|||
main.c \
|
||||
|
||||
|
||||
COMMON_DIR = ..
|
||||
COMMON_DIR = ../../bsp
|
||||
TOOLCHAIN_DIR = ../../..
|
||||
include ../common.mk
|
||||
include ../../bsp/common.mk
|
|
@ -1,7 +1,7 @@
|
|||
#include <stdint.h>
|
||||
|
||||
#include "../include/gpio.h"
|
||||
#include "../include/utils.h"
|
||||
#include "../../bsp/include/gpio.h"
|
||||
#include "../../bsp/include/utils.h"
|
||||
|
||||
|
||||
int main()
|
|
@ -16,6 +16,6 @@ C_SRCS := \
|
|||
main.c \
|
||||
|
||||
|
||||
COMMON_DIR = ..
|
||||
COMMON_DIR = ../../bsp
|
||||
TOOLCHAIN_DIR = ../../..
|
||||
include ../common.mk
|
||||
include ../../bsp/common.mk
|
|
@ -1,5 +1,5 @@
|
|||
#include <stdint.h>
|
||||
#include "../include/utils.h"
|
||||
#include "../../bsp/include/utils.h"
|
||||
|
||||
|
||||
int mul = 3;
|
|
@ -16,6 +16,6 @@ C_SRCS := \
|
|||
main.c \
|
||||
|
||||
|
||||
COMMON_DIR = ..
|
||||
COMMON_DIR = ../../bsp
|
||||
TOOLCHAIN_DIR = ../../..
|
||||
include ../common.mk
|
||||
include ../../bsp/common.mk
|
|
@ -1,8 +1,8 @@
|
|||
#include <stdint.h>
|
||||
|
||||
#include "../include/timer.h"
|
||||
#include "../include/gpio.h"
|
||||
#include "../include/utils.h"
|
||||
#include "../../bsp/include/timer.h"
|
||||
#include "../../bsp/include/gpio.h"
|
||||
#include "../../bsp/include/utils.h"
|
||||
|
||||
|
||||
static volatile uint32_t count;
|
|
@ -16,6 +16,6 @@ C_SRCS := \
|
|||
main.c \
|
||||
|
||||
|
||||
COMMON_DIR = ..
|
||||
COMMON_DIR = ../../bsp
|
||||
TOOLCHAIN_DIR = ../../..
|
||||
include ../common.mk
|
||||
include ../../bsp/common.mk
|
|
@ -1,7 +1,7 @@
|
|||
#include <stdint.h>
|
||||
|
||||
#include "../include/uart.h"
|
||||
#include "../include/xprintf.h"
|
||||
#include "../../bsp/include/uart.h"
|
||||
#include "../../bsp/include/xprintf.h"
|
||||
|
||||
|
||||
|
|
@ -16,6 +16,6 @@ C_SRCS := \
|
|||
main.c \
|
||||
|
||||
|
||||
COMMON_DIR = ..
|
||||
COMMON_DIR = ../../bsp
|
||||
TOOLCHAIN_DIR = ../../..
|
||||
include ../common.mk
|
||||
include ../../bsp/common.mk
|
|
@ -1,7 +1,7 @@
|
|||
#include <stdint.h>
|
||||
|
||||
#include "../include/uart.h"
|
||||
#include "../include/xprintf.h"
|
||||
#include "../../bsp/include/uart.h"
|
||||
#include "../../bsp/include/xprintf.h"
|
||||
|
||||
|
||||
|
|
@ -1,7 +1,5 @@
|
|||
# 目录说明
|
||||
|
||||
example:包含C语言程序例程。
|
||||
|
||||
isa:旧的指令兼容性测试源码。RISC-V官方已经不更新了。
|
||||
isa:旧的指令兼容性测试源码,RISC-V官方已经不更新了。
|
||||
|
||||
riscv-compliance:新的指令兼容性测试源码,RISC-V官方一直在更新。
|
|
@ -1,11 +0,0 @@
|
|||
#include <stdint.h>
|
||||
|
||||
|
||||
extern void timer0_irq_handler() __attribute__((weak));
|
||||
|
||||
|
||||
void trap_handler(uint32_t mcause, uint32_t mepc)
|
||||
{
|
||||
// we have only timer0 interrupt here
|
||||
timer0_irq_handler();
|
||||
}
|
Loading…
Reference in New Issue