当前位置:网站首页>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)
边栏推荐
- Machine learning difference in the competition and industry application
- Flink optimization
- Could not acquire management access for administration
- 国内数字藏品的乱象与未来
- 【回归预测-CNN预测】基于卷积神经网络CNN实现数据回归预测附matlab代码
- How to use Databricks for data analysis on TiDB Cloud | TiDB Cloud User Guide
- 1700. 无法吃午餐的学生数量
- 智能合约安全——私有数据访问
- [深入研究4G/5G/6G专题-46]: 5G Link Adaption链路自适应-2-常见缩略语
- 超T动力 盈运天下——中国重汽黄河/豪沃WP14T产品首发荣耀上市!
猜你喜欢
Redis 缓存穿透、击穿、雪崩以及一致性问题
Flink real-time data warehouse completed
MaxWell scraped data
71-page comprehensive overall solution for global tourism 2021 ppt
去腾讯面试,直接让人出门左拐 :幂等性都不知道!
Kubernetes应用管理深度剖析
使用 protobuf 进行数据序列化
Redis cache penetration, breakdown, avalanche and consistency issues
从实例来看DAO:权力分散的伟大尝试
The highest level of wiring in the computer room, the beauty is suffocating
随机推荐
localhost with 127.0.0.1
【云原生】阿里云ARMS业务实时监控
分布式前修课:MySQL实现分布式锁
CMake库搜索函数居然不搜索LD_LIBRARY_PATH
Flink optimization
Allure Advanced - Dynamically Generate Report Content
JVM性能调优
Could not acquire management access for administration
面试何惧调优!腾讯技术官私藏的性能优化方案手册,原理实战齐全
SLF4J的使用
浅析显卡市场的未来走向:现在可以抄底了吗?
CVE-2022-33891 Apache Spark 命令注入复现
SQL 优化这么做就对了!
LeetCode_98_验证二叉搜索树
SSE for Web Message Push
【回归预测-CNN预测】基于卷积神经网络CNN实现数据回归预测附matlab代码
闭包和装饰器
Office Automation | Office Software and Edraw MindMaster Shortcuts
About the data synchronization delay of MySQL master-slave replication
MASM32v11编程调用Process32First失败: 程序发出命令,但命令长度不正确