lwip-users
[Top][All Lists]
Advanced

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

Re: [lwip-users] lwip: Scan through the heap searching for a free block


From: vrnud
Subject: Re: [lwip-users] lwip: Scan through the heap searching for a free block that is big enough, beginning with the lowest free block.
Date: Thu, 28 Mar 2019 01:20:30 -0700 (MST)

HI,

I am very new to the tcpip world.

  netif_add(&gnetif, &ipaddr, &netmask, &gw, NULL, &ethernetif_init,
&tcpip_input);
is called from MX_LWIP_Init() function.

"But "raw" APIs functions must ONLY be called from TCPIP thread."
I dont know how to do that. can you please provide some example for the
same.

or example for 
" tcpip_callback() can be used get called back from TCPIP thread, it is safe
to call any "raw" APIs from there."

"Use LWIP_TCPIP_CORE_LOCKING. All "raw" APIs functions can be called when
lwIP core lock is aquired, see LOCK_TCPIP_CORE() and UNLOCK_TCPIP_CORE().
These macros cannot be used in an interrupt context! Note the OS must
correctly handle priority inversion for this."
LWIP_TCPIP_CORE_LOCKING is set 1 in code.

below is the code 
void tcp_echoserver_init(void)
{

  /* create new tcp pcb */
  tcp_echoserver_pcb = tcp_new();

  if (tcp_echoserver_pcb != NULL)
  {
    err_t err;
    
    /* bind echo_pcb to port 7 (ECHO protocol) ;7 FOR ECHO, 502 FOR MODBUS*/
    err = tcp_bind(tcp_echoserver_pcb, IP_ADDR_ANY, 502);
    
    if (err == ERR_OK)
    {
      /* start tcp listening for echo_pcb */
      tcp_echoserver_pcb = tcp_listen(tcp_echoserver_pcb);
      
      /* initialize LwIP tcp_accept callback function */
      tcp_accept(tcp_echoserver_pcb, tcp_echoserver_accept);
    }
    else 
    {
      /* deallocate the pcb */
      memp_free(MEMP_TCP_PCB, tcp_echoserver_pcb);
    }
  }

}

/**
  * @brief  This function is the implementation of tcp_accept LwIP callback
  * @param  arg: not used
  * @param  newpcb: pointer on tcp_pcb struct for the newly created tcp
connection
  * @param  err: not used 
  * @retval err_t: error status
  */
static err_t tcp_echoserver_accept(void *arg, struct tcp_pcb *newpcb, err_t
err)
{
  err_t ret_err;
  struct tcp_echoserver_struct *es;

  LWIP_UNUSED_ARG(arg);
  LWIP_UNUSED_ARG(err);

  /* set priority for the newly accepted tcp connection newpcb */
  tcp_setprio(newpcb, TCP_PRIO_MIN);

  /* allocate structure es to maintain tcp connection informations */
  es = (struct tcp_echoserver_struct *)mem_malloc(sizeof(struct
tcp_echoserver_struct));
  if (es != NULL)
  {
    es->state = ES_ACCEPTED;
    es->pcb = newpcb;
    es->retries = 0;
    es->p = NULL;
 
                if(gu8_addrs_chng_Link_break)
                {
                        gu8_addrs_chng_Link_break = 0;
                }

        
    /* pass newly allocated es structure as argument to newpcb */
    tcp_arg(newpcb, es);
    
    /* initialize lwip tcp_recv callback function for newpcb  */ 
    tcp_recv(newpcb, tcp_echoserver_recv);
    
    /* initialize lwip tcp_err callback function for newpcb  */
    tcp_err(newpcb, tcp_echoserver_error);
    
    /* initialize lwip tcp_poll callback function for newpcb */
    tcp_poll(newpcb, tcp_echoserver_poll, 0);
    
    ret_err = ERR_OK;
  }
  else
  {
    /*  close tcp connection */
    tcp_echoserver_connection_close(newpcb, es);
    /* return memory error */
    ret_err = ERR_MEM;
  }
  return ret_err;  
}

I am getting problem for particular this line
  /* allocate structure es to maintain tcp connection informations */
  es = (struct tcp_echoserver_struct *)mem_malloc(sizeof(struct
tcp_echoserver_struct));

Regards,
Vrund



--
Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html



reply via email to

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