Critical sections enter and exit

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Critical sections enter and exit

1,004件の閲覧回数
kai_liu
Senior Contributor I

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

ラベル(2)
タグ(1)
0 件の賞賛
1 返信

501件の閲覧回数
bobpaddock
Senior Contributor III

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.