Commit 73d9fafc authored by Dean Camera's avatar Dean Camera
Browse files

Added new EEPROM and FLASH buffer versions of the Endpoint and Pipe stream...

Added new EEPROM and FLASH buffer versions of the Endpoint and Pipe stream functions. Changed Endpoint.c and Pipe.c to use a templated system to build the seperate functions, rather than duplicating each function's code many times.
parent 1d26e782
......@@ -131,7 +131,7 @@ void EVENT_USB_UnhandledControlPacket(void)
Endpoint_ClearSETUP();
Endpoint_Write_Control_Stream_LE(DescriptorPointer, DescriptorSize);
Endpoint_Write_Control_PStream_LE(DescriptorPointer, DescriptorSize);
Endpoint_ClearOUT();
}
......
......@@ -50,6 +50,54 @@ CDC_Line_Coding_t LineCoding = { .BaudRateBPS = 9600,
.ParityType = Parity_None,
.DataBits = 8 };
#if 0
/* NOTE: Here you can set up a standard stream using the created virtual serial port, so that the standard stream functions in
* <stdio.h> can be used on the virtual serial port (e.g. fprintf(&USBSerial, "Test"); to print a string).
*/
static int CDC_putchar (char c, FILE *stream)
{
if (!(USB_IsConnected))
return -1;
Endpoint_SelectEndpoint(CDC_TX_EPNUM);
while (!(Endpoint_IsReadWriteAllowed()));
Endpoint_Write_Byte(c);
Endpoint_ClearIN();
return 0;
}
static int CDC_getchar (FILE *stream)
{
int c;
Endpoint_SelectEndpoint(CDC_RX_EPNUM);
for (;;)
{
if (!(USB_IsConnected))
return -1;
while (!(Endpoint_IsReadWriteAllowed()));
if (!(Endpoint_BytesInEndpoint()))
{
Endpoint_ClearOUT();
}
else
{
c = Endpoint_Read_Byte();
break;
}
}
return c;
}
static FILE USBSerial = FDEV_SETUP_STREAM(CDC_putchar, CDC_getchar, _FDEV_SETUP_RW);
#endif
/** Main program entry point. This routine contains the overall program flow, including initial
* setup of all components and the main program loop.
*/
......@@ -208,8 +256,8 @@ void CDC_Task(void)
#if 0
/* NOTE: Here you can use the notification endpoint to send back line state changes to the host, for the special RS-232
handshake signal lines (and some error states), via the CONTROL_LINE_IN_* masks and the following code:
*/
* handshake signal lines (and some error states), via the CONTROL_LINE_IN_* masks and the following code:
*/
USB_Notification_Header_t Notification = (USB_Notification_Header_t)
{
.NotificationType = (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE),
......
......@@ -112,7 +112,7 @@ void ProcessRNDISControlMessage(void)
ResponseReady = true;
RNDIS_Initialize_Message_t* INITIALIZE_Message = (RNDIS_Initialize_Message_t*)&RNDISMessageBuffer;
RNDIS_Initialize_Message_t* INITIALIZE_Message = (RNDIS_Initialize_Message_t*)&RNDISMessageBuffer;
RNDIS_Initialize_Complete_t* INITIALIZE_Response = (RNDIS_Initialize_Complete_t*)&RNDISMessageBuffer;
INITIALIZE_Response->MessageType = REMOTE_NDIS_INITIALIZE_CMPLT;
......
This diff is collapsed.
......@@ -1227,7 +1227,7 @@ PREDEFINED = __DOXYGEN__
# The macro definition that is found in the sources will be used.
# Use the PREDEFINED tag if you want to use a different macro definition.
EXPAND_AS_DEFINED =
EXPAND_AS_DEFINED = _CALLBACK_PARAM
# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then
# doxygen's preprocessor will remove all function-like macros that are alone
......
......@@ -241,47 +241,12 @@ static void USB_Device_GetDescriptor(void)
#if defined(USE_RAM_DESCRIPTORS)
Endpoint_Write_Control_Stream_LE(DescriptorPointer, DescriptorSize);
#elif defined(USE_EEPROM_DESCRIPTORS)
Endpoint_Write_Control_EStream_LE(DescriptorPointer, DescriptorSize);
#else
bool SendZLP;
if (USB_ControlRequest.wLength > DescriptorSize)
USB_ControlRequest.wLength = DescriptorSize;
while (USB_ControlRequest.wLength)
{
while (!(Endpoint_IsINReady()))
{
if (Endpoint_IsOUTReceived())
{
Endpoint_ClearOUT();
return;
}
}
while (USB_ControlRequest.wLength && (Endpoint_BytesInEndpoint() < USB_ControlEndpointSize))
{
#if defined (USE_EEPROM_DESCRIPTORS)
Endpoint_Write_Byte(eeprom_read_byte(DescriptorPointer++));
#else
Endpoint_Write_Byte(pgm_read_byte(DescriptorPointer++));
#endif
USB_ControlRequest.wLength--;
}
SendZLP = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize);
Endpoint_ClearIN();
}
if (SendZLP)
{
while (!(Endpoint_IsINReady()));
Endpoint_ClearIN();
}
while (!(Endpoint_IsOUTReceived()));
Endpoint_Write_Control_PStream_LE(DescriptorPointer, DescriptorSize);
#endif
Endpoint_ClearOUT();
}
......
......@@ -183,428 +183,116 @@ uint8_t Endpoint_Discard_Stream(uint16_t Length
return ENDPOINT_RWSTREAM_NoError;
}
uint8_t Endpoint_Write_Stream_LE(const void* Buffer, uint16_t Length
#if !defined(NO_STREAM_CALLBACKS)
, StreamCallbackPtr_t Callback
#endif
)
{
uint8_t* DataStream = (uint8_t*)Buffer;
uint8_t ErrorCode;
if ((ErrorCode = Endpoint_WaitUntilReady()))
return ErrorCode;
#if defined(FAST_STREAM_TRANSFERS)
uint8_t BytesRemToAlignment = (Endpoint_BytesInEndpoint() & 0x07);
if (Length >= 8)
{
Length -= BytesRemToAlignment;
switch (BytesRemToAlignment)
{
default:
do
{
if (!(Endpoint_IsReadWriteAllowed()))
{
Endpoint_ClearIN();
#if !defined(NO_STREAM_CALLBACKS)
if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))
return ENDPOINT_RWSTREAM_CallbackAborted;
#endif
if ((ErrorCode = Endpoint_WaitUntilReady()))
return ErrorCode;
}
Length -= 8;
Endpoint_Write_Byte(*(DataStream++));
case 7: Endpoint_Write_Byte(*(DataStream++));
case 6: Endpoint_Write_Byte(*(DataStream++));
case 5: Endpoint_Write_Byte(*(DataStream++));
case 4: Endpoint_Write_Byte(*(DataStream++));
case 3: Endpoint_Write_Byte(*(DataStream++));
case 2: Endpoint_Write_Byte(*(DataStream++));
case 1: Endpoint_Write_Byte(*(DataStream++));
} while (Length >= 8);
}
}
#endif
#define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_LE
#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
#define TEMPLATE_BUFFER_OFFSET(Length) 0
#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(*(BufferPtr++))
#include "Template/Template_Endpoint_RW.c"
#define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_LE
#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
#define TEMPLATE_BUFFER_OFFSET(Length) 0
#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(pgm_read_byte(BufferPtr++))
#include "Template/Template_Endpoint_RW.c"
#define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_LE
#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
#define TEMPLATE_BUFFER_OFFSET(Length) 0
#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(eeprom_read_byte(BufferPtr++))
#include "Template/Template_Endpoint_RW.c"
#define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_BE
#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
#define TEMPLATE_BUFFER_OFFSET(Length) Length - 1
#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(*(BufferPtr--))
#include "Template/Template_Endpoint_RW.c"
#define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_BE
#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
#define TEMPLATE_BUFFER_OFFSET(Length) Length - 1
#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(eeprom_read_byte(BufferPtr--))
#include "Template/Template_Endpoint_RW.c"
#define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_BE
#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN()
#define TEMPLATE_BUFFER_OFFSET(Length) Length - 1
#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(pgm_read_byte(BufferPtr--))
#include "Template/Template_Endpoint_RW.c"
#define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_LE
#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
#define TEMPLATE_BUFFER_OFFSET(Length) 0
#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *(BufferPtr++) = Endpoint_Read_Byte()
#include "Template/Template_Endpoint_RW.c"
#define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_LE
#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
#define TEMPLATE_BUFFER_OFFSET(Length) 0
#define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_write_byte(BufferPtr++, Endpoint_Read_Byte())
#include "Template/Template_Endpoint_RW.c"
#define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_BE
#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
#define TEMPLATE_BUFFER_OFFSET(Length) Length - 1
#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *(BufferPtr--) = Endpoint_Read_Byte()
#include "Template/Template_Endpoint_RW.c"
#define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_BE
#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT()
#define TEMPLATE_BUFFER_OFFSET(Length) Length - 1
#define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_write_byte(BufferPtr--, Endpoint_Read_Byte())
#include "Template/Template_Endpoint_RW.c"
while (Length)
{
if (!(Endpoint_IsReadWriteAllowed()))
{
Endpoint_ClearIN();
#if !defined(NO_STREAM_CALLBACKS)
if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))
return ENDPOINT_RWSTREAM_CallbackAborted;
#endif
if ((ErrorCode = Endpoint_WaitUntilReady()))
return ErrorCode;
}
else
{
Endpoint_Write_Byte(*(DataStream++));
Length--;
}
}
return ENDPOINT_RWSTREAM_NoError;
}
uint8_t Endpoint_Write_Stream_BE(const void* Buffer, uint16_t Length
#if !defined(NO_STREAM_CALLBACKS)
, StreamCallbackPtr_t Callback
#endif
)
{
uint8_t* DataStream = (uint8_t*)(Buffer + Length - 1);
uint8_t ErrorCode;
if ((ErrorCode = Endpoint_WaitUntilReady()))
return ErrorCode;
#if defined(FAST_STREAM_TRANSFERS)
uint8_t BytesRemToAlignment = (Endpoint_BytesInEndpoint() & 0x07);
if (Length >= 8)
{
Length -= BytesRemToAlignment;
switch (BytesRemToAlignment)
{
default:
do
{
if (!(Endpoint_IsReadWriteAllowed()))
{
Endpoint_ClearIN();
#if !defined(NO_STREAM_CALLBACKS)
if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))
return ENDPOINT_RWSTREAM_CallbackAborted;
#endif
if ((ErrorCode = Endpoint_WaitUntilReady()))
return ErrorCode;
}
Length -= 8;
Endpoint_Write_Byte(*(DataStream--));
case 7: Endpoint_Write_Byte(*(DataStream--));
case 6: Endpoint_Write_Byte(*(DataStream--));
case 5: Endpoint_Write_Byte(*(DataStream--));
case 4: Endpoint_Write_Byte(*(DataStream--));
case 3: Endpoint_Write_Byte(*(DataStream--));
case 2: Endpoint_Write_Byte(*(DataStream--));
case 1: Endpoint_Write_Byte(*(DataStream--));
} while (Length >= 8);
}
}
#endif
while (Length)
{
if (!(Endpoint_IsReadWriteAllowed()))
{
Endpoint_ClearIN();
#if !defined(NO_STREAM_CALLBACKS)
if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))
return ENDPOINT_RWSTREAM_CallbackAborted;
#endif
if ((ErrorCode = Endpoint_WaitUntilReady()))
return ErrorCode;
}
else
{
Endpoint_Write_Byte(*(DataStream--));
Length--;
}
}
return ENDPOINT_RWSTREAM_NoError;
}
uint8_t Endpoint_Read_Stream_LE(void* Buffer, uint16_t Length
#if !defined(NO_STREAM_CALLBACKS)
, StreamCallbackPtr_t Callback
#endif
)
{
uint8_t* DataStream = (uint8_t*)Buffer;
uint8_t ErrorCode;
if ((ErrorCode = Endpoint_WaitUntilReady()))
return ErrorCode;
#if defined(FAST_STREAM_TRANSFERS)
uint8_t BytesRemToAlignment = (Endpoint_BytesInEndpoint() & 0x07);
if (Length >= 8)
{
Length -= BytesRemToAlignment;
switch (BytesRemToAlignment)
{
default:
do
{
if (!(Endpoint_IsReadWriteAllowed()))
{
Endpoint_ClearOUT();
#if !defined(NO_STREAM_CALLBACKS)
if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))
return ENDPOINT_RWSTREAM_CallbackAborted;
#endif
if ((ErrorCode = Endpoint_WaitUntilReady()))
return ErrorCode;
}
Length -= 8;
*(DataStream++) = Endpoint_Read_Byte();
case 7: *(DataStream++) = Endpoint_Read_Byte();
case 6: *(DataStream++) = Endpoint_Read_Byte();
case 5: *(DataStream++) = Endpoint_Read_Byte();
case 4: *(DataStream++) = Endpoint_Read_Byte();
case 3: *(DataStream++) = Endpoint_Read_Byte();
case 2: *(DataStream++) = Endpoint_Read_Byte();
case 1: *(DataStream++) = Endpoint_Read_Byte();
} while (Length >= 8);
}
}
#endif
while (Length)
{
if (!(Endpoint_IsReadWriteAllowed()))
{
Endpoint_ClearOUT();
#if !defined(NO_STREAM_CALLBACKS)
if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))
return ENDPOINT_RWSTREAM_CallbackAborted;
#endif
if ((ErrorCode = Endpoint_WaitUntilReady()))
return ErrorCode;
}
else
{
*(DataStream++) = Endpoint_Read_Byte();
Length--;
}
}
return ENDPOINT_RWSTREAM_NoError;
}
uint8_t Endpoint_Read_Stream_BE(void* Buffer, uint16_t Length
#if !defined(NO_STREAM_CALLBACKS)
, StreamCallbackPtr_t Callback
#endif
)
{
uint8_t* DataStream = (uint8_t*)(Buffer + Length - 1);
uint8_t ErrorCode;
if ((ErrorCode = Endpoint_WaitUntilReady()))
return ErrorCode;
#if defined(FAST_STREAM_TRANSFERS)
uint8_t BytesRemToAlignment = (Endpoint_BytesInEndpoint() & 0x07);
if (Length >= 8)
{
Length -= BytesRemToAlignment;
switch (BytesRemToAlignment)
{
default:
do
{
if (!(Endpoint_IsReadWriteAllowed()))
{
Endpoint_ClearOUT();
#if !defined(NO_STREAM_CALLBACKS)
if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))
return ENDPOINT_RWSTREAM_CallbackAborted;
#endif
if ((ErrorCode = Endpoint_WaitUntilReady()))
return ErrorCode;
}
Length -= 8;
*(DataStream--) = Endpoint_Read_Byte();
case 7: *(DataStream--) = Endpoint_Read_Byte();
case 6: *(DataStream--) = Endpoint_Read_Byte();
case 5: *(DataStream--) = Endpoint_Read_Byte();
case 4: *(DataStream--) = Endpoint_Read_Byte();
case 3: *(DataStream--) = Endpoint_Read_Byte();
case 2: *(DataStream--) = Endpoint_Read_Byte();
case 1: *(DataStream--) = Endpoint_Read_Byte();
} while (Length >= 8);
}
}
#endif
while (Length)
{
if (!(Endpoint_IsReadWriteAllowed()))
{
Endpoint_ClearOUT();
#if !defined(NO_STREAM_CALLBACKS)
if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))
return ENDPOINT_RWSTREAM_CallbackAborted;
#endif
if ((ErrorCode = Endpoint_WaitUntilReady()))
return ErrorCode;
}
else
{
*(DataStream--) = Endpoint_Read_Byte();
Length--;
}
}
return ENDPOINT_RWSTREAM_NoError;
}
#endif
uint8_t Endpoint_Write_Control_Stream_LE(const void* Buffer, uint16_t Length)
{
uint8_t* DataStream = (uint8_t*)Buffer;
bool LastPacketFull = false;
if (Length > USB_ControlRequest.wLength)
Length = USB_ControlRequest.wLength;
while (Length && !(Endpoint_IsOUTReceived()))
{
while (!(Endpoint_IsINReady()));
while (Length && (Endpoint_BytesInEndpoint() < USB_ControlEndpointSize))
{
Endpoint_Write_Byte(*(DataStream++));
Length--;
}
LastPacketFull = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize);
Endpoint_ClearIN();
}
if (Endpoint_IsOUTReceived())
return ENDPOINT_RWCSTREAM_HostAborted;
if (LastPacketFull)
{
while (!(Endpoint_IsINReady()));
Endpoint_ClearIN();
}
while (!(Endpoint_IsOUTReceived()));
return ENDPOINT_RWCSTREAM_NoError;
}
uint8_t Endpoint_Write_Control_Stream_BE(const void* Buffer, uint16_t Length)
{
uint8_t* DataStream = (uint8_t*)(Buffer + Length - 1);
bool LastPacketFull = false;
if (Length > USB_ControlRequest.wLength)
Length = USB_ControlRequest.wLength;
while (Length && !(Endpoint_IsOUTReceived()))
{
if (Endpoint_IsINReady())
{
while (Length && (Endpoint_BytesInEndpoint() < USB_ControlEndpointSize))
{
Endpoint_Write_Byte(*(DataStream--));
Length--;
}
LastPacketFull = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize);
Endpoint_ClearIN();
}
}
if (Endpoint_IsOUTReceived())
return ENDPOINT_RWCSTREAM_HostAborted;
if (LastPacketFull)
{
while (!(Endpoint_IsINReady()));
Endpoint_ClearIN();
}
while (!(Endpoint_IsOUTReceived()));
return ENDPOINT_RWCSTREAM_NoError;
}
uint8_t Endpoint_Read_Control_Stream_LE(void* Buffer, uint16_t Length)
{
uint8_t* DataStream = (uint8_t*)Buffer;
while (Length)
{
if (Endpoint_IsOUTReceived())
{
while (Length && Endpoint_BytesInEndpoint())
{
*(DataStream++) = Endpoint_Read_Byte();
Length--;
}
Endpoint_ClearOUT();
}
}
while (!(Endpoint_IsINReady()));
return ENDPOINT_RWCSTREAM_NoError;
}
uint8_t Endpoint_Read_Control_Stream_BE(void* Buffer, uint16_t Length)
{
uint8_t* DataStream = (uint8_t*)(Buffer + Length - 1);
while (Length)