Rev 1106 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1106 | Rev 1557 | ||
|---|---|---|---|
| Line 7... | Line 7... | ||
| 7 | 7 | ||
| 8 | #include <drivers/misc/eeprom_crc8.h> |
8 | #include <drivers/misc/eeprom_crc8.h> |
| 9 | #include <avr/eeprom.h> |
9 | #include <avr/eeprom.h> |
| 10 | #define EEDATA (uint8_t*)&eeprom_<template>.Data |
10 | #define EEDATA (uint8_t*)&eeprom_<template>.Data |
| 11 | #define EEDATA16 (uint16_t*)&eeprom_<template>.Data |
11 | #define EEDATA16 (uint16_t*)&eeprom_<template>.Data |
| - | 12 | #define EEDATA32 (uint32_t*)&eeprom_<template>.Data |
|
| 12 | #define EEDATA_CALC_CRC eeprom_crc8((uint8_t*)&eeprom_<template>.Data,sizeof(struct <template>_Data)) |
13 | #define EEDATA_CALC_CRC eeprom_crc8((uint8_t*)&eeprom_<template>.Data,sizeof(struct <template>_Data)) |
| - | 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 |
|
| 13 | #define EEDATA_UPDATE_CRC eeprom_write_byte((uint8_t*)&eeprom_<template>.crc,eeprom_crc8((uint8_t*)&eeprom_<template>.Data,sizeof(struct <template>_Data))) |
18 | #define EEDATA_UPDATE_CRC eeprom_write_byte((uint8_t*)&eeprom_<template>.crc,eeprom_crc8((uint8_t*)&eeprom_<template>.Data,sizeof(struct <template>_Data))) |
| - | 19 | #endif |
|
| - | 20 | ||
| 14 | #define EEDATA_OK EEDATA_CALC_CRC == EEDATA_STORED_CRC |
21 | #define EEDATA_OK EEDATA_CALC_CRC == EEDATA_STORED_CRC |
| 15 | #define EEDATA_STORED_CRC eeprom_read_byte((uint8_t*)&eeprom_<template>.crc) |
22 | #define EEDATA_STORED_CRC eeprom_read_byte((uint8_t*)&eeprom_<template>.crc) |
| 16 | 23 | ||
| 17 | struct eeprom_<template>{ |
24 | struct eeprom_<template>{ |
| 18 | struct <template>_Data Data; |
25 | struct <template>_Data Data; |
| 19 | uint8_t crc; |
26 | uint8_t crc; |
| 20 | }; |
27 | }; |
| 21 | extern struct eeprom_<template> EEMEM eeprom_<template>; |
28 | extern struct eeprom_<template> EEMEM eeprom_<template>; |
| 22 | 29 | ||
| 23 | #define WITH_CRC 1 |
30 | #define WITH_CRC 1 |
| 24 | #define WITHOUT_CRC 0 |
31 | #define WITHOUT_CRC 0 |
| - | 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) |
|
| - | 35 | static __inline__ void eeprom_write_byte_crc(uint8_t *__p, uint8_t __value, uint8_t crc) { |
|
| - | 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 |
|
| 25 | static __inline__ void eeprom_write_byte_crc(uint8_t *__p, uint8_t __value, uint8_t crc) { |
57 | static __inline__ void eeprom_write_byte_crc(uint8_t *__p, uint8_t __value, uint8_t crc) { |
| 26 | if (__value != eeprom_read_byte(__p)) |
58 | if (__value != eeprom_read_byte(__p)) |
| 27 | { |
59 | { |
| 28 | eeprom_write_byte(__p, __value); |
60 | eeprom_write_byte(__p, __value); |
| 29 | if (crc == WITH_CRC) |
61 | if (crc == WITH_CRC) |
| 30 | { |
62 | { |
| 31 | EEDATA_UPDATE_CRC; |
63 | EEDATA_UPDATE_CRC; |
| 32 | } |
64 | } |
| 33 | } |
65 | } |
| 34 | } |
66 | } |
| 35 | static __inline__ void eeprom_write_word_crc(uint16_t *__p, uint16_t __value, uint8_t crc) { |
67 | static __inline__ void eeprom_write_word_crc(uint16_t *__p, uint16_t __value, uint8_t crc) { |
| 36 | if (__value != eeprom_read_word(__p)) |
68 | if (__value != eeprom_read_word(__p)) |
| 37 | { |
69 | { |
| Line 40... | Line 72... | ||
| 40 | { |
72 | { |
| 41 | EEDATA_UPDATE_CRC; |
73 | EEDATA_UPDATE_CRC; |
| 42 | } |
74 | } |
| 43 | } |
75 | } |
| 44 | } |
76 | } |
| - | 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 | ||
| 45 | #endif |
89 | #endif |