Subversion Repositories HomeAutomation

Rev

Blame | Last modification | View Log | SVN | RSS feed

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