-
Notifications
You must be signed in to change notification settings - Fork 0
Update ringbuf + ads1x9x to properly handle locks/ISRs #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
christopherwun
commented
Aug 27, 2025
- Split these ringbuf + ads1x9x updates from bno08x PR
- Copied Maria's comments on these files below
…anged addr default to -1, updated pointer resets to null instead of 0
| rb->write_idx = rb->read_idx = 0; | ||
| atomic_flag_clear(&rb->lock); | ||
|
|
||
| return rb; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(from Maria) Ensure read/write access to the allocated buffer is locked. Even if you’re handling it outside the API (prone to bugs, every caller must remember to lock), it’s safer to include locking within the API for future reuse. Consider also providing a _nolock variant so callers can lock once and perform multiple operations atomically without double-locking.
E.g:
'''
cionic_ringbuf_lock(&rb);
cionic_ringbuf_write_nolock(&rb, &b, len1);
cionic_ringbuf_write_nolock(&rb, &b, len2);
cionic_ringbuf_write_nolock (&rb, &b, len3);
cionic_ringbuf_unlock(&rb);
and
cionic_ringbuf_write(&rb, &b, len1); // this one will lock, write, and unlock
'''
If the buffer is touched in an ISR push to a queue and then in the task do the buffered writes with a mutex.
| } | ||
|
|
||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from Maria: See my earlier comment on locking the ring buffer.
As written, this code may block the ISR, too much is happening (memcpy in read_data, filtering, writing to the ring buffer). The ISR should be minimal; use a background callback to offload the work. I’ve attached example code (generated with ChatGPT) that shows how this can be done, and also some other suggestions it provided to make the code more efficient.