Removed software PDI/TPI emulation from the AVRISP-MKII clone project, as it was...
[pub/USBasp.git] / Demos / Host / ClassDriver / MassStorageHost / MassStorageHost.c
index 6b74d8d..beec0a7 100644 (file)
@@ -1,13 +1,13 @@
 /*\r
              LUFA Library\r
 /*\r
              LUFA Library\r
-     Copyright (C) Dean Camera, 2009.\r
+     Copyright (C) Dean Camera, 2010.\r
               \r
   dean [at] fourwalledcubicle [dot] com\r
       www.fourwalledcubicle.com\r
 */\r
 \r
 /*\r
               \r
   dean [at] fourwalledcubicle [dot] com\r
       www.fourwalledcubicle.com\r
 */\r
 \r
 /*\r
-  Copyright 2009  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
+  Copyright 2010  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
 \r
   Permission to use, copy, modify, distribute, and sell this \r
   software and its documentation for any purpose is hereby granted\r
 \r
   Permission to use, copy, modify, distribute, and sell this \r
   software and its documentation for any purpose is hereby granted\r
@@ -63,6 +63,7 @@ int main(void)
        puts_P(PSTR(ESC_FG_CYAN "Mass Storage Host Demo running.\r\n" ESC_FG_WHITE));\r
 \r
        LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);\r
        puts_P(PSTR(ESC_FG_CYAN "Mass Storage Host Demo running.\r\n" ESC_FG_WHITE));\r
 \r
        LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);\r
+       sei();\r
 \r
        for (;;)\r
        {\r
 \r
        for (;;)\r
        {\r
@@ -77,7 +78,7 @@ int main(void)
                                if (USB_Host_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData,\r
                                                                       sizeof(ConfigDescriptorData)) != HOST_GETCONFIG_Successful)\r
                                {\r
                                if (USB_Host_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData,\r
                                                                       sizeof(ConfigDescriptorData)) != HOST_GETCONFIG_Successful)\r
                                {\r
-                                       printf("Error Retrieving Configuration Descriptor.\r\n");\r
+                                       puts_P(PSTR("Error Retrieving Configuration Descriptor.\r\n"));\r
                                        LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
                                        USB_HostState = HOST_STATE_WaitForDeviceRemoval;\r
                                        break;\r
                                        LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
                                        USB_HostState = HOST_STATE_WaitForDeviceRemoval;\r
                                        break;\r
@@ -86,7 +87,7 @@ int main(void)
                                if (MS_Host_ConfigurePipes(&FlashDisk_MS_Interface,\r
                                                           ConfigDescriptorSize, ConfigDescriptorData) != MS_ENUMERROR_NoError)\r
                                {\r
                                if (MS_Host_ConfigurePipes(&FlashDisk_MS_Interface,\r
                                                           ConfigDescriptorSize, ConfigDescriptorData) != MS_ENUMERROR_NoError)\r
                                {\r
-                                       printf("Attached Device Not a Valid Mass Storage Device.\r\n");\r
+                                       puts_P(PSTR("Attached Device Not a Valid Mass Storage Device.\r\n"));\r
                                        LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
                                        USB_HostState = HOST_STATE_WaitForDeviceRemoval;\r
                                        break;\r
                                        LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
                                        USB_HostState = HOST_STATE_WaitForDeviceRemoval;\r
                                        break;\r
@@ -94,13 +95,14 @@ int main(void)
                                \r
                                if (USB_Host_SetDeviceConfiguration(1) != HOST_SENDCONTROL_Successful)\r
                                {\r
                                \r
                                if (USB_Host_SetDeviceConfiguration(1) != HOST_SENDCONTROL_Successful)\r
                                {\r
-                                       printf("Error Setting Device Configuration.\r\n");\r
+                                       puts_P(PSTR("Error Setting Device Configuration.\r\n"));\r
                                        LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
                                        USB_HostState = HOST_STATE_WaitForDeviceRemoval;\r
                                        break;\r
                                }\r
                                \r
                                        LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
                                        USB_HostState = HOST_STATE_WaitForDeviceRemoval;\r
                                        break;\r
                                }\r
                                \r
-                               printf("Mass Storage Device Enumerated.\r\n");\r
+                               puts_P(PSTR("Mass Storage Device Enumerated.\r\n"));\r
+                               LEDs_SetAllLEDs(LEDMASK_USB_READY);\r
                                USB_HostState = HOST_STATE_Configured;\r
                                break;\r
                        case HOST_STATE_Configured:\r
                                USB_HostState = HOST_STATE_Configured;\r
                                break;\r
                        case HOST_STATE_Configured:\r
@@ -109,17 +111,17 @@ int main(void)
                                uint8_t MaxLUNIndex;\r
                                if (MS_Host_GetMaxLUN(&FlashDisk_MS_Interface, &MaxLUNIndex))\r
                                {\r
                                uint8_t MaxLUNIndex;\r
                                if (MS_Host_GetMaxLUN(&FlashDisk_MS_Interface, &MaxLUNIndex))\r
                                {\r
-                                       printf("Error retrieving max LUN index.\r\n");\r
+                                       puts_P(PSTR("Error retrieving max LUN index.\r\n"));\r
                                        LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
                                        USB_HostState = HOST_STATE_WaitForDeviceRemoval;\r
                                        break;\r
                                }\r
                                \r
                                        LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
                                        USB_HostState = HOST_STATE_WaitForDeviceRemoval;\r
                                        break;\r
                                }\r
                                \r
-                               printf("Total LUNs: %d - Using first LUN in device.\r\n", (MaxLUNIndex + 1));\r
+                               printf_P(PSTR("Total LUNs: %d - Using first LUN in device.\r\n"), (MaxLUNIndex + 1));\r
                                \r
                                if (MS_Host_ResetMSInterface(&FlashDisk_MS_Interface))\r
                                {\r
                                \r
                                if (MS_Host_ResetMSInterface(&FlashDisk_MS_Interface))\r
                                {\r
-                                       printf("Error resetting Mass Storage interface.\r\n");\r
+                                       puts_P(PSTR("Error resetting Mass Storage interface.\r\n"));\r
                                        LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
                                        USB_HostState = HOST_STATE_WaitForDeviceRemoval;\r
                                        break;\r
                                        LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
                                        USB_HostState = HOST_STATE_WaitForDeviceRemoval;\r
                                        break;\r
@@ -128,7 +130,7 @@ int main(void)
                                SCSI_Request_Sense_Response_t SenseData;\r
                                if (MS_Host_RequestSense(&FlashDisk_MS_Interface, 0, &SenseData) != 0)\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
+                                       puts_P(PSTR("Error retrieving device sense.\r\n"));\r
                                        LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
                                        USB_HostState = HOST_STATE_WaitForDeviceRemoval;\r
                                        break;\r
                                        LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
                                        USB_HostState = HOST_STATE_WaitForDeviceRemoval;\r
                                        break;\r
@@ -136,7 +138,7 @@ int main(void)
                        \r
                                if (MS_Host_PreventAllowMediumRemoval(&FlashDisk_MS_Interface, 0, true))\r
                                {\r
                        \r
                                if (MS_Host_PreventAllowMediumRemoval(&FlashDisk_MS_Interface, 0, true))\r
                                {\r
-                                       printf("Error setting Prevent Device Removal bit.\r\n");\r
+                                       puts_P(PSTR("Error setting Prevent Device Removal bit.\r\n"));\r
                                        LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
                                        USB_HostState = HOST_STATE_WaitForDeviceRemoval;\r
                                        break;\r
                                        LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
                                        USB_HostState = HOST_STATE_WaitForDeviceRemoval;\r
                                        break;\r
@@ -145,15 +147,15 @@ int main(void)
                                SCSI_Inquiry_Response_t InquiryData;\r
                                if (MS_Host_GetInquiryData(&FlashDisk_MS_Interface, 0, &InquiryData))\r
                                {\r
                                SCSI_Inquiry_Response_t InquiryData;\r
                                if (MS_Host_GetInquiryData(&FlashDisk_MS_Interface, 0, &InquiryData))\r
                                {\r
-                                       printf("Error retrieving device Inquiry data.\r\n");\r
+                                       puts_P(PSTR("Error retrieving device Inquiry data.\r\n"));\r
                                        LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
                                        USB_HostState = HOST_STATE_WaitForDeviceRemoval;\r
                                        break;                          \r
                                }\r
 \r
                                        LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
                                        USB_HostState = HOST_STATE_WaitForDeviceRemoval;\r
                                        break;                          \r
                                }\r
 \r
-                               printf("Vendor \"%.8s\", Product \"%.16s\"\r\n", InquiryData.VendorID, InquiryData.ProductID);\r
+                               printf_P(PSTR("Vendor \"%.8s\", Product \"%.16s\"\r\n"), InquiryData.VendorID, InquiryData.ProductID);\r
                                \r
                                \r
-                               printf("Waiting until ready...\r\n");\r
+                               puts_P(PSTR("Waiting until ready...\r\n"));\r
 \r
                                for (;;)\r
                                {\r
 \r
                                for (;;)\r
                                {\r
@@ -165,37 +167,37 @@ int main(void)
                                        /* Check if an error other than a logical command error (device busy) received */\r
                                        if (ErrorCode != MS_ERROR_LOGICAL_CMD_FAILED)\r
                                        {\r
                                        /* Check if an error other than a logical command error (device busy) received */\r
                                        if (ErrorCode != MS_ERROR_LOGICAL_CMD_FAILED)\r
                                        {\r
-                                               printf("Error waiting for device to be ready.\r\n");\r
+                                               puts_P(PSTR("Error waiting for device to be ready.\r\n"));\r
                                                LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
                                                USB_HostState = HOST_STATE_WaitForDeviceRemoval;\r
                                                break;\r
                                        }\r
                                }\r
 \r
                                                LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
                                                USB_HostState = HOST_STATE_WaitForDeviceRemoval;\r
                                                break;\r
                                        }\r
                                }\r
 \r
-                               printf("Retrieving Capacity... ");\r
+                               puts_P(PSTR("Retrieving Capacity...\r\n"));\r
 \r
                                SCSI_Capacity_t DiskCapacity;\r
                                if (MS_Host_ReadDeviceCapacity(&FlashDisk_MS_Interface, 0, &DiskCapacity))\r
                                {\r
 \r
                                SCSI_Capacity_t DiskCapacity;\r
                                if (MS_Host_ReadDeviceCapacity(&FlashDisk_MS_Interface, 0, &DiskCapacity))\r
                                {\r
-                                       printf("Error retrieving device capacity.\r\n");\r
+                                       puts_P(PSTR("Error retrieving device capacity.\r\n"));\r
                                        LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
                                        USB_HostState = HOST_STATE_WaitForDeviceRemoval;\r
                                        break;\r
                                }\r
                                \r
                                        LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
                                        USB_HostState = HOST_STATE_WaitForDeviceRemoval;\r
                                        break;\r
                                }\r
                                \r
-                               printf("%lu blocks of %lu bytes.\r\n", DiskCapacity.Blocks, DiskCapacity.BlockSize);\r
+                               printf_P(PSTR("%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
 \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
+                                       puts_P(PSTR("Error reading device block.\r\n"));\r
                                        LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
                                        USB_HostState = HOST_STATE_WaitForDeviceRemoval;\r
                                        break;\r
                                }\r
                        \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
+                               puts_P(PSTR("\r\nContents of first block:\r\n"));\r
 \r
                                for (uint16_t Chunk = 0; Chunk < (DiskCapacity.BlockSize >> 4); Chunk++)\r
                                {\r
 \r
                                for (uint16_t Chunk = 0; Chunk < (DiskCapacity.BlockSize >> 4); Chunk++)\r
                                {\r
@@ -208,7 +210,7 @@ int main(void)
                                                printf_P(PSTR("%.2X "), CurrByte);\r
                                        }\r
                                        \r
                                                printf_P(PSTR("%.2X "), CurrByte);\r
                                        }\r
                                        \r
-                                       printf("    ");\r
+                                       printf_P(PSTR("    "));\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
                                        /* Print out the 16 bytes of the chunk in ASCII format */\r
                                        for (uint8_t ByteOffset = 0; ByteOffset < (1 << 4); ByteOffset++)\r
@@ -217,7 +219,7 @@ int main(void)
                                                putchar(isprint(CurrByte) ? CurrByte : '.');\r
                                        }\r
                                        \r
                                                putchar(isprint(CurrByte) ? CurrByte : '.');\r
                                        }\r
                                        \r
-                                       printf("\r\n");\r
+                                       printf_P(PSTR("\r\n"));\r
                                }\r
 \r
                                LEDs_SetAllLEDs(LEDMASK_USB_READY);\r
                                }\r
 \r
                                LEDs_SetAllLEDs(LEDMASK_USB_READY);\r