aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKévin Redon <kredon@sysmocom.de>2018-07-24 09:54:12 +0200
committerKévin Redon <kredon@sysmocom.de>2018-07-24 09:54:18 +0200
commita71a6f48cbc996bdc30216e4c452d8db8db053ab (patch)
tree39d925247d8cfa41e639e47f6b50004db4742e82
parent57b60d23cfc24fc12a0b78c6faf0e80758c15c39 (diff)
I2C: return error after failed write
The previous mechanism of retrying a failed write could become a infinite blocking loop (until watchdog tiemout). Also the array size is used to know how much data to write and verify instead of a constant. Change-Id: I8d2d090c5f4d1195f4c7eb29b3958a7bb05f56ec
-rw-r--r--firmware/libboard/qmod/source/board_qmod.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/firmware/libboard/qmod/source/board_qmod.c b/firmware/libboard/qmod/source/board_qmod.c
index 7ae1978..47a4cb6 100644
--- a/firmware/libboard/qmod/source/board_qmod.c
+++ b/firmware/libboard/qmod/source/board_qmod.c
@@ -70,8 +70,6 @@ const unsigned char __eeprom_bin[256] = {
#include "i2c.h"
static int write_hub_eeprom(void)
{
- const unsigned int __eeprom_bin_len = 256;
-
int i;
/* wait */
@@ -79,16 +77,18 @@ static int write_hub_eeprom(void)
TRACE_INFO("Writing EEPROM...\n\r");
/* write the EEPROM once */
- for (i = 0; i < 256; i++) {
+ for (i = 0; i < ARRAY_SIZE(__eeprom_bin); i++) {
int rc = eeprom_write_byte(0x50, i, __eeprom_bin[i]);
- /* if the result was negative, repeat that write */
- if (rc < 0)
- i--;
+ if (rc < 0) {
+ TRACE_ERROR("Writing EEPROM failed at byte %u: 0x%02x\n\r",
+ i, __eeprom_bin[i]);
+ return 1;
+ }
}
/* then pursue re-reading it again and again */
TRACE_INFO("Verifying EEPROM...\n\r");
- for (i = 0; i < 256; i++) {
+ for (i = 0; i < ARRAY_SIZE(__eeprom_bin); i++) {
int byte = eeprom_read_byte(0x50, i);
TRACE_INFO("0x%02x: %02x\n\r", i, byte);
if (byte != __eeprom_bin[i])