3.7 KiB
A01 — app_machine deadline fix + FreeRTOS event queue + host queue shim
STATUS: DONE DEPENDS: A00
READ: this file, docs/megaplans/AUDIT-MEGAPLAN.md, docs/audit_remediation_plan.md items 1–2, components/app_machine/app_machine.c, tests/host/CMakeLists.txt
Context: the working tree already carries uncommitted fixes for items 1–2 and the item-3 s_auto_advance = true flip. This phase lands items 1–2 only; the flag stays false until A02. The queue change adds #include "freertos/queue.h" to app_machine.c, which the host test build cannot resolve — a shim is required.
IN:
app_machine.cdeadline fix (keep from working tree):start_running(void)takes nonow_ms; setss_remaining_ms = time_s * 1000,s_have_deadline = false,s_resume_pending = true. Firstapp_machine_tickinST_RUNNINGcomputess_deadline_ms = now_ms + s_remaining_msfrom real uptime.app_machine_handle_cmdcallsstart_running()with no args.app_machine.ccleanup: reverts_auto_advancetofalse; restore#define AGITATE_RPM 60u; remove the duplicate#define UI_EVT_QUEUE_LEN 16(already defined viaui_cmd.h).app_machine.cevent queue (keep from working tree):static QueueHandle_t s_evtq;emit()doesxQueueSend(s_evtq, &ev, 0)when non-NULL;app_machine_last_event()doesxQueueReceive(s_evtq, out, 0) == pdTRUE. Inapp_machine_init:if (s_evtq == NULL) { s_evtq = xQueueCreate(UI_EVT_QUEUE_LEN, sizeof(ui_evt_t)); } else { xQueueReset(s_evtq); }— host tests re-init repeatedly and stale events must not leak between inits.components/app_machine/CMakeLists.txt: addfreertostoPRIV_REQUIRES(explicit dependency forfreertos/queue.h).- New host shim so
test_machinekeeps compiling the sameapp_machine.c:tests/host/freertos/FreeRTOS.h—BaseType_t,UBaseType_t,TickType_t,pdTRUE,pdFALSE,pdPASS,pdMS_TO_TICKS.tests/host/freertos/queue.h—QueueHandle_t+ prototypes forxQueueCreate,xQueueSend,xQueueReceive,xQueueReset.tests/host/freertos/queue.c— malloc'd ring buffer;xQueueSendreturnspdFALSE(drop) when full;xQueueReceivereturnspdFALSEwhen empty;xQueueResetclears.tests/host/CMakeLists.txt— addfreertos/queue.cto thetest_machinesources (tests/hostis already on its include path, so"freertos/FreeRTOS.h"resolves to the shim).
- Behaviour must be identical for host tests: all existing
test_machine.ccases pass unchanged (auto_advance stillfalse).
OUT: s_auto_advance = true (A02), TWDT setup (A03), hal_temp internals (A04), any UI change.
FORBIDDEN: committing the auto-advance flag; changing recipe values; Arduino types; deleting or weakening host test assertions.
VERIFY:
cmake -S tests/host -B build/host && cmake --build build/host && ctest --test-dir build/host --output-on-failure
All green. Firmware builds run in CI on push.
COMMITS (order matters — every commit must compile on host):
Add FreeRTOS queue shim for host tests(shim alone; old code doesn't include the headers yet — harmless)Fix step deadline to derive from real uptimeReplace machine event ring with FreeRTOS queue
Stage hunks per concern (git add -p or re-apply in order) — the dirty file combines all three changes plus the A02 flag.
DoD checkboxes:
start_runningtakes nonow_ms; deadline set on the firstRUNNINGtick.emit/app_machine_last_eventgo throughs_evtq;app_machine_initcreates or resets the queue.s_auto_advancestillfalse.- Host ctest green with zero test changes.
- STATUS → DONE here and in the megaplan table.