当前位置:网站首页>Memory-mapped, bit-band operations
Memory-mapped, bit-band operations
2022-07-30 15:31:00 【Erran gentleman】
Memory map in a nutshell,It is to map the address on the memory,The address of the memory that was originally to be accessed is operated on,Now you can operate on the address after his mapping,will be equivalent to an address operation on the original memory.
首先我们需要知道的,Actually the concept of storage,本质上其实就是,A contiguous memory address,Each memory size is different,The range of the address space contained will be different,以 Cortex-M3系列的芯片(4GB=0xFFFFFFFF,address each1代表一个字节).
有了存储器,We can of course manipulate its memory address directly,For example I want to manipulate peripheral memory,You can go directly to the memory address as0x4000000-0x5FFFFFFFaddress range to operate on,It doesn't seem like it's too much of a hassle:(List the address as you want0x40000000The corresponding storage space storage value is assigned as1)
/*片上外设基地址 */
#define PERIPH_BASE ((unsigned int)0x40000000)
/*总线基地址 */
#define AHB1PERIPH_BASE (PERIPH_BASE + 0x00020000)
/*GPIO外设基地址*/
#define GPIOC_BASE (AHB1PERIPH_BASE + 0x0800)
/* GPIOC寄存器地址,强制转换成指针 */
#define GPIOC_MODER *(unsigned int*(GPIOC_BASE+0x00)
GPIOC_MODER=1;
It doesn't seem so troublesome,Another excessive request,对地址为0x4000000in the third position1:
GPIOC_MODER=|(3<<1);
而不是
GPIOC_MODER=3<<1;
This is because when we operate, we usually operate on a certain bit,and leave the other bits unchanged,这个其实是比较麻烦的,Our original intention was to only operate on one of them,But what we had to do was keep the other bits the same,One more consideration,那有没有一种方法,能够实现,I just operate one directly,without changing the value of other bits,答案是有的,That's the bit-band operation!
Or the memory picture,This time there is a mapping:
映射关系:
bit_word_addr=bit_band_base+(byte_offset×32)+(bit_number×4)
Bit_band_base is the starting address of the alias area.
Bit_offset 为 bit-band The number of the byte in the area that contains the target bit.
Bit_number is the bit position of the target bit(0-7)
Bit_word_addr is the address of the word in alias memory mapped as the target bit.
其实很好理解,A memory address has a specific mapping function,Converts one bit of the original memory addressbit_number膨胀成4个字节,One byte of the original memory is naturally inflated,84=32个字节.Inflated word address=The address of the region where the bit band starts+The original address byte offset32+位数*4;
The concept is still a little fuzzy?
有图有真相,废话不多说,直接上图!
Learn about bit bands,Next look at the application,Generally, we perform bit-band operations mainly on peripherals,通常进行IObit-band operation of the port(Listed as the last litLEDlight link)
The base address is at0x4000000,0x42000000on the peripherals
Speaking of peripherals,Let's take a look at the carrying Bridge wire on the busAPB/AHB
in bridge wiring There are usually many peripherals on board,Let's take a look at where common peripherals are mounted:



With the understanding of the bit band,We can operate on a pin,See how the bit-band area is used in the lighting process:
/************************LED 宏定义**************************/
#define LED1_OFF GPIO_SetBits(GPIOC,GPIO_Pin_4)
#define LED2_OFF GPIO_SetBits(GPIOC,GPIO_Pin_5)
#define LED3_OFF GPIO_SetBits(GPIOC,GPIO_Pin_6)
#define LED4_OFF GPIO_SetBits(GPIOC,GPIO_Pin_7)
#define LED1_ON GPIO_ResetBits(GPIOC,GPIO_Pin_4)
#define LED2_ON GPIO_ResetBits(GPIOC,GPIO_Pin_5)
#define LED3_ON GPIO_ResetBits(GPIOC,GPIO_Pin_6)
#define LED4_ON GPIO_ResetBits(GPIOC,GPIO_Pin_7)
边栏推荐
猜你喜欢
随机推荐
MongoDB启动报错 Process: 29784 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=14)
MongoDB starts an error Process: 29784 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=14)
Go to Tencent for an interview and let people turn left directly: I don't know idempotency!
瑞吉外卖项目实战Day02
SSE for Web Message Push
自动化办公|办公软件和亿图脑图MindMaster快捷键
一文读懂网络效应对Web3的重要意义
MASM32v11编程调用Process32First失败: 程序发出命令,但命令长度不正确
【云原生】灰度发布、蓝绿发布、滚动发布、灰度发布解释
算力顶天地,存力纳乾坤:国家超级计算济南中心的一体两面
Alluxio为Presto赋能跨云的自助服务能力
Allure Advanced - Dynamically Generate Report Content
调试 - 笔记
golang modules初始化项目
Start learning C language
Could not acquire management access for administration
[机缘参悟-53]:《素书》-3-修身养志[求人之志章第三]
分布式前修课:MySQL实现分布式锁
5. DOM
Could not acquire management access for administration








