eeprom.h
Go to the documentation of this file.
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_24XX32, 00076 EEPROM_24XX64, 00077 EEPROM_24XX128, 00078 EEPROM_24XX256, 00079 EEPROM_24XX512, 00080 EEPROM_24XX1024, 00081 EEPROM_CNT, 00082 } EepromType; 00083 00089 typedef uint8_t e2dev_addr_t; 00090 00095 typedef struct Eeprom 00096 { 00097 KBlock blk; 00098 I2c *i2c; 00099 EepromType type; 00100 e2dev_addr_t addr; 00101 bool verify; 00102 #if !CONFIG_EEPROM_DISABLE_OLD_API 00103 union { 00104 KFile fd; 00105 KFileBlock fdblk; 00106 } DEPRECATED; 00107 #endif /* !CONFIG_EEPROM_DISABLE_OLD_API */ 00108 } Eeprom; 00109 00110 #if !CONFIG_EEPROM_DISABLE_OLD_API 00111 STATIC_ASSERT(offsetof(Eeprom, fd) == offsetof(Eeprom, fdblk.fd)); 00112 #endif /* !CONFIG_EEPROM_DISABLE_OLD_API */ 00113 00117 #define KBT_EEPROM MAKE_ID('E', 'E', 'P', 'R') 00118 00122 INLINE Eeprom * EEPROM_CAST_KBLOCK(KBlock *blk) 00123 { 00124 ASSERT(blk->priv.type == KBT_EEPROM); 00125 return (Eeprom *)blk; 00126 } 00127 00129 typedef uint16_t e2addr_t; 00130 00140 #define e2addr(type, field) ((e2addr_t)&(((type *)0)->field)) 00141 00145 typedef uint16_t e2blk_size_t; 00146 00150 typedef uint32_t e2_size_t; 00151 00156 typedef struct EepromInfo 00157 { 00158 bool has_dev_addr; 00159 e2blk_size_t blk_size; 00160 e2_size_t e2_size; 00161 } EepromInfo; 00162 00163 bool eeprom_erase(Eeprom *eep, e2addr_t addr, e2_size_t count); 00164 bool eeprom_verify_4(Eeprom *eep, e2addr_t addr, const void *buf, size_t count); 00165 void eeprom_init_5(Eeprom *eep, I2c *i2c, EepromType type, e2dev_addr_t addr, bool verify); 00166 00167 #if !CONFIG_EEPROM_DISABLE_OLD_API 00168 00169 DEPRECATED INLINE bool eeprom_verify_3(Eeprom *eep, const void *buf, size_t count) 00170 { 00171 return eeprom_verify_4(eep, (e2addr_t)eep->fdblk.fd.seek_pos, buf, count); 00172 } 00173 DEPRECATED INLINE void eeprom_init_4(Eeprom *eep, EepromType type, e2dev_addr_t addr, bool verify) 00174 { 00175 eeprom_init_5(eep, &local_i2c_old_api, type, addr, verify); 00176 kfileblock_init(&eep->fdblk, &eep->blk); 00177 } 00178 #endif /* !CONFIG_EEPROM_DISABLE_OLD_API */ 00179 00180 #endif /* DRV_EEPROM_H */
![(please configure the [header_logo] section in trac.ini)](/chrome/site/bertos_logo.png)