@@ -59,7 +59,8 @@ Write cycle time (byte or page) - 5 ms
5959#define EEPROM_I2C_CLOCK (i2cp->config->clock_speed)
6060#endif
6161*/
62- #define EEPROM_I2C_CLOCK 400000
62+ /* Fallback frequency if not provided via config and not detectable */
63+ #define EEPROM_I2C_CLOCK_DEFAULT 400000U
6364
6465/*
6566 ******************************************************************************
@@ -98,12 +99,13 @@ Write cycle time (byte or page) - 5 ms
9899/**
99100 * @brief Calculates requred timeout.
100101 */
101- static systime_t calc_timeout (I2CDriver * i2cp , size_t txbytes , size_t rxbytes ) {
102+ static systime_t calc_timeout (I2CDriver * i2cp , size_t txbytes , size_t rxbytes , uint32_t bus_hz ) {
102103 (void )i2cp ;
103104 const uint32_t bitsinbyte = 10 ;
104105 uint32_t tmo ;
106+ uint32_t freq = bus_hz ? bus_hz : EEPROM_I2C_CLOCK_DEFAULT ;
105107 tmo = ((txbytes + rxbytes + 1 ) * bitsinbyte * 1000 );
106- tmo /= EEPROM_I2C_CLOCK ;
108+ tmo /= freq ;
107109 tmo += 10 ; /* some additional milliseconds to be safer */
108110 return TIME_MS2I (tmo );
109111}
@@ -126,7 +128,7 @@ static msg_t eeprom_read(const I2CEepromFileConfig *eepcfg,
126128 const bool one_byte_addr = (eepcfg -> size <= 2048U );
127129 const uint32_t eff_off = offset + eepcfg -> barrier_low ;
128130 const size_t addr_bytes = one_byte_addr ? 1U : 2U ;
129- systime_t tmo = calc_timeout (eepcfg -> i2cp , addr_bytes , len );
131+ systime_t tmo = calc_timeout (eepcfg -> i2cp , addr_bytes , len , eepcfg -> bus_hz );
130132
131133 osalDbgAssert (((len <= eepcfg -> size ) && ((offset + len ) <= eepcfg -> size )),
132134 "out of device bounds" );
@@ -175,7 +177,7 @@ static msg_t eeprom_write(const I2CEepromFileConfig *eepcfg, uint32_t offset,
175177 const bool one_byte_addr = (eepcfg -> size <= 2048U );
176178 const uint32_t eff_off = offset + eepcfg -> barrier_low ;
177179 const size_t addr_bytes = one_byte_addr ? 1U : 2U ;
178- systime_t tmo = calc_timeout (eepcfg -> i2cp , (len + addr_bytes ), 0 );
180+ systime_t tmo = calc_timeout (eepcfg -> i2cp , (len + addr_bytes ), 0 , eepcfg -> bus_hz );
179181
180182 osalDbgAssert (((len <= eepcfg -> size ) && ((offset + len ) <= eepcfg -> size )),
181183 "out of device bounds" );
0 commit comments