Code: Select all
void EthernetTxThread(void*) {
chRegSetThreadName("ethtx");
systime_t prev = chVTGetSystemTime();
while(1) {
chSysLock();
chThdSuspendS(&trp);
chSysUnlock();
sendResponse();
}
}
void EthernetRxThread(void*) {
chRegSetThreadName("ethrx");
systime_t prev = chVTGetSystemTime();
while(1) {
if (parseMessage() != -1)
chThdResume(&trp, MSG_OK);
}
}
Inside parseMessage() is a blocking recvfrom() :
Code: Select all
int len = recvfrom(sock, recv_buf, sizeof(recv_buf), 0, (struct sockaddr*) ð_rx_addr, (socklen_t *)sizeof(eth_rx_addr));
Wireshark shows the PC is sending out packets at 10Hz as expected, and around 30% of the time the microcontroller responds in-time. However i see that sometimes it takes up to 1 second to respond. By capturing timestamps I saw that the delay is actually in the rx thread. recvfrom() is blocking for much longer than 100ms. I went a little lower and found that
Code: Select all
sys_arch_mbox_fetch(&conn->recvmbox, &buf, 0);
Are there LWIP options needed to improve the UDP rx performance?