From 477d9efc34bf7ea0d5e2d4e6d298ae8ea1ba74eb Mon Sep 17 00:00:00 2001 From: liangkangnan Date: Fri, 13 Aug 2021 10:07:13 +0800 Subject: [PATCH] sdk:examples: adapte to new perips Signed-off-by: liangkangnan --- sdk/bsp/include/uart.h | 4 +- sdk/bsp/lib/uart.c | 2 +- sdk/examples/coremark/core_portme.c | 116 +++++++++--------- .../freertos/Demo/tinyriscv_GCC/main.c | 6 +- .../freertos/Source/portable/RISC-V/port.c | 16 ++- sdk/examples/gpio/main.c | 32 +++-- sdk/examples/timer/main.c | 4 +- 7 files changed, 97 insertions(+), 83 deletions(-) diff --git a/sdk/bsp/include/uart.h b/sdk/bsp/include/uart.h index 72931bb..d1dfd03 100644 --- a/sdk/bsp/include/uart.h +++ b/sdk/bsp/include/uart.h @@ -50,9 +50,9 @@ extern "C" { #define UART_RXDATA_RXDATA_FIELD \ ((bitfield_field32_t) { .mask = UART_RXDATA_RXDATA_MASK, .index = UART_RXDATA_RXDATA_OFFSET }) -typedef void (*putc)(uint8_t); +typedef void (*myputc)(uint8_t); -void uart0_init(putc put); +void uart0_init(myputc putc); uint8_t uart0_getc(); void uart0_putc(uint8_t c); diff --git a/sdk/bsp/lib/uart.c b/sdk/bsp/lib/uart.c index c8262b9..9a52f2f 100644 --- a/sdk/bsp/lib/uart.c +++ b/sdk/bsp/lib/uart.c @@ -21,7 +21,7 @@ uint8_t uart0_getc() } // 115200bps, 8 N 1 -void uart0_init(putc put) +void uart0_init(myputc put) { // enable tx and rx UART0_REG(UART_CTRL_REG_OFFSET) |= 0x3; diff --git a/sdk/examples/coremark/core_portme.c b/sdk/examples/coremark/core_portme.c index b64285f..74a0245 100644 --- a/sdk/examples/coremark/core_portme.c +++ b/sdk/examples/coremark/core_portme.c @@ -1,58 +1,58 @@ -#include -#include -#include "coremark.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; - volatile ee_s32 seed2_volatile=0x3415; - volatile ee_s32 seed3_volatile=0x66; -#endif - -#if PERFORMANCE_RUN - volatile ee_s32 seed1_volatile=0x0; - volatile ee_s32 seed2_volatile=0x0; - volatile ee_s32 seed3_volatile=0x66; -#endif - -#if PROFILE_RUN - volatile ee_s32 seed1_volatile=0x8; - volatile ee_s32 seed2_volatile=0x8; - volatile ee_s32 seed3_volatile=0x8; -#endif - -volatile ee_s32 seed4_volatile=ITERATIONS; -volatile ee_s32 seed5_volatile=0; - -static CORE_TICKS t0, t1; - -void start_time(void) -{ - t0 = get_cycle_value(); -} - -void stop_time(void) -{ - t1 = get_cycle_value(); -} - -CORE_TICKS get_time(void) -{ - return t1 - t0; -} - -secs_ret time_in_secs(CORE_TICKS ticks) -{ - // scale timer down to avoid uint64_t -> double conversion in RV32 - int scale = 256; - uint32_t delta = ticks / scale; - uint32_t freq = CPU_FREQ_HZ / scale; - return delta / (double)freq; -} - -void portable_init(core_portable *p, int *argc, char *argv[]) -{ - uart_init(); -} +#include +#include +#include "coremark.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; + volatile ee_s32 seed2_volatile=0x3415; + volatile ee_s32 seed3_volatile=0x66; +#endif + +#if PERFORMANCE_RUN + volatile ee_s32 seed1_volatile=0x0; + volatile ee_s32 seed2_volatile=0x0; + volatile ee_s32 seed3_volatile=0x66; +#endif + +#if PROFILE_RUN + volatile ee_s32 seed1_volatile=0x8; + volatile ee_s32 seed2_volatile=0x8; + volatile ee_s32 seed3_volatile=0x8; +#endif + +volatile ee_s32 seed4_volatile=ITERATIONS; +volatile ee_s32 seed5_volatile=0; + +static CORE_TICKS t0, t1; + +void start_time(void) +{ + t0 = get_cycle_value(); +} + +void stop_time(void) +{ + t1 = get_cycle_value(); +} + +CORE_TICKS get_time(void) +{ + return t1 - t0; +} + +secs_ret time_in_secs(CORE_TICKS ticks) +{ + // scale timer down to avoid uint64_t -> double conversion in RV32 + int scale = 256; + uint32_t delta = ticks / scale; + uint32_t freq = CPU_FREQ_HZ / scale; + return delta / (double)freq; +} + +void portable_init(core_portable *p, int *argc, char *argv[]) +{ + uart0_init(uart0_putc); +} diff --git a/sdk/examples/freertos/Demo/tinyriscv_GCC/main.c b/sdk/examples/freertos/Demo/tinyriscv_GCC/main.c index 7f1ed8d..c0f5545 100644 --- a/sdk/examples/freertos/Demo/tinyriscv_GCC/main.c +++ b/sdk/examples/freertos/Demo/tinyriscv_GCC/main.c @@ -107,7 +107,7 @@ int main( void ) static void prvSetupHardware( void ) { - GPIO_REG(GPIO_CTRL) |= 0x1; // set gpio0 output mode + gpio_set_mode(GPIO0, GPIO_MODE_OUTPUT); // set gpio0 output mode } /*-----------------------------------------------------------*/ @@ -180,7 +180,7 @@ const uint32_t ulNullLoopDelay = 0x1ffffUL; { __asm volatile( "nop" ); } - GPIO_REG(GPIO_DATA) ^= 0x1; + gpio_set_output_toggle(GPIO0); // toggle led } } /*-----------------------------------------------------------*/ @@ -192,7 +192,7 @@ void vToggleLED( void ) set_test_pass(); while (1); #else - GPIO_REG(GPIO_DATA) ^= 0x1; + gpio_set_output_toggle(GPIO0); // toggle led #endif } diff --git a/sdk/examples/freertos/Source/portable/RISC-V/port.c b/sdk/examples/freertos/Source/portable/RISC-V/port.c index c444f73..b17e469 100644 --- a/sdk/examples/freertos/Source/portable/RISC-V/port.c +++ b/sdk/examples/freertos/Source/portable/RISC-V/port.c @@ -37,7 +37,7 @@ /* Standard includes. */ #include "string.h" -#include "include/machine_timer.h" +#include "include/timer.h" #include "include/rvic.h" /* Let the user override the pre-loading of the initial LR with the address of @@ -134,19 +134,23 @@ volatile uint32_t ulHartId; #endif #ifdef SIMULATION - machine_timer_set_cmp_val(5000); + timer0_set_div(50); + timer0_set_value(100); // 100us period #else - machine_timer_set_cmp_val(uxTimerIncrementsForOneTick); + timer0_set_div(configCPU_CLOCK_HZ/1000000); + timer0_set_value(1000000/configTICK_RATE_HZ); // 10ms period #endif - machine_timer_irq_enable(1);// enable timer interrupt + timer0_set_int_enable(1); + timer0_set_mode_auto_reload(); + rvic_set_irq_prio_level(0, 1); rvic_irq_enable(0); - machine_timer_enable(1); // start timer + timer0_start(1); // start timer } /*-----------------------------------------------------------*/ void xPortClearTimerIntPending() { - machine_timer_clear_irq_pending(); // clear int pending + timer0_clear_int_pending(); rvic_clear_irq_pending(0); } diff --git a/sdk/examples/gpio/main.c b/sdk/examples/gpio/main.c index ae22c90..38212ab 100644 --- a/sdk/examples/gpio/main.c +++ b/sdk/examples/gpio/main.c @@ -2,19 +2,29 @@ #include "../../bsp/include/gpio.h" #include "../../bsp/include/utils.h" - +#include "../../bsp/include/rvic.h" int main() { - gpio_output_enable(GPIO0); // gpio0输出模式 - gpio_input_enable(GPIO1); // gpio1输入模式 + gpio_set_mode(GPIO0, GPIO_MODE_OUTPUT); // gpio0输出模式 + gpio_set_mode(GPIO1, GPIO_MODE_INPUT); // gpio1输入模式 + gpio_set_interrupt_mode(GPIO1, GPIO_INTR_DOUBLE_EDGE); + rvic_irq_enable(3); + rvic_set_irq_prio_level(3, 1); + global_irq_enable(); - while (1) { - // 如果GPIO1输入高 - if (gpio_get_data(GPIO1)) - gpio_set_data(GPIO0, 1); // GPIO0输出高 - // 如果GPIO1输入低 - else - gpio_set_data(GPIO0, 0); // GPIO0输出低 - } + while (1); +} + +void gpio1_irq_handler() +{ + gpio_clear_intr_pending(GPIO1); + rvic_clear_irq_pending(3); + + // 如果GPIO1输入高 + if (gpio_get_input_data(GPIO1)) + gpio_set_output_data(GPIO0, 1); // GPIO0输出高 + // 如果GPIO1输入低 + else + gpio_set_output_data(GPIO0, 0); // GPIO0输出低 } diff --git a/sdk/examples/timer/main.c b/sdk/examples/timer/main.c index 12a922e..23c7918 100644 --- a/sdk/examples/timer/main.c +++ b/sdk/examples/timer/main.c @@ -43,13 +43,13 @@ int main() rvic_irq_enable(0); timer0_start(1); - gpio_output_enable(GPIO0); + gpio_set_mode(GPIO0, GPIO_MODE_OUTPUT); while (1) { // 500ms if (count == 50) { count = 0; - gpio_data_toggle(GPIO0); // toggle led + gpio_set_output_toggle(GPIO0); // toggle led } } #endif