lwip-users
[Top][All Lists]
Advanced

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

[lwip-users] LWIP client code causes hard fault error


From: shettys
Subject: [lwip-users] LWIP client code causes hard fault error
Date: Tue, 26 Jun 2012 03:53:13 -0700 (PDT)

Hello,

Could somebody please help me with my problem in setting up a TCP client.
The code is as posted below.
I call the TCPConnection_start before i go into the main loop, which
initializes the connection. Then i call the TCP_send periodically( to send
some ADC values).
When my server opens a connection on Port 7 and I run my program it works
fine and the ADC values are sent. However sometimes it just goes into a hard
fault handler. Could someone please let me know where i am wrong?

void TCPConnection_start(void)
{
  struct ip_addr DestIPaddr;
 
  /* create new tcp pcb */
  pcb = tcp_new();     
  if (pcb != NULL)
  {
    IP4_ADDR( &DestIPaddr, DEST_IP_ADDR0, DEST_IP_ADDR1, DEST_IP_ADDR2,
DEST_IP_ADDR3 );
       
    /* connect to destination address/port */
    tcp_connect(pcb,&DestIPaddr,DEST_PORT,TCPConnection_Established);
  }
}

/**
  * @brief Function called when TCP connection established
  * @param tpcb: pointer on the connection contol block
  * @param err: when connection correctly established err should be ERR_OK 
  * @retval err_t: returned error 
  */
static err_t TCPConnection_Established(void *arg, struct tcp_pcb *pcb, err_t
err)
{
  if (err == ERR_OK)   
  {
  /* allocate structure es to maintain tcp connection informations */
    es = (struct echoclient *)mem_malloc(sizeof(struct echoclient));
  
    if (es != NULL)
    {
          es->state = ES_CONNECTED;
      es->pcb = pcb;
         }
   }
}


void TCP_send(void)
{
      uint32_t (*ptr)[3]; // pointer to the     ADC_TDstamped_SRAM array.
      #ifdef UserButton_InteruptFor_ADCConversion
      sprintf((char*)data, "Potentiometer value is, %d\n",
ADC3ConvertedValue);

      /* allocate pbuf */
      es->p_tx = pbuf_alloc(PBUF_TRANSPORT, strlen((char*)data) ,
PBUF_POOL);
         
      if (es->p_tx)
      {       
     
            /* copy data to pbuf */
        pbuf_take(es->p_tx, (char*)data, strlen((char*)data));
        
        /* send data */
                TCPData_send(pcb,es);
      }
}

  
/**
  * @brief function used to send data
  * @param  tpcb: tcp control block
  * @param  es: pointer on structure of type echoclient containing info on
data 
  *             to be sent
  * @retval None 
  */
static void TCPData_send(struct tcp_pcb *pcb, struct echoclient * es)
{
  struct pbuf *ptr;
  err_t wr_err = ERR_OK;
 
  while ((wr_err == ERR_OK) &&
         (es->p_tx != NULL) && 
         (es->p_tx->len <= tcp_sndbuf(pcb)))
  {
    
    /* get pointer on pbuf from es structure */
    ptr = es->p_tx;

    /* enqueue data for transmission */
    wr_err = tcp_write(pcb, ptr->payload, ptr->len, 1);
    
    if (wr_err == ERR_OK)
    { 
      /* continue with next pbuf in chain (if any) */
      es->p_tx = ptr->next;
      
      if(es->p_tx != NULL)
      {
        /* increment reference count for es->p */
        pbuf_ref(es->p_tx);
      }
      
      /* free pbuf: will free pbufs up to es->p (because es->p has a
reference count > 0) */
      pbuf_free(ptr);
   }
   else if(wr_err == ERR_MEM)
   {
      /* we are low on memory, try later, defer to poll */
     es->p_tx = ptr;
   }
   else
   {
    }
  }
}
-- 
View this message in context: 
http://old.nabble.com/LWIP-client-code-causes-hard-fault-error-tp34071696p34071696.html
Sent from the lwip-users mailing list archive at Nabble.com.




reply via email to

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