Implemented unit timed tick and uart rx timeout

This commit is contained in:
2018-01-15 15:04:09 +01:00
parent b3d1f95e7d
commit 8272a36aee
8 changed files with 69 additions and 3 deletions
+10
View File
@@ -45,6 +45,9 @@ struct unit {
/** Bit-map of held resources */
ResourceMap resources;
uint16_t tick_interval;
uint16_t _tick_cnt;
};
/**
@@ -111,6 +114,13 @@ struct unit_driver {
* Handle an incoming request. Return true if command was OK.
*/
error_t (*handleRequest)(Unit *unit, TF_ID frame_id, uint8_t command, PayloadParser *pp);
/**
* Periodic update call.
* This is run from the SysTick interrupt handler,
* any communication should be deferred via the job queue.
*/
void (*updateTick)(Unit *unit);
};
/**
+18
View File
@@ -583,3 +583,21 @@ void ureg_print_unit_resources(IniWriter *iw)
}
iw_newline(iw);
}
void ureg_tick_units(void)
{
UlistEntry *li = ulist_head;
while (li != NULL) {
Unit *const pUnit = &li->unit;
if (pUnit->status == E_SUCCESS && pUnit->tick_interval > 0) {
if (pUnit->_tick_cnt == 0) {
if (pUnit->driver->updateTick) {
pUnit->driver->updateTick(pUnit);
}
pUnit->_tick_cnt = pUnit->tick_interval;
}
pUnit->_tick_cnt--;
}
li = li->next;
}
}
+5
View File
@@ -142,4 +142,9 @@ Unit *ureg_get_rsc_owner(Resource resource);
*/
void ureg_print_unit_resources(IniWriter *iw);
/**
* 1ms tick for all units that want it
*/
void ureg_tick_units(void);
#endif //GEX_UNIT_REGISTRY_H