hexagram/include/hexagram/schedule.h
2023-12-27 18:31:02 -05:00

46 lines
1.2 KiB
C

#ifndef _HEXAGRAM_SCHEDULE_H
#define _HEXAGRAM_SCHEDULE_H
#include <stdint.h>
#include <sys/types.h>
#include <sys/time.h>
#include <time.h>
#include <signal.h>
#include <hexagram/can.h>
typedef int (*hexagram_schedule_handler)(struct can_frame *, void *);
typedef struct _hexagram_schedule_slot {
time_t interval_us;
struct can_frame frame;
hexagram_schedule_handler handler;
} hexagram_schedule_slot;
typedef struct _hexagram_schedule_timer {
timer_t id;
struct sigevent ev;
struct itimerspec ts;
hexagram_schedule_slot *slot;
void *ctx;
int error;
} hexagram_schedule_timer;
typedef struct _hexagram_schedule {
hexagram_schedule_slot *table;
size_t count;
} hexagram_schedule;
hexagram_schedule *hexagram_schedule_create(hexagram_schedule_slot *table,
size_t count,
void *ctx);
void hexagram_schedule_destroy(hexagram_schedule *schedule);
int hexagram_schedule_run(hexagram_schedule *schedule);
int hexagram_schedule_stop(hexagram_schedule *schedule);
int hexagram_schedule_error(hexagram_schedule *schedule);
#endif /* _HEXAGRAM_SCHEDULE_H */