Right of Way

FreeRTOS Task Priority Exercise

Task

At a busy junction, the controller sends its morning traffic count to a console. The report takes about 175 ms to print. When a fire engine's siren is heard, every light must turn red at once to give the fire engine right of way, report or no report.

Write the two FreeRTOS tasks, and choose their priorities so a siren never waits for the report: report task: prints the report once with print_report(); siren task: calls all_red() each time wait_siren() returns. The FreeRTOS calls for this are xTaskCreate, vTaskStartScheduler and vTaskDelete; the Reference tab shows each one.

Circuit

Block diagram: U2, the siren detector, pulses PA0 of U1 STM32F4; inside U1 the siren task waits on PA0 through wait_siren() and runs all_red(), which holds PA5 high for the logic analyzer, and the report task prints through console_putc on USART1 TX, PA9, to a terminal

Pass condition

The eight report lines print whole and in order. PA5 goes high within 2 ms and low again within 7 ms of each siren.

Expected output for the one siren case: PA0 pulses high for 2 ms at 40 ms, during the report; PA5 goes high within 2 ms and low again by 47 ms, one pulse; the terminal shows the eight report lines, whole and in order

Notes

The siren detector raises PA0 for 2 ms per siren while your program runs, during the report. Leave the given code as is. FreeRTOS V11.1.0 is preemptive with a 1 ms tick. A task with a higher priority number runs as soon as it is ready.

Related challenges

Loading the interactive arena.