Added Doxygen documentation to the Audio class driver. Added new modules for each...
[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 /** \ingroup Group_USBDeviceClassDrivers
32 * @defgroup Group_USBClassMSDevice Mass Storage Device Class Driver - LUFA/Drivers/Class/Device/MassStorage.h
33 *
34 * \section Sec_Dependencies Module Source Dependencies
35 * The following files must be built with any user project that uses this module:
36 * - LUFA/Drivers/USB/Class/Device/MassStorage.c
37 *
38 * \section Module Description
39 * Functions, macros, variables, enums and types related to the management of USB Mass Storage Class interfaces
40 * within a USB device.
41 *
42 * @{
43 */
44
45 #ifndef _MS_CLASS_H_
46 #define _MS_CLASS_H_
47
48 /* Includes: */
49 #include "../../USB.h"
50
51 #include <string.h>
52
53 /* Enable C linkage for C++ Compilers: */
54 #if defined(__cplusplus)
55 extern "C" {
56 #endif
57
58 /* Macros: */
59 /** Mass Storage Class specific request to reset the Mass Storage interface, ready for the next command. */
60 #define REQ_MassStorageReset 0xFF
61
62 /** Mass Storage Class specific request to retrieve the total number of Logical Units (drives) in the SCSI device. */
63 #define REQ_GetMaxLUN 0xFE
64
65 /** Magic signature for a Command Block Wrapper used in the Mass Storage Bulk-Only transport protocol. */
66 #define MS_CBW_SIGNATURE 0x43425355UL
67
68 /** Magic signature for a Command Status Wrapper used in the Mass Storage Bulk-Only transport protocol. */
69 #define MS_CSW_SIGNATURE 0x53425355UL
70
71 /** Mask for a Command Block Wrapper's flags attribute to specify a command with data sent from host-to-device. */
72 #define MS_COMMAND_DIR_DATA_OUT (0 << 7)
73
74 /** Mask for a Command Block Wrapper's flags attribute to specify a command with data sent from device-to-host. */
75 #define MS_COMMAND_DIR_DATA_IN (1 << 7)
76
77 /* Type defines: */
78 /** Type define for a Command Block Wrapper, used in the Mass Storage Bulk-Only Transport protocol. */
79 typedef struct
80 {
81 uint32_t Signature; /**< Command block signature, must be CBW_SIGNATURE to indicate a valid Command Block */
82 uint32_t Tag; /**< Unique command ID value, to associate a command block wrapper with its command status wrapper */
83 uint32_t DataTransferLength; /** Length of the optional data portion of the issued command, in bytes */
84 uint8_t Flags; /**< Command block flags, indicating command data direction */
85 uint8_t LUN; /**< Logical Unit number this command is issued to */
86 uint8_t SCSICommandLength; /**< Length of the issued SCSI command within the SCSI command data array */
87 uint8_t SCSICommandData[16]; /**< Issued SCSI command in the Command Block */
88 } CommandBlockWrapper_t;
89
90 /** Type define for a Command Status Wrapper, used in the Mass Storage Bulk-Only Transport protocol. */
91 typedef struct
92 {
93 uint32_t Signature; /**< Status block signature, must be CSW_SIGNATURE to indicate a valid Command Status */
94 uint32_t Tag; /**< Unique command ID value, to associate a command block wrapper with its command status wrapper */
95 uint32_t DataTransferResidue; /**< Number of bytes of data not processed in the SCSI command */
96 uint8_t Status; /**< Status code of the issued command - a value from the MassStorage_CommandStatusCodes_t enum */
97 } CommandStatusWrapper_t;
98
99 /* Enums: */
100 /** Enum for the possible command status wrapper return status codes. */
101 enum MassStorage_CommandStatusCodes_t
102 {
103 SCSI_Command_Pass = 0, /**< Command completed with no error */
104 SCSI_Command_Fail = 1, /**< Command failed to complete - host may check the exact error via a SCSI REQUEST SENSE command */
105 SCSI_Phase_Error = 2 /**< Command failed due to being invalid in the current phase */
106 };
107
108 /* Type Defines: */
109 /** Type define for the virtual serial port line encoding settings, for storing the current USART configuration
110 * as set by the host via a class specific request.
111 */
112 typedef struct
113 {
114 uint8_t InterfaceNumber; /**< Interface number of the Mass Storage interface within the device */
115
116 uint8_t DataINEndpointNumber; /**< Endpoint number of the Mass Storage interface's IN data endpoint */
117 uint16_t DataINEndpointSize; /**< Size in bytes of the Mass Storage interface's IN data endpoint */
118
119 uint8_t DataOUTEndpointNumber; /**< Endpoint number of the Mass Storage interface's OUT data endpoint */
120 uint16_t DataOUTEndpointSize; /**< Size in bytes of the Mass Storage interface's OUT data endpoint */
121
122 uint8_t TotalLUNs;
123
124 CommandBlockWrapper_t CommandBlock;
125 CommandStatusWrapper_t CommandStatus;
126
127 bool IsMassStoreReset;
128 } USB_ClassInfo_MS_t;
129
130 /* Function Prototypes: */
131 #if defined(INCLUDE_FROM_MS_CLASS_C)
132 static void USB_MS_ReturnCommandStatus(USB_ClassInfo_MS_t* MSInterfaceInfo);
133 static bool USB_MS_ReadInCommandBlock(USB_ClassInfo_MS_t* MSInterfaceInfo);
134 static uint8_t StreamCallback_AbortOnMassStoreReset(void);
135 #endif
136
137 bool USB_MS_ConfigureEndpoints(USB_ClassInfo_MS_t* MSInterfaceInfo);
138 void USB_MS_ProcessControlPacket(USB_ClassInfo_MS_t* MSInterfaceInfo);
139 void USB_MS_USBTask(USB_ClassInfo_MS_t* MSInterfaceInfo);
140
141 bool CALLBACK_USB_MS_SCSICommandReceived(USB_ClassInfo_MS_t* MSInterfaceInfo);
142
143 /* Disable C linkage for C++ Compilers: */
144 #if defined(__cplusplus)
145 }
146 #endif
147
148 #endif
149
150 /** @} */