Set it up using tcpip_init().  For DHCP (started after the phy is configured), 
my startup is:
{
   ip_addr_t eth0ipaddr, eth0netmask, eth0gw;
   IP4_ADDR(&eth0gw, 0,0,0,0);  // Gateway is for routing.  Not used here.
   IP4_ADDR(&eth0ipaddr, 0,0,0,0);  // for DHCP, start with this IP 
   IP4_ADDR(&eth0netmask, 255,255,255,0);
   tcpip_init( NULL, NULL);
   netif_add( &g_NetIF, &eth0ipaddr, &eth0netmask, &eth0gw, NULL, 
ethernetif_init, tcpip_input);
   // Start netif using DHCP or stop netif if the phy link goes down
}
 
Marty

________________________________

From: [email protected] 
[mailto:[email protected]] On Behalf Of 
furiantes
Sent: Thursday, May 23, 2013 12:47 PM
To: Mailing list for lwIP users
Subject: Re: [lwip-users] LPC1768/9 LAN8720 FreeRTOS 7.4 LWIP 1.4.1


Thank you for your reply! I will see that options too. As I see the lwip is 
already have a thread to serve TCP (main_lwip_thread)

This is actully main part of TCP for lwip, if i understand right.

A source from 


lwIP / api / tcpip.c


/**
 * The main lwIP thread. This thread has exclusive access to lwIP core functions
 * (unless access to them is not locked). Other threads communicate with this
 * thread using message boxes.
 *
 * It also starts all the timers to make sure they are running in the right
 * thread context.
 *
 * @param arg unused argument
 */
extern struct netif *pxNetIfInUse;
sys_mbox_t *toOutput;
extern uint32_t cableState;
static void
tcpip_thread(void *arg)
{
  struct tcpip_msg *msg;
  LWIP_UNUSED_ARG(arg);

  if (tcpip_init_done != NULL) {
    tcpip_init_done(tcpip_init_done_arg);
  }
  toOutput = &mbox;
  LOCK_TCPIP_CORE();
  while (1) {                          /* MAIN Loop */
    UNLOCK_TCPIP_CORE();
    LWIP_TCPIP_THREAD_ALIVE();
    /* wait for a message, timeouts are processed while waiting */
    sys_timeouts_mbox_fetch(&mbox, (void **)&msg);
    LOCK_TCPIP_CORE();
    switch (msg->type) {
#if LWIP_NETCONN
    case TCPIP_MSG_API:
      LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: API message %p\n", (void *)msg));
      msg->msg.apimsg->function(&(msg->msg.apimsg->msg));
      break;
#endif /* LWIP_NETCONN */

#if !LWIP_TCPIP_CORE_LOCKING_INPUT
    case TCPIP_MSG_INPKT:
      LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: PACKET %p\n", (void *)msg));
#if LWIP_ETHERNET
      if (msg->msg.inp.netif->flags & (NETIF_FLAG_ETHARP | 
NETIF_FLAG_ETHERNET)) {
        ethernet_input(msg->msg.inp.p, msg->msg.inp.netif);
      } else
#endif /* LWIP_ETHERNET */
      {
        ip_input(msg->msg.inp.p, msg->msg.inp.netif);
      }
      memp_free(MEMP_TCPIP_MSG_INPKT, msg);
      break;
#endif /* LWIP_TCPIP_CORE_LOCKING_INPUT */

#if LWIP_NETIF_API
    case TCPIP_MSG_NETIFAPI:
      LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: Netif API message %p\n", (void 
*)msg));
      msg->msg.netifapimsg->function(&(msg->msg.netifapimsg->msg));
      break;
#endif /* LWIP_NETIF_API */

#if LWIP_TCPIP_TIMEOUT
    case TCPIP_MSG_TIMEOUT:
      LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: TIMEOUT %p\n", (void *)msg));
      sys_timeout(msg->msg.tmo.msecs, msg->msg.tmo.h, msg->msg.tmo.arg);
      memp_free(MEMP_TCPIP_MSG_API, msg);
      break;
    case TCPIP_MSG_UNTIMEOUT:
      LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: UNTIMEOUT %p\n", (void *)msg));
      sys_untimeout(msg->msg.tmo.h, msg->msg.tmo.arg);
      memp_free(MEMP_TCPIP_MSG_API, msg);
      break;
#endif /* LWIP_TCPIP_TIMEOUT */
/*my add on i will delete that and add a Martys solution*/
    case 165:
    {
        if(cableState == 0)
        {
                netif_set_link_down(pxNetIfInUse);
        }
        else
        {
                netif_set_link_up(pxNetIfInUse);
        }

        break;
    }

    case TCPIP_MSG_CALLBACK:
      LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: CALLBACK %p\n", (void *)msg));
      msg->msg.cb.function(msg->msg.cb.ctx);
      memp_free(MEMP_TCPIP_MSG_API, msg);
      break;

    case TCPIP_MSG_CALLBACK_STATIC:
      LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: CALLBACK_STATIC %p\n", (void 
*)msg));
      msg->msg.cb.function(msg->msg.cb.ctx);
      break;

    default:
      LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: invalid message: %d\n", 
msg->type));
      LWIP_ASSERT("tcpip_thread: invalid message", 0);
      break;
    }
  }
}



Dne 23.5.2013 17:28, piše FreeRTOS Info:


        
        
        On 23/05/2013 16:20, Pomeroy, Marty wrote:

                If I'm seeing this right, you are polling for link status, and 
want to
                figure out which is the better way to poll.
                
                First, all tcpip thread stuff MUST be done on the tcpip thread, 
so DO
                NOT call it from the timer interrupt.  Option 2 is eventually 
going to
                cause errors.
                
                But better still, most phy chips will generate an interrupt 
when a cable
                is inserted or pulled.  In that interrupt, send a message to 
update
                status.  My interrupt is basically:
                   tcpip_callback_with_block( s_HandlePhyInterrupt, NULL, 0);
                This passes a static function to be called from the tcpip 
thread.
                
                That's my preference - use the interrupt, let the phy chip 
notify your
                code when there is a change, have the interrupt pass a task-time
                interrupt handler to the tcpip thread.

        Normally in a FreeRTOS application you would want this to be event
        driven.  There are some example FreeRTOS lwIP integrations you can use
        as examples, but the general approach (although for different stack) can
        be seen in the example code at the bottom of this page:
        
        http://www.freertos.org/Pend-on-multiple-rtos-objects.html
        
        In this code the cable in/out interrupt would be packaged as a
        eNetworkDownEvent event.
        Regards,
        Richard.
        
        + http://www.FreeRTOS.org
        Designed for microcontrollers. More than 103000 downloads in 2012.
        
        + http://www.FreeRTOS.org/plus
        Trace, safety certification, FAT FS, TCP/IP, training, and more...
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        

                Marty
                 
                
                -----Original Message-----
                From: [email protected]
                [mailto:[email protected]] 
On
                Behalf Of furiantes
                Sent: Wednesday, May 22, 2013 9:56 AM
                To: [email protected]
                Subject: [lwip-users] LPC1768/9 LAN8720 FreeRTOS 7.4 LWIP 1.4.1
                
                Hello,
                
                first sorry for my english.
                
                I have a bit of problem don't to do this properly, what is a 
correct way
                (both ways are working). I want to make a lwip cable ON/OFF 
bulletproof.
                
                First my HW config is:
                
                - LPC1768 (i do with LPC1769 too)
                - LAN8720
                
                SW:
                - FreeRTOS 7.4
                - LWIP 1.4.1
                     - DHCP
                     - TCP
                
                I execute a TCP connection to some adress like 
www.example.com/file.txt 
                -> download that file (this is working at is looking)
                
                My code for init part is like:
                
                     setupHardware();
                     static struct s_network_config net;
                     net.use_dhcp = 1; // set to 1 to enable DHCP. Or set to 0 
and fill
                the struct manually
                     tcpip_init(network_init, &net);
                     InitDelayTimer();
                     xTaskCreate(hc_task, ( signed portCHAR * ) "send 
hc",1536u, NULL,
                TCPIP_THREAD_PRIO, NULL);
                     vTaskStartScheduler();
                
                So main lwip thread is in seperate thread, my connection is 
started in
                hc_task so it's seperated thread.
                
                I have a 2second timer too. From which i am checking my PHY and 
i am
                want to do a procedure now to handle cable 
disconetion/connection.
                
                I am guessing the right way:
                
                1. send a "special" message box to main lwip thread  so add a 
case and
                call a netif_set_link_down(pxNetIfInUse);,
                netif_set_link_up(pxNetIfInUse); 2. or in timer interrupt call
                netif_set_link_down(pxNetIfInUse);,
                netif_set_link_up(pxNetIfInUse);
                
                I want to restart DHCP and KILL TCP connection to start it 
again.
                
                So what is "more" right:
                
                - call in interrupt
                - or send a message box to mainlwip thread
                
                
                (code is simplified, for cable off i actual call function only 
once no
                matter this is actually a timer interrupt called in 2 sec 
intervalls)
                if(cableState == 0)
                         {
                             //link off
                             iface_up = 0;
                             netif_set_link_down(pxNetIfInUse); //method 2
                
                             /*method 1
                             msg.type= 165;
                             msg.msg.inp.netif = pxNetIfInUse;
                             res = sys_mbox_trypost(toOutput, &msg);*/
                
                         }
                         else
                         {
                             //link on
                             netif_set_link_up(pxNetIfInUse); //method 2
                
                             /*Method 1
                             msg.type= 165;
                             msg.msg.inp.netif = pxNetIfInUse;
                             res = sys_mbox_trypost(toOutput, &msg);
                             */
                         }
                
                
                
                Code:
                static void hc_task(void *parameters)
                {
                     struct hc_message mes;
                     mes.client_port_number = 4839;
                     mes.host_addres = "192.168.1.183\0";
                     mes.host_add[0] = 192;
                     mes.host_add[1] = 168;
                     mes.host_add[2] = 1;
                     mes.host_add[3] = 183;
                     mes.host_file = "test/data.php\0";
                     mes.host_port_number = 80;
                     mes.target = "http://192.168.1.183/test/data.php\0"; 
<http://192.168.1.183/test/data.php\0> ;
                     transferEnd = 0;
                     numberOfPacketsProc = 0;
                     totalRecievedSize = 0;
                     hc_send(&mes, 0);
                     vTaskDelete(NULL);
                }
                
                
                The hc_send thread:
                uint_fast8_t hc_send(const struct hc_message *mes, int8_t 
addParam) {
                
                     while(!is_netiface_up())
                     {
                         vTaskDelay(500);
                     }
                
                     if(bufferTmp == NULL)
                     {
                         bufferTmp = (char *) pvPortMalloc((PBUF_POOL_BUFSIZE +
                1)*sizeof(*bufferTmp));
                     }
                
                     if(bigDataBuffer == NULL)
                     {
                         bigDataBuffer = (char
                *)pvPortMalloc((256*12)*sizeof(*bigDataBuffer));
                     }
                
                
                     bufferCounterWriter = 0;
                     numberOfPacketsProc = 0;
                     totalRecievedSize = 0;
                     recieveTimer = 0;
                     stateFlag = 0;
                     transferEnd = 0;
                
                     struct ip_addr remote_ipaddr;
                     err_t ret_code = ERR_OK;
                
                     pcbHolder = tcp_new();
                     if(NULL == pcbHolder)
                     {
                         printf("tcp_new(): echec PCBHOLDER IS NULLLL.\n\r");
                         return -1;
                     }
                
                     tcp_err(pcbHolder, err_hc_tcp);
                
                     //for reconnect detection
                     if(addParam == 1)
                     {
                         //tcp_close(pcbHolder);
                         //pcbHolder = tcp_new();
                         if(NULL == pcbHolder)
                         {
                             printf("tcp_new(): echec. PCB HOLDER RETURN\n\r");
                             return -1;
                         }
                     }
                
                
                     //int portRead = mes->client_port_number;
                     IP4_ADDR(&remote_ipaddr, mes->host_add[0], 
mes->host_add[1], 
                mes->host_add[2], mes->host_add[3]);
                
                      ret_code = tcp_connect(pcbHolder, &remote_ipaddr, 
                mes->host_port_number, client_connected_my);
                      if(ERR_OK != ret_code)
                      {
                              printf("tcp_connect(): error RETURN -1\n\r");
                              return -1;
                      }
                
                
                      sprintf(request_my_c, "GET /%s HTTP/1.1\r\nAccept: 
                */*\r\nAccept-Language: sl\r\nUser-Agent: Mozilla/4.0 
(compatible; MSIE 
                5.01; Windows NT 5.0)\r\nHost: %s:%d\r\nConnection: 
Close\r\n\r\n", 
                mes->host_file, mes->host_addres, mes->host_port_number);
                      printf("%s", request_my_c);//
                
                      nsend_my_c = 0;
                      totalsend_my_c = 0;
                      nbytes_my_c=strlen(request_my_c);
                
                     return 0;
                }
                
                
                
                _______________________________________________
                lwip-users mailing list
                [email protected]
                https://lists.nongnu.org/mailman/listinfo/lwip-users
                
                _______________________________________________
                lwip-users mailing list
                [email protected]
                https://lists.nongnu.org/mailman/listinfo/lwip-users
                

        _______________________________________________
        lwip-users mailing list
        [email protected]
        https://lists.nongnu.org/mailman/listinfo/lwip-users
        


_______________________________________________
lwip-users mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/lwip-users

Reply via email to