CANopenNode
CANopen protocol stack
|
Eeprom specific data storage functions. More...
Files | |
file | CO_eeprom.h |
Eeprom interface for use with CO_storageEeprom. | |
file | CO_storageEeprom.h |
CANopen data storage object for storing data into block device (eeprom) | |
Functions | |
bool_t | CO_eeprom_init (void *storageModule) |
Initialize eeprom device, target system specific function. | |
size_t | CO_eeprom_getAddr (void *storageModule, bool_t isAuto, size_t len, bool_t *overflow) |
Get free address inside eeprom, target system specific function. | |
void | CO_eeprom_readBlock (void *storageModule, uint8_t *data, size_t eepromAddr, size_t len) |
Read block of data from the eeprom, target system specific function. | |
bool_t | CO_eeprom_writeBlock (void *storageModule, uint8_t *data, size_t eepromAddr, size_t len) |
Write block of data to the eeprom, target system specific function. | |
uint16_t | CO_eeprom_getCrcBlock (void *storageModule, size_t eepromAddr, size_t len) |
Get CRC checksum of the block of data stored in the eeprom, target system specific function. | |
bool_t | CO_eeprom_updateByte (void *storageModule, uint8_t data, size_t eepromAddr) |
Update one byte of data in the eeprom, target system specific function. | |
CO_ReturnError_t | CO_storageEeprom_init (CO_storage_t *storage, CO_CANmodule_t *CANmodule, void *storageModule, OD_entry_t *OD_1010_StoreParameters, OD_entry_t *OD_1011_RestoreDefaultParam, CO_storage_entry_t *entries, uint8_t entriesCount, uint32_t *storageInitError) |
Initialize data storage object (block device (eeprom) specific) | |
void | CO_storageEeprom_auto_process (CO_storage_t *storage, bool_t saveAll) |
Automatically update data if differs inside eeprom. | |
Eeprom specific data storage functions.
This is an interface into generic CANopenNode Data storage base for usage with eeprom chip like 25LC256. Functions CO_storageEeprom_init() and CO_storageEeprom_auto_process are target system independent. Functions specified by CO_eeprom.h file, must be defined by target system. For example implementation see CANopenPIC/PIC32.
Storage principle: This function first reads 'signatures' for all entries from the known address from the eeprom. If signature for each entry is correct, then data is read from correct address from the eeprom into storage location. If signature is wrong, then data for that entry is indicated as corrupt and CANopen emergency message is sent.
Signature also includes 16-bit CRC checksum of the data stored in eeprom. If it differs from CRC checksum calculated from the data actually loaded (on program startup), then entry is indicated as corrupt and CANopen emergency message is sent.
Signature is written to eeprom, when data block is stored via CANopen SDO write command to object 0x1010. Signature is erased, with CANopen SDO write command to object 0x1011. If signature is not valid or is erased for any entry, emergency message is sent. If eeprom is new, then all signatures are wrong, so it is best to store all parameters by writing to 0x1010, sub 1.
If entry attribute has CO_storage_auto set, then data block is stored autonomously, byte by byte, on change, during program run. Those data blocks are stored into write unprotected location. For auto storage to work, its signature in eeprom must be correct. CRC checksum for the data is not used.
bool_t CO_eeprom_init | ( | void * | storageModule | ) |
Initialize eeprom device, target system specific function.
storageModule | Pointer to storage module. |
Get free address inside eeprom, target system specific function.
Function is called several times for each storage block in the initialization phase after CO_eeprom_init().
storageModule | Pointer to storage module. | |
isAuto | True, if variable is auto stored or false if protected | |
len | Length of data, which will be stored to that location | |
[out] | overflow | set to true, if not enough eeprom memory |
void CO_eeprom_readBlock | ( | void * | storageModule, |
uint8_t * | data, | ||
size_t | eepromAddr, | ||
size_t | len ) |
Read block of data from the eeprom, target system specific function.
storageModule | Pointer to storage module. |
data | Pointer to data buffer, where data will be stored. |
eepromAddr | Address in eeprom, from where data will be read. |
len | Length of the data block to be read. |
Write block of data to the eeprom, target system specific function.
It is blocking function, so it waits, until all data is written.
storageModule | Pointer to storage module. |
data | Pointer to data buffer which will be written. |
eepromAddr | Address in eeprom, where data will be written. If data is stored across multiple pages, address must be aligned with page. |
len | Length of the data block. |
uint16_t CO_eeprom_getCrcBlock | ( | void * | storageModule, |
size_t | eepromAddr, | ||
size_t | len ) |
Get CRC checksum of the block of data stored in the eeprom, target system specific function.
storageModule | Pointer to storage module. |
eepromAddr | Address of data in eeprom. |
len | Length of the data. |
Update one byte of data in the eeprom, target system specific function.
Function is used by automatic storage. It updates byte in eeprom only if differs from data.
storageModule | Pointer to storage module. |
data | Data byte to be written |
eepromAddr | Address in eeprom, from where data will be updated. |
CO_ReturnError_t CO_storageEeprom_init | ( | CO_storage_t * | storage, |
CO_CANmodule_t * | CANmodule, | ||
void * | storageModule, | ||
OD_entry_t * | OD_1010_StoreParameters, | ||
OD_entry_t * | OD_1011_RestoreDefaultParam, | ||
CO_storage_entry_t * | entries, | ||
uint8_t | entriesCount, | ||
uint32_t * | storageInitError ) |
Initialize data storage object (block device (eeprom) specific)
This function should be called by application after the program startup, before CO_CANopenInit(). This function initializes storage object, OD extensions on objects 1010 and 1011, reads data from file, verifies them and writes data to addresses specified inside entries. This function internally calls CO_storage_init().
storage | This object will be initialized. It must be defined by application and must exist permanently. | |
CANmodule | CAN device, for optional usage. | |
storageModule | Pointer to storage module passed to CO_eeprom functions. | |
OD_1010_StoreParameters | OD entry for 0x1010 -"Store parameters". Entry is optional, may be NULL. | |
OD_1011_RestoreDefaultParam | OD entry for 0x1011 -"Restore default parameters". Entry is optional, may be NULL. | |
entries | Pointer to array of storage entries, see CO_storage_init. | |
entriesCount | Count of storage entries, must not be larger than CO_CONFIG_STORAGE_MAX_ENTRIES_COUNT. | |
[out] | storageInitError | If function returns CO_ERROR_DATA_CORRUPT, then this variable contains a bit mask from subIndexOD values, where data was not properly initialized. If other error, then this variable contains index or erroneous entry. If there is hardware error like missing eeprom, then storageInitError is 0xFFFFFFFF and function returns CO_ERROR_DATA_CORRUPT. |
void CO_storageEeprom_auto_process | ( | CO_storage_t * | storage, |
bool_t | saveAll ) |
Automatically update data if differs inside eeprom.
Should be called cyclically by program. Each interval it updates one byte.
storage | This object |
saveAll | If true, all bytes are updated, useful on program end. |