[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lwip-users] Confused - Should I loop on pbufs in my receive callback?
From: |
lauziepi |
Subject: |
[lwip-users] Confused - Should I loop on pbufs in my receive callback? |
Date: |
Mon, 29 Jul 2019 18:37:03 -0700 (MST) |
Hello,
I am seeing very slow response times from my device running lwip after
awhile. I have tried various settings as recommended here and elsewhere, and
the issue does not appear to be linked to an incorrect lwip configuration.
When searching around, I have seen a few people mentioning that the
interrupt can be raised when receiving a packet, but it does not guarantee
that only a single packet has been received (for example, a new packet could
be received before the interrupt is handled).
Below is my receive callback function. I have some custom error handling and
packet parsing / handling, but anyone familiar with lwip should recognize
the lwip function calls. Basically, my packets are supposed to match a
command, and the device running lwip is supposed to send a reply to the
"core" (a computer). Please note that I used example code provided by Xiling
as a starting point, as I am running lwip in a FPGA.
Here are 3 questions I have:
1 - Is it ok to reply to the packet directly in the receive callback? See
/errTcp = Eth_ControlPanel_SendPacket(&packet, tpcb);/ Would it be better to
raise a flag and send the response in my main loop?
2 - Am I supposed to add a loop somewhere in the receive callback to handle
the case where I can receive multiple packets before I can handle the
interrupt? I feel like I have more and more packets waiting in my queues,
and since I only read 1 packet each time I get an interrupt, this is why the
response time gets slower each time. What would be my looping conditions if
so?
3 - Does anything else appear wrong with this receive callback?
Thanks in advance, hopefully someone more experienced can shed some light on
this.
err_t ControlPanel_rcv_callback(void* arg, struct tcp_pcb *tpcb, struct
pbuf* p, err_t err)
{
if (!p) {
tcp_close(tpcb);
tcp_recv(tpcb, NULL);
return ERR_CONN;
}
tcp_recved(tpcb, p->len);
ParsedPacket packet;
bool hasBeenParsed = false;
u32 packetPayLoadSizePacket = p->len;
if((packetPayLoadSizePacket >= BASE_COMMAND_SIZE) &&
(packetPayLoadSizePacket <= (MAX_RX_DATA_RECEIVED_FROM_CORE +
BASE_COMMAND_SIZE)))
{
//xil_printf("Parsing packet received from core \n\r");
parseRxCmdFromCore(p->payload, &packet);
hasBeenParsed = true;
}
if(hasBeenParsed && (packet.packetSize == packetPayLoadSizePacket))
{
//xil_printf("The command from Core is now processed \n\r");
LabPETIICoreCmdProcessing(&packet);
}
else
{
//xil_printf("Error has been detected regarding packet size
\n\r");
packet.type = b_ERROR;
packet.data1 = e_BOARD_CMD_PACKETSIZE;
packet.errorFlag = b_ERROR;
packet.packetSize = BASE_COMMAND_SIZE;
}
pbuf_free(p);
buildResponsePacketForCore(&packet);
err_t errTcp;
errTcp = Eth_ControlPanel_SendPacket(&packet, tpcb);
tcp_close(tpcb);
return errTcp;
}
--
Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [lwip-users] Confused - Should I loop on pbufs in my receive callback?,
lauziepi <=