Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

4 anos atrás
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. * MSC Teensy36 USB Host Mass Storage library
  3. * Copyright (c) 2017-2019 Warren Watson.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining
  6. * a copy of this software and associated documentation files (the
  7. * "Software"), to deal in the Software without restriction, including
  8. * without limitation the rights to use, copy, modify, merge, publish,
  9. * distribute, sublicense, and/or sell copies of the Software, and to
  10. * permit persons to whom the Software is furnished to do so, subject to
  11. * the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be
  14. * included in all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  20. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  21. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  22. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  23. * SOFTWARE.
  24. */
  25. // msc.h
  26. #ifndef _MSC_H_
  27. #define _MSC_H_
  28. // SCSI Commands (minimal set)
  29. #define CBW_SIGNATURE 0x43425355UL
  30. #define CSW_SIGNATURE 0x53425355UL
  31. #define CMD_DIR_DATA_OUT 0x00
  32. #define CMD_DIR_DATA_IN 0x80
  33. #define CMD_RD_CAPACITY_10 0x25
  34. #define CMD_INQUIRY 0x12
  35. #define CMD_RD_10 0x28
  36. #define CMD_WR_10 0x2A
  37. #define CMD_TEST_UNIT_READY 0x00
  38. #define CMD_REQUEST_SENSE 0x03
  39. #define CMD_START_STOP_UNIT 0x1B
  40. #define CMD_REPORT_LUNS 0xA0
  41. #define NO_RD_WR 0x00 // transfer type is not read or write blocks.
  42. // Command Status Wrapper Error Codes
  43. #define MS_CBW_PASS 0
  44. #define MS_CBW_FAIL 1
  45. #define MS_CBW_PHASE_ERROR 2
  46. #define MS_CSW_TAG_ERROR 253
  47. #define MS_CSW_SIG_ERROR 254
  48. #define MS_SCSI_ERROR 255
  49. // SCSI Sense Key codes
  50. #define MS_NOT_READY 0x02
  51. #define MS_MEDIUM_ERROR 0x03
  52. #define MS_ILLEGAL_REQUEST 0x05
  53. #define MS_UNIT_ATTENTION 0x06
  54. #define MS_LBA_OUT_OF_RANGE 0x21
  55. #define MS_MEDIA_CHANGED 0x28
  56. #define MS_MEDIUM_NOT_PRESENT 0x3A
  57. // SCSI Error Codes
  58. #define MS_MEDIA_CHANGED_ERR 0x2A
  59. #define MS_NO_MEDIA_ERR 0x28
  60. #define MS_UNIT_NOT_READY 0x23
  61. #define MS_BAD_LBA_ERR 0x29
  62. #define MS_CMD_ERR 0x26
  63. #define MS_INIT_PASS 0
  64. #define MAXLUNS 16
  65. // These two defines are timeouts for detecting a connected drive
  66. // and waiting for it to be operational.
  67. #define MEDIA_READY_TIMEOUT 1000
  68. #define MSC_CONNECT_TIMEOUT 4000
  69. // Command Block Wrapper Struct
  70. typedef struct
  71. {
  72. uint32_t Signature;
  73. uint32_t Tag;
  74. uint32_t TransferLength;
  75. uint8_t Flags;
  76. uint8_t LUN;
  77. uint8_t CommandLength;
  78. uint8_t CommandData[16];
  79. } __attribute__((packed)) msCommandBlockWrapper_t;
  80. // MSC Command Status Wrapper Struct
  81. typedef struct
  82. {
  83. uint32_t Signature;
  84. uint32_t Tag;
  85. uint32_t DataResidue;
  86. uint8_t Status;
  87. } __attribute__((packed)) msCommandStatusWrapper_t;
  88. // MSC Device Capacity Struct
  89. typedef struct
  90. {
  91. uint32_t Blocks;
  92. uint32_t BlockSize;
  93. } msSCSICapacity_t;
  94. // MSC Inquiry Command Reponse Struct
  95. typedef struct
  96. {
  97. unsigned DeviceType : 5;
  98. unsigned PeripheralQualifier : 3;
  99. unsigned Reserved : 7;
  100. unsigned Removable : 1;
  101. uint8_t Version;
  102. unsigned ResponseDataFormat : 4;
  103. unsigned Reserved2 : 1;
  104. unsigned NormACA : 1;
  105. unsigned TrmTsk : 1;
  106. unsigned AERC : 1;
  107. uint8_t AdditionalLength;
  108. uint8_t Reserved3[2];
  109. unsigned SoftReset : 1;
  110. unsigned CmdQue : 1;
  111. unsigned Reserved4 : 1;
  112. unsigned Linked : 1;
  113. unsigned Sync : 1;
  114. unsigned WideBus16Bit : 1;
  115. unsigned WideBus32Bit : 1;
  116. unsigned RelAddr : 1;
  117. uint8_t VendorID[8];
  118. uint8_t ProductID[16];
  119. uint8_t RevisionID[4];
  120. } __attribute__((packed)) msInquiryResponse_t;
  121. // Request Sense Response Struct
  122. typedef struct
  123. {
  124. uint8_t ResponseCode;
  125. uint8_t SegmentNumber;
  126. unsigned SenseKey : 4;
  127. unsigned Reserved : 1;
  128. unsigned ILI : 1;
  129. unsigned EOM : 1;
  130. unsigned FileMark : 1;
  131. uint8_t Information[4];
  132. uint8_t AdditionalLength;
  133. uint8_t CmdSpecificInformation[4];
  134. uint8_t AdditionalSenseCode;
  135. uint8_t AdditionalSenseQualifier;
  136. uint8_t FieldReplaceableUnitCode;
  137. uint8_t SenseKeySpecific[3];
  138. uint8_t padding[234];
  139. } __attribute__((packed)) msRequestSenseResponse_t;
  140. // MSC Drive status/info struct
  141. typedef struct {
  142. bool connected = false; // Device is connected
  143. bool initialized = false; // Device is initialized
  144. bool mounted = false; // Device is mounted
  145. const char * drvName = 0;
  146. uint32_t bufferSize = 0;
  147. uint8_t hubNumber;
  148. uint8_t hubPort;
  149. uint8_t deviceAddress;
  150. uint16_t idVendor;
  151. uint16_t idProduct;
  152. msSCSICapacity_t capacity;
  153. msInquiryResponse_t inquiry;
  154. } __attribute__((packed)) msDriveInfo_t;
  155. #endif //_MSC_H_