![]() |
Using a compile time option (described below), the project can be configured to either create a basic blinky style demo, or a more comprehensive test and demo application that includes tasks that exercise the interrupt nesting behaviour.
See also the FAQ My application does not run, what could be wrong?
The FreeRTOS demo application is dependent on the CMSIS library, which is provided as a separate LPCXpresso project. The demo application project and the CMSIS project must both be imported into an LPCXpresso workspace. Both projects are located in subdirectories of the FreeRTOS/Demo/CORTEX_M0_LPC1114_LPCXpresso directory, and can be imported into LPCXpresso together. The Preparing the Eclipse Project section below contains important information on setting up the demo project directory, and importing the demo project into the LPCXpresso IDE.
Preparing the Eclipse project directory
Eclipse projects can be either standard makefile projects, or managed make projects.
The FreeRTOS LPCXpresso ARM Cortex-M0 project uses a managed make project. This in
turn means that either:
CreateProjectDirectoryStructure.bat must be executed before the LPCXpresso project is imported into the Eclipse workspace.
CreateProjectDirectoryStructure.bat cannot be executed from within the LPCXpresso IDE.
main_blinky() creates one queue, and two tasks. It then starts the scheduler.
The queue send task is implemented by the prvQueueSendTask() function in main_blinky.c. prvQueueSendTask() sits in a loop that causes it to repeatedly block for 200 milliseconds, before sending the value 100 to the queue that was created within main_blinky(). Once the value is sent, the task loops back around to block for another 200 milliseconds.
The queue receive task is implemented by the prvQueueReceiveTask() function in main_blinky.c. prvQueueReceiveTask() sits in a loop where it repeatedly blocks on attempts to read data from the queue that was created within main_blinky(). When data is received, the task checks the value of the data, and if the value equals the expected 100, toggles the LED. The 'block time' parameter passed to the queue receive function specifies that the task should be held in the Blocked state indefinitely to wait for data to be available on the queue. The queue receive task will only leave the Blocked state when the queue send task writes to the queue. As the queue send task writes to the queue every 200 milliseconds, the queue receive task leaves the Blocked state every 200 milliseconds, and therefore toggles the LED every 200 milliseconds.
main_full() creates a set of standard demo tasks (including a set of tasks that test the interrupt nesting behaviour), some application specific test tasks, and a timer. It then starts the scheduler.
These fill the registers with known values, then check that each register maintains its expected value for the lifetime of the task. Each task uses a different set of values. The reg test tasks execute with a very low priority, so get preempted very frequently. A register containing an unexpected value is indicative of an error in the context switching mechanism.
The check software timer period is initially set to three seconds. Its callback function checks that all the standard demo tasks, and the register check tasks, are not only still executing, but are executing without reporting any errors. If the check timer callback discovers that a task has either stalled, or reported an error, then it changes the period of the check timer from the initial three seconds, to just 200ms. The callback function also toggles the LED each time it is called. This provides a visual indication of the system status: If the LED toggles every three seconds, then no issues have been discovered. If the LED toggles every 200ms, then an issue has been discovered with at least one task.
Note that portEND_SWITCHING_ISR() will leave interrupts enabled.
The interrupt nesting test tasks require that two timers are configured to generate interrupts. The interrupt service routines are defined in IntQueueTimer.c, and can be used as examples for application writers. They do not, however, directly demonstrate the use of FreeRTOS safe API functions (those that end in "FromISR"). Therefore, a dummy interrupt implementation called Dummy_IRQHandler() is provided at the end of main.c, and duplicated below.
void Dummy_IRQHandler(void)
{
long lHigherPriorityTaskWoken = pdFALSE;
/* Clear the interrupt if necessary. */
Dummy_ClearITPendingBit();
/* This interrupt does nothing more than demonstrate how to synchronise a
task with an interrupt. A semaphore is used for this purpose. Note
lHigherPriorityTaskWoken is initialised to zero. Only FreeRTOS API functions
that end in "FromISR" can be called from an ISR. */
xSemaphoreGiveFromISR( xTestSemaphore, &lHigherPriorityTaskWoken );
/* If there was a task that was blocked on the semaphore, and giving the
semaphore caused the task to unblock, and the unblocked task has a priority
higher than the current Running state task (the task that this interrupt
interrupted), then lHigherPriorityTaskWoken will have been set to pdTRUE
internally within xSemaphoreGiveFromISR(). Passing pdTRUE into the
portEND_SWITCHING_ISR() macro will result in a context switch being pended to
ensure this interrupt returns directly to the unblocked, higher priority,
task. Passing pdFALSE into portEND_SWITCHING_ISR() has no effect. */
portEND_SWITCHING_ISR( lHigherPriorityTaskWoken );
}
Note that the following lines are included in FreeRTOSConfig.h.
#define vPortSVCHandler SVC_Handler #define xPortPendSVHandler PendSV_Handler #define xPortSysTickHandler SysTick_HandlerThese definitions map the FreeRTOS kernel interrupt handler function names onto the CMSIS interrupt handler functions names (or at least whatever is used in the unmodified vector table supplied by the compiler) - and in so doing, allow the Code Red provided linker script and start up files to be used without modification.
Attention please!: See the page dedicated to setting interrupt priorities on ARM Cortex-M devices. Remember that ARM Cortex-M cores use numerically low priority numbers to represent HIGH priority interrupts. This can seem counter-intuitive and is easy to forget! If you wish to assign an interrupt a low priority do NOT assign it a priority of 0 (or other low numeric value) as this will result in the interrupt actually having the highest priority in the system. Also, do not leave interrupt priorities unassigned, as by default they will have a priority of 0 and therefore the highest priority possible.
This sets the frequency of the RTOS tick interrupt. The supplied value of 1000Hz is useful for testing the RTOS kernel functionality, but is faster than most applications require. Lowering this value will improve efficiency.
Each port #defines 'BaseType_t' to equal the most efficient data type for that processor. This port defines BaseType_t to be of type long.
Note that vPortEndScheduler() has not been implemented.