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

- File List
- Globals

# df_mem.h File Reference

Copyright (c) 2004This file contains the interface routines of Data Flash memory. More...

`#include "conf\conf_access.h"`
`#include "modules\control_access\ctrl_status.h"`
`#include "lib_mcu\usb\usb_drv.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.

## Defines
#define | ENTRY_SIZE 32
| FAT specification.
#define | PBR_SECTOR (0)
#define | FAT_SECTOR (PBR_SECTOR + VMEM_RESERVED_SIZE)
#define | ROOT_SECTOR (FAT_SECTOR + (VMEM_SIZE_FAT*VMEM_NB_FATS))
#define | FILE_SECTOR (ROOT_SECTOR + ((ENTRY_SIZE*VMEM_NB_ROOT_ENTRY) / VMEM_SECTOR_SIZE))
## 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)
| This function gives the address of the last valid 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 on.
Ctrl_status | df_write_10 (U32 addr, U16 nb_sector)
| This fonction initialise the memory for a write operation.
Ctrl_status | df_ram_2_df (U32 addr, U8 *ram)
| This fonction initialise the memory for a write operation from ram buffer.
Ctrl_status | df_df_2_ram (U32 addr, U8 *ram)
| This fonction read 1 sector from DF to ram buffer.
Ctrl_status | df_ram_2_df_write (void)
| This fonction transfer ram to the memory data.
Ctrl_status | df_df_2_ram_read (void)
| This fonction transfer the memory data to ram.
Ctrl_status | df_usb_read (void)
| This fonction transfer the memory data (programed in scsi_read_10) directly to the usb interface.
Ctrl_status | df_usb_write (void)
| This fonction transfer the usb data (programed in scsi_write_10) directly to the memory data.

## Detailed Description

Copyright (c) 2004This file contains the interface routines of Data Flash memory.

Use of this program is subject to Atmel's End User License Agreement. Please read file license.txt for copyright notice.

Version:
  1.1 (c5131-mass-storage-complete-1_0_0)

Todo:

Bug:

Definition in file df_mem.h.

## Define Documentation

#define ENTRY_SIZE 32

FAT specification.

Definition at line 26 of file df_mem.h.

#define PBR_SECTOR (0)

Definition at line 31 of file df_mem.h.

#define FAT_SECTOR (PBR_SECTOR + VMEM_RESERVED_SIZE)

Definition at line 32 of file df_mem.h.

#define ROOT_SECTOR (FAT_SECTOR + (VMEM_SIZE_FAT*VMEM_NB_FATS))

Definition at line 33 of file df_mem.h.

#define FILE_SECTOR (ROOT_SECTOR + ((ENTRY_SIZE*VMEM_NB_ROOT_ENTRY) / VMEM_SECTOR_SIZE))

Definition at line 34 of file df_mem.h.

## Function Documentation

void df_mem_init | ( | void |  | ) |

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

Warning:
  Code:?? bytes (function code length)

Parameters:

  | none |

Returns:
  none

/

Definition at line 59 of file df_mem.c.

References df_init().

Referenced by storage_task_init().

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

Here is the call graph for this function:

Ctrl_status df_test_unit_ready | ( | void |  | ) |

This function tests the state of the DF memory.

Warning:
  Code:?? bytes (function code length)

Parameters:

  | none |

Returns:
  Ctrl_status It is ready -> CTRL_GOOD Else -> CTRL_NO_PRESENT /

Definition at line 76 of file df_mem.c.

References CTRL_GOOD, CTRL_NO_PRESENT, df_mem_check(), and OK.

    00077 {
    00078    return( (OK==df_mem_check()) ? CTRL_GOOD : CTRL_NO_PRESENT);
    00079 }

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.

Warning:
  Code:?? bytes (function code length)

Parameters:

  | *u32_nb_sector | number of sector (sector = 512B). OUT

Returns:
  Ctrl_status It is ready -> CTRL_GOOD /

Definition at line 92 of file df_mem.c.

References CTRL_GOOD, and DF_DISK_SIZE.

    00093 {
    00094    *u32_nb_sector = DF_DISK_SIZE;
    00095    return CTRL_GOOD;
    00096 }

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.

Warning:
  Code:?? bytes (function code length)

Returns:
  FALSE -> the memory is not write-protected (always) /

Definition at line 110 of file df_mem.c.

References FALSE.

    00111 {
    00112    return FALSE;
    00113 }

Bool df_removal | ( | void |  | ) |

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

Parameters:

  | none |

Warning:
  Code:?? bytes (function code length)

Returns:
  FALSE -> The memory isn't removed /

Definition at line 125 of file df_mem.c.

References FALSE.

    00126 {
    00127    return FALSE;
    00128 }

Ctrl_status df_read_10 | ( | U32 | addr,
|  | U16 | nb_sector |
| ) |  |  |

This function performs a read operation of n sectors from a given address on.

(sector = 512B)

DATA FLOW is: DF => USB

Warning:
  Code:?? bytes (function code length)

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

References CTRL_GOOD, df_read_close(), df_read_open(), df_read_sector(), and LSB0.

    00151 {
    00152 #if   (DF_NB_MEM != 1)                 // if more than 1 memory, variables are needed for zones mangement
    00153    U32   next_sector_addr = addr;
    00154    U16   nb_sectors_remaining = nb_sector;
    00155 #endif
    00156
    00157 #if   (DF_NB_MEM == 1)     /* 1 DATAFLASH */
    00158    df_read_open(addr);                    // wait device is not busy, then send command & address
    00159    df_read_sector(nb_sector);             // transfer data from memory to USB
    00160 #else                      /* 2 or 4 DATAFLASH */
    00161    #ifdef DF_4_MB             // 512B PAGES
    00162    while (nb_sectors_remaining != 0)
    00163    {
    00164       df_read_open(next_sector_addr);     // wait device is not busy, then send command & address
    00165       df_read_sector(1);                  // transfer the page from memory to USB
    00166       df_read_close();
    00167       nb_sectors_remaining--;
    00168       next_sector_addr++;
    00169    }
    00170    #else                      // 1024B PAGES
    00171    while (nb_sectors_remaining != 0)
    00172    {
    00173       df_read_open(next_sector_addr);     // wait device is not busy, then send command & address
    00174       if ((LSB0(next_sector_addr)&0x01) == 0)
    00175       {
    00176         if (nb_sectors_remaining == 1)
    00177         {
    00178            df_read_sector(1);
    00179            df_read_close();
    00180            nb_sectors_remaining--;
    00181            next_sector_addr++;
    00182         }
    00183         else
    00184         {
    00185           df_read_sector(2);
    00186           df_read_close();
    00187           nb_sectors_remaining -= 2;
    00188           next_sector_addr += 2;
    00189         }
    00190       }
    00191       else
    00192       {
    00193         df_read_sector(1);
    00194         df_read_close();
    00195         nb_sectors_remaining--;
    00196         next_sector_addr++;
    00197       }
    00198    }
    00199    #endif
    00200 #endif
    00201    df_read_close();                    // unselect memory
    00202    return CTRL_GOOD;
    00203 }

Here is the call graph for this function:

Ctrl_status df_write_10 | ( | U32 | addr,
|  | U16 | nb_sector |
| ) |  |  |

This fonction initialise the memory for a write operation.

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

Definition at line 219 of file df_mem.c.

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

    00220 {
    00221 #if   (DF_NB_MEM != 1)                 // if more than 1 memory, variables are needed for zones mangement
    00222    U32   next_sector_addr = addr;
    00223    U16   nb_sectors_remaining = nb_sector;
    00224 #endif
    00225
    00226 #if      (DF_NB_MEM == 1)  /* 1 DATAFLASH */
    00227    df_write_open(addr);                    // wait device is not busy, then send command & address
    00228    df_write_sector(nb_sector);             // transfer data from memory to USB
    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       df_write_sector(1);                  // transfer the page from memory to USB
    00235       df_write_close();
    00236       nb_sectors_remaining--;
    00237       next_sector_addr++;
    00238    }
    00239    #else                // 1024B PAGES
    00240    while (nb_sectors_remaining != 0)
    00241    {
    00242       df_write_open(next_sector_addr);     // wait device is not busy, then send command & address
    00243       if ((LSB0(next_sector_addr)&0x01) == 0)
    00244       {
    00245         if (nb_sectors_remaining == 1)
    00246         {
    00247           df_write_sector(1);
    00248           df_write_close();
    00249           nb_sectors_remaining--;
    00250           next_sector_addr++;
    00251         }
    00252         else
    00253         {
    00254           df_write_sector(2);
    00255           df_write_close();
    00256           nb_sectors_remaining -= 2;
    00257           next_sector_addr += 2;
    00258         }
    00259       }
    00260       else
    00261       {
    00262         df_write_sector(1);
    00263         df_write_close();
    00264         nb_sectors_remaining--;
    00265         next_sector_addr++;
    00266       }
    00267    }
    00268    #endif
    00269 #endif
    00270    df_write_close();                    // unselect memory
    00271    return CTRL_GOOD;
    00272 }

Here is the call graph for this function:

Ctrl_status df_ram_2_df | ( | U32 | addr,
|  | U8 * | ram |
| ) |  |  |

This fonction initialise the memory for a write operation from ram buffer.

DATA FLOW is: RAM => DF

(sector = 512B)

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

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

    00318 {
    00319    df_write_open(addr);
    00320    df_write_sector_from_ram(ram);
    00321    df_write_close();
    00322    return CTRL_GOOD;
    00323 }

Here is the call graph for this function:

Ctrl_status df_df_2_ram | ( | U32 | addr,
|  | U8 * | ram |
| ) |  |  |

This fonction read 1 sector from DF to ram buffer.

DATA FLOW is: DF => RAM

(sector = 512B)

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

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

    00338 {
    00339    df_read_open(addr);
    00340    df_read_sector_2_ram(ram);
    00341    df_read_close();
    00342    return CTRL_GOOD;
    00343 }

Here is the call graph for this function:

Ctrl_status df_ram_2_df_write | ( | void |  | ) |

This fonction transfer ram to the memory data.

Returns:
  Ctrl_status It is ready -> CTRL_GOOD

Definition at line 363 of file df_mem.c.

References CTRL_GOOD.

    00364 {
    00365    return CTRL_GOOD;
    00366 }

Ctrl_status df_df_2_ram_read | ( | void |  | ) |

This fonction transfer the memory data to ram.

Returns:
  Ctrl_status It is ready -> CTRL_GOOD

Definition at line 352 of file df_mem.c.

References CTRL_GOOD.

    00353 {
    00354    return CTRL_GOOD;
    00355 }

Ctrl_status df_usb_read | ( | void |  | ) |

This fonction transfer the memory data (programed in scsi_read_10) directly to the usb interface.

Returns:
  Ctrl_status It is ready -> CTRL_GOOD

Definition at line 285 of file df_mem.c.

References CTRL_GOOD.

    00286 {
    00287    return CTRL_GOOD;
    00288 }

Ctrl_status df_usb_write | ( | void |  | ) |

This fonction transfer the usb data (programed in scsi_write_10) directly to the memory data.

Returns:
  Ctrl_status It is ready -> CTRL_GOOD

Definition at line 296 of file df_mem.c.

References CTRL_GOOD.

    00297 {
    00298    return CTRL_GOOD;
    00299 }