X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;ds=sidebyside;f=bertos%2Fdrv%2Fflash.h;h=eccaf7519a6ec20e8baec1a820aadc324dc2580d;hb=42621a35d4428a3e73441fe91ccfd502992233ec;hp=eda1e985979d1c8c822f5a7857d0ef9cd1f4d63a;hpb=cb5ac008ef47b00966b573c2df2c1eeacf452b98;p=bertos.git diff --git a/bertos/drv/flash.h b/bertos/drv/flash.h index eda1e985..eccaf751 100644 --- a/bertos/drv/flash.h +++ b/bertos/drv/flash.h @@ -36,74 +36,87 @@ * \author Daniele Basile * * $WIZ$ module_name = "flash" -* $WIZ$ module_depends = "kfile" +* $WIZ$ module_depends = "kfile", "kfile_block", "kblock" +* $WIZ$ module_configuration = "bertos/cfg/cfg_emb_flash.h" */ #ifndef DRV_FLASH_H #define DRV_FLASH_H +#include "cfg/cfg_emb_flash.h" + #include -#include +#include +#include +#include +#include -#include CPU_HEADER(flash) +#include + +#if COMPILER_C99 + #define flash_init(...) PP_CAT(flash_init ## _, COUNT_PARMS(__VA_ARGS__)) (__VA_ARGS__) +#else + #define flash_init(args...) PP_CAT(flash_init ## _, COUNT_PARMS(args)) (args) +#endif + +/* + * Embedded flash error flags + */ +#define FLASH_WR_OK 0 ///< Write ok. +#define FLASH_NOT_ERASED BV(1) ///< Flash memory was not erased before to write it. +#define FLASH_WR_PROTECT BV(2) ///< Write not allowed the flash memory was protected. +#define FLASH_WR_TIMEOUT BV(3) ///< Timeout while writing +#define FLASH_WR_ERR BV(4) ///< Invalid command and/or a bad keywords + +struct FlashHardware; /** -* EmbFlash KFile context structure. -*/ + * EmbFlash KFile context structure. + */ typedef struct Flash { - /** - * File descriptor. - */ - KFile fd; - - /** - * Flag for checking if current page is modified. - */ - bool page_dirty; - - /** - * Current buffered page. - */ - page_t curr_page; - - /** - * Temporary buffer cointaing data block to - * write on flash. - */ - uint8_t page_buf[FLASH_PAGE_SIZE]; + KBlock blk; + struct FlashHardware *hw; + #if !CONFIG_FLASH_DISABLE_OLD_API + union { + KFile fd; + KFileBlock fdblk; + } DEPRECATED; + #endif /* !CONFIG_FLASH_DISABLE_OLD_API */ } Flash; /** -* ID for FLASH -*/ -#define KFT_FLASH MAKE_ID('F', 'L', 'A', 'S') + * ID for FLASH + */ +#define KBT_FLASH MAKE_ID('F', 'L', 'A', 'S') /** * Convert + ASSERT from generic KFile to Flash. */ -INLINE Flash * FLASH_CAST(KFile *fd) +INLINE Flash *FLASH_CAST(KBlock *fls) { - ASSERT(fd->_type == KFT_FLASH); - return (Flash *)fd; + ASSERT(fls->priv.type == KBT_FLASH); + return (Flash *)fls; } +void flash_hw_init(Flash *fls, int flags); +void flash_hw_initUnbuffered(Flash *fls, int flags); -MOD_DEFINE(flash); +#include CPU_HEADER(flash) -/** - * - * Initialize PWM hw. - */ -INLINE void flash_init(Flash *fd) -{ - flash_hw_init(fd); +#define flash_init_2(fls, flags) (flags & KB_OPEN_UNBUFF) ? \ + flash_hw_initUnbuffered(fls, flags) : flash_hw_init(fls, flags) - MOD_INIT(flash); +#if !CONFIG_FLASH_DISABLE_OLD_API +INLINE DEPRECATED void flash_init_1(Flash *fls) +{ + flash_hw_init(fls, 0); + kfileblock_init(&fls->fdblk, &fls->blk); } +#endif /* !CONFIG_FLASH_DISABLE_OLD_API */ - +#include CPU_HEADER(flash) #endif /* DRV_FLASH_H */