Fraise  2.1
FRAmework for Interfacing Software and Electronics
fraise_eeprom

EEPROM emulation in flash memory. More...

EEPROM emulation in flash memory.

Eeprom is first initialized at boot time by the system calling eeprom_setup(), which copies the last saved version of the data from flash to an dedicated RAM area. This area can then be read or modified. If modified, the RAM area must be written back to flash with eeprom_commit().

The fraise_eeprom API reserves some bytes at the beginning of the emulated EEPROM to store fraise system data, such as the "name" and the "ID" of the device.

Hi-level persistent parameter API

This API allows to declare a set of parameters, and automates saving to and reloading from the EEPROM emulation.

void eeprom_declare_main ()
 User defined function where to declare the parameters. More...
 
void eeprom_declare_data (char *data, uint8_t size)
 Declare data of arbitrary size. More...
 
void eeprom_declare_int8 (int8_t *data)
 Declare a 8-bit signed parameter. More...
 
void eeprom_declare_uint8 (uint8_t *data)
 Declare a 8-bit unsigned parameter. More...
 
void eeprom_declare_int16 (int16_t *data)
 Declare a 16-bit signed parameter. More...
 
void eeprom_declare_uint16 (uint16_t *data)
 Declare a 16-bit unsigned parameter. More...
 
void eeprom_declare_int32 (int32_t *data)
 Declare a 32-bit signed parameter. More...
 
void eeprom_declare_uint32 (uint32_t *data)
 Declare a 32-bit unsigned parameter. More...
 
void eeprom_load ()
 Reload all the parameters from eeprom. More...
 
void eeprom_save ()
 Save all the parameters to eeprom. More...
 

Low-level API

void eeprom_setup ()
 Initialize the eeprom by copying data from flash to RAM. More...
 
char eeprom_user_read (int address)
 Read a byte from eeprom user space. More...
 
void eeprom_user_write (int address, char data)
 Write a byte to eeprom user space. More...
 
void eeprom_write_name (char *newname)
 Change the device name in eeprom. More...
 
const char * eeprom_get_name ()
 Read the device name stored in eeprom. More...
 
void eeprom_set_id (uint8_t newid)
 Change the device ID in eeprom. More...
 
uint8_t eeprom_get_id ()
 Read the device ID stored in eeprom. More...
 
void eeprom_commit ()
 Actually write the eeprom area to flash. More...
 

Function Documentation

◆ eeprom_declare_main()

void eeprom_declare_main ( )

User defined function where to declare the parameters.

Note
User has to define this function, which must be a list of eeprom_declare_*() calls. Example:
void eeprom_main() {
}

◆ eeprom_declare_data()

void eeprom_declare_data ( char *  data,
uint8_t  size 
)

Declare data of arbitrary size.

Note
use in eeprom_declare_main() only
Parameters
datathe address of the declared data
sizethe size of the data

◆ eeprom_declare_int8()

void eeprom_declare_int8 ( int8_t *  data)
inline

Declare a 8-bit signed parameter.

Note
use in eeprom_declare_main() only
Parameters
datathe address of the declared parameter

◆ eeprom_declare_uint8()

void eeprom_declare_uint8 ( uint8_t *  data)
inline

Declare a 8-bit unsigned parameter.

Note
use in eeprom_declare_main() only
Parameters
datathe address of the declared parameter

◆ eeprom_declare_int16()

void eeprom_declare_int16 ( int16_t *  data)
inline

Declare a 16-bit signed parameter.

Note
use in eeprom_declare_main() only
Parameters
datathe address of the declared parameter

◆ eeprom_declare_uint16()

void eeprom_declare_uint16 ( uint16_t *  data)
inline

Declare a 16-bit unsigned parameter.

Note
use in eeprom_declare_main() only
Parameters
datathe address of the declared parameter

◆ eeprom_declare_int32()

void eeprom_declare_int32 ( int32_t *  data)
inline

Declare a 32-bit signed parameter.

Note
use in eeprom_declare_main() only
Parameters
datathe address of the declared parameter

◆ eeprom_declare_uint32()

void eeprom_declare_uint32 ( uint32_t *  data)
inline

Declare a 32-bit unsigned parameter.

Note
use in eeprom_declare_main() only
Parameters
datathe address of the declared parameter

◆ eeprom_load()

void eeprom_load ( )

Reload all the parameters from eeprom.

Note
You might want to call this function in your setup().

◆ eeprom_save()

void eeprom_save ( )

Save all the parameters to eeprom.

Note
eeprom_save() automatically calls eeprom_commit() after the RAM image is updated.

◆ eeprom_setup()

void eeprom_setup ( )

Initialize the eeprom by copying data from flash to RAM.

Note
This function is automatically called at startup. You shouldn't need to call it manually.

◆ eeprom_user_read()

char eeprom_user_read ( int  address)

Read a byte from eeprom user space.

Parameters
addressthe address to read
Returns
the data at this address

◆ eeprom_user_write()

void eeprom_user_write ( int  address,
char  data 
)

Write a byte to eeprom user space.

Parameters
addressthe address to write to
datathe value of the byte to write

◆ eeprom_write_name()

void eeprom_write_name ( char *  newname)

Change the device name in eeprom.

Parameters
newnamethe new name to store (no more than 16 chars)

◆ eeprom_get_name()

const char* eeprom_get_name ( )

Read the device name stored in eeprom.

Returns
the currently stored name

◆ eeprom_set_id()

void eeprom_set_id ( uint8_t  newid)

Change the device ID in eeprom.

Parameters
newidthe new ID to store (must be in range [1:126])

◆ eeprom_get_id()

uint8_t eeprom_get_id ( )

Read the device ID stored in eeprom.

Returns
the currently stored ID

◆ eeprom_commit()

void eeprom_commit ( )

Actually write the eeprom area to flash.

Note
This function is protected with a critical section, which ensures that interrupt are fully disabled during actual flash writing.
eeprom_declare_uint8
void eeprom_declare_uint8(uint8_t *data)
Declare a 8-bit unsigned parameter.
Definition: fraise_eeprom.h:68
eeprom_declare_int16
void eeprom_declare_int16(int16_t *data)
Declare a 16-bit signed parameter.
Definition: fraise_eeprom.h:74