df.h

Go to the documentation of this file.
00001 /*H**************************************************************************
00002 * NAME:         df.h
00003 *----------------------------------------------------------------------------
00004 * Copyright (c) 2006 Atmel.
00005 *----------------------------------------------------------------------------
00006 * RELEASE:      at90usb162-2enum-mouse_ms-1_0_1
00007 * REVISION:     1.3
00008 *----------------------------------------------------------------------------
00009 * PURPOSE:
00010 * This file contains the low-level dataflash interface.
00011 *****************************************************************************/
00012 
00013 #ifndef _DF_H_
00014 #define _DF_H_
00015 
00016 /*_____ I N C L U D E S ____________________________________________________*/
00017 
00018 #include "config.h"
00019 
00020 
00021 /*_____ M A C R O S ________________________________________________________*/
00022 
00023 #ifndef DF_SECTOR_SIZE
00024 #define DF_SECTOR_SIZE   512   //default sector size is 512 bytes
00025 #endif
00026 
00027 /* FAT Format Structure */
00028 typedef struct
00029 {
00030   Uint16 nb_cylinder;
00031   Byte   nb_head;
00032   Byte   nb_sector;
00033   Byte   nb_hidden_sector;
00034   Byte   nb_sector_per_cluster;
00035 } s_format;
00036 
00037 #define MEM_BSY       0
00038 #define MEM_OK        1
00039 #define MEM_KO        2
00040 
00041 /*----- DataFlash definition -----*/
00042 #define DF_MSK_DENSITY    ((Byte)0x3C)      /* status density mask */
00043 #define DF_MSK_BIT_BUSY   ((Byte)0x80)
00044 #define DF_MEM_BUSY       ((Byte)0x00)
00045 
00046 #define DF_RD_STATUS      ((Byte)0xD7)      /* read status cmd */
00047 #define DF_PG_ERASE       ((Byte)0x81)      /* page erase cmd  */
00048 #define DF_BK_ERASE       ((Byte)0x50)      /* block erase cmd */
00049 
00050 #define DF_WR_BUF_1       ((Byte)0x84)      /* write buffer 1 cmd */
00051 #define DF_WR_BUF_2       ((Byte)0x87)      /* write buffer 2 cmd */
00052 #define DF_B1_MAIN        ((Byte)0x83)      /* buffer 1 to main program with erase cmd */
00053 #define DF_B2_MAIN        ((Byte)0x86)      /* buffer 2 to main program with erase cmd */
00054 
00055 #define DF_RD_MAIN        ((Byte)0xD2)      /* main memory page read cmd */
00056 #define DF_TF_BUF_1       ((Byte)0x53)      /* main memory page to buffer 1 transfer cmd */
00057 #define DF_TF_BUF_2       ((Byte)0x55)      /* main memory page to buffer 2 transfer cmd */
00058 #define DF_RD_BUF_1       ((Byte)0xD4)      /* buffer 1 read cmd */
00059 #define DF_RD_BUF_2       ((Byte)0xD6)      /* buffer 2 read cmd */
00060 
00061 
00062 /* Memory Size based on 512 bytes block size */
00063 #define DF_SIZE_4MB         ((Uint32)(8192 - 1))
00064 #define DF_SIZE_8MB         ((Uint32)(16384 - 1))
00065 #define DF_SIZE_16MB        ((Uint32)(32768 - 1))
00066 #define DF_SIZE_32MB        ((Uint32)(65536 - 1))
00067 #define DF_SIZE_64MB        ((Uint32)(131072 - 1))
00068 
00069 #define DF_4MB            ((Byte)0)
00070 #define DF_8MB            ((Byte)1)
00071 #define DF_16MB           ((Byte)2)
00072 #define DF_32MB           ((Byte)3)
00073 #define DF_64MB           ((Byte)4)
00074 
00075 
00076 /* BUSY Management and Memory Selection */
00077 
00078 /* The variable "df_mem_busy" can contain the state of 4 dataflash */
00079 #define  df_set_busy(i)       (df_mem_busy |= (1<<i))
00080 #define  df_release_busy(i)   (df_mem_busy &= ~(1<<i))
00081 #define  is_df_busy(i)        (((df_mem_busy&(1<<i)) != 0) ? TRUE : FALSE)
00082 
00083 /* The variable "df_select" contains the current number of the memory addressed */
00084 #define  MEM_DF0           0x00
00085 #define  MEM_DF1           0x01
00086 #define  MEM_DF2           0x02
00087 #define  MEM_DF3           0x03
00088 
00089 
00090 /*_____ D E F I N I T I O N ________________________________________________*/
00091 
00092 #ifdef DF_4_MB            /* AT45DB321 memories */
00093   #define DF_SHFT_DFIDX   (22)              /* RShift to apply to an absolute
00094                                              * Byte address to get the DF idx */
00095   #define DF_DENSITY      ((Byte)0x34)
00096   #define DF_PG_BUF_1     ((Byte)0x82)      /* main memory program through buf1 */
00097   #define DF_PG_BUF_2     ((Byte)0x85)      /* main memory program through buf2 */
00098   #define DF_PAGE_SIZE    (512)             /* page length */
00099   #define DF_PAGE_MASK    ((Byte)0x01)      /* mask MSB page bits */
00100   #define DF_SHFT_B1      (1)
00101   #define DF_SHFT_B2      (7)
00102 #endif
00103 
00104 #ifdef DF_8_MB             /* AT45DB642 memories */
00105   #define DF_SHFT_DFIDX   (23)             /* RShift to apply to an absolute
00106                                              * Byte address to get the DF idx */
00107   #define DF_DENSITY      ((Byte)0x3C)
00108   #define DF_PG_BUF_1     ((Byte)0x82)      /* fast main memory program through buf1 */
00109   #define DF_PG_BUF_2     ((Byte)0x85)      /* fast main memory program through buf2 */
00110   #define DF_PAGE_SIZE    (1024)            /* page length */
00111   #define DF_PAGE_MASK    ((Byte)0x03)      /* mask MSB page bits */
00112   #define DF_SHFT_B1      (1)
00113   #define DF_SHFT_B2      (7)
00114 #endif
00115 
00116 
00117 /*_____ D E C L A R A T I O N ______________________________________________*/
00118 
00119 bit     df_init (void);
00120 bit     df_mem_check(void);
00121 bit     df_read_open (Uint32);
00122 void    df_read_close (void);
00123 bit     df_write_open (Uint32);
00124 void    df_write_close (void);
00125 
00127 bit     df_write_sector (Uint16);
00128 bit     df_read_sector (Uint16);
00129 
00131 bit     df_read_sector_2_ram(U8 *ram);
00132 bit     df_write_sector_from_ram(U8 *ram);
00133 
00134 
00135 s_format  * df_format (void);
00136 
00137 
00138 /* Disk size: number of block - 1 */
00139 #define Df_disk_size()            ((Uint32)(DF_DISK_SIZE))
00140 #define Df_disk_size_0()          ((Byte)(Df_disk_size() >> 24))
00141 #define Df_disk_size_1()          ((Byte)(Df_disk_size() >> 16))
00142 #define Df_disk_size_2()          ((Byte)(Df_disk_size() >> 8))
00143 #define Df_disk_size_3()          ((Byte)(Df_disk_size()))
00144 
00145 /* Block size: size of a block in byte */
00146 #define Df_block_size()           ((Uint32)512)
00147 #define Df_block_size_0()         ((Byte)(Df_block_size() >> 24))
00148 #define Df_block_size_1()         ((Byte)(Df_block_size() >> 16))
00149 #define Df_block_size_2()         ((Byte)(Df_block_size() >> 8))
00150 #define Df_block_size_3()         ((Byte)(Df_block_size()))
00151 
00152 
00153 #endif  /* _DF_H_ */
00154 
00155 

Generated on Fri Jun 15 14:07:32 2007 for Atmel by  doxygen 1.5.1-p1