|
@@ -57,8 +57,8 @@ static void eeprom_write(uint16_t w_addr,uint8_t *data,uint16_t lenth);
|
|
|
static void eeprom_read(uint16_t r_addr,uint8_t *data,uint16_t lenth);
|
|
static void eeprom_read(uint16_t r_addr,uint8_t *data,uint16_t lenth);
|
|
|
static void check_threshold(uint8_t in_out,uint8_t channel);
|
|
static void check_threshold(uint8_t in_out,uint8_t channel);
|
|
|
|
|
|
|
|
-static void eeprom_page_read(uint16_t addr,uint8_t *data,uint16_t lenth);
|
|
|
|
|
-static void eeprom_write_page(uint16_t addr,uint8_t *data,uint16_t chuank);
|
|
|
|
|
|
|
+static uint8_t eeprom_page_read(uint16_t addr,uint8_t *data,uint16_t lenth);
|
|
|
|
|
+static uint8_t eeprom_write_page(uint16_t addr,uint8_t *data,uint16_t chuank);
|
|
|
static void eeprom_auto_page_write(uint16_t addr,uint8_t *data,uint16_t lenth);
|
|
static void eeprom_auto_page_write(uint16_t addr,uint8_t *data,uint16_t lenth);
|
|
|
static void eeprom_auto_page_read(uint16_t addr,uint8_t *data,uint16_t lenth);
|
|
static void eeprom_auto_page_read(uint16_t addr,uint8_t *data,uint16_t lenth);
|
|
|
static inline void iic_set_sda_input()
|
|
static inline void iic_set_sda_input()
|
|
@@ -83,6 +83,7 @@ void eeprom_init(void)
|
|
|
board->check_threshold = check_threshold;
|
|
board->check_threshold = check_threshold;
|
|
|
board->read_eeprom_page = eeprom_auto_page_read;
|
|
board->read_eeprom_page = eeprom_auto_page_read;
|
|
|
board->write_eeprom_page = eeprom_auto_page_write;
|
|
board->write_eeprom_page = eeprom_auto_page_write;
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -137,6 +138,7 @@ static void iic_stop_signal(void)
|
|
|
IIC_SDA_CLR;
|
|
IIC_SDA_CLR;
|
|
|
DelayNus(4);
|
|
DelayNus(4);
|
|
|
IIC_SCL_SET;
|
|
IIC_SCL_SET;
|
|
|
|
|
+ DelayNus(4);
|
|
|
IIC_SDA_SET;
|
|
IIC_SDA_SET;
|
|
|
DelayNus(4);
|
|
DelayNus(4);
|
|
|
}
|
|
}
|
|
@@ -407,28 +409,32 @@ static void check_threshold(uint8_t in_out,uint8_t channel)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-static void eeprom_page_read(uint16_t addr,uint8_t *data,uint16_t lenth)
|
|
|
|
|
|
|
+static uint8_t eeprom_page_read(uint16_t addr,uint8_t *data,uint16_t lenth)
|
|
|
{
|
|
{
|
|
|
if(lenth == 0 || lenth > PAGE_SIZE || ((addr % PAGE_SIZE) + lenth > PAGE_SIZE))
|
|
if(lenth == 0 || lenth > PAGE_SIZE || ((addr % PAGE_SIZE) + lenth > PAGE_SIZE))
|
|
|
{
|
|
{
|
|
|
- return;
|
|
|
|
|
|
|
+ return 1;
|
|
|
}
|
|
}
|
|
|
iic_start_signal();
|
|
iic_start_signal();
|
|
|
if(USER_DEFINE_EEPROM_TYPE > AT24C16)
|
|
if(USER_DEFINE_EEPROM_TYPE > AT24C16)
|
|
|
{
|
|
{
|
|
|
iic_send_byte(0XA0);
|
|
iic_send_byte(0XA0);
|
|
|
- iic_wait_ack();
|
|
|
|
|
|
|
+ if(iic_wait_ack())
|
|
|
|
|
+ goto failed;
|
|
|
iic_send_byte(addr >> 8);
|
|
iic_send_byte(addr >> 8);
|
|
|
}else
|
|
}else
|
|
|
{
|
|
{
|
|
|
iic_send_byte(0XA0 + ((addr / 256) << 1));
|
|
iic_send_byte(0XA0 + ((addr / 256) << 1));
|
|
|
}
|
|
}
|
|
|
- iic_wait_ack();
|
|
|
|
|
|
|
+ if(iic_wait_ack())
|
|
|
|
|
+ goto failed;
|
|
|
iic_send_byte(addr % 256);
|
|
iic_send_byte(addr % 256);
|
|
|
- iic_wait_ack();
|
|
|
|
|
|
|
+ if(iic_wait_ack())
|
|
|
|
|
+ goto failed;
|
|
|
iic_start_signal();
|
|
iic_start_signal();
|
|
|
iic_send_byte(0XA1);
|
|
iic_send_byte(0XA1);
|
|
|
- iic_wait_ack();
|
|
|
|
|
|
|
+ if(iic_wait_ack())
|
|
|
|
|
+ goto failed;
|
|
|
|
|
|
|
|
for(int i = 0; i < lenth;i++)
|
|
for(int i = 0; i < lenth;i++)
|
|
|
{
|
|
{
|
|
@@ -442,35 +448,50 @@ static void eeprom_page_read(uint16_t addr,uint8_t *data,uint16_t lenth)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
iic_stop_signal();
|
|
iic_stop_signal();
|
|
|
|
|
+
|
|
|
|
|
+ return 0;
|
|
|
|
|
+failed:
|
|
|
|
|
+ iic_stop_signal();
|
|
|
|
|
+ return 1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-static void eeprom_write_page(uint16_t addr,uint8_t *data,uint16_t chuank)
|
|
|
|
|
|
|
+static uint8_t eeprom_write_page(uint16_t addr,uint8_t *data,uint16_t chuank)
|
|
|
{
|
|
{
|
|
|
if(chuank == 0 || chuank > PAGE_SIZE || ((addr % PAGE_SIZE) + chuank > PAGE_SIZE))
|
|
if(chuank == 0 || chuank > PAGE_SIZE || ((addr % PAGE_SIZE) + chuank > PAGE_SIZE))
|
|
|
{
|
|
{
|
|
|
- return;
|
|
|
|
|
|
|
+ return 1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
iic_start_signal();
|
|
iic_start_signal();
|
|
|
if(USER_DEFINE_EEPROM_TYPE > AT24C16)
|
|
if(USER_DEFINE_EEPROM_TYPE > AT24C16)
|
|
|
{
|
|
{
|
|
|
iic_send_byte(0XA0);
|
|
iic_send_byte(0XA0);
|
|
|
- iic_wait_ack();
|
|
|
|
|
|
|
+ if(iic_wait_ack())
|
|
|
|
|
+ goto failed;
|
|
|
iic_send_byte(addr >> 8);
|
|
iic_send_byte(addr >> 8);
|
|
|
}else
|
|
}else
|
|
|
{
|
|
{
|
|
|
iic_send_byte(0XA0 + ((addr / 256) << 1));
|
|
iic_send_byte(0XA0 + ((addr / 256) << 1));
|
|
|
}
|
|
}
|
|
|
- iic_wait_ack();
|
|
|
|
|
|
|
+ if(iic_wait_ack())
|
|
|
|
|
+ goto failed;
|
|
|
iic_send_byte(addr % 256);
|
|
iic_send_byte(addr % 256);
|
|
|
- iic_wait_ack();
|
|
|
|
|
|
|
+ if(iic_wait_ack())
|
|
|
|
|
+ goto failed;
|
|
|
for(uint16_t i = 0; i < chuank;i++)
|
|
for(uint16_t i = 0; i < chuank;i++)
|
|
|
{
|
|
{
|
|
|
iic_send_byte(data[i]);
|
|
iic_send_byte(data[i]);
|
|
|
- iic_wait_ack();
|
|
|
|
|
|
|
+ if(iic_wait_ack())
|
|
|
|
|
+ goto failed;
|
|
|
}
|
|
}
|
|
|
iic_stop_signal();
|
|
iic_stop_signal();
|
|
|
DelayNms(7);
|
|
DelayNms(7);
|
|
|
|
|
+
|
|
|
|
|
+ return 0;
|
|
|
|
|
+failed:
|
|
|
|
|
+ iic_stop_signal();
|
|
|
|
|
+ return 1;
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -480,12 +501,19 @@ static void eeprom_auto_page_write(uint16_t addr,uint8_t *data,uint16_t lenth)
|
|
|
{
|
|
{
|
|
|
uint16_t remaining = lenth;
|
|
uint16_t remaining = lenth;
|
|
|
uint8_t *p = data;
|
|
uint8_t *p = data;
|
|
|
|
|
+ uint8_t count = 5;
|
|
|
|
|
|
|
|
while(remaining > 0)
|
|
while(remaining > 0)
|
|
|
{
|
|
{
|
|
|
uint8_t chunk = PAGE_SIZE - (addr % PAGE_SIZE);
|
|
uint8_t chunk = PAGE_SIZE - (addr % PAGE_SIZE);
|
|
|
if(chunk > remaining) chunk = remaining;
|
|
if(chunk > remaining) chunk = remaining;
|
|
|
- eeprom_write_page(addr, p,chunk);
|
|
|
|
|
|
|
+ do{
|
|
|
|
|
+ if(!eeprom_write_page(addr, p,chunk))
|
|
|
|
|
+ {
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }while(count--);
|
|
|
|
|
+
|
|
|
addr += chunk;
|
|
addr += chunk;
|
|
|
p += chunk;
|
|
p += chunk;
|
|
|
remaining -= chunk;
|
|
remaining -= chunk;
|
|
@@ -497,16 +525,21 @@ static void eeprom_auto_page_read(uint16_t addr,uint8_t *data,uint16_t lenth)
|
|
|
{
|
|
{
|
|
|
uint16_t remaining = lenth;
|
|
uint16_t remaining = lenth;
|
|
|
uint8_t *p = data;
|
|
uint8_t *p = data;
|
|
|
-
|
|
|
|
|
|
|
+ uint8_t count = 5;
|
|
|
|
|
+
|
|
|
while(remaining > 0)
|
|
while(remaining > 0)
|
|
|
{
|
|
{
|
|
|
uint8_t chunk = PAGE_SIZE - (addr % PAGE_SIZE);
|
|
uint8_t chunk = PAGE_SIZE - (addr % PAGE_SIZE);
|
|
|
if(chunk > remaining) chunk = remaining;
|
|
if(chunk > remaining) chunk = remaining;
|
|
|
-
|
|
|
|
|
- eeprom_page_read(addr, p, chunk);
|
|
|
|
|
-
|
|
|
|
|
|
|
+ do{
|
|
|
|
|
+ if(!eeprom_page_read(addr, p, chunk))
|
|
|
|
|
+ {
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }while(count--);
|
|
|
addr += chunk;
|
|
addr += chunk;
|
|
|
p += chunk;
|
|
p += chunk;
|
|
|
remaining -= chunk;
|
|
remaining -= chunk;
|
|
|
}
|
|
}
|
|
|
-}
|
|
|
|
|
|
|
+}
|
|
|
|
|
+
|