Compare commits

..

1 Commits

Author SHA1 Message Date
Thomas Klaehn
85e960e612 Add virtual timer 2020-04-20 08:15:50 +02:00
4 changed files with 13 additions and 6 deletions

View File

@ -42,10 +42,10 @@ int main(void)
{
cm4::InterruptGuardian::enable_interrupts();
while(true) {
for(auto it = std::begin(leds); it != std::end(leds); ++it) {
nrf52::Gpio * tmp = *it;
tmp->toggle();
delay.delay(200);
for(auto it = leds.begin(); it != leds.end(); ++it) {
nrf52::Gpio * led = *it;
led->toggle();
delay.ms(200);
}
}
return 0;

View File

@ -9,7 +9,7 @@ Delay::Delay()
{
}
void Delay::delay(uint64_t time_ms)
void Delay::ms(uint64_t time_ms)
{
this->pause = true;
this->timer_set_period_ms(time_ms);

View File

@ -12,7 +12,7 @@ class Delay
public:
Delay();
void delay(uint64_t);
void ms(uint64_t);
void notification();

View File

@ -33,6 +33,7 @@ void VirtualTimerDistributor::register_timer(VirtualTimerInterface *timer)
}
for(auto it = this->virtual_timer_list.begin(); it != this->virtual_timer_list.end(); ++it) {
if(*it == nullptr) {
// FIXME: We might need an interrupt lock here?
*it = timer;
num_registered_timers++;
break;
@ -45,8 +46,13 @@ void VirtualTimerDistributor::register_timer(VirtualTimerInterface *timer)
void VirtualTimerDistributor::unregister_timer(VirtualTimerInterface *timer)
{
if(num_registered_timers == 0) {
// FIXME: Error notification
return;
}
for(auto it = this->virtual_timer_list.begin(); it != this->virtual_timer_list.end(); ++it) {
if(*it == timer) {
// FIXME: We might need an interrupt lock here?
*it = nullptr;
num_registered_timers--;
break;
@ -59,6 +65,7 @@ void VirtualTimerDistributor::unregister_timer(VirtualTimerInterface *timer)
void VirtualTimerDistributor::notify(uint64_t time_ms)
{
// FIXME: We're still in interrupt context of hw timer interrupt.
for(auto it = this->virtual_timer_list.begin(); it != this->virtual_timer_list.end(); ++it) {
if(*it != nullptr) {
VirtualTimerInterface *vt = *it;