Contiki 2.5
scsi_decoder.h
Go to the documentation of this file.
1 /* This file has been prepared for Doxygen automatic documentation generation.*/
2 /*! \file scsi_decoder.h *******************************************************
3  *
4  * \brief
5  * This file is the scsi decoder
6  *
7  * \addtogroup usbstick
8  *
9  * \author
10  * Atmel Corporation: http://www.atmel.com \n
11  * Support email: avr@atmel.com
12  ******************************************************************************/
13 /*
14  Copyright (c) 2004 ATMEL Corporation
15  All rights reserved.
16 
17  Redistribution and use in source and binary forms, with or without
18  modification, are permitted provided that the following conditions are met:
19 
20  * Redistributions of source code must retain the above copyright
21  notice, this list of conditions and the following disclaimer.
22  * Redistributions in binary form must reproduce the above copyright
23  notice, this list of conditions and the following disclaimer in
24  the documentation and/or other materials provided with the
25  distribution.
26  * Neither the name of the copyright holders nor the names of
27  contributors may be used to endorse or promote products derived
28  from this software without specific prior written permission.
29 
30  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
31  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
34  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
35  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
36  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
37  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
38  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
39  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
40  POSSIBILITY OF SUCH DAMAGE.
41 */
42 
43 /**
44  \addtogroup usbstorage
45  @{
46 */
47 #ifndef _SCSI_DECODER_H_
48 #define _SCSI_DECODER_H_
49 
50 //_____ I N C L U D E S ____________________________________________________
51 
52 
53 //_____ M A C R O S ________________________________________________________
54 
55 typedef struct
56 {
57  U8 key;
58  U8 asc;
59  U8 ascq;
60 } s_scsi_sense;
61 
62 
63 //_____ D E C L A R A T I O N S ____________________________________________
64 
65 Bool scsi_decode_command (void);
66 
67 /****************************************************************************/
68 /* Command for all SCSI device types */
69 /****************************************************************************/
70 
71 #define SBC_CMD_TEST_UNIT_READY (0x00)
72 #define SBC_CMD_REQUEST_SENSE (0x03)
73 #define SBC_CMD_FORMAT_UNIT (0x04)
74 #define SBC_CMD_READ_6 (0x08)
75 #define SBC_CMD_INQUIRY (0x12)
76 #define SBC_CMD_MODE_SELECT_6 (0x15)
77 #define SBC_CMD_MODE_SENSE_6 (0x1A)
78 #define SBC_CMD_START_STOP_UNIT (0x1B)
79 #define SBC_CMD_RECEIVE_DIAGNOSTICS (0x1C)
80 #define SBC_CMD_SEND_DIAGNOSTIC (0x1D)
81 #define SBC_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL (0x1E)
82 #define SBC_CMD_READ_LONG (0x23)
83 #define SBC_CMD_READ_CAPACITY (0x25)
84 #define SBC_CMD_READ_CD_ROM_CAPACITY (0x25)
85 #define SBC_CMD_READ_10 (0x28)
86 #define SBC_CMD_WRITE_10 (0x2A)
87 #define SBC_CMD_VERIFY_10 (0x2F)
88 #define SBC_CMD_SYNCHRONIZE_CACHE (0x35)
89 #define SBC_CMD_WRITE_BUFFER (0x3B)
90 #define SBC_CMD_CHANGE_DEFINITION (0x40)
91 #define SBC_CMD_READ_TOC (0x43)
92 #define SBC_CMD_MODE_SELECT_10 (0x55)
93 #define SBC_CMD_RESERVE_10 (0x56)
94 #define SBC_CMD_RELEASE_10 (0x57)
95 #define SBC_CMD_MODE_SENSE_10 (0x5A)
96 
97 #define SBC_CONTROL_BYTE (0x00)
98 #define SBC_CMD_DIR_IN (0x80)
99 #define SBC_CMD_DIR_OUT (0x00)
100 
101 
102 /****************************************************************************/
103 /* Sense Key Code */
104 /****************************************************************************/
105 #define SBC_SENSE_KEY_NO_SENSE (0x00)
106 #define SBC_SENSE_KEY_RECOVERED_ERROR (0x01)
107 #define SBC_SENSE_KEY_NOT_READY (0x02)
108 #define SBC_SENSE_KEY_MEDIUM_ERROR (0x03)
109 #define SBC_SENSE_KEY_HARDWARE_ERROR (0x04)
110 #define SBC_SENSE_KEY_ILLEGAL_REQUEST (0x05)
111 #define SBC_SENSE_KEY_UNIT_ATTENTION (0x06)
112 #define SBC_SENSE_KEY_DATA_PROTECT (0x07)
113 #define SBC_SENSE_KEY_BLANK_CHECK (0x08)
114 #define SBC_SENSE_KEY_VENDOR_SPECIFIC (0x09)
115 #define SBC_SENSE_KEY_COPY_ABORTED (0x0A)
116 #define SBC_SENSE_KEY_ABORTED_COMMAND (0x0B)
117 #define SBC_SENSE_KEY_VOLUME_OVERFLOW (0x0D)
118 #define SBC_SENSE_KEY_MISCOMPARE (0x0E)
119 
120 /****************************************************************************/
121 /* ASC code assignments */
122 /****************************************************************************/
123 #define SBC_ASC_NO_ADDITIONAL_SENSE_INFORMATION (0x00)
124 #define SBC_ASC_LOGICAL_UNIT_NOT_READY (0x04)
125 #define SBC_ASC_INVALID_FIELD_IN_CDB (0x24)
126 #define SBC_ASC_WRITE_PROTECTED (0x27)
127 #define SBC_ASC_FORMAT_ERROR (0x31)
128 #define SBC_ASC_INVALID_COMMAND_OPERATION_CODE (0x20)
129 #define SBC_ASC_NOT_READY_TO_READY_CHANGE (0x28)
130 #define SBC_ASC_MEDIUM_NOT_PRESENT (0x3A)
131 
132 /****************************************************************************/
133 /* ASCQ code assignments */
134 /****************************************************************************/
135 #define SBC_ASCQ_FORMAT_COMMAND_FAILED (0x01)
136 #define SBC_ASCQ_INITIALIZING_COMMAND_REQUIRED (0x02)
137 #define SBC_ASCQ_OPERATION_IN_PROGRESS (0x07)
138 
139 
140 /****************************************************************************/
141 /* REQUEST SENSE PARAMETERS */
142 /****************************************************************************/
143 #define SBC_RESPONSE_CODE_SENSE (0x70)
144 #define SBC_ADDITIONAL_SENSE_LENGTH (0x0A)
145 #define SBC_COMMAND_SPECIFIC_INFORMATION_3 (0x00)
146 #define SBC_COMMAND_SPECIFIC_INFORMATION_2 (0x00)
147 #define SBC_COMMAND_SPECIFIC_INFORMATION_1 (0x00)
148 #define SBC_COMMAND_SPECIFIC_INFORMATION_0 (0x00)
149 #define SBC_FIELD_REPLACEABLE_UNIT_CODE (0x00)
150 #define SBC_SENSE_KEY_SPECIFIC_2 (0x00)
151 #define SBC_SENSE_KEY_SPECIFIC_1 (0x00)
152 #define SBC_SENSE_KEY_SPECIFIC_0 (0x00)
153 
154 /******* number of bytes of READ CAPACITY response *********/
155 #define SBC_READ_CAPACITY_LENGTH (0x08)
156 
157 
158 /****************************************************************************/
159 /*MODE SENSE and REQUEST SENSE DEFINITIONS */
160 /****************************************************************************/
161 
162 /*************** Direct access medium type ****************/
163 #define SBC_DEFAULT_MEDIUM_TYPE (0x00)
164 #define SBC_FLEXIBLE_DISK_SINGLE_SIDED_UNSPECIFIED (0x01)
165 #define SBC_FLEXIBLE_DISK_DOUBLE_SIDED_UNSPECIFIED (0x02)
166 
167 #define SBC_MEDIUM_TYPE SBC_DEFAULT_MEDIUM_TYPE
168 
169 #define SBC_DEV_SPEC_PARAM_WR_ENABLE (0x00)
170 #define SBC_DEV_SPEC_PARAM_WR_PROTECT (0x80)
171 #define SBC_BLOCK_DESCRIPTOR_LENGTH (0x00)
172 
173 #define SBC_MSK_DBD (0x08)
174 #define SBC_MSK_PAGE_CONTROL (0xC0)
175 #define SBC_MSK_PAGE_CODE (0x3F)
176 
177 
178 /************ General Page Code paramaters *****************/
179 #define SBC_PAGE_CODE_READ_WRITE_ERROR_RECOVERY (0x01)
180 #define SBC_PAGE_CODE_FORMAT_DEVICE (0x03)
181 #define SBC_PAGE_CODE_FLEXIBLE_DISK (0x05)
182 #define SBC_PAGE_CODE_INFORMATIONAL_EXCEPTIONS (0x1C)
183 #define SBC_PAGE_CODE_ALL (0x3F)
184 
185 
186 #define SBC_PAGE_LENGTH_INFORMATIONAL_EXCEPTIONS (0x0A)
187 #define SBC_PAGE_LENGTH_READ_WRITE_ERROR_RECOVERY (0x0A)
188 #define SBC_PAGE_LENGTH_FLEXIBLE_DISK (0x1E)
189 #define SBC_PAGE_LENGTH_FORMAT_DEVICE (0x16)
190 
191 
192 
193 #define SBC_MODE_DATA_LENGTH_INFORMATIONAL_EXCEPTIONS (SBC_PAGE_LENGTH_INFORMATIONAL_EXCEPTIONS + 2 + 3)
194 #define SBC_MODE_DATA_LENGTH_READ_WRITE_ERROR_RECOVERY (SBC_PAGE_LENGTH_READ_WRITE_ERROR_RECOVERY + 2 + 3 )
195 #define SBC_MODE_DATA_LENGTH_FLEXIBLE_DISK (SBC_PAGE_LENGTH_FLEXIBLE_DISK + 2 + 3 )
196 #define SBC_MODE_DATA_LENGTH_FORMAT_DEVICE (SBC_PAGE_LENGTH_FORMAT_DEVICE + 2 + 3 )
197 /*SBC_PAGE_LENGTH_FLEXIBLE_DISK + 2 + \*/
198 #define SBC_MODE_DATA_LENGTH_CODE_ALL (SBC_PAGE_LENGTH_READ_WRITE_ERROR_RECOVERY + 2 + \
199  SBC_PAGE_LENGTH_INFORMATIONAL_EXCEPTIONS + 2 + \
200  SBC_BLOCK_DESCRIPTOR_LENGTH + \
201  + 3 )
202 
203 /* SBC_MODE_DATA_LENGTH_FORMAT_DEVICE + 2 + \*/
204 /****** Information exceptions control page parameters *****/
205 #define SBC_MRIE (0x05)
206 
207 /*************** Format device page parameters *************/
208 #define SBC_TRACK_PER_ZONE_MSB (0x00)
209 #define SBC_TRACK_PER_ZONE_LSB (0x00)
210 #define SBC_ALTERNATE_SECTORS_PER_ZONE_MSB (0x00)
211 #define SBC_ALTERNATE_SECTORS_PER_ZONE_LSB (0x00)
212 #define SBC_ALTERNATE_TRACK_PER_ZONE_MSB (0x00)
213 #define SBC_ALTERNATE_TRACK_PER_ZONE_LSB (0x00)
214 #define SBC_ALTERNATE_TRACK_PER_LU_MSB (0x00)
215 #define SBC_ALTERNATE_TRACK_PER_LU_LSB (0x00)
216 
217 /************* Flexible Disk page Parameters ***************/
218 #define SBC_TRANSFER_RATE_MSB (0x13)
219 #define SBC_TRANSFER_RATE_LSB (0x88)
220 /* 1388h 5 Mbit/s */
221 /* 07D0h 2 Mbit/s */
222 /* 03E8h 1 Mbit/s */
223 /* 01F4h 500 kbit/s */
224 /* 012Ch 300 kbit/s */
225 /* 00FAh 250 kbit/s */
226 
227 #define SBC_NUMBER_OF_HEAD (0x04)
228 #define SBC_SECTOR_PER_TRACK (0x20)
229 #define SBC_DATA_BYTE_PER_SECTOR_MSB (0x02)
230 #define SBC_DATA_BYTE_PER_SECTOR_LSB (0x00)
231 #define SBC_NUMBER_OF_CYLINDERS_MSB (0x01)
232 #define SBC_NUMBER_OF_CYLINDERS_LSB (0xE9)
233 #define SBC_STARTING_CYLINDER_WRITE_COMPENSATION_MSB (0x00)
234 #define SBC_STARTING_CYLINDER_WRITE_COMPENSATION_LSB (0x00)
235 #define SBC_STARTING_CYLINDER_REDUCED_WRITE_MSB (0x00)
236 #define SBC_STARTING_CYLINDER_REDUCED_WRITE_LSB (0x00)
237 #define SBC_DEVICE_STEP_RATE_MSB (0x00)
238 #define SBC_DEVICE_STEP_RATE_LSB (0x00)
239 #define SBC_DEVICE_STEP_PULSE_WIDTH (0x00)
240 #define SBC_HEAD_SETTLE_DELAY_MSB (0x00)
241 #define SBC_HEAD_SETTLE_DELAY_LSB (0x00)
242 #define SBC_MOTOR_ON_DELAY (0x00)
243 #define SBC_MOTOR_OFF_DELAY (0x00)
244 #define SBC_STEP_PULSE_PER_CYLINDER (0x00)
245 #define SBC_WRITE_COMPENSATION (0x00)
246 #define SBC_HEAD_LOAD_DELAY (0x00)
247 #define SBC_HEAD_UNLOAD_DELAY (0x00)
248 #define SBC_PIN34_PIN2 (0x00)
249 #define SBC_PIN4_PIN1 (0x00)
250 #define SBC_MEDIUM_ROTATION_RATE_MSB (0x00)
251 #define SBC_MEDIUM_ROTATION_RATE_LSB (0x00)
252 
253 /************ Read/Write Error Recovery parameters**********/
254 #define SBC_READ_RETRY_COUNT (0x03)
255 #define SBC_WRITE_RETRY_COUNT (0x80)
256 #define SBC_CORRECTION_SPAN (0x00)
257 #define SBC_HEAD_OFFSET_COUNT (0x00)
258 #define SBC_DATA_STROBE_OFFSET (0x00)
259 #define SBC_RECOVERY_LIMIT_MSB (0x00)
260 #define SBC_RECOVERY_LIMIT_LSB (0x00)
261 
262 
263 /*_____ D E F I N I T I O N ________________________________________________*/
264 
265 #define SBC_MAX_INQUIRY_DATA (0x60) // value ?
266 
267 struct sbc_st_std_inquiry_data
268 {
269  Byte DeviceType : 5;
270  Byte PeripheralQualifier : 3;
271 
272  Byte Reserved1 : 7;
273  Byte RemovableMedia : 1;
274 
275  Byte Version;
276 
277  Byte Reserved3 : 5;
278  Byte NormACA : 1;
279  Byte Obsolete0 : 1;
280  Byte AERC : 1;
281 
282  Byte Reserved4[3];
283 
284  Byte SoftReset : 1;
285  Byte CommandQueue : 1;
286  Byte Reserved5 : 1;
287  Byte LinkedCommands : 1;
288  Byte Synchronous : 1;
289  Byte Wide16Bit : 1;
290  Byte Wide32Bit : 1;
291  Byte RelativeAddressing : 1;
292 };
293 
294 
295 //_____ D E C L A R A T I O N S ____________________________________________
296 
297 #define Sbc_send_failed() (g_scsi_status = COMMAND_FAILED)
298 #define Sbc_send_check_condition() (g_scsi_status = CHECK_CONDITION)
299 #define Sbc_send_good() (g_scsi_status = COMMAND_PASSED)
300 
301 /*#define Sbc_valid_write_usb(length) ( Usb_set_TXRDY(), \
302  dCBWDataTransferLength -= length, \
303  while (!Usb_tx_complete()),\
304  Usb_clear_TXCMPL() )
305 */
306 #define Sbc_build_sense(skey, sasc, sascq) ( g_scsi_sense.key = skey, \
307  g_scsi_sense.asc = sasc, \
308  g_scsi_sense.ascq = sascq )
309 
310 #define Sbc_valid_write_usb(length) ( Usb_send_in(), \
311  g_scsi_data_remaining -= length )
312 
313 
314 #define COMMAND_PASSED 0x00
315 #define COMMAND_FAILED 0x01
316 #define CHECK_CONDITION 0x02
317 #define PHASE_ERROR 0x02
318 
319 
320 Bool sbc_inquiry (void);
321 Bool sbc_mode_sense( Bool sense_10 );
322 Bool sbc_mode_select_6 (void);
323 Bool sbc_request_sense (void);
324 Bool sbc_format (void);
325 Bool sbc_write_10 (void);
326 Bool sbc_read_10 (void);
327 Bool sbc_test_unit_ready(void);
328 Bool sbc_read_capacity(void);
330 
331 void sbc_lun_status_is_good(void);
334 void sbc_lun_status_is_fail(void);
335 void sbc_lun_status_is_protected(void);
336 
337 #endif /* _SCSI_DECODER_H_ */
338 /** @} */