ARM-software / CMSIS_5

CMSIS Version 5 Development Repository
http://arm-software.github.io/CMSIS_5/index.html
Apache License 2.0
1.34k stars 1.08k forks source link

Question to exclusive access with LDREX/STREX #610

Closed joabeck closed 5 years ago

joabeck commented 5 years ago

Hello, Because the documentation regarding LDREX and STREX is a little bit unclear to me, i have the following question: Is it possible to use an RTOS-independent exclusive access using the instructions LDREX and STREX without interfering with the RTOS?

I like to use this exclusive access in different threads and in interrupt functions.

Thank you for your support. Best regards Joachim

JonatanAntoni commented 5 years ago

Hello @joabeck,

You might want to use the atomic functions used in RTX5 as a reference about using LDREX and STREX instructions, e.g. https://github.com/ARM-software/CMSIS_5/blob/01c7adb7685da540be9297b5a93e6640ea3333ce/CMSIS/RTOS2/RTX/Source/rtx_core_cm.h#L474-L489

Using you own exclusive access sequences should not interfere with the RTOS. The monitor is claimed by any LDREX instruction and cleared by the according STREX instruction, or by CLREX instruction, or when an exception occurs. It doesn't actually check whether a certain memory area is accessed concurrently. It simply assumes a concurrent access might occur if the sequence is interrupted. In that case you need to repeat the sequence.

Does this answer your questions?

Cheers, Jonatan

joabeck commented 5 years ago

Hi Jonathan, Thank you for your complete and fast answer! Best regards Joachim