00001
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 #include "conf_access.h"
00051
00052
00053 #if MEM_USB == ENABLE
00054
00055 #include "usb_drv.h"
00056 #include "host_mem.h"
00057 #include "scsi_decoder.h"
00058 #include "usb_host_task.h"
00059 #include "host_mass_storage_task.h"
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070 static U8 buf_cmd[31];
00071
00072 U8 host_selected_lun;
00073
00074 U8 g_pipe_ms_in;
00075 U8 g_pipe_ms_out;
00076 U8 g_u8_sector_size;
00077 U8 g_b_read_run = FALSE;
00078 U32 g_u32_read_addr;
00079 U16 g_u16_read_sector;
00080
00081
00082
00083
00084 static Ctrl_status host_read_10_ram_stop(void);
00085
00086
00089 static void host_ms_stall_management(U8 pipe)
00090 {
00091 U16 nb;
00092
00093 host_clear_endpoint_feature(Host_get_pipe_endpoint_number(pipe) | MSK_EP_DIR);
00094 Host_ack_stall(g_pipe_ms_in);
00095 Host_reset_data_toggle(g_pipe_ms_in);
00096
00097
00098 nb = sizeof(buf_cmd);
00099 host_get_data(g_pipe_ms_in, &nb, buf_cmd);
00100
00101 host_ms_request_sense();
00102 }
00103
00104
00111 Ctrl_status host_ms_inquiry(void)
00112 {
00113 Ctrl_status status;
00114 U16 nb;
00115
00116 if (!Is_host_ms_configured()) return CTRL_FAIL;
00117
00118 if (g_b_read_run && (status = host_read_10_ram_stop()) != CTRL_GOOD) return status;
00119
00120 buf_cmd[0] = 'U';
00121 buf_cmd[1] = 'S';
00122 buf_cmd[2] = 'B';
00123 buf_cmd[3] = 'C';
00124 buf_cmd[4] = 0x64;
00125 buf_cmd[5] = 0x00;
00126 buf_cmd[6] = 0x00;
00127 buf_cmd[7] = 0x00;
00128 buf_cmd[8] = 0x24;
00129 buf_cmd[9] = 0x00;
00130 buf_cmd[10] = 0x00;
00131 buf_cmd[11] = 0x00;
00132 buf_cmd[12] = SBC_CMD_DIR_IN;
00133 buf_cmd[13] = host_selected_lun;
00134 buf_cmd[14] = 0x06;
00135 buf_cmd[15] = SBC_CMD_INQUIRY;
00136 buf_cmd[16] = 0x00;
00137 buf_cmd[17] = 0x00;
00138 buf_cmd[18] = 0x00;
00139 buf_cmd[19] = 0x24;
00140 buf_cmd[20] = 0x00;
00141 buf_cmd[21] = 0x00;
00142 buf_cmd[22] = 0x00;
00143 buf_cmd[23] = 0x00;
00144 buf_cmd[24] = 0x00;
00145 buf_cmd[25] = 0x00;
00146 buf_cmd[26] = 0x00;
00147 buf_cmd[27] = 0x00;
00148 buf_cmd[28] = 0x00;
00149 buf_cmd[29] = 0x00;
00150 buf_cmd[30] = 0x00;
00151
00152
00153 if (host_send_data(g_pipe_ms_out, sizeof(buf_cmd), buf_cmd) != PIPE_GOOD)
00154 return CTRL_FAIL;
00155
00156
00157 nb = sizeof(buf_cmd);
00158 if (host_get_data(g_pipe_ms_in, &nb, buf_cmd) != PIPE_GOOD)
00159 return CTRL_FAIL;
00160
00161
00162 nb = sizeof(buf_cmd);
00163 if (host_get_data(g_pipe_ms_in, &nb, buf_cmd) != PIPE_GOOD)
00164 return CTRL_FAIL;
00165
00166 return (buf_cmd[12] == COMMAND_PASSED) ? CTRL_GOOD : CTRL_FAIL;
00167 }
00168
00169
00172 U8 host_ms_request_sense(void)
00173 {
00174 volatile U32 delay;
00175 U16 nb;
00176 U8 sense_key, sense_key_add;
00177 Status_t status;
00178
00179 if (!Is_host_ms_configured()) return SBC_SENSE_KEY_NO_SENSE;
00180
00181 if (g_b_read_run && host_read_10_ram_stop() != CTRL_GOOD) return SBC_SENSE_KEY_MEDIUM_ERROR;
00182
00183 buf_cmd[0] = 'U';
00184 buf_cmd[1] = 'S';
00185 buf_cmd[2] = 'B';
00186 buf_cmd[3] = 'C';
00187 buf_cmd[4] = 0x65;
00188 buf_cmd[5] = 0x00;
00189 buf_cmd[6] = 0x00;
00190 buf_cmd[7] = 0x00;
00191 buf_cmd[8] = 0x12;
00192 buf_cmd[9] = 0x00;
00193 buf_cmd[10] = 0x00;
00194 buf_cmd[11] = 0x00;
00195 buf_cmd[12] = SBC_CMD_DIR_IN;
00196 buf_cmd[13] = host_selected_lun;
00197 buf_cmd[14] = 0x06;
00198 buf_cmd[15] = SBC_CMD_REQUEST_SENSE;
00199 buf_cmd[16] = 0x00;
00200 buf_cmd[17] = 0x00;
00201 buf_cmd[18] = 0x00;
00202 buf_cmd[19] = 0x12;
00203 buf_cmd[20] = 0x00;
00204 buf_cmd[21] = 0x00;
00205 buf_cmd[22] = 0x00;
00206 buf_cmd[23] = 0x00;
00207 buf_cmd[24] = 0x00;
00208 buf_cmd[25] = 0x00;
00209 buf_cmd[26] = 0x00;
00210 buf_cmd[27] = 0x00;
00211 buf_cmd[28] = 0x00;
00212 buf_cmd[29] = 0x00;
00213 buf_cmd[30] = 0x00;
00214
00215
00216 if (host_send_data(g_pipe_ms_out, sizeof(buf_cmd), buf_cmd) != PIPE_GOOD)
00217 return CTRL_FAIL;
00218
00219
00220 for (delay = 100000; delay; delay--);
00221 nb = sizeof(buf_cmd);
00222 status = host_get_data(g_pipe_ms_in, &nb, buf_cmd);
00223 if (status == PIPE_STALL)
00224 {
00225 host_ms_stall_management(g_pipe_ms_in);
00226 return CTRL_FAIL;
00227 }
00228 else if (status != PIPE_GOOD)
00229 return SBC_SENSE_KEY_NO_SENSE;
00230
00231 sense_key = buf_cmd[2] & 0x0F;
00232 sense_key_add = buf_cmd[12];
00233
00234
00235 nb = sizeof(buf_cmd);
00236 if (host_get_data(g_pipe_ms_in, &nb, buf_cmd) != PIPE_GOOD)
00237 return CTRL_FAIL;
00238
00239 if (buf_cmd[12] != COMMAND_PASSED) return SBC_SENSE_KEY_NO_SENSE;
00240
00241 switch (sense_key)
00242 {
00243 case SBC_SENSE_KEY_NOT_READY:
00244 if (sense_key_add == SBC_ASC_MEDIUM_NOT_PRESENT)
00245 return CTRL_NO_PRESENT;
00246 break;
00247 case SBC_SENSE_KEY_UNIT_ATTENTION:
00248 if (sense_key_add == SBC_ASC_NOT_READY_TO_READY_CHANGE)
00249 return CTRL_BUSY;
00250 if (sense_key_add == SBC_ASC_MEDIUM_NOT_PRESENT)
00251 return CTRL_NO_PRESENT;
00252 break;
00253 case SBC_SENSE_KEY_HARDWARE_ERROR:
00254 case SBC_SENSE_KEY_DATA_PROTECT:
00255 break;
00256 default:
00257 sense_key = SBC_SENSE_KEY_NO_SENSE;
00258 break;
00259 }
00260
00261 return sense_key;
00262 }
00263
00264
00267 U8 host_get_lun(void)
00268 {
00269 if (!Is_host_ms_configured()) return 0;
00270
00271 data_stage[0] = 0;
00272 host_ms_get_max_lun();
00273
00274 return data_stage[0] + 1;
00275 }
00276
00277
00285 Ctrl_status host_test_unit_ready(U8 lun)
00286 {
00287 Ctrl_status status;
00288 U16 nb;
00289 Status_t get_data_status;
00290
00291 host_selected_lun = lun;
00292
00293 if (!Is_host_ms_configured()) return CTRL_FAIL;
00294
00295 if (g_b_read_run && (status = host_read_10_ram_stop()) != CTRL_GOOD) return status;
00296
00297 buf_cmd[0] = 'U';
00298 buf_cmd[1] = 'S';
00299 buf_cmd[2] = 'B';
00300 buf_cmd[3] = 'C';
00301 buf_cmd[4] = 0x60;
00302 buf_cmd[5] = 0x00;
00303 buf_cmd[6] = 0x00;
00304 buf_cmd[7] = 0x00;
00305 buf_cmd[8] = 0x00;
00306 buf_cmd[9] = 0x00;
00307 buf_cmd[10] = 0x00;
00308 buf_cmd[11] = 0x00;
00309 buf_cmd[12] = SBC_CMD_DIR_OUT;
00310 buf_cmd[13] = host_selected_lun;
00311 buf_cmd[14] = 0x06;
00312 buf_cmd[15] = SBC_CMD_TEST_UNIT_READY;
00313 buf_cmd[16] = 0x00;
00314 buf_cmd[17] = 0x00;
00315 buf_cmd[18] = 0x00;
00316 buf_cmd[19] = 0x00;
00317 buf_cmd[20] = 0x00;
00318 buf_cmd[21] = 0x00;
00319 buf_cmd[22] = 0x00;
00320 buf_cmd[23] = 0x00;
00321 buf_cmd[24] = 0x00;
00322 buf_cmd[25] = 0x00;
00323 buf_cmd[26] = 0x00;
00324 buf_cmd[27] = 0x00;
00325 buf_cmd[28] = 0x00;
00326 buf_cmd[29] = 0x00;
00327 buf_cmd[30] = 0x00;
00328
00329
00330 if (host_send_data(g_pipe_ms_out, sizeof(buf_cmd), buf_cmd) != PIPE_GOOD)
00331 return CTRL_FAIL;
00332
00333
00334 nb = sizeof(buf_cmd);
00335 get_data_status = host_get_data(g_pipe_ms_in, &nb, buf_cmd);
00336 if (get_data_status == PIPE_STALL)
00337 {
00338 host_ms_stall_management(g_pipe_ms_in);
00339 return CTRL_FAIL;
00340 }
00341 else if (get_data_status != PIPE_GOOD)
00342 return CTRL_FAIL;
00343
00344 if (buf_cmd[12] != COMMAND_PASSED)
00345 {
00346 if (host_ms_request_sense() == CTRL_BUSY)
00347 return CTRL_BUSY;
00348 return CTRL_FAIL;
00349 }
00350
00351 Host_set_device_ready();
00352
00353 return CTRL_GOOD;
00354 }
00355
00356
00365 Ctrl_status host_read_capacity(U8 lun, U32 *u32_nb_sector)
00366 {
00367 Ctrl_status status;
00368 U16 nb;
00369 Status_t get_data_status;
00370
00371 host_selected_lun = lun;
00372 g_u8_sector_size = 0;
00373
00374 if (!Is_host_ms_configured()) return CTRL_FAIL;
00375
00376 if (g_b_read_run && (status = host_read_10_ram_stop()) != CTRL_GOOD) return status;
00377
00378 buf_cmd[0] = 'U';
00379 buf_cmd[1] = 'S';
00380 buf_cmd[2] = 'B';
00381 buf_cmd[3] = 'C';
00382 buf_cmd[4] = 0x61;
00383 buf_cmd[5] = 0x00;
00384 buf_cmd[6] = 0x00;
00385 buf_cmd[7] = 0x00;
00386 buf_cmd[8] = 0x08;
00387 buf_cmd[9] = 0x00;
00388 buf_cmd[10] = 0x00;
00389 buf_cmd[11] = 0x00;
00390 buf_cmd[12] = SBC_CMD_DIR_IN;
00391 buf_cmd[13] = lun;
00392 buf_cmd[14] = 0x0A;
00393 buf_cmd[15] = SBC_CMD_READ_CAPACITY_10;
00394 buf_cmd[16] = 0x00;
00395 buf_cmd[17] = 0x00;
00396 buf_cmd[18] = 0x00;
00397 buf_cmd[19] = 0x00;
00398 buf_cmd[20] = 0x00;
00399 buf_cmd[21] = 0x00;
00400 buf_cmd[22] = 0x00;
00401 buf_cmd[23] = 0x00;
00402 buf_cmd[24] = 0x00;
00403 buf_cmd[25] = 0x00;
00404 buf_cmd[26] = 0x00;
00405 buf_cmd[27] = 0x00;
00406 buf_cmd[28] = 0x00;
00407 buf_cmd[29] = 0x00;
00408 buf_cmd[30] = 0x00;
00409
00410
00411 if (host_send_data(g_pipe_ms_out, sizeof(buf_cmd), buf_cmd) != PIPE_GOOD)
00412 return CTRL_FAIL;
00413
00414
00415 nb = sizeof(buf_cmd);
00416 get_data_status = host_get_data(g_pipe_ms_in, &nb, buf_cmd);
00417 if (get_data_status == PIPE_STALL)
00418 {
00419 host_ms_stall_management(g_pipe_ms_in);
00420 return CTRL_FAIL;
00421 }
00422 else if (get_data_status != PIPE_GOOD)
00423 return CTRL_FAIL;
00424
00425 *u32_nb_sector = sbc_format_scsi_to_mcu_data(32, *(U32 *)(buf_cmd + 0));
00426 g_u8_sector_size = sbc_format_scsi_to_mcu_data(32, *(U32 *)(buf_cmd + 4)) >> 9;
00427
00428
00429 nb = sizeof(buf_cmd);
00430 if (host_get_data(g_pipe_ms_in, &nb, buf_cmd) != PIPE_GOOD)
00431 return CTRL_FAIL;
00432
00433 if (buf_cmd[12] != COMMAND_PASSED)
00434 return CTRL_FAIL;
00435
00436 Host_set_device_ready();
00437
00438 return CTRL_GOOD;
00439 }
00440
00441
00445 U8 host_read_sector_size(U8 lun)
00446 {
00447 return g_u8_sector_size;
00448 }
00449
00450
00456 Bool host_wr_protect(U8 lun)
00457 {
00458 U16 nb;
00459 Bool write_protect;
00460 Status_t status;
00461
00462 host_selected_lun = lun;
00463
00464 if (!Is_host_ms_configured() ||
00465 g_u8_sector_size != 1 ||
00466 (g_b_read_run && host_read_10_ram_stop() != CTRL_GOOD))
00467 return TRUE;
00468
00469 buf_cmd[0] = 'U';
00470 buf_cmd[1] = 'S';
00471 buf_cmd[2] = 'B';
00472 buf_cmd[3] = 'C';
00473 buf_cmd[4] = 0x63;
00474 buf_cmd[5] = 0x00;
00475 buf_cmd[6] = 0x00;
00476 buf_cmd[7] = 0x00;
00477 buf_cmd[8] = 0x0C;
00478 buf_cmd[9] = 0x00;
00479 buf_cmd[10] = 0x00;
00480 buf_cmd[11] = 0x00;
00481 buf_cmd[12] = SBC_CMD_DIR_IN;
00482 buf_cmd[13] = host_selected_lun;
00483 buf_cmd[14] = 0x06;
00484 buf_cmd[15] = SBC_CMD_MODE_SENSE_6;
00485 buf_cmd[16] = 0x00;
00486 buf_cmd[17] = 0x3F;
00487 buf_cmd[18] = 0x00;
00488 buf_cmd[19] = 0x0C;
00489 buf_cmd[20] = 0x00;
00490 buf_cmd[21] = 0x00;
00491 buf_cmd[22] = 0x00;
00492 buf_cmd[23] = 0x00;
00493 buf_cmd[24] = 0x00;
00494 buf_cmd[25] = 0x00;
00495 buf_cmd[26] = 0x00;
00496 buf_cmd[27] = 0x00;
00497 buf_cmd[28] = 0x00;
00498 buf_cmd[29] = 0x00;
00499 buf_cmd[30] = 0x00;
00500
00501
00502 if (host_send_data(g_pipe_ms_out, sizeof(buf_cmd), buf_cmd) != PIPE_GOOD)
00503 return CTRL_FAIL;
00504
00505
00506 nb = sizeof(buf_cmd);
00507 if (host_get_data(g_pipe_ms_in, &nb, buf_cmd) != PIPE_GOOD)
00508 return CTRL_FAIL;
00509
00510 write_protect = buf_cmd[2] >> 7;
00511
00512
00513 nb = sizeof(buf_cmd);
00514 status = host_get_data(g_pipe_ms_in, &nb, buf_cmd);
00515 if (status == PIPE_STALL)
00516 {
00517 host_ms_stall_management(g_pipe_ms_in);
00518 return FALSE;
00519 }
00520 else if (status != PIPE_GOOD)
00521 return FALSE;
00522
00523 if (buf_cmd[12] != COMMAND_PASSED) return FALSE;
00524
00525 return write_protect;
00526 }
00527
00528
00531 Bool host_removal(void)
00532 {
00533 return Is_host_ms_configured();
00534 }
00535
00536
00537
00538
00539 #if ACCESS_MEM_TO_RAM == ENABLED
00540
00550 Ctrl_status host_read_10_ram(U32 addr, void *ram)
00551 {
00552 Ctrl_status status;
00553 U16 nb;
00554 U16 u16_nb_byte_ignore_at_beg;
00555 U32 u32_host_ms_address;
00556 U32 u32_host_ms_sector;
00557
00558 if (!Is_host_ms_configured()) return CTRL_FAIL;
00559
00560
00561 if (!g_b_read_run || addr != g_u32_read_addr)
00562 {
00563 if (g_b_read_run && (status = host_read_10_ram_stop()) != CTRL_GOOD) return status;
00564
00565
00566 if( 0 == g_u8_sector_size )
00567 {
00568
00569 if( CTRL_GOOD != host_read_capacity( host_selected_lun, &u32_host_ms_sector))
00570 return CTRL_FAIL;
00571 }
00572
00573
00574 u32_host_ms_address = addr / g_u8_sector_size;
00575
00576
00577 u16_nb_byte_ignore_at_beg = (addr % g_u8_sector_size) * HOST_SECTOR_SIZE;
00578
00579
00580 u32_host_ms_sector = g_u8_sector_size * HOST_SECTOR_SIZE;
00581
00582
00583 g_u32_read_addr = addr;
00584 g_u16_read_sector = (u32_host_ms_address + 1) * g_u8_sector_size - addr;
00585
00586 buf_cmd[0] = 'U';
00587 buf_cmd[1] = 'S';
00588 buf_cmd[2] = 'B';
00589 buf_cmd[3] = 'C';
00590 buf_cmd[4] = 0x66;
00591 buf_cmd[5] = 0x00;
00592 buf_cmd[6] = 0x00;
00593 buf_cmd[7] = 0x00;
00594 buf_cmd[8] = LSB0W(u32_host_ms_sector);
00595 buf_cmd[9] = LSB1W(u32_host_ms_sector);
00596 buf_cmd[10] = LSB2W(u32_host_ms_sector);
00597 buf_cmd[11] = LSB3W(u32_host_ms_sector);
00598 buf_cmd[12] = SBC_CMD_DIR_IN;
00599 buf_cmd[13] = host_selected_lun;
00600 buf_cmd[14] = 0x0A;
00601 buf_cmd[15] = SBC_CMD_READ_10;
00602 buf_cmd[16] = 0x00;
00603 buf_cmd[17] = MSB0W(u32_host_ms_address);
00604 buf_cmd[18] = MSB1W(u32_host_ms_address);
00605 buf_cmd[19] = MSB2W(u32_host_ms_address);
00606 buf_cmd[20] = MSB3W(u32_host_ms_address);
00607 buf_cmd[21] = 0x00;
00608 buf_cmd[22] = 0x00;
00609 buf_cmd[23] = 0x01;
00610 buf_cmd[24] = 0x00;
00611 buf_cmd[25] = 0x00;
00612 buf_cmd[26] = 0x00;
00613 buf_cmd[27] = 0x00;
00614 buf_cmd[28] = 0x00;
00615 buf_cmd[29] = 0x00;
00616 buf_cmd[30] = 0x00;
00617
00618
00619 host_send_data(g_pipe_ms_out, sizeof(buf_cmd), buf_cmd);
00620
00621
00622 if (host_get_data(g_pipe_ms_in, &u16_nb_byte_ignore_at_beg, NULL) == PIPE_STALL)
00623 {
00624 host_ms_stall_management(g_pipe_ms_in);
00625 return CTRL_FAIL;
00626 }
00627
00628 g_b_read_run = TRUE;
00629 }
00630
00631
00632 nb = HOST_SECTOR_SIZE;
00633 if (host_get_data(g_pipe_ms_in, &nb, ram) == PIPE_STALL)
00634 {
00635 host_ms_stall_management(g_pipe_ms_in);
00636 return CTRL_FAIL;
00637 }
00638
00639 g_u32_read_addr++;
00640 if (!--g_u16_read_sector) return host_read_10_ram_stop();
00641
00642 return CTRL_GOOD;
00643 }
00644
00645
00656 Ctrl_status host_read_10_extram(U32 addr, void *ram, U8 nb_sector)
00657 {
00658 Ctrl_status status;
00659 U16 nb;
00660 U32 u32_host_ms_sector;
00661
00662 if (!Is_host_ms_configured()) return CTRL_FAIL;
00663
00664 if ( g_u8_sector_size != 1) {
00665
00666 while( nb_sector != 0 ) {
00667 status = host_read_10_ram(addr, ram);
00668 if (status != CTRL_GOOD) return status;
00669 nb_sector--;
00670 addr++;
00671 ram = (U8*)ram + HOST_SECTOR_SIZE;
00672 }
00673 return CTRL_GOOD;
00674 }
00675
00676 if (g_b_read_run && (status = host_read_10_ram_stop()) != CTRL_GOOD) return status;
00677
00678
00679
00680 u32_host_ms_sector = (U32)nb_sector * HOST_SECTOR_SIZE;
00681
00682
00683 g_u32_read_addr = addr;
00684
00685 buf_cmd[0] = 'U';
00686 buf_cmd[1] = 'S';
00687 buf_cmd[2] = 'B';
00688 buf_cmd[3] = 'C';
00689 buf_cmd[4] = 0x66;
00690 buf_cmd[5] = 0x00;
00691 buf_cmd[6] = 0x00;
00692 buf_cmd[7] = 0x00;
00693 buf_cmd[8] = LSB0W(u32_host_ms_sector);
00694 buf_cmd[9] = LSB1W(u32_host_ms_sector);
00695 buf_cmd[10] = LSB2W(u32_host_ms_sector);
00696 buf_cmd[11] = LSB3W(u32_host_ms_sector);
00697 buf_cmd[12] = SBC_CMD_DIR_IN;
00698 buf_cmd[13] = host_selected_lun;
00699 buf_cmd[14] = 0x0A;
00700 buf_cmd[15] = SBC_CMD_READ_10;
00701 buf_cmd[16] = 0x00;
00702 buf_cmd[17] = MSB0W(addr);
00703 buf_cmd[18] = MSB1W(addr);
00704 buf_cmd[19] = MSB2W(addr);
00705 buf_cmd[20] = MSB3W(addr);
00706 buf_cmd[21] = 0x00;
00707 buf_cmd[22] = 0x00;
00708 buf_cmd[23] = nb_sector;
00709 buf_cmd[24] = 0x00;
00710 buf_cmd[25] = 0x00;
00711 buf_cmd[26] = 0x00;
00712 buf_cmd[27] = 0x00;
00713 buf_cmd[28] = 0x00;
00714 buf_cmd[29] = 0x00;
00715 buf_cmd[30] = 0x00;
00716
00717
00718 host_send_data(g_pipe_ms_out, sizeof(buf_cmd), buf_cmd);
00719
00720
00721 nb = HOST_SECTOR_SIZE;
00722 while( nb_sector != 0 ) {
00723 if (host_get_data(g_pipe_ms_in, &nb, ram) == PIPE_STALL)
00724 {
00725 host_ms_stall_management(g_pipe_ms_in);
00726 return CTRL_FAIL;
00727 }
00728 nb_sector--;
00729 ram = (U8*)ram + HOST_SECTOR_SIZE;
00730 }
00731
00732
00733 nb = sizeof(buf_cmd);
00734 host_get_data(g_pipe_ms_in, &nb, buf_cmd);
00735
00736 return (buf_cmd[12] == COMMAND_PASSED) ? CTRL_GOOD : CTRL_FAIL;
00737 }
00738
00739
00740
00747 Ctrl_status host_read_10_ram_stop(void)
00748 {
00749 U16 nb;
00750
00751 g_b_read_run = FALSE;
00752
00753
00754 g_u16_read_sector *= HOST_SECTOR_SIZE;
00755 if (host_get_data(g_pipe_ms_in, &g_u16_read_sector, NULL) == PIPE_STALL)
00756 {
00757 host_ms_stall_management(g_pipe_ms_in);
00758 return CTRL_FAIL;
00759 }
00760
00761
00762 nb = sizeof(buf_cmd);
00763 host_get_data(g_pipe_ms_in, &nb, buf_cmd);
00764
00765 return (buf_cmd[12] == COMMAND_PASSED) ? CTRL_GOOD : CTRL_FAIL;
00766 }
00767
00768
00778 Ctrl_status host_write_10_ram(U32 addr, const void *ram)
00779 {
00780 return host_write_10_extram(addr, ram, 1);
00781 }
00782
00793 Ctrl_status host_write_10_extram(U32 addr, const void *ram, U8 nb_sector)
00794 {
00795 Ctrl_status status;
00796 U16 nb;
00797 U32 dCBWDataTransferLength;
00798
00799 if (!Is_host_ms_configured() ||
00800 g_u8_sector_size != 1)
00801 return CTRL_FAIL;
00802
00803 if (g_b_read_run && (status = host_read_10_ram_stop()) != CTRL_GOOD) return status;
00804
00805 dCBWDataTransferLength = (U32)nb_sector * HOST_SECTOR_SIZE;
00806
00807 buf_cmd[0] = 'U';
00808 buf_cmd[1] = 'S';
00809 buf_cmd[2] = 'B';
00810 buf_cmd[3] = 'C';
00811 buf_cmd[4] = 0x66;
00812 buf_cmd[5] = 0x00;
00813 buf_cmd[6] = 0x00;
00814 buf_cmd[7] = 0x00;
00815 buf_cmd[8] = LSB0W(dCBWDataTransferLength);
00816 buf_cmd[9] = LSB1W(dCBWDataTransferLength);
00817 buf_cmd[10] = LSB2W(dCBWDataTransferLength);
00818 buf_cmd[11] = LSB3W(dCBWDataTransferLength);
00819 buf_cmd[12] = SBC_CMD_DIR_OUT;
00820 buf_cmd[13] = host_selected_lun;
00821 buf_cmd[14] = 0x0A;
00822 buf_cmd[15] = SBC_CMD_WRITE_10;
00823 buf_cmd[16] = 0x00;
00824 buf_cmd[17] = MSB0W(addr);
00825 buf_cmd[18] = MSB1W(addr);
00826 buf_cmd[19] = MSB2W(addr);
00827 buf_cmd[20] = MSB3W(addr);
00828 buf_cmd[21] = 0x00;
00829 buf_cmd[22] = 0x00;
00830 buf_cmd[23] = nb_sector;
00831 buf_cmd[24] = 0x00;
00832 buf_cmd[25] = 0x00;
00833 buf_cmd[26] = 0x00;
00834 buf_cmd[27] = 0x00;
00835 buf_cmd[28] = 0x00;
00836 buf_cmd[29] = 0x00;
00837 buf_cmd[30] = 0x00;
00838
00839
00840 host_send_data(g_pipe_ms_out, sizeof(buf_cmd), buf_cmd);
00841
00842
00843 while( nb_sector!= 0 )
00844 {
00845 if (host_send_data(g_pipe_ms_out, HOST_SECTOR_SIZE, ram) == PIPE_STALL)
00846 {
00847 host_ms_stall_management(g_pipe_ms_out);
00848 return CTRL_FAIL;
00849 }
00850 nb_sector--;
00851 ram = (U8*)ram + HOST_SECTOR_SIZE;
00852 }
00853
00854
00855 nb = sizeof(buf_cmd);
00856 host_get_data(g_pipe_ms_in, &nb, buf_cmd);
00857
00858 return (buf_cmd[12] == COMMAND_PASSED) ? CTRL_GOOD : CTRL_FAIL;
00859 }
00860
00861 #endif // ACCESS_MEM_TO_RAM == ENABLED
00862
00863
00864 #endif // MEM_USB == ENABLE