Page 1 of 1

Chibios+Lwip

Posted: Wed Apr 11, 2012 5:30 pm
by pacoblackxx
Hi all,

I was looking the ARM7-AT91SAM7X-LWIP-GCC example, and i saw that there is a thread called < msg_t lwip_thread(void *p) >

This is normaly not needed by the Lwip (I mean that only the ethernetif.c, sys_arch.c etc files need to be ported)

Then why is this thread used? Is there any complication in porting Lwip into Chibios? (so some kind of hack is needed)?

Also, in the same thread the declarations below are done:
sys_init();
mem_init();
memp_init();
pbuf_init();
netif_init();
ip_init();
tcpip_init(NULL, NULL);

These are normally done by lwip_init(). Why we call them here?

Thanx,
Nick

Re: Chibios+Lwip

Posted: Wed Apr 11, 2012 6:23 pm
by Giovanni
That thread is the interface between the MAC driver and lwIP, that work could be done in the main thread but usually you want to use the main thread for your application and do the TCP/IP stuff at a lower priority. I would be interested in learning a better solution, I am not a huge lwIP expert.

About initializations, this is how it was done in the example when I first ported lwIP 1.2, probably I missed the general initialization function, thank for suggesting this.

Giovanni

Re: Chibios+Lwip

Posted: Fri Apr 20, 2012 6:45 pm
by pacoblackxx
In lwip, i have a thread that is waiting for a semaphore, and a vector routine that is called every time the ethernet receives a packet. I use stm32f4 drivers, without the hall. Some times the system freezes, and no thread is working. Is something wrong with the way the interrupt communicates with the thread?


Code: Select all

/* Interrupt routine */
/* NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3; */
/*  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; */
void Vector134(void)
{
   CH_IRQ_PROLOGUE();
   chSysLockFromIsr();

   inInterrupts++;

   /* Frame received */
   if ( ETH_GetDMAFlagStatus(ETH_DMA_FLAG_R) == SET)
   {
      inPackets++;
      /* Give the semaphore to wakeup LwIP task */
      chSemSignalI(&ethernetInputSematophore);   
   }

   /* Clear the interrupt flags. */
   /* Clear the Eth DMA Rx IT pending bits */
   ETH_DMAClearITPendingBit(ETH_DMA_IT_R);
   ETH_DMAClearITPendingBit(ETH_DMA_IT_NIS);
   
   chSysUnlockFromIsr()
   CH_IRQ_EPILOGUE();
}


/* Ethrenet input monitoring (normal prio) */
msg_t ethernetInputMonitoringThread(void *arg)
{
   struct pbuf *p;
   (void)arg;chRegSetThreadName("ethernetInputMonitoringThread");
   
   print("Ehthernet Input Monitoring Thread Started@%dms\r\n",chTimeNow());

   for( ;; )
   {
      //print("Waiting for input...");
      if (chSemWaitTimeout(&ethernetInputSematophore,200)==RDY_OK)
      {
         //packet received, pass it to lwip..
         p = low_level_input( s_pxNetIf );
         if (ERR_OK != s_pxNetIf->input( p, s_pxNetIf))
         {
            pbuf_free(p);
            p=NULL;
         }
      }
      else{}
   }

   
   while (TRUE) {}
}

Re: Chibios+Lwip

Posted: Fri Apr 20, 2012 6:53 pm
by Giovanni
Signaling looks correct, just keep in mind that a counter semaphore is unbounded and can overflow if signaled faster than it is taken. Binary semaphores are better in this role.

I doubt this is your problem anyway. Make sure to enable all the debug options and see if something is caught.

Giovanni