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
Visitor laura_lmaxi
Visitor
459 Views
Registered: ‎04-22-2014

send data using echoserver example of lwip

Hello everybody

I am working with the zynq7000 and I had initial success when I implement the echo server aplication that the sdk has as an example, right now I am trying to send data every certain amount of time( I am using the same timer the example use) for some reason I can only send data as part as the recv_callback function, but if I make another function to send my data, it won't do it, it looks like it is writing in the buffer, but it looks like it never send it. I have some of my code here. Thank you so much for looking into it.

 

Best Regards,

Laura

this is the echo.c that I modified

/*
/******************************************************************************
*
* Copyright (C) 2009 - 2014 Xilinx, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* Use of the Software is limited solely to applications:
* (a) running on a Xilinx device, or
* (b) that interact with a Xilinx device through a bus or interconnect.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of the Xilinx shall not be used
* in advertising or otherwise to promote the sale, use or other dealings in
* this Software without prior written authorization from Xilinx.
*
******************************************************************************/

#include <stdio.h>
#include <string.h>
#include "memory.h"

#include <FD6_ASCAN.h>
#include "xtmrctr.h"
#include "xscugic.h"
#include "xil_exception.h"
#include "lwip/err.h"
#include "lwip/tcp.h"

#include "platform.h"
#include "platform_config.h"
#if defined (__arm__) || defined (__aarch64__)
#include "xil_printf.h"
#endif


struct tcp_pcb *tpcb;
int connected;


void print_app_header()
{
xil_printf("\n\r\n\r-----lwIP TCP echo server ------\n\r");
xil_printf("TCP packets sent to port 6001 will be echoed back\n\r");
}

 


int comp_string(char * input1, char * input2)
{
int length1,length2;
int x;
char * input1_cp;
length1 = strlen(input1);
length2 = strlen(input2);
x = 0;

 

while(x < length2)
{

if(input1[x] != input2[x])
return 0;
else
{
x++;
}

}
return 1;
}

err_t send_data(struct tcp_pcb *tpcb)
{
u32 * dataRead;
int j;
int error;
char temp [13];


print("I am here\r\n");
dataRead = ReadMemory(0x40000000,64);

 

for(j=0;j < 64;j++)
{

sprintf(temp, "0x%08X" , *(dataRead+j));
strcat(temp," ");

if(j%4 != 3)
strcat(temp," ");
else
strcat(temp,"\r\n");

printf("%x\n",tcp_sndbuf(tpcb));
if (tcp_sndbuf(tpcb) > ((strlen(temp)+1)))
{
error = tcp_write(tpcb,temp,strlen(temp)+1,1);
printf("%x\n",error);

}
else
xil_printf("no space in tcp_sndbuf\n\r");


}


return ERR_OK;
}

err_t recv_callback(void *arg, struct tcp_pcb *tpcb,
struct pbuf *p, err_t err)
{
int x;


/* do not read the packet if we are not in ESTABLISHED state */
if (!p) {
tcp_close(tpcb);
tcp_recv(tpcb, NULL);
return ERR_OK;
}

/* indicate that the packet has been received */
tcp_recved(tpcb, p->len);

char * input = (char *)p->payload;


// x = comp_string(input,"READ");

// if(x == 1)
// send_data(tpcb);
// else
WriteData(input,0x43c00000, p->len);


pbuf_free(p);

return ERR_OK;
}

 

err_t accept_callback(void *arg, struct tcp_pcb *newpcb, err_t err)

{
static int connection = 1;
tpcb = newpcb;
/* set the send and receive callback for this connection */
tcp_recv(newpcb, recv_callback);


/* just use an integer number indicating the connection id as the
callback argument */
tcp_arg(newpcb, (void*)(UINTPTR)connection);

/* increment for subsequent accepted connections */
connection++;
connected = 1;

return ERR_OK;
}
void transfer_data()
{

if(connected == 1)
send_data(tpcb);
}

struct tcp_pcb * start_application()
{
struct tcp_pcb *pcb;
err_t err;
unsigned port = 7;

/* create new TCP PCB structure */
connected = 0;
pcb = tcp_new();
if (!pcb) {
xil_printf("Error creating PCB. Out of Memory\n\r");
// return -1;
}

/* bind to specified @port */
err = tcp_bind(pcb, IP_ADDR_ANY, port);
if (err != ERR_OK) {
xil_printf("Unable to bind to port %d: err = %d\n\r", port, err);
// return -2;
}

/* we do not need any arguments to callback functions */
//
tcp_arg(pcb, NULL);

/* listen for connections */
pcb = tcp_listen(pcb);
if (!pcb) {
xil_printf("Out of memory while tcp_listen\n\r");
// return -3;
}


/* specify callback to use for incoming connections */
tcp_accept(pcb, accept_callback);

 

xil_printf("TCP echo server started @ port %d\n\r", port);

return pcb;
}

and this is part of my main.c file

start_application();
cleanup_platform();

/* receive and process packets */
while (1)
{
xemacif_input(echo_netif);

if(TcpFastTmrFlag)
{
transfer_data();
tcp_fasttmr();
}


}

 

 

 

0 Kudos