I am looking at getting some code production-ready. I have several instances of code like this:
// Wait up to one second for specified token to be returned
static bool sd_wait_token(sd_card_t *this, uint8_t token) {
const uint32_t timeout = 1000;
TickType_t xStart = xTaskGetTickCount();
do {
if (token == sd_spi_write(this, SPI_FILL_CHAR)) {
return true;
}
} while ((xTaskGetTickCount() - xStart) < pdMS_TO_TICKS(timeout));
DBG_PRINTF("sd_wait_token: timeout\n");
return false;
}
I’m on a 32-bit processor with configTICK_RATE_HZ 1000u, and it occurs to me that these timeouts will turn into pumpkins after 49 days:
Excellent! I didn’t think of that. So, I need do nothing.
Except… I also use xTaskGetTickCount in my FreeRTOS_time function because I need frequent timestamps, and going to the RTC is expensive, so I only do it once per hour. And, it looks like time_t is 64 bits on this platform. So, I’ll have to deal with wrap there.
Note, you can build a 64 bit time stamp with FreeRTOS if your TickType_t is 32 bits, as FreeRTOS does also keep an overflow counter. The function vTaskSetTimeOutState will get both counters and put it into a structure, which you could access to build a 64 bit time stamp.