Looking for Very simple UDP send Recieve 52235

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Looking for Very simple UDP send Recieve 52235

2,544 Views
admin
Specialist II
I've been trying to play with a MCF52235 badge board and get a very simple UDP send and recieve scheme working.. been playing with the coldfire_lite code with the nichlite stack.. i'm having alot of trouble following the flow of the code and how to incorporate it into my code to allow for simple udp send and recieve of data packets..
 
If anyone has any advice or possibly sample code to help point me in the correct direction it would be much appreciated..

I did get the coldfirelite webserver running and played with it.. but when i tried to disect the code and understand it and even use the debugger to step thru it i ran into alot of issues trying to follow where the code was going..
 
Thanks for any help..
T.


Message Edited by spiralprophet on 2007-06-04 07:03 PM
Labels (1)
0 Kudos
3 Replies

444 Views
bkatt
Contributor IV
The udp interface is not similar to tcp, so the webserver code is not too helpful.

To send by udp, first get a packet with udp_alloc() specifying your data length and zero for the optlen. This sets the nb_prot pointer correctly but puts junk in nb_len. Replace nb_len with your length, copy your data to nb_prot, and set fhost to the ip address. Now you can call udp_send with the two ports and the packet.

To receive by udp, you must write an upcall function, and install it with udp_open(). When a packet arrives, the upcall function is called by the ip stack with a packet. You get at the data using the nb_prot pointer and nb_len length. The remote host is at fhost. Getting the remote port is tricky; I use:

Code:
struct udp *pup = (struct udp *) (p->nb_prot - sizeof(struct udp));port = pup->ud_srcp;

You should release the packet with udp_free() when you no longer need it (don't keep it very long because there aren't many packets).

Note that the example webserver uses msring, but the distributed copy of msring_add() has the % character (percent for modulus) replaced by & (ampersand) in the first line, which could lead to mysterious bugs.


0 Kudos

444 Views
admin
Specialist II
Thanks for you help.. What about initialization.. I'm going to give it a shot but was wondering if you had any input on the initialization of the ethernet controller.. etc...
 
Thanks Again
T.
0 Kudos

444 Views
bkatt
Contributor IV
Most of the initialization worked fine out of the box. 100 ethernet came right up and it wasn't hard to find where to set the mac address and ip number. Auto negotiation is broken in the hardware, so they have a kludgy startup that sets it to 100, then waits for link up or eventually sets it back to 10. I reduced the loop counter because the delay was too long for my purposes.
0 Kudos