diff --git a/dev/eeprom.c b/dev/eeprom.c index 0014165687de280512cec06b1a7d7a7efbe742d5..a1af13c82b48e84c91db7bdcd578c2331843ab64 100644 --- a/dev/eeprom.c +++ b/dev/eeprom.c @@ -45,12 +45,26 @@ * ------------------------------------------------ */ +uint8_t has_eeprom = 0; + +uint8_t eeprom_present(uint8_t i2cif, uint8_t i2c_addr) +{ + has_eeprom = 1; + if( !mi2c_devprobe(i2cif, i2c_addr) ) + if( !mi2c_devprobe(i2cif, i2c_addr) ) + has_eeprom = 0; + + return 0; +} int eeprom_read(uint8_t i2cif, uint8_t i2c_addr, uint32_t offset, uint8_t *buf, size_t size) { int i; unsigned char c; + if(!has_eeprom) + return -1; + mi2c_start(i2cif); if(mi2c_put_byte(i2cif, i2c_addr << 1) < 0) { @@ -77,6 +91,9 @@ int eeprom_write(uint8_t i2cif, uint8_t i2c_addr, uint32_t offset, uint8_t *buf, { int i, busy; + if(!has_eeprom) + return -1; + for(i=0;i<size;i++) { mi2c_start(i2cif); @@ -227,7 +244,9 @@ int8_t eeprom_init_purge(uint8_t i2cif, uint8_t i2c_addr) uint16_t used = 0xffff, i; uint16_t pattern = 0xff; - eeprom_read(i2cif, i2c_addr, EE_BASE_INIT, &used, sizeof(used)); + if( eeprom_read(i2cif, i2c_addr, EE_BASE_INIT, &used, sizeof(used)) != sizeof(used) ) + return EE_RET_I2CERR; + if(used==0xffff) used=0; for(i=0; i<used; ++i) eeprom_write(i2cif, i2c_addr, EE_BASE_INIT+sizeof(used)+i, &pattern, 1); diff --git a/include/eeprom.h b/include/eeprom.h index 978add306296ec9d89e8722081a9f0af03cc940e..3d5ca9e9ba17fd1ed43ed35ec13ca976da61f2c9 100644 --- a/include/eeprom.h +++ b/include/eeprom.h @@ -17,6 +17,7 @@ extern int32_t sfp_alpha; extern int32_t sfp_deltaTx; extern int32_t sfp_deltaRx; extern uint32_t cal_phase_transition; +extern uint8_t has_eeprom; struct s_sfpinfo { @@ -27,6 +28,7 @@ struct s_sfpinfo uint8_t chksum; } __attribute__((__packed__)); +uint8_t eeprom_present(uint8_t i2cif, uint8_t i2c_addr); int eeprom_read(uint8_t i2cif, uint8_t i2c_addr, uint32_t offset, uint8_t *buf, size_t size); int eeprom_write(uint8_t i2cif, uint8_t i2c_addr, uint32_t offset, uint8_t *buf, size_t size); diff --git a/shell/cmd_calib.c b/shell/cmd_calib.c index 743eae451818334da6a6479338c81ad9f5ce6140..e8b3e0c1f1ec2175a6f202e0e945918a24924603 100644 --- a/shell/cmd_calib.c +++ b/shell/cmd_calib.c @@ -22,7 +22,7 @@ int cmd_calib(const char *args[]) } else if( !args[0] ) { - if( eeprom_phtrans(WRPC_FMC_I2C, FMC_EEPROM_ADR, &trans, 0) ) + if( eeprom_phtrans(WRPC_FMC_I2C, FMC_EEPROM_ADR, &trans, 0) >0 ) { mprintf("Found phase transition in EEPROM: %dps\n", trans); cal_phase_transition = trans; diff --git a/shell/shell.c b/shell/shell.c index 4dbd300e2ca6865aef33dee82a66d0ebb41712c9..5a4729fbec5e338cb333c9e13a934fcff6d1feda 100644 --- a/shell/shell.c +++ b/shell/shell.c @@ -6,6 +6,7 @@ #include "uart.h" #include "syscon.h" #include "shell.h" +#include "eeprom.h" #define SH_MAX_LINE_LEN 80 #define SH_MAX_ARGS 8 @@ -274,9 +275,8 @@ int shell_boot_script(void) uint8_t next=0; //first check if EEPROM is really there - if( !mi2c_devprobe(WRPC_FMC_I2C, FMC_EEPROM_ADR) ) - if( !mi2c_devprobe(WRPC_FMC_I2C, FMC_EEPROM_ADR) ) - return -1; + eeprom_present(WRPC_FMC_I2C, FMC_EEPROM_ADR); + if(!has_eeprom) return -1; while(1) {