Fixed StillImageHost not correctly freezing and unfreezing data pipes while waiting for a response block header.

Added basic PIMA commands to the StillImage Host Class driver - need to extend to PIMA specific command functions.
pull/1469/head
Dean Camera 15 years ago
parent bda4bd4501
commit 5908e28e8d

@ -127,7 +127,9 @@ uint8_t SImage_RecieveBlockHeader(void)
}
}
Pipe_Freeze();
Pipe_SelectPipe(SIMAGE_DATA_OUT_PIPE);
Pipe_Unfreeze();
/* Check if pipe stalled (command failed by device) */
if (Pipe_IsStalled())
@ -139,7 +141,9 @@ uint8_t SImage_RecieveBlockHeader(void)
return PIPE_RWSTREAM_PipeStalled;
}
Pipe_Freeze();
Pipe_SelectPipe(SIMAGE_DATA_IN_PIPE);
Pipe_Unfreeze();
/* Check if pipe stalled (command failed by device) */
if (Pipe_IsStalled())
@ -156,13 +160,6 @@ uint8_t SImage_RecieveBlockHeader(void)
return PIPE_RWSTREAM_DeviceDisconnected;
}
/* Freeze OUT pipe after use */
Pipe_SelectPipe(SIMAGE_DATA_OUT_PIPE);
Pipe_Freeze();
/* Select the IN data pipe for data reception */
Pipe_SelectPipe(SIMAGE_DATA_IN_PIPE);
/* Load in the response from the attached device */
Pipe_Read_Stream_LE(&PIMA_ReceivedBlock, PIMA_COMMAND_SIZE(0));

@ -66,15 +66,15 @@
*
* \param[in] params Number of parameters which are to be sent in the Param field of the container
*/
#define PIMA_COMMAND_SIZE(params) ((sizeof(PIMA_SendBlock) - sizeof(PIMA_SendBlock.Params)) + \
(params * sizeof(PIMA_SendBlock.Params[0])))
#define PIMA_COMMAND_SIZE(params) ((sizeof(SI_PIMA_Container_t) - sizeof(((SI_PIMA_Container_t*)NULL)->Params)) + \
(params * sizeof(((SI_PIMA_Container_t*)NULL)->Params[0])))
/** Used in the DataLength field of a PIMA container, to give the total container size in bytes for
* a data container.
*
* \param[in] datalen Length in bytes of the data in the container
*/
#define PIMA_DATA_SIZE(datalen) ((sizeof(PIMA_SendBlock) - sizeof(PIMA_SendBlock.Params)) + datalen)
#define PIMA_DATA_SIZE(datalen) ((sizeof(SI_PIMA_Container_t) - sizeof(((SI_PIMA_Container_t*)NULL)->Params)) + datalen)
/* Type defines: */
/** Type define for a PIMA container, use to send commands and receive responses to and from an
@ -101,7 +101,15 @@
};
/* Enums: */
enum SI_PIMA_ResponseCodes_t
{
PIMA_RESPONSE_OK = 1,
PIMA_RESPONSE_GeneralError = 2,
PIMA_RESPONSE_SessionNotOpen = 3,
PIMA_RESPONSE_InvalidTransaction = 4,
PIMA_RESPONSE_OperationNotSupported = 5,
PIMA_RESPONSE_ParameterNotSupported = 6,
};
/* Type Defines: */

@ -95,9 +95,12 @@ static uint8_t DComp_NextMSInterface(void* CurrentDescriptor)
{
if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface)
{
if ((DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).Class == MASS_STORE_CLASS) &&
(DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).SubClass == MASS_STORE_SUBCLASS) &&
(DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).Protocol == MASS_STORE_PROTOCOL))
USB_Descriptor_Interface_t* CurrentInterface = DESCRIPTOR_PCAST(CurrentDescriptor,
USB_Descriptor_Interface_t);
if ((CurrentInterface->Class == MASS_STORE_CLASS) &&
(CurrentInterface->SubClass == MASS_STORE_SUBCLASS) &&
(CurrentInterface->Protocol == MASS_STORE_PROTOCOL))
{
return DESCRIPTOR_SEARCH_Found;
}

@ -106,9 +106,12 @@ uint8_t DComp_SI_Host_NextSIInterface(void* CurrentDescriptor)
{
if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface)
{
if ((DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).Class == STILL_IMAGE_CLASS) &&
(DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).SubClass == STILL_IMAGE_SUBCLASS) &&
(DESCRIPTOR_CAST(CurrentDescriptor, USB_Descriptor_Interface_t).Protocol == STILL_IMAGE_PROTOCOL))
USB_Descriptor_Interface_t* CurrentInterface = DESCRIPTOR_PCAST(CurrentDescriptor,
USB_Descriptor_Interface_t);
if ((CurrentInterface->Class == STILL_IMAGE_CLASS) &&
(CurrentInterface->SubClass == STILL_IMAGE_SUBCLASS) &&
(CurrentInterface->Protocol == STILL_IMAGE_PROTOCOL))
{
return DESCRIPTOR_SEARCH_Found;
}
@ -145,4 +148,144 @@ void SI_Host_USBTask(USB_ClassInfo_SI_Host_t* SIInterfaceInfo)
}
void SImage_Host_SendBlockHeader(USB_ClassInfo_SI_Host_t* SIInterfaceInfo, SI_PIMA_Container_t* PIMAHeader)
{
Pipe_SelectPipe(SIInterfaceInfo->Config.DataOUTPipeNumber);
Pipe_Unfreeze();
Pipe_Write_Stream_LE(PIMAHeader, PIMA_COMMAND_SIZE(0), NO_STREAM_CALLBACK);
if (PIMAHeader->Type == CType_CommandBlock)
{
uint8_t ParamBytes = (PIMAHeader->DataLength - PIMA_COMMAND_SIZE(0));
if (ParamBytes)
Pipe_Write_Stream_LE(&PIMAHeader->Params, ParamBytes, NO_STREAM_CALLBACK);
Pipe_ClearOUT();
}
Pipe_Freeze();
}
uint8_t SImage_Host_RecieveBlockHeader(USB_ClassInfo_SI_Host_t* SIInterfaceInfo, SI_PIMA_Container_t* PIMAHeader)
{
uint16_t TimeoutMSRem = COMMAND_DATA_TIMEOUT_MS;
Pipe_SelectPipe(SIInterfaceInfo->Config.DataINPipeNumber);
Pipe_Unfreeze();
while (!(Pipe_IsReadWriteAllowed()))
{
if (USB_INT_HasOccurred(USB_INT_HSOFI))
{
USB_INT_Clear(USB_INT_HSOFI);
TimeoutMSRem--;
if (!(TimeoutMSRem))
{
return PIPE_RWSTREAM_Timeout;
}
}
Pipe_Freeze();
Pipe_SelectPipe(SIInterfaceInfo->Config.DataOUTPipeNumber);
Pipe_Unfreeze();
if (Pipe_IsStalled())
{
USB_Host_ClearPipeStall(SIInterfaceInfo->Config.DataOUTPipeNumber);
return PIPE_RWSTREAM_PipeStalled;
}
Pipe_Freeze();
Pipe_SelectPipe(SIInterfaceInfo->Config.DataINPipeNumber);
Pipe_Unfreeze();
if (Pipe_IsStalled())
{
USB_Host_ClearPipeStall(SIInterfaceInfo->Config.DataINPipeNumber);
return PIPE_RWSTREAM_PipeStalled;
}
if (USB_HostState == HOST_STATE_Unattached)
return PIPE_RWSTREAM_DeviceDisconnected;
}
Pipe_Read_Stream_LE(PIMAHeader, PIMA_COMMAND_SIZE(0), NO_STREAM_CALLBACK);
if (PIMAHeader->Type == CType_ResponseBlock)
{
uint8_t ParamBytes = (PIMAHeader->DataLength - PIMA_COMMAND_SIZE(0));
if (ParamBytes)
Pipe_Read_Stream_LE(&PIMAHeader->Params, ParamBytes, NO_STREAM_CALLBACK);
Pipe_ClearIN();
}
Pipe_Freeze();
return PIPE_RWSTREAM_NoError;
}
uint8_t SImage_Host_SendData(USB_ClassInfo_SI_Host_t* SIInterfaceInfo, void* Buffer, uint16_t Bytes)
{
uint8_t ErrorCode;
Pipe_SelectPipe(SIInterfaceInfo->Config.DataOUTPipeNumber);
Pipe_Unfreeze();
ErrorCode = Pipe_Write_Stream_LE(Buffer, Bytes, NO_STREAM_CALLBACK);
Pipe_ClearOUT();
Pipe_Freeze();
return ErrorCode;
}
uint8_t SImage_Host_ReadData(USB_ClassInfo_SI_Host_t* SIInterfaceInfo, void* Buffer, uint16_t Bytes)
{
uint8_t ErrorCode;
Pipe_SelectPipe(SIInterfaceInfo->Config.DataINPipeNumber);
Pipe_Unfreeze();
ErrorCode = Pipe_Read_Stream_LE(Buffer, Bytes, NO_STREAM_CALLBACK);
Pipe_Freeze();
return ErrorCode;
}
bool SImage_Host_IsEventReceived(USB_ClassInfo_SI_Host_t* SIInterfaceInfo)
{
bool IsEventReceived = false;
Pipe_SelectPipe(SIInterfaceInfo->Config.EventsPipeNumber);
Pipe_Unfreeze();
if (Pipe_BytesInPipe())
IsEventReceived = true;
Pipe_Freeze();
return IsEventReceived;
}
uint8_t SImage_Host_RecieveEventHeader(USB_ClassInfo_SI_Host_t* SIInterfaceInfo, SI_PIMA_Container_t* PIMAHeader)
{
uint8_t ErrorCode;
Pipe_SelectPipe(SIInterfaceInfo->Config.EventsPipeNumber);
Pipe_Unfreeze();
ErrorCode = Pipe_Read_Stream_LE(PIMAHeader, sizeof(SI_PIMA_Container_t), NO_STREAM_CALLBACK);
Pipe_ClearIN();
Pipe_Freeze();
return ErrorCode;
}
#endif

@ -120,6 +120,13 @@
uint8_t SI_Host_ConfigurePipes(USB_ClassInfo_SI_Host_t* SIInterfaceInfo, uint16_t ConfigDescriptorLength,
uint8_t* DeviceConfigDescriptor) ATTR_NON_NULL_PTR_ARG(1, 3);
void SImage_Host_SendBlockHeader(USB_ClassInfo_SI_Host_t* SIInterfaceInfo, SI_PIMA_Container_t* PIMAHeader);
uint8_t SImage_Host_RecieveBlockHeader(USB_ClassInfo_SI_Host_t* SIInterfaceInfo, SI_PIMA_Container_t* PIMAHeader);
uint8_t SImage_Host_SendData(USB_ClassInfo_SI_Host_t* SIInterfaceInfo, void* Buffer, uint16_t Bytes);
uint8_t SImage_Host_ReadData(USB_ClassInfo_SI_Host_t* SIInterfaceInfo, void* Buffer, uint16_t Bytes);
bool SImage_Host_IsEventReceived(USB_ClassInfo_SI_Host_t* SIInterfaceInfo);
uint8_t SImage_Host_RecieveEventHeader(USB_ClassInfo_SI_Host_t* SIInterfaceInfo, SI_PIMA_Container_t* PIMAHeader);
/* Private Interface - For use in library only: */
#if !defined(__DOXYGEN__)
/* Macros: */

@ -47,6 +47,7 @@
* - Fixed Device mode HID Class driver always sending IN packets, even when nothing to report
* - Fixed Device mode HID Class driver not explicitly initializing the ReportSize parameter to zero before calling callback
* routine, so that ignored callbacks don't cause incorrect data to be sent
* - Fixed StillImageHost not correctly freezing and unfreezing data pipes while waiting for a response block header
*
*
* \section Sec_ChangeLog090810 Version 090810

Loading…
Cancel
Save