lwip-users
[Top][All Lists]
Advanced

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

Re: [lwip-users] XAPP663 (TCP/IP on V2P devices using lwIP) problem


From: Mechouk Nicolas
Subject: Re: [lwip-users] XAPP663 (TCP/IP on V2P devices using lwIP) problem
Date: Tue, 27 May 2008 15:14:17 +0200
User-agent: Thunderbird 1.5.0.7 (Windows/20060909)

Thanks for your answer Bill.

I've still working on my client application and the behavior of my system is strange: My soft run but if I erase or add a "xil_printf("...")", it doen't work anymore.

It's very strange because no relation between uart and ethernet.... Maybe, some conflict on the bus......

If somebody have any idea about that.......

These are my source files :

client.c (with main()):
/*
...
  
 * (c) Copyright 2002, 2003 Xilinx, Inc.
...
 */
/*
 * Copyright (c) 2001, 2002, 2003 Swedish Institute of Computer Science.
...
 */
/* Xilinx Includes */
#include "xuartns550_l.h"
#include "xtime_l.h"
#include "xparameters.h"
#include "xcache_l.h"
#include "xgpio_l.h"
/* lwIP Includes */
#include "netif/xemacif.h"
#include "lwip/tcp.h"
#include "lwip/memp.h"
#include "netif/etharp.h"
#include "TxTest.h"
#define UART_BASEADDR   XPAR_RS232_UART_1_BASEADDR
#define UART_CLOCK      XPAR_XUARTNS550_CLOCK_HZ
#define UART_BAUDRATE   115200
#define LWIP_TIMER_CYCLES (XPAR_CPU_PPC405_CORE_CLOCK_FREQ_HZ / 1000 \
                           * TCP_TMR_INTERVAL )
// Upper 6 bytes of MAC - Xilinx Ethernet OUI = 00-0A-35 - 00 00 0E EB 94 B4
#define XILINX_MAC_OUI0 0x00
#define XILINX_MAC_OUI1 0x00
#define XILINX_MAC_OUI2 0x0E
  
static void show_dotted_decimal( char * address_array);
static void show_dashed_hex( int bytes, char *address_array);
// Static Global Variables
static u8_t my_timer = 0;
// External Global Variables
// defined in lwip/src/core/tcp.c 
extern u32_t tcp_ticks; 
// defined in EDK generated xemacif_g.c file 
extern XEmacIf_Config XEmacIf_ConfigTable[]; 
  
/*---------------------------------------------------------------------------*/
// show dotted decimal prints a dotted decimal address to the UART           */
/*---------------------------------------------------------------------------*/
static void show_dotted_decimal( char *address_array)
{
   int bb;
   char temp;
   for(bb=0;bb<4;bb++)
   {
      temp = address_array[bb];
      if(bb!=0) xil_printf(".");
      xil_printf("%d", (int) temp);      
   }
}
/*---------------------------------------------------------------------------*/
/* show dashed hex prints a dashed hex address to the UART                   */
/*---------------------------------------------------------------------------*/
static void show_dashed_hex( int bytes, char *address_array)
{
   //Assumes the caller passes the correct number of bytes
   int bb;
   for(bb=0;bb<bytes;bb++)
   {
      if(bb !=0) xil_printf("-");
      xil_printf("%02X", (int) address_array[bb]);
   }
}
/*---------------------------------------------------------------------------*/
/* my_tmr - Called Periodically to dispatch TCP and ARP timers               */
/*---------------------------------------------------------------------------*/
void my_tmr(void)
{
   ++my_timer;
   if(my_timer == 10) {
      my_timer = 0;
   }
   if(my_timer & 1) {
      /* Call tcp_fasttmr() every 2 ms, i.e.,
       * every other timer my_tmr() is called. */
      tcp_fasttmr();
   }
   if(my_timer == 0 || my_timer == 5) {
      /* Call tcp_slowtmr() every 5 ms, i.e.,
       * every fifth timer my_tmr() is called. */
      tcp_slowtmr();
      if (tcp_ticks%2000 == 0)
         /* Call etharp_tmr() every 20th call to tcp_slowtmr().
          * tcp_ticks is a global var defined in core/tcp.c */
         etharp_tmr();
   }
}
/*---------------------------------------------------------------------------*/
/* new_my_tmr - Called Periodically to dispatch TCP and ARP timers               */
/*---------------------------------------------------------------------------*/
void new_my_tmr(void)
{
  tcp_tmr();
  etharp_tmr();
}
/*---------------------------------------------------------------------------*/
/* main function                                                             */
/*---------------------------------------------------------------------------*/
int main ()
{
   struct tcp_pcb *gddpp_pcb;
   struct ip_addr ipaddr, netmask, gw;
   struct netif *default_netif;
   char menu_select = 0;
   XTime ml_base, ml_new, ml_offset;
   int waiting_for_timer = 1;
   char low_mac[3] = {0xEB,0x94,0xB4};  //EB 94 B4
   char fullmac[6] = {XILINX_MAC_OUI0, XILINX_MAC_OUI1, XILINX_MAC_OUI2,
                      low_mac[0], low_mac[2], low_mac[3]};
   char ip[4] =      {147,210,11,22};
   char subnet[4] =  {255,255,255,0};
   char gateway[4] = {147,210,11,254};
   unsigned int init_wait = 15000000;
    
  
   /*-------------------------------------------------------------------------
   * Uart Init
   *
   * The XIo stuff below is to make the new ABQ drivers act like the original
   * SEG drivers from V2PDK 1.0.  Otherwise, the UART won't work on some 
   * revisions of the Insight Boards.
   * 
   *------------------------------------------------------------------------*/
   /* Disable Interrupts */
    XIo_Out8(UART_BASEADDR + XUN_LCR_OFFSET, 0UL);
   XIo_Out8(UART_BASEADDR + XUN_IER_OFFSET, 0UL);
   /* Clear Latches */
   XIo_In8(UART_BASEADDR + XUN_LSR_OFFSET);
   XIo_In8(UART_BASEADDR + XUN_IIR_OFFSET);
   XIo_In8(UART_BASEADDR + XUN_MSR_OFFSET);
   /* Disable FIFOs (16450) */
   XIo_Out8(UART_BASEADDR + XUN_FCR_OFFSET, 0UL);
   /* Normal ABQ level 0 driver inits */
   XUartNs550_SetBaud(UART_BASEADDR, UART_CLOCK, UART_BAUDRATE);
   XUartNs550_mSetLineControlReg(UART_BASEADDR, XUN_LCR_8_DATA_BITS);
   /* Sets DTR, RTS, and OUT2 in the MCR */
   XIo_Out8(UART_BASEADDR + XUN_MCR_OFFSET, 
         XUN_MCR_OUT_2 | XUN_MCR_RTS | XUN_MCR_DTR);
   xil_printf("\n\r\n");
   xil_printf("Starting Up...\r\n");
   xil_printf("Console: 115200 initialized.\r\n");
  
    
   /*-----------------------------------------------------------------------*/
   /* Timer Inits                                                           */
   /*-----------------------------------------------------------------------*/
   ml_offset = LWIP_TIMER_CYCLES;
   /*-----------------------------------------------------------------------*/
   /* Do LWIP System Inits                                                  */
   /*-----------------------------------------------------------------------*/
   #ifdef STATS
      stats_init();
   #endif // STATS //
   xil_printf("Initializing Memory Structures.");
   sys_init();
    xil_printf(".");
   mem_init();
   xil_printf(".");
   memp_init();
   xil_printf(".");
   pbuf_init();
   xil_printf(" done.\r\n");
   // clear UART Receive Buffer
   while (XUartNs550_mIsReceiveData(UART_BASEADDR)) 
      { XUartNs550_RecvByte(UART_BASEADDR); }
   // set GPIO I/O Mask
   //XGpio_mSetDataDirection(XPAR_MYGPIO_BASEADDR, 0x00000FFF);
   // Turn on 4 LEDs (Active Low)
   //XGpio_mSetDataReg(XPAR_MYGPIO_BASEADDR, 0x00000000);
   
   /*-----------------------------------------------------------------------*/
   /* Initial Header and Menus.  Do this before the netif_init() so we can  */
   /* change the MAC Address and IP addresses if needed                     */
   /*-----------------------------------------------------------------------*/
   while(init_wait--);
   fullmac[0] = XILINX_MAC_OUI0;
   fullmac[1] = XILINX_MAC_OUI1;
   fullmac[2] = XILINX_MAC_OUI2;
   fullmac[3] = low_mac[0];
   fullmac[4] = low_mac[1];
   fullmac[5] = low_mac[2];
   
     
   /*-----------------------------------------------------------------------*/
   /* Set host addresses                                                    */
   /*-----------------------------------------------------------------------*/
   xemacif_setmac(0, (u8_t *) fullmac);                        //Set MAC
   IP4_ADDR(&gw, gateway[0],gateway[1],gateway[2],gateway[3]); //Set gateway
   IP4_ADDR(&ipaddr, ip[0],ip[1],ip[2],ip[3]);                 //Set ip
   IP4_ADDR(&netmask,subnet[0],subnet[1],subnet[2],subnet[3]); //Set subnet msk
   
   /*-----------------------------------------------------------------------*/
   /* Show some host boot stuff and parameters                              */
   /*-----------------------------------------------------------------------*/
   xil_printf("\r\nStarting Network Interface...\r\n");
   xil_printf("  MAC Address: "); show_dashed_hex(6, fullmac);  xil_printf("\r\n");
   xil_printf("  IP Address: ");  show_dotted_decimal(ip);      xil_printf("\r\n");
   xil_printf("  Subnet Mask: "); show_dotted_decimal(subnet);  xil_printf("\r\n");
   xil_printf("  Gateway IP: ");  show_dotted_decimal(gateway); xil_printf("\r\n");
   xil_printf("  Serv Port: 6500 \r\n");
   
   /*-----------------------------------------------------------------------*/
   /* Initialize netif                                                      */
   /*-----------------------------------------------------------------------*/
   netif_init();
   
   /*-----------------------------------------------------------------------*/
   /* Initialize TCP Stack                                                  */
   /*-----------------------------------------------------------------------*/
   tcp_init();
   
   /*-----------------------------------------------------------------------*/
   /* Set up the lwIP network interface...                                  */
   /*-----------------------------------------------------------------------*/
   default_netif = netif_add(&ipaddr, 
                             &netmask,
                             &gw,
                             &XEmacIf_ConfigTable[0],
                             xemacif_init,
                             ip_input
                             );
   
   netif_set_default(default_netif);
   
   /*-----------------------------------------------------------------------*/
   /* create new tcp pcb and start applications                             */
   /*-----------------------------------------------------------------------*/
   
   // Start the Client
   xil_printf("\n\nTxTest Client Running ... "); xil_printf("\r\n");
   TxTest_init();
       
   while (1) {
     while (waiting_for_timer) {
         // Call to check if there are any packets
       xemacif_input(default_netif);
       send_data(tx_pcb, ps);
     }
      xil_printf("Call my_tmr()\r\n");
     // Call my_tmr()
     new_my_tmr();
     waiting_for_timer = 1;
   }
   return (1);
}
and Txtest.c :

/*  TxTest.c
 * Copyright (c) 2001-2003 Swedish Institute of Computer Science.
...
 */
#include "lwip/debug.h"
#include "lwip/stats.h"
#include "lwip/tcp.h"
#include "TxTest.h"
#include "smip_trimode_dasip_moore_uint16.h" //header for my IP
#include "xparameters.h" //use to have the @ of my IP
struct tcp_pcb *tx_pcb;
struct TxTest_state *ps = NULL;
int totsent = 0;
char data_buf[TXTEST_PKT_SIZE] __attribute__((aligned (4)));
char data[7] __attribute__((aligned (4)));
unsigned char smipId[3] = "000";
unsigned char mccId;
unsigned char cCmd[8]; 
/*---------------------------------------------------------------------------*/
/*
 * charHex2Int
 */
static int charHex2Int(char c) {
    switch (c) {
           case '0' : return 0; break;
           case '1' : return 1; break;
           case '2' : return 2; break;
           case '3' : return 3; break;
           case '4' : return 4; break;
           case '5' : return 5; break;
           case '6' : return 6; break;
           case '7' : return 7; break;
           case '8' : return 8; break;
           case '9' : return 9; break;
           case 'a' : return 10; break;
           case 'b' : return 11; break;
           case 'c' : return 12; break;
           case 'd' : return 13; break;
           case 'e' : return 14; break;
           case 'f' : return 15; break;
           case 'A' : return 10; break;
           case 'B' : return 11; break;
           case 'C' : return 12; break;
           case 'D' : return 13; break;
           case 'E' : return 14; break;
           case 'F' : return 15; break;
           default  : return 0;
    }
}
/*---------------------------------------------------------------------------*/
static void modeSending(unsigned char smipId[3], unsigned char mccId, unsigned char cCmd[8])
{
    int cCmdH = 0;
    unsigned char smipNb[3] = "256";
    char mcc[1] = "m";
    int i;
    
    for (i = 0; i<=7; i++) cCmdH = 16*cCmdH + charHex2Int(cCmd[i]);
    if (mccId == mcc[0]) {// mcc = "m"
        xil_printf("test mcc ok \r\n");
        if (smipId[0] == smipNb[0] && smipId[1] == smipNb[1] && smipId[2] == smipNb[2]) {// smipNb = "256"
            xil_printf("test smipId ok \r\n");
            //xil_printf("nouveau mode : %X \r\n", cCmdH);
            SMIP_TRIMODE_DASIP_MOORE_UINT16_mWriteReg(XPAR_SMIP_TRIMODE_DASIP_MOORE_UINT16_0_BASEADDR + 0x10, 0, cCmdH);
            //xil_printf("mccId : %c,\ncCmd : %X,\nsmipId : %c\%c%c\n\r",mccId,cCmdH,smipId[0],smipId[1],smipId[2]);
        } else {
            xil_printf("test smipId KO \r\n");
        }
    } else {xil_printf("test mcc KO \r\n");}
}
/*---------------------------------------------------------------------------*/
static void
close_conn(struct tcp_pcb *pcb, struct TxTest_state *ps)
{
  tcp_arg(pcb, NULL);
  tcp_sent(pcb, NULL);  
  tcp_recv(pcb, NULL);
  if(ps != NULL) {
    //mem_free(ps->buf_p);
    mem_free(ps);
  }
  pcb->state = CLOSE_WAIT;
  if (tcp_close(pcb) != ERR_OK)
    print("[TxTest could not close] \r\n");
  else
    print("[TxTest_closed] \r\n");
}
/*-----------------------------------------------------------------------------------*/
static err_t recv_callback(void *arg, struct tcp_pcb *tpcb,
                               struct pbuf *p, err_t err)
{
    char *datarcv;
    unsigned char smipId[3] = "000";
    unsigned char mccId;
    unsigned char cCmd[9];
    
    xil_printf("Receive started...\n\r");
    // all we do is say we've received the packet 
    // we don't actually make use of it 
    tcp_recved(tpcb, p->tot_len);
   datarcv = p->payload;
    //xil_printf("data : %12s\n\r",datarcv);
    mccId = datarcv[0];
    cCmd[0] = datarcv[1];
    cCmd[1] = datarcv[2];
    cCmd[2] = datarcv[3];
    cCmd[3] = datarcv[4];
    cCmd[4] = datarcv[5];
    cCmd[5] = datarcv[6];
    cCmd[6] = datarcv[7];
    cCmd[7] = datarcv[8];
    cCmd[8] = '\0';
    smipId[0] = datarcv[9];
    smipId[1] = datarcv[10];
    smipId[2] = datarcv[11];
    xil_printf("mccId : %c\n\rcCmd : %s\n\rsmipId : %c\%c%c\n\r",mccId,cCmd,smipId[0],smipId[1],smipId[2]);
    
    modeSending(smipId, mccId, cCmd);
    pbuf_free(p);
    if (tcp_close(tpcb) != ERR_OK)
      xil_printf("[TxTest could not close] \r\n");
   else
    xil_printf("[TxTest_closed] \r\n");//*/
    return ERR_OK;
}
/*---------------------------------------------------------------------------*/
static void
TxTest_err(void *arg, err_t err)
{
  //struct TxTest_state *ps = arg;
  xil_printf("TxTest_err\r\n");
  if(arg != NULL) {
    //mem_free(ps->buf_p);
    mem_free(ps);
  }
}
 /*---------------------------------------------------------------------------*/
void
send_data(struct tcp_pcb *pcb, struct TxTest_state *ps)
{
  err_t err = ERR_OK;
  u16_t len;
  /* We cannot send more data than space available in the send
     buffer. */     
  if (tcp_sndbuf(pcb) < ps->left) {
    len = tcp_sndbuf(pcb);
  } else {
    len = ps->left;
  }
  //xil_printf("Len: %d \r\n", len);
  if (len > 0) {
    err = tcp_write(pcb, ps->buf_p, len, 1);
    //err = tcp_write(pcb, ps->buf_p, len, 0);
  }
  /*
    if (err != ERR_MEM) {
    if (len > 0 ) {
    ps->buf_p += len;
    ps->left -= len;
    } else {
    ps->buf_p = data_buf;
    ps->left = TXTEST_PKT_SIZE;
    }
    }
  */
}
/*---------------------------------------------------------------------------*/
static err_t
TxTest_sent(void *arg, struct tcp_pcb *pcb, int rcvlen)
{
  struct TxTest_state *ps = (struct TxTest_state *)arg;
  int buflen, len;
  int stat;
  /*
    if (ps->left > 0) {    
    send_data(pcb, ps);
    } else {
    //close_conn(pcb, ps);
    ps->buf_p = data_buf;
    ps->left = TXTEST_PKT_SIZE;
    send_data(pcb, ps);    
    
    }
  */
  if (rcvlen > 0 ) {
    ps->buf_p += len;
    ps->left -= len;
  } 
  if (ps->left <= 0) {
    ps->buf_p = data;
    ps->left = 6;
  }
  
  //print("[TxTest_sent]  \r\n");
  return ERR_OK;
}     
/*---------------------------------------------------------------------------*/
static err_t
TxTest_connected(void *arg, struct tcp_pcb *pcb, err_t error)
{
  char *buf_p;
  int i, len;
  int stat, buflen;
  char *data;
  xil_printf("[TxTest_connected]\r\n");
  tcp_setprio(pcb, TCP_PRIO_MIN);
  
  ps = mem_malloc(sizeof(struct TxTest_state));
  if (ps == NULL){
    xil_printf("could not malloc memory for TxTest_state\r\n");
    return ERR_MEM;
  }
    xil_printf("init data\r\n");
  len = TXTEST_PKT_SIZE; 
  
  data[0] = 'm';
  data[1] = 'o';
  data[2] = 'd';
  data[3] = 'e';
  data[4] = '2';
  data[5] = '\n';
  data[6] = '\0';
  xil_printf("data : %s\r\n", data);
  
  xil_printf("init struct\r\n");
  /* Initialize the structure. */
  ps->left = 6;
  ps->buf_p = data;
  
  
  /* Tell TCP that this is the structure we wish to be passed for our
     callbacks. */
  xil_printf("***** tcp_arg *****\r\n");
  tcp_arg(pcb, ps);
  
  xil_printf("***** tcp_err *****\r\n");
  tcp_err(pcb, TxTest_err);
  
  xil_printf("***** tcp_sent *****\r\n");
  tcp_sent(pcb, TxTest_sent);
  
  /* We cannot send more data than space available in the send
     buffer. */     
  xil_printf("***** send_data *****\r\n");
  send_data(pcb, ps);
  tcp_recv(pcb, recv_callback);
  if(ps != NULL) 
     mem_free(ps);//*/
     
  xil_printf("Fin TxTest_connected\r\n");
  return ERR_OK;
}
/*---------------------------------------------------------------------------*/
void
TxTest_init(void)
{
  struct ip_addr ipaddrServ;
  char ipServ[4] = {147,210,11,226};
  int portServ;
  int stat;
  int i;
  xil_printf("[TxTest_init]\r\n");
  IP4_ADDR(&ipaddrServ, ipServ[0],ipServ[1],ipServ[2],ipServ[3]);
  portServ = 6500;
  tx_pcb = tcp_new();
  if ( !tx_pcb){
    xil_printf("tcp_new fails\r\n");
    return;
  }
  xil_printf("Connection...\r\n");
  stat = tcp_connect(tx_pcb, &ipaddrServ, portServ, TxTest_connected);
  if (stat == ERR_MEM)
    print("[TxTest_connect] memory error \r\n");
}
/*---------------------------------------------------------------------------*/




Bill Auerbach a écrit :

Start with opt.h for reference values.  You MEM_SIZE and TCP_SND_BUF can be much much smaller.

 

Bill

 

From: address@hidden [mailto:address@hidden] On Behalf Of Mechouk Nicolas
Sent: Wednesday, May 21, 2008 12:20 PM
To: Mailing list for lwIP users
Subject: Re: [lwip-users] XAPP663 (TCP/IP on V2P devices using lwIP) problem

 

Thanks Bill.

It was a useful answer....But I've an other question.

For my application, I only need one connection from my client (my XUP V2P) to my server (my PC). I've no SDRAM on my board, just embedded memory (BRAM).
The sending data size is about 128 bits.

>From lwipopts.h, what are the mininal sizes can I use to keep my ethernet connection functionnal ?

I tried these :                                                            (new  //old value)

#define MEM_SIZE                                 1*1024*1024  //16*1024*1024
#define MEMP_NUM_TCP_PCB                               1  //8
#define MEMP_NUM_TCP_PCB_LISTEN                1 //16
#define PBUF_POOL_SIZE                                        1 //512
#define TCP_SND_BUF                                 16*1024 //32*1024

and echo server still works but I want to use the least possible (I don't know if my english is very correct...... ^^; )

Regards,

Nicolas








Bill Auerbach a écrit :

lwIP memory buffers are statically allocated which can cause BSS to be quite
large if your lwipopts.h defines a lot of storage.  BSS doesn't take up
space in the output (elf) file so it's not uncommon to see programs
requiring much more storage than the output file size.
 
I hope I hit the mark what you were questioning.
 
Bill
 
  
-----Original Message-----
From: address@hidden
[mailto:address@hidden] On
Behalf Of Mechouk Nicolas
Sent: Tuesday, May 20, 2008 12:48 PM
To: Mailing list for lwIP users
Subject: [lwip-users] XAPP663 (TCP/IP on V2P devices using lwIP)
problem
 
Hi there,
 
I try to use lwIP to perform a TCP client application on my XUP V2P. I
use files of xapp663 from Xilinx.
But I'm very surprized by the programm size :
 
text            data    bss               dec               hex
75886        996    17598688    17675570    10db532
 
The lwIP lib file is about 200Ko and my .elf file isa about 200Ko too.
 
Anyone can illuminate me on this issue????
Regards,
 
Nicolas
 
 
 
_______________________________________________
lwip-users mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/lwip-users
    
 
 
 
_______________________________________________
lwip-users mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/lwip-users
 
  

_______________________________________________ lwip-users mailing list address@hidden http://lists.nongnu.org/mailman/listinfo/lwip-users

reply via email to

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