Hopper

FreeRTOS Burst Logging Exercise

Task

At a grain store, a sensor reads a hopper's level each time a load drops in. Loads come in quick bursts. The store's log prints every reading, but slowly, and a reading lost or printed twice puts the records out.

Write the two FreeRTOS tasks and start them, so every reading prints once, in the order it was taken: sampler task, priority 2: takes a reading with read_level() each time wait_strobe() returns; logger task, priority 1: prints each reading with print_reading(n, level), n counting from 1. The FreeRTOS calls for this are xTaskCreate, vTaskStartScheduler, xQueueCreate, xQueueSend and xQueueReceive; the Reference tab shows each one.

Circuit

Block diagram: U2, a level sensor, puts its level on PA0 to PA3 and strobes PA4 of U1 STM32F4; inside U1 the sampler task at priority 2 hands each reading through a queue to the logger task at priority 1, which prints it on USART1 TX, PA9, to a terminal

Pass condition

Every reading, once and in order: two bursts of six print 1 L=3 to 12 L=0.

Expected output for the two bursts case: PA4 strobes six times 2 ms apart at 20 ms and again at 54 ms, while the first burst is still printing; each reading prints as one 8 ms line, back to back from 20 ms to about 117 ms, 1 L=3 to 12 L=0, twelve lines in all

Notes

The sensor strobes PA4 once per reading while your program runs, in bursts of up to six readings 2 ms apart. A reading's level is on PA0 to PA3 from just before its strobe until the next reading. 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.