I am porting some drivers to KL25Z, which has ring buffer management. The original code has CRITICAL_SECTION_ENTER and CRITICAL_SECTION_EXIT macros, which basically disable interrupt and enable interrupt.
But should we keep some critical register(s) before entering critical sections, and restore after exiting? And which registers should be saved? And any reference code? because I am not good at assembly.
Allan K Liu
If a simple single writer, single reader, ring buffer is turning IRQs on and off it is not implemented correctly.
Here is some C code that you can use:
WebSVN - Projects - Rev 230 - /common/CBUF.h
I cove what to watch out for in my Blog related to Queue code:
Software Safety: Even "Design Patterns" still have bugs. A common Queue bug.
Main point is to be aware of what the atomic size of an increment will be. If multi-byte resisters get split your code will have hard to reproduce bugs.