Fixed incorrect PID value being used in the USBtoSerial project (thanks to Phill).
[pub/lufa.git] / Demos / Device / MassStorage / MassStorage.c
index 4032648..82e7e8a 100644 (file)
 #define  INCLUDE_FROM_MASSSTORAGE_C\r
 #include "MassStorage.h"\r
 \r
-/* Project Tags, for reading out using the ButtLoad project */\r
-BUTTLOADTAG(ProjName,    "LUFA MassStore App");\r
-BUTTLOADTAG(BuildTime,   __TIME__);\r
-BUTTLOADTAG(BuildDate,   __DATE__);\r
-BUTTLOADTAG(LUFAVersion, "LUFA V" LUFA_VERSION_STRING);\r
-\r
 /* Scheduler Task List */\r
 TASK_LIST\r
 {\r
-       { Task: USB_MassStorage      , TaskStatus: TASK_STOP },\r
+       { .Task = USB_MassStorage      , .TaskStatus = TASK_STOP },\r
 };\r
 \r
 /* Global Variables */\r
@@ -54,7 +48,7 @@ TASK_LIST
 CommandBlockWrapper_t  CommandBlock;\r
 \r
 /** Structure to hold the latest Command Status Wrapper to return to the host, containing the status of the last issued command. */\r
-CommandStatusWrapper_t CommandStatus = { Signature: CSW_SIGNATURE };\r
+CommandStatusWrapper_t CommandStatus = { .Signature = CSW_SIGNATURE };\r
 \r
 /** Flag to asynchronously abort any in-progress data transfers upon the reception of a mass storage reset command. */\r
 volatile bool          IsMassStoreReset = false;\r
@@ -91,21 +85,8 @@ int main(void)
        Scheduler_Start();\r
 }\r
 \r
-/** Event handler for the USB_Reset event. This fires when the USB interface is reset by the USB host, before the\r
- *  enumeration process begins, and enables the control endpoint interrupt so that control requests can be handled\r
- *  asynchronously when they arrive rather than when the control endpoint is polled manually.\r
- */\r
-EVENT_HANDLER(USB_Reset)\r
-{\r
-       /* Select the control endpoint */\r
-       Endpoint_SelectEndpoint(ENDPOINT_CONTROLEP);\r
-\r
-       /* Enable the endpoint SETUP interrupt ISR for the control endpoint */\r
-       USB_INT_Enable(ENDPOINT_INT_SETUP);\r
-}\r
-\r
 /** Event handler for the USB_Connect event. This indicates that the device is enumerating via the status LEDs. */\r
-EVENT_HANDLER(USB_Connect)\r
+void EventHandler_USB_Connect(void)\r
 {\r
        /* Indicate USB enumerating */\r
        UpdateStatus(Status_USBEnumerating);\r
@@ -117,7 +98,7 @@ EVENT_HANDLER(USB_Connect)
 /** Event handler for the USB_Disconnect event. This indicates that the device is no longer connected to a host via\r
  *  the status LEDs and stops the Mass Storage management task.\r
  */\r
-EVENT_HANDLER(USB_Disconnect)\r
+void EventHandler_USB_Disconnect(void)\r
 {\r
        /* Stop running mass storage task */\r
        Scheduler_SetTaskMode(USB_MassStorage, TASK_STOP);\r
@@ -129,7 +110,7 @@ EVENT_HANDLER(USB_Disconnect)
 /** Event handler for the USB_ConfigurationChanged event. This is fired when the host set the current configuration\r
  *  of the USB device after enumeration - the device endpoints are configured and the Mass Storage management task started.\r
  */\r
-EVENT_HANDLER(USB_ConfigurationChanged)\r
+void EventHandler_USB_ConfigurationChanged(void)\r
 {\r
        /* Setup Mass Storage In and Out Endpoints */\r
        Endpoint_ConfigureEndpoint(MASS_STORAGE_IN_EPNUM, EP_TYPE_BULK,\r
@@ -151,38 +132,38 @@ EVENT_HANDLER(USB_ConfigurationChanged)
  *  control requests that are not handled internally by the USB library (including the Mass Storage class-specific\r
  *  requests) so that they can be handled appropriately for the application.\r
  */\r
-EVENT_HANDLER(USB_UnhandledControlPacket)\r
+void EventHandler_USB_UnhandledControlPacket(void)\r
 {\r
        /* Process UFI specific control requests */\r
-       switch (bRequest)\r
+       switch (USB_ControlRequest.bRequest)\r
        {\r
                case REQ_MassStorageReset:\r
-                       if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
                        {\r
-                               Endpoint_ClearSetupReceived();\r
+                               Endpoint_ClearSETUP();\r
 \r
                                /* Indicate that the current transfer should be aborted */\r
                                IsMassStoreReset = true;                        \r
 \r
                                /* Acknowledge status stage */\r
-                               while (!(Endpoint_IsSetupINReady()));\r
-                               Endpoint_ClearSetupIN();\r
+                               while (!(Endpoint_IsINReady()));\r
+                               Endpoint_ClearIN();\r
                        }\r
 \r
                        break;\r
                case REQ_GetMaxLUN:\r
-                       if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
                        {\r
-                               /* Indicate to the host the number of supported LUNs (virtual disks) on the device */\r
-                               Endpoint_ClearSetupReceived();\r
+                               Endpoint_ClearSETUP();\r
 \r
+                               /* Indicate to the host the number of supported LUNs (virtual disks) on the device */\r
                                Endpoint_Write_Byte(TOTAL_LUNS - 1);\r
                                \r
-                               Endpoint_ClearSetupIN();\r
+                               Endpoint_ClearIN();\r
                                \r
                                /* Acknowledge status stage */\r
-                               while (!(Endpoint_IsSetupOUTReceived()));\r
-                               Endpoint_ClearSetupOUT();\r
+                               while (!(Endpoint_IsOUTReceived()));\r
+                               Endpoint_ClearOUT();\r
                        }\r
                        \r
                        break;\r
@@ -234,7 +215,7 @@ TASK(USB_MassStorage)
                Endpoint_SelectEndpoint(MASS_STORAGE_OUT_EPNUM);\r
                \r
                /* Check to see if a command from the host has been issued */\r
-               if (Endpoint_ReadWriteAllowed())\r
+               if (Endpoint_IsReadWriteAllowed())\r
                {       \r
                        /* Indicate busy */\r
                        UpdateStatus(Status_ProcessingCommandBlock);\r
@@ -268,6 +249,11 @@ TASK(USB_MassStorage)
                                        /* Reset the data endpoint banks */\r
                                        Endpoint_ResetFIFO(MASS_STORAGE_OUT_EPNUM);\r
                                        Endpoint_ResetFIFO(MASS_STORAGE_IN_EPNUM);\r
+                                       \r
+                                       Endpoint_SelectEndpoint(MASS_STORAGE_OUT_EPNUM);\r
+                                       Endpoint_ClearStall();\r
+                                       Endpoint_SelectEndpoint(MASS_STORAGE_IN_EPNUM);\r
+                                       Endpoint_ClearStall();\r
 \r
                                        /* Clear the abort transfer flag */\r
                                        IsMassStoreReset = false;\r
@@ -297,7 +283,7 @@ static bool ReadInCommandBlock(void)
 \r
        /* Read in command block header */\r
        Endpoint_Read_Stream_LE(&CommandBlock, (sizeof(CommandBlock) - sizeof(CommandBlock.SCSICommandData)),\r
-                               AbortOnMassStoreReset);\r
+                               StreamCallback_AbortOnMassStoreReset);\r
 \r
        /* Check if the current command is being aborted by the host */\r
        if (IsMassStoreReset)\r
@@ -319,14 +305,14 @@ static bool ReadInCommandBlock(void)
        /* Read in command block command data */\r
        Endpoint_Read_Stream_LE(&CommandBlock.SCSICommandData,\r
                                CommandBlock.SCSICommandLength,\r
-                               AbortOnMassStoreReset);\r
+                               StreamCallback_AbortOnMassStoreReset);\r
          \r
        /* Check if the current command is being aborted by the host */\r
        if (IsMassStoreReset)\r
          return false;\r
 \r
        /* Finalize the stream transfer to send the last packet */\r
-       Endpoint_ClearCurrentBank();\r
+       Endpoint_ClearOUT();\r
        \r
        return true;\r
 }\r
@@ -360,20 +346,20 @@ static void ReturnCommandStatus(void)
        \r
        /* Write the CSW to the endpoint */\r
        Endpoint_Write_Stream_LE(&CommandStatus, sizeof(CommandStatus),\r
-                                 AbortOnMassStoreReset);\r
+                                 StreamCallback_AbortOnMassStoreReset);\r
        \r
        /* Check if the current command is being aborted by the host */\r
        if (IsMassStoreReset)\r
          return;\r
 \r
        /* Finalize the stream transfer to send the last packet */\r
-       Endpoint_ClearCurrentBank();\r
+       Endpoint_ClearIN();\r
 }\r
 \r
 /** Stream callback function for the Endpoint stream read and write functions. This callback will abort the current stream transfer\r
  *  if a Mass Storage Reset request has been issued to the control endpoint.\r
  */\r
-STREAM_CALLBACK(AbortOnMassStoreReset)\r
+uint8_t StreamCallback_AbortOnMassStoreReset(void)\r
 {      \r
        /* Abort if a Mass Storage reset command was received */\r
        if (IsMassStoreReset)\r
@@ -382,24 +368,3 @@ STREAM_CALLBACK(AbortOnMassStoreReset)
        /* Continue with the current stream operation */\r
        return STREAMCALLBACK_Continue;\r
 }\r
-\r
-/** ISR for the general Pipe/Endpoint interrupt vector. This ISR fires when a control request has been issued to the control endpoint,\r
- *  so that the request can be processed. As several elements of the Mass Storage implementation require asynchronous control requests\r
- *  (such as endpoint stall clearing and Mass Storage Reset requests during data transfers) this is done via interrupts rather than\r
- *  polling.\r
- */\r
-ISR(ENDPOINT_PIPE_vect, ISR_BLOCK)\r
-{\r
-       /* Check if the control endpoint has received a request */\r
-       if (Endpoint_HasEndpointInterrupted(ENDPOINT_CONTROLEP))\r
-       {\r
-               /* Clear the endpoint interrupt */\r
-               Endpoint_ClearEndpointInterrupt(ENDPOINT_CONTROLEP);\r
-\r
-               /* Process the control request */\r
-               USB_USBTask();\r
-\r
-               /* Handshake the endpoint setup interrupt - must be after the call to USB_USBTask() */\r
-               USB_INT_Clear(ENDPOINT_INT_SETUP);\r
-       }\r
-}\r