APM:Libraries
usbd_msc_scsi.c
Go to the documentation of this file.
1 
33 /* Includes ------------------------------------------------------------------*/
34 #include "usbd_msc_bot.h"
35 #include "usbd_msc_scsi.h"
36 #include "usbd_msc_mem.h"
37 #include "usbd_msc_data.h"
38 #include <stdbool.h>
39 #include <stdio.h>
40 #include <string.h>
41 
42 
85 
86 uint32_t SCSI_blk_size;
87 uint32_t SCSI_blk_nbr;
88 
89 uint32_t SCSI_blk_addr;
90 uint32_t SCSI_blk_len;
91 
99 //[ move out data transfer from ISR level to task
100 typedef void (*voidFuncPtr)(void);
101 
102 
103 typedef struct USB_REC {
104  void *pdev;
105  uint8_t lun;
106  bool is_write;
107 } USB_rec;
108 
109 // this is not true queue because there is only one request at a time, but this allows to exclude disabling of interrupts
110 #define USB_QUEUE_SIZE 4
112 static uint8_t usb_read_ptr, usb_write_ptr;
113 
114 // HAL task management for USB
115 extern void hal_set_task_active(void * handle);
116 extern void hal_context_switch_isr();
117 extern void *hal_register_task(voidFuncPtr task, uint32_t stack);
118 extern void hal_set_task_priority(void * handle, uint8_t prio);
119 
120 static void usb_task();
121 static void *task_handle;
122 
123 void SCSI_Init() {
124  usb_read_ptr=0;
125  usb_write_ptr=0;
126 
127  task_handle = hal_register_task(usb_task, 2048); // 2K stack
128  hal_set_task_priority(task_handle, 80); // very high
129 }
130 //]
131 
132 //#define SCSI_DEBUG
133 
134 //[ debug
135 #ifdef SCSI_DEBUG
136 #define SCSI_LOG_LEN 500
137 typedef struct SCSI_LOG {
138  enum SCSI_Commands cmd;
139  enum BOT_STATE state;
140  bool alt;
141  uint32_t addr;
142  uint32_t len;
143  uint8_t params[8];
144  int8_t ret;
145  uint8_t rdp;
146  uint8_t wrp;
147 } SCSI_log;
148 
149 static uint16_t scsi_log_ptr=0;
150 
151 static SCSI_log *curr_log;
152 
153 static SCSI_log scsi_log[SCSI_LOG_LEN+1];
154 #endif
155 //]
156 
157 
158 
159 
163 static int8_t SCSI_TestUnitReady(uint8_t lun, uint8_t *params);
164 static int8_t SCSI_Inquiry(uint8_t lun, uint8_t *params);
165 static int8_t SCSI_ReadFormatCapacity(uint8_t lun, uint8_t *params);
166 static int8_t SCSI_ReadCapacity10(uint8_t lun, uint8_t *params);
167 static int8_t SCSI_RequestSense (uint8_t lun, uint8_t *params);
168 static int8_t SCSI_StartStopUnit(uint8_t lun, uint8_t *params);
169 static int8_t SCSI_ModeSense6 (uint8_t lun, uint8_t *params);
170 static int8_t SCSI_ModeSense10 (uint8_t lun, uint8_t *params);
171 static int8_t SCSI_Write10(uint8_t lun , uint8_t *params);
172 static int8_t SCSI_Read10(uint8_t lun , uint8_t *params);
173 static int8_t SCSI_Verify10(uint8_t lun, uint8_t *params);
174 static int8_t SCSI_CheckAddressRange (uint8_t lun ,
175  uint32_t blk_offset ,
176  uint16_t blk_nbr);
177 static int8_t SCSI_ProcessRead (uint8_t lun);
178 
179 static int8_t SCSI_ProcessWrite (uint8_t lun);
199  uint8_t lun,
200  uint8_t *params)
201 {
202  cdev = pdev;
203 
204  int8_t ret=-1;
205 
206 // if(!task_handle) SCSI_Init(); can't be registered from ISR!
207 
208 #ifdef SCSI_DEBUG
209  printf("\nSCSI cmd=%d ", params[0]);
210 
211  SCSI_log *p = &scsi_log[scsi_log_ptr++];
212  if(scsi_log_ptr>=SCSI_LOG_LEN) scsi_log_ptr=0;
213  p->cmd = params[0];
214  p->state = MSC_BOT_State;
215  memmove(p->params,params+1,8);
216  p->ret=55;
217  p->alt = false;
218  p->addr=0;
219  p->len=0;
220  curr_log=p;
221 #endif
222  switch (params[0]) {
224  ret=SCSI_TestUnitReady(lun, params);
225  break;
226 
227  case SCSI_REQUEST_SENSE:
228  ret=SCSI_RequestSense (lun, params);
229  break;
230 
231  case SCSI_INQUIRY:
232  ret= SCSI_Inquiry(lun, params);
233  break;
234 
236  ret= SCSI_StartStopUnit(lun, params);
237  break;
238 
240  ret= SCSI_StartStopUnit(lun, params);
241  break;
242 
243  case SCSI_MODE_SENSE6:
244  ret= SCSI_ModeSense6 (lun, params);
245  break;
246 
247  case SCSI_MODE_SENSE10:
248  ret= SCSI_ModeSense10 (lun, params);
249  break;
250 
252  ret= SCSI_ReadFormatCapacity(lun, params);
253  break;
254 
256  ret= SCSI_ReadCapacity10(lun, params);
257  break;
258 
259  case SCSI_READ10:
260  ret= SCSI_Read10(lun, params);
261  return ret; // without MSC_BOT_CBW_finish(p->pdev);
262 
263  case SCSI_WRITE10:
264  ret= SCSI_Write10(lun, params);
265  return ret; // without MSC_BOT_CBW_finish(p->pdev);
266 
267  case SCSI_VERIFY10:
268  ret=SCSI_Verify10(lun, params);
269  break;
270 
271  default:
272  SCSI_SenseCode(lun,
274  INVALID_CDB);
275  ret= -1;
276  break;
277  }
278 
279  MSC_BOT_CBW_finish(pdev);
280 
281  return ret;
282 }
283 
284 
292 static int8_t SCSI_TestUnitReady(uint8_t lun, uint8_t *params)
293 {
294 
295  /* case 9 : Hi > D0 */
296  if (MSC_BOT_cbw.dDataLength != 0) {
299  INVALID_CDB);
300  return -1;
301  }
302 
303  if(USBD_STORAGE_fops->IsReady(lun) !=0 ) {
304  SCSI_SenseCode(lun,
305  NOT_READY,
307  return -1;
308  }
309 
310  MSC_BOT_DataLen = 0;
311  return 0;
312 }
313 
321 static int8_t SCSI_Inquiry(uint8_t lun, uint8_t *params)
322 {
323  uint8_t* pPage;
324  uint16_t len;
325 
326  if (params[1] & 0x01)/*Evpd is set*/
327  {
328  pPage = (uint8_t *)MSC_Page00_Inquiry_Data;
329  len = LENGTH_INQUIRY_PAGE00;
330  }
331  else
332  {
333 
334  pPage = (uint8_t *)&USBD_STORAGE_fops->pInquiry[lun * USBD_STD_INQUIRY_LENGTH];
335  len = pPage[4] + 5;
336 
337  if (params[4] <= len)
338  {
339  len = params[4];
340  }
341  }
342  MSC_BOT_DataLen = len;
343 
344  while (len)
345  {
346  len--;
347  MSC_BOT_Data[len] = pPage[len];
348  }
349  return 0;
350 }
351 
359 static int8_t SCSI_ReadCapacity10(uint8_t lun, uint8_t *params)
360 {
361 
363  {
364  SCSI_SenseCode(lun,
365  NOT_READY,
367  return -1;
368  }
369  else
370  {
371 
372  MSC_BOT_Data[0] = (uint8_t)((SCSI_blk_nbr - 1) >> 24);
373  MSC_BOT_Data[1] = (uint8_t)((SCSI_blk_nbr - 1) >> 16);
374  MSC_BOT_Data[2] = (uint8_t)((SCSI_blk_nbr - 1) >> 8);
375  MSC_BOT_Data[3] = (uint8_t)((SCSI_blk_nbr - 1));
376 
377  MSC_BOT_Data[4] = (uint8_t)(SCSI_blk_size >> 24);
378  MSC_BOT_Data[5] = (uint8_t)(SCSI_blk_size >> 16);
379  MSC_BOT_Data[6] = (uint8_t)(SCSI_blk_size >> 8);
380  MSC_BOT_Data[7] = (uint8_t)(SCSI_blk_size);
381 
382  MSC_BOT_DataLen = 8;
383  return 0;
384  }
385 }
393 static int8_t SCSI_ReadFormatCapacity(uint8_t lun, uint8_t *params)
394 {
395 
396  uint32_t blk_size;
397  uint32_t blk_nbr;
398  uint16_t i;
399 
400  for(i=0 ; i < 12 ; i++)
401  {
402  MSC_BOT_Data[i] = 0;
403  }
404 
405  if(USBD_STORAGE_fops->GetCapacity(lun, &blk_nbr, &blk_size) != 0)
406  {
407  SCSI_SenseCode(lun,
408  NOT_READY,
410  return -1;
411  }
412  else
413  {
414  MSC_BOT_Data[3] = 0x08;
415  MSC_BOT_Data[4] = (uint8_t)((blk_nbr - 1) >> 24);
416  MSC_BOT_Data[5] = (uint8_t)((blk_nbr - 1) >> 16);
417  MSC_BOT_Data[6] = (uint8_t)((blk_nbr - 1) >> 8);
418  MSC_BOT_Data[7] = (uint8_t)((blk_nbr - 1));
419 
420  MSC_BOT_Data[8] = 0x02;
421  MSC_BOT_Data[9] = (uint8_t)(blk_size >> 16);
422  MSC_BOT_Data[10] = (uint8_t)(blk_size >> 8);
423  MSC_BOT_Data[11] = (uint8_t)(blk_size);
424 
425  MSC_BOT_DataLen = 12;
426  return 0;
427  }
428 }
436 static int8_t SCSI_ModeSense6 (uint8_t lun, uint8_t *params)
437 {
438 
439  uint16_t len = 8 ;
440  MSC_BOT_DataLen = len;
441 
442  while (len)
443  {
444  len--;
446  }
447  return 0;
448 }
449 
457 static int8_t SCSI_ModeSense10 (uint8_t lun, uint8_t *params)
458 {
459  uint16_t len = 8;
460 
461  MSC_BOT_DataLen = len;
462 
463  while (len)
464  {
465  len--;
467  }
468  return 0;
469 }
470 
479 static int8_t SCSI_RequestSense (uint8_t lun, uint8_t *params)
480 {
481  uint8_t i;
482 
483  for(i=0 ; i < REQUEST_SENSE_DATA_LEN ; i++) {
484  MSC_BOT_Data[i] = 0;
485  }
486 
487  MSC_BOT_Data[0] = 0x70;
488  MSC_BOT_Data[7] = REQUEST_SENSE_DATA_LEN - 6;
489 
491 
492  MSC_BOT_Data[2] = SCSI_Sense[SCSI_Sense_Head].Skey;
493  MSC_BOT_Data[12] = SCSI_Sense[SCSI_Sense_Head].w.b.ASCQ;
494  MSC_BOT_Data[13] = SCSI_Sense[SCSI_Sense_Head].w.b.ASC;
495  SCSI_Sense_Head++;
496 
498  SCSI_Sense_Head = 0;
499  }
500  }
502 
503  if (params[4] <= REQUEST_SENSE_DATA_LEN) {
504  MSC_BOT_DataLen = params[4];
505  }
506  return 0;
507 }
508 
518 void SCSI_SenseCode(uint8_t lun, uint8_t sKey, uint8_t ASC)
519 {
520  SCSI_Sense[SCSI_Sense_Tail].Skey = sKey;
521  SCSI_Sense[SCSI_Sense_Tail].w.ASC = ASC << 8;
522  SCSI_Sense_Tail++;
524  {
525  SCSI_Sense_Tail = 0;
526  }
527 }
535 static int8_t SCSI_StartStopUnit(uint8_t lun, uint8_t *params)
536 {
537  MSC_BOT_DataLen = 0;
538  return 0;
539 }
540 
548 static int8_t SCSI_Read10(uint8_t lun , uint8_t *params)
549 {
550  if(MSC_BOT_State == BOT_IDLE) { /* Idle */
551 
552  /* case 10 : Ho <> Di */
553  if ((MSC_BOT_cbw.bmFlags & 0x80) != 0x80) {
556  INVALID_CDB);
557  return -1;
558  }
559 
560  if(USBD_STORAGE_fops->IsReady(lun) !=0 ) {
561  SCSI_SenseCode(lun,
562  NOT_READY,
564  return -1;
565  }
566 
567  SCSI_blk_addr = (params[2] << 24) | \
568  (params[3] << 16) | \
569  (params[4] << 8) | \
570  params[5];
571 
572  SCSI_blk_len = (params[7] << 8) | \
573  params[8];
574 
575 
576 
578  return -1; /* error */
579  }
580 
584 
585  /* cases 4,5 : Hi <> Dn */
589  INVALID_CDB);
590  return -1;
591  }
592  }
593 
594 #ifdef SCSI_DEBUG
595  curr_log->addr = SCSI_blk_addr;
596  curr_log->len = SCSI_blk_len;
597  curr_log->rdp = usb_read_ptr;
598  curr_log->wrp = usb_write_ptr;
599 #endif
600 
601 #if 1
602  USB_rec *p = &usb_queue[usb_write_ptr];
603 
604  uint16_t old_wp = usb_write_ptr++;
605  if(usb_write_ptr >= USB_QUEUE_SIZE) { // move write pointer
606  usb_write_ptr=0; // ring
607  }
608  if(usb_write_ptr == usb_read_ptr) { // buffer overflow
609  usb_write_ptr=old_wp; // not overwrite, just skip last data
610  } else {
611  p->pdev = cdev;
612  p->lun = lun;
613  p->is_write = false;
614  }
615 
616 // printf("\nUSB: enqueue read blk=%ld\n", SCSI_blk_addr / SCSI_blk_size);
617 
618  uint32_t fifoemptymsk = 0x1 << (MSC_IN_EP & 0x7F);
619  USB_OTG_MODIFY_REG32(&cdev->regs.DREGS->DIEPEMPMSK, fifoemptymsk, 0); // clear FIFO Empty mask until real data write to prevent interrupt
620 
621  hal_set_task_active(task_handle); // resume task
622  hal_context_switch_isr(); // and reschedule tasks after interrupt
623  return 0;
624 #else // as it was before
625 
627  return SCSI_ProcessRead(lun);
628 #endif
629 }
630 
631 
640 static int8_t SCSI_Write10 (uint8_t lun , uint8_t *params)
641 {
642  if (MSC_BOT_State == BOT_IDLE) { /* Idle */
643 
644  /* case 8 : Hi <> Do */
645  if ((MSC_BOT_cbw.bmFlags & 0x80) == 0x80){
648  INVALID_CDB);
649  return -1;
650  }
651 
652  /* Check whether Media is ready */
653  if(USBD_STORAGE_fops->IsReady(lun) !=0 ){
654  SCSI_SenseCode(lun,
655  NOT_READY,
657  return -1;
658  }
659 
660  /* Check If media is write-protected */
661  if(USBD_STORAGE_fops->IsWriteProtected(lun) !=0 ) {
662  SCSI_SenseCode(lun,
663  NOT_READY,
665  return -1;
666  }
667 
668 
669  SCSI_blk_addr = (params[2] << 24) | \
670  (params[3] << 16) | \
671  (params[4] << 8) | \
672  params[5];
673 
674  SCSI_blk_len = (params[7] << 8) | \
675  params[8];
676 
677  /* check if LBA address is in the right range */
679  return -1; /* error */
680  }
681 
684 
685  /* cases 3,11,13 : Hn,Ho <> D0 */
689  INVALID_CDB);
690  return -1;
691  }
692 
693  /* Prepare EP to receive first data packet */
695  DCD_EP_PrepareRx (cdev,
696  MSC_OUT_EP,
697  MSC_BOT_Data,
699 
700 #ifdef SCSI_DEBUG
701  curr_log->addr = SCSI_blk_addr;
702  curr_log->len = SCSI_blk_len;
703  curr_log->rdp = usb_read_ptr;
704  curr_log->wrp = usb_write_ptr;
705 #endif
706 
707  return 0;
708  }
709  /* Write Process ongoing */
710 
711 
712 #ifdef SCSI_DEBUG
713  curr_log->addr = SCSI_blk_addr;
714  curr_log->len = SCSI_blk_len;
715  curr_log->rdp = usb_read_ptr;
716  curr_log->wrp = usb_write_ptr;
717  curr_log->alt = true;
718 
719 #endif
720 
721 
722 #if 1
723  USB_rec *p = &usb_queue[usb_write_ptr];
724 
725  uint16_t old_wp = usb_write_ptr++;
726  if(usb_write_ptr >= USB_QUEUE_SIZE) { // move write pointer
727  usb_write_ptr=0; // ring
728  }
729  if(usb_write_ptr == usb_read_ptr) { // buffer overflow
730  usb_write_ptr=old_wp; // not overwrite, just skip last data
731  } else {
732  p->pdev = cdev;
733  p->lun = lun;
734  p->is_write = true;
735  }
736 
737 // printf("\nUSB: enqueue write blk=%ld\n", SCSI_blk_addr / SCSI_blk_size);
738 
739  hal_set_task_active(task_handle); // resume task
740  hal_context_switch_isr(); // and reschedule tasks after interrupt
741  return 0;
742 #else // as it was before
743 
744  return SCSI_ProcessWrite(lun);
745 #endif
746 }
747 
748 //[ real data read/write executed as task
749 static void usb_task(){
750 
751  while(usb_read_ptr != usb_write_ptr) { // there are samples
752  USB_rec *p = &usb_queue[usb_read_ptr++];
753 
754  if(usb_read_ptr >= USB_QUEUE_SIZE) { // move write pointer
755  usb_read_ptr=0; // ring
756  }
757 
758 #ifdef SCSI_DEBUG
759  SCSI_log *l = &scsi_log[scsi_log_ptr++];
760  if(scsi_log_ptr>=SCSI_LOG_LEN) scsi_log_ptr=0;
761  l->cmd = 100 + p->is_write;
762  l->state = MSC_BOT_State;
763  l->ret=0;
764  l->alt = true;
765  l->addr=SCSI_blk_addr;
766  l->len=SCSI_blk_len;
767  l->rdp = usb_read_ptr;
768  l->wrp = usb_write_ptr;
769  curr_log=l;
770 #endif
771 
772  int8_t ret;
773  if(p->is_write){
774 // printf("\nUSB: do write blk=%ld\n", SCSI_blk_addr / SCSI_blk_size);
775 
776  ret = SCSI_ProcessWrite(p->lun);
777  } else {
778 // printf("\nUSB: do read blk=%ld\n", SCSI_blk_addr / SCSI_blk_size);
780  ret = SCSI_ProcessRead(p->lun);
781 
782  uint32_t fifoemptymsk = 0x1 << (MSC_IN_EP & 0x7F);
783  USB_OTG_MODIFY_REG32(&cdev->regs.DREGS->DIEPEMPMSK, 0, fifoemptymsk); // Set FIFO Empty mask after real data write to allow next interrupt
784 
785  }
787 
788  if(ret<0) {
789 #ifdef SCSI_DEBUG
790  l->ret = ret;
791 #endif
793  } else {
794 #ifdef SCSI_DEBUG
795  l->ret = 1;
796 #endif
797  }
798  }
799 }
800 //]
801 
802 
811 static int8_t SCSI_Verify10(uint8_t lun , uint8_t *params){
812  if ((params[1]& 0x02) == 0x02) {
814  return -1; /* Error, Verify Mode Not supported*/
815  }
816 
818  return -1; /* error */
819  }
820  MSC_BOT_DataLen = 0;
821  return 0;
822 }
823 
832 static int8_t SCSI_CheckAddressRange (uint8_t lun , uint32_t blk_offset , uint16_t blk_nbr)
833 {
834 
835  if ((blk_offset + blk_nbr) > SCSI_blk_nbr ) {
837  return -1;
838  }
839  return 0;
840 }
841 
848 static int8_t SCSI_ProcessRead (uint8_t lun)
849 {
850  uint32_t len;
851 
853 
854  // read block from storage
855  if( USBD_STORAGE_fops->Read(lun ,
856  MSC_BOT_Data,
858  len / SCSI_blk_size) < 0) {
859 
861  return -1;
862  }
863 
864  // and setup TX
865  DCD_EP_Tx (cdev,
866  MSC_IN_EP,
867  MSC_BOT_Data,
868  len);
869 
870 
871  SCSI_blk_addr += len;
872  SCSI_blk_len -= len;
873 
874  /* case 6 : Hi = Di */
875  MSC_BOT_csw.dDataResidue -= len;
876 
877  if (SCSI_blk_len == 0) {
879  }
880  return 0;
881 }
882 
890 static int8_t SCSI_ProcessWrite (uint8_t lun)
891 {
892  uint32_t len;
893 
895 
896  if(USBD_STORAGE_fops->Write(lun ,
897  MSC_BOT_Data,
899  len / SCSI_blk_size) < 0) {
901  return -1;
902  }
903 
904 
905  SCSI_blk_addr += len;
906  SCSI_blk_len -= len;
907 
908  /* case 12 : Ho = Do */
909  MSC_BOT_csw.dDataResidue -= len;
910 
911  if (SCSI_blk_len == 0) {
913  } else {
914  /* Prapare EP to Receive next packet */
915  DCD_EP_PrepareRx (cdev,
916  MSC_OUT_EP,
917  MSC_BOT_Data,
919  }
920 
921  return 0;
922 }
937 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
static int8_t SCSI_ProcessRead(uint8_t lun)
SCSI_ProcessRead Handle Read Process.
uint32_t dDataResidue
Definition: usbd_msc_bot.h:102
bool is_write
int printf(const char *fmt,...)
Definition: stdio.c:113
#define MSC_IN_EP
Definition: usbd_conf.h:84
void SCSI_Init()
#define USB_QUEUE_SIZE
static uint8_t usb_read_ptr
SCSI_Sense_TypeDef SCSI_Sense[SENSE_LIST_DEEPTH]
Definition: usbd_msc_scsi.c:82
uint8_t SCSI_Sense_Tail
Definition: usbd_msc_scsi.c:84
uint8_t MSC_BOT_Data[]
int8_t(* GetCapacity)(uint8_t lun, uint32_t *block_num, uint32_t *block_size)
Definition: usbd_msc_mem.h:61
uint32_t SCSI_blk_nbr
Definition: usbd_msc_scsi.c:87
static int8_t SCSI_StartStopUnit(uint8_t lun, uint8_t *params)
SCSI_StartStopUnit Process Start Stop Unit command.
void hal_set_task_priority(void *handle, uint8_t prio)
Definition: Scheduler.cpp:1440
uint8_t bmFlags
Definition: usbd_msc_bot.h:90
void * hal_register_task(voidFuncPtr task, uint32_t stack)
Definition: Scheduler.cpp:1441
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:261
uint16_t MSC_BOT_DataLen
Definition: usbd_msc_bot.c:72
header for the STORAGE DISK file file
static int8_t SCSI_Inquiry(uint8_t lun, uint8_t *params)
SCSI_Inquiry Process Inquiry command.
static void usb_task()
struct _SENSE_ITEM::@44::_ASCs b
int8_t(* IsReady)(uint8_t lun)
Definition: usbd_msc_mem.h:62
#define LENGTH_INQUIRY_PAGE00
Definition: usbd_msc_data.h:50
void MSC_BOT_CBW_finish(USB_OTG_CORE_HANDLE *pdev)
Definition: usbd_msc_bot.c:277
uint32_t SCSI_blk_addr
Definition: usbd_msc_scsi.c:89
static int8_t SCSI_ProcessWrite(uint8_t lun)
SCSI_ProcessWrite Handle Write Process.
#define MIN(a, b)
Definition: usb_conf.h:215
struct USB_REC USB_rec
void(* voidFuncPtr)(void)
__IO uint32_t DIEPEMPMSK
Definition: usb_regs.h:128
const uint8_t MSC_Page00_Inquiry_Data[]
Definition: usbd_msc_data.c:72
uint32_t dDataLength
Definition: usbd_msc_bot.h:89
#define USBD_STD_INQUIRY_LENGTH
Definition: usbd_msc_mem.h:48
int8_t SCSI_ProcessCmd(USB_OTG_CORE_HANDLE *pdev, uint8_t lun, uint8_t *params)
SCSI_ProcessCmd Process SCSI commands.
SCSI_Commands
Definition: usbd_msc_scsi.h:51
static void * task_handle
header for the usbd_msc_data.c file
const USBD_STORAGE_cb_TypeDef *const USBD_STORAGE_fops
int8_t * pInquiry
Definition: usbd_msc_mem.h:67
void hal_set_task_active(void *handle)
Definition: Scheduler.cpp:1438
static int8_t SCSI_TestUnitReady(uint8_t lun, uint8_t *params)
SCSI_TestUnitReady Process SCSI Test Unit Ready Command.
#define MSC_MEDIA_PACKET
Definition: usbd_conf.h:97
static int state
Definition: Util.cpp:20
header for the usbd_msc_scsi.c file
uint8_t MSC_BOT_State
Definition: usbd_msc_bot.c:73
int8_t(* Write)(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len)
Definition: usbd_msc_mem.h:65
void hal_context_switch_isr()
Definition: Scheduler.cpp:1439
static uint8_t usb_write_ptr
static int8_t SCSI_RequestSense(uint8_t lun, uint8_t *params)
SCSI_RequestSense Process Request Sense command.
void * pdev
#define SENSE_LIST_DEEPTH
Definition: usbd_msc_scsi.h:48
#define MSC_OUT_EP
Definition: usbd_conf.h:85
static int8_t SCSI_Write10(uint8_t lun, uint8_t *params)
SCSI_Write10 Process Write10 command.
static int8_t SCSI_Read10(uint8_t lun, uint8_t *params)
SCSI_Read10 Process Read10 command.
BOT_STATE
Definition: usbd_msc_bot.h:49
const uint8_t MSC_Mode_Sense10_data[]
Definition: usbd_msc_data.c:93
MSC_BOT_CBW_TypeDef MSC_BOT_cbw
static USB_rec usb_queue[USB_QUEUE_SIZE+1]
#define CSW_CMD_PASSED
Definition: usbd_msc_bot.h:63
static int8_t SCSI_ReadFormatCapacity(uint8_t lun, uint8_t *params)
SCSI_ReadFormatCapacity Process Read Format Capacity command.
int8_t(* IsWriteProtected)(uint8_t lun)
Definition: usbd_msc_mem.h:63
USB_OTG_CORE_HANDLE * cdev
Definition: usbd_msc_scsi.c:92
void SCSI_SenseCode(uint8_t lun, uint8_t sKey, uint8_t ASC)
SCSI_SenseCode Load the last error code in the error list.
static int8_t SCSI_CheckAddressRange(uint8_t lun, uint32_t blk_offset, uint16_t blk_nbr)
SCSI_CheckAddressRange Check address range.
MSC_BOT_CSW_TypeDef MSC_BOT_csw
union _SENSE_ITEM::@44 w
uint32_t SCSI_blk_size
Definition: usbd_msc_scsi.c:86
uint8_t lun
uint32_t SCSI_blk_len
Definition: usbd_msc_scsi.c:90
uint8_t bLUN
Definition: usbd_msc_bot.h:91
static int8_t SCSI_ModeSense6(uint8_t lun, uint8_t *params)
SCSI_ModeSense6 Process Mode Sense6 command.
uint8_t SCSI_Sense_Head
Definition: usbd_msc_scsi.c:83
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:324
#define CSW_CMD_FAILED
Definition: usbd_msc_bot.h:64
header for the usbd_msc_bot.c file
int8_t(* Read)(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len)
Definition: usbd_msc_mem.h:64
USB_OTG_CORE_REGS regs
Definition: usb_core.h:299
static int8_t SCSI_ReadCapacity10(uint8_t lun, uint8_t *params)
SCSI_ReadCapacity10 Process Read Capacity 10 command.
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:221
static int8_t SCSI_Verify10(uint8_t lun, uint8_t *params)
SCSI_Verify10 Process Verify10 command.
#define USB_OTG_MODIFY_REG32(reg, clear_mask, set_mask)
Definition: usb_defines.h:223
static int8_t SCSI_ModeSense10(uint8_t lun, uint8_t *params)
SCSI_ModeSense10 Process Mode Sense10 command.
USB_OTG_DREGS * DREGS
Definition: usb_regs.h:225
const uint8_t MSC_Mode_Sense6_data[]
Definition: usbd_msc_data.c:82