Add new RNDIS_Host_IsPacketReceived(), RNDIS_Device_ReadPacket() and RNDIS_Device_WritePacket() functions to the Device RNDIS Class Driver.

Modify RNDIS demos to suit the simplified Ethernet_Frame_Info_t structure.
This commit is contained in:
Dean Camera 2011-05-18 14:33:34 +00:00
parent 41de1d1dab
commit 9d733d44b4
15 changed files with 173 additions and 96 deletions

View file

@ -96,7 +96,6 @@ void Ethernet_ProcessPacket(Ethernet_Frame_Info_t* const FrameIN,
/* Set the response length in the buffer and indicate that a response is ready to be sent */
FrameOUT->FrameLength = (sizeof(Ethernet_Frame_Header_t) + RetSize);
FrameOUT->FrameInBuffer = true;
}
}
@ -104,7 +103,7 @@ void Ethernet_ProcessPacket(Ethernet_Frame_Info_t* const FrameIN,
if (RetSize != NO_PROCESS)
{
/* Clear the frame buffer */
FrameIN->FrameInBuffer = false;
FrameIN->FrameLength = 0;
}
}

View file

@ -55,7 +55,8 @@ TCP_ConnectionState_t ConnectionStateTable[MAX_TCP_CONNECTIONS];
* level. If an application produces a response, this task constructs the appropriate Ethernet frame and places it into the Ethernet OUT
* buffer for later transmission.
*/
void TCP_TCPTask(USB_ClassInfo_RNDIS_Device_t* const RNDISInterfaceInfo)
void TCP_TCPTask(USB_ClassInfo_RNDIS_Device_t* const RNDISInterfaceInfo,
Ethernet_Frame_Info_t* const FrameOUT)
{
/* Run each application in sequence, to process incoming and generate outgoing packets */
for (uint8_t CSTableEntry = 0; CSTableEntry < MAX_TCP_CONNECTIONS; CSTableEntry++)
@ -73,11 +74,8 @@ void TCP_TCPTask(USB_ClassInfo_RNDIS_Device_t* const RNDISInterfaceInfo)
}
}
/* Get pointer to the output frame info struct for convenience */
Ethernet_Frame_Info_t* FrameOUT = &RNDISInterfaceInfo->State.FrameOUT;
/* Bail out early if there is already a frame waiting to be sent in the Ethernet OUT buffer */
if (FrameOUT->FrameInBuffer)
if (FrameOUT->FrameLength)
return;
/* Send response packets from each application as the TCP packet buffers are filled by the applications */
@ -147,7 +145,6 @@ void TCP_TCPTask(USB_ClassInfo_RNDIS_Device_t* const RNDISInterfaceInfo)
/* Set the response length in the buffer and indicate that a response is ready to be sent */
FrameOUT->FrameLength = PacketSize;
FrameOUT->FrameInBuffer = true;
ConnectionStateTable[CSTableEntry].Info.Buffer.Ready = false;

View file

@ -228,7 +228,8 @@
} TCP_Header_t;
/* Function Prototypes: */
void TCP_TCPTask(USB_ClassInfo_RNDIS_Device_t* const RNDISInterfaceInfo);
void TCP_TCPTask(USB_ClassInfo_RNDIS_Device_t* const RNDISInterfaceInfo,
Ethernet_Frame_Info_t* const FrameOUT);
void TCP_Init(void);
bool TCP_SetPortState(const uint16_t Port,
const uint8_t State,

View file

@ -63,6 +63,8 @@ USB_ClassInfo_RNDIS_Device_t Ethernet_RNDIS_Interface =
},
};
static Ethernet_Frame_Info_t FrameIN;
static Ethernet_Frame_Info_t FrameOUT;
/** Main program entry point. This routine contains the overall program flow, including initial
* setup of all components and the main program loop.
@ -79,14 +81,23 @@ int main(void)
for (;;)
{
if (Ethernet_RNDIS_Interface.State.FrameIN.FrameInBuffer)
if (RNDIS_Device_IsPacketReceived(&Ethernet_RNDIS_Interface))
{
LEDs_SetAllLEDs(LEDMASK_USB_BUSY);
Ethernet_ProcessPacket(&Ethernet_RNDIS_Interface.State.FrameIN, &Ethernet_RNDIS_Interface.State.FrameOUT);
RNDIS_Device_ReadPacket(&Ethernet_RNDIS_Interface, &FrameIN.FrameData, &FrameIN.FrameLength);
Ethernet_ProcessPacket(&FrameIN, &FrameOUT);
if (FrameOUT.FrameLength)
{
RNDIS_Device_SendPacket(&Ethernet_RNDIS_Interface, &FrameOUT.FrameData, FrameOUT.FrameLength);
FrameOUT.FrameLength = 0;
}
LEDs_SetAllLEDs(LEDMASK_USB_READY);
}
TCP_TCPTask(&Ethernet_RNDIS_Interface);
TCP_TCPTask(&Ethernet_RNDIS_Interface, &FrameOUT);
RNDIS_Device_USBTask(&Ethernet_RNDIS_Interface);
USB_USBTask();

View file

@ -100,7 +100,6 @@ void Ethernet_ProcessPacket(void)
/* Set the response length in the buffer and indicate that a response is ready to be sent */
FrameOUT.FrameLength = (sizeof(Ethernet_Frame_Header_t) + RetSize);
FrameOUT.FrameInBuffer = true;
}
}
@ -108,7 +107,7 @@ void Ethernet_ProcessPacket(void)
if (RetSize != NO_PROCESS)
{
/* Clear the frame buffer */
FrameIN.FrameInBuffer = false;
FrameIN.FrameLength = 0;
}
}

View file

@ -74,7 +74,7 @@ void TCP_Task(void)
}
/* Bail out early if there is already a frame waiting to be sent in the Ethernet OUT buffer */
if (FrameOUT.FrameInBuffer)
if (FrameOUT.FrameLength)
return;
/* Send response packets from each application as the TCP packet buffers are filled by the applications */
@ -144,7 +144,6 @@ void TCP_Task(void)
/* Set the response length in the buffer and indicate that a response is ready to be sent */
FrameOUT.FrameLength = PacketSize;
FrameOUT.FrameInBuffer = true;
ConnectionStateTable[CSTableEntry].Info.Buffer.Ready = false;

View file

@ -204,7 +204,7 @@ void RNDIS_Task(void)
Endpoint_SelectEndpoint(CDC_RX_EPNUM);
/* Check if the data OUT endpoint contains data, and that the IN buffer is empty */
if (Endpoint_IsOUTReceived() && !(FrameIN.FrameInBuffer))
if (Endpoint_IsOUTReceived() && !(FrameIN.FrameLength))
{
/* Read in the packet message header */
Endpoint_Read_Stream_LE(&RNDISPacketHeader, sizeof(RNDIS_Packet_Message_t), NULL);
@ -224,16 +224,13 @@ void RNDIS_Task(void)
/* Store the size of the Ethernet frame */
FrameIN.FrameLength = RNDISPacketHeader.DataLength;
/* Indicate Ethernet IN buffer full */
FrameIN.FrameInBuffer = true;
}
/* Select the data IN endpoint */
Endpoint_SelectEndpoint(CDC_TX_EPNUM);
/* Check if the data IN endpoint is ready for more data, and that the IN buffer is full */
if (Endpoint_IsINReady() && FrameOUT.FrameInBuffer)
if (Endpoint_IsINReady() && FrameOUT.FrameLength)
{
/* Clear the packet header with all 0s so that the relevant fields can be filled */
memset(&RNDISPacketHeader, 0, sizeof(RNDIS_Packet_Message_t));
@ -254,7 +251,7 @@ void RNDIS_Task(void)
Endpoint_ClearIN();
/* Indicate Ethernet OUT buffer no longer full */
FrameOUT.FrameInBuffer = false;
FrameOUT.FrameLength = 0;
}
}
}
@ -273,7 +270,7 @@ void Ethernet_Task(void)
return;
/* Check if a frame has been written to the IN frame buffer */
if (FrameIN.FrameInBuffer)
if (FrameIN.FrameLength)
{
/* Indicate packet processing started */
LEDs_SetAllLEDs(LEDMASK_USB_BUSY);