$npx -y skills add easyzoom/aix-skills --skill embedded-buffer-queue-libsUse when integrating, porting, configuring, or debugging embedded ring buffers, circular buffers, FIFO queues, Ring-Buffer, or QueueForMcu libraries
| 1 | # Embedded Buffer Queue Libs |
| 2 | |
| 3 | ## Overview |
| 4 | |
| 5 | Use this skill for embedded ring buffers and lightweight queues. The core decision is ownership and concurrency: single producer/consumer, ISR-to-task, task-to-task, DMA-to-task, or multi-producer use. |
| 6 | |
| 7 | ## When To Use |
| 8 | |
| 9 | Use this skill when: |
| 10 | |
| 11 | - The user wants to integrate or debug Ring-Buffer, QueueForMcu, circular buffers, FIFOs, UART RX buffers, log queues, or event queues. |
| 12 | - The issue involves overflow, data loss, race conditions, wraparound, off-by-one capacity, ISR safety, or DMA buffer handoff. |
| 13 | |
| 14 | Do not use this skill for RTOS-native queues unless the issue is about wrapping a custom buffer around them. |
| 15 | |
| 16 | ## First Questions |
| 17 | |
| 18 | Ask for: |
| 19 | |
| 20 | - Buffer/queue library and intended data type. |
| 21 | - Producer and consumer contexts: ISR, DMA, task, main loop, shell, or logger. |
| 22 | - Required behavior on full/empty: drop, overwrite oldest, block, error, or backpressure. |
| 23 | - Element size, capacity, maximum burst, and latency budget. |
| 24 | - Whether operations must be lock-free or protected by critical sections. |
| 25 | |
| 26 | ## Integration Checklist |
| 27 | |
| 28 | 1. Define ownership. |
| 29 | Specify exactly who writes, who reads, and whether there can be multiple producers or consumers. |
| 30 | |
| 31 | 1. Define full/empty semantics. |
| 32 | Do not leave overwrite/drop/block behavior implicit. |
| 33 | |
| 34 | 1. Check capacity math. |
| 35 | Many ring buffers hold `N-1` items to distinguish full from empty. |
| 36 | |
| 37 | 1. Protect concurrent access. |
| 38 | Use interrupt masking, atomics, mutexes, or single-producer/single-consumer rules as appropriate. |
| 39 | |
| 40 | 1. Verify wraparound. |
| 41 | Test writes and reads across the end of the buffer. |
| 42 | |
| 43 | 1. Add telemetry. |
| 44 | Track high-water mark, overflow count, drop count, or queue full events. |
| 45 | |
| 46 | ## Common Failures |
| 47 | |
| 48 | - Race between ISR producer and task consumer. |
| 49 | - Off-by-one capacity causes one byte or one element to disappear. |
| 50 | - DMA writes into a buffer while CPU reads stale cached data. |
| 51 | - Full buffer silently overwrites critical data. |
| 52 | - Queue stores pointers to stack objects that go out of scope. |
| 53 | |
| 54 | ## Verification |
| 55 | |
| 56 | Before claiming buffer/queue works: |
| 57 | |
| 58 | - State producer/consumer contexts and protection strategy. |
| 59 | - Confirm full, empty, wraparound, and overflow behavior. |
| 60 | - Confirm maximum burst fits capacity or drops are counted intentionally. |
| 61 | - For DMA/cache systems, state cache maintenance or memory placement. |
| 62 | |
| 63 | ## Example |
| 64 | |
| 65 | User: |
| 66 | |
| 67 | ```text |
| 68 | UART 中断收数据用 ring buffer,偶尔丢字节。 |
| 69 | ``` |
| 70 | |
| 71 | Agent: |
| 72 | |
| 73 | 1. Asks for producer/consumer contexts, baud, buffer size, overflow policy, and critical sections. |
| 74 | 1. Checks N versus N-1 capacity and ISR/task race. |
| 75 | 1. Adds overflow counters and tests burst input across wraparound. |