diff --git a/prefab/conn_blocks/ipv4/ip_assembler.c b/prefab/conn_blocks/ipv4/ip_assembler.c index d43137e..9269331 100644 --- a/prefab/conn_blocks/ipv4/ip_assembler.c +++ b/prefab/conn_blocks/ipv4/ip_assembler.c @@ -55,7 +55,7 @@ static void ipra_remove_chain(IPv4Assembler * ipra, uint16_t id) { return; } - timer_unsched(E.tmr, chainDesc->id); // remove timeout schedule + timer_unsched(E.tmr, chainDesc->alarmID); // remove timeout schedule IPv4Fragment * iter = chainDesc->fragChain; // unlink and release fragment chain while (iter != NULL) { IPv4Fragment * oldIter = iter; @@ -66,7 +66,7 @@ static void ipra_remove_chain(IPv4Assembler * ipra, uint16_t id) { FragChainDesc * chainIter = ipra->chains; while (chainIter != NULL) { // unlink chain from chain list if (chainIter->next == chainDesc) { // if element is found - chainIter->next = chainDesc->next; // skip by looked up element by setting next properly + chainIter->next = chainDesc->next; // skip looked up element by setting next properly break; // break the loop } chainIter = chainIter->next; @@ -104,7 +104,7 @@ static void ipra_insert_into_chain(FragChainDesc *chainDesc, const IPv4Props *ip ((iter->next == NULL) || (iter->next->offset >= (frag->offset + frag->size)))) { frag->next = iter->next; iter->next = frag; - } else if ((iter == chainDesc->fragChain) && (frag->offset < iter->offset)) { // insert before the firstly received segment + } else if ((iter == chainDesc->fragChain) && (frag->offset < iter->offset)) { // insert before the first received segment frag->next = iter; chainDesc->fragChain = frag; } @@ -141,8 +141,7 @@ void ipra_input(IPv4Assembler *ipra, const IPv4Props *ipProps, const uint8_t *pa AlarmUserData aud; aud.ptr = ipra; aud.u = chainDesc->id; - timer_sched_rel(E.tmr, IP_REASSEMBLY_TIMEOUT_US, ipra_timeout, aud); - timer_report(E.tmr); + chainDesc->alarmID = timer_sched_rel(E.tmr, IP_REASSEMBLY_TIMEOUT_US, ipra_timeout, aud); } bool ipra_try_reassemble(IPv4Assembler *ipra, uint16_t id, uint8_t **payload, uint16_t *size, PcktHeaderElement *pcktHdrLe) { diff --git a/timer.c b/timer.c index c6806a2..03b14b8 100644 --- a/timer.c +++ b/timer.c @@ -106,7 +106,6 @@ uint32_t timer_sched(Timer *tmr, const TimePoint *t, TimerAlarmCb cb, AlarmUserD // increase allocation count tmr->nSched++; - MSG("%d %s\n", tmr->nSched, __FUNCTION__); // replace nearest if needed if (tmr->nSched > 1) { @@ -129,6 +128,10 @@ uint32_t timer_sched_rel(Timer *tmr, int64_t us, TimerAlarmCb cb, AlarmUserData } void timer_unsched(Timer *tmr, uint32_t id) { + if (id == 0) { // no unscheduling on receiving unknown id + return; + } + ETHLIB_OS_MTX_LOCK(&(tmr->tabMtx)); if (tmr->nSched > 0) { @@ -136,7 +139,6 @@ void timer_unsched(Timer *tmr, uint32_t id) { if (alarm != NULL) { memset(alarm, 0, sizeof(AlarmAssignment)); tmr->nSched--; - MSG("%d %s\n", tmr->nSched, __FUNCTION__); timer_update_nearest_alarm(tmr); } } @@ -181,11 +183,12 @@ void timer_tick(Timer *tmr, int64_t us) { // decrease scheduled alarm count tmr->nSched--; - MSG("%d %s\n", tmr->nSched, __FUNCTION__); // update nearest alarm timer_update_nearest_alarm(tmr); + ETHLIB_OS_MTX_UNLOCK(&(tmr->tabMtx)); + // invoke callback if (alarm.cb != NULL) { alarm.cb(tmr, alarm.params); @@ -195,7 +198,6 @@ void timer_tick(Timer *tmr, int64_t us) { t_alarm = time_to_us(&(tmr->nextAlarm->time)); } - ETHLIB_OS_MTX_UNLOCK(&(tmr->tabMtx)); } } } diff --git a/timer.h b/timer.h index 5c697f6..4878dfc 100644 --- a/timer.h +++ b/timer.h @@ -10,8 +10,8 @@ * A single point in time */ typedef struct { - int64_t s; ///< Seconds - int64_t us; ///< Microseconds + uint32_t s; ///< Seconds + uint32_t us; ///< Microseconds } TimePoint; /**