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 |
||
| 1557 | arune | 12 | #define EEDATA32 (uint32_t*)&eeprom_<template>.Data |
| 1106 | linlun | 13 | #define EEDATA_CALC_CRC eeprom_crc8((uint8_t*)&eeprom_<template>.Data,sizeof(struct <template>_Data)) |
| 1557 | arune | 14 | |
| 15 | #if ((__AVR_LIBC_MAJOR__ == 1 && __AVR_LIBC_MINOR__ == 6 && __AVR_LIBC_REVISION__ >= 7)||(__AVR_LIBC_MAJOR__ == 1 && __AVR_LIBC_MINOR__ > 6)||__AVR_LIBC_MAJOR__ > 1) |
||
| 16 | #define EEDATA_UPDATE_CRC eeprom_update_byte((uint8_t*)&eeprom_<template>.crc,eeprom_crc8((uint8_t*)&eeprom_<template>.Data,sizeof(struct <template>_Data))) |
||
| 17 | #else |
||
| 1106 | linlun | 18 | #define EEDATA_UPDATE_CRC eeprom_write_byte((uint8_t*)&eeprom_<template>.crc,eeprom_crc8((uint8_t*)&eeprom_<template>.Data,sizeof(struct <template>_Data))) |
| 1557 | arune | 19 | #endif |
| 20 | |||
| 1106 | linlun | 21 | #define EEDATA_OK EEDATA_CALC_CRC == EEDATA_STORED_CRC |
| 22 | #define EEDATA_STORED_CRC eeprom_read_byte((uint8_t*)&eeprom_<template>.crc) |
||
| 23 | |||
| 24 | struct eeprom_<template>{ |
||
| 25 | struct <template>_Data Data; |
||
| 26 | uint8_t crc; |
||
| 27 | }; |
||
| 28 | extern struct eeprom_<template> EEMEM eeprom_<template>; |
||
| 29 | |||
| 30 | #define WITH_CRC 1 |
||
| 31 | #define WITHOUT_CRC 0 |
||
| 1557 | arune | 32 | |
| 33 | |||
| 34 | #if ((__AVR_LIBC_MAJOR__ == 1 && __AVR_LIBC_MINOR__ == 6 && __AVR_LIBC_REVISION__ >= 7)||(__AVR_LIBC_MAJOR__ == 1 && __AVR_LIBC_MINOR__ > 6)||__AVR_LIBC_MAJOR__ > 1) |
||
| 1106 | linlun | 35 | static __inline__ void eeprom_write_byte_crc(uint8_t *__p, uint8_t __value, uint8_t crc) { |
| 1557 | arune | 36 | eeprom_update_byte(__p, __value); |
| 37 | if (crc == WITH_CRC) |
||
| 38 | { |
||
| 39 | EEDATA_UPDATE_CRC; |
||
| 40 | } |
||
| 41 | } |
||
| 42 | static __inline__ void eeprom_write_word_crc(uint16_t *__p, uint16_t __value, uint8_t crc) { |
||
| 43 | eeprom_update_word(__p, __value); |
||
| 44 | if (crc == WITH_CRC) |
||
| 45 | { |
||
| 46 | EEDATA_UPDATE_CRC; |
||
| 47 | } |
||
| 48 | } |
||
| 49 | static __inline__ void eeprom_write_dword_crc(uint32_t *__p, uint32_t __value, uint8_t crc) { |
||
| 50 | eeprom_update_dword(__p, __value); |
||
| 51 | if (crc == WITH_CRC) |
||
| 52 | { |
||
| 53 | EEDATA_UPDATE_CRC; |
||
| 54 | } |
||
| 55 | } |
||
| 56 | #else |
||
| 57 | static __inline__ void eeprom_write_byte_crc(uint8_t *__p, uint8_t __value, uint8_t crc) { |
||
| 1106 | linlun | 58 | if (__value != eeprom_read_byte(__p)) |
| 59 | { |
||
| 60 | eeprom_write_byte(__p, __value); |
||
| 61 | if (crc == WITH_CRC) |
||
| 62 | { |
||
| 63 | EEDATA_UPDATE_CRC; |
||
| 64 | } |
||
| 65 | } |
||
| 66 | } |
||
| 67 | static __inline__ void eeprom_write_word_crc(uint16_t *__p, uint16_t __value, uint8_t crc) { |
||
| 68 | if (__value != eeprom_read_word(__p)) |
||
| 69 | { |
||
| 70 | eeprom_write_word(__p, __value); |
||
| 71 | if (crc == WITH_CRC) |
||
| 72 | { |
||
| 73 | EEDATA_UPDATE_CRC; |
||
| 74 | } |
||
| 75 | } |
||
| 76 | } |
||
| 1557 | arune | 77 | static __inline__ void eeprom_write_dword_crc(uint32_t *__p, uint32_t __value, uint8_t crc) { |
| 78 | if (__value != eeprom_read_dword(__p)) |
||
| 79 | { |
||
| 80 | eeprom_write_dword(__p, __value); |
||
| 81 | if (crc == WITH_CRC) |
||
| 82 | { |
||
| 83 | EEDATA_UPDATE_CRC; |
||
| 84 | } |
||
| 85 | } |
||
| 86 | } |
||
| 87 | #endif |
||
| 88 | |||
| 89 | #endif |