ARMEBS4  revision-26.06.2015
usbh_msc_bot.h
1 #include "heivs/config.h"
2 #if (USE_STM32_USB_HOST_MODE || USE_STM32_USB_USE_DEVICE_MODE || USE_STM32_USB_OTG_MODE)
3 /**
4  ******************************************************************************
5  * @file usbh_msc_bot.h
6  * @author MCD Application Team
7  * @version V2.1.0
8  * @date 19-March-2012
9  * @brief Header file for usbh_msc_bot.c
10  ******************************************************************************
11  * @attention
12  *
13  * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
14  *
15  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
16  * You may not use this file except in compliance with the License.
17  * You may obtain a copy of the License at:
18  *
19  * http://www.st.com/software_license_agreement_liberty_v2
20  *
21  * Unless required by applicable law or agreed to in writing, software
22  * distributed under the License is distributed on an "AS IS" BASIS,
23  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24  * See the License for the specific language governing permissions and
25  * limitations under the License.
26  *
27  ******************************************************************************
28  */
29 
30 /* Define to prevent recursive ----------------------------------------------*/
31 #ifndef __USBH_MSC_BOT_H__
32 #define __USBH_MSC_BOT_H__
33 
34 /* Includes ------------------------------------------------------------------*/
35 #include "stm32/usb/usbh_stdreq.h"
36 
37 
38 /** @addtogroup USBH_LIB
39  * @{
40  */
41 
42 /** @addtogroup USBH_CLASS
43  * @{
44  */
45 
46 /** @addtogroup USBH_MSC_CLASS
47  * @{
48  */
49 
50 /** @defgroup USBH_MSC_BOT
51  * @brief This file is the Header file for usbh_msc_core.c
52  * @{
53  */
54 
55 
56 /** @defgroup USBH_MSC_BOT_Exported_Types
57  * @{
58  */
59 
60 typedef union _USBH_CBW_Block
61 {
62  struct __CBW
63  {
64  uint32_t CBWSignature;
65  uint32_t CBWTag;
66  uint32_t CBWTransferLength;
67  uint8_t CBWFlags;
68  uint8_t CBWLUN;
69  uint8_t CBWLength;
70  uint8_t CBWCB[16];
71 }field;
72  uint8_t CBWArray[31];
73 }HostCBWPkt_TypeDef;
74 
75 typedef enum
76 {
77  USBH_MSC_BOT_INIT_STATE = 0,
78  USBH_MSC_BOT_RESET,
79  USBH_MSC_GET_MAX_LUN,
80  USBH_MSC_TEST_UNIT_READY,
81  USBH_MSC_READ_CAPACITY10,
82  USBH_MSC_MODE_SENSE6,
83  USBH_MSC_REQUEST_SENSE,
84  USBH_MSC_BOT_USB_TRANSFERS,
85  USBH_MSC_DEFAULT_APPLI_STATE,
86  USBH_MSC_CTRL_ERROR_STATE,
87  USBH_MSC_UNRECOVERED_STATE
88 }
89 MSCState;
90 
91 
92 typedef struct _BOTXfer
93 {
94 uint8_t MSCState;
95 uint8_t MSCStateBkp;
96 uint8_t MSCStateCurrent;
97 uint8_t CmdStateMachine;
98 uint8_t BOTState;
99 uint8_t BOTStateBkp;
100 uint8_t* pRxTxBuff;
101 uint16_t DataLength;
102 uint8_t BOTXferErrorCount;
103 uint8_t BOTXferStatus;
104 } USBH_BOTXfer_TypeDef;
105 
106 
107 typedef union _USBH_CSW_Block
108 {
109  struct __CSW
110  {
111  uint32_t CSWSignature;
112  uint32_t CSWTag;
113  uint32_t CSWDataResidue;
114  uint8_t CSWStatus;
115  }field;
116  uint8_t CSWArray[13];
117 }HostCSWPkt_TypeDef;
118 
119 /**
120  * @}
121  */
122 
123 
124 
125 /** @defgroup USBH_MSC_BOT_Exported_Defines
126  * @{
127  */
128 #define USBH_MSC_SEND_CBW 1
129 #define USBH_MSC_SENT_CBW 2
130 #define USBH_MSC_BOT_DATAIN_STATE 3
131 #define USBH_MSC_BOT_DATAOUT_STATE 4
132 #define USBH_MSC_RECEIVE_CSW_STATE 5
133 #define USBH_MSC_DECODE_CSW 6
134 #define USBH_MSC_BOT_ERROR_IN 7
135 #define USBH_MSC_BOT_ERROR_OUT 8
136 
137 
138 #define USBH_MSC_BOT_CBW_SIGNATURE 0x43425355
139 #define USBH_MSC_BOT_CBW_TAG 0x20304050
140 #define USBH_MSC_BOT_CSW_SIGNATURE 0x53425355
141 #define USBH_MSC_CSW_DATA_LENGTH 0x000D
142 #define USBH_MSC_BOT_CBW_PACKET_LENGTH 31
143 #define USBH_MSC_CSW_LENGTH 13
144 #define USBH_MSC_CSW_MAX_LENGTH 63
145 
146 /* CSW Status Definitions */
147 #define USBH_MSC_CSW_CMD_PASSED 0x00
148 #define USBH_MSC_CSW_CMD_FAILED 0x01
149 #define USBH_MSC_CSW_PHASE_ERROR 0x02
150 
151 #define USBH_MSC_SEND_CSW_DISABLE 0
152 #define USBH_MSC_SEND_CSW_ENABLE 1
153 
154 #define USBH_MSC_DIR_IN 0
155 #define USBH_MSC_DIR_OUT 1
156 #define USBH_MSC_BOTH_DIR 2
157 
158 //#define USBH_MSC_PAGE_LENGTH 0x40
159 #define USBH_MSC_PAGE_LENGTH 512
160 
161 
162 #define CBW_CB_LENGTH 16
163 #define CBW_LENGTH 10
164 #define CBW_LENGTH_TEST_UNIT_READY 6
165 
166 #define USB_REQ_BOT_RESET 0xFF
167 #define USB_REQ_GET_MAX_LUN 0xFE
168 
169 #define MAX_BULK_STALL_COUNT_LIMIT 0x04 /* If STALL is seen on Bulk
170  Endpoint continously, this means
171  that device and Host has phase error
172  Hence a Reset is needed */
173 
174 /**
175  * @}
176  */
177 
178 /** @defgroup USBH_MSC_BOT_Exported_Macros
179  * @{
180  */
181 /**
182  * @}
183  */
184 
185 /** @defgroup USBH_MSC_BOT_Exported_Variables
186  * @{
187  */
188 extern USBH_BOTXfer_TypeDef USBH_MSC_BOTXferParam;
189 extern HostCBWPkt_TypeDef USBH_MSC_CBWData;
190 extern HostCSWPkt_TypeDef USBH_MSC_CSWData;
191 /**
192  * @}
193  */
194 
195 /** @defgroup USBH_MSC_BOT_Exported_FunctionsPrototype
196  * @{
197  */
198 void USBH_MSC_HandleBOTXfer(USB_OTG_CORE_HANDLE *pdev,
199  USBH_HOST *phost);
200 uint8_t USBH_MSC_DecodeCSW(USB_OTG_CORE_HANDLE *pdev,
201  USBH_HOST *phost);
202 void USBH_MSC_Init(USB_OTG_CORE_HANDLE *pdev);
203 USBH_Status USBH_MSC_BOT_Abort(USB_OTG_CORE_HANDLE *pdev,
204  USBH_HOST *phost,
205  uint8_t direction);
206 /**
207  * @}
208  */
209 
210 #endif //__USBH_MSC_BOT_H__
211 
212 
213 /**
214  * @}
215  */
216 
217 /**
218  * @}
219  */
220 
221 /**
222  * @}
223  */
224 
225 /**
226  * @}
227  */
228 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
229 #endif /* (USE_STM32_USB_HOST_MODE || USE_STM32_USB_USE_DEVICE_MODE || USE_STM32_USB_OTG_MODE) */
libheivs configuration file