A general query on how to implement a timeout in chibios correctly.
I currently do the following, for example:
Code: Select all
static THD_WORKING_AREA(wa_thread, 128);
static THD_FUNCTION(Tasks, arg) {
systime_t timeout;
(void)arg;
while(TRUE){
chThdSleepMilliseconds(10);
if(GetArray(&buffer[0], 1) == 1){
if(buffer[0] == 0x55){
timeout = chVTGetSystemTimeX() + TIME_S2I(5);
}
}
// .....
if(chVTGetSystemTimeX() > timeout){
chMBPostTimeout(&mailbox, code, TIME_IMMEDIATE);
}
}
}
But it occurs to me that in this way when the counter (chVTGetSystemTimeX()) reach its maximum and then restart from zero it can generate an error. What would be the correct way to implement it?
Regards!