Atmel Software Framework

 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Virtual Memory in RAM

The component manages a disk on a volatile memory (internal RAM).

This can be connected to a File System management or a USB Device Mass Storage Interface via the service Memory Control Access.

Functions

Ctrl_status virtual_mem_2_ram (uint32_t addr, void *ram)
 This function transfers 1 data sector from memory to RAM sector = 512 bytes. More...
 
Ctrl_status virtual_ram_2_mem (uint32_t addr, const void *ram)
 This function transfers 1 data sector from memory to RAM sector = 512 bytes. More...
 
Ctrl_status virtual_read_capacity (uint32_t *uint32_t_nb_sector)
 This function returns the address of the last valid sector. More...
 
bool virtual_removal (void)
 This function informs about the memory type. More...
 
Ctrl_status virtual_test_unit_ready (void)
 This function tests memory state, and starts memory initialization. More...
 
bool virtual_unload (bool unload)
 This function unloads/loads the memory. More...
 
Ctrl_status virtual_usb_read_10 (uint32_t addr, uint16_t nb_sector)
 This function transfers the memory data to the USB MSC interface. More...
 
static Ctrl_status virtual_usb_trans (uint32_t addr, uint16_t nb_sector, bool b_read)
 This function transfers the data between memory and USB MSC interface. More...
 
Ctrl_status virtual_usb_write_10 (uint32_t addr, uint16_t nb_sector)
 This function transfers the USB MSC data to the memory. More...
 
bool virtual_wr_protect (void)
 This function returns the write-protected mode. More...
 

Variables

static bool b_vmem_unloaded = false
 
static COMPILER_WORD_ALIGNED
uint8_t 
vmem_data [VMEM_NB_SECTOR *VMEM_SECTOR_SIZE]
 

Ctrl_status virtual_mem_2_ram ( uint32_t  addr,
void *  ram 
)

This function transfers 1 data sector from memory to RAM sector = 512 bytes.

Parameters
addrSector address to start read
ramAddress of RAM buffer
Returns
Ctrl_status It is ready -> CTRL_GOOD Memory unplug -> CTRL_NO_PRESENT Not initialized or changed -> CTRL_BUSY An error occurred -> CTRL_FAIL

References CTRL_FAIL, CTRL_GOOD, Max, min, virtual_check_init(), vmem_data, VMEM_NB_SECTOR, and VMEM_SECTOR_SIZE.

Ctrl_status virtual_ram_2_mem ( uint32_t  addr,
const void *  ram 
)

This function transfers 1 data sector from memory to RAM sector = 512 bytes.

Parameters
addrSector address to start write
ramAddress of RAM buffer
Returns
Ctrl_status It is ready -> CTRL_GOOD Memory unplug -> CTRL_NO_PRESENT Not initialized or changed -> CTRL_BUSY An error occurred -> CTRL_FAIL

References CTRL_FAIL, CTRL_GOOD, virtual_check_init(), vmem_data, VMEM_NB_SECTOR, and VMEM_SECTOR_SIZE.

Ctrl_status virtual_read_capacity ( uint32_t *  uint32_t_nb_sector)

This function returns the address of the last valid sector.

Parameters
uint32_t_nb_sectorPointer to number of sectors (sector=512 bytes)
Returns
Ctrl_status It is ready -> CTRL_GOOD Memory unplug -> CTRL_NO_PRESENT Not initialized or changed -> CTRL_BUSY An error occurred -> CTRL_FAIL

References b_vmem_unloaded, CTRL_GOOD, CTRL_NO_PRESENT, Max, virtual_check_init(), and VMEM_NB_SECTOR.

bool virtual_removal ( void  )

This function informs about the memory type.

Returns
true if the memory is removable
Ctrl_status virtual_test_unit_ready ( void  )

This function tests memory state, and starts memory initialization.

Returns
Ctrl_status It is ready -> CTRL_GOOD Memory unplug -> CTRL_NO_PRESENT Not initialized or changed -> CTRL_BUSY An error occurred -> CTRL_FAIL

References b_vmem_unloaded, CTRL_GOOD, CTRL_NO_PRESENT, and virtual_check_init().

bool virtual_unload ( bool  unload)

This function unloads/loads the memory.

Returns
true if the memory is unloaded

References b_vmem_unloaded.

Ctrl_status virtual_usb_read_10 ( uint32_t  addr,
uint16_t  nb_sector 
)

This function transfers the memory data to the USB MSC interface.

This function transfers the memory data (programmed in sbc_read_10) directly to the USB interface sector = 512 bytes.

Parameters
addrSector address to start read
nb_sectorNumber of sectors to transfer (sector=512 bytes)
Returns
Ctrl_status It is ready -> CTRL_GOOD Memory unplug -> CTRL_NO_PRESENT Not initialized or changed -> CTRL_BUSY An error occurred -> CTRL_FAIL

References CTRL_FAIL, CTRL_GOOD, data_to_transfer, g_scsi_ep_ms_in, Is_usb_endpoint_enabled, Is_usb_in_ready, Max, min, Usb_ack_in_ready_send, Usb_reset_endpoint_fifo_access, usb_write_ep_txpacket(), virtual_check_init(), virtual_usb_trans(), vmem_data, VMEM_NB_SECTOR, and VMEM_SECTOR_SIZE.

static Ctrl_status virtual_usb_trans ( uint32_t  addr,
uint16_t  nb_sector,
bool  b_read 
)
static

This function transfers the data between memory and USB MSC interface.

Parameters
addrSector address to start read
nb_sectorNumber of sectors to transfer (sector=512 bytes)
b_readMemory to USB, if true
Returns
Ctrl_status It is ready -> CTRL_GOOD Memory unplug -> CTRL_NO_PRESENT Not initialized or changed -> CTRL_BUSY An error occurred -> CTRL_FAIL

References buffer, CTRL_FAIL, CTRL_GOOD, min, NULL, udi_msc_trans_block(), vmem_data, VMEM_NB_SECTOR, and VMEM_SECTOR_SIZE.

Referenced by virtual_usb_read_10(), and virtual_usb_write_10().

Ctrl_status virtual_usb_write_10 ( uint32_t  addr,
uint16_t  nb_sector 
)

This function transfers the USB MSC data to the memory.

This function transfers the USB data (programmed in sbc_write_10) directly to the memory interface sector = 512 bytes.

Parameters
addrSector address to start write
nb_sectorNumber of sectors to transfer (sector=512 bytes)
Returns
Ctrl_status It is ready -> CTRL_GOOD Memory unplug -> CTRL_NO_PRESENT Not initialized or changed -> CTRL_BUSY An error occurred -> CTRL_FAIL

References CTRL_FAIL, CTRL_GOOD, data_to_transfer, g_scsi_ep_ms_out, Is_usb_endpoint_enabled, Is_usb_out_received, Usb_ack_out_received_free, usb_read_ep_rxpacket(), Usb_reset_endpoint_fifo_access, virtual_check_init(), virtual_usb_trans(), vmem_data, VMEM_NB_SECTOR, and VMEM_SECTOR_SIZE.

bool virtual_wr_protect ( void  )

This function returns the write-protected mode.

This function returns the write-protected mode Only used by memory removal with a HARDWARE-SPECIFIC write-protected detection.

Returns
true if the memory is protected

bool b_vmem_unloaded = false
static