Baton

FreeRTOS Binary Semaphore Exercise

Task

At a running track, a sensor on the starter's pistol raises PA0 when it fires. The start light on PA5 must flip that instant, and the race log must print START with the race number. The task that flips the light is a relay runner. It waits with a hand held out behind it for the baton.

Write the two FreeRTOS tasks, handing each start from one to the other with a binary semaphore: starter task, priority 1: each time wait_gun() returns, gives the semaphore, then prints the race with print_start(n), n counting from 1; light task, priority 2: calls flip_light() each time it takes the semaphore. The FreeRTOS calls for this are xTaskCreate, vTaskStartScheduler, xSemaphoreCreateBinary, xSemaphoreTake and xSemaphoreGive; the Reference tab shows each one.

Circuit

Block diagram: U2, the gun sensor, pulses PA0 of U1 STM32F4; inside U1 the starter task waits on PA0 through wait_gun() and hands each start to the light task through a binary semaphore; the light task flips the start light on PA5; the starter task prints through console_putc on USART1 TX, PA9, to a terminal

Pass condition

For each shot, PA5 flips within 1 ms, then one START n line prints, in order.

Expected output for the one start case: PA0 pulses high for 2 ms at 30 ms; PA5 flips high within 1 ms, once, before the START 1 line prints; the terminal shows START 1

Notes

The pistol sensor raises PA0 for 2 ms per shot while your program runs. 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.