2021-08-10 01:54:20 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "../../bsp/include/timer.h"
|
|
|
|
#include "../../bsp/include/utils.h"
|
|
|
|
#include "../../bsp/include/rvic.h"
|
|
|
|
#include "../../bsp/include/gpio.h"
|
|
|
|
|
|
|
|
static volatile uint32_t count;
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
count = 0;
|
|
|
|
|
|
|
|
#ifdef SIMULATION
|
|
|
|
timer0_set_div(50);
|
|
|
|
timer0_set_value(100); // 100us period
|
|
|
|
timer0_clear_int_pending();
|
|
|
|
timer0_set_int_enable(1);
|
|
|
|
timer0_set_mode_auto_reload();
|
2021-08-10 03:26:46 +00:00
|
|
|
rvic_set_irq_prio_level(0, 1);
|
2021-08-10 01:54:20 +00:00
|
|
|
global_irq_enable();
|
|
|
|
rvic_irq_enable(0);
|
|
|
|
timer0_start(1);
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
if (count == 3) {
|
|
|
|
timer0_start(0);
|
|
|
|
// TODO: do something
|
|
|
|
set_test_pass();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
#else
|
|
|
|
timer0_set_div(25);
|
|
|
|
timer0_set_value(10000); // 10ms period
|
|
|
|
timer0_clear_int_pending();
|
|
|
|
timer0_set_int_enable(1);
|
|
|
|
timer0_set_mode_auto_reload();
|
2021-08-10 03:26:46 +00:00
|
|
|
rvic_set_irq_prio_level(0, 1);
|
2021-08-10 01:54:20 +00:00
|
|
|
global_irq_enable();
|
|
|
|
rvic_irq_enable(0);
|
|
|
|
timer0_start(1);
|
|
|
|
|
2021-08-13 02:07:13 +00:00
|
|
|
gpio_set_mode(GPIO0, GPIO_MODE_OUTPUT);
|
2021-08-10 01:54:20 +00:00
|
|
|
|
|
|
|
while (1) {
|
|
|
|
// 500ms
|
|
|
|
if (count == 50) {
|
|
|
|
count = 0;
|
2021-08-13 02:07:13 +00:00
|
|
|
gpio_set_output_toggle(GPIO0); // toggle led
|
2021-08-10 01:54:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void timer_irq_handler()
|
|
|
|
{
|
|
|
|
count++;
|
|
|
|
|
|
|
|
timer0_clear_int_pending();
|
|
|
|
rvic_clear_irq_pending(0);
|
|
|
|
}
|