Rev 1062 | Rev 1125 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1062 | Rev 1106 | ||
|---|---|---|---|
| Line 24... | Line 24... | ||
| 24 | struct <template>_Data{ |
24 | struct <template>_Data{ |
| 25 | ///TODO: Define EEPROM variables needed by the module |
25 | ///TODO: Define EEPROM variables needed by the module |
| 26 | uint8_t x; |
26 | uint8_t x; |
| 27 | uint16_t y; |
27 | uint16_t y; |
| 28 | }; |
28 | }; |
| - | 29 | #endif |
|
| 29 | 30 | ||
| 30 | // Do not change anything below this line. |
- | |
| 31 | // ---------------------------------------------------------------- |
- | |
| 32 | - | ||
| 33 | #include <drivers/misc/eeprom_crc8.h> |
- | |
| 34 | #include <avr/eeprom.h> |
- | |
| 35 | #define EEDATA (uint8_t*)&eeprom_<template>.Data |
- | |
| 36 | #define EEDATA16 (uint16_t*)&eeprom_<template>.Data |
- | |
| 37 | #define EEDATA_CALC_CRC eeprom_crc8((uint8_t*)&eeprom_<template>.Data,sizeof(struct <template>_Data)) |
- | |
| 38 | #define EEDATA_UPDATE_CRC eeprom_write_byte((uint8_t*)&eeprom_<template>.crc,eeprom_crc8((uint8_t*)&eeprom_<template>.Data,sizeof(struct <template>_Data))) |
- | |
| 39 | #define EEDATA_OK EEDATA_CALC_CRC == EEDATA_STORED_CRC |
- | |
| 40 | #define EEDATA_STORED_CRC eeprom_read_byte((uint8_t*)&eeprom_<template>.crc) |
- | |
| 41 | - | ||
| 42 | struct eeprom_<template>{ |
- | |
| 43 | struct <template>_Data Data; |
- | |
| 44 | uint8_t crc; |
- | |
| 45 | }; |
- | |
| 46 | extern struct eeprom_<template> EEMEM eeprom_<template>; |
- | |
| 47 | - | ||
| 48 | #define WITH_CRC 1 |
- | |
| 49 | #define WITHOUT_CRC 0 |
- | |
| 50 | static __inline__ void eeprom_write_byte_crc(uint8_t *__p, uint8_t __value, uint8_t crc) { |
- | |
| 51 | if (__value != eeprom_read_byte(__p)) |
- | |
| 52 | { |
- | |
| 53 | eeprom_write_byte(__p, __value); |
- | |
| 54 | if (crc == WITH_CRC) |
- | |
| 55 | { |
- | |
| 56 | EEDATA_UPDATE_CRC; |
- | |
| 57 | } |
- | |
| 58 | } |
- | |
| 59 | } |
- | |
| 60 | static __inline__ void eeprom_write_word_crc(uint16_t *__p, uint16_t __value, uint8_t crc) { |
- | |
| 61 | if (__value != eeprom_read_word(__p)) |
- | |
| 62 | { |
- | |
| 63 | eeprom_write_word(__p, __value); |
- | |
| 64 | if (crc == WITH_CRC) |
- | |
| 65 | { |
- | |
| 66 | EEDATA_UPDATE_CRC; |
- | |
| 67 | } |
- | |
| 68 | } |
- | |
| 69 | } |
- | |
| 70 | #endif |
- | |
| 71 | #endif // <TEMPLATE> |
31 | #endif // <TEMPLATE> |