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 59be074
Show file tree
Hide file tree
Showing 3 changed files with 25 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
23 changes: 19 additions & 4 deletions src/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,33 @@ 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_);

puts("waituntil");

if (self == NULL) {
puts("self is NULL");
}

if (self->env_ == NULL) {
puts("env is NULL");
}

if (self->env_->wait_until == NULL) {
puts("wait_until is NULL");
}

// sleep until this time
puts("waiting until");
while (true) {}
self->env_->wait_until(self->env_, next_tag.time);
puts("done waiting");
//while(true) {}

puts("processing tag");

// process this tag
do {
self->prepare_time_step(self);
Expand All @@ -58,7 +74,6 @@ void Scheduler_run(Scheduler *self) {
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 59be074

Please sign in to comment.