Removed new Start of Frame event from the library; performance suffered far too much...
[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 /* Macros: */
40 /** Mass Storage Class specific request to reset the Mass Storage interface, ready for the next command. */
41 #define REQ_MassStorageReset 0xFF
42
43 /** Mass Storage Class specific request to retrieve the total number of Logical Units (drives) in the SCSI device. */
44 #define REQ_GetMaxLUN 0xFE
45
46 /** Maximum length of a SCSI command which can be issued by the device or host in a Mass Storage bulk wrapper. */
47 #define MAX_SCSI_COMMAND_LENGTH 16
48
49 /** Magic signature for a Command Block Wrapper used in the Mass Storage Bulk-Only transport protocol. */
50 #define CBW_SIGNATURE 0x43425355UL
51
52 /** Magic signature for a Command Status Wrapper used in the Mass Storage Bulk-Only transport protocol. */
53 #define CSW_SIGNATURE 0x53425355UL
54
55 /** Mask for a Command Block Wrapper's flags attribute to specify a command with data sent from host-to-device. */
56 #define COMMAND_DIRECTION_DATA_OUT (0 << 7)
57
58 /** Mask for a Command Block Wrapper's flags attribute to specify a command with data sent from device-to-host. */
59 #define COMMAND_DIRECTION_DATA_IN (1 << 7)
60
61 /* Type defines: */
62 /** Type define for a Command Block Wrapper, used in the Mass Storage Bulk-Only Transport protocol. */
63 typedef struct
64 {
65 uint32_t Signature; /**< Command block signature, must be CBW_SIGNATURE to indicate a valid Command Block */
66 uint32_t Tag; /**< Unique command ID value, to associate a command block wrapper with its command status wrapper */
67 uint32_t DataTransferLength; /** Length of the optional data portion of the issued command, in bytes */
68 uint8_t Flags; /**< Command block flags, indicating command data direction */
69 uint8_t LUN; /**< Logical Unit number this command is issued to */
70 uint8_t SCSICommandLength; /**< Length of the issued SCSI command within the SCSI command data array */
71 uint8_t SCSICommandData[MAX_SCSI_COMMAND_LENGTH]; /**< Issued SCSI command in the Command Block */
72 } CommandBlockWrapper_t;
73
74 /** Type define for a Command Status Wrapper, used in the Mass Storage Bulk-Only Transport protocol. */
75 typedef struct
76 {
77 uint32_t Signature; /**< Status block signature, must be CSW_SIGNATURE to indicate a valid Command Status */
78 uint32_t Tag; /**< Unique command ID value, to associate a command block wrapper with its command status wrapper */
79 uint32_t DataTransferResidue; /**< Number of bytes of data not processed in the SCSI command */
80 uint8_t Status; /**< Status code of the issued command - a value from the MassStorage_CommandStatusCodes_t enum */
81 } CommandStatusWrapper_t;
82
83 /* Enums: */
84 /** Enum for the possible command status wrapper return status codes. */
85 enum MassStorage_CommandStatusCodes_t
86 {
87 Command_Pass = 0, /**< Command completed with no error */
88 Command_Fail = 1, /**< Command failed to complete - host may check the exact error via a SCSI REQUEST SENSE command */
89 Phase_Error = 2 /**< Command failed due to being invalid in the current phase */
90 };
91
92 /* Type Defines: */
93 /** Type define for the virtual serial port line encoding settings, for storing the current USART configuration
94 * as set by the host via a class specific request.
95 */
96 typedef struct
97 {
98 uint8_t InterfaceNumber; /**< Interface number of the Mass Storage interface within the device */
99
100 uint8_t DataINEndpointNumber; /**< Endpoint number of the Mass Storage interface's IN data endpoint */
101 uint16_t DataINEndpointSize; /**< Size in bytes of the Mass Storage interface's IN data endpoint */
102
103 uint8_t DataOUTEndpointNumber; /**< Endpoint number of the Mass Storage interface's OUT data endpoint */
104 uint16_t DataOUTEndpointSize; /**< Size in bytes of the Mass Storage interface's OUT data endpoint */
105
106 uint8_t TotalLUNs;
107
108 CommandBlockWrapper_t CommandBlock;
109 CommandStatusWrapper_t CommandStatus;
110
111 bool IsMassStoreReset;
112 } USB_ClassInfo_MS_t;
113
114 /* Function Prototypes: */
115 #if defined(INCLUDE_FROM_MS_CLASS_C)
116 static void USB_MS_ReturnCommandStatus(USB_ClassInfo_MS_t* MSInterfaceInfo);
117 static bool USB_MS_ReadInCommandBlock(USB_ClassInfo_MS_t* MSInterfaceInfo);
118 static uint8_t StreamCallback_AbortOnMassStoreReset(void);
119 #endif
120
121 void USB_MS_USBTask(USB_ClassInfo_MS_t* MSInterfaceInfo);
122 bool USB_MS_ConfigureEndpoints(USB_ClassInfo_MS_t* MSInterfaceInfo);
123 void USB_MS_ProcessControlPacket(USB_ClassInfo_MS_t* MSInterfaceInfo);
124
125 bool CALLBACK_USB_MS_SCSICommandReceived(USB_ClassInfo_MS_t* MSInterfaceInfo);
126
127 #endif