Common abstraction layer for memory interfaces.
It provides interfaces between: Memory and USB, Memory and RAM, Memory and Memory. Common API for XMEGA and UC3.
Macros | |
#define | SECTOR_SIZE 512 |
Enumerations | |
enum | Ctrl_status { CTRL_GOOD = PASS, CTRL_FAIL = FAIL, CTRL_NO_PRESENT = FAIL + 1, CTRL_BUSY = FAIL + 2 } |
Status returned by CTRL_ACCESS interfaces. More... | |
Variables | |
bool | g_wr_protect |
Write protect. More... | |
LUN IDs | |
#define | LUN_ID_0 (0) |
First static LUN. More... | |
#define | LUN_ID_1 (LUN_ID_0 + LUN_0) |
#define | LUN_ID_2 (LUN_ID_1 + LUN_1) |
#define | LUN_ID_3 (LUN_ID_2 + LUN_2) |
#define | LUN_ID_4 (LUN_ID_3 + LUN_3) |
#define | LUN_ID_5 (LUN_ID_4 + LUN_4) |
#define | LUN_ID_6 (LUN_ID_5 + LUN_5) |
#define | LUN_ID_7 (LUN_ID_6 + LUN_6) |
#define | MAX_LUN (LUN_ID_7 + LUN_7) |
Number of static LUNs. More... | |
#define | LUN_ID_USB (MAX_LUN) |
First dynamic LUN (USB host mass storage). More... | |
Control Interface | |
U8 | get_nb_lun (void) |
Returns the number of LUNs. More... | |
U8 | get_cur_lun (void) |
Returns the current LUN. More... | |
Ctrl_status | mem_test_unit_ready (U8 lun) |
Tests the memory state and initializes the memory if required. More... | |
Ctrl_status | mem_read_capacity (U8 lun, U32 *u32_nb_sector) |
Returns the address of the last valid sector (512 bytes) in the memory. More... | |
U8 | mem_sector_size (U8 lun) |
Returns the size of the physical sector. More... | |
bool | mem_unload (U8 lun, bool unload) |
Unload/load the medium. More... | |
bool | mem_wr_protect (U8 lun) |
Returns the write-protection state of the memory. More... | |
bool | mem_removal (U8 lun) |
Tells whether the memory is removable. More... | |
const char * | mem_name (U8 lun) |
Returns a pointer to the LUN name. More... | |
MEM <-> USB Interface | |
Ctrl_status | memory_2_usb (U8 lun, U32 addr, U16 nb_sector) |
Transfers data from the memory to USB. More... | |
Ctrl_status | usb_2_memory (U8 lun, U32 addr, U16 nb_sector) |
Transfers data from USB to the memory. More... | |
MEM <-> RAM Interface | |
Ctrl_status | memory_2_ram (U8 lun, U32 addr, void *ram) |
Copies 1 data sector from the memory to RAM. More... | |
Ctrl_status | ram_2_memory (U8 lun, U32 addr, const void *ram) |
Copies 1 data sector from RAM to the memory. More... | |
Streaming MEM <-> MEM Interface | |
Ctrl_status | stream_mem_to_mem (U8 src_lun, U32 src_addr, U8 dest_lun, U32 dest_addr, U16 nb_sector) |
Copies data from one memory to another. More... | |
Ctrl_status | stream_state (U8 id) |
Returns the state of a streaming data transfer. More... | |
U16 | stream_stop (U8 id) |
Stops a streaming data transfer. More... | |
#define | ID_STREAM_ERR 0xFF |
Erroneous streaming data transfer ID. More... | |
#define ID_STREAM_ERR 0xFF |
Erroneous streaming data transfer ID.
#define LUN_ID_0 (0) |
First static LUN.
Referenced by get_cur_lun().
#define LUN_ID_USB (MAX_LUN) |
First dynamic LUN (USB host mass storage).
Referenced by disk_initialize(), main(), mem_read_capacity(), mem_sector_size(), mem_test_unit_ready(), mem_unload(), and mem_wr_protect().
Number of static LUNs.
Referenced by disk_initialize(), get_nb_lun(), mem_name(), mem_read_capacity(), mem_removal(), mem_sector_size(), mem_test_unit_ready(), mem_unload(), mem_wr_protect(), memory_2_ram(), memory_2_usb(), ram_2_memory(), and usb_2_memory().
#define SECTOR_SIZE 512 |
enum Ctrl_status |
U8 get_cur_lun | ( | void | ) |
U8 get_nb_lun | ( | void | ) |
Returns the number of LUNs.
References Ctrl_access_lock, Ctrl_access_unlock, Lun_usb_get_lun, and MAX_LUN.
const char* mem_name | ( | U8 | lun | ) |
Returns a pointer to the LUN name.
lun | Logical Unit Number. |
References ENABLE, LUN_USB, LUN_USB_NAME, MAX_LUN, NULL, and UNUSED.
Referenced by udi_msc_spc_inquiry().
Ctrl_status mem_read_capacity | ( | U8 | lun, |
U32 * | u32_nb_sector | ||
) |
Returns the address of the last valid sector (512 bytes) in the memory.
lun | Logical Unit Number. |
u32_nb_sector | Pointer to the address of the last valid sector. |
References Ctrl_access_lock, Ctrl_access_unlock, CTRL_FAIL, LUN_ID_USB, Lun_usb_read_capacity, MAX_LUN, and status.
Referenced by disk_ioctl(), disk_read(), disk_write(), and udi_msc_sbc_read_capacity().
Tells whether the memory is removable.
lun | Logical Unit Number. |
true
if the memory is removable, else false
. References Ctrl_access_lock, Ctrl_access_unlock, Lun_usb_removal, MAX_LUN, and UNUSED.
Referenced by udi_msc_spc_inquiry().
Returns the size of the physical sector.
lun | Logical Unit Number. |
References Ctrl_access_lock, Ctrl_access_unlock, ENABLE, LUN_ID_USB, LUN_USB, Lun_usb_read_sector_size, and MAX_LUN.
Referenced by disk_ioctl(), disk_read(), and disk_write().
Ctrl_status mem_test_unit_ready | ( | U8 | lun | ) |
Tests the memory state and initializes the memory if required.
The TEST UNIT READY SCSI primary command allows an application client to poll a LUN until it is ready without having to allocate memory for returned data.
This command may be used to check the media status of LUNs with removable media.
lun | Logical Unit Number. |
References Ctrl_access_lock, Ctrl_access_unlock, CTRL_FAIL, LUN_ID_USB, Lun_usb_test_unit_ready, MAX_LUN, and status.
Referenced by disk_initialize(), disk_ioctl(), disk_status(), and udi_msc_spc_testunitready_global().
Unload/load the medium.
lun | Logical Unit Number. |
unload | true to unload the medium, false to load the medium. |
true
if unload/load success, else false
. References Ctrl_access_lock, Ctrl_access_unlock, ENABLE, LUN_ID_USB, LUN_USB, MAX_LUN, and UNUSED.
Referenced by udi_msc_sbc_start_stop().
Returns the write-protection state of the memory.
lun | Logical Unit Number. |
true
if the memory is write-protected, else false
.References Ctrl_access_lock, Ctrl_access_unlock, LUN_ID_USB, Lun_usb_wr_protect, and MAX_LUN.
Referenced by disk_initialize(), udi_msc_sbc_trans(), and udi_msc_spc_mode_sense().
Ctrl_status memory_2_ram | ( | U8 | lun, |
U32 | addr, | ||
void * | ram | ||
) |
Copies 1 data sector from the memory to RAM.
lun | Logical Unit Number. |
addr | Address of first memory sector to read. |
ram | Pointer to RAM buffer to write. |
References Ctrl_access_lock, Ctrl_access_unlock, CTRL_FAIL, Lun_usb_mem_2_ram, MAX_LUN, memory_start_read_action, memory_stop_read_action, status, and UNUSED.
Referenced by disk_read(), and stream_mem_to_mem().
Ctrl_status memory_2_usb | ( | U8 | lun, |
U32 | addr, | ||
U16 | nb_sector | ||
) |
Transfers data from the memory to USB.
lun | Logical Unit Number. |
addr | Address of first memory sector to read. |
nb_sector | Number of sectors to transfer. |
References Ctrl_access_lock, Ctrl_access_unlock, CTRL_FAIL, MAX_LUN, memory_start_read_action, memory_stop_read_action, and status.
Referenced by udi_msc_process_trans().
Ctrl_status ram_2_memory | ( | U8 | lun, |
U32 | addr, | ||
const void * | ram | ||
) |
Copies 1 data sector from RAM to the memory.
lun | Logical Unit Number. |
addr | Address of first memory sector to write. |
ram | Pointer to RAM buffer to read. |
References Ctrl_access_lock, Ctrl_access_unlock, CTRL_FAIL, Lun_usb_ram_2_mem, MAX_LUN, memory_start_write_action, memory_stop_write_action, status, and UNUSED.
Referenced by disk_write(), and stream_mem_to_mem().
Ctrl_status stream_mem_to_mem | ( | U8 | src_lun, |
U32 | src_addr, | ||
U8 | dest_lun, | ||
U32 | dest_addr, | ||
U16 | nb_sector | ||
) |
Copies data from one memory to another.
src_lun | Source Logical Unit Number. |
src_addr | Source address of first memory sector to read. |
dest_lun | Destination Logical Unit Number. |
dest_addr | Destination address of first memory sector to write. |
nb_sector | Number of sectors to copy. |
References COMPILER_ALIGNED, CTRL_GOOD, memory_2_ram(), ram_2_memory(), sector_buf, and status.
Ctrl_status stream_state | ( | U8 | id | ) |
Ctrl_status usb_2_memory | ( | U8 | lun, |
U32 | addr, | ||
U16 | nb_sector | ||
) |
Transfers data from USB to the memory.
lun | Logical Unit Number. |
addr | Address of first memory sector to write. |
nb_sector | Number of sectors to transfer. |
References Ctrl_access_lock, Ctrl_access_unlock, CTRL_FAIL, MAX_LUN, memory_start_write_action, memory_stop_write_action, and status.
Referenced by udi_msc_process_trans().
bool g_wr_protect |
Write protect.