2020-03-08 07:09:30 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2020-04-06 13:28:56 +00:00
|
|
|
#include "../include/timer.h"
|
|
|
|
#include "../include/gpio.h"
|
2020-04-11 11:03:49 +00:00
|
|
|
#include "../include/utils.h"
|
2020-03-08 07:09:30 +00:00
|
|
|
|
|
|
|
|
2020-04-11 11:03:49 +00:00
|
|
|
static volatile uint32_t count;
|
2020-03-08 07:09:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
2020-03-29 15:19:14 +00:00
|
|
|
count = 0;
|
2020-03-08 07:09:30 +00:00
|
|
|
|
2020-04-11 11:03:49 +00:00
|
|
|
#ifdef SIMULATION
|
|
|
|
TIMER0_REG(TIMER0_VALUE) = 500; // 10us period
|
|
|
|
TIMER0_REG(TIMER0_CTRL) = 0x07; // enable interrupt and start timer
|
|
|
|
|
|
|
|
while (1) {
|
2020-04-18 03:39:27 +00:00
|
|
|
if (count == 2) {
|
|
|
|
TIMER0_REG(TIMER0_CTRL) = 0x00; // stop timer
|
|
|
|
count = 0;
|
|
|
|
// TODO: do something
|
|
|
|
set_test_pass();
|
|
|
|
break;
|
2020-04-11 11:03:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
TIMER0_REG(TIMER0_VALUE) = 500000; // 10ms period
|
2020-03-29 15:19:14 +00:00
|
|
|
TIMER0_REG(TIMER0_CTRL) = 0x07; // enable interrupt and start timer
|
2020-03-08 07:09:30 +00:00
|
|
|
|
2020-04-06 13:28:56 +00:00
|
|
|
GPIO_REG(GPIO_DATA) = 0x1;
|
|
|
|
|
2020-03-08 07:09:30 +00:00
|
|
|
while (1) {
|
2020-04-18 03:39:27 +00:00
|
|
|
// 500ms
|
|
|
|
if (count == 50) {
|
|
|
|
count = 0;
|
|
|
|
GPIO_REG(GPIO_DATA) ^= 0x1; // toggle led
|
2020-03-08 07:09:30 +00:00
|
|
|
}
|
|
|
|
}
|
2020-04-11 11:03:49 +00:00
|
|
|
#endif
|
2020-03-08 07:09:30 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-04-11 11:03:49 +00:00
|
|
|
void timer0_irq_handler()
|
2020-03-08 07:09:30 +00:00
|
|
|
{
|
2020-04-18 03:39:27 +00:00
|
|
|
TIMER0_REG(TIMER0_CTRL) |= (1 << 2) | (1 << 0); // clear int pending and start timer
|
2020-03-08 07:09:30 +00:00
|
|
|
|
2020-04-18 03:39:27 +00:00
|
|
|
count++;
|
2020-03-08 07:09:30 +00:00
|
|
|
}
|