OD storage
socketCAN

## Files

file | CO_OD_storage.h
| CANopen Object Dictionary storage object for Linux SocketCAN.

## Data Structures

struct | CO_OD_storage_t
| Object Dictionary storage object. More...

## Functions

CO_SDO_abortCode_t | CO_ODF_1010 (CO_ODF_arg_t *ODF_arg)
| Callback for use inside CO_OD_configure() function for OD object 1010.
CO_SDO_abortCode_t | CO_ODF_1011 (CO_ODF_arg_t *ODF_arg)
| Callback for use inside CO_OD_configure() function for OD object 1011.
int | CO_OD_storage_saveSecure (uint8_t *odAddress, uint32_t odSize, char *filename)
| Save memory block to a file. More...
int | CO_OD_storage_restoreSecure (char *filename)
| Remove OD storage file. More...
CO_ReturnError_t | CO_OD_storage_init (CO_OD_storage_t *odStor, uint8_t *odAddress, uint32_t odSize, char *filename)
| Initialize OD storage object and load data from file. More...
CO_ReturnError_t | CO_OD_storage_autoSave (CO_OD_storage_t *odStor, uint32_t timer1usDiff, uint32_t delay_us)
| Automatically save memory block if differs from file. More...
void | CO_OD_storage_autoSaveClose (CO_OD_storage_t *odStor)
| Closes file opened by CO_OD_storage_autoSave. More...

## Detailed Description

Object Dictionary storage implementation for CANopenNode on Linux

## Function Documentation

## CO_OD_storage_saveSecure()

int CO_OD_storage_saveSecure | ( | uint8_t * | odAddress,
|  | uint32_t | odSize,
|  | char * | filename
| ) |  |

Save memory block to a file.

Function renames current file to filename.old, copies contents from odAddress to filename, adds two bytes of CRC code. It then verifies the written file and in case of errors sets back the old file and returns error.

Function is used with CANopen OD object at index 1010.

Parameters

  odAddress | Address of the memory block, which will be stored.
  odSize | Size of the above memory block.
  filename | Name of the file, where data will be stored.

Returns
  0 on success, -1 on error.

## CO_OD_storage_restoreSecure()

int CO_OD_storage_restoreSecure | ( | char * | filename | ) |

Remove OD storage file.

Function renames current file to filename.old, then creates empty file and writes two bytes "-\n" to it. When program will start next time, default values are used for Object Dictionary. In case of error in renaming to .old it keeps the original file and returns error.

Writing data to file is secured with mutex CO_LOCK_OD.

Function is used with CANopen OD object at index 1011.

Parameters

  filename | Name of the file.

Returns
  0 on success, -1 on error.

## CO_OD_storage_init()

CO_ReturnError_t CO_OD_storage_init | ( | CO_OD_storage_t * | odStor,
|  | uint8_t * | odAddress,
|  | uint32_t | odSize,
|  | char * | filename
| ) |  |

Initialize OD storage object and load data from file.

Called after program startup. Load storage file and copy data to Object Dictionary variables.

Parameters

  odStor | This object will be initialized.
  odAddress | Address of the memory block from Object dictionary, where data will be copied.
  odSize | Size of the above memory block.
  filename | Name of the file, where data are stored.

Returns
  CO_ReturnError_t: CO_ERROR_NO, CO_ERROR_DATA_CORRUPT (Data in file corrupt), CO_ERROR_CRC (CRC from MBR does not match the CRC of OD_ROM block in file), CO_ERROR_ILLEGAL_ARGUMENT or CO_ERROR_OUT_OF_MEMORY (malloc failed).

## CO_OD_storage_autoSave()

CO_ReturnError_t CO_OD_storage_autoSave | ( | CO_OD_storage_t * | odStor,
|  | uint32_t | timer1usDiff,
|  | uint32_t | delay_us
| ) |  |

Automatically save memory block if differs from file.

Should be called cyclically by program. It first verifies, if memory block differs from file and if it does, it saves it to file with two additional CRC bytes. File remains opened.

Parameters

  odStor | OD storage object.
  timer1usDiff | Time difference in microseconds since last call.
  delay_us | Delay (inhibit) time between writes to disk in microseconds (60000 for example).

Returns
  CO_ReturnError_t: CO_ERROR_NO, CO_ERROR_DATA_CORRUPT (Data in file corrupt), CO_ERROR_ILLEGAL_ARGUMENT or CO_ERROR_OUT_OF_MEMORY (malloc failed).

## CO_OD_storage_autoSaveClose()

void CO_OD_storage_autoSaveClose | ( | CO_OD_storage_t * | odStor | ) |

Closes file opened by CO_OD_storage_autoSave.

Parameters

  odStor | OD storage object.