Rev 1106 | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1106 | linlun | 1 | #ifndef <TEMPLATE>_EEPROM |
| 2 | #define <TEMPLATE>_EEPROM |
||
| 3 | |||
| 4 | #include "<template>.h" |
||
| 5 | // Do not change anything below this line. |
||
| 6 | // ---------------------------------------------------------------- |
||
| 7 | |||
| 8 | #include <drivers/misc/eeprom_crc8.h> |
||
| 9 | #include <avr/eeprom.h> |
||
| 10 | #define EEDATA (uint8_t*)&eeprom_<template>.Data |
||
| 11 | #define EEDATA16 (uint16_t*)&eeprom_<template>.Data |
||
| 12 | #define EEDATA_CALC_CRC eeprom_crc8((uint8_t*)&eeprom_<template>.Data,sizeof(struct <template>_Data)) |
||
| 13 | #define EEDATA_UPDATE_CRC eeprom_write_byte((uint8_t*)&eeprom_<template>.crc,eeprom_crc8((uint8_t*)&eeprom_<template>.Data,sizeof(struct <template>_Data))) |
||
| 14 | #define EEDATA_OK EEDATA_CALC_CRC == EEDATA_STORED_CRC |
||
| 15 | #define EEDATA_STORED_CRC eeprom_read_byte((uint8_t*)&eeprom_<template>.crc) |
||
| 16 | |||
| 17 | struct eeprom_<template>{ |
||
| 18 | struct <template>_Data Data; |
||
| 19 | uint8_t crc; |
||
| 20 | }; |
||
| 21 | extern struct eeprom_<template> EEMEM eeprom_<template>; |
||
| 22 | |||
| 23 | #define WITH_CRC 1 |
||
| 24 | #define WITHOUT_CRC 0 |
||
| 25 | static __inline__ void eeprom_write_byte_crc(uint8_t *__p, uint8_t __value, uint8_t crc) { |
||
| 26 | if (__value != eeprom_read_byte(__p)) |
||
| 27 | { |
||
| 28 | eeprom_write_byte(__p, __value); |
||
| 29 | if (crc == WITH_CRC) |
||
| 30 | { |
||
| 31 | EEDATA_UPDATE_CRC; |
||
| 32 | } |
||
| 33 | } |
||
| 34 | } |
||
| 35 | static __inline__ void eeprom_write_word_crc(uint16_t *__p, uint16_t __value, uint8_t crc) { |
||
| 36 | if (__value != eeprom_read_word(__p)) |
||
| 37 | { |
||
| 38 | eeprom_write_word(__p, __value); |
||
| 39 | if (crc == WITH_CRC) |
||
| 40 | { |
||
| 41 | EEDATA_UPDATE_CRC; |
||
| 42 | } |
||
| 43 | } |
||
| 44 | } |
||
| 45 | #endif |