Atmel Software Framework

avr32/services/usb/_asf_v1/class/mass_storage/examples/virtual_mem/virtual_mem.c File Reference
#include "conf_access.h"
#include "virtual_mem.h"
#include "usb_drv.h"
#include "scsi_decoder.h"
#include <string.h>

Functions

static void virtual_check_init (void)
 This function initializes the memory. More...
 
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 *u32_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...
 
Ctrl_status virtual_usb_read_10 (uint32_t addr, uint16_t nb_sector)
 This function transfers the memory data (programmed in sbc_read_10) directly to the USB interface sector = 512 bytes. More...
 
Ctrl_status virtual_usb_write_10 (uint32_t addr, uint16_t nb_sector)
 This function transfers the USB data (programmed in sbc_write_10) directly to the memory interface sector = 512 bytes. More...
 
bool virtual_wr_protect (void)
 This function returns the write-protected mode Only used by memory removal with a HARDWARE-SPECIFIC write-protected detection. More...
 

Variables

static bool cram_init = false
 
static 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
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
Ctrl_status virtual_read_capacity ( uint32_t *  u32_nb_sector)

This function returns the address of the last valid sector.

Parameters
u32_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
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
Ctrl_status virtual_usb_read_10 ( uint32_t  addr,
uint16_t  nb_sector 
)

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
Returns
Ctrl_status It is ready -> CTRL_GOOD Memory unplug -> CTRL_NO_PRESENT Not initialized or changed -> CTRL_BUSY An error occurred -> CTRL_FAIL
Ctrl_status virtual_usb_write_10 ( uint32_t  addr,
uint16_t  nb_sector 
)

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
Returns
Ctrl_status It is ready -> CTRL_GOOD Memory unplug -> CTRL_NO_PRESENT Not initialized or changed -> CTRL_BUSY An error occurred -> CTRL_FAIL
bool virtual_wr_protect ( void  )

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

Warning
The customer must unplug the memory to change this write-protected mode.
Returns
true if the memory is protected

bool cram_init = false
static

Referenced by virtual_check_init().