Skip to content

Commit

Permalink
warp_esp32_i2c, warp_esp32_rtc: Reduce I2C timeout durations
Browse files Browse the repository at this point in the history
I2C accesses are performed blocking and in case of a missing response,
the main task is blocked for the full timeout duration.
I2C responses are either very quick or missing completely,
so there's no point in using long timeout durations.
Reduce the timeouts to sensible minimums, to avoid blocking
the main task for too long when either I2C chip stops responding.

The temperature sensor replies usually take less than 1ms, sometimes up to 3ms, so use 6ms to be safe.
The RTC replies usually take about 0.5ms, sometimes up to 2ms, so use 4ms to be safe.
  • Loading branch information
MattiasTF committed Nov 22, 2024
1 parent 423e5ef commit 0b74988
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion software/src/modules/warp_esp32_i2c/warp_esp32_i2c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wold-style-cast"
// portTICK_PERIOD_MS expands to an old style cast.
static TickType_t i2c_timeout = 1000 / portTICK_PERIOD_MS;
static TickType_t i2c_timeout = 6 / portTICK_PERIOD_MS;
#pragma GCC diagnostic pop

static uint8_t tmp_cmd_buf[I2C_LINK_RECOMMENDED_SIZE(2)] = {};
Expand Down
2 changes: 1 addition & 1 deletion software/src/modules/warp_esp32_rtc/warp_esp32_rtc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wold-style-cast"
// portTICK_PERIOD_MS expands to an old style cast.
static TickType_t i2c_timeout = 1000 / portTICK_PERIOD_MS;
static TickType_t i2c_timeout = 4 / portTICK_PERIOD_MS;
#pragma GCC diagnostic pop

static uint8_t intToBCD(uint8_t num) {
Expand Down

0 comments on commit 0b74988

Please sign in to comment.