feat(core): Add 8-bit and 16-bit atomic operation support#11244
Open
wdfk-prog wants to merge 1 commit intoRT-Thread:masterfrom
Open
feat(core): Add 8-bit and 16-bit atomic operation support#11244wdfk-prog wants to merge 1 commit intoRT-Thread:masterfrom
wdfk-prog wants to merge 1 commit intoRT-Thread:masterfrom
Conversation
|
👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread! 为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。 🛠 操作步骤 | Steps
完成后,提交将自动更新至 如有问题欢迎联系我们,再次感谢您的贡献!💐 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
为什么提交这份PR (why to submit this PR)
当前原子操作接口主要面向
rt_atomic_t,缺少对 8 位和 16 位原子类型的统一支持。这会带来以下问题:
因此,提交此 PR,为 RT-Thread 原子操作框架补充 8 位和 16 位原子类型及其相关接口,并同时支持硬件实现和软件回退路径。
你的解决方案是什么 (what is your solution)
本 PR 主要做了以下改动:
在
rttypes.h中新增原子类型定义:rt_atomic8_trt_atomic16_t在
rtatomic.h中新增 8 位和 16 位原子操作接口,包括:load/storeand/or对标准原子实现路径(
RT_USING_STDC_ATOMIC)补充对应宏映射,使 8 位和 16 位接口可以直接映射到标准原子操作;对硬件原子实现路径(
RT_USING_HW_ATOMIC)增加分层支持:ARCH_USING_HW_ATOMIC_8ARCH_USING_HW_ATOMIC_16在纯软件原子路径中新增以下实现:
rt_soft_atomic_load8rt_soft_atomic_store8rt_soft_atomic_load16rt_soft_atomic_store16rt_soft_atomic_and8rt_soft_atomic_or8rt_soft_atomic_and16rt_soft_atomic_or16这些实现通过关中断保护临界区,保证原子性;
在
libcpu/Kconfig中新增架构能力配置项:ARCH_USING_HW_ATOMIC_8ARCH_USING_HW_ATOMIC_16并为支持相关硬件原子能力的 ARM 架构默认选中这些选项;
在
libcpu/arm/common/atomic_arm.c中新增 ARM 平台 8 位和 16 位硬件原子支持,包括:LDREXB/STREXBLDREXH/STREXHload/store/and/or实现;保持现有 32 位原子操作接口和行为不变,仅扩展更小宽度类型的支持能力。
通过这些调整,RT-Thread 原子操作框架可以统一支持 8 位、16 位和原有宽度的原子访问与按位操作,同时兼容标准原子、硬件原子和软件回退三种实现路径。
请提供验证的bsp和config (provide the config and bsp)
BSP:
bsp/stm32/stm32l496-st-nucleo.config:
RT_USING_HW_ATOMICaction: