UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
4,996 Views
Registered: ‎11-03-2013

No output in teraterm

Guys, I am trying to send some data over ethernet using ML410 FPGA. What I am actually doing is, wrote a C code in which I created and binded a socket and wrote a function that sends  some dummy data for now stored in a character array(string). So when I dump my code in ML410 lan is up and when I open teraterm I cannot find any data and getting a message 'connection refused'. I am a newbie and i think when I dump my code, my board becomes server as it is sending data and my PC is a client that receives data, if I am correct. I am posting my code, have a look guys. I may be missing something. i also added the output I got in console after running on my ML410. Thanks.

/*
 * data_send.c
 *
 *  Created on: Jan 8, 2014
 *      Author: Administrator
 */
#include "xmk.h"
#include <stdio.h>
#include <malloc.h>
#include <string.h>

#include "xenv_standalone.h"
#include "xparameters.h"

#include "netif/xadapter.h"
#include "netif/xemacliteif.h"
#include "sys/socket.h"
#include "lwip/inet.h"
#include "lwip/sockets.h"
#include "lwipopts.h"
#include "xtime_l.h"
#include "xexception_l.h"
#include "netdb.h"
#include "sys/types.h"
#include "signal.h"
#include "netinet/in.h"
#include "lwip/opt.h"
#include "netif.h"
#ifdef XPAR_ETHERNET_MAC_BASEADDR
#define EMAC_BASEADDR  XPAR_ETHERNET_MAC_BASEADDR
#elif XPAR_LLTEMAC_0_BASEADDR
#define EMAC_BASEADDR  XPAR_LLTEMAC_0_BASEADDR
#else
#error
#endif
#define MHZ 300
#define PIT_INTERVAL (250*MHZ*1000)
#define APP_DRS
int DRS_application_thread();
void DRS_process_request(int);

/* ------------MAIN------------- */

// initialize xikernel
int main()
{
        xilkernel_main();
}

struct netif server_netif;


int network_thread()
{
        struct netif *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, 0x9b, 0x3a };

        netif = &server_netif;

/* initliaze IP addresses to be used */
        IP4_ADDR(&ipaddr,  192, 168,   1, 2);
        IP4_ADDR(&netmask, 255, 255, 255,  0);
        IP4_ADDR(&gw,      192, 168,   1,  0);

/* print out IP settings of the board */
        print("\n\r\n\r");
//      print_ip_settings(&ipaddr, &netmask, &gw);
        print_ip("Board IP: ", &ipaddr);
        print_ip("Netmask : ", &netmask);
        print_ip("Gateway : ", &gw);

/* 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);

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

/* start packet receive thread - required for lwIP operation */
        sys_thread_new("packet receive thread",xemacif_input_thread, netif,0, DEFAULT_THREAD_PRIO);

/* now we can start application threads */
        #ifdef APP_DRS
                /* start DRS thread */
                sys_thread_new("drs thread",DRS_application_thread,NULL, 0, DEFAULT_THREAD_PRIO);
        #endif
        return 0;
}

int main_thread()
{
        /* initialize lwIP before calling sys_thread_new */
        lwip_init();

        /* any thread using lwIP should be created using sys_thread_new */
        sys_thread_new("network thread",network_thread, NULL,0, DEFAULT_THREAD_PRIO);
}
int
DRS_application_thread()
{
        int sock, new_sd;
        struct sockaddr_in address, remote;
        int size;

        /* create a TCP socket */
        if ((sock = lwip_socket(AF_INET, SOCK_STREAM, 0)) < 0)

                return;

        /* bind to port 8080 at any interface */
        address.sin_family = AF_INET;
        address.sin_port = htons(8080);
        address.sin_addr.s_addr = INADDR_ANY;

        if (lwip_bind(sock, (struct sockaddr *)&address, sizeof (address)) < 0)
                return;

        /* listen for incoming connections */
        lwip_listen(sock, 5);

        size = sizeof(remote);

        while (1) {
                new_sd = lwip_accept(sock, (struct sockaddr *)&remote, &size);
                /* spawn a separate handler for each request */
                sys_thread_new("drs process request",DRS_process_request, (void*)new_sd,0, DEFAULT_THREAD_PRIO);

        }
}
void
DRS_process_request(int sd)
{
        int read_len ;
        char *pbuf;

        pbuf = (unsigned char *) calloc(100, sizeof(unsigned char));

		   pbuf[0]='D';
           pbuf[1]='L';
           pbuf[2]='R';
           pbuf[3]='L';
           pbuf[4]=' ';
           pbuf[5]='D';
           pbuf[6]='A';
           pbuf[7]='T';
           pbuf[8]='A';
while(read(sd,pbuf,sizeof(pbuf))>0)
{
	while(1)
	{
		 write(sd, pbuf, 100);   //writing in to string//
		 printf("%s \n",pbuf);
	}
}

        /* close connection */


        close(sd);
}

 console.jpg

jeevanreddymandali
Tags (3)
0 Kudos
4 Replies
4,958 Views
Registered: ‎11-03-2013

Re: No output in teraterm

Guys anybody, please tell me what am I doing wrong.
Regards,
jeevanreddymandali
0 Kudos
Explorer
Explorer
4,934 Views
Registered: ‎03-31-2011

Re: No output in teraterm

check wther ur prog is running fine..r u getting those print statement in hyperterminal...dont include xilkernel at first stage...just check whether ur ethernet communication is fine in standalone mode

0 Kudos
4,924 Views
Registered: ‎11-03-2013

Re: No output in teraterm

My program is running fine in standalone mode. Yes those statements are on SDK console window using COM1 (hyperterminal). But what does pbuf allocated deallocated means? Why is this shown and why does this happening that fast?
jeevanreddymandali
0 Kudos
Visitor gy343279479
Visitor
2,607 Views
Registered: ‎07-26-2015

Re: No output in teraterm

hello, is DRS_application_thread defined by your ? or there is a example

0 Kudos