sdk:examples: use pinmux to config IO

Signed-off-by: liangkangnan <liangkangnan@163.com>
pull/4/head
liangkangnan 2021-09-13 18:11:20 +08:00
parent 3b7fa13a73
commit d40f39a091
6 changed files with 48 additions and 22 deletions

View File

@ -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);
}

View File

@ -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
}

View File

@ -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);

View File

@ -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++;

View File

@ -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

View File

@ -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);