Library emulating a 16 byte high endurance EEPROM using one page of on-chip Flash memory.
Functions | |
| void | lib_eeprom_byte_write (uint8_t adr, uint8_t dat) |
| void | lib_eeprom_bytes_write (uint8_t adr, uint8_t *p, uint8_t n) |
| uint8_t | lib_eeprom_byte_read (uint8_t adr) |
| void | lib_eeprom_bytes_read (uint8_t adr, uint8_t *p, uint8_t n) |
| void lib_eeprom_byte_write | ( | uint8_t | adr, |
| uint8_t | dat | ||
| ) |
Function to write a byte to the EEPROM
| adr | 8 bit address in EEPROM |
| dat | byte to write |
Definition at line 50 of file lib_eeprom.c.
{
uint8_t i;
uint8_t xdata *ea = get_eeprom_address(adr);
if (dat == *ea)
return;
if (*ea != 0xff)
{
ea -= adr;
for(i=0;i<EEPROM_SIZE;i++)
eeprom_buf[i] = *ea++;
eeprom_buf[adr] = dat;
if (ea == (HAL_DATA_NV_BASE_ADDRESS + HAL_FLASH_PAGE_SIZE))
{
hal_flash_page_erase(HAL_DATA_NV_FLASH_PN0);
if(HAL_DATA_NV_FLASH_PAGES == 2)
{
hal_flash_page_erase(HAL_DATA_NV_FLASH_PN1);
}
ea = (uint8_t xdata *)(HAL_DATA_NV_BASE_ADDRESS + EEPROM_SIZE);
}
else
{
if (*fa == 0x00)
fa++;
if (*fa == 0xff)
hal_flash_byte_write((uint16_t)fa, 0xf0);
else
hal_flash_byte_write((uint16_t)fa, 0x00);
}
for(i=0;i<EEPROM_SIZE;i++)
{
hal_flash_byte_write((uint16_t)ea, eeprom_buf[i]);
ea++;
}
}
else
{
// When the byte at current location is 0xff we write the
// byte directly to the flash:
hal_flash_byte_write((uint16_t)ea, dat);
}
}
| void lib_eeprom_bytes_write | ( | uint8_t | adr, |
| uint8_t * | p, | ||
| uint8_t | n | ||
| ) |
Function to write n bytes to the EEPROM
| adr | 8 bit address in EEPROM |
| *p | pointer to bytes to write |
| n | number of bytes to write |
Definition at line 96 of file lib_eeprom.c.
{
while(n--)
lib_eeprom_byte_write(adr++, *p++);
}
| uint8_t lib_eeprom_byte_read | ( | uint8_t | adr ) |
Function to read a byte from the EEPROM
| adr | 8 bit address in EEPROM |
Definition at line 102 of file lib_eeprom.c.
{
uint8_t xdata *fa = get_eeprom_address(adr);
return *fa;
}
| void lib_eeprom_bytes_read | ( | uint8_t | adr, |
| uint8_t * | p, | ||
| uint8_t | n | ||
| ) |
Function to read n bytes from the EEPROM
| adr | 8 bit address in EEPROM |
| *p | pointer to bytes to write |
| n | number of bytes to read |
Definition at line 108 of file lib_eeprom.c.
{
uint8_t xdata *fa = get_eeprom_address(adr);
while(n--)
{
*p++ = *fa++;
}
}
1.7.2