Ctrl_status ram_2_memory(U8 lun, U32 addr, const void *ram) { Ctrl_status status; #if MAX_LUN==0 UNUSED(lun); #endif if (!Ctrl_access_lock()) return CTRL_FAIL; memory_start_write_action(1); status = #if MAX_LUN (lun < MAX_LUN) ? lun_desc[lun].ram_2_mem(addr, ram) : #endif #if LUN_USB == ENABLE Lun_usb_ram_2_mem(addr, ram); #else CTRL_FAIL; #endif memory_stop_write_action(); Ctrl_access_unlock(); return status; }
bool mem_unload(U8 lun, bool unload) { bool unloaded; #if !MAX_LUN || !defined(Lun_usb_unload) UNUSED(lun); #endif if (!Ctrl_access_lock()) return false; unloaded = #if MAX_LUN (lun < MAX_LUN) ? (lun_desc[lun].unload ? lun_desc[lun].unload(unload) : !unload) : #endif #if LUN_USB == ENABLE # if defined(Lun_usb_unload) Lun_usb_unload(lun - LUN_ID_USB, unload); # else !unload; /* Can not unload: load success, unload fail */ # endif #else false; /* No mem, unload/load fail */ #endif Ctrl_access_unlock(); return unloaded; }
Bool mem_wr_protect (U8 lun) { Bool wr_protect; if (!Ctrl_access_lock ()) return TRUE; if (lun == 1) { wr_protect = TRUE; } wr_protect = #if MAX_LUN (lun < MAX_LUN) ? lun_desc[lun].wr_protect () : #endif #if LUN_USB == ENABLE Lun_usb_wr_protect (lun - LUN_ID_USB); #else TRUE; #endif Ctrl_access_unlock (); return wr_protect; }
Ctrl_status memory_2_ram(U8 lun, U32 addr, void *ram, uint32_t numBlocks) { Ctrl_status status; #if MAX_LUN==0 UNUSED(lun); #endif if (!Ctrl_access_lock()) return CTRL_FAIL; memory_start_read_action(1); status = #if MAX_LUN (lun < MAX_LUN) ? lun_desc[lun].mem_2_ram(addr, ram, numBlocks) : #endif #if LUN_USB == ENABLE Lun_usb_mem_2_ram(addr, ram, numBlocks); #else CTRL_FAIL; #endif memory_stop_read_action(); Ctrl_access_unlock(); return status; }
Ctrl_status mem_test_unit_ready (U8 lun) { Ctrl_status status; if (!Ctrl_access_lock ()) return CTRL_FAIL; status = #if MAX_LUN (lun < MAX_LUN) ? lun_desc[lun].test_unit_ready () : #endif #if LUN_USB == ENABLE Lun_usb_test_unit_ready (lun - LUN_ID_USB); #else CTRL_FAIL; #endif Ctrl_access_unlock (); /* { U8 Text[10]; CI_StringOut ("STATUS "); switch (lun) { case 0: CI_StringOut (" UNCYP L0"); break; case 1: CI_StringOut (" ENCYP L1"); break; default: CI_StringOut (" *** ERROR LUN ***"); break; } switch (status) { case CTRL_GOOD : CI_StringOut (" CTRL_GOOD\r\n"); break; case CTRL_FAIL : CI_StringOut (" CTRL_FAIL\r\n"); break; case CTRL_NO_PRESENT : CI_StringOut (" CTRL_NO_PRESENT\r\n"); break; case CTRL_BUSY : CI_StringOut (" CTRL_BUSY\r\n"); break; } } */ return status; }
U8 get_nb_lun(void) { #if MEM_USB == ENABLE U8 nb_lun; if (!Ctrl_access_lock()) return MAX_LUN; nb_lun = MAX_LUN + host_get_lun(); Ctrl_access_unlock(); return nb_lun; #else return MAX_LUN; #endif }
Ctrl_status usb_2_memory(U8 lun, U32 addr, U16 nb_sector) { Ctrl_status status; if (!Ctrl_access_lock()) return CTRL_FAIL; memory_start_write_action(nb_sector); status = #if MAX_LUN (lun < MAX_LUN) ? lun_desc[lun].usb_write_10(addr, nb_sector) : #endif CTRL_FAIL; memory_stop_write_action(); Ctrl_access_unlock(); return status; }
U8 get_nb_lun(void) { #if MEM_USB == ENABLE # ifndef Lun_usb_get_lun # define Lun_usb_get_lun() host_get_lun() # endif U8 nb_lun; if (!Ctrl_access_lock()) return MAX_LUN; nb_lun = MAX_LUN + Lun_usb_get_lun(); Ctrl_access_unlock(); return nb_lun; #else return MAX_LUN; #endif }
bool mem_wr_protect(U8 lun) { bool wr_protect; if (!Ctrl_access_lock()) return true; wr_protect = #if MAX_LUN (lun < MAX_LUN) ? lun_desc[lun].wr_protect() : #endif #if LUN_USB == ENABLE Lun_usb_wr_protect(lun - LUN_ID_USB); #else true; #endif Ctrl_access_unlock(); return wr_protect; }
U8 mem_sector_size(U8 lun) { U8 sector_size; if (!Ctrl_access_lock()) return 0; sector_size = #if MAX_LUN (lun < MAX_LUN) ? 1 : #endif #if LUN_USB == ENABLE Lun_usb_read_sector_size(lun - LUN_ID_USB); #else 0; #endif Ctrl_access_unlock(); return sector_size; }
Ctrl_status mem_read_capacity(U8 lun, U32 *u32_nb_sector) { Ctrl_status status; if (!Ctrl_access_lock()) return CTRL_FAIL; status = #if MAX_LUN (lun < MAX_LUN) ? lun_desc[lun].read_capacity(u32_nb_sector) : #endif #if LUN_USB == ENABLE Lun_usb_read_capacity(lun - LUN_ID_USB, u32_nb_sector); #else CTRL_FAIL; #endif Ctrl_access_unlock(); return status; }
Ctrl_status mem_test_unit_ready(U8 lun) { Ctrl_status status; if (!Ctrl_access_lock()) return CTRL_FAIL; status = #if MAX_LUN (lun < MAX_LUN) ? lun_desc[lun].test_unit_ready() : #endif #if LUN_USB == ENABLE Lun_usb_test_unit_ready(lun - LUN_ID_USB); #else CTRL_FAIL; #endif Ctrl_access_unlock(); return status; }
Bool mem_removal(U8 lun) { Bool removal; if (!Ctrl_access_lock()) return TRUE; removal = #if MAX_LUN (lun < MAX_LUN) ? lun_desc[lun].removal() : #endif #if LUN_USB == ENABLE Lun_usb_removal(); #else TRUE; #endif Ctrl_access_unlock(); return removal; }
bool mem_removal(U8 lun) { bool removal; #if MAX_LUN==0 UNUSED(lun); #endif if (!Ctrl_access_lock()) return true; removal = #if MAX_LUN (lun < MAX_LUN) ? lun_desc[lun].removal() : #endif #if LUN_USB == ENABLE Lun_usb_removal(); #else true; #endif Ctrl_access_unlock(); return removal; }
Ctrl_status usb_2_memory (U8 lun, U32 addr, U16 nb_sector) { Ctrl_status status; if (!Ctrl_access_lock ()) return CTRL_FAIL; memory_start_write_action (nb_sector); status = #if MAX_LUN (lun < MAX_LUN) ? lun_desc[lun].usb_write_10 (addr, nb_sector) : #endif CTRL_FAIL; memory_stop_write_action (); Ctrl_access_unlock (); USB_Log_st.MSD_WriteCalls_u32++; USB_Log_st.MSD_BytesWrite_u32 += nb_sector; time ((time_t *) & USB_Log_st.MSD_LastWriteAccess_u32); return status; }
Ctrl_status memory_2_usb (U8 lun, U32 addr, U16 nb_sector) { Ctrl_status status; if (!Ctrl_access_lock ()) return CTRL_FAIL; memory_start_read_action (nb_sector); status = #if MAX_LUN (lun < MAX_LUN) ? lun_desc[lun].usb_read_10 (addr, nb_sector) : #endif CTRL_FAIL; memory_stop_read_action (); Ctrl_access_unlock (); USB_Log_st.MSD_ReadCalls_u32++; USB_Log_st.MSD_BytesRead_u32 += nb_sector; time ((time_t *) & USB_Log_st.MSD_LastReadAccess_u32); return status; }