52 lines
1.3 KiB
C
52 lines
1.3 KiB
C
#include "resets.h"
|
|
#include "clock.h"
|
|
#include "irq.h"
|
|
#include "gpio.h"
|
|
#include "uart.h"
|
|
#include "timer.h"
|
|
#include "stdio.h"
|
|
#include "RP2040.h"
|
|
|
|
#define TIMER_ALARM_ID TIMER_ALARM_0
|
|
#define TIMER_PERIOD_US (1000 * 1000)
|
|
|
|
struct uart_cfg_s uart_cfg = {
|
|
.baudrate = 6 * 1000 * 1000,
|
|
.mode = UART_MODE_TX_RX,
|
|
.data_bits = UART_DATABITS_8,
|
|
.parity = UART_PARITY_NONE,
|
|
.stop_bits = UART_STOPBITS_1,
|
|
.fifo_enable = ENABLE,
|
|
.tx_fifo_level = UART_FIFO_LEVEL_1_2,
|
|
.rx_fifo_level = UART_FIFO_LEVEL_1_2,
|
|
};
|
|
|
|
void timer_alarm_0_isr(void)
|
|
{
|
|
timer_int_clear(TIMER_ALARM_ID);
|
|
timer_alarm_set(TIMER_ALARM_ID, timer_alarm_get(TIMER_ALARM_ID) + TIMER_PERIOD_US);
|
|
printf("time low count = %ld\r\n", timer_count_l_read_raw());
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
reset_unreset_blocks_wait(RESETS_BLOCK_IO_BANK0 | RESETS_BLOCK_PADS_BANK0 | RESETS_BLOCK_UART0 | RESETS_BLOCK_TIMER);
|
|
gpio_init_simple(0, GPIO_FUNC_UART, DISABLE, ENABLE);
|
|
__enable_irq();
|
|
uart_init(UART_ID_0, &uart_cfg);
|
|
printf("timer interrupt example.\r\n");
|
|
|
|
irq_init();
|
|
timer_count_write(0);
|
|
timer_alarm_set(TIMER_ALARM_ID, TIMER_PERIOD_US);
|
|
timer_int_enable(TIMER_ALARM_ID);
|
|
irq_attach(TIMER_IRQ_0, timer_alarm_0_isr);
|
|
irq_enable(TIMER_IRQ_0);
|
|
|
|
while (1) {
|
|
|
|
}
|
|
|
|
return 0;
|
|
}
|