You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How fast can I expect Udp.parsePacket() to be? In this example code, I am parsing UDP packets and toggling a GPIO pin to see how fast the code runs IRL. The parsing takes 330nS. I expected (based on the clock speeds and the 100MBps interface) the speeds to be orders of magnitude higher... 330ns is around 550 clock cycles. I just want to know if there is something I can do to improve this or that the library is focused on compatibility, not performance. Thanks!
#include <NativeEthernet.h>
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip(192, 168, 1, 177);
unsigned int localPort = 6454; // local port to listen on
// buffers for receiving and sending data
#define UDP_TX_PACKET_MAX_SIZE 1480
unsigned char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; // buffer to hold incoming packet,
char ReplyBuffer[] = "acknowledged"; // a string to send back
// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;
const int PIN_0 = 38;
int packetSize = 0;
void setup() {
// noInterrupts();
teensyMAC(mac);
pinMode(PIN_0, OUTPUT);
Ethernet.begin(mac, ip);
Udp.begin(localPort);
}
void loop() {
while (1) {
digitalToggleFast(PIN_0);
//delayNanoseconds(1);
packetSize = Udp.parsePacket();
if (packetSize) {
Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
}
}
}
/*********************** teensyMAC *********************/
void teensyMAC(uint8_t *mac)
{
for (uint8_t by = 0; by < 2; by++) mac[by] = (HW_OCOTP_MAC1 >> ((1 - by) * 8)) & 0xFF;
for (uint8_t by = 0; by < 4; by++) mac[by + 2] = (HW_OCOTP_MAC0 >> ((3 - by) * 8)) & 0xFF;
}
The text was updated successfully, but these errors were encountered:
How fast can I expect Udp.parsePacket() to be? In this example code, I am parsing UDP packets and toggling a GPIO pin to see how fast the code runs IRL. The parsing takes 330nS. I expected (based on the clock speeds and the 100MBps interface) the speeds to be orders of magnitude higher... 330ns is around 550 clock cycles. I just want to know if there is something I can do to improve this or that the library is focused on compatibility, not performance. Thanks!
The text was updated successfully, but these errors were encountered: