Repository navigation
feat(arch,container): ISR safety abstraction and interrupt-safe ringbuf APIs (#105) - #112
Merged
Merged
Conversation
#105) Add <ttak/arch/ttak_critical.h> with task-context and ISR-context critical-section macros: - TTAK_ENTER_CRITICAL()/TTAK_EXIT_CRITICAL(): cpsid i/cpsie i on Cortex-M, taskENTER/EXIT_CRITICAL() on FreeRTOS, documented no-ops on hosted POSIX and MSVC/x86. - TTAK_ENTER_CRITICAL_ISR(state)/TTAK_EXIT_CRITICAL_ISR(state): PRIMASK save/restore on Cortex-M, taskENTER/EXIT_CRITICAL_FROM_ISR() on FreeRTOS (the state argument carries the interrupt mask, which the FreeRTOS FromISR API requires). Add ttak_ringbuf_push_isr()/ttak_ringbuf_pop_isr(): they never take the pthread rwlock (illegal in ISR) and serialize with the ISR critical section instead, so an ISR can never deadlock against a task holding the lock. When a buffer is shared between a task and an ISR, both sides must use the _isr variants; the regular task-context APIs stay unchanged. Tests: - tests/test_ringbuf_isr.c: host smoke test of the _isr API surface (no-op critical sections), plus a Cortex-M producer/consumer test that pends NVIC IRQ0 (new weak TTAK_IRQ0..3 slots in the startup vector table) which pushes payloads from the ISR while the task pops and asserts order and no loss, on both bare-metal and FreeRTOS builds. - Registered in BAREMETAL_TESTS so it runs in the QEMU mps2-an500 bare-metal and FreeRTOS CI jobs. Documented the macros and the task/ISR mixing rule in README.
gg582
force-pushed
the
feat/isr-safe-primitives
branch
from
October 29, 2026 12:07
3a4af42 to
6f57e33
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #105.
What
<ttak/arch/ttak_critical.h>— task-context and ISR-context critical sections:TTAK_ENTER_CRITICAL()/TTAK_EXIT_CRITICAL()— Cortex-M:cpsid i/cpsie i; FreeRTOS:taskENTER_CRITICAL()/taskEXIT_CRITICAL(); hosted POSIX / MSVC x86: documented no-ops.TTAK_ENTER_CRITICAL_ISR(state)/TTAK_EXIT_CRITICAL_ISR(state)— Cortex-M: PRIMASK save/restore; FreeRTOS:taskENTER_CRITICAL_FROM_ISR()/taskEXIT_CRITICAL_FROM_ISR(). Thestateargument (attak_critical_state_tdeclared by the caller) carries the interrupt mask between enter/exit — required for correct nesting and for the FreeRTOS BASEPRI-based FromISR API.Ring buffer
_isrvariants —ttak_ringbuf_push_isr()/ttak_ringbuf_pop_isr():_isrvariants; the regular APIs must not be mixed with them on the same buffer.Tests
tests/test_ringbuf_isr.c:_isrAPI surface and ordering (critical sections are no-ops there, per documentation).TTAK_IRQ0..IRQ3_Handlerslots added to the harness vector table intests/baremetal/startup_cortex_m.c— which pushes a burst of payloads from the real ISR while the task pops withttak_ringbuf_pop_isr(), asserting in-order delivery with no loss across buffer wrap-around (200 items through a 16-slot buffer).BAREMETAL_TESTS, so it runs in the existingqemu-testsandfreertos-qemu-testsCI jobs with no runner changes.Docs
README "ISR safety and critical sections" section under Microcontrollers (Bare Metal).
Verified locally
make test— full host suite passes.make PLATFORM=baremetal BOARD=mps2_an500test image builds for the new test (and lib builds for cortex-m0plus/m3-class flags:-mcpu=cortex-m0plus -mthumb -mfloat-abi=softand cortex-m4f).make PLATFORM=freertos ... baremetal-tests— all 39 images build against FreeRTOS V11.1.0.check_stack_usage.py --core cortex-m7passes (new_isrframes are 8 B, same as the task variants).Deferred to CI
qemu-system-armis not installed locally and could not be installed; the images build and the test follows the existing harness conventions exactly.