64 U8 g_scsi_command[16];
66 U32 g_scsi_data_remaining;
69 FLASH U8 g_sbc_product_id[16] = SBC_PRODUCT_ID;
70 FLASH U8 g_sbc_revision_id[4] = SBC_REVISION_ID;
74 s_scsi_sense g_scsi_sense;
77 FLASH
struct sbc_st_std_inquiry_data sbc_std_inquiry_data =
121 static void send_informational_exceptions_page (
void);
122 static void send_read_write_error_recovery_page (U8);
123 static void sbc_header_mode_sense( Bool b_sense_10 , U8 u8_data_length );
142 if (g_scsi_command[0] == SBC_CMD_WRITE_10)
144 Scsi_start_write_action();
145 status = sbc_write_10();
146 Scsi_stop_write_action();
149 if (g_scsi_command[0] == SBC_CMD_READ_10 )
151 Scsi_start_read_action();
152 status = sbc_read_10();
153 Scsi_stop_read_action();
157 switch (g_scsi_command[0])
159 case SBC_CMD_REQUEST_SENSE:
163 case SBC_CMD_INQUIRY:
167 case SBC_CMD_TEST_UNIT_READY:
168 return sbc_test_unit_ready();
171 case SBC_CMD_READ_CAPACITY:
172 return sbc_read_capacity();
175 case SBC_CMD_MODE_SENSE_6:
179 case SBC_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL:
183 case SBC_CMD_VERIFY_10:
186 case SBC_CMD_MODE_SENSE_10:
190 case SBC_CMD_FORMAT_UNIT:
192 case SBC_CMD_MODE_SELECT_6:
197 case SBC_CMD_START_STOP_UNIT:
198 case SBC_CMD_SEND_DIAGNOSTIC:
199 case SBC_CMD_READ_LONG:
200 case SBC_CMD_SYNCHRONIZE_CACHE:
201 case SBC_CMD_WRITE_BUFFER:
202 case SBC_CMD_RESERVE_10:
203 case SBC_CMD_RELEASE_10:
207 Sbc_build_sense(SBC_SENSE_KEY_ILLEGAL_REQUEST, SBC_ASC_INVALID_COMMAND_OPERATION_CODE, 0x00);
233 U8 allocation_length, i;
234 U8 request_sens_output[18];
236 allocation_length = g_scsi_command[4];
239 request_sens_output[0] = SBC_RESPONSE_CODE_SENSE;
240 request_sens_output[1] = 0x00;
241 request_sens_output[2] = g_scsi_sense.key;
243 request_sens_output[3] = 0x00;
244 request_sens_output[4] = 0x00;
245 request_sens_output[5] = 0x00;
246 request_sens_output[6] = 0x00;
248 request_sens_output[7] = SBC_ADDITIONAL_SENSE_LENGTH;
249 request_sens_output[8] = SBC_COMMAND_SPECIFIC_INFORMATION_3;
250 request_sens_output[9] = SBC_COMMAND_SPECIFIC_INFORMATION_2;
251 request_sens_output[10] = SBC_COMMAND_SPECIFIC_INFORMATION_1;
252 request_sens_output[11] = SBC_COMMAND_SPECIFIC_INFORMATION_0;
254 request_sens_output[12] = g_scsi_sense.asc;
255 request_sens_output[13] = g_scsi_sense.ascq;
257 request_sens_output[14] = SBC_FIELD_REPLACEABLE_UNIT_CODE;
258 request_sens_output[15] = SBC_SENSE_KEY_SPECIFIC_2;
259 request_sens_output[16] = SBC_SENSE_KEY_SPECIFIC_1;
260 request_sens_output[17] = SBC_SENSE_KEY_SPECIFIC_0;
263 for( i=0 ; i<allocation_length ; i++ )
267 Sbc_valid_write_usb( allocation_length );
293 U8 allocation_length, i;
301 if( (0 == (g_scsi_command[1] & 0x03) )
302 && (0 == g_scsi_command[2] ) )
307 allocation_length = g_scsi_command[4];
308 if (allocation_length > SBC_MAX_INQUIRY_DATA)
310 allocation_length = SBC_MAX_INQUIRY_DATA;
314 ptr = (FLASH U8*) &sbc_std_inquiry_data;
316 for ( i=0 ; ((i != 36) && (allocation_length > i)); i++)
320 ptr = (FLASH U8 *) &g_sbc_vendor_id;
324 ptr = (FLASH U8 *) &g_sbc_product_id;
328 ptr = (FLASH U8 *) &g_sbc_revision_id;
332 #else // AVRGCC does not support point to PGM space
333 #warning with avrgcc assumes devices descriptors are stored in the lower 64Kbytes of on-chip flash memory
351 while( allocation_length > i )
355 Sbc_valid_write_usb(64);
356 allocation_length -= 64;
363 Sbc_valid_write_usb(allocation_length);
370 Sbc_build_sense(SBC_SENSE_KEY_ILLEGAL_REQUEST, SBC_ASC_INVALID_FIELD_IN_CDB, 0x00);
376 Bool sbc_test_unit_ready(
void)
384 case CTRL_NO_PRESENT :
401 Bool sbc_read_capacity (
void)
403 _MEM_TYPE_SLOW_ U32 mem_size_nb_sector;
417 Sbc_valid_write_usb(SBC_READ_CAPACITY_LENGTH);
422 case CTRL_NO_PRESENT :
439 Bool sbc_read_10 (
void)
444 MSB0(mass_addr) = g_scsi_command[2];
445 MSB1(mass_addr) = g_scsi_command[3];
446 MSB2(mass_addr) = g_scsi_command[4];
447 MSB3(mass_addr) = g_scsi_command[5];
449 MSB(mass_size) = g_scsi_command[7];
450 LSB(mass_size) = g_scsi_command[8];
454 switch (
memory_2_usb( usb_LUN , mass_addr, mass_size ) )
458 g_scsi_data_remaining = g_scsi_data_remaining - (512 * (Uint32)mass_size);
462 case CTRL_NO_PRESENT :
487 Bool sbc_write_10 (
void)
492 MSB0(mass_addr) = g_scsi_command[2];
493 MSB1(mass_addr) = g_scsi_command[3];
494 MSB2(mass_addr) = g_scsi_command[4];
495 MSB3(mass_addr) = g_scsi_command[5];
497 MSB(mass_size) = g_scsi_command[7];
498 LSB(mass_size) = g_scsi_command[8];
506 #warning For Win98 data must be read to avoid blocking
514 g_scsi_data_remaining = g_scsi_data_remaining - (512 * (Uint32)mass_size);
518 case CTRL_NO_PRESENT :
560 U8 allocation_length;
563 allocation_length = g_scsi_command[8];
565 allocation_length = g_scsi_command[4];
568 switch ( g_scsi_command[2] & SBC_MSK_PAGE_CODE )
570 case SBC_PAGE_CODE_INFORMATIONAL_EXCEPTIONS:
571 sbc_header_mode_sense( b_sense_10 , SBC_MODE_DATA_LENGTH_INFORMATIONAL_EXCEPTIONS );
572 send_informational_exceptions_page();
573 Sbc_valid_write_usb(SBC_MODE_DATA_LENGTH_INFORMATIONAL_EXCEPTIONS + 1);
576 case SBC_PAGE_CODE_READ_WRITE_ERROR_RECOVERY:
577 sbc_header_mode_sense( b_sense_10 , SBC_MODE_DATA_LENGTH_READ_WRITE_ERROR_RECOVERY );
578 send_read_write_error_recovery_page(allocation_length);
579 Sbc_valid_write_usb(SBC_MODE_DATA_LENGTH_READ_WRITE_ERROR_RECOVERY + 1);
582 case SBC_PAGE_CODE_ALL:
583 sbc_header_mode_sense( b_sense_10 , SBC_MODE_DATA_LENGTH_CODE_ALL );
586 if (allocation_length == 8)
588 Sbc_valid_write_usb(8);
594 if (allocation_length == 4)
596 Sbc_valid_write_usb(4);
601 send_read_write_error_recovery_page(allocation_length);
602 if (allocation_length > 12)
604 send_informational_exceptions_page();
605 Sbc_valid_write_usb(SBC_MODE_DATA_LENGTH_CODE_ALL + 1);
609 Sbc_valid_write_usb(allocation_length);
615 Sbc_build_sense(SBC_SENSE_KEY_ILLEGAL_REQUEST, SBC_ASC_INVALID_FIELD_IN_CDB, 0x00);
631 void sbc_header_mode_sense( Bool b_sense_10 , U8 u8_data_length )
677 void send_informational_exceptions_page (
void)
706 void send_read_write_error_recovery_page (U8 length)
752 Sbc_build_sense(SBC_SENSE_KEY_NO_SENSE, SBC_ASC_NO_ADDITIONAL_SENSE_INFORMATION, 0x00);
760 Sbc_build_sense(SBC_SENSE_KEY_NOT_READY, SBC_ASC_MEDIUM_NOT_PRESENT, 0x00);
768 Sbc_build_sense(SBC_SENSE_KEY_UNIT_ATTENTION, SBC_ASC_NOT_READY_TO_READY_CHANGE, 0x00 );
776 Sbc_build_sense(SBC_SENSE_KEY_HARDWARE_ERROR, SBC_ASC_NO_ADDITIONAL_SENSE_INFORMATION, 0x00);
784 Sbc_build_sense(SBC_SENSE_KEY_DATA_PROTECT, SBC_ASC_WRITE_PROTECTED, 0x00);
This file contains the possible external configuration of the USB.
Bool scsi_decode_command(void)
SCSI decoder function.
void sbc_lun_status_is_busy_or_change(void)
This fonction send the UFI status busy and change.
void sbc_lun_status_is_protected(void)
This fonction send the UFI status FAIL because write protection.
This file is the scsi decoder.
#define LSB(u16)
Least significant byte of u16.
This file contains the USB driver routines.
#define Usb_write_byte(byte)
writes byte in FIFO for current endpoint
Bool sbc_prevent_allow_medium_removal(void)
This function manages the SCSI PREVENT ALLOW MEDIUM REMOVAL command (0x1E)
Ctrl_status mem_read_capacity(U8 lun, U32 _MEM_TYPE_SLOW_ *u32_nb_sector)
This fonction return the capacity of the memory.
void sbc_lun_status_is_fail(void)
This fonction send the UFI status FAIL.
Bool mem_wr_protect(U8 lun)
This fonction return is the write protected mode.
#define TRUE
An alias for one, used for clarity.
Ctrl_status mem_test_unit_ready(U8 lun)
This fonction test the state of memory, and start the initialisation of the memory.
Bool sbc_inquiry(void)
This function manages the SCSI INQUIRY command (0x12)
void sbc_lun_status_is_not_present(void)
This fonction send the UFI status "lun not present".
Ctrl_status memory_2_usb(U8 lun, U32 addr, U16 nb_sector)
This fonction returns a pointer to the LUN name.
This file contains the interface :
Bool sbc_mode_sense(Bool b_sense_10)
This function manages the SCSI MODE SENSE command (0x1A for sense 6 and 0x5A for sense 10) ...
void sbc_lun_status_is_good(void)
This fonction send the UFI status GOOD.
Ctrl_status usb_2_memory(U8 lun, U32 addr, U16 nb_sector)
This fonction trabsfer a data from usb to memory.
Bool sbc_request_sense(void)
This function manages the SCSI REQUEST SENSE command (0x03)
#define SBC_VENDOR_ID
------— Device Mass Storage Identifiers Signature --------------------—
#define FALSE
An alias for zero, used for clarity.
This file contains the interface :
#define MSB(u16)
Most significant byte of u16.