34 lines
1.1 KiB
C
34 lines
1.1 KiB
C
#include "resets.h"
|
|
#include "gpio.h"
|
|
#include "uart.h"
|
|
#include "timer.h"
|
|
#include "irq.h"
|
|
#include "stdio.h"
|
|
|
|
#define TIMER_ALARM_ID TIMER_ALARM_0
|
|
#define TIMER_PERIOD_US (1000 * 1000)
|
|
|
|
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_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("timer_interrupt example\r\n");
|
|
|
|
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);
|
|
|
|
return 0;
|
|
}
|