Minor documentation page updates.
[pub/USBasp.git] / LUFA / Drivers / USB / Class / Device / MassStorage.h
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2009.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
7 */
8
9 /*
10 Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
12 Permission to use, copy, modify, and distribute this software
13 and its documentation for any purpose and without fee is hereby
14 granted, provided that the above copyright notice appear in all
15 copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
20
21 The author disclaim all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
28 this software.
29 */
30
31 #ifndef _MS_CLASS_H_
32 #define _MS_CLASS_H_
33
34 /* Includes: */
35 #include "../../USB.h"
36
37 #include <string.h>
38
39 /* Enable C linkage for C++ Compilers: */
40 #if defined(__cplusplus)
41 extern "C" {
42 #endif
43
44 /* Macros: */
45 /** Mass Storage Class specific request to reset the Mass Storage interface, ready for the next command. */
46 #define REQ_MassStorageReset 0xFF
47
48 /** Mass Storage Class specific request to retrieve the total number of Logical Units (drives) in the SCSI device. */
49 #define REQ_GetMaxLUN 0xFE
50
51 /** Magic signature for a Command Block Wrapper used in the Mass Storage Bulk-Only transport protocol. */
52 #define MS_CBW_SIGNATURE 0x43425355UL
53
54 /** Magic signature for a Command Status Wrapper used in the Mass Storage Bulk-Only transport protocol. */
55 #define MS_CSW_SIGNATURE 0x53425355UL
56
57 /** Mask for a Command Block Wrapper's flags attribute to specify a command with data sent from host-to-device. */
58 #define MS_COMMAND_DIR_DATA_OUT (0 << 7)
59
60 /** Mask for a Command Block Wrapper's flags attribute to specify a command with data sent from device-to-host. */
61 #define MS_COMMAND_DIR_DATA_IN (1 << 7)
62
63 /* Type defines: */
64 /** Type define for a Command Block Wrapper, used in the Mass Storage Bulk-Only Transport protocol. */
65 typedef struct
66 {
67 uint32_t Signature; /**< Command block signature, must be CBW_SIGNATURE to indicate a valid Command Block */
68 uint32_t Tag; /**< Unique command ID value, to associate a command block wrapper with its command status wrapper */
69 uint32_t DataTransferLength; /** Length of the optional data portion of the issued command, in bytes */
70 uint8_t Flags; /**< Command block flags, indicating command data direction */
71 uint8_t LUN; /**< Logical Unit number this command is issued to */
72 uint8_t SCSICommandLength; /**< Length of the issued SCSI command within the SCSI command data array */
73 uint8_t SCSICommandData[16]; /**< Issued SCSI command in the Command Block */
74 } CommandBlockWrapper_t;
75
76 /** Type define for a Command Status Wrapper, used in the Mass Storage Bulk-Only Transport protocol. */
77 typedef struct
78 {
79 uint32_t Signature; /**< Status block signature, must be CSW_SIGNATURE to indicate a valid Command Status */
80 uint32_t Tag; /**< Unique command ID value, to associate a command block wrapper with its command status wrapper */
81 uint32_t DataTransferResidue; /**< Number of bytes of data not processed in the SCSI command */
82 uint8_t Status; /**< Status code of the issued command - a value from the MassStorage_CommandStatusCodes_t enum */
83 } CommandStatusWrapper_t;
84
85 /* Enums: */
86 /** Enum for the possible command status wrapper return status codes. */
87 enum MassStorage_CommandStatusCodes_t
88 {
89 SCSI_Command_Pass = 0, /**< Command completed with no error */
90 SCSI_Command_Fail = 1, /**< Command failed to complete - host may check the exact error via a SCSI REQUEST SENSE command */
91 SCSI_Phase_Error = 2 /**< Command failed due to being invalid in the current phase */
92 };
93
94 /* Type Defines: */
95 /** Type define for the virtual serial port line encoding settings, for storing the current USART configuration
96 * as set by the host via a class specific request.
97 */
98 typedef struct
99 {
100 uint8_t InterfaceNumber; /**< Interface number of the Mass Storage interface within the device */
101
102 uint8_t DataINEndpointNumber; /**< Endpoint number of the Mass Storage interface's IN data endpoint */
103 uint16_t DataINEndpointSize; /**< Size in bytes of the Mass Storage interface's IN data endpoint */
104
105 uint8_t DataOUTEndpointNumber; /**< Endpoint number of the Mass Storage interface's OUT data endpoint */
106 uint16_t DataOUTEndpointSize; /**< Size in bytes of the Mass Storage interface's OUT data endpoint */
107
108 uint8_t TotalLUNs;
109
110 CommandBlockWrapper_t CommandBlock;
111 CommandStatusWrapper_t CommandStatus;
112
113 bool IsMassStoreReset;
114 } USB_ClassInfo_MS_t;
115
116 /* Function Prototypes: */
117 #if defined(INCLUDE_FROM_MS_CLASS_C)
118 static void USB_MS_ReturnCommandStatus(USB_ClassInfo_MS_t* MSInterfaceInfo);
119 static bool USB_MS_ReadInCommandBlock(USB_ClassInfo_MS_t* MSInterfaceInfo);
120 static uint8_t StreamCallback_AbortOnMassStoreReset(void);
121 #endif
122
123 bool USB_MS_ConfigureEndpoints(USB_ClassInfo_MS_t* MSInterfaceInfo);
124 void USB_MS_ProcessControlPacket(USB_ClassInfo_MS_t* MSInterfaceInfo);
125 void USB_MS_USBTask(USB_ClassInfo_MS_t* MSInterfaceInfo);
126
127 bool CALLBACK_USB_MS_SCSICommandReceived(USB_ClassInfo_MS_t* MSInterfaceInfo);
128
129 /* Disable C linkage for C++ Compilers: */
130 #if defined(__cplusplus)
131 }
132 #endif
133
134 #endif