Lab Assignment: FreeRTOS Tasks
Objective
To give you some experience in:
- Loading firmware onto the SJOne board
- Using FreeRTOS tasks and seeing how they behave
Assignment
Part 1. Fill Out the Code
Use the following code template:
- Reference the code comments for what you need to do.
- Fill out the xTaskCreate method parameters.
- See the FreeRTOS+Tasks document or checkout the FreeRTOS xTaskCreate API website.
- Do not use printf, instead use uart0_puts() function from #include "uart0_min.h"
Set the priority of the two tasks to 1 (lower number = low priority)
FreeRTOSConfig.h defines the total priority levels, but for the template project it is likely to be 4
#include "FreeRTOS.h"
#include "task.h"
#include "uart0_min.h"
void vTaskOneCode(void)
{
while(1)
{
uart0_puts("aaaaaaaaaaaaaaaaaaaa");
vTaskDelay(100); // This sleeps the task for 100ms (because 1 RTOS tick = 1 millisecond)
}
}
// Create another task and run this code in a while(1) loop
void vTaskTwoCode(void)
{
while(1)
{
uart0_puts("bbbbbbbbbbbbbbbbbbbb");
vTaskDelay(100);
}
}
// You can comment out the sample code of lpc1758_freertos project and run this code instead
int main(int argc, char const *argv[])
{
/// This "stack" memory is enough for each task to run properly
const uint32_t STACK_SIZE = 1024;
/**
* Observe and explain the following scenarios:
*
* 1) Same Priority: A = 1, B = 1
* 2) Different Priority: A = 2, B = 1
* 3) Different Priority: A = 1, B = 2
*
* Turn in screen shots of what you observed
* as well as an explanation of what you observed
*/
xTaskCreate(vTaskOneCode, /* Fill in the rest parameters for this task */ );
xTaskCreate(vTaskTwoCode, /* Fill in the rest parameters for this task */ );
/* Start Scheduler - This will not return, and your tasks will start to run their while(1) loop */
vTaskStartScheduler();
return 0;
}
Code Block 1: Main.cpp
Part 2: Make observations of the output
- How come 4(or 3 sometimes) characters are printed from each task? Why not 2 or 5, or 6?
- Alter the priority of one of the tasks, and note down the observations. Note down WHAT you see and WHY.
Hints
- The printf data appears over 38400bps UART, which can roughly send 4 characters per millisecond
- When you send 20 chars (aaaaaaaaaaaaaaaaaaaa), it would take roughly 5ms to send the data
- The SJ-One board RTOS runs at 1Khz meaning that 1 RTOS tick is 1 millisecond
Part 3. Change the priority levels
Now that you have the code running with identical priority levels do the following:
- Change the priority of the two tasks.
- A=1, B=1
- A=2, B=1
- A=1, B=2
- Take a screenshot of what you see from the console.
- Write an explanation of why you think the output came out the way it did using your knowledge about RTOS.
What to turn in (to Canvas as PDF):
- Relevant code
- Your observation and explanation
- Snapshot of the output for all scenarios.