Start prototyping things

This commit is contained in:
XANTRONIX Development 2023-12-24 00:11:00 -05:00
parent e6a85bc03a
commit ad3af5b7fa

36
src/schedule.c Normal file
View file

@ -0,0 +1,36 @@
#include <stdlib.h>
#include <hexagram/schedule.h>
hexagram_schedule *hexagram_schedule_create(hexagram_table_entry *table,
size_t count) {
hexagram_schedule *schedule;
size_t i;
if ((schedule = malloc(sizeof(*schedule) + count * sizeof(hexagram_schedule_slot))) == 0) {
goto error_malloc_schedule;
}
schedule->timer = NULL;
schedule->current = 0;
for (i=0; i<count; i++) {
hexagram_schedule_slot *slot = &((hexagram_schedule_slot *)(schedule + 1))[i];
slot->interval_us = 0;
slot->entry = &table[i];
}
return schedule;
error_malloc_schedule:
return NULL;
}
void hexagram_schedule_destroy(hexagram_schedule *schedule) {
if (schedule->timer) {
timer_delete(schedule->timer);
}
free(schedule);
}