nf_mngt.h

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

Generated on Wed Sep 23 09:17:02 2009 for ATMEL by  doxygen 1.5.3