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
Pass condition
For each shot, PA5 flips within 1 ms, then one START n line prints, in order.
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.