dataflash.h

Go to the documentation of this file.
00001 
00041 #ifndef DRV_DATAFLASH_H
00042 #define DRV_DATAFLASH_H
00043 
00044 #include <kern/kfile.h>
00045 #include <cfg/compiler.h>
00046 
00047 #include <appconfig.h>
00048 
00049 
00054 typedef uint32_t dataflash_page_t;
00055 typedef uint32_t dataflash_offset_t;
00056 typedef uint32_t dataflash_size_t;
00057 /*\}*/
00058 
00062 typedef void (dataflash_setReset_t)(bool);
00063 typedef void (dataflash_setCS_t)(bool);
00064 
00073 typedef enum DataflashType
00074 {
00075     DFT_AT45DB041B,
00076     DFT_AT45DB081D,
00077     DFT_AT45DB161D,
00078     DFT_CNT
00079 } DataflashType;
00080 
00081 
00085 typedef struct KFileDataflash
00086 {
00087     KFile fd;                       
00088     KFile *channel;                 
00089     DataflashType dev;              
00090     dataflash_page_t current_page;  
00091     bool page_dirty;                
00092     dataflash_setReset_t *setReset; 
00093     dataflash_setCS_t *setCS;       
00094 } KFileDataflash;
00095 
00099 #define KFT_DATAFLASH MAKE_ID('D', 'F', 'L', 'H')
00100 
00104 INLINE KFileDataflash * KFILEDATAFLASH(KFile *fd)
00105 {
00106     ASSERT(fd->_type == KFT_DATAFLASH);
00107     return (KFileDataflash *)fd;
00108 }
00109 
00110 #define RESET_PULSE_WIDTH     10 
00111 #define BUSY_BIT            0x80 
00112 #define CMP_BIT             0x40 
00113 
00114 
00119 #define GET_ID_DESITY_DEVICE(reg_stat) (((reg_stat) & 0x3C) >> 2)
00120 
00124 typedef enum DataFlashOpcode {
00129     DFO_READ_FLASH_MEM_BYTE_D  = 0x0B, 
00130     DFO_READ_FLASH_MEM_BYTE_B  = 0xE8, 
00131 
00132     DFO_READ_FLASH_MEM       = 0xD2, 
00133     DFO_READ_BUFF1           = 0xD4, 
00134     DFO_READ_BUFF2           = 0xD6, 
00135     /* \}*/
00136 
00141     DFO_WRITE_BUFF1          =  0x84, 
00142     DFO_WRITE_BUFF2          =  0x87, 
00143     DFO_WRITE_BUFF1_TO_MEM_E =  0x83, 
00144     DFO_WRITE_BUFF2_TO_MEM_E =  0x86, 
00145     DFO_WRITE_BUFF1_TO_MEM   =  0x88, 
00146     DFO_WRITE_BUFF2_TO_MEM   =  0x89, 
00147     DFO_ERASE_PAGE           =  0x81, 
00148     DFO_ERASE_BLOCK          =  0x50, 
00149     DFO_ERASE_SECTOR         =  0x7C, 
00150     DFO_WRITE_MEM_TR_BUFF1   =  0x82, 
00151     DFO_WRITE_MEM_TR_BUFF2   =  0x85, 
00152     /* \}*/
00153 
00158     DFO_MOV_MEM_TO_BUFF1     =  0x53, 
00159     DFO_MOV_MEM_TO_BUFF2     =  0x55, 
00160     DFO_CMP_MEM_TO_BUFF1     =  0x60, 
00161     DFO_CMP_MEM_TO_BUFF2     =  0x61, 
00162     DFO_ARW_MEM_TR_BUFF1     =  0x58, 
00163     DFO_ARW_MEM_TR_BUFF2     =  0x59, 
00164     DFO_PWR_DOWN             =  0xB9, 
00165     DFO_RESUME_PWR_DOWN      =  0xAB, 
00166     DFO_READ_STATUS          =  0xD7, 
00167     DFO_ID_DEV               =  0x9F  
00168     /* \}*/
00169 } DataFlashOpcode;
00170 
00171 
00175 typedef struct DataflashInfo
00176 {
00177     uint8_t density_id;       
00178     dataflash_size_t page_size;       
00179     uint8_t page_bits;        
00180     uint16_t page_cnt;        
00181     DataFlashOpcode read_cmd; 
00182 } DataflashInfo;
00183 
00184 
00185 bool dataflash_init(KFileDataflash *fd, KFile *ch, DataflashType type, dataflash_setCS_t *setCS, dataflash_setReset_t *setReset);
00186 
00187 #endif /* DRV_DATAFLASH_H */