flash25.h
Go to the documentation of this file.00001
00041 #ifndef DRV_FLASH25_H
00042 #define DRV_FLASH25_H
00043
00044 #include <cfg/compiler.h>
00045 #include "cfg/cfg_flash25.h"
00046
00047 #include <kern/kfile.h>
00048
00052 typedef uint32_t flash25Addr_t;
00053 typedef uint32_t flash25Size_t;
00054 typedef uint8_t flash25Offset_t;
00055
00059 typedef struct Flash25
00060 {
00061 KFile fd;
00062 KFile *channel;
00063 } Flash25;
00064
00068 #define KFT_FLASH25 MAKE_ID('F', 'L', '2', '5')
00069
00070
00074 INLINE Flash25 * FLASH25_CAST(KFile *fd)
00075 {
00076 ASSERT(fd->_type == KFT_FLASH25);
00077 return (Flash25 *)fd;
00078 }
00079
00088 #define FLASH25_AT25F2048 1
00089
00090 #if CONFIG_FLASH25 == FLASH25_AT25F2048
00091 #define FLASH25_MANUFACTURER_ID 0x1F // ATMEL
00092 #define FLASH25_DEVICE_ID 0x63 // Device ID
00093 #define FLASH25_PAGE_SIZE 256 // Page size in byte
00094 #define FLASH25_NUM_SECTOR 4 // Number of section in serial memory
00095 #define FLASH25_SECTOR_SIZE 65536UL // Section size in byte
00096 #define FLASH25_MEM_SIZE FLASH25_NUM_SECTOR * FLASH25_SECTOR_SIZE
00097 #define FLASH25_NUM_PAGE FLASH25_MEM_SIZE / FLASH25_PAGE_SIZE
00098 #elif
00099 #error Nothing memory defined in CONFIG_FLASH25 are support.
00100 #endif
00101
00102 #define RDY_BIT 0x1 // Statuts of write cycle
00103
00104
00108 typedef enum {
00109 FLASH25_WREN = 0x6,
00110 FLASH25_WRDI = 0x4,
00111 FLASH25_RDSR = 0x5,
00112 FLASH25_WRSR = 0x1,
00113 FLASH25_READ = 0x3,
00114 FLASH25_PROGRAM = 0x2,
00115 FLASH25_SECTORE_ERASE = 0x52,
00116 FLASH25_CHIP_ERASE = 0x62,
00117 FLASH25_RDID = 0x15
00118 } Flash25Opcode;
00119
00123 #if CONFIG_FLASH25 != FLASH25_AT25F2048
00124 #error Nothing memory defined in CONFIG_FLASH25 are support.
00125 #endif
00126
00127 typedef enum {
00128 FLASH25_SECT1 = 0x0,
00129 FLASH25_SECT2 = 0x10000,
00130 FLASH25_SECT3 = 0x20000,
00131 FLASH25_SECT4 = 0x30000,
00132 } Flash25Sector;
00133
00134 void flash25_init(Flash25 *fd, KFile *ch);
00135 void flash25_chipErase(Flash25 *fd);
00136 void flash25_sectorErase(Flash25 *fd, Flash25Sector sector);
00137 bool flash25_test(KFile *channel);
00138
00139 #endif
00140