chVTGetSystemTimeX overflow
Posted: Thu Mar 07, 2019 10:45 pm
Hi guys!
This is my first post!
I'm new to Chibios, so if this is a dumb question, please excuse.
I'm using a STM32F103, I have some functions that need to wait for a specific number of milliseconds.
I'm using chVTGetSystemTimeX to get the start time and check periodically if X milliseconds have passed. The problem is that my system time overflows and goes back to zero in a short period of a time, making my function run much before it should.
I don't have a 32bits timer available, I tried increasing the system tick time, but I'm almost in its limit.
Here is a pseudo code:
The problem is that if the cycle_start_time is, for example, 0xFF00, after the system time reaches 0xFFFF it will overflow, and the next check it will not be "WithinX"... thus, running the function before it should.
How do you guys handle it?
This is my first post!
I'm new to Chibios, so if this is a dumb question, please excuse.
I'm using a STM32F103, I have some functions that need to wait for a specific number of milliseconds.
I'm using chVTGetSystemTimeX to get the start time and check periodically if X milliseconds have passed. The problem is that my system time overflows and goes back to zero in a short period of a time, making my function run much before it should.
I don't have a 32bits timer available, I tried increasing the system tick time, but I'm almost in its limit.
Here is a pseudo code:
Code: Select all
systime_t cycle_start_time = chVTGetSystemTimeX();
systime_t cycle_end_time = cycle_start_time + TIME_MS2I(3000);
...
if(!chVTIsSystemTimeWithinX(cycle_start_time, cycle_end_time) {
runMyFunction();
}
The problem is that if the cycle_start_time is, for example, 0xFF00, after the system time reaches 0xFFFF it will overflow, and the next check it will not be "WithinX"... thus, running the function before it should.
How do you guys handle it?