In the UdpReaderTask, upkt(&fifo, 0 * TICKS_PER_SECOND), it holding time 25ms,
J2[8] = 1; //just for test holding time
UDPPacket upkt(&fifo, 0 * TICKS_PER_SECOND); // it holding time 25ms,
J2[8] = 0;
this code have taken so much of MCU time
how to reduce the time for UDP packet receiving process
-
- Posts: 6
- Joined: Sun Aug 05, 2012 8:27 pm
- Location: tianjin China
Re: how to reduce the time for UDP packet receiving process
A couple of things:
1. 0*TICKS_PER_SECOND == 0 and typically passing a wait time of 0 means wait forever (until a response is received in this case) The actual call is to OSFifoPend. The NB docs don't specifically state for this call if 0 means wait for a response but that is usually the case in my experience. (There is an OS call OSFifoPendNoWait but I think you would have to rewrite this method to use it).
2. A wait of 1 tick would be the shortest. You can shorten it by changing the definition of TICKS_PER_SECOND and rebuilding the system. See the FAQ for more info.
3. A wait of 1 tick, is in my experience, non-deterministic. The actual wait time will be anywhere from almost nothing to one full tick depending on how far into the tick you are when the call is made.
4. AND MOST IMPORTANTLY TO ME - Since you have this instrumented could you comment out the call to the UDPPackt constructor and tell me how long the time is between raising and lowering J2[8]. It's germane to a recent discussion about the performance of the PinIO class.
1. 0*TICKS_PER_SECOND == 0 and typically passing a wait time of 0 means wait forever (until a response is received in this case) The actual call is to OSFifoPend. The NB docs don't specifically state for this call if 0 means wait for a response but that is usually the case in my experience. (There is an OS call OSFifoPendNoWait but I think you would have to rewrite this method to use it).
2. A wait of 1 tick would be the shortest. You can shorten it by changing the definition of TICKS_PER_SECOND and rebuilding the system. See the FAQ for more info.
3. A wait of 1 tick, is in my experience, non-deterministic. The actual wait time will be anywhere from almost nothing to one full tick depending on how far into the tick you are when the call is made.
4. AND MOST IMPORTANTLY TO ME - Since you have this instrumented could you comment out the call to the UDPPackt constructor and tell me how long the time is between raising and lowering J2[8]. It's germane to a recent discussion about the performance of the PinIO class.
Re: how to reduce the time for UDP packet receiving process
The code as written will wait until there is a UDP packet....
Unless yo are cetain that there are multiple UDP packets already queued up on the fifo your measuring network latency.....
If you want to not wait at all unless there is an availible UDP packet then...
OS_FIFO_EL * potential_udp_packet =OSFifoPendNoWait( &fifo);
if(potential_udp_packet!=NULL)
{
UDPPacket ThePacket( (PoolPtr) potential_udp_packet );
//One should always include ...
if(ThePacket.Validate())
{ //process the packet...
}
}
Otherwise a wait time of 0 is forever...
Unless yo are cetain that there are multiple UDP packets already queued up on the fifo your measuring network latency.....
If you want to not wait at all unless there is an availible UDP packet then...
OS_FIFO_EL * potential_udp_packet =OSFifoPendNoWait( &fifo);
if(potential_udp_packet!=NULL)
{
UDPPacket ThePacket( (PoolPtr) potential_udp_packet );
//One should always include ...
if(ThePacket.Validate())
{ //process the packet...
}
}
Otherwise a wait time of 0 is forever...