73 #define Ctrl_access_lock() ctrl_access_lock() 77 #define Ctrl_access_unlock() xSemaphoreGive(ctrl_access_semphr) 94 #define Ctrl_access_lock() true 98 #define Ctrl_access_unlock() 102 #endif // FREERTOS_USED 113 #if ACCESS_USB == true && ACCESS_MEM_TO_RAM == true 114 #define Lun_desc_entry(lun) \ 116 TPASTE3(Lun_, lun, _test_unit_ready),\ 117 TPASTE3(Lun_, lun, _read_capacity),\ 118 TPASTE3(Lun_, lun, _unload),\ 119 TPASTE3(Lun_, lun, _wr_protect),\ 120 TPASTE3(Lun_, lun, _removal),\ 121 TPASTE3(Lun_, lun, _usb_read_10),\ 122 TPASTE3(Lun_, lun, _usb_write_10),\ 123 TPASTE3(Lun_, lun, _mem_2_ram),\ 124 TPASTE3(Lun_, lun, _ram_2_mem),\ 125 TPASTE3(LUN_, lun, _NAME)\ 127 #elif ACCESS_USB == true 128 #define Lun_desc_entry(lun) \ 130 TPASTE3(Lun_, lun, _test_unit_ready),\ 131 TPASTE3(Lun_, lun, _read_capacity),\ 132 TPASTE3(Lun_, lun, _unload),\ 133 TPASTE3(Lun_, lun, _wr_protect),\ 134 TPASTE3(Lun_, lun, _removal),\ 135 TPASTE3(Lun_, lun, _usb_read_10),\ 136 TPASTE3(Lun_, lun, _usb_write_10),\ 137 TPASTE3(LUN_, lun, _NAME)\ 139 #elif ACCESS_MEM_TO_RAM == true 140 #define Lun_desc_entry(lun) \ 142 TPASTE3(Lun_, lun, _test_unit_ready),\ 143 TPASTE3(Lun_, lun, _read_capacity),\ 144 TPASTE3(Lun_, lun, _unload),\ 145 TPASTE3(Lun_, lun, _wr_protect),\ 146 TPASTE3(Lun_, lun, _removal),\ 147 TPASTE3(Lun_, lun, _mem_2_ram),\ 148 TPASTE3(Lun_, lun, _ram_2_mem),\ 149 TPASTE3(LUN_, lun, _NAME)\ 152 #define Lun_desc_entry(lun) \ 154 TPASTE3(Lun_, lun, _test_unit_ready),\ 155 TPASTE3(Lun_, lun, _read_capacity),\ 156 TPASTE3(Lun_, lun, _unload),\ 157 TPASTE3(Lun_, lun, _wr_protect),\ 158 TPASTE3(Lun_, lun, _removal),\ 159 TPASTE3(LUN_, lun, _NAME)\ 169 bool (*wr_protect)(void);
170 bool (*removal)(void);
171 #if ACCESS_USB == true 175 #if ACCESS_MEM_TO_RAM == true 183 # ifndef Lun_0_unload 184 # define Lun_0_unload NULL 189 # ifndef Lun_1_unload 190 # define Lun_1_unload NULL 195 # ifndef Lun_2_unload 196 # define Lun_2_unload NULL 201 # ifndef Lun_3_unload 202 # define Lun_3_unload NULL 207 # ifndef Lun_4_unload 208 # define Lun_4_unload NULL 213 # ifndef Lun_5_unload 214 # define Lun_5_unload NULL 219 # ifndef Lun_6_unload 220 # define Lun_6_unload NULL 225 # ifndef Lun_7_unload 226 # define Lun_7_unload NULL 235 #if GLOBAL_WR_PROTECT == true 247 bool ctrl_access_init(
void)
250 if (!ctrl_access_semphr)
253 vSemaphoreCreateBinary(ctrl_access_semphr);
256 if (!ctrl_access_semphr)
return false;
267 static bool ctrl_access_lock(
void)
270 if (!ctrl_access_semphr)
return false;
278 #endif // FREERTOS_USED 283 #if MEM_USB == ENABLE 284 # ifndef Lun_usb_get_lun 285 # define Lun_usb_get_lun() host_get_lun() 316 (lun <
MAX_LUN) ? lun_desc[lun].test_unit_ready() :
318 #if LUN_USB == ENABLE 338 (lun <
MAX_LUN) ? lun_desc[lun].read_capacity(u32_nb_sector) :
340 #if LUN_USB == ENABLE 377 #if !MAX_LUN || !defined(Lun_usb_unload) 386 (lun_desc[lun].unload ?
387 lun_desc[lun].unload(unload) : !unload) :
412 (lun <
MAX_LUN) ? lun_desc[lun].wr_protect() :
414 #if LUN_USB == ENABLE 437 (lun <
MAX_LUN) ? lun_desc[lun].removal() :
439 #if LUN_USB == ENABLE 471 #if ACCESS_USB == true 487 (lun <
MAX_LUN) ? lun_desc[lun].usb_read_10(addr, nb_sector) :
507 (lun <
MAX_LUN) ? lun_desc[lun].usb_write_10(addr, nb_sector) :
520 #endif // ACCESS_USB == true 523 #if ACCESS_MEM_TO_RAM == true 542 (lun <
MAX_LUN) ? lun_desc[lun].mem_2_ram(addr, ram) :
544 #if LUN_USB == ENABLE 569 (lun <
MAX_LUN) ? lun_desc[lun].ram_2_mem(addr, ram) :
571 #if LUN_USB == ENABLE 586 #endif // ACCESS_MEM_TO_RAM == true 589 #if ACCESS_STREAM == true 596 #if ACCESS_MEM_TO_MEM == true 603 static U8 sector_buf[FS_512B];
615 #endif // ACCESS_MEM_TO_MEM == true 634 #endif // ACCESS_STREAM == true
U8 get_cur_lun(void)
Returns the current LUN.
#define UNUSED(v)
Marking v as a unused parameter or value.
#define Lun_usb_removal()
uint16_t U16
16-bit unsigned integer.
#define Lun_usb_get_lun()
Ctrl_status ram_2_memory(U8 lun, U32 addr, const void *ram)
Copies 1 data sector from RAM to the memory.
Ctrl_status mem_test_unit_ready(U8 lun)
Tests the memory state and initializes the memory if required.
Ctrl_status usb_2_memory(U8 lun, U32 addr, U16 nb_sector)
Transfers data from USB to the memory.
#define Lun_usb_test_unit_ready(lun)
U8 mem_sector_size(U8 lun)
Returns the size of the physical sector.
#define memory_start_write_action(nb_sectors)
U8 get_nb_lun(void)
Returns the number of LUNs.
Commonly used includes, types and macros.
Ctrl_status memory_2_ram(U8 lun, U32 addr, void *ram)
Copies 1 data sector from the memory to RAM.
#define Lun_usb_read_sector_size(lun)
COMPILER_ALIGNED(32)
Buffer to receive data.
uint32_t U32
32-bit unsigned integer.
Ctrl_status memory_2_usb(U8 lun, U32 addr, U16 nb_sector)
Transfers data from the memory to USB.
#define memory_stop_write_action()
#define MAX_LUN
Number of static LUNs.
#define Lun_usb_ram_2_mem(addr, ram)
#define LUN_USB
Disable Host Mass-Storage Memory.
#define Ctrl_access_unlock()
Unlocks accesses to LUNs.
#define memory_stop_read_action()
#define Lun_usb_wr_protect(lun)
#define xSemaphoreTake(xSemaphore, xBlockTime)
Ctrl_status
Status returned by CTRL_ACCESS interfaces.
unsigned char bool
Boolean.
bool mem_wr_protect(U8 lun)
Returns the write-protection state of the memory.
bool mem_unload(U8 lun, bool unload)
Unload/load the medium.
uint8_t U8
8-bit unsigned integer.
#define Lun_usb_read_capacity(lun, nb_sect)
bool g_wr_protect
Write protect.
Ctrl_status stream_state(U8 id)
Returns the state of a streaming data transfer.
#define Lun_usb_mem_2_ram(addr, ram)
bool mem_removal(U8 lun)
Tells whether the memory is removable.
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.
#define Ctrl_access_lock()
Locks accesses to LUNs.
const char * mem_name(U8 lun)
Returns a pointer to the LUN name.
#define memory_start_read_action(nb_sectors)
U16 stream_stop(U8 id)
Stops a streaming data transfer.
Ctrl_status mem_read_capacity(U8 lun, U32 *u32_nb_sector)
Returns the address of the last valid sector (512 bytes) in the memory.
#define LUN_ID_0
First static LUN.