#include "resets.h" #include "timer.h" #include "gpio.h" #include "uart.h" #include "stdio.h" #define LED_PIN (25) #define LED_TIME (500 * 1000) /* 500ms */ int main(void) { reset_unreset_blocks_wait(RESETS_BLOCK_IO_BANK0 | RESETS_BLOCK_UART0 | RESETS_BLOCK_TIMER); gpio_init(0, GPIO_FUNC_UART | GPIO_PULL_UP | GPIO_DRIVE_4MA); /* UART_TX pin */ gpio_init(1, GPIO_FUNC_UART | GPIO_PULL_UP | GPIO_SCHMITT | GPIO_PAD_IE | GPIO_PAD_OD); /* UART_RX pin */ uart_init(uart0_hw, 6 * 1000 * 1000, UART_DATABITS_8 | UART_PARITY_NONE | UART_STOPBITS_1); printf("gpio_led example\r\n"); timer_count_write(0); gpio_init(LED_PIN, GPIO_FUNC_NULL | GPIO_OVER_OUT_HIGH | GPIO_OVER_OE_ENABLE | GPIO_PULL_UP | GPIO_DRIVE_4MA); /* LED pin */ while (1) { static int flag = 0; static uint64_t tick_led = 0; uint64_t tick_now; tick_now = timer_count_read(); if (tick_now >= (tick_led + LED_TIME)) { if (flag & 1) { gpio_set(LED_PIN); } else { gpio_clear(LED_PIN); } flag ^= 1; tick_led = tick_now; printf("tick_led = %llu\r\n", tick_led); } } return 0; }