This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/LAUNCHXL2-RM57L: Decrease time intervals to send and receive data using lwIP

Part Number: LAUNCHXL2-RM57L

Tool/software: Code Composer Studio

Hello,

I am using the lwip library on the RM57 launchpad and it is working properly. I am using Raw/TCP for an echo_tcp example, so I can send and receive data to another device on my LAN.

I am finding that the launchpad (it was configured as a server, as in the demo) only receives and transmits the packets on about 250 ms intervals, and I need to send data faster than this. I know that this is possible, because when I use breakpoints in the debug mode, sometimes, I got intervals up to 5 ms.

I thought it was possible to decrease this time by changing parameters in tcpip_tcp_timer(), for example, the TCP_TMR_INTERVAL, so I changed this value from the default of 250 ms to lower values, but I didn't get any change.

I would like to know what parameters I should configure to decrease these time intervals.

Any help is welcome.

Many thanks!

  • Hi Linda,

    Can you post your already working echo tcp example? 

  • Hi QJ Wang,

    This is my working echo TCP example. Previously, I was printing the data at the terminal using the SCI port, to view the data that the RM57 launchpad was receiving and sending at the CCS terminal. I am using the sciDisplayText function in the code that I am working on to print this data in the terminal. However, when I removed the display of the data on the terminal through the SCI port, the latency decreased considerably. In the last tests that I have done, I have obtained time intervals less than 50 ms, so I think that the problem has been solved. But, I remain attentive to any other recommendation.

    Thank you so much for your reply. 

    Best regards.

    // Source: initialization and control path for the lwIP and EMAC driver and can be called from system main
    // Source echo_tcp_ip in: cvs.savannah.gnu.org/.../
    
    #include "lwiplib.h"
    #include "HL_sci.h"
    #include "lwip\inet.h"
    #include "locator.h"
    #include "lwip/debug.h"
    #include "lwip/stats.h"
    #include "lwip/tcp.h"
    #include<stdio.h>
    
    #define sciREGx  sciREG1
    
    uint8_t    txtCRLF[]         = {'\r', '\n'};
    uint8_t    txtTitle[]        = {"WELCOME - LINK: CCL/TI "};
    uint8_t    txtTI[]           = {"Texas Instruments"};
    uint8_t    txtLittleEndian[] = {"Device Little Endian"};
    uint8_t    txtEnetInit[]     = {"Ethernet (DHCP)"};
    uint8_t    txtErrorInit[]    = {"-------- ERROR INICIALIZANDO HARDWARE --------"};
    uint8_t    txtIPAddrTxt[]    = {"IPv4: "};
    uint8_t    * txtIPAddrItoA;
    
    volatile int countEMACCore0RxIsr = 0;
    #pragma INTERRUPT(EMACCore0RxIsr, IRQ)
    
    void EMACCore0RxIsr(void)
    {
       countEMACCore0RxIsr++;
       lwIPRxIntHandler(0);
    }
    
    volatile int countEMACCore0TxIsr = 0;
    #pragma INTERRUPT(EMACCore0TxIsr, IRQ)
    
    void EMACCore0TxIsr(void)
    {
     countEMACCore0TxIsr++;
       lwIPTxIntHandler(0);
    }
    
    void IntMasterIRQEnable(void)
    {
     _enable_IRQ();
     return;
    }
    
    void IntMasterIRQDisable(void)
    {
     _disable_IRQ();
     return;
    }
    
    unsigned int IntMasterStatusGet(void)
    {
       return (0xC0 & _get_CPSR());
    }
    
    void sciDisplayText(sciBASE_t *sci, uint8_t *text,uint32_t length)
    {
       while(length--)
       {
           while ((sci->FLR & 0x4) == 4);
           sciSendByte(sci,*text++);
       };
    }
    
    void sciNotification(sciBASE_t *sci, uint32_t flags)
    {
        return;
    }
    
    void smallDelay(void) {
          static volatile unsigned int delayval;
          delayval = 10000;
          while(delayval--);
    }
    
    static struct tcp_pcb *ccl_pcb;
    
    enum ccl_states
    {
      ES_NONE = 0,
      ES_ACCEPTED,
      ES_RECEIVED,
      ES_CLOSING
    };
    
    struct ccl_state
    {
      u8_t state;
      u8_t retries;
      struct tcp_pcb *pcb;
      struct pbuf *p;
    };
    
    err_t ccl_accept(void *arg, struct tcp_pcb *newpcb, err_t err);
    err_t ccl_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err);
    void ccl_error(void *arg, err_t err);
    void ccl_close(struct tcp_pcb *tpcb, struct ccl_state *es);
    void ccl_send(struct tcp_pcb *tpcb, struct ccl_state *es);
    
    ///////////////////////////////////////////////////////////////////////////
    //                                                                       //
    ///////////////////////////////////////////////////////////////////////////
    
    err_t ccl_accept(void *arg, struct tcp_pcb *newpcb, err_t err)
    {
      err_t ret_err;
      struct ccl_state *es;
      LWIP_UNUSED_ARG(arg);
      LWIP_UNUSED_ARG(err);
      tcp_setprio(newpcb, TCP_PRIO_MIN);
      sciDisplayText(sciREGx, txtCRLF, sizeof(txtCRLF));
      sciDisplayText(sciREGx, (uint8_t*)"PRIORITY", sizeof("PRIORITY"));
      sciDisplayText(sciREGx, txtCRLF, sizeof(txtCRLF));
      es = (struct ccl_state *)mem_malloc(sizeof(struct ccl_state));
      if (es != NULL)
      {
        es->state = ES_ACCEPTED;
        es->pcb = newpcb;
        es->retries = 0;
        es->p = NULL;
        sciDisplayText(sciREGx, txtCRLF, sizeof(txtCRLF));
        sciDisplayText(sciREGx, (uint8_t*)"ACCEPTED", sizeof("ACCEPTED"));
        sciDisplayText(sciREGx, txtCRLF, sizeof(txtCRLF));
        tcp_arg(newpcb, es);
        tcp_recv(newpcb, ccl_recv);
        tcp_err(newpcb, ccl_error);
        ret_err = ERR_OK;
      }
      else
      {
        ret_err = ERR_MEM;
      }
      return ret_err;
    }
    
    err_t ccl_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
    {
      struct ccl_state *es;
      err_t ret_err;
      LWIP_ASSERT("arg != NULL",arg != NULL);
      es = (struct ccl_state *)arg;
      if (p == NULL)
      {
        es->state = ES_CLOSING;
        if(es->p == NULL)
        {
           ccl_close(tpcb, es);
           sciDisplayText(sciREGx, txtCRLF, sizeof(txtCRLF));
           sciDisplayText(sciREGx, (uint8_t*)"CLOSE", sizeof("CLOSE"));
           sciDisplayText(sciREGx, txtCRLF, sizeof(txtCRLF));
        }
        else
        {
          ccl_send(tpcb, es);
        }
        ret_err = ERR_OK;
      }
      else if(err != ERR_OK)
      {
        if (p != NULL)
        {
            es->p = NULL;
            pbuf_free(p);
        }
        ret_err = err;
        sciDisplayText(sciREGx, txtCRLF, sizeof(txtCRLF));
        sciDisplayText(sciREGx, (uint8_t*)"P ERROR", sizeof("P ERROR"));
        sciDisplayText(sciREGx, txtCRLF, sizeof(txtCRLF));
      }
    
      else if(es->state == ES_ACCEPTED)
      {
        es->state = ES_RECEIVED;
        es->p = p;
        ccl_send(tpcb, es);
        ret_err = ERR_OK;
      }
    
      else if (es->state == ES_RECEIVED)
      {
        if(es->p == NULL)
        {
            es->p = p;
            ccl_send(tpcb, es);
        }
        else
        {
            struct pbuf *ptr;
            ptr = es->p;
            pbuf_chain(ptr,p);
        }
          ret_err = ERR_OK;
      }
      else if(es->state == ES_CLOSING)
      {
        tcp_recved(tpcb, p->tot_len);
        es->p = NULL;
        pbuf_free(p);
        ret_err = ERR_OK;
      }
      else
      {
        tcp_recved(tpcb, p->tot_len);
        es->p = NULL;
        pbuf_free(p);
        ret_err = ERR_OK;
      }
      return ret_err;
    }
    
    void ccl_error(void *arg, err_t err)
    {
      struct ccl_state *es;
      LWIP_UNUSED_ARG(err);
      es = (struct ccl_state *)arg;
      if (es != NULL)
      {
        mem_free(es);
      }
    }
    
    void ccl_close(struct tcp_pcb *tpcb, struct ccl_state *es)
    {
      tcp_arg(tpcb, NULL);
      tcp_sent(tpcb, NULL);
      tcp_recv(tpcb, NULL);
      tcp_err(tpcb, NULL);
      tcp_poll(tpcb, NULL, 0);
    
      if (es != NULL)
      {
        mem_free(es);
      }
      tcp_close(tpcb);
    }
    
    void ccl_send(struct tcp_pcb *tpcb, struct ccl_state *es)
    {
        struct pbuf *ptr;
        err_t wr_err = ERR_OK;
        while ((wr_err == ERR_OK) &&
                 (es->p != NULL) &&
                 (es->p->len <= tcp_sndbuf(tpcb)))
          {
          ptr = es->p;
          wr_err = tcp_write(tpcb, ptr->payload, ptr->len, 1);
          tcp_output(tpcb);
          if (wr_err == ERR_OK)
          {
             u16_t plen;
             u8_t freed;
             plen = ptr->len;
             es->p = ptr->next;
             if(es->p != NULL)
             {
                 pbuf_ref(es->p);
             }
             do
              {
                freed = pbuf_free(ptr);
              } while(freed == 0);
             tcp_recved(tpcb, plen);
           }
           else if(wr_err == ERR_MEM)
           {
             es->p = ptr;
           }
           else
           {
           }
        }
    }
    
    void local_center_init(void)
    {
      ccl_pcb = tcp_new();
    
      sciDisplayText(sciREGx, txtCRLF, sizeof(txtCRLF));
      sciDisplayText(sciREGx, (uint8_t*)"NEW PCB", sizeof("NEW PCB"));
      sciDisplayText(sciREGx, txtCRLF, sizeof(txtCRLF));
    
      if (ccl_pcb != NULL)
      {
        err_t err;
    
        struct ip_addr remota;
        IP4_ADDR(&remota,0,0,0,0);
        err = tcp_bind(ccl_pcb,&remota,200);
    
        if (err == ERR_OK)
        {
          ccl_pcb = tcp_listen(ccl_pcb);
          tcp_accept(ccl_pcb, ccl_accept);
        }
        else
        {
        }
      }
      else
      {
      }
    }
    
    void EMAC_LwIP_Main (uint8_t * macAddress)
    {
       unsigned int   ipAddr;
       struct in_addr devIPAddress;
    
       sciInit();
    
     IntMasterIRQEnable();
     _enable_FIQ();
    
     sciDisplayText(sciREGx, txtEnetInit, sizeof(txtEnetInit));
    
     ipAddr = lwIPInit(0, macAddress, 0, 0, 0, IPADDR_USE_DHCP);
    
     sciDisplayText(sciREGx, (uint8_t*)"..WAIT", sizeof("..WAIT"));
     sciDisplayText(sciREGx, txtCRLF, sizeof(txtCRLF));
    
     if (0 == ipAddr) {
       sciDisplayText(sciREGx, txtCRLF, sizeof(txtCRLF));
       sciDisplayText(sciREGx, txtCRLF, sizeof(txtCRLF));
       sciDisplayText(sciREGx, txtErrorInit, sizeof(txtErrorInit));
       sciDisplayText(sciREGx, txtCRLF, sizeof(txtCRLF));
       sciDisplayText(sciREGx, txtCRLF, sizeof(txtCRLF));
     } else {
    
       devIPAddress.s_addr = ipAddr;
       txtIPAddrItoA = (uint8_t *)inet_ntoa(devIPAddress);
    
       sciDisplayText(sciREGx, txtCRLF, sizeof(txtCRLF));
       sciDisplayText(sciREGx, txtCRLF, sizeof(txtCRLF));
    
       sciDisplayText(sciREGx, txtTitle, sizeof(txtTitle));
       sciDisplayText(sciREGx, txtCRLF, sizeof(txtCRLF));
    
       sciDisplayText(sciREGx, txtTI, sizeof(txtTI));
       sciDisplayText(sciREGx, txtCRLF, sizeof(txtCRLF));
    
       sciDisplayText(sciREGx, txtLittleEndian, sizeof(txtLittleEndian));
       sciDisplayText(sciREGx, txtCRLF, sizeof(txtCRLF));
    
       sciDisplayText(sciREGx, txtIPAddrTxt, sizeof(txtIPAddrTxt));
       sciDisplayText(sciREGx, txtIPAddrItoA, 16);
       sciDisplayText(sciREGx, txtCRLF, sizeof(txtCRLF));
    
       local_center_init();
    
    while (1) {}
     }
    }

  • Hi Lida,

    I assume you have solved the issue with your echo-tcp code.

  • Hi QJ Wang, thank you very much for your attention.