eLua platform interface - Ethernet support
Overview
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; } else return 0; } void SysTickIntHandler() { // Handle virtual timers cmn_virtual_timer_cb(); // 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. platform_eth_force_interrupt(); } void EthernetIntHandler() { u32 temp; // Read and Clear the interrupt. temp = EthernetIntStatus( ETH_BASE, false ); EthernetIntClear( ETH_BASE, temp ); // Call the UIP main loop elua_uip_mainloop(); }
Functions
void platform_eth_send_packet( const void* src, u32 size )
Sends an Ethernet packet to the network
Arguments:
- src - start address of the Ethernet packet
- size - size of the Ethernet packet
Returns: nothing.
u32 platform_eth_get_packet_nb( void* buf, u32 maxlen );
Non-blocking read of an Ethernet packet from the network
Arguments:
- buf - start address of the receive buffer
- maxlen - maximum length of the Ethernet packet
Returns: the size of the read packet or 0 if no packet is available
void platform_eth_force_interrupt();
Force the Ethernet interrupt on the platform (see overview above for details)
Arguments: none.
Returns: nothing.
u32 platform_eth_get_elapsed_time();
Get the elapsed time (in ms) since the last invocation of the uIP main loop (elua_uip_mainloop, from which this function is called). See overview for a possible implementation of this function).
Arguments: none.
Returns:
- 0 if the uIP loop was called because of Ethernet activity, not because a timer expired
- the Ethernet timer period in ms (which indicates timer activity)