From d40f39a0918f2d3ca67d70f10aab06ad8743400d Mon Sep 17 00:00:00 2001 From: liangkangnan Date: Mon, 13 Sep 2021 18:11:20 +0800 Subject: [PATCH] sdk:examples: use pinmux to config IO Signed-off-by: liangkangnan --- sdk/examples/coremark/core_portme.c | 3 ++ .../freertos/Demo/tinyriscv_GCC/main.c | 6 +-- sdk/examples/i2c_slave/main.c | 6 +++ sdk/examples/int_preempt/main.c | 44 ++++++++++++------- sdk/examples/timer/main.c | 7 ++- sdk/examples/uart_int/main.c | 4 ++ 6 files changed, 48 insertions(+), 22 deletions(-) diff --git a/sdk/examples/coremark/core_portme.c b/sdk/examples/coremark/core_portme.c index 74a0245..2f1cd7e 100644 --- a/sdk/examples/coremark/core_portme.c +++ b/sdk/examples/coremark/core_portme.c @@ -4,6 +4,7 @@ #include "../../bsp/include/utils.h" #include "../../bsp/include/uart.h" #include "../../bsp/include/xprintf.h" +#include "../../bsp/include/pinmux.h" #if VALIDATION_RUN volatile ee_s32 seed1_volatile=0x3415; @@ -54,5 +55,7 @@ secs_ret time_in_secs(CORE_TICKS ticks) void portable_init(core_portable *p, int *argc, char *argv[]) { + pinmux_set_io0_func(IO0_UART0_TX); + pinmux_set_io3_func(IO3_UART0_RX); 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 c0f5545..ae5324e 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_set_mode(GPIO0, GPIO_MODE_OUTPUT); // set gpio0 output mode + gpio_set_mode(GPIO7, GPIO_MODE_OUTPUT); // set gpio7 output mode } /*-----------------------------------------------------------*/ @@ -180,7 +180,7 @@ const uint32_t ulNullLoopDelay = 0x1ffffUL; { __asm volatile( "nop" ); } - gpio_set_output_toggle(GPIO0); // toggle led + gpio_set_output_toggle(GPIO7); // toggle led } } /*-----------------------------------------------------------*/ @@ -192,7 +192,7 @@ void vToggleLED( void ) set_test_pass(); while (1); #else - gpio_set_output_toggle(GPIO0); // toggle led + gpio_set_output_toggle(GPIO7); // toggle led #endif } diff --git a/sdk/examples/i2c_slave/main.c b/sdk/examples/i2c_slave/main.c index ed2548c..9d89525 100644 --- a/sdk/examples/i2c_slave/main.c +++ b/sdk/examples/i2c_slave/main.c @@ -5,6 +5,7 @@ #include "../../bsp/include/xprintf.h" #include "../../bsp/include/utils.h" #include "../../bsp/include/rvic.h" +#include "../../bsp/include/pinmux.h" #define SLAVE_ADDR (0xAA) @@ -19,6 +20,11 @@ static volatile op_e op; int main() { + pinmux_set_io0_func(IO0_UART0_TX); + pinmux_set_io3_func(IO3_UART0_RX); + pinmux_set_io6_func(IO6_I2C0_SCL); + pinmux_set_io8_func(IO8_I2C0_SDA); + uart0_init(uart0_putc); i2c0_set_mode(I2C_MODE_SLAVE); diff --git a/sdk/examples/int_preempt/main.c b/sdk/examples/int_preempt/main.c index c7912cb..e01b027 100644 --- a/sdk/examples/int_preempt/main.c +++ b/sdk/examples/int_preempt/main.c @@ -6,6 +6,7 @@ #include "../../bsp/include/gpio.h" #include "../../bsp/include/uart.h" #include "../../bsp/include/xprintf.h" +#include "../../bsp/include/pinmux.h" static volatile uint32_t count; @@ -13,6 +14,9 @@ int main() { count = 0; + pinmux_set_io0_func(IO0_UART0_TX); + pinmux_set_io3_func(IO3_UART0_RX); + uart0_init(uart0_putc); timer0_set_div(25); @@ -21,24 +25,28 @@ int main() timer0_set_int_enable(1); timer0_set_mode_ontshot(); // timer0中断优先级为1 - rvic_set_irq_prio_level(0, 1); + rvic_set_irq_prio_level(RVIC_INT_ID_0, 1); global_irq_enable(); - rvic_irq_enable(0); + rvic_irq_enable(RVIC_INT_ID_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); + // IO7用作GPIO7 + pinmux_set_io7_func(IO7_GPIO7); + // IO9用作GPIO9 + pinmux_set_io9_func(IO9_GPIO9); + // gpio7输出模式 + gpio_set_mode(GPIO7, GPIO_MODE_OUTPUT); + // gpio9输入模式 + gpio_set_mode(GPIO9, GPIO_MODE_INPUT); + // gpio9双沿中断 + gpio_set_interrupt_mode(GPIO9, GPIO_INTR_DOUBLE_EDGE); + rvic_irq_enable(RVIC_INT_ID_9); + // gpio9中断优先级为2 + rvic_set_irq_prio_level(RVIC_INT_ID_9, 2); while (1) { if (count == 3) { - gpio_set_output_toggle(GPIO0); // toggle led + gpio_set_output_toggle(GPIO7); // toggle led busy_wait(500 * 1000); } } @@ -49,17 +57,19 @@ void timer0_irq_handler() timer0_clear_int_pending(); rvic_clear_irq_pending(0); - xprintf("timer0 isr\n"); + xprintf("timer0 isr enter\n"); // GPIO0对应LED为灭 - gpio_set_output_data(GPIO0, 1); + gpio_set_output_data(GPIO7, 1); while (count != 3); + + xprintf("timer0 isr exit\n"); } -void gpio1_irq_handler() +void gpio9_irq_handler() { - gpio_clear_intr_pending(GPIO1); - rvic_clear_irq_pending(3); + gpio_clear_intr_pending(GPIO9); + rvic_clear_irq_pending(RVIC_INT_ID_9); xprintf("gpio1 isr\n"); count++; diff --git a/sdk/examples/timer/main.c b/sdk/examples/timer/main.c index 2415c50..ff67c30 100644 --- a/sdk/examples/timer/main.c +++ b/sdk/examples/timer/main.c @@ -4,6 +4,7 @@ #include "../../bsp/include/utils.h" #include "../../bsp/include/rvic.h" #include "../../bsp/include/gpio.h" +#include "../../bsp/include/pinmux.h" static volatile uint32_t count; @@ -43,13 +44,15 @@ int main() rvic_irq_enable(0); timer0_start(1); - gpio_set_mode(GPIO0, GPIO_MODE_OUTPUT); + // IO7用作GPIO7 + pinmux_set_io7_func(IO7_GPIO7); + gpio_set_mode(GPIO7, GPIO_MODE_OUTPUT); while (1) { // 500ms if (count == 50) { count = 0; - gpio_set_output_toggle(GPIO0); // toggle led + gpio_set_output_toggle(GPIO7); // toggle led } } #endif diff --git a/sdk/examples/uart_int/main.c b/sdk/examples/uart_int/main.c index a5cdde8..341bb00 100644 --- a/sdk/examples/uart_int/main.c +++ b/sdk/examples/uart_int/main.c @@ -4,6 +4,7 @@ #include "../../bsp/include/xprintf.h" #include "../../bsp/include/rvic.h" #include "../../bsp/include/utils.h" +#include "../../bsp/include/pinmux.h" #define UART_TXB (80) @@ -34,6 +35,9 @@ static void uart_putc(uint8_t c) int main() { + pinmux_set_io0_func(IO0_UART0_TX); + pinmux_set_io3_func(IO3_UART0_RX); + uart0_init(uart_putc); rvic_irq_enable(1); rvic_set_irq_prio_level(1, 1);