First Shift

First FreeRTOS Task Exercise

Task

At a factory gate, the night shift starts when the doors open. The gate's controller prints OPEN once when it powers up. Then it logs every car that drives in all night, so the guard can check arrivals in the morning.

Print OPEN once, then CAR n for each car, counting n from 1, for as long as the board runs: OPEN, CAR 1, CAR 2, CAR 3 and on, one per line Write gate_task, a FreeRTOS task at priority 1 that prints CAR n each time wait_car() returns, and the rest of main, which prints OPEN and gets the task running. The FreeRTOS calls for this are xTaskCreate and vTaskStartScheduler; the Reference tab shows each one.

Circuit

Block diagram: U2, the car sensor at the gate, pulses PA0 of U1 STM32F4 as each car passes; inside U1, main runs first, and the gate task waits on PA0 through wait_car() and prints through print_line and print_car on USART1 TX, PA9, to a terminal

Pass condition

OPEN prints, then one CAR line per car, in order. CAR 1 prints within 2 ms of the first car reaching PA0.

Expected output for three cars: PA0 pulses high for 5 ms at 20, 45 and 80 ms; the terminal shows OPEN at power up, then CAR 1, CAR 2 and CAR 3, the first within 2 ms of its car

Notes

The car sensor drives PA0 high for 5 ms as each car passes, while your program runs. Leave the given code as is. FreeRTOS V11.1.0. A task is a function FreeRTOS runs on its own. Priority 1 is a task's urgency. A bigger number is more urgent. FreeRTOS keeps time in ticks of one millisecond.

Related challenges

Loading the interactive arena.