Search code examples
qtudparduinointerruptethernet

Is UDP interrupts-proof?


One quick question: do interrupts on say, an Arduino, interfere in any way with sending and receiving datagrams via UDP? Or does the data "wait" in some kind of buffer?

If it is useful for the answer, I'm using the UDP library on Arduino Mega with Ethernet shield and QUdpSocket of Qt on a Lenovo X201, through a TP-LINK WR702N Nano.

Thanks, Mister Mystère


Solution

  • The Arduino Ethernet shield is based on the Wiznet W5100 chip which contains a 16k buffer used for Rx and Tx buffers data sheet. The chip implements the protocol stack, which means that packets are received and transmitted independent of the Arduino main board chip. For any practical amount of data transport, interrupts or tasks on the main chip will not interfere with the network stack. If you are transporting data on scale of 16k and not able to keep up, then you could start to loose data.

    The Arduino wifi shields actually contain an microcontroller "bigger" than the Arduino itself, and that also would buffer the ethernet traffic. Part of the reason the ethernet chips cost as much as an Arduino is that they are carrying much of the work load.

    Thinking about the question "what do the interrupts interrupt?" is a good question. You can be ensured that everything in the loop() will be interrupted at any point, or better to think at every possible point. The interrupts do not occur at the C++ code level, but at the machine code level. In the middle of any line of C++ code you should expect that an interrupt will occur. So interrupt handlers that share variables with the loop() code need some careful consideration. For example if your loop() contains

    y = 3 + 4*x * 5 * x*x;
    

    and an interrupt handler modifies the global variable x, the value of y can end up with some impossible values. If you have operations in your loop() that you want protected from interrupts, you have the ability to disable interrupts

    see noInterupts()