Fixed StillImageHost not correctly freezing and unfreezing data pipes while waiting...
authorDean Camera <dean@fourwalledcubicle.com>
Tue, 1 Sep 2009 13:35:30 +0000 (13:35 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Tue, 1 Sep 2009 13:35:30 +0000 (13:35 +0000)
Added basic PIMA commands to the StillImage Host Class driver - need to extend to PIMA specific command functions.

Demos/Host/LowLevel/StillImageHost/Lib/StillImageCommands.c
LUFA/Drivers/USB/Class/Common/StillImage.h
LUFA/Drivers/USB/Class/Host/MassStorage.c
LUFA/Drivers/USB/Class/Host/StillImage.c
LUFA/Drivers/USB/Class/Host/StillImage.h
LUFA/ManPages/ChangeLog.txt

index 970df4f..fbff2f4 100644 (file)
@@ -127,7 +127,9 @@ uint8_t SImage_RecieveBlockHeader(void)
                        }\r
                }\r
                \r
+               Pipe_Freeze();\r
                Pipe_SelectPipe(SIMAGE_DATA_OUT_PIPE);\r
+               Pipe_Unfreeze();\r
 \r
                /* Check if pipe stalled (command failed by device) */\r
                if (Pipe_IsStalled())\r
@@ -139,7 +141,9 @@ uint8_t SImage_RecieveBlockHeader(void)
                        return PIPE_RWSTREAM_PipeStalled;\r
                }\r
 \r
+               Pipe_Freeze();\r
                Pipe_SelectPipe(SIMAGE_DATA_IN_PIPE);\r
+               Pipe_Unfreeze();\r
 \r
                /* Check if pipe stalled (command failed by device) */\r
                if (Pipe_IsStalled())\r
@@ -155,14 +159,7 @@ uint8_t SImage_RecieveBlockHeader(void)
                if (USB_HostState == HOST_STATE_Unattached)\r
                  return PIPE_RWSTREAM_DeviceDisconnected;\r
        }\r
-       \r
-       /* Freeze OUT pipe after use */\r
-       Pipe_SelectPipe(SIMAGE_DATA_OUT_PIPE);\r
-       Pipe_Freeze();\r
-\r
-       /* Select the IN data pipe for data reception */\r
-       Pipe_SelectPipe(SIMAGE_DATA_IN_PIPE);\r
-       \r
+               \r
        /* Load in the response from the attached device */\r
        Pipe_Read_Stream_LE(&PIMA_ReceivedBlock, PIMA_COMMAND_SIZE(0));\r
        \r
index 2723aeb..804b312 100644 (file)
                 *\r
                 *  \param[in] params  Number of parameters which are to be sent in the Param field of the container\r
                 */\r
-               #define PIMA_COMMAND_SIZE(params)      ((sizeof(PIMA_SendBlock) - sizeof(PIMA_SendBlock.Params)) + \\r
-                                                       (params * sizeof(PIMA_SendBlock.Params[0])))\r
+               #define PIMA_COMMAND_SIZE(params)      ((sizeof(SI_PIMA_Container_t) - sizeof(((SI_PIMA_Container_t*)NULL)->Params)) + \\r
+                                                       (params * sizeof(((SI_PIMA_Container_t*)NULL)->Params[0])))\r
 \r
                /** Used in the DataLength field of a PIMA container, to give the total container size in bytes for\r
                 *  a data container.\r
                 *\r
                 *  \param[in] datalen  Length in bytes of the data in the container\r
                 */\r
-               #define PIMA_DATA_SIZE(datalen)        ((sizeof(PIMA_SendBlock) - sizeof(PIMA_SendBlock.Params)) + datalen)\r
+               #define PIMA_DATA_SIZE(datalen)        ((sizeof(SI_PIMA_Container_t) - sizeof(((SI_PIMA_Container_t*)NULL)->Params)) + datalen)\r
 \r
        /* Type defines: */\r
                /** Type define for a PIMA container, use to send commands and receive responses to and from an\r
                };      \r
                \r
        /* Enums: */\r
-       \r
+               enum SI_PIMA_ResponseCodes_t\r
+               {\r
+                       PIMA_RESPONSE_OK                     = 1,\r
+                       PIMA_RESPONSE_GeneralError           = 2,\r
+                       PIMA_RESPONSE_SessionNotOpen         = 3,\r
+                       PIMA_RESPONSE_InvalidTransaction     = 4,\r
+                       PIMA_RESPONSE_OperationNotSupported  = 5,\r
+                       PIMA_RESPONSE_ParameterNotSupported  = 6,\r
+               };\r
        \r
        /* Type Defines: */\r
        \r
index 6a8373a..678c070 100644 (file)
@@ -95,9 +95,12 @@ static uint8_t DComp_NextMSInterface(void* CurrentDescriptor)
 {\r
        if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface)\r
        {\r
-               if ((DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).Class    == MASS_STORE_CLASS)    &&\r
-                   (DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).SubClass == MASS_STORE_SUBCLASS) &&\r
-                   (DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).Protocol == MASS_STORE_PROTOCOL))\r
+               USB_Descriptor_Interface_t* CurrentInterface = DESCRIPTOR_PCAST(CurrentDescriptor,\r
+                                                                               USB_Descriptor_Interface_t);\r
+\r
+               if ((CurrentInterface->Class    == MASS_STORE_CLASS)    &&\r
+                   (CurrentInterface->SubClass == MASS_STORE_SUBCLASS) &&\r
+                   (CurrentInterface->Protocol == MASS_STORE_PROTOCOL))\r
                {\r
                        return DESCRIPTOR_SEARCH_Found;\r
                }\r
index ed38eae..10759f6 100644 (file)
@@ -106,9 +106,12 @@ uint8_t DComp_SI_Host_NextSIInterface(void* CurrentDescriptor)
 {\r
        if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface)\r
        {\r
-               if ((DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).Class    == STILL_IMAGE_CLASS)    &&\r
-                   (DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).SubClass == STILL_IMAGE_SUBCLASS) &&\r
-                   (DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).Protocol == STILL_IMAGE_PROTOCOL))\r
+               USB_Descriptor_Interface_t* CurrentInterface = DESCRIPTOR_PCAST(CurrentDescriptor,\r
+                                                                               USB_Descriptor_Interface_t);\r
+\r
+               if ((CurrentInterface->Class    == STILL_IMAGE_CLASS)    &&\r
+                   (CurrentInterface->SubClass == STILL_IMAGE_SUBCLASS) &&\r
+                   (CurrentInterface->Protocol == STILL_IMAGE_PROTOCOL))\r
                {\r
                        return DESCRIPTOR_SEARCH_Found;\r
                }\r
@@ -145,4 +148,144 @@ void SI_Host_USBTask(USB_ClassInfo_SI_Host_t* SIInterfaceInfo)
 \r
 }\r
 \r
+void SImage_Host_SendBlockHeader(USB_ClassInfo_SI_Host_t* SIInterfaceInfo, SI_PIMA_Container_t* PIMAHeader)\r
+{\r
+       Pipe_SelectPipe(SIInterfaceInfo->Config.DataOUTPipeNumber);\r
+       Pipe_Unfreeze();\r
+\r
+       Pipe_Write_Stream_LE(PIMAHeader, PIMA_COMMAND_SIZE(0), NO_STREAM_CALLBACK);\r
+       \r
+       if (PIMAHeader->Type == CType_CommandBlock)\r
+       {\r
+               uint8_t ParamBytes = (PIMAHeader->DataLength - PIMA_COMMAND_SIZE(0));\r
+\r
+               if (ParamBytes)\r
+                 Pipe_Write_Stream_LE(&PIMAHeader->Params, ParamBytes, NO_STREAM_CALLBACK);\r
+               \r
+               Pipe_ClearOUT();\r
+       }\r
+                                       \r
+       Pipe_Freeze();\r
+}\r
+\r
+uint8_t SImage_Host_RecieveBlockHeader(USB_ClassInfo_SI_Host_t* SIInterfaceInfo, SI_PIMA_Container_t* PIMAHeader)\r
+{\r
+       uint16_t TimeoutMSRem = COMMAND_DATA_TIMEOUT_MS;\r
+\r
+       Pipe_SelectPipe(SIInterfaceInfo->Config.DataINPipeNumber);\r
+       Pipe_Unfreeze();\r
+       \r
+       while (!(Pipe_IsReadWriteAllowed()))\r
+       {\r
+               if (USB_INT_HasOccurred(USB_INT_HSOFI))\r
+               {\r
+                       USB_INT_Clear(USB_INT_HSOFI);\r
+                       TimeoutMSRem--;\r
+\r
+                       if (!(TimeoutMSRem))\r
+                       {\r
+                               return PIPE_RWSTREAM_Timeout;\r
+                       }\r
+               }\r
+               \r
+               Pipe_Freeze();\r
+               Pipe_SelectPipe(SIInterfaceInfo->Config.DataOUTPipeNumber);\r
+               Pipe_Unfreeze();\r
+\r
+               if (Pipe_IsStalled())\r
+               {\r
+                       USB_Host_ClearPipeStall(SIInterfaceInfo->Config.DataOUTPipeNumber);\r
+                       return PIPE_RWSTREAM_PipeStalled;\r
+               }\r
+\r
+               Pipe_Freeze();\r
+               Pipe_SelectPipe(SIInterfaceInfo->Config.DataINPipeNumber);\r
+               Pipe_Unfreeze();\r
+\r
+               if (Pipe_IsStalled())\r
+               {\r
+                       USB_Host_ClearPipeStall(SIInterfaceInfo->Config.DataINPipeNumber);\r
+                       return PIPE_RWSTREAM_PipeStalled;\r
+               }\r
+                 \r
+               if (USB_HostState == HOST_STATE_Unattached)\r
+                 return PIPE_RWSTREAM_DeviceDisconnected;\r
+       }\r
+       \r
+       Pipe_Read_Stream_LE(PIMAHeader, PIMA_COMMAND_SIZE(0), NO_STREAM_CALLBACK);\r
+       \r
+       if (PIMAHeader->Type == CType_ResponseBlock)\r
+       {\r
+               uint8_t ParamBytes = (PIMAHeader->DataLength - PIMA_COMMAND_SIZE(0));\r
+\r
+               if (ParamBytes)\r
+                 Pipe_Read_Stream_LE(&PIMAHeader->Params, ParamBytes, NO_STREAM_CALLBACK);\r
+               \r
+               Pipe_ClearIN();\r
+       }\r
+       \r
+       Pipe_Freeze();\r
+       \r
+       return PIPE_RWSTREAM_NoError;\r
+}\r
+\r
+uint8_t SImage_Host_SendData(USB_ClassInfo_SI_Host_t* SIInterfaceInfo, void* Buffer, uint16_t Bytes)\r
+{\r
+       uint8_t ErrorCode;\r
+\r
+       Pipe_SelectPipe(SIInterfaceInfo->Config.DataOUTPipeNumber);\r
+       Pipe_Unfreeze();\r
+       \r
+       ErrorCode = Pipe_Write_Stream_LE(Buffer, Bytes, NO_STREAM_CALLBACK);\r
+\r
+       Pipe_ClearOUT();\r
+       Pipe_Freeze();\r
+       \r
+       return ErrorCode;\r
+}\r
+\r
+uint8_t SImage_Host_ReadData(USB_ClassInfo_SI_Host_t* SIInterfaceInfo, void* Buffer, uint16_t Bytes)\r
+{\r
+       uint8_t ErrorCode;\r
+\r
+       Pipe_SelectPipe(SIInterfaceInfo->Config.DataINPipeNumber);\r
+       Pipe_Unfreeze();\r
+\r
+       ErrorCode = Pipe_Read_Stream_LE(Buffer, Bytes, NO_STREAM_CALLBACK);\r
+\r
+       Pipe_Freeze();\r
+       \r
+       return ErrorCode;\r
+}\r
+\r
+bool SImage_Host_IsEventReceived(USB_ClassInfo_SI_Host_t* SIInterfaceInfo)\r
+{\r
+       bool IsEventReceived = false;\r
+\r
+       Pipe_SelectPipe(SIInterfaceInfo->Config.EventsPipeNumber);\r
+       Pipe_Unfreeze();\r
+       \r
+       if (Pipe_BytesInPipe())\r
+         IsEventReceived = true;\r
+       \r
+       Pipe_Freeze();\r
+       \r
+       return IsEventReceived;\r
+}\r
+\r
+uint8_t SImage_Host_RecieveEventHeader(USB_ClassInfo_SI_Host_t* SIInterfaceInfo, SI_PIMA_Container_t* PIMAHeader)\r
+{\r
+       uint8_t ErrorCode;\r
+\r
+       Pipe_SelectPipe(SIInterfaceInfo->Config.EventsPipeNumber);\r
+       Pipe_Unfreeze();\r
+       \r
+       ErrorCode = Pipe_Read_Stream_LE(PIMAHeader, sizeof(SI_PIMA_Container_t), NO_STREAM_CALLBACK);\r
+       \r
+       Pipe_ClearIN();\r
+       Pipe_Freeze();\r
+       \r
+       return ErrorCode;\r
+}\r
+\r
 #endif\r
index d970594..f4d1bb1 100644 (file)
                         */\r
                        uint8_t SI_Host_ConfigurePipes(USB_ClassInfo_SI_Host_t* SIInterfaceInfo, uint16_t ConfigDescriptorLength,\r
                                            uint8_t* DeviceConfigDescriptor) ATTR_NON_NULL_PTR_ARG(1, 3);\r
+\r
+                       void SImage_Host_SendBlockHeader(USB_ClassInfo_SI_Host_t* SIInterfaceInfo, SI_PIMA_Container_t* PIMAHeader);\r
+                       uint8_t SImage_Host_RecieveBlockHeader(USB_ClassInfo_SI_Host_t* SIInterfaceInfo, SI_PIMA_Container_t* PIMAHeader);\r
+                       uint8_t SImage_Host_SendData(USB_ClassInfo_SI_Host_t* SIInterfaceInfo, void* Buffer, uint16_t Bytes);\r
+                       uint8_t SImage_Host_ReadData(USB_ClassInfo_SI_Host_t* SIInterfaceInfo, void* Buffer, uint16_t Bytes);\r
+                       bool SImage_Host_IsEventReceived(USB_ClassInfo_SI_Host_t* SIInterfaceInfo);\r
+                       uint8_t SImage_Host_RecieveEventHeader(USB_ClassInfo_SI_Host_t* SIInterfaceInfo, SI_PIMA_Container_t* PIMAHeader);\r
                                                          \r
        /* Private Interface - For use in library only: */\r
        #if !defined(__DOXYGEN__)\r
index 3280e8e..d62a31c 100644 (file)
@@ -47,6 +47,7 @@
   *  - Fixed Device mode HID Class driver always sending IN packets, even when nothing to report\r
   *  - Fixed Device mode HID Class driver not explicitly initializing the ReportSize parameter to zero before calling callback\r
   *    routine, so that ignored callbacks don't cause incorrect data to be sent\r
+  *  - Fixed StillImageHost not correctly freezing and unfreezing data pipes while waiting for a response block header\r
   *\r
   *\r
   *  \section Sec_ChangeLog090810 Version 090810\r