|
ProtoCore v0.0.1
Deterministic, zero-heap network stack for embedded targets
|
Layer: Foundation ยท Build flags: PC_ENABLE_PREEMPT_QUEUE
Hardware events (a DMA-complete interrupt, a GPIO edge, a bus byte) arrive in ISR context, where you must do as little as possible. The preempting work queue is the clean hand-off: the ISR posts a small fixed-size item and the scheduler preempts straight to a dedicated high-priority task that does the real work - so the heavy processing runs off the interrupt, immediately, not on the next loop tick.
It is one queue feeding one core-pinned task, with static (zero-heap) storage:
Post from an ISR - interrupt-safe, asks for an immediate context switch:
Post from a task - back, urgent (front), each with a wait timeout, all fail-closed (they return false and drop rather than block forever) when the queue is full:
On hardware the high-priority task drains the queue automatically. Measured on a DevKitV1: an ISR post reaches the handler in ~12 us, and the queue never backs up past one item (each post is processed before the next arrives).
Sizing. PC_PQ_DEPTH (items), PC_PQ_ITEM_SIZE (bytes per item), and PC_PQ_STACK (task stack) are compile-time because the storage is static; pc_pq_high_water() reports the peak depth so you can size PC_PQ_DEPTH.
Build-flag note. PC_ENABLE_PREEMPT_QUEUE must reach the library build (an in-sketch #define does not reach the separately compiled library), so pass it as a build flag: