Previous pages have demonstrated a stand alone LPCOpen project that uses
the USB drivers built into the LPC1800 part to very easily
create a USB
virtual COM port, and a FreeRTOS LPCOpen project that
created a simple ping echo
server. This page shows how to take advantage of FreeRTOS's multi tasking
environment to very easily add the virutal COM port example into the echo
server example, so both examples run on the LPC1830 Xplorer board simultaneously.
It is assumed that all preceding steps have already been completed.
The instructions on this page combine the TCP and USB examples in a crude manner. The page that follows demonstrates how some small FreeRTOS specific updates to the code can change the run-time behaviour, and in so doing improve run-time efficiency. Improved run-time efficiency in turn allows the microcontroller to either execute a larger and more complex application, or spend more of its time in a low power state.
The following C source files within the usbd_rom_cdc_vcom project are used to implement the interface to the hardware USB drivers, define the USB CDC descriptors, and provide the simple USB CDC echo functionality respectively:
The three C source files listed above rely on the following two C header files:
Copy all five files from the usbd_rom_cdc_vcom project into the src and inc folders as apprpriate of the freertos_tcpecho project. The file copy can be done directly from the Eclipse project explorer window, or as a standard file copy (the Eclipse project will need to be refreshed if the a standard file copy is used).
View the properties for the freertos_tcpecho project by right clicking on the project in the Eclipse project explorer and selecting 'Properties' from the pop up menu.
Add /lpc_chip_18xx/inc/usbd as an include path.
Open the freertos_tcpecho.c file that was just copied into the TCP project, and located the definition of main(). Change the definition of main() from:
int main(void)to
void cdc_task( void *pvParameters )Note some of the initialisation code is also duplicated in the two main() functions (one of which was just renamed), but this can be ignored in this basic example.
This time open the freertos_cdcecho.c C source file and locate the implementation of main() it contains. It already creates an lwIP task. Add in code that also creates the Virtual COM / CDC task, as shown in the image below.
Next:
Using simple FreeRTOS techniques to massively reduce CPU usage