timer aded
This commit is contained in:
parent
0ae4bc9526
commit
0b20b8cb60
@ -76,7 +76,7 @@ const ArpEntry *arpc_get_ask(ArpCache *arpc, ip4_addr ip) {
|
||||
uint32_t attemptN = 0;
|
||||
while (((entry = arpc_get(arpc, ip)) == NULL) && (attemptN < ETHLIB_ARP_RETRY_COUNT)) {
|
||||
arpc_ask(arpc, ip);
|
||||
ETHLIB_SLEEP(20);
|
||||
ETHLIB_SLEEP_MS(20);
|
||||
//attemptN++;
|
||||
}
|
||||
|
||||
|
22
timer.c
Normal file
22
timer.c
Normal file
@ -0,0 +1,22 @@
|
||||
//
|
||||
// Created by epagris on 2022.12.21..
|
||||
//
|
||||
|
||||
#include "timer.h"
|
||||
#include "dynmem.h"
|
||||
#include "utils.h"
|
||||
|
||||
Timer *timer_new(uint32_t maxSched) {
|
||||
uint32_t tmrHdrSize = sizeof(TimePoint) + sizeof(AlarmAssignment *) + 2 * sizeof(uint32_t);
|
||||
Timer * tmr = (Timer *) dynmem_alloc(tmrHdrSize + maxSched * sizeof(AlarmAssignment));
|
||||
ASSERT_NULL(tmr);
|
||||
|
||||
tmr->maxSched = maxSched;
|
||||
tmr->nSched = 0;
|
||||
tmr->nextAlarm = NULL;
|
||||
tmr->time.s = 0;
|
||||
tmr->time.ns = 0;
|
||||
memset(tmr->alarms, 0, maxSched * sizeof(AlarmAssignment));
|
||||
|
||||
return tmr;
|
||||
}
|
50
timer.h
Normal file
50
timer.h
Normal file
@ -0,0 +1,50 @@
|
||||
#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
|
Loading…
x
Reference in New Issue
Block a user