scsi_decoder.h

Go to the documentation of this file.
00001 /* This file has been prepared for Doxygen automatic documentation generation.*/
00002 /*! \file scsi_decoder.h *******************************************************
00003  *
00004  * \brief
00005  *      This file is the scsi decoder
00006  *
00007  * \addtogroup usbstick
00008  *
00009  * \author
00010  *      Atmel Corporation: http://www.atmel.com \n
00011  *      Support email: avr@atmel.com
00012  ******************************************************************************/
00013 /* 
00014    Copyright (c) 2004  ATMEL Corporation
00015    All rights reserved.
00016 
00017    Redistribution and use in source and binary forms, with or without
00018    modification, are permitted provided that the following conditions are met:
00019 
00020    * Redistributions of source code must retain the above copyright
00021      notice, this list of conditions and the following disclaimer.
00022    * Redistributions in binary form must reproduce the above copyright
00023      notice, this list of conditions and the following disclaimer in
00024      the documentation and/or other materials provided with the
00025      distribution.
00026    * Neither the name of the copyright holders nor the names of
00027      contributors may be used to endorse or promote products derived
00028      from this software without specific prior written permission.
00029 
00030   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00031   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00032   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00033   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00034   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00035   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00036   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00037   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00038   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00039   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00040   POSSIBILITY OF SUCH DAMAGE.
00041 */
00042 
00043 /**
00044  \addtogroup usbstorage
00045  @{
00046 */
00047 #ifndef _SCSI_DECODER_H_
00048 #define _SCSI_DECODER_H_
00049 
00050 //_____ I N C L U D E S ____________________________________________________
00051 
00052 
00053 //_____ M A C R O S ________________________________________________________
00054 
00055 typedef struct
00056 {
00057   U8      key;
00058   U8      asc;
00059   U8      ascq;
00060 } s_scsi_sense;
00061 
00062 
00063 //_____ D E C L A R A T I O N S ____________________________________________
00064 
00065 Bool scsi_decode_command  (void);
00066 
00067 /****************************************************************************/
00068 /* Command for all SCSI device types                                        */
00069 /****************************************************************************/
00070 
00071 #define SBC_CMD_TEST_UNIT_READY                   (0x00)
00072 #define SBC_CMD_REQUEST_SENSE                     (0x03)
00073 #define SBC_CMD_FORMAT_UNIT                       (0x04)
00074 #define SBC_CMD_READ_6                            (0x08)
00075 #define SBC_CMD_INQUIRY                           (0x12)
00076 #define SBC_CMD_MODE_SELECT_6                     (0x15)
00077 #define SBC_CMD_MODE_SENSE_6                      (0x1A)
00078 #define SBC_CMD_START_STOP_UNIT                   (0x1B)
00079 #define SBC_CMD_RECEIVE_DIAGNOSTICS               (0x1C)
00080 #define SBC_CMD_SEND_DIAGNOSTIC                   (0x1D)
00081 #define SBC_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL      (0x1E)
00082 #define SBC_CMD_READ_LONG                         (0x23)
00083 #define SBC_CMD_READ_CAPACITY                     (0x25)
00084 #define SBC_CMD_READ_CD_ROM_CAPACITY              (0x25)
00085 #define SBC_CMD_READ_10                           (0x28)
00086 #define SBC_CMD_WRITE_10                          (0x2A)
00087 #define SBC_CMD_VERIFY_10                         (0x2F)
00088 #define SBC_CMD_SYNCHRONIZE_CACHE                 (0x35)
00089 #define SBC_CMD_WRITE_BUFFER                      (0x3B)
00090 #define SBC_CMD_CHANGE_DEFINITION                 (0x40)
00091 #define SBC_CMD_READ_TOC                          (0x43)
00092 #define SBC_CMD_MODE_SELECT_10                    (0x55)
00093 #define SBC_CMD_RESERVE_10                        (0x56)
00094 #define SBC_CMD_RELEASE_10                        (0x57)
00095 #define SBC_CMD_MODE_SENSE_10                     (0x5A)
00096 
00097 #define SBC_CONTROL_BYTE                          (0x00)
00098 #define SBC_CMD_DIR_IN                            (0x80)
00099 #define SBC_CMD_DIR_OUT                           (0x00)
00100 
00101 
00102 /****************************************************************************/
00103 /* Sense Key Code                                                           */
00104 /****************************************************************************/
00105 #define SBC_SENSE_KEY_NO_SENSE                        (0x00)
00106 #define SBC_SENSE_KEY_RECOVERED_ERROR                 (0x01)
00107 #define SBC_SENSE_KEY_NOT_READY                       (0x02)
00108 #define SBC_SENSE_KEY_MEDIUM_ERROR                    (0x03)
00109 #define SBC_SENSE_KEY_HARDWARE_ERROR                  (0x04)
00110 #define SBC_SENSE_KEY_ILLEGAL_REQUEST                 (0x05)
00111 #define SBC_SENSE_KEY_UNIT_ATTENTION                  (0x06)
00112 #define SBC_SENSE_KEY_DATA_PROTECT                    (0x07)
00113 #define SBC_SENSE_KEY_BLANK_CHECK                     (0x08)
00114 #define SBC_SENSE_KEY_VENDOR_SPECIFIC                 (0x09)
00115 #define SBC_SENSE_KEY_COPY_ABORTED                    (0x0A)
00116 #define SBC_SENSE_KEY_ABORTED_COMMAND                 (0x0B)
00117 #define SBC_SENSE_KEY_VOLUME_OVERFLOW                 (0x0D)
00118 #define SBC_SENSE_KEY_MISCOMPARE                      (0x0E)
00119 
00120 /****************************************************************************/
00121 /* ASC code assignments                                                     */
00122 /****************************************************************************/
00123 #define SBC_ASC_NO_ADDITIONAL_SENSE_INFORMATION       (0x00)
00124 #define SBC_ASC_LOGICAL_UNIT_NOT_READY                (0x04)
00125 #define SBC_ASC_INVALID_FIELD_IN_CDB                  (0x24)
00126 #define SBC_ASC_WRITE_PROTECTED                       (0x27)
00127 #define SBC_ASC_FORMAT_ERROR                          (0x31)
00128 #define SBC_ASC_INVALID_COMMAND_OPERATION_CODE        (0x20)
00129 #define SBC_ASC_NOT_READY_TO_READY_CHANGE             (0x28)
00130 #define SBC_ASC_MEDIUM_NOT_PRESENT                    (0x3A)
00131 
00132 /****************************************************************************/
00133 /* ASCQ code assignments                                                    */
00134 /****************************************************************************/
00135 #define SBC_ASCQ_FORMAT_COMMAND_FAILED                (0x01)
00136 #define SBC_ASCQ_INITIALIZING_COMMAND_REQUIRED        (0x02)
00137 #define SBC_ASCQ_OPERATION_IN_PROGRESS                (0x07)
00138 
00139 
00140 /****************************************************************************/
00141 /* REQUEST SENSE PARAMETERS                                                 */
00142 /****************************************************************************/
00143 #define SBC_RESPONSE_CODE_SENSE                       (0x70)
00144 #define SBC_ADDITIONAL_SENSE_LENGTH                   (0x0A)
00145 #define SBC_COMMAND_SPECIFIC_INFORMATION_3            (0x00)
00146 #define SBC_COMMAND_SPECIFIC_INFORMATION_2            (0x00)
00147 #define SBC_COMMAND_SPECIFIC_INFORMATION_1            (0x00)
00148 #define SBC_COMMAND_SPECIFIC_INFORMATION_0            (0x00)
00149 #define SBC_FIELD_REPLACEABLE_UNIT_CODE               (0x00)
00150 #define SBC_SENSE_KEY_SPECIFIC_2                      (0x00)
00151 #define SBC_SENSE_KEY_SPECIFIC_1                      (0x00)
00152 #define SBC_SENSE_KEY_SPECIFIC_0                      (0x00)
00153 
00154 /******* number of bytes of READ CAPACITY response *********/
00155 #define SBC_READ_CAPACITY_LENGTH                      (0x08)
00156 
00157 
00158 /****************************************************************************/
00159 /*MODE SENSE and REQUEST SENSE DEFINITIONS                                  */
00160 /****************************************************************************/
00161 
00162 /*************** Direct access medium type ****************/
00163 #define SBC_DEFAULT_MEDIUM_TYPE                       (0x00)
00164 #define SBC_FLEXIBLE_DISK_SINGLE_SIDED_UNSPECIFIED    (0x01)
00165 #define SBC_FLEXIBLE_DISK_DOUBLE_SIDED_UNSPECIFIED    (0x02)
00166 
00167 #define SBC_MEDIUM_TYPE                               SBC_DEFAULT_MEDIUM_TYPE
00168 
00169 #define SBC_DEV_SPEC_PARAM_WR_ENABLE                  (0x00)
00170 #define SBC_DEV_SPEC_PARAM_WR_PROTECT                 (0x80)
00171 #define SBC_BLOCK_DESCRIPTOR_LENGTH                   (0x00)
00172 
00173 #define SBC_MSK_DBD                                   (0x08)
00174 #define SBC_MSK_PAGE_CONTROL                          (0xC0)
00175 #define SBC_MSK_PAGE_CODE                             (0x3F)
00176 
00177 
00178 /************ General Page Code paramaters *****************/
00179 #define SBC_PAGE_CODE_READ_WRITE_ERROR_RECOVERY       (0x01)
00180 #define SBC_PAGE_CODE_FORMAT_DEVICE                   (0x03)
00181 #define SBC_PAGE_CODE_FLEXIBLE_DISK                   (0x05)
00182 #define SBC_PAGE_CODE_INFORMATIONAL_EXCEPTIONS        (0x1C)
00183 #define SBC_PAGE_CODE_ALL                             (0x3F)
00184 
00185 
00186 #define SBC_PAGE_LENGTH_INFORMATIONAL_EXCEPTIONS      (0x0A)
00187 #define SBC_PAGE_LENGTH_READ_WRITE_ERROR_RECOVERY     (0x0A)
00188 #define SBC_PAGE_LENGTH_FLEXIBLE_DISK                 (0x1E)
00189 #define SBC_PAGE_LENGTH_FORMAT_DEVICE                 (0x16)
00190 
00191 
00192 
00193 #define SBC_MODE_DATA_LENGTH_INFORMATIONAL_EXCEPTIONS   (SBC_PAGE_LENGTH_INFORMATIONAL_EXCEPTIONS + 2 + 3)
00194 #define SBC_MODE_DATA_LENGTH_READ_WRITE_ERROR_RECOVERY  (SBC_PAGE_LENGTH_READ_WRITE_ERROR_RECOVERY + 2 + 3 )
00195 #define SBC_MODE_DATA_LENGTH_FLEXIBLE_DISK              (SBC_PAGE_LENGTH_FLEXIBLE_DISK + 2 + 3 )
00196 #define SBC_MODE_DATA_LENGTH_FORMAT_DEVICE              (SBC_PAGE_LENGTH_FORMAT_DEVICE + 2 + 3 )
00197 /*SBC_PAGE_LENGTH_FLEXIBLE_DISK + 2  + \*/
00198 #define SBC_MODE_DATA_LENGTH_CODE_ALL                 (SBC_PAGE_LENGTH_READ_WRITE_ERROR_RECOVERY + 2 + \
00199                                                        SBC_PAGE_LENGTH_INFORMATIONAL_EXCEPTIONS + 2 + \
00200                                                        SBC_BLOCK_DESCRIPTOR_LENGTH + \
00201                                                        + 3 )
00202 
00203 /*                                                       SBC_MODE_DATA_LENGTH_FORMAT_DEVICE + 2 + \*/
00204 /****** Information exceptions control page parameters *****/
00205 #define SBC_MRIE                                      (0x05)
00206 
00207 /*************** Format device page parameters *************/
00208 #define SBC_TRACK_PER_ZONE_MSB                        (0x00)
00209 #define SBC_TRACK_PER_ZONE_LSB                        (0x00)
00210 #define SBC_ALTERNATE_SECTORS_PER_ZONE_MSB            (0x00)
00211 #define SBC_ALTERNATE_SECTORS_PER_ZONE_LSB            (0x00)
00212 #define SBC_ALTERNATE_TRACK_PER_ZONE_MSB              (0x00)
00213 #define SBC_ALTERNATE_TRACK_PER_ZONE_LSB              (0x00)
00214 #define SBC_ALTERNATE_TRACK_PER_LU_MSB                (0x00)
00215 #define SBC_ALTERNATE_TRACK_PER_LU_LSB                (0x00)
00216 
00217 /************* Flexible Disk page Parameters ***************/
00218 #define SBC_TRANSFER_RATE_MSB                         (0x13)
00219 #define SBC_TRANSFER_RATE_LSB                         (0x88)
00220 /* 1388h    5 Mbit/s   */
00221 /* 07D0h    2 Mbit/s   */
00222 /* 03E8h    1 Mbit/s   */
00223 /* 01F4h    500 kbit/s */
00224 /* 012Ch    300 kbit/s */
00225 /* 00FAh    250 kbit/s */
00226 
00227 #define SBC_NUMBER_OF_HEAD                            (0x04)
00228 #define SBC_SECTOR_PER_TRACK                          (0x20)
00229 #define SBC_DATA_BYTE_PER_SECTOR_MSB                  (0x02)
00230 #define SBC_DATA_BYTE_PER_SECTOR_LSB                  (0x00)
00231 #define SBC_NUMBER_OF_CYLINDERS_MSB                   (0x01)
00232 #define SBC_NUMBER_OF_CYLINDERS_LSB                   (0xE9)
00233 #define SBC_STARTING_CYLINDER_WRITE_COMPENSATION_MSB  (0x00)
00234 #define SBC_STARTING_CYLINDER_WRITE_COMPENSATION_LSB  (0x00)
00235 #define SBC_STARTING_CYLINDER_REDUCED_WRITE_MSB       (0x00)
00236 #define SBC_STARTING_CYLINDER_REDUCED_WRITE_LSB       (0x00)
00237 #define SBC_DEVICE_STEP_RATE_MSB                      (0x00)
00238 #define SBC_DEVICE_STEP_RATE_LSB                      (0x00)
00239 #define SBC_DEVICE_STEP_PULSE_WIDTH                   (0x00)
00240 #define SBC_HEAD_SETTLE_DELAY_MSB                     (0x00)
00241 #define SBC_HEAD_SETTLE_DELAY_LSB                     (0x00)
00242 #define SBC_MOTOR_ON_DELAY                            (0x00)
00243 #define SBC_MOTOR_OFF_DELAY                           (0x00)
00244 #define SBC_STEP_PULSE_PER_CYLINDER                   (0x00)
00245 #define SBC_WRITE_COMPENSATION                        (0x00)
00246 #define SBC_HEAD_LOAD_DELAY                           (0x00)
00247 #define SBC_HEAD_UNLOAD_DELAY                         (0x00)
00248 #define SBC_PIN34_PIN2                                (0x00)
00249 #define SBC_PIN4_PIN1                                 (0x00)
00250 #define SBC_MEDIUM_ROTATION_RATE_MSB                  (0x00)
00251 #define SBC_MEDIUM_ROTATION_RATE_LSB                  (0x00)
00252 
00253 /************ Read/Write Error Recovery parameters**********/
00254 #define SBC_READ_RETRY_COUNT                          (0x03)
00255 #define SBC_WRITE_RETRY_COUNT                         (0x80)
00256 #define SBC_CORRECTION_SPAN                           (0x00)
00257 #define SBC_HEAD_OFFSET_COUNT                         (0x00)
00258 #define SBC_DATA_STROBE_OFFSET                        (0x00)
00259 #define SBC_RECOVERY_LIMIT_MSB                        (0x00)
00260 #define SBC_RECOVERY_LIMIT_LSB                        (0x00)
00261 
00262 
00263 /*_____ D E F I N I T I O N ________________________________________________*/
00264 
00265 #define SBC_MAX_INQUIRY_DATA                          (0x60) // value ?
00266 
00267 struct sbc_st_std_inquiry_data
00268 {
00269   Byte    DeviceType : 5;
00270   Byte    PeripheralQualifier : 3;
00271 
00272   Byte    Reserved1 : 7;
00273   Byte    RemovableMedia : 1;
00274 
00275   Byte    Version;
00276 
00277   Byte    Reserved3 : 5;
00278   Byte    NormACA : 1;
00279   Byte    Obsolete0 : 1;
00280   Byte    AERC : 1;
00281 
00282   Byte    Reserved4[3];
00283 
00284   Byte    SoftReset : 1;
00285   Byte    CommandQueue : 1;
00286   Byte    Reserved5 : 1;
00287   Byte    LinkedCommands : 1;
00288   Byte    Synchronous : 1;
00289   Byte    Wide16Bit : 1;
00290   Byte    Wide32Bit : 1;
00291   Byte    RelativeAddressing : 1;
00292 };
00293 
00294 
00295 //_____ D E C L A R A T I O N S ____________________________________________
00296 
00297 #define Sbc_send_failed()                 (g_scsi_status = COMMAND_FAILED)
00298 #define Sbc_send_check_condition()        (g_scsi_status = CHECK_CONDITION)
00299 #define Sbc_send_good()                   (g_scsi_status = COMMAND_PASSED)
00300 
00301 /*#define Sbc_valid_write_usb(length)       ( Usb_set_TXRDY(), \
00302                                             dCBWDataTransferLength -= length, \
00303                                             while (!Usb_tx_complete()),\
00304                                             Usb_clear_TXCMPL() )
00305 */
00306 #define Sbc_build_sense(skey, sasc, sascq)   ( g_scsi_sense.key  = skey, \
00307                                                g_scsi_sense.asc  = sasc, \
00308                                                g_scsi_sense.ascq = sascq )
00309 
00310 #define Sbc_valid_write_usb(length)          ( Usb_send_in(), \
00311                                                g_scsi_data_remaining -= length )
00312 
00313 
00314 #define COMMAND_PASSED                0x00
00315 #define COMMAND_FAILED                0x01
00316 #define CHECK_CONDITION               0x02
00317 #define PHASE_ERROR                   0x02
00318 
00319 
00320 Bool  sbc_inquiry (void);
00321 Bool  sbc_mode_sense( Bool sense_10 );
00322 Bool  sbc_mode_select_6 (void);
00323 Bool  sbc_request_sense (void);
00324 Bool  sbc_format (void);
00325 Bool  sbc_write_10 (void);
00326 Bool  sbc_read_10  (void);
00327 Bool  sbc_test_unit_ready(void);
00328 Bool  sbc_read_capacity(void);
00329 Bool  sbc_prevent_allow_medium_removal(void);
00330 
00331 void  sbc_lun_status_is_good(void);
00332 void  sbc_lun_status_is_busy_or_change(void);
00333 void  sbc_lun_status_is_not_present(void);
00334 void  sbc_lun_status_is_fail(void);
00335 void  sbc_lun_status_is_protected(void);
00336 
00337 #endif /* _SCSI_DECODER_H_ */
00338 /** @} */

Generated on Mon Apr 11 14:23:36 2011 for Contiki 2.5 by  doxygen 1.6.1