lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] tcp_connect doesn't start the callback function


From: Marianovich, Andre
Subject: [lwip-users] tcp_connect doesn't start the callback function
Date: Fri, 19 Mar 2010 10:19:00 +0100
User-agent: Thunderbird 2.0.0.23 (Windows/20090812)

Hi

At some point there was a mail in which someone had a problem with the tcp_connect function but there was no answer. This did not seem to call the callback function. I now have the same problem. I would like to write a client (lwIP RAW API) to connect to a host running iperf. But apparently the tcp_connect function does nothing, does not call the callback function I suppose and it will not connect. All should run on the PPC 405 of a Xilinx Virtex 4 board. Below I've added the whole code which is quite similar to the code of the previously mentioned message.

Might someone have any idea to fix this problem? By the way, does anyone have a good tutorial how to develop client (tcp) with lwIP?

Regards.


################################ main.c ################################



#include <stdio.h>
#include "xenv_standalone.h"
#include "xparameters.h"
#include "netif/xadapter.h"

#ifdef XPAR_EMACLITE_0_BASEADDR
#define EMAC_BASEADDR  XPAR_EMACLITE_0_BASEADDR
#elif XPAR_LLTEMAC_0_BASEADDR
#define EMAC_BASEADDR  XPAR_LLTEMAC_0_BASEADDR
#else
#error
#endif

int start_application();
int transfer_data();

void print_ip(char *msg, struct ip_addr *ip)
{
        print(msg);
xil_printf("%d.%d.%d.%d\n\r", ip4_addr1(ip), ip4_addr2(ip), ip4_addr3(ip), ip4_addr4(ip));
}

void print_ip_settings(struct ip_addr *ip, struct ip_addr *mask, struct ip_addr *gw)
{
        print_ip("Board IP: ", ip);
        print_ip("Netmask : ", mask);
        print_ip("Gateway : ", gw);
}

int main()
{
        struct netif *netif, server_netif;
        struct ip_addr ipaddr, netmask, gw;

        /* the mac address of the board. this should be unique per board */
unsigned char mac_ethernet_address[] = {0x00, 0x0A, 0x35, 0x01, 0xC2, 0x5C};
        netif = &server_netif;

        #ifdef __MICROBLAZE__
        microblaze_init_icache_range(0, XPAR_MICROBLAZE_0_CACHE_BYTE_SIZE);
        microblaze_init_dcache_range(0, XPAR_MICROBLAZE_0_DCACHE_BYTE_SIZE);
        #endif

        /* enable caches */
        XCACHE_ENABLE_ICACHE();
        XCACHE_ENABLE_DCACHE();
        //platform_setup_interrupts();

        /* initliaze IP addresses to be used */
        IP4_ADDR(&ipaddr,  131, 169,   117, 2);
        IP4_ADDR(&netmask, 255, 255, 255,  0);
        IP4_ADDR(&gw,      0, 0, 0, 0);

        print_app_header();
        print_ip_settings(&ipaddr, &netmask, &gw);
        
        lwip_init();

        /* Add network interface to the netif_list, and set it as default */

if (!xemac_add(netif, &ipaddr, &netmask, &gw, mac_ethernet_address, EMAC_BASEADDR))
        {
                xil_printf("Error adding N/W interface\n\r");
                return -1;
        }

        netif_set_default(netif);


        /* Create a new DHCP client for this interface.
         * Note: you must call dhcp_fine_tmr() and dhcp_coarse_tmr() at
        * the predefined regular intervals after starting the client.
        */

         /* dhcp_start(netif); */
        
        /* now enable interrupts */
        platform_enable_interrupts();

        /* specify that the network if is up */
        netif_set_up(netif);

        /* start the application (web server, rxtest, txtest, etc..) */
        start_application();

        /* receive and process packets */
        while (1)
        {
                xemacif_input(netif);
                transfer_data();
        }

        XCACHE_DISABLE_DCACHE();
        XCACHE_DISABLE_ICACHE();
        
        #ifdef __MICROBLAZE__
        microblaze_init_dcache_range(0, XPAR_MICROBLAZE_0_DCACHE_BYTE_SIZE);
        microblaze_init_icache_range(0, XPAR_MICROBLAZE_0_CACHE_BYTE_SIZE);
        #endif

        return 0;
}

############################ txtest.c ##################################

#include <stdio.h>
#include <string.h>
#include "lwip/err.h"
#include "lwip/tcp.h"
#include "xexception_l.h"

static struct tcp_pcb *connected_pcb = NULL;

#define SEND_BUFSIZE (1446)
#define TCP_SND_BUFFER 8192

static char send_buf[SEND_BUFSIZE];

int transfer_data()
{
        int copy = 1;
        err_t err;
        struct tcp_pcb *tpcb = connected_pcb;
        static packet_cnt = 0;
        int buflen;

         if (!connected_pcb)
                return ERR_OK;

        if ((buflen = tcp_sndbuf(tpcb)) > SEND_BUFSIZE)
        {
                packet_cnt++;
                err = tcp_write(tpcb, send_buf, SEND_BUFSIZE, copy);
                
                if (err != ERR_OK)
                {
                        xil_printf("Error on tcp_write: %d\n\r", err);
                        //while (1);
                        return -1;
                }
        }

        if ((buflen = tcp_sndbuf(tpcb)) >= (TCP_SND_BUFFER - 3 * SEND_BUFSIZE))
        {
                packet_cnt++;

                err = tcp_write(tpcb, send_buf, SEND_BUFSIZE, copy);
                
                if (err != ERR_OK)
                {
                        xil_printf("Error on tcp_write: %d\n\r", err);
                        //while (1);
                        return -1;
                }
        }

        if ((buflen = tcp_sndbuf(tpcb)) >= (TCP_SND_BUFFER - 3 * SEND_BUFSIZE))
        {
                packet_cnt++;
                err = tcp_write(tpcb, send_buf, SEND_BUFSIZE, copy);

                if (err != ERR_OK)
                {
                        xil_printf("Error on tcp_write: %d\n\r", err);
                        //while (1);
                        return -1;
                }
        }
        
        return 0;
}

err_t sent_callback(void *arg, struct tcp_pcb *tpcb, u16_t len)
{
 return ERR_OK;
}

err_t connected_callback(void *arg, struct tcp_pcb *tpcb, err_t err)
{
        LWIP_UNUSED_ARG(arg);
        LWIP_UNUSED_ARG(err);
        xil_printf("txperf: Connected to iperf server\n\r");

        /* store state */
        //connected_pcb = tpcb;
        
        /* set callback values & functions */
        tcp_arg(tpcb, NULL);
        tcp_sent(tpcb, sent_callback);

        /* initiate data transfer */
        return ERR_OK;
}

int start_application()
{
        struct tcp_pcb *pcb;
        struct ip_addr ipaddr;
        err_t err = ERR_CONN;
        u16_t port;
        int i;

        /* create new TCP PCB structure */
        pcb = tcp_new();

        if (!pcb)
        {
                xil_printf("Error creating PCB. Out of Memory\n\r");
                return -1;
        }

        /* connect to iperf server */
        IP4_ADDR(&ipaddr,  131, 169, 117, 59);  /* iperf server address */
        port = 5001;     /* iperf server port */
        err = tcp_connect(pcb, &ipaddr, port, connected_callback);
        if (err != ERR_OK)
        {
                xil_printf("tcp_connect returned error: %d\n\r", err);
                return err;
        }
        
        connected_pcb = pcb;
        
        xil_printf("tcp_connect issued\n\r");




        /* initialize data buffer being sent */
        for (i = 0; i < SEND_BUFSIZE; i++)
        {       
                send_buf[i] = (i % 10) + '0';
        }

        return 0;
}

void print_app_header()
{
        xil_printf("\f-----lwIP Transmit Test [Board -> Host] ------\n\n\r");
xil_printf("To perform TCP TX bandwidth calculation, run iperf from your host machine as: \n\n\r");
        xil_printf("iperf -s -p 2000 -i 2 \n\n\r");
xil_printf("Host should have IP 172.16.1.250 (can be changed in txperf.c)\n\n\r");
}

void platform_enable_interrupts()
{
#ifdef __MICROBLAZE__
    microblaze_enable_interrupts();
#elif  __PPC__
        XExc_mEnableExceptions(XEXC_NON_CRITICAL);
#endif
}





reply via email to

[Prev in Thread] Current Thread [Next in Thread]