flash25.h
Go to the documentation of this file.00001
00045 #ifndef DRV_FLASH25_H
00046 #define DRV_FLASH25_H
00047
00048 #include "cfg/cfg_flash25.h"
00049 #include <cfg/compiler.h>
00050
00051 #include <kern/kfile.h>
00052
00056 typedef uint32_t flash25Addr_t;
00057 typedef uint32_t flash25Size_t;
00058 typedef uint8_t flash25Offset_t;
00059
00063 typedef struct Flash25
00064 {
00065 KFile fd;
00066 KFile *channel;
00067 } Flash25;
00068
00072 #define KFT_FLASH25 MAKE_ID('F', 'L', '2', '5')
00073
00074
00078 INLINE Flash25 * FLASH25_CAST(KFile *fd)
00079 {
00080 ASSERT(fd->_type == KFT_FLASH25);
00081 return (Flash25 *)fd;
00082 }
00083
00093 #define FLASH25_AT25F2048 1
00094
00095 #if CONFIG_FLASH25 == FLASH25_AT25F2048
00096 #define FLASH25_MANUFACTURER_ID 0x1F // ATMEL
00097 #define FLASH25_DEVICE_ID 0x63 // Device ID
00098 #define FLASH25_PAGE_SIZE 256 // Page size in byte
00099 #define FLASH25_NUM_SECTOR 4 // Number of section in serial memory
00100 #define FLASH25_SECTOR_SIZE 65536UL // Section size in byte
00101 #define FLASH25_MEM_SIZE FLASH25_NUM_SECTOR * FLASH25_SECTOR_SIZE
00102 #define FLASH25_NUM_PAGE FLASH25_MEM_SIZE / FLASH25_PAGE_SIZE
00103 #elif
00104 #error Nothing memory defined in CONFIG_FLASH25 are support.
00105 #endif
00106
00107 #define RDY_BIT 0x1 // Statuts of write cycle
00108
00112 typedef enum {
00113 FLASH25_WREN = 0x6,
00114 FLASH25_WRDI = 0x4,
00115 FLASH25_RDSR = 0x5,
00116 FLASH25_WRSR = 0x1,
00117 FLASH25_READ = 0x3,
00118 FLASH25_PROGRAM = 0x2,
00119 FLASH25_SECTORE_ERASE = 0x52,
00120 FLASH25_CHIP_ERASE = 0x62,
00121 FLASH25_RDID = 0x15
00122 } Flash25Opcode;
00123
00127 #if CONFIG_FLASH25 != FLASH25_AT25F2048
00128 #error Nothing memory defined in CONFIG_FLASH25 are support.
00129 #endif
00130
00131 typedef enum {
00132 FLASH25_SECT1 = 0x0,
00133 FLASH25_SECT2 = 0x10000,
00134 FLASH25_SECT3 = 0x20000,
00135 FLASH25_SECT4 = 0x30000,
00136 } Flash25Sector;
00137
00138 void flash25_init(Flash25 *fd, KFile *ch);
00139 void flash25_chipErase(Flash25 *fd);
00140 void flash25_sectorErase(Flash25 *fd, Flash25Sector sector);
00141 bool flash25_test(KFile *channel);
00142
00143 #endif
00144