df_mem.h File Reference

#include "conf/conf_access.h"
#include "modules/control_access/ctrl_status.h"

Include dependency graph for df_mem.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

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_host_write_10 (U32 addr, U16 nb_sector)
 This fonction initialise the memory for a write operation in usb host mode.
Ctrl_status df_host_read_10 (U32 addr, U16 nb_sector)
 This fonction initialise the memory for a read operation in usb host mode.
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.
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.


Detailed Description

This file contains the interface routines of Data Flash memory.

Author:
Atmel Corporation: http://www.atmel.com
Support and FAQ: http://support.atmel.no/

Definition in file df_mem.h.


Function Documentation

void df_mem_init ( void   ) 

This function initializes the hw/sw ressources required to drive the DF.

Definition at line 61 of file df_mem.c.

References df_init().

00062 {
00063    df_init();        // Init the DF driver and its communication link.
00064 }

Here is the call graph for this function:

Ctrl_status df_test_unit_ready ( void   ) 

This function tests the state of the DF memory.

Returns:
Ctrl_status It is ready -> CTRL_GOOD Not initialize -> CTRL_BUSY Else -> CTRL_NO_PRESENT

Definition at line 74 of file df_mem.c.

References CTRL_BUSY, CTRL_GOOD, CTRL_NO_PRESENT, df_mem_check(), g_b_df_protected, g_b_df_protected_last, and OK.

00075 {
00076    if( g_b_df_protected != g_b_df_protected_last )
00077    {
00078       g_b_df_protected_last = g_b_df_protected;
00079       return CTRL_BUSY;
00080    }
00081    return( (OK==df_mem_check()) ? CTRL_GOOD : CTRL_NO_PRESENT);
00082 }

Here is the call graph for this function:

Ctrl_status df_read_capacity ( U32 _MEM_TYPE_SLOW_ *  u32_nb_sector  ) 

This function gives the address of the last valid sector.

Parameters:
*u32_nb_sector number of sector (sector = 512B)
Returns:
Ctrl_status It is ready -> CTRL_GOOD Not initialize -> CTRL_BUSY Else -> CTRL_NO_PRESENT

Definition at line 94 of file df_mem.c.

References DF_NB_MEM, and df_test_unit_ready().

00095 {
00096 #ifdef DF_4_MB              // AT45DB321 memories
00097    *u32_nb_sector = ((DF_NB_MEM*4*1024L*1024L)/512)-1;
00098 #endif
00099 #ifdef DF_8_MB              // AT45DB642 memories
00100    *u32_nb_sector = ((DF_NB_MEM*8*1024L*1024L)/512)-1;
00101 #endif
00102    return df_test_unit_ready();
00103 }

Here is the call graph for this function:

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.

Returns:
FALSE, the memory is not write-protected

Definition at line 114 of file df_mem.c.

References g_b_df_protected.

00115 {
00116    return g_b_df_protected;
00117 }

Bool df_removal ( void   ) 

This function tells if the memory has been removed or not.

Returns:
FALSE, The memory isn't removed

Definition at line 124 of file df_mem.c.

References FALSE.

00125 {
00126    return FALSE;
00127 }

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.

Parameters:
addr Sector address to start the read from
nb_sector Number of sectors to transfer
Returns:
Ctrl_status It is ready -> CTRL_GOOD A error occur -> CTRL_FAIL

Definition at line 142 of file df_mem.c.

References CTRL_FAIL, CTRL_GOOD, df_read_close(), df_read_open(), df_read_sector(), KO, LSB0, and OK.

00143 {
00144    U8 status = OK;
00145 #if   (DF_NB_MEM == 1)     // 1 DATAFLASH
00146    df_read_open(addr);                    // wait device is not busy, then send command & address
00147    status = df_read_sector(nb_sector);             // transfer data from memory to USB
00148    
00149 #else                      // 2 or 4 DATAFLASH
00150    U32   next_sector_addr = addr;
00151    U16   nb_sectors_remaining = nb_sector;
00152    
00153    #ifdef DF_4_MB             // 512B PAGES
00154    while( (nb_sectors_remaining != 0) && (status == OK))
00155    {
00156       df_read_open(next_sector_addr);     // wait device is not busy, then send command & address
00157       status = df_read_sector(1);                  // transfer the page from memory to USB
00158       df_read_close();
00159       nb_sectors_remaining--;
00160       next_sector_addr++;
00161    }
00162    #else                      // 1024B PAGES
00163    while( (nb_sectors_remaining != 0) && (status == OK))
00164    {
00165       df_read_open(next_sector_addr);     // wait device is not busy, then send command & address
00166       if ((LSB0(next_sector_addr)&0x01) == 0)
00167       {
00168         if (nb_sectors_remaining == 1)
00169         {
00170            status = df_read_sector(1);
00171            df_read_close();
00172            nb_sectors_remaining--;
00173            next_sector_addr++;
00174         }
00175         else
00176         {
00177           status = df_read_sector(2);
00178           df_read_close();
00179           nb_sectors_remaining -= 2;
00180           next_sector_addr += 2;
00181         }
00182       }
00183       else
00184       {
00185         status = df_read_sector(1);
00186         df_read_close();
00187         nb_sectors_remaining--;
00188         next_sector_addr++;
00189       }
00190    }
00191    #endif
00192 #endif
00193    
00194    df_read_close();
00195    if(status == KO)
00196       return CTRL_FAIL;
00197    return CTRL_GOOD;
00198 }

Here is the call graph for this function:

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.

Parameters:
addr Sector address to start write
nb_sector Number of sectors to transfer
Returns:
Ctrl_status It is ready -> CTRL_GOOD A error occur -> CTRL_FAIL

Definition at line 210 of file df_mem.c.

References CTRL_FAIL, CTRL_GOOD, df_mem_init(), df_write_close(), df_write_open(), df_write_sector(), g_b_df_protected, KO, and LSB0.

00211 {
00212 #if   (DF_NB_MEM != 1)                 // if more than 1 memory, variables are needed for zones mangement
00213    U32   next_sector_addr = addr;
00214    U16   nb_sectors_remaining = nb_sector;
00215 #endif
00216 
00217    if( g_b_df_protected ) return CTRL_FAIL;
00218 
00219 #if      (DF_NB_MEM == 1)  /* 1 DATAFLASH */
00220    df_write_open(addr);                    // wait device is not busy, then send command & address
00221    if( KO == df_write_sector(nb_sector) )  // transfer data from memory to USB
00222    {
00223       df_mem_init();
00224       return CTRL_FAIL;
00225    }
00226 #else                      /* 2 or 4 DATAFLASH */
00227    #ifdef DF_4_MB       // 512B PAGES
00228    while (nb_sectors_remaining != 0)
00229    {
00230       df_write_open(next_sector_addr);     // wait device is not busy, then send command & address
00231       if( KO == df_write_sector(1))        // transfer the page from memory to USB
00232       {
00233          df_mem_init();
00234          return CTRL_FAIL;
00235       }
00236       df_write_close();
00237       nb_sectors_remaining--;
00238       next_sector_addr++;
00239    }
00240    #else                // 1024B PAGES
00241    while (nb_sectors_remaining != 0)
00242    {
00243       df_write_open(next_sector_addr);     // wait device is not busy, then send command & address
00244       if ((LSB0(next_sector_addr)&0x01) == 0)
00245       {
00246         if (nb_sectors_remaining == 1)
00247         {
00248           if( KO == df_write_sector(1))    // transfer the page from memory to USB
00249           {
00250              df_mem_init();
00251              return CTRL_FAIL;
00252           }
00253           df_write_close();
00254           nb_sectors_remaining--;
00255           next_sector_addr++;
00256         }
00257         else
00258         {
00259           if( KO == df_write_sector(2))    // transfer the page from memory to USB
00260           {
00261              df_mem_init();
00262              return CTRL_FAIL;
00263           }
00264           df_write_close();
00265           nb_sectors_remaining -= 2;
00266           next_sector_addr += 2;
00267         }
00268       }
00269       else
00270       {
00271         if( KO == df_write_sector(1))      // transfer the page from memory to USB
00272         {
00273            df_mem_init();
00274            return CTRL_FAIL;
00275         }
00276         df_write_close();
00277         nb_sectors_remaining--;
00278         next_sector_addr++;
00279       }
00280    }
00281    #endif
00282 #endif
00283    df_write_close();                    // unselect memory
00284    return CTRL_GOOD;
00285 }

Here is the call graph for this function:

Ctrl_status df_host_write_10 ( U32  addr,
U16  nb_sector 
)

This fonction initialise the memory for a write operation in usb host mode.

DATA FLOW is: DF => USB

(sector = 512B)

Parameters:
addr Sector address to start write
nb_sector Number of sectors to transfer
Returns:
Ctrl_status It is ready -> CTRL_GOOD A error occur -> CTRL_FAIL Write_10 in host mode means reading the DF

Definition at line 305 of file df_mem.c.

00306 {
00307 #if   (DF_NB_MEM != 1)                 // if more than 1 memory, variables are needed for zones mangement
00308    U32   next_sector_addr = addr;
00309    U16   nb_sectors_remaining = nb_sector;
00310 #endif
00311 
00312 #if   (DF_NB_MEM == 1)     /* 1 DATAFLASH */
00313    df_read_open(addr);                    // wait device is not busy, then send command & address
00314    df_host_read_sector(nb_sector);             // transfer data from memory to USB
00315 #else                      /* 2 or 4 DATAFLASH */
00316    #ifdef DF_4_MB             // 512B PAGES
00317    while (nb_sectors_remaining != 0)
00318    {
00319       df_read_open(next_sector_addr);     // wait device is not busy, then send command & address
00320       df_host_read_sector(1);                  // transfer the page from memory to USB
00321       df_read_close();
00322       nb_sectors_remaining--;
00323       next_sector_addr++;
00324    }
00325    #else                      // 1024B PAGES
00326    while (nb_sectors_remaining != 0)
00327    {
00328       df_read_open(next_sector_addr);     // wait device is not busy, then send command & address
00329       if ((LSB0(next_sector_addr)&0x01) == 0)
00330       {
00331         if (nb_sectors_remaining == 1)
00332         {
00333            df_host_read_sector(1);
00334            df_read_close();
00335            nb_sectors_remaining--;
00336            next_sector_addr++;
00337         }
00338         else
00339         {
00340           df_host_read_sector(2);
00341           df_read_close();
00342           nb_sectors_remaining -= 2;
00343           next_sector_addr += 2;
00344         }
00345       }
00346       else
00347       {
00348         df_host_read_sector(1);
00349         df_read_close();
00350         nb_sectors_remaining--;
00351         next_sector_addr++;
00352       }
00353    }
00354    #endif
00355 #endif
00356    df_read_close();                    // unselect memory
00357    return CTRL_GOOD;
00358 }

Ctrl_status df_host_read_10 ( U32  addr,
U16  nb_sector 
)

This fonction initialise the memory for a read operation in usb host mode.

DATA FLOW is: USB => DF

(sector = 512B)

Parameters:
addr Sector address to start write
nb_sector Number of sectors to transfer
Returns:
Ctrl_status It is ready -> CTRL_GOOD A error occur -> CTRL_FAIL Read_10 in host mode means writing the DF

Definition at line 374 of file df_mem.c.

References CTRL_GOOD, df_host_write_sector(), df_write_close(), df_write_open(), and LSB0.

00375 {
00376 #if   (DF_NB_MEM != 1)                 // if more than 1 memory, variables are needed for zones mangement
00377    U32   next_sector_addr = addr;
00378    U16   nb_sectors_remaining = nb_sector;
00379 #endif
00380 
00381 #if      (DF_NB_MEM == 1)  /* 1 DATAFLASH */
00382    df_write_open(addr);                    // wait device is not busy, then send command & address
00383    df_host_write_sector(nb_sector);             // transfer data from memory to USB
00384 #else                      /* 2 or 4 DATAFLASH */
00385    #ifdef DF_4_MB       // 512B PAGES
00386    while (nb_sectors_remaining != 0)
00387    {
00388       df_write_open(next_sector_addr);     // wait device is not busy, then send command & address
00389       df_host_write_sector(1);                  // transfer the page from memory to USB
00390       df_write_close();
00391       nb_sectors_remaining--;
00392       next_sector_addr++;
00393    }
00394    #else                // 1024B PAGES
00395    while (nb_sectors_remaining != 0)
00396    {
00397       df_write_open(next_sector_addr);     // wait device is not busy, then send command & address
00398       if ((LSB0(next_sector_addr)&0x01) == 0)
00399       {
00400         if (nb_sectors_remaining == 1)
00401         {
00402           df_host_write_sector(1);
00403           df_write_close();
00404           nb_sectors_remaining--;
00405           next_sector_addr++;
00406         }
00407         else
00408         {
00409           df_host_write_sector(2);
00410           df_write_close();
00411           nb_sectors_remaining -= 2;
00412           next_sector_addr += 2;
00413         }
00414       }
00415       else
00416       {
00417         df_host_write_sector(1);
00418         df_write_close();
00419         nb_sectors_remaining--;
00420         next_sector_addr++;
00421       }
00422    }
00423    #endif
00424 #endif
00425    df_write_close();                    // unselect memory
00426    return CTRL_GOOD;
00427 }

Here is the call graph for this function:

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.

Parameters:
addr Sector address to write
ram Ram buffer pointer
Returns:
Ctrl_status It is ready -> CTRL_GOOD A error occur -> CTRL_FAIL

Definition at line 461 of file df_mem.c.

References CTRL_GOOD, df_write_close(), df_write_open(), and df_write_sector_from_ram().

00462 {
00463    df_write_open(addr);
00464    df_write_sector_from_ram(ram);
00465    df_write_close();
00466    return CTRL_GOOD;
00467 }

Here is the call graph for this function:

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.

Parameters:
addr Sector address to read
ram Ram buffer pointer
Returns:
Ctrl_status It is ready -> CTRL_GOOD A error occur -> CTRL_FAIL

Definition at line 443 of file df_mem.c.

References CTRL_GOOD, df_read_close(), df_read_open(), and df_read_sector_2_ram().

00444 {
00445    df_read_open(addr);
00446    df_read_sector_2_ram(ram);
00447    df_read_close();
00448    return CTRL_GOOD;
00449 }

Here is the call graph for this function:


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