51 lines
1.1 KiB
C
51 lines
1.1 KiB
C
#ifndef ETHERLIB_TEST_TIMER_H
|
|
#define ETHERLIB_TEST_TIMER_H
|
|
|
|
#include <stdint.h>
|
|
|
|
/**
|
|
* A single point in time
|
|
*/
|
|
typedef struct {
|
|
uint32_t s; ///< Seconds
|
|
uint32_t ns; ///< Nanoseconds
|
|
} TimePoint;
|
|
|
|
|
|
struct Timer_;
|
|
|
|
typedef union {
|
|
void * ptr;
|
|
uint32_t u;
|
|
} AlarmUserData;
|
|
|
|
typedef void (*TimerAlarmCb)(struct Timer_ * timer, AlarmUserData user);
|
|
|
|
typedef struct {
|
|
TimePoint time; ///< Alarm time
|
|
TimerAlarmCb cb; ///< Pointer to callback function
|
|
AlarmUserData params; ///< User data passed to callback function
|
|
} AlarmAssignment;
|
|
|
|
/**
|
|
* Timer class
|
|
*/
|
|
typedef struct Timer_ {
|
|
TimePoint time; ///< Absolute time
|
|
AlarmAssignment * nextAlarm; ///< Nearest alarm
|
|
uint32_t maxSched; ///< Maximum number of scheduled alarms
|
|
uint32_t nSched; ///< Number of scheduled alarms
|
|
AlarmAssignment alarms[]; ///< Alarm assigment pool
|
|
} Timer;
|
|
|
|
/**
|
|
* Create new timer
|
|
* @param maxSched number of maximum alarms to be scheduled
|
|
* @return pointer to new instance OR NULL on error
|
|
*/
|
|
Timer * timer_new(uint32_t maxSched);
|
|
|
|
|
|
|
|
#endif //ETHERLIB_TEST_TIMER_H
|