Prusa MINI Firmware overview
USBH_MSC_SCSI_Private_Functions
Collaboration diagram for USBH_MSC_SCSI_Private_Functions:

Functions

USBH_StatusTypeDef USBH_MSC_SCSI_TestUnitReady (USBH_HandleTypeDef *phost, uint8_t lun)
 USBH_MSC_SCSI_TestUnitReady Issue TestUnitReady command. More...
 
USBH_StatusTypeDef USBH_MSC_SCSI_ReadCapacity (USBH_HandleTypeDef *phost, uint8_t lun, SCSI_CapacityTypeDef *capacity)
 USBH_MSC_SCSI_ReadCapacity Issue Read Capacity command. More...
 
USBH_StatusTypeDef USBH_MSC_SCSI_Inquiry (USBH_HandleTypeDef *phost, uint8_t lun, SCSI_StdInquiryDataTypeDef *inquiry)
 USBH_MSC_SCSI_Inquiry Issue Inquiry command. More...
 
USBH_StatusTypeDef USBH_MSC_SCSI_RequestSense (USBH_HandleTypeDef *phost, uint8_t lun, SCSI_SenseTypeDef *sense_data)
 USBH_MSC_SCSI_RequestSense Issue RequestSense command. More...
 
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. More...
 
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. More...
 

Detailed Description

Function Documentation

◆ USBH_MSC_SCSI_TestUnitReady()

USBH_StatusTypeDef USBH_MSC_SCSI_TestUnitReady ( USBH_HandleTypeDef phost,
uint8_t  lun 
)

USBH_MSC_SCSI_TestUnitReady Issue TestUnitReady command.

Parameters
phostHost handle
lunLogical Unit Number
Return values
USBHStatus
106 {
108  MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData;
109 
110  switch(MSC_Handle->hbot.cmd_state)
111  {
112  case BOT_CMD_SEND:
113 
114  /*Prepare the CBW and relevent field*/
116  MSC_Handle->hbot.cbw.field.Flags = USB_EP_DIR_OUT;
117  MSC_Handle->hbot.cbw.field.CBLength = CBW_LENGTH;
118 
119  USBH_memset(MSC_Handle->hbot.cbw.field.CB, 0, CBW_CB_LENGTH);
120  MSC_Handle->hbot.cbw.field.CB[0] = OPCODE_TEST_UNIT_READY;
121 
122  MSC_Handle->hbot.state = BOT_SEND_CBW;
123  MSC_Handle->hbot.cmd_state = BOT_CMD_WAIT;
124  error = USBH_BUSY;
125  break;
126 
127  case BOT_CMD_WAIT:
128  error = USBH_MSC_BOT_Process(phost, lun);
129  break;
130 
131  default:
132  break;
133  }
134 
135  return error;
136 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

Parameters
phostHost handle
lunLogical Unit Number
capacitypointer to the capacity structure
Return values
USBHStatus
149 {
151  MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData;
152 
153  switch(MSC_Handle->hbot.cmd_state)
154  {
155  case BOT_CMD_SEND:
156 
157  /*Prepare the CBW and relevent field*/
159  MSC_Handle->hbot.cbw.field.Flags = USB_EP_DIR_IN;
160  MSC_Handle->hbot.cbw.field.CBLength = CBW_LENGTH;
161 
162  USBH_memset(MSC_Handle->hbot.cbw.field.CB, 0, CBW_CB_LENGTH);
163  MSC_Handle->hbot.cbw.field.CB[0] = OPCODE_READ_CAPACITY10;
164 
165  MSC_Handle->hbot.state = BOT_SEND_CBW;
166 
167  MSC_Handle->hbot.cmd_state = BOT_CMD_WAIT;
168  MSC_Handle->hbot.pbuf = (uint8_t *)MSC_Handle->hbot.data;
169  error = USBH_BUSY;
170  break;
171 
172  case BOT_CMD_WAIT:
173 
174  error = USBH_MSC_BOT_Process(phost, lun);
175 
176  if(error == USBH_OK)
177  {
178  /*assign the capacity*/
179  capacity->block_nbr = MSC_Handle->hbot.pbuf[3] | (MSC_Handle->hbot.pbuf[2] << 8) |\
180  (MSC_Handle->hbot.pbuf[1] << 16) | (MSC_Handle->hbot.pbuf[0] << 24);
181 
182  /*assign the page length*/
183  capacity->block_size = MSC_Handle->hbot.pbuf[7] | (MSC_Handle->hbot.pbuf[6] << 8);
184  }
185  break;
186 
187  default:
188  break;
189  }
190 
191  return error;
192 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

Parameters
phostHost handle
lunLogical Unit Number
capacitypointer to the inquiry structure
Return values
USBHStatus
205 {
207  MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData;
208  switch(MSC_Handle->hbot.cmd_state)
209  {
210  case BOT_CMD_SEND:
211 
212  /*Prepare the CBW and relevent field*/
214  MSC_Handle->hbot.cbw.field.Flags = USB_EP_DIR_IN;
215  MSC_Handle->hbot.cbw.field.CBLength = CBW_LENGTH;
216 
217  USBH_memset(MSC_Handle->hbot.cbw.field.CB, 0, CBW_LENGTH);
218  MSC_Handle->hbot.cbw.field.CB[0] = OPCODE_INQUIRY;
219  MSC_Handle->hbot.cbw.field.CB[1] = (lun << 5);
220  MSC_Handle->hbot.cbw.field.CB[2] = 0;
221  MSC_Handle->hbot.cbw.field.CB[3] = 0;
222  MSC_Handle->hbot.cbw.field.CB[4] = 0x24;
223  MSC_Handle->hbot.cbw.field.CB[5] = 0;
224 
225  MSC_Handle->hbot.state = BOT_SEND_CBW;
226 
227  MSC_Handle->hbot.cmd_state = BOT_CMD_WAIT;
228  MSC_Handle->hbot.pbuf = (uint8_t *)MSC_Handle->hbot.data;
229  error = USBH_BUSY;
230  break;
231 
232  case BOT_CMD_WAIT:
233 
234  error = USBH_MSC_BOT_Process(phost, lun);
235 
236  if(error == USBH_OK)
237  {
238  USBH_memset(inquiry, 0, sizeof(SCSI_StdInquiryDataTypeDef));
239  /*assign Inquiry Data */
240  inquiry->DeviceType = MSC_Handle->hbot.pbuf[0] & 0x1F;
241  inquiry->PeripheralQualifier = MSC_Handle->hbot.pbuf[0] >> 5;
242  inquiry->RemovableMedia = (MSC_Handle->hbot.pbuf[1] & 0x80)== 0x80;
243  USBH_memcpy (inquiry->vendor_id, &MSC_Handle->hbot.pbuf[8], 8);
244  USBH_memcpy (inquiry->product_id, &MSC_Handle->hbot.pbuf[16], 16);
245  USBH_memcpy (inquiry->revision_id, &MSC_Handle->hbot.pbuf[32], 4);
246  }
247  break;
248 
249  default:
250  break;
251  }
252 
253  return error;
254 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

Parameters
phostHost handle
lunLogical Unit Number
capacitypointer to the sense data structure
Return values
USBHStatus
267 {
269  MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData;
270 
271  switch(MSC_Handle->hbot.cmd_state)
272  {
273  case BOT_CMD_SEND:
274 
275  /*Prepare the CBW and relevent field*/
277  MSC_Handle->hbot.cbw.field.Flags = USB_EP_DIR_IN;
278  MSC_Handle->hbot.cbw.field.CBLength = CBW_LENGTH;
279 
280  USBH_memset(MSC_Handle->hbot.cbw.field.CB, 0, CBW_CB_LENGTH);
281  MSC_Handle->hbot.cbw.field.CB[0] = OPCODE_REQUEST_SENSE;
282  MSC_Handle->hbot.cbw.field.CB[1] = (lun << 5);
283  MSC_Handle->hbot.cbw.field.CB[2] = 0;
284  MSC_Handle->hbot.cbw.field.CB[3] = 0;
285  MSC_Handle->hbot.cbw.field.CB[4] = DATA_LEN_REQUEST_SENSE;
286  MSC_Handle->hbot.cbw.field.CB[5] = 0;
287 
288  MSC_Handle->hbot.state = BOT_SEND_CBW;
289  MSC_Handle->hbot.cmd_state = BOT_CMD_WAIT;
290  MSC_Handle->hbot.pbuf = (uint8_t *)MSC_Handle->hbot.data;
291  error = USBH_BUSY;
292  break;
293 
294  case BOT_CMD_WAIT:
295 
296  error = USBH_MSC_BOT_Process(phost, lun);
297 
298  if(error == USBH_OK)
299  {
300  sense_data->key = MSC_Handle->hbot.pbuf[2] & 0x0F;
301  sense_data->asc = MSC_Handle->hbot.pbuf[12];
302  sense_data->ascq = MSC_Handle->hbot.pbuf[13];
303  }
304  break;
305 
306  default:
307  break;
308  }
309 
310  return error;
311 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

Parameters
phostHost handle
lunLogical Unit Number
addresssector address
pbufpointer to data
lengthnumber of sector to write
Return values
USBHStatus
328 {
330 
331  MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData;
332 
333  switch(MSC_Handle->hbot.cmd_state)
334  {
335  case BOT_CMD_SEND:
336 
337  /*Prepare the CBW and relevent field*/
338  MSC_Handle->hbot.cbw.field.DataTransferLength = length * 512;
339  MSC_Handle->hbot.cbw.field.Flags = USB_EP_DIR_OUT;
340  MSC_Handle->hbot.cbw.field.CBLength = CBW_LENGTH;
341 
342  USBH_memset(MSC_Handle->hbot.cbw.field.CB, 0, CBW_CB_LENGTH);
343  MSC_Handle->hbot.cbw.field.CB[0] = OPCODE_WRITE10;
344 
345  /*logical block address*/
346  MSC_Handle->hbot.cbw.field.CB[2] = (((uint8_t*)&address)[3]);
347  MSC_Handle->hbot.cbw.field.CB[3] = (((uint8_t*)&address)[2]);
348  MSC_Handle->hbot.cbw.field.CB[4] = (((uint8_t*)&address)[1]);
349  MSC_Handle->hbot.cbw.field.CB[5] = (((uint8_t*)&address)[0]);
350 
351 
352  /*Transfer length */
353  MSC_Handle->hbot.cbw.field.CB[7] = (((uint8_t *)&length)[1]) ;
354  MSC_Handle->hbot.cbw.field.CB[8] = (((uint8_t *)&length)[0]) ;
355 
356 
357  MSC_Handle->hbot.state = BOT_SEND_CBW;
358  MSC_Handle->hbot.cmd_state = BOT_CMD_WAIT;
359  MSC_Handle->hbot.pbuf = pbuf;
360  error = USBH_BUSY;
361  break;
362 
363  case BOT_CMD_WAIT:
364  error = USBH_MSC_BOT_Process(phost, lun);
365  break;
366 
367  default:
368  break;
369  }
370 
371  return error;
372 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

Parameters
phostHost handle
lunLogical Unit Number
addresssector address
pbufpointer to data
lengthnumber of sector to read
Return values
USBHStatus
389 {
391  MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData;
392 
393  switch(MSC_Handle->hbot.cmd_state)
394  {
395  case BOT_CMD_SEND:
396 
397  /*Prepare the CBW and relevent field*/
398  MSC_Handle->hbot.cbw.field.DataTransferLength = length * 512;
399  MSC_Handle->hbot.cbw.field.Flags = USB_EP_DIR_IN;
400  MSC_Handle->hbot.cbw.field.CBLength = CBW_LENGTH;
401 
402  USBH_memset(MSC_Handle->hbot.cbw.field.CB, 0, CBW_CB_LENGTH);
403  MSC_Handle->hbot.cbw.field.CB[0] = OPCODE_READ10;
404 
405  /*logical block address*/
406  MSC_Handle->hbot.cbw.field.CB[2] = (((uint8_t*)&address)[3]);
407  MSC_Handle->hbot.cbw.field.CB[3] = (((uint8_t*)&address)[2]);
408  MSC_Handle->hbot.cbw.field.CB[4] = (((uint8_t*)&address)[1]);
409  MSC_Handle->hbot.cbw.field.CB[5] = (((uint8_t*)&address)[0]);
410 
411 
412  /*Transfer length */
413  MSC_Handle->hbot.cbw.field.CB[7] = (((uint8_t *)&length)[1]) ;
414  MSC_Handle->hbot.cbw.field.CB[8] = (((uint8_t *)&length)[0]) ;
415 
416 
417  MSC_Handle->hbot.state = BOT_SEND_CBW;
418  MSC_Handle->hbot.cmd_state = BOT_CMD_WAIT;
419  MSC_Handle->hbot.pbuf = pbuf;
420  error = USBH_BUSY;
421  break;
422 
423  case BOT_CMD_WAIT:
424  error = USBH_MSC_BOT_Process(phost, lun);
425  break;
426 
427  default:
428  break;
429  }
430 
431  return error;
432 }
Here is the call graph for this function:
Here is the caller graph for this function:
DATA_LEN_INQUIRY
#define DATA_LEN_INQUIRY
Definition: usbh_msc_scsi.h:97
BOT_CBWTypeDef::__CBW::CBLength
uint8_t CBLength
Definition: usbh_msc_bot.h:111
auto_build.error
bool error
Definition: auto_build.py:637
USBH_MSC_BOT_Process
USBH_StatusTypeDef USBH_MSC_BOT_Process(USBH_HandleTypeDef *phost, uint8_t lun)
USBH_MSC_BOT_Process The function handle the BOT protocol.
Definition: usbh_msc_bot.c:173
BOT_CBWTypeDef::__CBW::CB
uint8_t CB[16]
Definition: usbh_msc_bot.h:112
CBW_LENGTH
#define CBW_LENGTH
Definition: usbh_msc_scsi.h:101
CBW_CB_LENGTH
#define CBW_CB_LENGTH
Definition: usbh_msc_scsi.h:100
OPCODE_READ10
#define OPCODE_READ10
Definition: usbh_msc_scsi.h:90
BOT_HandleTypeDef::cbw
BOT_CBWTypeDef cbw
Definition: usbh_msc_bot.h:137
OPCODE_INQUIRY
#define OPCODE_INQUIRY
Definition: usbh_msc_scsi.h:93
SCSI_SenseTypeDef::key
uint8_t key
Definition: usbh_msc_scsi.h:69
SCSI_StdInquiryDataTypeDef::product_id
uint8_t product_id[17]
Definition: usbh_msc_scsi.h:81
USB_EP_DIR_IN
#define USB_EP_DIR_IN
Definition: usbh_def.h:176
BOT_CBWTypeDef::field
struct BOT_CBWTypeDef::__CBW field
BOT_HandleTypeDef::cmd_state
BOT_CMDStateTypeDef cmd_state
Definition: usbh_msc_bot.h:136
_MSC_Process::hbot
BOT_HandleTypeDef hbot
Definition: usbh_msc.h:129
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
SCSI_SenseTypeDef::asc
uint8_t asc
Definition: usbh_msc_scsi.h:70
OPCODE_READ_CAPACITY10
#define OPCODE_READ_CAPACITY10
Definition: usbh_msc_scsi.h:89
SCSI_SenseTypeDef::ascq
uint8_t ascq
Definition: usbh_msc_scsi.h:71
USBH_OK
Definition: usbh_def.h:304
BOT_CMD_SEND
Definition: usbh_msc_bot.h:72
SCSI_StdInquiryDataTypeDef::revision_id
uint8_t revision_id[5]
Definition: usbh_msc_scsi.h:82
BOT_CBWTypeDef::__CBW::Flags
uint8_t Flags
Definition: usbh_msc_bot.h:109
SCSI_CapacityTypeDef::block_nbr
uint32_t block_nbr
Definition: usbh_msc_scsi.h:61
SCSI_StdInquiryDataTypeDef::vendor_id
uint8_t vendor_id[9]
Definition: usbh_msc_scsi.h:80
SCSI_StdInquiryDataTypeDef::PeripheralQualifier
uint8_t PeripheralQualifier
Definition: usbh_msc_scsi.h:77
SCSI_StdInquiryDataTypeDef
Definition: usbh_msc_scsi.h:75
uint8_t
const uint8_t[]
Definition: 404_html.c:3
address
UsbDeviceAddress address
Definition: address.h:202
DATA_LEN_READ_CAPACITY10
#define DATA_LEN_READ_CAPACITY10
Definition: usbh_msc_scsi.h:96
USBH_StatusTypeDef
USBH_StatusTypeDef
Definition: usbh_def.h:302
BOT_HandleTypeDef::state
BOT_StateTypeDef state
Definition: usbh_msc_bot.h:134
BOT_HandleTypeDef::pbuf
uint8_t * pbuf
Definition: usbh_msc_bot.h:141
OPCODE_REQUEST_SENSE
#define OPCODE_REQUEST_SENSE
Definition: usbh_msc_scsi.h:92
USBH_FAIL
Definition: usbh_def.h:306
DATA_LEN_MODE_TEST_UNIT_READY
#define DATA_LEN_MODE_TEST_UNIT_READY
Definition: usbh_msc_scsi.h:95
USBH_BUSY
Definition: usbh_def.h:305
SCSI_StdInquiryDataTypeDef::RemovableMedia
uint8_t RemovableMedia
Definition: usbh_msc_scsi.h:79
SCSI_StdInquiryDataTypeDef::DeviceType
uint8_t DeviceType
Definition: usbh_msc_scsi.h:78
BOT_HandleTypeDef::data
uint32_t data[16]
Definition: usbh_msc_bot.h:133
length
png_uint_32 length
Definition: png.c:2247
OPCODE_TEST_UNIT_READY
#define OPCODE_TEST_UNIT_READY
Definition: usbh_msc_scsi.h:88
_USBH_HandleTypeDef::pActiveClass
USBH_ClassTypeDef * pActiveClass
Definition: usbh_def.h:458
BOT_CBWTypeDef::__CBW::DataTransferLength
uint32_t DataTransferLength
Definition: usbh_msc_bot.h:108
BOT_SEND_CBW
Definition: usbh_msc_bot.h:88
pbuf
Definition: pbuf.h:142
OPCODE_WRITE10
#define OPCODE_WRITE10
Definition: usbh_msc_scsi.h:91
BOT_CMD_WAIT
Definition: usbh_msc_bot.h:73
_MSC_Process
Definition: usbh_msc.h:116
DATA_LEN_REQUEST_SENSE
#define DATA_LEN_REQUEST_SENSE
Definition: usbh_msc_scsi.h:98
SCSI_CapacityTypeDef::block_size
uint16_t block_size
Definition: usbh_msc_scsi.h:62
USB_EP_DIR_OUT
#define USB_EP_DIR_OUT
Definition: usbh_def.h:175