[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lwip-users] UDP send example
From: |
Jon Bean |
Subject: |
[lwip-users] UDP send example |
Date: |
Fri, 10 Jul 2020 11:44:00 +0100 |
User-agent: |
Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 |
Hi
I am trying to setup an application on a Texas Instruments TIVA micro
controller. What I am trying to do is first receive a UDP packet from a
pc to the board. I then want to be able to send packets back when I have
data to send. I have managed to do this using the UDP echo example. But
this send a packet back when it gets a response. I tried calling my send
function from a loop in main. But it just crashed. I asked on the TI
form and was told I need to call the udp_sendto function from an
interrupt. I cahnged the code so that it is aclled from the LWIP timer
handler. But its still crashing. Can anyone see an issue with the code
below or have a working example? Thanks
The udp_addr and udp_port vars are what I set when I get the receive
packet from the host. The new_udp_pcb is created in my setup function.
void eth_udp_tx()
{
struct pbuf *p;
uint8_t buf[4];
p = pbuf_alloc(PBUF_TRANSPORT, 4, PBUF_POOL);
p->len = 4;
p->tot_len = 4;
p->payload = buf;
if (p)
{
udp_sendto(new_udp_pcb, p, udp_addr, udp_port);
pbuf_free(p);
}
}
void eth_udp_rx(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct
ip_addr *addr, u16_t port)
{
uint32_t len;
char *p_payload;
uint8_t buf[16];
int i;
if (p != NULL)
{
p_payload = (char *)p->payload;
len = p->tot_len;
for (i=0;i<len;i++)
{
buf[i] = p_payload[i];
}
udp_rx_done = 1;
udp_addr = addr;
udp_port = port;
/* send received packet back to sender */
//udp_sendto(new_udp_pcb, p, addr, port);
/* free the pbuf */
pbuf_free(p);
}
}
void eth_udp_init(void)
{
//struct udp_pcb * pcb;
/* get new pcb */
new_udp_pcb = udp_new();
if (new_udp_pcb == NULL) {
LWIP_DEBUGF(UDP_DEBUG, ("udp_new failed!\n"));
return;
}
/* bind to any IP address on port 23 */
if (udp_bind(new_udp_pcb, IP_ADDR_ANY, 23) != ERR_OK) {
LWIP_DEBUGF(UDP_DEBUG, ("udp_bind failed!\n"));
return;
}
/* set udp_echo_recv() as callback function
for received packets */
udp_recv(new_udp_pcb, eth_udp_rx, NULL);
}
- [lwip-users] UDP send example,
Jon Bean <=