Hi Martin
The reception of a UDP packet follows the following path:
1. Rx frame reception causes an interrupt which causes the Ethernet task to be scheduled
2. The Ethernet task runs and handles the IP frame, detecting that it is carring UDP and calls the UDP handling subroutine
3. The UDP handler matches the UDP frame to a port and thus the handling listener, which it calls
4. Your listener function operates
5. On return form the listener handling teh Ethernet task checks whether there are further receptions waiting - either it quits of moves to 2 again.
I would expect the delay between 1 and 4 to be in the tens of us range for your processor family - see
http://www.utasker.com/docs/uTasker/uTaskerBenchmarks.PDF showing that a 120MHz K70F120 can receive and echo a 1024 byte UDP payload in less than 100us.
Of course there are possible explanations for slowness, which are as follows:
A) There is a delay between 1 and 2 due to the fact that the processor is performing other task execution and can't yet execute the Ethernet task. The scheduler is co-operative and so if there is a task that runs for a long time it will cause a delay here.
B) Your listener function takes a long time to complete
In both cases, when further receptions arrive they will be queued for the Ethernet task and so it will handle multiple waiting receptions the next time that it can run.
As a simple test I would use the UDP listener to simply signal the frame reception (like toggle an output/LED) but nothing more and (temporarily) remove other tasks that could be slowing the Ethernet scheduling down. You should then be able to prove that essentially the lister can handle each reception individually and with a fast reaction time. Then check how long your listener takes to operate to see whether it is a cause of the slowness. Finally add the other tasks back until you can identify one that is blocking other task scheduling (running for > 10ms for example).
Once identified it is usally quite easy to make an adjustement to optimise the overall behaviour.
Hope you can identify the cause.
Regards
Mark
P.S. Check that your project is using
#define ETHERNET_RELEASE_AFTER_EVERY_FRAME // handle only one Ethernet reception frame at a time and allow other tasks to be scheduled in betweensince this is the preferred method since 2011 (avoids needing to signal each reception frame with a queue entry). Also there is an optional define to limit the number of frames processed in one go by the Ethernet task:
#define ETHERNET_RELEASE_LIMIT 3 // allow a maximum of three reception frames to be handledNeither of they should however cause the behaviour that you are seeing.