BeRTOS
|
00001 00066 #ifndef DRV_FLASH_H 00067 #define DRV_FLASH_H 00068 00069 #include "cfg/cfg_emb_flash.h" 00070 00071 #include <cfg/macros.h> 00072 #include <cfg/compiler.h> 00073 00074 #include <io/kblock.h> 00075 #include <io/kfile.h> 00076 #include <io/kfile_block.h> 00077 00078 #include <cpu/attr.h> 00079 00080 #if COMPILER_C99 00081 #define flash_init(...) PP_CAT(flash_init_, COUNT_PARMS(__VA_ARGS__)) (__VA_ARGS__) 00082 #else 00083 00095 #define flash_init(args...) PP_CAT(flash_init_, COUNT_PARMS(args)) (args) 00096 #endif 00097 00102 #define FLASH_WR_OK 0 ///< Write ok. 00103 #define FLASH_NOT_ERASED BV(1) ///< Flash memory was not erased before to write it. 00104 #define FLASH_WR_PROTECT BV(2) ///< Write not allowed the flash memory was protected. 00105 #define FLASH_WR_TIMEOUT BV(3) ///< Timeout while writing 00106 #define FLASH_WR_ERR BV(4) ///< Invalid command and/or a bad keywords 00107 00109 struct FlashHardware; 00110 00114 typedef struct Flash 00115 { 00116 KBlock blk; 00117 struct FlashHardware *hw; 00118 #if !CONFIG_FLASH_DISABLE_OLD_API 00119 union { 00120 KFile fd; 00121 KFileBlock fdblk; 00122 } DEPRECATED; 00123 #endif /* !CONFIG_FLASH_DISABLE_OLD_API */ 00124 } Flash; 00125 00126 /* 00127 * ID for FLASH 00128 */ 00129 #define KBT_FLASH MAKE_ID('F', 'L', 'A', 'S') 00130 00134 INLINE Flash *FLASH_CAST(KBlock *fls) 00135 { 00136 ASSERT(fls->priv.type == KBT_FLASH); 00137 return (Flash *)fls; 00138 } 00139 00140 void flash_hw_init(Flash *fls, int flags); 00141 void flash_hw_initUnbuffered(Flash *fls, int flags); 00142 00143 #include CPU_HEADER(flash) 00144 00149 #define FLASH_WRITE_ONCE BV(0) ///< Allow only one write per block. 00150 #define FLASH_UNBUFFERED BV(1) ///< Open flash memory disabling page caching, no modification and partial write are allowed. 00151 00158 #define flash_init_2(fls, flags) (flags & FLASH_UNBUFFERED) ? \ 00159 flash_hw_initUnbuffered(fls, flags) : flash_hw_init(fls, flags) 00160 00161 #if !CONFIG_FLASH_DISABLE_OLD_API 00162 INLINE DEPRECATED void flash_init_1(Flash *fls) 00163 { 00164 flash_hw_init(fls, 0); 00165 kfileblock_init(&fls->fdblk, &fls->blk); 00166 } 00167 #endif /* !CONFIG_FLASH_DISABLE_OLD_API */ 00168 00171 #endif /* DRV_FLASH_H */