Commit 44c37218 authored by Grzegorz Daniluk's avatar Grzegorz Daniluk

faster i2c for eeprom

On VFC-HD reading EEPROM was taking too long. E.g. reading SFP database through
snmp was taking ~0.5s which was enough to break the timestamps for received PTP
frames and thus the timing. See issue 1649 in wr-cores project on OHWR.
parent b5fbea63
......@@ -12,17 +12,15 @@
#include "syscon.h"
#include "i2c.h"
#define I2C_DELAY 300
void mi2c_delay(void)
void mi2c_delay(uint32_t delay)
{
int i;
for (i = 0; i < I2C_DELAY; i++)
for (i = 0; i < delay; i++)
asm volatile ("nop");
}
#define M_SDA_OUT(i, x) { gpio_out(i2c_if[i].sda, x); mi2c_delay(); }
#define M_SCL_OUT(i, x) { gpio_out(i2c_if[i].scl, x); mi2c_delay(); }
#define M_SDA_OUT(i, x) { gpio_out(i2c_if[i].sda, x); mi2c_delay(i2c_if[i].loop_delay); }
#define M_SCL_OUT(i, x) { gpio_out(i2c_if[i].scl, x); mi2c_delay(i2c_if[i].loop_delay); }
#define M_SDA_IN(i) gpio_in(i2c_if[i].sda)
void mi2c_start(uint8_t i2cif)
......
......@@ -11,8 +11,8 @@
#include <string.h>
struct s_i2c_if i2c_if[2] = {
{SYSC_GPSR_FMC_SCL, SYSC_GPSR_FMC_SDA},
{SYSC_GPSR_SFP_SCL, SYSC_GPSR_SFP_SDA}
{SYSC_GPSR_FMC_SCL, SYSC_GPSR_FMC_SDA, FMC_I2C_DELAY},
{SYSC_GPSR_SFP_SCL, SYSC_GPSR_SFP_SDA, SFP_I2C_DELAY}
};
volatile struct SYSCON_WB *syscon;
......
......@@ -14,7 +14,7 @@ void mi2c_stop(uint8_t i2cif);
void mi2c_get_byte(uint8_t i2cif, unsigned char *data, uint8_t last);
unsigned char mi2c_put_byte(uint8_t i2cif, unsigned char data);
void mi2c_delay(void);
void mi2c_delay(uint32_t delay);
//void mi2c_scan(uint8_t i2cif);
#endif
......@@ -91,10 +91,13 @@ struct SYSCON_WB {
#define WRPC_FMC_I2C 0
#define WRPC_SFP_I2C 1
#define FMC_I2C_DELAY 15
#define SFP_I2C_DELAY 300
struct s_i2c_if {
uint32_t scl;
uint32_t sda;
uint32_t loop_delay;
};
extern struct s_i2c_if i2c_if[2];
......
Markdown is supported
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