BeRTOS
|
00001 00043 #ifndef DRV_EEPROM_H 00044 #define DRV_EEPROM_H 00045 00046 #include "cfg/cfg_eeprom.h" 00047 00048 #include <cfg/compiler.h> 00049 #include <cfg/debug.h> 00050 00051 #include <drv/i2c.h> 00052 00053 #include <io/kblock.h> 00054 #include <io/kfile.h> 00055 #include <io/kfile_block.h> 00056 00057 #include <cpu/attr.h> 00058 00059 #if COMPILER_C99 00060 #define eeprom_init(...) PP_CAT(eeprom_init ## _, COUNT_PARMS(__VA_ARGS__)) (__VA_ARGS__) 00061 #define eeprom_verify(...) PP_CAT(eeprom_verify ## _, COUNT_PARMS(__VA_ARGS__)) (__VA_ARGS__) 00062 #else 00063 #define eeprom_init(args...) PP_CAT(eeprom_init ## _, COUNT_PARMS(args)) (args) 00064 #define eeprom_verify(args...) PP_CAT(eeprom_verify ## _, COUNT_PARMS(args)) (args) 00065 #endif 00066 00067 00071 typedef enum EepromType 00072 { 00073 EEPROM_24XX08, 00074 EEPROM_24XX16, 00075 EEPROM_24XX256, 00076 EEPROM_24XX512, 00077 EEPROM_24XX1024, 00078 EEPROM_CNT, 00079 } EepromType; 00080 00086 typedef uint8_t e2dev_addr_t; 00087 00092 typedef struct Eeprom 00093 { 00094 KBlock blk; 00095 I2c *i2c; 00096 EepromType type; 00097 e2dev_addr_t addr; 00098 bool verify; 00099 #if !CONFIG_EEPROM_DISABLE_OLD_API 00100 union { 00101 KFile fd; 00102 KFileBlock fdblk; 00103 } DEPRECATED; 00104 #endif /* !CONFIG_EEPROM_DISABLE_OLD_API */ 00105 } Eeprom; 00106 00107 #if !CONFIG_EEPROM_DISABLE_OLD_API 00108 STATIC_ASSERT(offsetof(Eeprom, fd) == offsetof(Eeprom, fdblk.fd)); 00109 #endif /* !CONFIG_EEPROM_DISABLE_OLD_API */ 00110 00114 #define KBT_EEPROM MAKE_ID('E', 'E', 'P', 'R') 00115 00119 INLINE Eeprom * EEPROM_CAST_KBLOCK(KBlock *blk) 00120 { 00121 ASSERT(blk->priv.type == KBT_EEPROM); 00122 return (Eeprom *)blk; 00123 } 00124 00126 typedef uint16_t e2addr_t; 00127 00137 #define e2addr(type, field) ((e2addr_t)&(((type *)0)->field)) 00138 00142 typedef uint16_t e2blk_size_t; 00143 00147 typedef uint32_t e2_size_t; 00148 00153 typedef struct EepromInfo 00154 { 00155 bool has_dev_addr; 00156 e2blk_size_t blk_size; 00157 e2_size_t e2_size; 00158 } EepromInfo; 00159 00160 bool eeprom_erase(Eeprom *eep, e2addr_t addr, e2_size_t count); 00161 bool eeprom_verify_4(Eeprom *eep, e2addr_t addr, const void *buf, size_t count); 00162 void eeprom_init_5(Eeprom *eep, I2c *i2c, EepromType type, e2dev_addr_t addr, bool verify); 00163 00164 #if !CONFIG_EEPROM_DISABLE_OLD_API 00165 00166 DEPRECATED INLINE bool eeprom_verify_3(Eeprom *eep, const void *buf, size_t count) 00167 { 00168 return eeprom_verify_4(eep, (e2addr_t)eep->fdblk.fd.seek_pos, buf, count); 00169 } 00170 DEPRECATED INLINE void eeprom_init_4(Eeprom *eep, EepromType type, e2dev_addr_t addr, bool verify) 00171 { 00172 eeprom_init_5(eep, &local_i2c_old_api, type, addr, verify); 00173 kfileblock_init(&eep->fdblk, &eep->blk); 00174 } 00175 #endif /* !CONFIG_EEPROM_DISABLE_OLD_API */ 00176 00177 #endif /* DRV_EEPROM_H */