SCSI.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. LUFA Library
  3. Copyright (C) Dean Camera, 2017.
  4. dean [at] fourwalledcubicle [dot] com
  5. www.lufa-lib.org
  6. */
  7. /*
  8. Copyright 2017 Dean Camera (dean [at] fourwalledcubicle [dot] com)
  9. Permission to use, copy, modify, distribute, and sell this
  10. software and its documentation for any purpose is hereby granted
  11. without fee, provided that the above copyright notice appear in
  12. all copies and that both that the copyright notice and this
  13. permission notice and warranty disclaimer appear in supporting
  14. documentation, and that the name of the author not be used in
  15. advertising or publicity pertaining to distribution of the
  16. software without specific, written prior permission.
  17. The author disclaims all warranties with regard to this
  18. software, including all implied warranties of merchantability
  19. and fitness. In no event shall the author be liable for any
  20. special, indirect or consequential damages or any damages
  21. whatsoever resulting from loss of use, data or profits, whether
  22. in an action of contract, negligence or other tortious action,
  23. arising out of or in connection with the use or performance of
  24. this software.
  25. */
  26. /** \file
  27. *
  28. * Header file for SCSI.c.
  29. */
  30. #ifndef _SCSI_H_
  31. #define _SCSI_H_
  32. /* Includes: */
  33. #include <avr/io.h>
  34. #include <avr/pgmspace.h>
  35. #include <LUFA/Common/Common.h>
  36. #include <LUFA/Drivers/USB/USB.h>
  37. #include <LUFA/Drivers/Board/LEDs.h>
  38. #include "../MassStorage.h"
  39. #include "../Descriptors.h"
  40. #include "DataflashManager.h"
  41. /* Macros: */
  42. /** Macro to set the current SCSI sense data to the given key, additional sense code and additional sense qualifier. This
  43. * is for convenience, as it allows for all three sense values (returned upon request to the host to give information about
  44. * the last command failure) in a quick and easy manner.
  45. *
  46. * \param[in] Key New SCSI sense key to set the sense code to
  47. * \param[in] Acode New SCSI additional sense key to set the additional sense code to
  48. * \param[in] Aqual New SCSI additional sense key qualifier to set the additional sense qualifier code to
  49. */
  50. #define SCSI_SET_SENSE(Key, Acode, Aqual) do { SenseData.SenseKey = (Key); \
  51. SenseData.AdditionalSenseCode = (Acode); \
  52. SenseData.AdditionalSenseQualifier = (Aqual); } while (0)
  53. /** Macro for the \ref SCSI_Command_ReadWrite_10() function, to indicate that data is to be read from the storage medium. */
  54. #define DATA_READ true
  55. /** Macro for the \ref SCSI_Command_ReadWrite_10() function, to indicate that data is to be written to the storage medium. */
  56. #define DATA_WRITE false
  57. /** Value for the DeviceType entry in the SCSI_Inquiry_Response_t enum, indicating a Block Media device. */
  58. #define DEVICE_TYPE_BLOCK 0x00
  59. /** Value for the DeviceType entry in the SCSI_Inquiry_Response_t enum, indicating a CD-ROM device. */
  60. #define DEVICE_TYPE_CDROM 0x05
  61. /* Type Defines: */
  62. /** Type define for a SCSI response structure to a SCSI INQUIRY command. For details of the
  63. * structure contents, refer to the SCSI specifications.
  64. */
  65. typedef struct
  66. {
  67. unsigned DeviceType : 5;
  68. unsigned PeripheralQualifier : 3;
  69. unsigned Reserved : 7;
  70. unsigned Removable : 1;
  71. uint8_t Version;
  72. unsigned ResponseDataFormat : 4;
  73. unsigned Reserved2 : 1;
  74. unsigned NormACA : 1;
  75. unsigned TrmTsk : 1;
  76. unsigned AERC : 1;
  77. uint8_t AdditionalLength;
  78. uint8_t Reserved3[2];
  79. unsigned SoftReset : 1;
  80. unsigned CmdQue : 1;
  81. unsigned Reserved4 : 1;
  82. unsigned Linked : 1;
  83. unsigned Sync : 1;
  84. unsigned WideBus16Bit : 1;
  85. unsigned WideBus32Bit : 1;
  86. unsigned RelAddr : 1;
  87. uint8_t VendorID[8];
  88. uint8_t ProductID[16];
  89. uint8_t RevisionID[4];
  90. } MS_SCSI_Inquiry_Response_t;
  91. /** Type define for a SCSI sense structure to a SCSI REQUEST SENSE command. For details of the
  92. * structure contents, refer to the SCSI specifications.
  93. */
  94. typedef struct
  95. {
  96. uint8_t ResponseCode;
  97. uint8_t SegmentNumber;
  98. unsigned SenseKey : 4;
  99. unsigned Reserved : 1;
  100. unsigned ILI : 1;
  101. unsigned EOM : 1;
  102. unsigned FileMark : 1;
  103. uint8_t Information[4];
  104. uint8_t AdditionalLength;
  105. uint8_t CmdSpecificInformation[4];
  106. uint8_t AdditionalSenseCode;
  107. uint8_t AdditionalSenseQualifier;
  108. uint8_t FieldReplaceableUnitCode;
  109. uint8_t SenseKeySpecific[3];
  110. } MS_SCSI_Request_Sense_Response_t;
  111. /* Function Prototypes: */
  112. bool SCSI_DecodeSCSICommand(void);
  113. #if defined(INCLUDE_FROM_SCSI_C)
  114. static bool SCSI_Command_Inquiry(void);
  115. static bool SCSI_Command_Request_Sense(void);
  116. static bool SCSI_Command_Read_Capacity_10(void);
  117. static bool SCSI_Command_Send_Diagnostic(void);
  118. static bool SCSI_Command_ReadWrite_10(const bool IsDataRead);
  119. static bool SCSI_Command_ModeSense_6(void);
  120. #endif
  121. #endif