The embedded WEB server implementation presented here uses a hardware TCP/IP co-processor. This demo is one of 4 embedded Ethernet demos currently available for download.
The standard FreeRTOS demo application is intended to be used as a reference and as a starting point for new applications. This embedded WEB server demo is included in addition to the standard demo to provide a more application orientated example.
This application does not include a fully featured WEB server but does provide a working, preemptive, multitasking example that includes an interrupt driven I2C driver and an interrupt driven interface with a WIZnet W3100A TCP/IP coprocessor.
The processor operates in THUMB mode wherever possible.
The download includes the following files:
In addition the flash.c file from the standard demo application is required.
The WEB server task:
The WEB server task spends most of its time blocked waiting for interrupts from either the WIZnet TCP/IP processor or the I2C peripheral.
This is a very basic implementation that allows a single connection at a time, and closes the connection as soon as the HTML page transmission has completed.
The I2C driver manages a pool of 'messages' (see the xI2CMessage structure defined in i2c.h). When an application task calls i2cMessage() the I2C driver fills an xI2CMessage structure with the message details - then places the new xI2CMessage structure into a queue of messages waiting to be actioned. This way the application task can continue executing without having to wait for the I2C message to be transacted.
The I2C interrupt routines handles the peripheral generated events to send/receive data over the I2C bus. When a message has completed it checks the queue to see if any further message are waiting to be transmitted. If so the next message is removed from the queue and transmission starts immediately.
By using the xMessageCompleteSemaphore parameter of the i2cMessage() function an application task can optionally wait (block) until the I2C message has been completely transacted. While it is blocked the other tasks will execute. This is particularly relevant when reading data over the I2C bus as the application task needs to know when the data has been received.
The C0_ISR register within the WIZnet device is used to determine the cause of the interrupt, but the I2C interface means that C0_ISR cannot be read from within the interrupt service routine. In addition the assertion of the interrupt cannot be cleared as this too requires writing to the WIZnet device, again over the I2C bus.
With the interrupt (EINT0) still being asserted the only way of leaving the interrupt service routine is to disable the I2C interrupt within the microcontroller (otherwise the interrupt service routine would be immediately re-entered). After disabling the interrupt the service routine unblocks the WEB server task - which must then immediately read the C0_ISR register, clear the interrupts, then re-enable the I2C interrupts in the microcontroller. It is important therefore that the WEB server task is the highest priority task - thus ensuring that it always executes immediately following an EINT0 interrupt.
The comments in the source code provide more details.
Any and all data, files, source code, html content and documentation included in the FreeRTOS distribution or available on this site are the exclusive property of Richard Barry.
See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Richard Barry.