#include "config.h"#include "df_mem.h"#include "df.h"
Go to the source code of this file.
Functions | |
| void | df_check_init (void) |
| void | df_mem_init (void) |
| This function initializes the hw/sw ressources required to drive the DF. | |
| Ctrl_status | df_test_unit_ready (void) |
| This function tests the state of the DF memory. | |
| Ctrl_status | df_read_capacity (U32 _MEM_TYPE_SLOW_ *u32_nb_sector) |
| Bool | df_wr_protect (void) |
| This function returns the write protected status of the memory. | |
| Bool | df_removal (void) |
| This function tells if the memory has been removed or not. | |
| Ctrl_status | df_read_10 (U32 addr, U16 nb_sector) |
| This function performs a read operation of n sectors from a given address to USB. | |
| Ctrl_status | df_write_10 (U32 addr, U16 nb_sector) |
| This function performs a write operation of n sectors to a given address from USB. | |
| Ctrl_status | df_df_2_ram (U32 addr, U8 *ram) |
| This function performs a read operation of 1 sector from a given address to RAM buffer. | |
| Ctrl_status | df_ram_2_df (U32 addr, U8 *ram) |
| This function performs a write operation of 1 sector to a given address from RAM buffer. | |
Variables | |
| Bool | g_b_df_protected = FALSE |
| Bool | g_b_df_protected_last = FALSE |
Definition in file df_mem.c.
| void df_check_init | ( | void | ) |
| void df_mem_init | ( | void | ) |
This function initializes the hw/sw ressources required to drive the DF.
Definition at line 64 of file df_mem.c.
Referenced by df_write_10(), and storage_task_init().
00065 { 00066 df_init(); // Init the DF driver and its communication link. 00067 }
| Ctrl_status df_test_unit_ready | ( | void | ) |
This function tests the state of the DF memory.
Definition at line 77 of file df_mem.c.
Referenced by df_read_capacity().
00078 { 00079 if( g_b_df_protected != g_b_df_protected_last ) 00080 { 00081 g_b_df_protected_last = g_b_df_protected; 00082 return CTRL_BUSY; 00083 } 00084 return( (OK==df_mem_check()) ? CTRL_GOOD : CTRL_NO_PRESENT); 00085 }
| Ctrl_status df_read_capacity | ( | U32 _MEM_TYPE_SLOW_ * | u32_nb_sector | ) |
This function gives the address of the last valid sector.
| *u32_nb_sector | number of sector (sector = 512B) |
Definition at line 97 of file df_mem.c.
00098 { 00099 #ifdef DF_4_MB // AT45DB321 memories 00100 *u32_nb_sector = ((DF_NB_MEM*4*1024L*1024L)/512)-1; 00101 #endif 00102 #ifdef DF_8_MB // AT45DB642 memories 00103 *u32_nb_sector = ((DF_NB_MEM*8*1024L*1024L)/512)-1; 00104 #endif 00105 return df_test_unit_ready(); 00106 }
| Bool df_wr_protect | ( | void | ) |
This function returns the write protected status of the memory.
Only used by memory removal with a HARDWARE SPECIFIC write protected detection !!! The customer must unplug the memory to change this write protected status, which cannot be for a DF.
Definition at line 117 of file df_mem.c.
00118 { 00119 return g_b_df_protected; 00120 }
| Bool df_removal | ( | void | ) |
| Ctrl_status df_read_10 | ( | U32 | addr, | |
| U16 | nb_sector | |||
| ) |
This function performs a read operation of n sectors from a given address to USB.
| addr | Sector address to start the read from | |
| nb_sector | Number of sectors to transfer |
Definition at line 145 of file df_mem.c.
00146 { 00147 U8 status = OK; 00148 #if (DF_NB_MEM == 1) // 1 DATAFLASH 00149 df_read_open(addr); // wait device is not busy, then send command & address 00150 status = df_read_sector(nb_sector); // transfer data from memory to USB 00151 00152 #else // 2 or 4 DATAFLASH 00153 U32 next_sector_addr = addr; 00154 U16 nb_sectors_remaining = nb_sector; 00155 00156 #ifdef DF_4_MB // 512B PAGES 00157 while( (nb_sectors_remaining != 0) && (status == OK)) 00158 { 00159 df_read_open(next_sector_addr); // wait device is not busy, then send command & address 00160 status = df_read_sector(1); // transfer the page from memory to USB 00161 df_read_close(); 00162 nb_sectors_remaining--; 00163 next_sector_addr++; 00164 } 00165 #else // 1024B PAGES 00166 while( (nb_sectors_remaining != 0) && (status == OK)) 00167 { 00168 df_read_open(next_sector_addr); // wait device is not busy, then send command & address 00169 if ((LSB0(next_sector_addr)&0x01) == 0) 00170 { 00171 if (nb_sectors_remaining == 1) 00172 { 00173 status = df_read_sector(1); 00174 df_read_close(); 00175 nb_sectors_remaining--; 00176 next_sector_addr++; 00177 } 00178 else 00179 { 00180 status = df_read_sector(2); 00181 df_read_close(); 00182 nb_sectors_remaining -= 2; 00183 next_sector_addr += 2; 00184 } 00185 } 00186 else 00187 { 00188 status = df_read_sector(1); 00189 df_read_close(); 00190 nb_sectors_remaining--; 00191 next_sector_addr++; 00192 } 00193 } 00194 #endif 00195 #endif 00196 00197 df_read_close(); 00198 if(status == KO) 00199 return CTRL_FAIL; 00200 return CTRL_GOOD; 00201 }
| Ctrl_status df_write_10 | ( | U32 | addr, | |
| U16 | nb_sector | |||
| ) |
This function performs a write operation of n sectors to a given address from USB.
| addr | Sector address to start write | |
| nb_sector | Number of sectors to transfer |
Definition at line 213 of file df_mem.c.
00214 { 00215 #if (DF_NB_MEM != 1) // if more than 1 memory, variables are needed for zones mangement 00216 U32 next_sector_addr = addr; 00217 U16 nb_sectors_remaining = nb_sector; 00218 #endif 00219 00220 if( g_b_df_protected ) return CTRL_FAIL; 00221 00222 #if (DF_NB_MEM == 1) /* 1 DATAFLASH */ 00223 df_write_open(addr); // wait device is not busy, then send command & address 00224 if( KO == df_write_sector(nb_sector) ) // transfer data from memory to USB 00225 { 00226 df_mem_init(); 00227 return CTRL_FAIL; 00228 } 00229 #else /* 2 or 4 DATAFLASH */ 00230 #ifdef DF_4_MB // 512B PAGES 00231 while (nb_sectors_remaining != 0) 00232 { 00233 df_write_open(next_sector_addr); // wait device is not busy, then send command & address 00234 if( KO == df_write_sector(1)) // transfer the page from memory to USB 00235 { 00236 df_mem_init(); 00237 return CTRL_FAIL; 00238 } 00239 df_write_close(); 00240 nb_sectors_remaining--; 00241 next_sector_addr++; 00242 } 00243 #else // 1024B PAGES 00244 while (nb_sectors_remaining != 0) 00245 { 00246 df_write_open(next_sector_addr); // wait device is not busy, then send command & address 00247 if ((LSB0(next_sector_addr)&0x01) == 0) 00248 { 00249 if (nb_sectors_remaining == 1) 00250 { 00251 if( KO == df_write_sector(1)) // transfer the page from memory to USB 00252 { 00253 df_mem_init(); 00254 return CTRL_FAIL; 00255 } 00256 df_write_close(); 00257 nb_sectors_remaining--; 00258 next_sector_addr++; 00259 } 00260 else 00261 { 00262 if( KO == df_write_sector(2)) // transfer the page from memory to USB 00263 { 00264 df_mem_init(); 00265 return CTRL_FAIL; 00266 } 00267 df_write_close(); 00268 nb_sectors_remaining -= 2; 00269 next_sector_addr += 2; 00270 } 00271 } 00272 else 00273 { 00274 if( KO == df_write_sector(1)) // transfer the page from memory to USB 00275 { 00276 df_mem_init(); 00277 return CTRL_FAIL; 00278 } 00279 df_write_close(); 00280 nb_sectors_remaining--; 00281 next_sector_addr++; 00282 } 00283 } 00284 #endif 00285 #endif 00286 df_write_close(); // unselect memory 00287 return CTRL_GOOD; 00288 }
| Ctrl_status df_df_2_ram | ( | U32 | addr, | |
| U8 * | ram | |||
| ) |
This function performs a read operation of 1 sector from a given address to RAM buffer.
| addr | Sector address to read | |
| ram | Ram buffer pointer |
Definition at line 303 of file df_mem.c.
00304 { 00305 df_read_open(addr); 00306 df_read_sector_2_ram(ram); 00307 df_read_close(); 00308 return CTRL_GOOD; 00309 }
| Ctrl_status df_ram_2_df | ( | U32 | addr, | |
| U8 * | ram | |||
| ) |
This function performs a write operation of 1 sector to a given address from RAM buffer.
| addr | Sector address to write | |
| ram | Ram buffer pointer |
Definition at line 321 of file df_mem.c.
00322 { 00323 df_write_open(addr); 00324 df_write_sector_from_ram(ram); 00325 df_write_close(); 00326 return CTRL_GOOD; 00327 }
| Bool g_b_df_protected = FALSE |
Definition at line 53 of file df_mem.c.
Referenced by df_test_unit_ready(), df_wr_protect(), and df_write_10().
| Bool g_b_df_protected_last = FALSE |
1.5.3