ATMEL: df_mem.h File Reference

- Main Page
- Modules
- Data Structures
- Files
- Related Pages

# 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.

- Compiler: IAR EWAVR and GNU GCC for AVR
- Supported devices: AT90USB1287, AT90USB1286, AT90USB647, AT90USB646

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 64 of file df_mem.c.

References df_init().

    00065 {
    00066    df_init();        // Init the DF driver and its communication link.
    00067 }

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 77 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.

    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 }

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 97 of file df_mem.c.

References DF_NB_MEM, and df_test_unit_ready().

    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 }

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 117 of file df_mem.c.

References g_b_df_protected.

    00118 {
    00119    return g_b_df_protected;
    00120 }

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 127 of file df_mem.c.

References FALSE.

    00128 {
    00129    return FALSE;
    00130 }

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 145 of file df_mem.c.

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

    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 }

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 213 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.

    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 }

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 308 of file df_mem.c.

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

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 377 of file df_mem.c.

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

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

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 464 of file df_mem.c.

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

    00465 {
    00466    df_write_open(addr);
    00467    df_write_sector_from_ram(ram);
    00468    df_write_close();
    00469    return CTRL_GOOD;
    00470 }

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 446 of file df_mem.c.

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

    00447 {
    00448    df_read_open(addr);
    00449    df_read_sector_2_ram(ram);
    00450    df_read_close();
    00451    return CTRL_GOOD;
    00452 }

Here is the call graph for this function: