Skip to content

Commit

Permalink
next point
Browse files Browse the repository at this point in the history
  • Loading branch information
tanneberger committed Sep 13, 2024
1 parent 61f1ef8 commit ad5e615
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/environment.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ void Environment_start(Environment *self) {
}

int Environment_wait_until(Environment *self, instant_t wakeup_time) {
puts("wait until env");
hardware_wait_for(self->current_tag.time, wakeup_time);
return 0;
}
Expand All @@ -28,5 +29,7 @@ void Environment_ctor(Environment *self, Reactor *main) {
self->running = false;
self->wait_until = Environment_wait_until;
self->calculate_levels = Environment_calculate_levels;
self->current_tag.time = 0;
self->current_tag.microstep = 0;
Scheduler_ctor(&self->scheduler, self);
}
5 changes: 3 additions & 2 deletions src/hardware/riot/riot_implementation.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ void hardware_wait_for(instant_t current_time, instant_t wake_up_time) {
//ztimer_t timeout = { .callback=callback, .arg="Hello ztimer!" };
//ztimer_set(ZTIMER_SEC, &timeout, 2);

puts("riot sleep");
if (IS_USED(MODULE_ZTIMER)) {
puts("calculating delta");
int64_t time_delta = wake_up_time - current_time;
int64_t usec = time_delta / 1000;

printf("sleeping microseconds %lli\n", usec);
ztimer_sleep(ZTIMER_USEC, usec);
} else {
puts("boring sleep");
uint32_t loops = coreclk() / 20;
for (volatile uint32_t i = 0; i < loops; i++) { }
}
Expand Down
14 changes: 10 additions & 4 deletions src/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,29 @@ void Scheduler_prepare_timestep(Scheduler *self) {
void Scheduler_run(Scheduler *self) {
puts("entering main-loop");

while(true) {}

while (!self->event_queue_.empty(&self->event_queue_)) {
// fetch tag from next event in queue
puts("fetching next tag");
tag_t next_tag = self->event_queue_.next_tag(&self->event_queue_);

// sleep until this time
puts("waiting until");
puts("waiting");
self->env_->wait_until(self->env_, next_tag.time);

puts("processing tag");
// process this tag
do {
puts("prepare time");
self->prepare_time_step(self);

puts("pop event queue");
Event event = self->event_queue_.pop(&self->event_queue_);
self->env_->current_tag = event.tag;
event.trigger->is_present = true;

if (event.trigger->update_value) {
// e.g. Timer Event
puts("call update_value function");
event.trigger->update_value(event.trigger);
}

Expand All @@ -51,14 +54,17 @@ void Scheduler_run(Scheduler *self) {
self->reaction_queue_.insert(&self->reaction_queue_, event.trigger->effects[i]);
}

puts("finished pushing events");
while(true) {}
} while (lf_tag_compare(next_tag, self->event_queue_.next_tag(&self->event_queue_)) == 0);

puts("done processing events");

while (!self->reaction_queue_.empty(&self->reaction_queue_)) {
Reaction *reaction = self->reaction_queue_.pop(&self->reaction_queue_);
reaction->body(reaction);
}
}
printf("Scheduler out of events. Shutting down.\n");
}

void Scheduler_recursive_level(Reactor *reactor, int current_level) {
Expand Down

0 comments on commit ad5e615

Please sign in to comment.