Prusa MINI Firmware overview
USBH_MSC_CORE_Private_Functions
Collaboration diagram for USBH_MSC_CORE_Private_Functions:

Functions

uint8_t USBH_MSC_IsReady (USBH_HandleTypeDef *phost)
 USBH_MSC_IsReady The function check if the MSC function is ready. More...
 
int8_t USBH_MSC_GetMaxLUN (USBH_HandleTypeDef *phost)
 USBH_MSC_GetMaxLUN The function return the Max LUN supported. More...
 
uint8_t USBH_MSC_UnitIsReady (USBH_HandleTypeDef *phost, uint8_t lun)
 USBH_MSC_UnitIsReady The function check whether a LUN is ready. More...
 
USBH_StatusTypeDef USBH_MSC_GetLUNInfo (USBH_HandleTypeDef *phost, uint8_t lun, MSC_LUNTypeDef *info)
 USBH_MSC_GetLUNInfo The function return a LUN information. More...
 
USBH_StatusTypeDef USBH_MSC_Read (USBH_HandleTypeDef *phost, uint8_t lun, uint32_t address, uint8_t *pbuf, uint32_t length)
 USBH_MSC_Read The function performs a Read operation. More...
 
USBH_StatusTypeDef USBH_MSC_Write (USBH_HandleTypeDef *phost, uint8_t lun, uint32_t address, uint8_t *pbuf, uint32_t length)
 USBH_MSC_Write The function performs a Write operation. More...
 
static USBH_StatusTypeDef USBH_MSC_InterfaceInit (USBH_HandleTypeDef *phost)
 USBH_MSC_InterfaceInit The function init the MSC class. More...
 
static USBH_StatusTypeDef USBH_MSC_InterfaceDeInit (USBH_HandleTypeDef *phost)
 USBH_MSC_InterfaceDeInit The function DeInit the Pipes used for the MSC class. More...
 
static USBH_StatusTypeDef USBH_MSC_ClassRequest (USBH_HandleTypeDef *phost)
 USBH_MSC_ClassRequest The function is responsible for handling Standard requests for MSC class. More...
 
static USBH_StatusTypeDef USBH_MSC_Process (USBH_HandleTypeDef *phost)
 USBH_MSC_Process The function is for managing state machine for MSC data transfers. More...
 
static USBH_StatusTypeDef USBH_MSC_SOFProcess (USBH_HandleTypeDef *phost)
 USBH_MSC_SOFProcess The function is for SOF state. More...
 
static USBH_StatusTypeDef USBH_MSC_RdWrProcess (USBH_HandleTypeDef *phost, uint8_t lun)
 USBH_MSC_RdWrProcess The function is for managing state machine for MSC I/O Process. More...
 

Detailed Description

Function Documentation

◆ USBH_MSC_IsReady()

uint8_t USBH_MSC_IsReady ( USBH_HandleTypeDef phost)

USBH_MSC_IsReady The function check if the MSC function is ready.

Parameters
phostHost handle
Return values
USBHStatus
618 {
619  MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData;
620 
621  if(phost->gState == HOST_CLASS)
622  {
623  return (MSC_Handle->state == MSC_IDLE);
624  }
625  else
626  {
627  return 0;
628  }
629 }

◆ USBH_MSC_GetMaxLUN()

int8_t USBH_MSC_GetMaxLUN ( USBH_HandleTypeDef phost)

USBH_MSC_GetMaxLUN The function return the Max LUN supported.

Parameters
phostHost handle
Return values
logicalUnit Number supported
638 {
639  MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData;
640 
641  if ((phost->gState == HOST_CLASS) && (MSC_Handle->state == MSC_IDLE))
642  {
643  return MSC_Handle->max_lun;
644  }
645  return 0xFF;
646 }
Here is the call graph for this function:

◆ USBH_MSC_UnitIsReady()

uint8_t USBH_MSC_UnitIsReady ( USBH_HandleTypeDef phost,
uint8_t  lun 
)

USBH_MSC_UnitIsReady The function check whether a LUN is ready.

Parameters
phostHost handle
lunlogical Unit Number
Return values
Lunstatus (0: not ready / 1: ready)
656 {
657  MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData;
658 
659  if(phost->gState == HOST_CLASS)
660  {
661  return (MSC_Handle->unit[lun].error == MSC_OK);
662  }
663  else
664  {
665  return 0;
666  }
667 }
Here is the caller graph for this function:

◆ USBH_MSC_GetLUNInfo()

USBH_StatusTypeDef USBH_MSC_GetLUNInfo ( USBH_HandleTypeDef phost,
uint8_t  lun,
MSC_LUNTypeDef info 
)

USBH_MSC_GetLUNInfo The function return a LUN information.

Parameters
phostHost handle
lunlogical Unit Number
Return values
USBHStatus
677 {
678  MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData;
679  if(phost->gState == HOST_CLASS)
680  {
681  USBH_memcpy(info,&MSC_Handle->unit[lun], sizeof(MSC_LUNTypeDef));
682  return USBH_OK;
683  }
684  else
685  {
686  return USBH_FAIL;
687  }
688 }
Here is the caller graph for this function:

◆ USBH_MSC_Read()

USBH_StatusTypeDef USBH_MSC_Read ( USBH_HandleTypeDef phost,
uint8_t  lun,
uint32_t  address,
uint8_t pbuf,
uint32_t  length 
)

USBH_MSC_Read The function performs a Read operation.

Parameters
phostHost handle
lunlogical Unit Number
addresssector address
pbufpointer to data
lengthnumber of sector to read
Return values
USBHStatus
705 {
706  uint32_t timeout;
707  MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData;
708 
709  if ((phost->device.is_connected == 0) ||
710  (phost->gState != HOST_CLASS) ||
711  (MSC_Handle->unit[lun].state != MSC_IDLE))
712  {
713  return USBH_FAIL;
714  }
715  MSC_Handle->state = MSC_READ;
716  MSC_Handle->unit[lun].state = MSC_READ;
717  MSC_Handle->rw_lun = lun;
718  USBH_MSC_SCSI_Read(phost,
719  lun,
720  address,
721  pbuf,
722  length);
723 
724  timeout = phost->Timer;
725 
726  while (USBH_MSC_RdWrProcess(phost, lun) == USBH_BUSY)
727  {
728  if(((phost->Timer - timeout) > (10000 * length)) || (phost->device.is_connected == 0))
729  {
730  MSC_Handle->state = MSC_IDLE;
731  return USBH_FAIL;
732  }
733  }
734  MSC_Handle->state = MSC_IDLE;
735  return USBH_OK;
736 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ USBH_MSC_Write()

USBH_StatusTypeDef USBH_MSC_Write ( USBH_HandleTypeDef phost,
uint8_t  lun,
uint32_t  address,
uint8_t pbuf,
uint32_t  length 
)

USBH_MSC_Write The function performs a Write operation.

Parameters
phostHost handle
lunlogical Unit Number
addresssector address
pbufpointer to data
lengthnumber of sector to write
Return values
USBHStatus
753 {
754  uint32_t timeout;
755  MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData;
756 
757  if ((phost->device.is_connected == 0) ||
758  (phost->gState != HOST_CLASS) ||
759  (MSC_Handle->unit[lun].state != MSC_IDLE))
760  {
761  return USBH_FAIL;
762  }
763  MSC_Handle->state = MSC_WRITE;
764  MSC_Handle->unit[lun].state = MSC_WRITE;
765  MSC_Handle->rw_lun = lun;
766  USBH_MSC_SCSI_Write(phost,
767  lun,
768  address,
769  pbuf,
770  length);
771 
772  timeout = phost->Timer;
773  while (USBH_MSC_RdWrProcess(phost, lun) == USBH_BUSY)
774  {
775  if(((phost->Timer - timeout) > (10000 * length)) || (phost->device.is_connected == 0))
776  {
777  MSC_Handle->state = MSC_IDLE;
778  return USBH_FAIL;
779  }
780  }
781  MSC_Handle->state = MSC_IDLE;
782  return USBH_OK;
783 }
Here is the call graph for this function:

◆ USBH_MSC_InterfaceInit()

static USBH_StatusTypeDef USBH_MSC_InterfaceInit ( USBH_HandleTypeDef phost)
static

USBH_MSC_InterfaceInit The function init the MSC class.

Parameters
phostHost handle
Return values
USBHStatus
150 {
151  uint8_t interface = 0;
153  MSC_HandleTypeDef *MSC_Handle;
154 
155  interface = USBH_FindInterface(phost, phost->pActiveClass->ClassCode, MSC_TRANSPARENT, MSC_BOT);
156 
157  if(interface == 0xFF) /* Not Valid Interface */
158  {
159  USBH_DbgLog ("Cannot Find the interface for %s class.", phost->pActiveClass->Name);
160  status = USBH_FAIL;
161  }
162  else
163  {
164  USBH_SelectInterface (phost, interface);
165 
167  MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData;
168 
170  {
171  MSC_Handle->InEp = (phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[0].bEndpointAddress);
173  }
174  else
175  {
176  MSC_Handle->OutEp = (phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[0].bEndpointAddress);
178  }
179 
181  {
182  MSC_Handle->InEp = (phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[1].bEndpointAddress);
184  }
185  else
186  {
187  MSC_Handle->OutEp = (phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[1].bEndpointAddress);
189  }
190 
191  MSC_Handle->current_lun = 0;
192  MSC_Handle->rw_lun = 0;
193  MSC_Handle->state = MSC_INIT;
194  MSC_Handle->error = MSC_OK;
195  MSC_Handle->req_state = MSC_REQ_IDLE;
196  MSC_Handle->OutPipe = USBH_AllocPipe(phost, MSC_Handle->OutEp);
197  MSC_Handle->InPipe = USBH_AllocPipe(phost, MSC_Handle->InEp);
198 
199  USBH_MSC_BOT_Init(phost);
200 
201  /* De-Initialize LUNs information */
202  USBH_memset(MSC_Handle->unit, 0, sizeof(MSC_Handle->unit));
203 
204  /* Open the new channels */
205  USBH_OpenPipe (phost,
206  MSC_Handle->OutPipe,
207  MSC_Handle->OutEp,
208  phost->device.address,
209  phost->device.speed,
211  MSC_Handle->OutEpSize);
212 
213  USBH_OpenPipe (phost,
214  MSC_Handle->InPipe,
215  MSC_Handle->InEp,
216  phost->device.address,
217  phost->device.speed,
219  MSC_Handle->InEpSize);
220 
221 
222  USBH_LL_SetToggle (phost, MSC_Handle->InPipe,0);
223  USBH_LL_SetToggle (phost, MSC_Handle->OutPipe,0);
224  status = USBH_OK;
225  }
226  return status;
227 }
Here is the call graph for this function:

◆ USBH_MSC_InterfaceDeInit()

USBH_StatusTypeDef USBH_MSC_InterfaceDeInit ( USBH_HandleTypeDef phost)
static

USBH_MSC_InterfaceDeInit The function DeInit the Pipes used for the MSC class.

Parameters
phostHost handle
Return values
USBHStatus
236 {
237  MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData;
238 
239  if ( MSC_Handle->OutPipe)
240  {
241  USBH_ClosePipe(phost, MSC_Handle->OutPipe);
242  USBH_FreePipe (phost, MSC_Handle->OutPipe);
243  MSC_Handle->OutPipe = 0; /* Reset the Channel as Free */
244  }
245 
246  if ( MSC_Handle->InPipe)
247  {
248  USBH_ClosePipe(phost, MSC_Handle->InPipe);
249  USBH_FreePipe (phost, MSC_Handle->InPipe);
250  MSC_Handle->InPipe = 0; /* Reset the Channel as Free */
251  }
252 
253  if(phost->pActiveClass->pData)
254  {
255  USBH_free (phost->pActiveClass->pData);
256  phost->pActiveClass->pData = 0;
257  }
258 
259  return USBH_OK;
260 }
Here is the call graph for this function:

◆ USBH_MSC_ClassRequest()

static USBH_StatusTypeDef USBH_MSC_ClassRequest ( USBH_HandleTypeDef phost)
static

USBH_MSC_ClassRequest The function is responsible for handling Standard requests for MSC class.

Parameters
phostHost handle
Return values
USBHStatus
270 {
271  MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData;
273  uint8_t i;
274 
275  /* Switch MSC REQ state machine */
276  switch (MSC_Handle->req_state)
277  {
278  case MSC_REQ_IDLE:
279  case MSC_REQ_GET_MAX_LUN:
280  /* Issue GetMaxLUN request */
281  status = USBH_MSC_BOT_REQ_GetMaxLUN(phost, (uint8_t *)&MSC_Handle->max_lun);
282 
283  /* When devices do not support the GetMaxLun request, this should
284  be considred as only one logical unit is supported */
286  {
287  MSC_Handle->max_lun = 0;
288  status = USBH_OK;
289  }
290 
291  if(status == USBH_OK)
292  {
293  MSC_Handle->max_lun = (uint8_t )(MSC_Handle->max_lun) + 1;
294  USBH_UsrLog ("Number of supported LUN: %lu", (int32_t)(MSC_Handle->max_lun));
295 
296  for(i = 0; i < MSC_Handle->max_lun; i++)
297  {
298  MSC_Handle->unit[i].prev_ready_state = USBH_FAIL;
299  MSC_Handle->unit[i].state_changed = 0;
300  }
301  }
302  break;
303 
304  case MSC_REQ_ERROR :
305  /* a Clear Feature should be issued here */
306  if(USBH_ClrFeature(phost, 0x00) == USBH_OK)
307  {
308  MSC_Handle->req_state = MSC_Handle->prev_req_state;
309  }
310  break;
311 
312  default:
313  break;
314  }
315 
316  return status;
317 }
Here is the call graph for this function:

◆ USBH_MSC_Process()

static USBH_StatusTypeDef USBH_MSC_Process ( USBH_HandleTypeDef phost)
static

USBH_MSC_Process The function is for managing state machine for MSC data transfers.

Parameters
phostHost handle
Return values
USBHStatus
326 {
327  MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData;
329  USBH_StatusTypeDef scsi_status = USBH_BUSY ;
330  USBH_StatusTypeDef ready_status = USBH_BUSY ;
331 
332  switch (MSC_Handle->state)
333  {
334  case MSC_INIT:
335 
336  if(MSC_Handle->current_lun < MSC_Handle->max_lun)
337  {
338 
339  MSC_Handle->unit[MSC_Handle->current_lun].error = MSC_NOT_READY;
340  /* Switch MSC REQ state machine */
341  switch (MSC_Handle->unit[MSC_Handle->current_lun].state)
342  {
343  case MSC_INIT:
344  USBH_UsrLog ("LUN #%d: ", MSC_Handle->current_lun);
345  MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_READ_INQUIRY;
346  MSC_Handle->timer = phost->Timer;
347 
348  case MSC_READ_INQUIRY:
349  scsi_status = USBH_MSC_SCSI_Inquiry(phost, MSC_Handle->current_lun, &MSC_Handle->unit[MSC_Handle->current_lun].inquiry);
350 
351  if( scsi_status == USBH_OK)
352  {
353  USBH_UsrLog ("Inquiry Vendor : %s", MSC_Handle->unit[MSC_Handle->current_lun].inquiry.vendor_id);
354  USBH_UsrLog ("Inquiry Product : %s", MSC_Handle->unit[MSC_Handle->current_lun].inquiry.product_id);
355  USBH_UsrLog ("Inquiry Version : %s", MSC_Handle->unit[MSC_Handle->current_lun].inquiry.revision_id);
356  MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_TEST_UNIT_READY;
357  }
358  if( scsi_status == USBH_FAIL)
359  {
360  MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_REQUEST_SENSE;
361  }
362  else if(scsi_status == USBH_UNRECOVERED_ERROR)
363  {
364  MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_IDLE;
365  MSC_Handle->unit[MSC_Handle->current_lun].error = MSC_ERROR;
366  }
367  break;
368 
369  case MSC_TEST_UNIT_READY:
370  ready_status = USBH_MSC_SCSI_TestUnitReady(phost, MSC_Handle->current_lun);
371 
372  if( ready_status == USBH_OK)
373  {
374  if( MSC_Handle->unit[MSC_Handle->current_lun].prev_ready_state != USBH_OK)
375  {
376  MSC_Handle->unit[MSC_Handle->current_lun].state_changed = 1;
377  USBH_UsrLog ("MSC Device ready");
378  }
379  else
380  {
381  MSC_Handle->unit[MSC_Handle->current_lun].state_changed = 0;
382  }
383  MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_READ_CAPACITY10;
384  MSC_Handle->unit[MSC_Handle->current_lun].error = MSC_OK;
385  MSC_Handle->unit[MSC_Handle->current_lun].prev_ready_state = USBH_OK;
386  }
387  if( ready_status == USBH_FAIL)
388  {
389  /* Media not ready, so try to check again during 10s */
390  if( MSC_Handle->unit[MSC_Handle->current_lun].prev_ready_state != USBH_FAIL)
391  {
392  MSC_Handle->unit[MSC_Handle->current_lun].state_changed = 1;
393  USBH_UsrLog ("MSC Device NOT ready");
394  }
395  else
396  {
397  MSC_Handle->unit[MSC_Handle->current_lun].state_changed = 0;
398  }
399  MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_REQUEST_SENSE;
400  MSC_Handle->unit[MSC_Handle->current_lun].error = MSC_NOT_READY;
401  MSC_Handle->unit[MSC_Handle->current_lun].prev_ready_state = USBH_FAIL;
402  }
403  else if(ready_status == USBH_UNRECOVERED_ERROR)
404  {
405  MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_IDLE;
406  MSC_Handle->unit[MSC_Handle->current_lun].error = MSC_ERROR;
407  }
408  break;
409 
410  case MSC_READ_CAPACITY10:
411  scsi_status = USBH_MSC_SCSI_ReadCapacity(phost,MSC_Handle->current_lun, &MSC_Handle->unit[MSC_Handle->current_lun].capacity) ;
412 
413  if(scsi_status == USBH_OK)
414  {
415  if(MSC_Handle->unit[MSC_Handle->current_lun].state_changed == 1)
416  {
417  USBH_UsrLog ("MSC Device capacity : %lu Bytes", \
418  (int32_t)(MSC_Handle->unit[MSC_Handle->current_lun].capacity.block_nbr * MSC_Handle->unit[MSC_Handle->current_lun].capacity.block_size));
419  USBH_UsrLog ("Block number : %lu", (int32_t)(MSC_Handle->unit[MSC_Handle->current_lun].capacity.block_nbr));
420  USBH_UsrLog ("Block Size : %lu", (int32_t)(MSC_Handle->unit[MSC_Handle->current_lun].capacity.block_size));
421  }
422  MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_IDLE;
423  MSC_Handle->unit[MSC_Handle->current_lun].error = MSC_OK;
424  MSC_Handle->current_lun++;
425  }
426  else if( scsi_status == USBH_FAIL)
427  {
428  MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_REQUEST_SENSE;
429  }
430  else if(scsi_status == USBH_UNRECOVERED_ERROR)
431  {
432  MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_IDLE;
433  MSC_Handle->unit[MSC_Handle->current_lun].error = MSC_ERROR;
434  }
435  break;
436 
437  case MSC_REQUEST_SENSE:
438  scsi_status = USBH_MSC_SCSI_RequestSense(phost, MSC_Handle->current_lun, &MSC_Handle->unit[MSC_Handle->current_lun].sense);
439 
440  if( scsi_status == USBH_OK)
441  {
442  if((MSC_Handle->unit[MSC_Handle->current_lun].sense.key == SCSI_SENSE_KEY_UNIT_ATTENTION) ||
443  (MSC_Handle->unit[MSC_Handle->current_lun].sense.key == SCSI_SENSE_KEY_NOT_READY) )
444  {
445 
446  if((phost->Timer - MSC_Handle->timer) < 10000)
447  {
448  MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_TEST_UNIT_READY;
449  break;
450  }
451  }
452 
453  USBH_UsrLog ("Sense Key : %x", MSC_Handle->unit[MSC_Handle->current_lun].sense.key);
454  USBH_UsrLog ("Additional Sense Code : %x", MSC_Handle->unit[MSC_Handle->current_lun].sense.asc);
455  USBH_UsrLog ("Additional Sense Code Qualifier: %x", MSC_Handle->unit[MSC_Handle->current_lun].sense.ascq);
456  MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_IDLE;
457  MSC_Handle->current_lun++;
458  }
459  if( scsi_status == USBH_FAIL)
460  {
461  USBH_UsrLog ("MSC Device NOT ready");
462  MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_UNRECOVERED_ERROR;
463  }
464  else if(scsi_status == USBH_UNRECOVERED_ERROR)
465  {
466  MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_IDLE;
467  MSC_Handle->unit[MSC_Handle->current_lun].error = MSC_ERROR;
468  }
469  break;
470 
472  MSC_Handle->current_lun++;
473  break;
474 
475  default:
476  break;
477  }
478 
479 #if (USBH_USE_OS == 1)
480  osMessagePut ( phost->os_event, USBH_CLASS_EVENT, 0);
481 #endif
482  }
483  else
484  {
485  MSC_Handle->current_lun = 0;
486  MSC_Handle->state = MSC_IDLE;
487 #if (USBH_USE_OS == 1)
488  osMessagePut ( phost->os_event, USBH_CLASS_EVENT, 0);
489 #endif
490  phost->pUser(phost, HOST_USER_CLASS_ACTIVE);
491  }
492  break;
493 
494  case MSC_IDLE:
495  error = USBH_OK;
496  break;
497 
498  default:
499  break;
500  }
501  return error;
502 }
Here is the call graph for this function:

◆ USBH_MSC_SOFProcess()

static USBH_StatusTypeDef USBH_MSC_SOFProcess ( USBH_HandleTypeDef phost)
static

USBH_MSC_SOFProcess The function is for SOF state.

Parameters
phostHost handle
Return values
USBHStatus
512 {
513 
514  return USBH_OK;
515 }

◆ USBH_MSC_RdWrProcess()

static USBH_StatusTypeDef USBH_MSC_RdWrProcess ( USBH_HandleTypeDef phost,
uint8_t  lun 
)
static

USBH_MSC_RdWrProcess The function is for managing state machine for MSC I/O Process.

Parameters
phostHost handle
lunlogical Unit Number
Return values
USBHStatus
524 {
525  MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData;
527  USBH_StatusTypeDef scsi_status = USBH_BUSY ;
528 
529  /* Switch MSC REQ state machine */
530  switch (MSC_Handle->unit[lun].state)
531  {
532 
533  case MSC_READ:
534  scsi_status = USBH_MSC_SCSI_Read(phost,lun, 0, NULL, 0) ;
535 
536  if(scsi_status == USBH_OK)
537  {
538  MSC_Handle->unit[lun].state = MSC_IDLE;
539  error = USBH_OK;
540  }
541  else if( scsi_status == USBH_FAIL)
542  {
543  MSC_Handle->unit[lun].state = MSC_REQUEST_SENSE;
544  }
545  else if(scsi_status == USBH_UNRECOVERED_ERROR)
546  {
547  MSC_Handle->unit[lun].state = MSC_UNRECOVERED_ERROR;
548  error = USBH_FAIL;
549  }
550 #if (USBH_USE_OS == 1)
551  osMessagePut ( phost->os_event, USBH_CLASS_EVENT, 0);
552 #endif
553  break;
554 
555  case MSC_WRITE:
556  scsi_status = USBH_MSC_SCSI_Write(phost,lun, 0, NULL, 0) ;
557 
558  if(scsi_status == USBH_OK)
559  {
560  MSC_Handle->unit[lun].state = MSC_IDLE;
561  error = USBH_OK;
562  }
563  else if( scsi_status == USBH_FAIL)
564  {
565  MSC_Handle->unit[lun].state = MSC_REQUEST_SENSE;
566  }
567  else if(scsi_status == USBH_UNRECOVERED_ERROR)
568  {
569  MSC_Handle->unit[lun].state = MSC_UNRECOVERED_ERROR;
570  error = USBH_FAIL;
571  }
572 #if (USBH_USE_OS == 1)
573  osMessagePut ( phost->os_event, USBH_CLASS_EVENT, 0);
574 #endif
575  break;
576 
577  case MSC_REQUEST_SENSE:
578  scsi_status = USBH_MSC_SCSI_RequestSense(phost, lun, &MSC_Handle->unit[lun].sense);
579 
580  if( scsi_status == USBH_OK)
581  {
582  USBH_UsrLog ("Sense Key : %x", MSC_Handle->unit[lun].sense.key);
583  USBH_UsrLog ("Additional Sense Code : %x", MSC_Handle->unit[lun].sense.asc);
584  USBH_UsrLog ("Additional Sense Code Qualifier: %x", MSC_Handle->unit[lun].sense.ascq);
585  MSC_Handle->unit[lun].state = MSC_IDLE;
586  MSC_Handle->unit[lun].error = MSC_ERROR;
587 
588  error = USBH_FAIL;
589  }
590  if( scsi_status == USBH_FAIL)
591  {
592  USBH_UsrLog ("MSC Device NOT ready");
593  }
594  else if(scsi_status == USBH_UNRECOVERED_ERROR)
595  {
596  MSC_Handle->unit[lun].state = MSC_UNRECOVERED_ERROR;
597  error = USBH_FAIL;
598  }
599 #if (USBH_USE_OS == 1)
600  osMessagePut ( phost->os_event, USBH_CLASS_EVENT, 0);
601 #endif
602  break;
603 
604  default:
605  break;
606 
607  }
608  return error;
609 }
Here is the call graph for this function:
Here is the caller graph for this function:
MSC_REQ_GET_MAX_LUN
Definition: usbh_msc.h:91
USBH_malloc
#define USBH_malloc
Definition: usbh_conf.h:148
_MSC_Process::timer
uint32_t timer
Definition: usbh_msc.h:133
MSC_NOT_READY
Definition: usbh_msc.h:81
MSC_TRANSPARENT
#define MSC_TRANSPARENT
Definition: usbh_msc.h:157
MSC_REQ_ERROR
Definition: usbh_msc.h:92
USBH_UNRECOVERED_ERROR
Definition: usbh_def.h:308
MSC_TEST_UNIT_READY
Definition: usbh_msc.h:67
auto_build.error
bool error
Definition: auto_build.py:637
USBH_MSC_SCSI_Read
USBH_StatusTypeDef USBH_MSC_SCSI_Read(USBH_HandleTypeDef *phost, uint8_t lun, uint32_t address, uint8_t *pbuf, uint32_t length)
USBH_MSC_SCSI_Read Issue Read10 command.
Definition: usbh_msc_scsi.c:384
HOST_USER_CLASS_ACTIVE
#define HOST_USER_CLASS_ACTIVE
Definition: usbh_core.h:65
USBH_SelectInterface
USBH_StatusTypeDef USBH_SelectInterface(USBH_HandleTypeDef *phost, uint8_t interface)
USBH_SelectInterface Select current interface.
Definition: usbh_core.c:233
USBH_CLASS_EVENT
Definition: usbh_def.h:398
USBH_DeviceTypeDef::current_interface
uint8_t current_interface
Definition: usbh_def.h:428
USBH_MSC_BOT_Init
USBH_StatusTypeDef USBH_MSC_BOT_Init(USBH_HandleTypeDef *phost)
USBH_MSC_BOT_Init The function Initializes the BOT protocol.
Definition: usbh_msc_bot.c:151
MSC_LUNTypeDef::capacity
SCSI_CapacityTypeDef capacity
Definition: usbh_msc.h:107
_ConfigurationDescriptor::Itf_Desc
USBH_InterfaceDescTypeDef Itf_Desc[USBH_MAX_NUM_INTERFACES]
Definition: usbh_def.h:296
SCSI_SENSE_KEY_UNIT_ATTENTION
#define SCSI_SENSE_KEY_UNIT_ATTENTION
Definition: usbh_msc_scsi.h:112
MSC_LUNTypeDef
Definition: usbh_msc.h:102
USBH_ClrFeature
USBH_StatusTypeDef USBH_ClrFeature(USBH_HandleTypeDef *phost, uint8_t ep_num)
USBH_ClrFeature This request is used to clear or disable a specific feature.
Definition: usbh_ctlreq.c:308
_InterfaceDescriptor::Ep_Desc
USBH_EpDescTypeDef Ep_Desc[USBH_MAX_NUM_ENDPOINTS]
Definition: usbh_def.h:281
USBH_MSC_SCSI_ReadCapacity
USBH_StatusTypeDef USBH_MSC_SCSI_ReadCapacity(USBH_HandleTypeDef *phost, uint8_t lun, SCSI_CapacityTypeDef *capacity)
USBH_MSC_SCSI_ReadCapacity Issue Read Capacity command.
Definition: usbh_msc_scsi.c:146
USBH_free
#define USBH_free
Definition: usbh_conf.h:151
MSC_UNRECOVERED_ERROR
Definition: usbh_msc.h:73
i
uint8_t i
Definition: screen_test_graph.c:72
USBH_ClosePipe
USBH_StatusTypeDef USBH_ClosePipe(USBH_HandleTypeDef *phost, uint8_t pipe_num)
USBH_ClosePipe Close a pipe.
Definition: usbh_pipes.c:121
MSC_WRITE
Definition: usbh_msc.h:72
SCSI_SenseTypeDef::key
uint8_t key
Definition: usbh_msc_scsi.h:69
USBH_MSC_SCSI_TestUnitReady
USBH_StatusTypeDef USBH_MSC_SCSI_TestUnitReady(USBH_HandleTypeDef *phost, uint8_t lun)
USBH_MSC_SCSI_TestUnitReady Issue TestUnitReady command.
Definition: usbh_msc_scsi.c:104
SCSI_StdInquiryDataTypeDef::product_id
uint8_t product_id[17]
Definition: usbh_msc_scsi.h:81
_USBH_HandleTypeDef::Timer
__IO uint32_t Timer
Definition: usbh_def.h:461
_MSC_Process::OutEpSize
uint16_t OutEpSize
Definition: usbh_msc.h:123
NULL
#define NULL
Definition: usbd_def.h:53
USBH_ClassTypeDef::pData
void * pData
Definition: usbh_def.h:446
USBH_memset
#define USBH_memset
Definition: usbh_conf.h:154
USBH_memcpy
#define USBH_memcpy
Definition: usbh_conf.h:157
MSC_READ_CAPACITY10
Definition: usbh_msc.h:68
_MSC_Process::InPipe
uint8_t InPipe
Definition: usbh_msc.h:119
MSC_LUNTypeDef::error
MSC_ErrorTypeDef error
Definition: usbh_msc.h:105
USBH_DeviceTypeDef::address
uint8_t address
Definition: usbh_def.h:425
MSC_LUNTypeDef::inquiry
SCSI_StdInquiryDataTypeDef inquiry
Definition: usbh_msc.h:109
USBH_MSC_RdWrProcess
static USBH_StatusTypeDef USBH_MSC_RdWrProcess(USBH_HandleTypeDef *phost, uint8_t lun)
USBH_MSC_RdWrProcess The function is for managing state machine for MSC I/O Process.
Definition: usbh_msc.c:523
USBH_FreePipe
USBH_StatusTypeDef USBH_FreePipe(USBH_HandleTypeDef *phost, uint8_t idx)
USBH_Free_Pipe Free the USB Pipe.
Definition: usbh_pipes.c:158
SCSI_SenseTypeDef::asc
uint8_t asc
Definition: usbh_msc_scsi.h:70
USBH_DeviceTypeDef::CfgDesc
USBH_CfgDescTypeDef CfgDesc
Definition: usbh_def.h:430
USBH_OpenPipe
USBH_StatusTypeDef USBH_OpenPipe(USBH_HandleTypeDef *phost, uint8_t ch_num, uint8_t epnum, uint8_t dev_address, uint8_t speed, uint8_t ep_type, uint16_t mps)
USBH_Open_Pipe Open a pipe.
Definition: usbh_pipes.c:93
_MSC_Process::prev_req_state
MSC_ReqStateTypeDef prev_req_state
Definition: usbh_msc.h:128
MSC_OK
Definition: usbh_msc.h:80
MSC_READ_INQUIRY
Definition: usbh_msc.h:69
MSC_LUNTypeDef::state_changed
uint8_t state_changed
Definition: usbh_msc.h:110
SCSI_SenseTypeDef::ascq
uint8_t ascq
Definition: usbh_msc_scsi.h:71
USBH_OK
Definition: usbh_def.h:304
osMessagePut
osStatus osMessagePut(osMessageQId queue_id, uint32_t info, uint32_t millisec)
Put a Message to a Queue.
Definition: cmsis_os.c:1113
USBH_MSC_SCSI_Inquiry
USBH_StatusTypeDef USBH_MSC_SCSI_Inquiry(USBH_HandleTypeDef *phost, uint8_t lun, SCSI_StdInquiryDataTypeDef *inquiry)
USBH_MSC_SCSI_Inquiry Issue Inquiry command.
Definition: usbh_msc_scsi.c:202
USBH_DbgLog
#define USBH_DbgLog(...)
Definition: usbh_conf.h:185
_USBH_HandleTypeDef::device
USBH_DeviceTypeDef device
Definition: usbh_def.h:456
USBH_DeviceTypeDef::speed
uint8_t speed
Definition: usbh_def.h:426
SCSI_StdInquiryDataTypeDef::revision_id
uint8_t revision_id[5]
Definition: usbh_msc_scsi.h:82
_MSC_Process::rw_lun
uint16_t rw_lun
Definition: usbh_msc.h:132
USBH_DeviceTypeDef::is_connected
__IO uint8_t is_connected
Definition: usbh_def.h:427
_MSC_Process::unit
MSC_LUNTypeDef unit[MAX_SUPPORTED_LUN]
Definition: usbh_msc.h:130
MSC_REQUEST_SENSE
Definition: usbh_msc.h:70
if
if(size<=((png_alloc_size_t) -1) - ob)
Definition: pngwrite.c:2176
SCSI_SENSE_KEY_NOT_READY
#define SCSI_SENSE_KEY_NOT_READY
Definition: usbh_msc_scsi.h:108
SCSI_CapacityTypeDef::block_nbr
uint32_t block_nbr
Definition: usbh_msc_scsi.h:61
_MSC_Process::state
MSC_StateTypeDef state
Definition: usbh_msc.h:125
SCSI_StdInquiryDataTypeDef::vendor_id
uint8_t vendor_id[9]
Definition: usbh_msc_scsi.h:80
_MSC_Process::current_lun
uint16_t current_lun
Definition: usbh_msc.h:131
uint8_t
const uint8_t[]
Definition: 404_html.c:3
MSC_LUNTypeDef::prev_ready_state
USBH_StatusTypeDef prev_ready_state
Definition: usbh_msc.h:106
USBH_UsrLog
#define USBH_UsrLog(...)
Definition: usbh_conf.h:166
address
UsbDeviceAddress address
Definition: address.h:202
_MSC_Process::req_state
MSC_ReqStateTypeDef req_state
Definition: usbh_msc.h:127
MSC_BOT
#define MSC_BOT
Definition: usbh_msc.h:156
USBH_StatusTypeDef
USBH_StatusTypeDef
Definition: usbh_def.h:302
_MSC_Process::InEpSize
uint16_t InEpSize
Definition: usbh_msc.h:124
USB_EP_TYPE_BULK
#define USB_EP_TYPE_BULK
Definition: usbh_def.h:172
USBH_LL_SetToggle
USBH_StatusTypeDef USBH_LL_SetToggle(USBH_HandleTypeDef *phost, uint8_t, uint8_t)
Set toggle for a pipe.
Definition: usbh_conf.c:564
status
static status_t status
Definition: filament_sensor.c:37
_MSC_Process::InEp
uint8_t InEp
Definition: usbh_msc.h:122
_MSC_Process::error
MSC_ErrorTypeDef error
Definition: usbh_msc.h:126
USBH_MSC_SCSI_RequestSense
USBH_StatusTypeDef USBH_MSC_SCSI_RequestSense(USBH_HandleTypeDef *phost, uint8_t lun, SCSI_SenseTypeDef *sense_data)
USBH_MSC_SCSI_RequestSense Issue RequestSense command.
Definition: usbh_msc_scsi.c:264
_MSC_Process::OutPipe
uint8_t OutPipe
Definition: usbh_msc.h:120
_MSC_Process::max_lun
uint32_t max_lun
Definition: usbh_msc.h:118
USBH_MSC_SCSI_Write
USBH_StatusTypeDef USBH_MSC_SCSI_Write(USBH_HandleTypeDef *phost, uint8_t lun, uint32_t address, uint8_t *pbuf, uint32_t length)
USBH_MSC_SCSI_Write Issue write10 command.
Definition: usbh_msc_scsi.c:323
USBH_FindInterface
uint8_t USBH_FindInterface(USBH_HandleTypeDef *phost, uint8_t Class, uint8_t SubClass, uint8_t Protocol)
USBH_FindInterface Find the interface index for a specific class.
Definition: usbh_core.c:274
USBH_MSC_BOT_REQ_GetMaxLUN
USBH_StatusTypeDef USBH_MSC_BOT_REQ_GetMaxLUN(USBH_HandleTypeDef *phost, uint8_t *Maxlun)
USBH_MSC_BOT_REQ_GetMaxLUN The function the MSC BOT GetMaxLUN request.
Definition: usbh_msc_bot.c:130
MSC_READ
Definition: usbh_msc.h:71
_MSC_Process::OutEp
uint8_t OutEp
Definition: usbh_msc.h:121
USBH_FAIL
Definition: usbh_def.h:306
USBH_BUSY
Definition: usbh_def.h:305
MSC_IDLE
Definition: usbh_msc.h:66
_USBH_HandleTypeDef::pUser
void(* pUser)(struct _USBH_HandleTypeDef *pHandle, uint8_t id)
Definition: usbh_def.h:464
USBH_ClassTypeDef::Name
const char * Name
Definition: usbh_def.h:439
MSC_INIT
Definition: usbh_msc.h:65
length
png_uint_32 length
Definition: png.c:2247
_USBH_HandleTypeDef::pActiveClass
USBH_ClassTypeDef * pActiveClass
Definition: usbh_def.h:458
_USBH_HandleTypeDef::gState
__IO HOST_StateTypeDef gState
Definition: usbh_def.h:452
pbuf
Definition: pbuf.h:142
USBH_AllocPipe
uint8_t USBH_AllocPipe(USBH_HandleTypeDef *phost, uint8_t ep_addr)
USBH_Alloc_Pipe Allocate a new Pipe.
Definition: usbh_pipes.c:138
MSC_LUNTypeDef::state
MSC_StateTypeDef state
Definition: usbh_msc.h:104
MSC_REQ_IDLE
Definition: usbh_msc.h:89
HOST_CLASS
Definition: usbh_def.h:338
MSC_ERROR
Definition: usbh_msc.h:82
_EndpointDescriptor::wMaxPacketSize
uint16_t wMaxPacketSize
Definition: usbh_def.h:265
_MSC_Process
Definition: usbh_msc.h:116
_EndpointDescriptor::bEndpointAddress
uint8_t bEndpointAddress
Definition: usbh_def.h:263
SCSI_CapacityTypeDef::block_size
uint16_t block_size
Definition: usbh_msc_scsi.h:62
USBH_NOT_SUPPORTED
Definition: usbh_def.h:307
MSC_LUNTypeDef::sense
SCSI_SenseTypeDef sense
Definition: usbh_msc.h:108
info
uint8_t info[12]
Definition: masstorage.h:54