eLua platform interface - Ethernet support


NOTE: TCP/IP support is experimental in eLua. Although functional, it's quite incomplete at the moment.

This part of the platform interface groups functions related to accessing the Ethernet interface (internal or external) of the CPU. Note that unlike the other parts of the platform interface this one is dedicated for TCP/IP support and thus it does not correspond directly to an eLua module, although the net module is implemented with functions that rely on this part of the platform interface. Currently only the uIP TCP/IP stack is supported by eLua.

uIP is implemented in eLua using two hardware interrupts (that should be available on your platform): the Ethernet receive interrupt (to handle incoming packets) and a timer interrupt (timers are used internally by uIP). However, the uIP main loop is only called from the Ethernet interrupt handler in eLua, so in order to acknowledge the timer interrupt (as well as to provide some optimizations) a function that "forces" an Ethernet interrupt must also be provided by the platform interface (see here for details).

To put everything together, part of the Ethernet platform interface for the lm3s platform is given below:

u32 platform_eth_get_elapsed_time()
    if( eth_timer_fired )
      eth_timer_fired = 0;
      return SYSTICKMS;
      return 0;

  void SysTickIntHandler()
    // Handle virtual timers

    // Indicate that a SysTick interrupt has occurred.
    eth_timer_fired = 1;

    // Generate a fake Ethernet interrupt.  This will perform the actual work
    // of incrementing the timers and taking the appropriate actions.

  void EthernetIntHandler()
    u32 temp;

    // Read and Clear the interrupt.
    temp = EthernetIntStatus( ETH_BASE, false );
    EthernetIntClear( ETH_BASE, temp );

    // Call the UIP main loop