nf_mngt.h

Go to the documentation of this file.
00001 /*This file has been prepared for Doxygen automatic documentation generation.*/
00015 
00016 /* Copyright (c) 2007, Atmel Corporation All rights reserved.
00017  *
00018  * Redistribution and use in source and binary forms, with or without
00019  * modification, are permitted provided that the following conditions are met:
00020  *
00021  * 1. Redistributions of source code must retain the above copyright notice,
00022  * this list of conditions and the following disclaimer.
00023  *
00024  * 2. Redistributions in binary form must reproduce the above copyright notice,
00025  * this list of conditions and the following disclaimer in the documentation
00026  * and/or other materials provided with the distribution.
00027  *
00028  * 3. The name of ATMEL may not be used to endorse or promote products derived
00029  * from this software without specific prior written permission.
00030  *
00031  * THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED
00032  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00033  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND
00034  * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
00035  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00036  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00037  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00038  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00039  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00040  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00041  */
00042 
00043 #ifndef _NF_MNGT_H_
00044 #define _NF_MNGT_H_
00045 
00046 //_____ I N C L U D E S ____________________________________________________
00047 
00048 #include "config.h"
00049 #include "conf_nf.h"
00050 #include "nf.h"
00051 #include "modules/control_access/ctrl_status.h"
00052 #include "nf_drv.h"
00053 
00054 //_____ M A C R O S ________________________________________________________
00055 
00056 //_____ D E C L A R A T I O N ______________________________________________
00057 
00058 #define NF_BLK_RCV_NO_RECOVERY        0xA5
00059 #define NF_BLK_RCV_PENDING_RECOVERY   0x5A
00060 
00061 #define NF_LOW_N_FREE_THRESHOLD      5     // Min number of free blocks, otherwize the memory need to be reformatted
00062 
00063 #if (NF_N_DEVICES==1)
00064 #  define NF_SHIFT_N_DEVICES           0 // (1<<n) Number of devices
00065 
00066 #elif (NF_N_DEVICES==2)
00067 #  define NF_SHIFT_N_DEVICES           1 // (1<<n) Number of devices
00068 
00069 #elif (NF_N_DEVICES==4)
00070 #  define NF_SHIFT_N_DEVICES           2 // (1<<n) Number of devices
00071 #endif
00072 
00073 #if (NF_GENERIC_DRIVER==(TRUE))
00074 #  define NF_PAGE_BUFFER_SIZE         2048
00075 #else
00076 //#  define NF_PAGE_BUFFER_SIZE         (1L<<NF_SHIFT_PAGE_BYTE)
00077 #  define NF_PAGE_BUFFER_SIZE         2048
00078 #endif
00079 #define NF_FULL_PAGE_BUFFER_SIZE    ( (NF_PAGE_BUFFER_SIZE) + (NF_PAGE_BUFFER_SIZE)/32 )
00080 #define NF_SHIFT_SUBLUT_PHYS      ( (G_SHIFT_PAGE_BYTE)-1 )        // (1<<n) size of sublut, unit in physical block
00081 #define NF_SUBLUT_SIZE            ( 1L<<(NF_SHIFT_SUBLUT_PHYS) )   // size of sublut, unit in physical block
00082 
00083 
00084 #if (NF_AUTO_DETECT_2KB==TRUE)
00085 #  define NF_N_MAX_BLOCKS    (8*1024)  // Allow 1GByte for 2kB-NF
00086 #  define N_SUBLUT    (NF_N_DEVICES*NF_N_MAX_BLOCKS/(512/2))
00087 
00088 #elif (NF_AUTO_DETECT_512B==TRUE)
00089 #  define NF_N_MAX_BLOCKS    (8*1024)  // Allow 128MB for 512B-NF
00090 #  define N_SUBLUT    (NF_N_DEVICES*NF_N_MAX_BLOCKS/(512/2))
00091 
00092 #else
00093 #  if (NF_GENERIC_DRIVER==(TRUE))
00094 #     define N_SUBLUT    (NF_N_DEVICES*NF_N_BLOCKS/(512/2))     To check...
00095 #  else
00096 #     define N_SUBLUT    (NF_N_DEVICES*NF_N_BLOCKS/(1L<<(NF_SHIFT_PAGE_BYTE-1)))
00097 #  endif
00098 #endif
00099 
00100 #if (NF_GENERIC_DRIVER==TRUE)
00101 #  define S_SHIFT_SECTOR_BYTE       s_shift_sector_byte
00102 #  define S_SHIFT_LOG_PAGE_SECTOR   s_shift_log_page_sector
00103 #  define S_SHIFT_LOG_BLOCK_SECTOR  s_shift_log_block_sector
00104 #  error  To be tested
00105 #else
00106 #  define S_SHIFT_SECTOR_BYTE       (NF_SHIFT_SECTOR_BYTE)
00107 #  define S_SHIFT_LOG_PAGE_SECTOR   ((G_SHIFT_PAGE_BYTE - S_SHIFT_SECTOR_BYTE) + NF_SHIFT_N_DEVICES)
00108 #  define S_SHIFT_LOG_BLOCK_SECTOR  ((S_SHIFT_LOG_PAGE_SECTOR) + (G_SHIFT_BLOCK_PAGE))
00109 #endif
00110 
00111 
00112 #define S_MNGT_DEV                ((NF_N_DEVICES)-1)
00113 
00114 #if (_ASSERT_==ENABLE)
00115 _MEM_TYPE_SLOW_ U16 _debug;
00116 static void nf_check_fbb( Bool b_ecc_err );
00117 static void nf_check_lut( void );
00118 #  define Nf_check_fbb(x)  nf_check_fbb(x)
00119 #  define Nf_check_lut()   nf_check_lut()
00120 #else
00121 #  define Nf_check_fbb(x)
00122 #  define Nf_check_lut()
00123 #endif
00124 
00125 typedef struct
00126 {
00127    struct
00128    {
00129       U8 valid:1 ;
00130       U8 dirty:1 ;
00131    } ctrl;
00132    U16  first ; // first logical number (included)
00133    U16  last  ; // last  logical number (included)
00134 #define CACHE_LUT_SIZE   (NF_CACHE_LUT_LOG_SZ*NF_N_DEVICES) // Size in U16
00135    U16  mem[ CACHE_LUT_SIZE ];
00136 } Cache_lut;
00137 
00138 typedef struct
00139 {
00140    struct
00141    {
00142       U8 valid:1 ;
00143       U8 dirty:1 ;
00144    } ctrl;
00145    U8   p     ; // Current logical number position
00146    U8   max   ; // number of logical entry
00147 #define CACHE_FBB_SIZE   (NF_CACHE_FBB_LOG_SZ*NF_N_DEVICES) // Size in U16
00148    U16  mem[ CACHE_FBB_SIZE ];
00149 } Cache_fbb;
00150 
00151 typedef enum
00152 {
00153    NF_READ=0
00154 ,  NF_WRITE
00155 } Nf_sense;
00156 
00157 //_____ F U N C T I O N S __________________________________________________
00158 
00159 Ctrl_status    nf_test_unit_ready         ( void ) ;
00160 Ctrl_status    nf_read_capacity           ( U32* ) ;
00161 Bool           nf_wr_protect              ( void ) ;
00162 Bool           nf_removal                 ( void ) ;
00163 Ctrl_status    nf_10                      ( U32 addr , U16 nb_sector, Nf_sense );
00164 
00165 Ctrl_status    nf_dfc_read_resume         ( void );   // function that resume the dfc interface of the memory
00166 Ctrl_status    nf_dfc_write_resume        ( void );   // function that resume the dfc interface of the memory
00167 Ctrl_status    nf_dfc_read_stop           ( U16 remaining_sectors );   // function that stops the dfc interface of the memory
00168 Ctrl_status    nf_dfc_write_stop          ( U16 remaining_sectors );   // function that stops the dfc interface of the memory
00169 
00170 void           nf_dfc_read_standby        ( U16 );
00171 void           nf_dfc_read_restart        ( void );
00172 
00173 U32            nf_get_sectors_number      ( void ) ;
00174 U8*            nf_get_buffer_addr         ( void ) ;
00175 void           nf_init                    ( void ) ;
00176 Status_bool    nf_verify                  ( void ) ;
00177 Status_bool    nf_verify_resume           ( void ) ;
00178 void           nf_cleanup_memory          ( void ) ;
00179 void           nf_upload                  ( U8 _MEM_TYPE_SLOW_*, U8 );
00180 void           nf_download                ( U8 _MEM_TYPE_SLOW_*, U8 );
00181 U32            nf_block_2_page            ( U16 block_addr );
00182 void           nf_ecc_mngt                ( void );
00183 void           nf_sync                    ( void );
00184 void           nf_copy                    ( U32 copy_dst );
00185 Status_bool    nf_write_lut               ( U8 pos, U8 i_sub_lut, U16 sub_lut_log_sz );
00186 Status_bool    nf_write_fbb               ( void );
00187 void           nf_cache_fbb_refill        ( void );
00188 void           nf_swap                    (U8 dev_id, U8 u8_ofst_lut, U8 u8_ofst_fbb);
00189 void           nf_cache_fbb_flush         ( Bool );
00190 void           nf_recovery(            U16 block_1, U16 block_2);
00191 void           nf_copy_tail               ( void );
00192 
00193 // New functions, to be tested
00194 Ctrl_status    nf_read_10( U32 log_sector , U16 n_sectors);
00195 Ctrl_status    nf_write_10( U32 log_sector , U16 n_sectors);
00196 Ctrl_status    nf_ram_2_nf                (U32 addr, U8 *ram);
00197 Ctrl_status    nf_nf_2_ram                (U32 addr, U8 *ram);
00198 
00199 #endif  // _NF_MNGT_H_
00200 

Generated on Fri Oct 31 14:31:24 2008 for ATMEL by  doxygen 1.5.3