Seesaw

FreeRTOS Two Tasks Sharing a Beat Exercise

Task

A seesaw in a science museum rocks by itself. One FreeRTOS task lifts its end and logs UP, the other lowers its end and logs DOWN. A technician reads the tick count on each line to check both ends move together. The tick is FreeRTOS's clock. Ticks come every millisecond.

Write up_task and down_task, two tasks at priority 1 named UP and DOWN, made in that order. Each says its name with say(), then waits 20 ms, for as long as the board runs: 0 UP, 0 DOWN, 20 UP, 20 DOWN, 40 UP and on, one per line The FreeRTOS calls for this are xTaskCreate, vTaskStartScheduler and vTaskDelay; the Reference tab shows each one.

Circuit

Block diagram: inside U1 STM32F4, the up task and the down task, both at priority 1, print their names through the given say(), which stamps each with the FreeRTOS tick count, out of USART1 TX, PA9, to a terminal

Pass condition

Each line shows the tick it was said on. UP then DOWN come on the same tick, on ticks 0, 20, 40 and on.

Expected output for the first 100 ms: UP then DOWN on ticks 0, 20, 40, 60, 80 and 100, both ends on the same tick, twelve lines in all

Notes

Leave the given code as is. FreeRTOS V11.1.0. The millisecond tick counts from the moment the scheduler starts. On this board, tasks of the same priority first run in the order they were made.

Related challenges

Loading the interactive arena.