Handshake

FreeRTOS Shared Console Exercise

Task

At a water pump station, one serial console records everything. A log task writes the station's readings to it line by line, and an alarm task must report the moment the pump trips. The night operator reads the console the next morning. A line with another broken into the middle of it is no use to anyone.

Write print_line and the two FreeRTOS tasks, so every line reaches the console whole: log task, priority 1: prints the eight lines of log_lines, once, in order; alarm task, priority 2: prints FAULT: PUMP TRIPPED each time wait_trip() returns. The FreeRTOS calls for this are xTaskCreate, vTaskStartScheduler, vTaskDelete, xSemaphoreCreateMutex, xSemaphoreTake and xSemaphoreGive; the Reference tab shows each one.

Circuit

Block diagram: U2, the pump driver, pulses its FAULT output into PA0 of U1 STM32F4; inside U1 the log task at priority 1 and the alarm task at priority 2, which waits on PA0 through wait_trip(), both print through console_putc on USART1 TX, PA9, to a terminal

Pass condition

The eight log lines print in order. Each trip prints FAULT: PUMP TRIPPED once, as soon as the console is free, right after the line printing when PA0 rose.

Expected output for the one trip case: PA0 pulses high for 2 ms at 30 ms, during the second log line; the console finishes that line, prints FAULT: PUMP TRIPPED, then the other six log lines, nine whole lines in all

Notes

The pump driver trips while your program runs, pulsing PA0 high for 2 ms. 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.