搜索
bottom↓
回复: 6

请教朋友们,STM32 项目中这语句啥意思?

[复制链接]

出75入8汤圆

发表于 3 天前 | 显示全部楼层 |阅读模式
volatile uint32_t blelock                         __attribute__((at(BITBAND(STATE_ADDR,14)))); KEIL编译,这句看不懂,网上搜也搜不到。

阿莫论坛20周年了!感谢大家的支持与爱护!!

知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)

出0入1209汤圆

发表于 3 天前 | 显示全部楼层
这不是绝对地址定位么?本坛就有
https://www.amobbs.com/thread-5592242-1-1.html

出0入18汤圆

发表于 3 天前 | 显示全部楼层
问一下GPT啊,
In this code snippet, the volatile uint32_t blelock is a variable definition with specific attributes. Here is a detailed explanation:

volatile: This keyword tells the compiler that the value of blelock can be changed at any time without any action being taken by the code. This is often used for variables that are accessed by multiple threads or hardware.

uint32_t: This is a typedef defined in the stdint.h header file, which represents an unsigned 32-bit integer.

blelock: This is the name of the variable.

__attribute__((at(...))): This is a GCC-specific extension that places the variable at a specific memory address. The at attribute is used to specify the absolute address where the variable should be placed. This is useful in embedded systems where certain variables need to be placed at specific hardware addresses.

BITBAND(STATE_ADDR, 14): This is a macro or function that calculates the specific address where the variable should be placed. Bit-banding is a technique used in some microcontrollers (like ARM Cortex-M) to map a bit in the bit-band region to a word in the bit-band alias region. This allows bit-level manipulation through word-level instructions.

STATE_ADDR: This would be a base address defined elsewhere in the code.
14: This is the bit number in the bit-banding region.
Putting it all together, this line of code defines a 32-bit volatile integer blelock and places it at a specific bit-banded address derived from STATE_ADDR and bit number 14. This allows efficient manipulation of a single bit in the bit-banding region.

出1325入193汤圆

发表于 3 天前 | 显示全部楼层
定义 `blelock` 的32位无符号整型变量,
变量被映射到 `STATE_ADDR` 基地址上的第14个位,使用位带操作可以单独对这个位进行读写操作。

简单来说,这段代码的作用是定义一个可以单独操作特定位的变量.

出75入8汤圆

 楼主| 发表于 3 天前 | 显示全部楼层
kitten 发表于 2024-7-19 11:18
这不是绝对地址定位么?本坛就有
https://www.amobbs.com/thread-5592242-1-1.html
(引用自2楼)

谢谢,还是不太理解,就是FLASH中的一个值改写一下?

出75入8汤圆

 楼主| 发表于 3 天前 | 显示全部楼层
tang_qianfeng 发表于 2024-7-19 11:19
问一下GPT啊,
In this code snippet, the volatile uint32_t blelock is a variable definition with spec ...
(引用自3楼)

在这个代码片段中,易失性uint32_t block是一个具有特定属性的变量定义。下面是详细的解释:volatile:这个关键字告诉编译器,block的值可以在任何时候改变,而不需要代码执行任何操作。这通常用于由多个线程或硬件访问的变量。uint32_t:这是一个在stint .h头文件中定义的类型定义,它表示一个无符号32位整数。blelock:变量的名称。attribute_((at(…)):这是一个特定于gcc的扩展,它将变量放置在特定的内存地址。at属性用于指定应该放置变量的绝对地址。这在需要将某些变量放置在特定硬件地址的嵌入式系统中非常有用。BITBAND(STATE_ADDR, 14):这是一个宏或函数,用于计算变量应该放置的特定地址。位带是在一些微控制器(如ARM Cortex-M)中使用的一种技术,用于将位带区域中的位映射到位带别名区域中的字。这允许通过字级指令进行位级操作。STATE_ADDR:这将是在代码的其他地方定义的基址。14:表示位带区域的位数。将所有这些放在一起,这行代码定义了一个32位易失性整数块,并将其放置在从STATE_ADDR和位号14派生的特定位带地址上。这允许有效地操作位带区域中的单个位。谢谢,用有道翻译了一下。

出75入8汤圆

 楼主| 发表于 3 天前 | 显示全部楼层
lb0857 发表于 2024-7-19 11:25
定义 `blelock` 的32位无符号整型变量,
变量被映射到 `STATE_ADDR` 基地址上的第14个位,使用位带操作可以 ...
(引用自4楼)

好的,谢谢,我再看看。
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片。注意:要连续压缩2次才能满足要求!!】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-7-22 20:17

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表