usbd_msc_bot.c
Go to the documentation of this file.
1 
28 /* Includes ------------------------------------------------------------------*/
29 #include "usbd_msc_bot.h"
30 #include "usbd_msc_scsi.h"
31 #include "usbd_ioreq.h"
32 #include "usbd_msc_mem.h"
33 
34 #define UNUSED(x) (void)(x)
35 
74 uint16_t MSC_BOT_DataLen;
75 uint8_t MSC_BOT_State;
77 
78 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
79  #if defined ( __ICCARM__ )
80  #pragma data_alignment=4
81  #endif
82 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
84 
85 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
86  #if defined ( __ICCARM__ )
87  #pragma data_alignment=4
88  #endif
89 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
91 
92 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
93  #if defined ( __ICCARM__ )
94  #pragma data_alignment=4
95  #endif
96 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
106 static void MSC_BOT_CBW_Decode (USB_OTG_CORE_HANDLE *pdev);
107 
108 static void MSC_BOT_SendData (USB_OTG_CORE_HANDLE *pdev,
109  uint8_t* pbuf,
110  uint16_t len);
111 
112 static void MSC_BOT_Abort(USB_OTG_CORE_HANDLE *pdev);
131 {
135 
136  DCD_EP_Flush(pdev, MSC_OUT_EP);
137  DCD_EP_Flush(pdev, MSC_IN_EP);
138  /* Prapare EP to Receive First BOT Cmd */
139  DCD_EP_PrepareRx (pdev,
140  MSC_OUT_EP,
141  (uint8_t *)&MSC_BOT_cbw,
143 }
144 
152 {
155  /* Prapare EP to Receive First BOT Cmd */
156  DCD_EP_PrepareRx (pdev,
157  MSC_OUT_EP,
158  (uint8_t *)&MSC_BOT_cbw,
160 }
161 
169 {
170  UNUSED(pdev);
172 }
173 
182  uint8_t epnum)
183 {
184  UNUSED(epnum);
185  switch (MSC_BOT_State)
186  {
187  case BOT_DATA_IN:
188  if(SCSI_ProcessCmd(pdev,
190  &MSC_BOT_cbw.CB[0]) < 0)
191  {
193  }
194  break;
195 
196  case BOT_SEND_DATA:
197  case BOT_LAST_DATA_IN:
199 
200  break;
201 
202  default:
203  break;
204  }
205 }
214  uint8_t epnum)
215 {
216  UNUSED(epnum);
217  switch (MSC_BOT_State)
218  {
219  case BOT_IDLE:
220  MSC_BOT_CBW_Decode(pdev);
221  break;
222 
223  case BOT_DATA_OUT:
224 
225  if(SCSI_ProcessCmd(pdev,
227  &MSC_BOT_cbw.CB[0]) < 0)
228  {
230  }
231 
232  break;
233 
234  default:
235  break;
236  }
237 
238 }
239 
247 {
248 
251 
252  if ((USBD_GetRxCount (pdev ,MSC_OUT_EP) != BOT_CBW_LENGTH) ||
254  (MSC_BOT_cbw.bLUN > 1) ||
255  (MSC_BOT_cbw.bCBLength < 1) ||
256  (MSC_BOT_cbw.bCBLength > 16))
257  {
258 
261  INVALID_CDB);
263  MSC_BOT_Abort(pdev);
264 
265  }
266  else
267  {
268  if(SCSI_ProcessCmd(pdev,
270  &MSC_BOT_cbw.CB[0]) < 0)
271  {
272  MSC_BOT_Abort(pdev);
273  }
274  /*Burst xfer handled internally*/
275  else if ((MSC_BOT_State != BOT_DATA_IN) &&
278  {
279  if (MSC_BOT_DataLen > 0)
280  {
281  MSC_BOT_SendData(pdev,
282  MSC_BOT_Data,
284  }
285  else if (MSC_BOT_DataLen == 0)
286  {
287  MSC_BOT_SendCSW (pdev,
289  }
290  }
291  }
292 }
293 
303  uint8_t* buf,
304  uint16_t len)
305 {
306 
307  len = MIN (MSC_BOT_cbw.dDataLength, len);
308  MSC_BOT_csw.dDataResidue -= len;
311 
312  DCD_EP_Tx (pdev, MSC_IN_EP, buf, len);
313 }
314 
323  uint8_t CSW_Status)
324 {
326  MSC_BOT_csw.bStatus = CSW_Status;
328 
329  DCD_EP_Tx (pdev,
330  MSC_IN_EP,
331  (uint8_t *)&MSC_BOT_csw,
333 
334  /* Prepare EP to Receive next Cmd */
335  DCD_EP_PrepareRx (pdev,
336  MSC_OUT_EP,
337  (uint8_t *)&MSC_BOT_cbw,
339 
340 }
341 
350 {
351 
352  if ((MSC_BOT_cbw.bmFlags == 0) &&
353  (MSC_BOT_cbw.dDataLength != 0) &&
355  {
356  DCD_EP_Stall(pdev, MSC_OUT_EP );
357  }
358  DCD_EP_Stall(pdev, MSC_IN_EP);
359 
361  {
362  DCD_EP_PrepareRx (pdev,
363  MSC_OUT_EP,
364  (uint8_t *)&MSC_BOT_cbw,
366  }
367 }
368 
377 void MSC_BOT_CplClrFeature (USB_OTG_CORE_HANDLE *pdev, uint8_t epnum)
378 {
379  if(MSC_BOT_Status == BOT_STATE_ERROR )/* Bad CBW Signature */
380  {
381  DCD_EP_Stall(pdev, MSC_IN_EP);
383  }
384  else if(((epnum & 0x80) == 0x80) && ( MSC_BOT_Status != BOT_STATE_RECOVERY))
385  {
387  }
388 
389 }
404 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
uint32_t dDataResidue
Definition: usbd_msc_bot.h:100
#define MSC_IN_EP
Definition: usbd_conf.h:66
uint32_t dSignature
Definition: usbd_msc_bot.h:85
uint32_t DCD_EP_Tx(USB_OTG_CORE_HANDLE *pdev, uint8_t ep_addr, uint8_t *pbuf, uint32_t buf_len)
Transmit data over USB.
Definition: usb_dcd.c:271
uint8_t MSC_BOT_Data[]
#define INVALID_CDB
Definition: usbd_msc_scsi.h:97
void MSC_BOT_CplClrFeature(USB_OTG_CORE_HANDLE *pdev, uint8_t epnum)
MSC_BOT_CplClrFeature Complete the clear feature request.
Definition: usbd_msc_bot.c:377
void MSC_BOT_Reset(USB_OTG_CORE_HANDLE *pdev)
MSC_BOT_Reset Reset the BOT Machine.
Definition: usbd_msc_bot.c:151
#define BOT_IDLE
Definition: usbd_msc_bot.h:49
#define BOT_STATE_NORMAL
Definition: usbd_msc_bot.h:66
int8_t SCSI_ProcessCmd(USB_OTG_CORE_HANDLE *pdev, uint8_t lun, uint8_t *cmd)
SCSI_ProcessCmd Process SCSI commands.
uint32_t DCD_EP_Flush(USB_OTG_CORE_HANDLE *pdev, uint8_t epnum)
This Function flushes the FIFOs.
Definition: usb_dcd.c:360
uint8_t bmFlags
Definition: usbd_msc_bot.h:88
static void MSC_BOT_SendData(USB_OTG_CORE_HANDLE *pdev, uint8_t *pbuf, uint16_t len)
MSC_BOT_SendData Send the requested data.
Definition: usbd_msc_bot.c:302
void MSC_BOT_DataOut(USB_OTG_CORE_HANDLE *pdev, uint8_t epnum)
MSC_BOT_DataOut Proccess MSC OUT data.
Definition: usbd_msc_bot.c:213
uint32_t DCD_EP_Stall(USB_OTG_CORE_HANDLE *pdev, uint8_t epnum)
Stall an endpoint.
Definition: usb_dcd.c:306
uint16_t MSC_BOT_DataLen
Definition: usbd_msc_bot.c:74
header for the STORAGE DISK file file
#define BOT_CSW_SIGNATURE
Definition: usbd_msc_bot.h:56
uint32_t dTag
Definition: usbd_msc_bot.h:86
#define BOT_DATA_IN
Definition: usbd_msc_bot.h:51
#define UNUSED(x)
Definition: usbd_msc_bot.c:34
uint16_t USBD_GetRxCount(USB_OTG_CORE_HANDLE *pdev, uint8_t epnum)
USBD_GetRxCount returns the received data length.
Definition: usbd_ioreq.c:225
#define MIN(a, b)
Definition: usb_defines.h:178
void MSC_BOT_DataIn(USB_OTG_CORE_HANDLE *pdev, uint8_t epnum)
MSC_BOT_DataIn Handle BOT IN data stage.
Definition: usbd_msc_bot.c:181
#define BOT_CSW_LENGTH
Definition: usbd_msc_bot.h:58
uint32_t dDataLength
Definition: usbd_msc_bot.h:87
uint32_t dTag
Definition: usbd_msc_bot.h:99
#define __ALIGN_BEGIN
uint8_t MSC_BOT_Status
Definition: usbd_msc_bot.c:76
#define BOT_STATE_RECOVERY
Definition: usbd_msc_bot.h:67
uint8_t CB[16]
Definition: usbd_msc_bot.h:91
#define BOT_SEND_DATA
Definition: usbd_msc_bot.h:53
#define MSC_MEDIA_PACKET
Definition: usbd_conf.h:79
#define BOT_CBW_SIGNATURE
Definition: usbd_msc_bot.h:55
header for the usbd_msc_scsi.c file
uint8_t MSC_BOT_State
Definition: usbd_msc_bot.c:75
__ALIGN_BEGIN uint8_t MSC_BOT_Data[MSC_MEDIA_PACKET] __ALIGN_END
Definition: usbd_msc_bot.c:83
uint32_t DCD_EP_PrepareRx(USB_OTG_CORE_HANDLE *pdev, uint8_t ep_addr, uint8_t *pbuf, uint16_t buf_len)
DCD_EP_PrepareRx.
Definition: usb_dcd.c:231
header file for the usbd_ioreq.c file
#define BOT_CBW_LENGTH
Definition: usbd_msc_bot.h:57
#define MSC_OUT_EP
Definition: usbd_conf.h:67
void MSC_BOT_DeInit(USB_OTG_CORE_HANDLE *pdev)
MSC_BOT_DeInit Uninitialize the BOT Machine.
Definition: usbd_msc_bot.c:168
#define ILLEGAL_REQUEST
Definition: usbd_msc_scsi.h:86
static void MSC_BOT_CBW_Decode(USB_OTG_CORE_HANDLE *pdev)
MSC_BOT_CBW_Decode Decode the CBW command and set the BOT state machine accordingtly.
Definition: usbd_msc_bot.c:246
#define BOT_LAST_DATA_IN
Definition: usbd_msc_bot.h:52
USBD_STORAGE_cb_TypeDef * USBD_STORAGE_fops
MSC_BOT_CBW_TypeDef MSC_BOT_cbw
#define CSW_CMD_PASSED
Definition: usbd_msc_bot.h:61
void SCSI_SenseCode(uint8_t lun, uint8_t sKey, uint8_t ASC)
SCSI_SenseCode Load the last error code in the error list.
MSC_BOT_CSW_TypeDef MSC_BOT_csw
#define BOT_DATA_OUT
Definition: usbd_msc_bot.h:50
uint8_t bLUN
Definition: usbd_msc_bot.h:89
uint8_t bCBLength
Definition: usbd_msc_bot.h:90
void MSC_BOT_SendCSW(USB_OTG_CORE_HANDLE *pdev, uint8_t CSW_Status)
MSC_BOT_SendCSW Send the Command Status Wrapper.
Definition: usbd_msc_bot.c:322
uint8_t bStatus
Definition: usbd_msc_bot.h:101
uint32_t dSignature
Definition: usbd_msc_bot.h:98
#define CSW_CMD_FAILED
Definition: usbd_msc_bot.h:62
int8_t(* Init)(uint8_t lun)
Definition: usbd_msc_mem.h:60
header for the usbd_msc_bot.c file
void MSC_BOT_Init(USB_OTG_CORE_HANDLE *pdev)
MSC_BOT_Init Initialize the BOT Process.
Definition: usbd_msc_bot.c:130
#define BOT_STATE_ERROR
Definition: usbd_msc_bot.h:68
static void MSC_BOT_Abort(USB_OTG_CORE_HANDLE *pdev)
MSC_BOT_Abort Abort the current transfer.
Definition: usbd_msc_bot.c:349


rosflight_firmware
Author(s): Daniel Koch , James Jackson
autogenerated on Thu Oct 24 2019 03:17:20