Add more skeleton functions and definitions to the Mass Storage Host mode Class driver.
Made Endpoint_Write_DWord_* functions echo the structure of the matching Endpoint routines for clarity.
break;\r
}\r
\r
+ SCSI_Request_Sense_Response_t SenseData;\r
+ if (MS_Host_RequestSense(&FlashDisk_MS_Interface, 0, &SenseData) != 0)\r
+ {\r
+ printf("Error retrieving device sense.\r\n");\r
+ LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
+ USB_HostState = HOST_STATE_WaitForDeviceRemoval;\r
+ break;\r
+ }\r
+ \r
+ if (MS_Host_PreventAllowMediumRemoval(&FlashDisk_MS_Interface, 0, true))\r
+ {\r
+ printf("Error setting Prevent Device Removal bit.\r\n");\r
+ LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
+ USB_HostState = HOST_STATE_WaitForDeviceRemoval;\r
+ break;\r
+ }\r
+\r
SCSI_Inquiry_Response_t InquiryData;\r
if (MS_Host_GetInquiryData(&FlashDisk_MS_Interface, &InquiryData))\r
{\r
}\r
while (!(DeviceReady));\r
\r
- puts_P(PSTR("Retrieving Capacity... "));\r
+ printf("Retrieving Capacity... ");\r
\r
SCSI_Capacity_t DiskCapacity;\r
if (MS_Host_ReadDeviceCapacity(&FlashDisk_MS_Interface, 0, &DiskCapacity))\r
\r
printf("%lu blocks of %lu bytes.\r\n", DiskCapacity.Blocks, DiskCapacity.BlockSize);\r
\r
+ uint8_t BlockBuffer[DiskCapacity.BlockSize];\r
+\r
+ if (MS_Host_ReadDeviceBlocks(&FlashDisk_MS_Interface, 0, 0x00000000, 1, DiskCapacity.BlockSize, BlockBuffer))\r
+ {\r
+ printf("Error reading device block.\r\n");\r
+ LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
+ USB_HostState = HOST_STATE_WaitForDeviceRemoval;\r
+ break;\r
+ }\r
+ \r
+ printf("\r\nContents of first block:\r\n");\r
+\r
+ for (uint16_t Chunk = 0; Chunk < (DiskCapacity.BlockSize >> 4); Chunk++)\r
+ {\r
+ uint8_t* ChunkPtr = &BlockBuffer[Chunk << 4];\r
+ \r
+ /* Print out the 16 bytes of the chunk in HEX format */\r
+ for (uint8_t ByteOffset = 0; ByteOffset < (1 << 4); ByteOffset++)\r
+ {\r
+ char CurrByte = *(ChunkPtr + ByteOffset);\r
+ printf_P(PSTR("%.2X "), CurrByte);\r
+ }\r
+ \r
+ printf(" ");\r
+\r
+ /* Print out the 16 bytes of the chunk in ASCII format */\r
+ for (uint8_t ByteOffset = 0; ByteOffset < (1 << 4); ByteOffset++)\r
+ {\r
+ char CurrByte = *(ChunkPtr + ByteOffset);\r
+ putchar(isprint(CurrByte) ? CurrByte : '.');\r
+ }\r
+ \r
+ printf("\r\n");\r
+ }\r
+\r
LEDs_SetAllLEDs(LEDMASK_USB_READY);\r
USB_HostState = HOST_STATE_WaitForDeviceRemoval;\r
break;\r
#include <avr/wdt.h>\r
#include <avr/pgmspace.h>\r
#include <avr/power.h>\r
+ #include <ctype.h>\r
#include <stdio.h>\r
\r
#include <LUFA/Version.h>\r
# code.
%:
- make -C ClassDriver/ $@
+ #make -C ClassDriver/ $@ -- TODO: Re-enable once Host Mode class drivers complete
make -C LowLevel/ $@
\r
}\r
\r
-static uint8_t MassStore_SendCommand(USB_ClassInfo_MS_Host_t* MSInterfaceInfo, MS_CommandBlockWrapper_t* SCSICommandBlock)\r
+static uint8_t MS_Host_SendCommand(USB_ClassInfo_MS_Host_t* MSInterfaceInfo, MS_CommandBlockWrapper_t* SCSICommandBlock)\r
{\r
uint8_t ErrorCode = PIPE_RWSTREAM_NoError;\r
\r
return PIPE_RWSTREAM_NoError;\r
}\r
\r
-static uint8_t MassStore_WaitForDataReceived(USB_ClassInfo_MS_Host_t* MSInterfaceInfo)\r
+static uint8_t MS_Host_WaitForDataReceived(USB_ClassInfo_MS_Host_t* MSInterfaceInfo)\r
{\r
uint16_t TimeoutMSRem = COMMAND_DATA_TIMEOUT_MS;\r
\r
return PIPE_RWSTREAM_NoError;\r
}\r
\r
-static uint8_t MassStore_SendReceiveData(USB_ClassInfo_MS_Host_t* MSInterfaceInfo,\r
+static uint8_t MS_Host_SendReceiveData(USB_ClassInfo_MS_Host_t* MSInterfaceInfo,\r
MS_CommandBlockWrapper_t* SCSICommandBlock, void* BufferPtr)\r
{\r
uint8_t ErrorCode = PIPE_RWSTREAM_NoError;\r
return PIPE_RWSTREAM_NoError;\r
}\r
\r
-static uint8_t MassStore_GetReturnedStatus(USB_ClassInfo_MS_Host_t* MSInterfaceInfo,\r
+static uint8_t MS_Host_GetReturnedStatus(USB_ClassInfo_MS_Host_t* MSInterfaceInfo,\r
MS_CommandStatusWrapper_t* SCSICommandStatus)\r
{\r
uint8_t ErrorCode = PIPE_RWSTREAM_NoError;\r
\r
- if ((ErrorCode = MassStore_WaitForDataReceived(MSInterfaceInfo)) != PIPE_RWSTREAM_NoError)\r
+ if ((ErrorCode = MS_Host_WaitForDataReceived(MSInterfaceInfo)) != PIPE_RWSTREAM_NoError)\r
return ErrorCode;\r
\r
Pipe_SelectPipe(MSInterfaceInfo->Config.DataINPipeNumber);\r
\r
uint8_t MS_Host_GetInquiryData(USB_ClassInfo_MS_Host_t* MSInterfaceInfo, SCSI_Inquiry_Response_t* InquiryData)\r
{\r
+ if ((USB_HostState != HOST_STATE_Configured) || !(MSInterfaceInfo->State.Active))\r
+ return HOST_SENDCONTROL_DeviceDisconnect;\r
\r
}\r
\r
uint8_t MS_Host_TestUnitReady(USB_ClassInfo_MS_Host_t* MSInterfaceInfo, uint8_t LUNIndex, bool* DeviceReady);\r
+\r
uint8_t MS_Host_ReadDeviceCapacity(USB_ClassInfo_MS_Host_t* MSInterfaceInfo, uint8_t LUNIndex,\r
SCSI_Capacity_t* DeviceCapacity);\r
\r
+uint8_t MS_Host_RequestSense(USB_ClassInfo_MS_Host_t* MSInterfaceInfo, uint8_t LUNIndex,\r
+ SCSI_Request_Sense_Response_t* SenseData);\r
+\r
+uint8_t MS_Host_PreventAllowMediumRemoval(USB_ClassInfo_MS_Host_t* MSInterfaceInfo, uint8_t LUNIndex, bool PreventRemoval); \r
+\r
+uint8_t MS_Host_ReadDeviceBlocks(USB_ClassInfo_MS_Host_t* MSInterfaceInfo, uint8_t LUNIndex, uint32_t BlockAddr,\r
+ uint8_t Blocks, uint16_t BlockSize, void* BlockBuffer);\r
+\r
+uint8_t MS_Host_WriteDeviceBlocks(USB_ClassInfo_MS_Host_t* MSInterfaceInfo, uint8_t LUNIndex, uint32_t BlockAddr,\r
+ uint8_t Blocks, uint16_t BlockSize, void* BlockBuffer);\r
+\r
#endif\r
*/\r
uint8_t MS_Host_ResetMSInterface(USB_ClassInfo_MS_Host_t* MSInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);\r
\r
+ /** Sends a GET MAX LUN control request to the attached device, retrieving the index of the highest LUN (Logical\r
+ * UNit, a logical drive) in the device. This value can then be used in the other functions of the Mass Storage\r
+ * Host mode Class driver to address a specific LUN within the device.\r
+ *\r
+ * \param[in,out] MSInterfaceInfo Pointer to a structure containing a MS Class host configuration and state\r
+ * \param[out] MaxLUNIndex Pointer to a location where the highest LUN index value should be stored\r
+ *\r
+ * \return A value from the \ref USB_Host_SendControlErrorCodes_t enum\r
+ */\r
uint8_t MS_Host_GetMaxLUN(USB_ClassInfo_MS_Host_t* MSInterfaceInfo, uint8_t* MaxLUNIndex) ATTR_NON_NULL_PTR_ARG(1, 2);\r
\r
uint8_t MS_Host_GetInquiryData(USB_ClassInfo_MS_Host_t* MSInterfaceInfo,\r
uint8_t MS_Host_ReadDeviceCapacity(USB_ClassInfo_MS_Host_t* MSInterfaceInfo, uint8_t LUNIndex,\r
SCSI_Capacity_t* DeviceCapacity) ATTR_NON_NULL_PTR_ARG(1, 3);\r
\r
+ uint8_t MS_Host_RequestSense(USB_ClassInfo_MS_Host_t* MSInterfaceInfo, uint8_t LUNIndex,\r
+ SCSI_Request_Sense_Response_t* SenseData) ATTR_NON_NULL_PTR_ARG(1, 3);\r
+ \r
+ uint8_t MS_Host_PreventAllowMediumRemoval(USB_ClassInfo_MS_Host_t* MSInterfaceInfo, uint8_t LUNIndex,\r
+ bool PreventRemoval) ATTR_NON_NULL_PTR_ARG(1);\r
+ \r
+ uint8_t MS_Host_ReadDeviceBlocks(USB_ClassInfo_MS_Host_t* MSInterfaceInfo, uint8_t LUNIndex, uint32_t BlockAddr,\r
+ uint8_t Blocks, uint16_t BlockSize, void* BlockBuffer) ATTR_NON_NULL_PTR_ARG(1, 6);\r
+ \r
+ uint8_t MS_Host_WriteDeviceBlocks(USB_ClassInfo_MS_Host_t* MSInterfaceInfo, uint8_t LUNIndex, uint32_t BlockAddr,\r
+ uint8_t Blocks, uint16_t BlockSize, void* BlockBuffer) ATTR_NON_NULL_PTR_ARG(1, 6);\r
+\r
/* Private Interface - For use in library only: */\r
#if !defined(__DOXYGEN__)\r
/* Macros: */\r
static uint8_t DComp_NextMassStorageInterface(void* CurrentDescriptor);\r
static uint8_t DComp_NextInterfaceBulkDataEndpoint(void* CurrentDescriptor);\r
\r
- static uint8_t MassStore_SendCommand(USB_ClassInfo_MS_Host_t* MSInterfaceInfo,\r
- MS_CommandBlockWrapper_t* SCSICommandBlock);\r
- static uint8_t MassStore_WaitForDataReceived(USB_ClassInfo_MS_Host_t* MSInterfaceInfo);\r
- static uint8_t MassStore_SendReceiveData(USB_ClassInfo_MS_Host_t* MSInterfaceInfo, \r
- MS_CommandBlockWrapper_t* SCSICommandBlock, void* BufferPtr);\r
- static uint8_t MassStore_GetReturnedStatus(USB_ClassInfo_MS_Host_t* MSInterfaceInfo,\r
- MS_CommandStatusWrapper_t* SCSICommandStatus);\r
+ static uint8_t MS_Host_SendCommand(USB_ClassInfo_MS_Host_t* MSInterfaceInfo,\r
+ MS_CommandBlockWrapper_t* SCSICommandBlock);\r
+ static uint8_t MS_Host_WaitForDataReceived(USB_ClassInfo_MS_Host_t* MSInterfaceInfo);\r
+ static uint8_t MS_Host_SendReceiveData(USB_ClassInfo_MS_Host_t* MSInterfaceInfo, \r
+ MS_CommandBlockWrapper_t* SCSICommandBlock, void* BufferPtr);\r
+ static uint8_t MS_Host_GetReturnedStatus(USB_ClassInfo_MS_Host_t* MSInterfaceInfo,\r
+ MS_CommandStatusWrapper_t* SCSICommandStatus);\r
#endif\r
#endif\r
\r
static inline void Pipe_Write_DWord_LE(const uint32_t DWord) ATTR_ALWAYS_INLINE;\r
static inline void Pipe_Write_DWord_LE(const uint32_t DWord)\r
{\r
- Pipe_Write_Word_LE(DWord);\r
- Pipe_Write_Word_LE(DWord >> 16);\r
+ UPDATX = (DWord & 0xFF);\r
+ UPDATX = (DWord >> 8);\r
+ UPDATX = (DWord >> 16);\r
+ UPDATX = (DWord >> 24);\r
}\r
\r
/** Writes four bytes to the currently selected pipe's bank in big endian format, for IN\r
static inline void Pipe_Write_DWord_BE(const uint32_t DWord) ATTR_ALWAYS_INLINE;\r
static inline void Pipe_Write_DWord_BE(const uint32_t DWord)\r
{\r
- Pipe_Write_Word_BE(DWord >> 16);\r
- Pipe_Write_Word_BE(DWord);\r
+ UPDATX = (DWord >> 24);\r
+ UPDATX = (DWord >> 16);\r
+ UPDATX = (DWord >> 8);\r
+ UPDATX = (DWord & 0xFF);\r
} \r
\r
/** Discards four bytes from the currently selected pipe's bank, for OUT direction pipes. \r
* - Added return values to the CDC and MIDI class driver transmit functions\r
* - Added extra masks to the SPI driver, changed SPI_Init() so that the clock polarity and sample modes can be set\r
* - Optimized Endpoint_Read_Word_* and Pipe_Read_Word_* macros to reduce compiled size\r
+ * - Added non-null function parameter pointer restrictions to USB Class drivers to improve user code reliability\r
*\r
* <b>Fixed:</b>\r
* - Fixed possible lockup in the CDC device class driver, when the host sends data that is a multiple of the\r