Skip to content
Snippets Groups Projects
Commit bc6b72e0 authored by Grzegorz Daniluk's avatar Grzegorz Daniluk
Browse files

check FMC EEPROM presence before doing anything on it

parent 03dd3536
Branches
Tags
No related merge requests found
......@@ -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);
......
......@@ -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);
......
......@@ -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;
......
......@@ -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)
{
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment