ATMEL: scsi_decoder.h Source File

- Main Page
- Modules
- Data Structures
- Files
- Related Pages

# scsi_decoder.h

Go to the documentation of this file.

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