Cortex M3 - 如何使用信号量
我有一个关于在 cortex m3 中使用信号量的问题。我找到了一个线程“ARM cortex:使用位带的互斥体” ARM cortex:使用位带的互斥体位带。 有一个问题的简短描述,最后一个答案对我的问题有好处 - 但我不确定如何在 c/c++ 中实现它。
“我从未在 ARM 上使用过位带;我的倾向是对所有此类操作使用加载独占/存储条件。使用循环来加载独占旧值,计算新值,然后使用条件存储将其写回。循环直到条件存储成功(如果第一次没有成功,则可能是第二次)。”
如果有人可以发布如何使用它的简短代码,我将非常感激。
谢谢, 马丁
I have a question about using semaphores in cortex m3. I've found a thread "ARM cortex: mutex using bit banding" ARM cortex: mutex using bit banding .
There is a short description of the problem, and the last answer would be good for my problem - but I am not sure how can I implement it in c/c++.
"I've never used bit-banding on the ARM; my inclination instead would be to use load-exclusive/store-conditional for all such operations. Use a loop to load-exclusive the old value, compute the new value, and use a conditional store to write it back. Loop until the conditional store succeeds (which it probably will the second time, if it doesn't the first)."
I would be very grateful if someone could post a short code how to use it.
Thanks,
Martin
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请注意,位带并非在所有实现中都可用(最值得注意的是,NXP 的 LPC1xxx 系列中缺少位带)。
有关使用 LDREX/STREX 实现信号量的官方方法,请参阅 ARM 同步原语开发文章。它使用ARM汇编。
下面是我制作的一个简单的类,它使用编译器内部函数(未经测试!)。这个名字可能用词不当,因为它实际上像互斥体一样工作。它还缺少可能需要的 DMB 指令。
Please note that bit-banding is not available on all implementations (most notably, it's missing in NXP's LPC1xxx series).
For an official way of implementing semaphore using LDREX/STREX, see ARM Synchronization Primitives Development Article. It uses ARM assembly.
Below is a simple class I made that uses compiler intrinsics (untested!). The name is probably a misnomer since it actually works like a mutex. It's also missing DMB instructions which might be necessary.