当前位置:网站首页>位绑定
位绑定
2022-06-23 08:58:00 【七月流星.】
1,位绑定的概念:
将一个单元(32位)中的某个位通过一个算法映射到地址,对地址进行操作(最低位有效)。
2,位绑定的优点:
直接操作地址,代码执行效率更高,安全性高
3,cortex中绑定区域:
SRAM区:0x2000 0000 ~ 0x200f ffff (1M的绑定区)
片上外设:0x4000 0000 ~ 0x200f ffff (1M的绑定区)
4,通过位绑定实现位的快速操作:
位绑定公式:
SRAM区:
绑定后的新地址 = 0x2200 0000 +((本身地址 - 0x2000 0000)*8 + n)*4
= 0x2200 0000 +(本身地址 - 0x2000 0000)*32 + n*4 //*32是32个位,*4是4个字节,n=0~7是以字节为单位;n=0~31是以字为单位
片上外设:
绑定后的新地址 = 0x4200 0000 +((本身地址 - 0x4000 0000)*8 + n)*4
= 0x4200 0000 +(本身地址 - 0x4000 0000)*32 + n*4
5,示例:
#include"stm32f10x_lib.h"
#include"stdio.h"
#define PA1 GPIOA->BSRR
#define PA0 GPIOA->BRR
#define GPIOA_ODR_A (GPIOA_BASE + 0x0C)
#define GPIOA_IDR_A (GPIOA_BASE + 0x08)
#define BitBand(Addr,BitNum) *((volatile unsigned long *)((Addr&0xF0000000)+0x2000000+((Addr&0xFFFFF)<<5)+(BitNum<<2)))
#define PAout(n) BitBand(GPIOA_ODR_A,n)
#define PAin(n) BitBand(GPIOA_IDR_A,n)
int main(void)
{
// ODR地址 基地址 偏移地址
// u32 *PAO3 = (u32 *)(GPIOA_BASE+0x0C);
// 绑定后的地址 第三位
u32 *PAO3 = (u32 *)(0x42000000+(0x4001080C-0x40000000)*32+3*4);
u32 *PAI11 = (u32 *)(0x42000000+(0x40010808-0x40000000)*32+11*4);
// 或者u32 *PAI11 = (u32 *)(0x42000000+(0x40010809-0x40000000)*32+3*4);
//1,PA0~PA7作为输出:推挽输出50MHZ; PA8~PA15作为输入:浮空输入
GPIOA->CRL = 0x33333333;
GPIOA->CRH = 0x44444444;
//2,输入状态反映到对应引脚的输出
while(1)
{
if((GPIOA->IDR & 0x0100) == 0x0100) /*8*/ PA1 = 0x01; //宏定义方式
else PA0 = 0x01;
if((GPIOA->IDR & 0x0200) == 0x0200) /*9*/ PA1 = 0x02;
else PA0 = 0x02;
if((GPIOA->IDR & 0x0400) == 0x0400) /*10*/ GPIOA->BSRR = 0x04; //位操作方式
else GPIOA->BRR = 0x04;
//A = GPIOA_BASE + ODRÆ«ÒÆµØÖ· = GPIOA_BASE+0x0C n = 3
//A = GPIOA_BASE + IDRÆ«ÒÆµØÖ· = GPIOA_BASE_0x08 n = 3
if(*PAI11 == 1) /*11*/ *PAO3 = 1; //位绑定方式
else *PAO3 = 0;
if((GPIOA->IDR & 0x1000) == 0x1000) /*12*/ GPIOA->ODR = GPIOA->ODR | 0x10; //计算
else GPIOA->ODR = GPIOA->ODR & (~0x10);
if(PAin(13) == 1) /*13*/ PAout(5) = 1; //位绑定公式方法
else PAout(5) = 0;
if((GPIOA->IDR & 0x4000) == 0x4000) /*14*/ GPIOA->ODR = GPIOA->ODR | 0x40;
else GPIOA->ODR = GPIOA->ODR & (~0x40);
if((GPIOA->IDR & 0x8000) == 0x8000) /*15*/ GPIOA->ODR = GPIOA->ODR | 0x80;
else GPIOA->ODR = GPIOA->ODR & (~0x80);
}
return(1);
}
边栏推荐
- In June, China database industry analysis report was released! Smart wind, train storage and regeneration
- [cloud native | kubernetes] kubernetes principle and installation (II)
- The fourth online workshop review
- MySQL fault case | mysqldump: couldn't execute 'select column_ NAME
- Utilisation du cookie du module de demande de noeud
- Unity grid programming 08
- Comprehensive analysis of news capture
- Best time to buy and sell stock
- [qnx hypervisor 2.2 user manual]6.2 network
- 点击添加下拉框
猜你喜欢
![[event registration] sofastack × CSDN jointly held the open source series meetup, which was launched on June 24](/img/e1/97c92290a2a5e68f05cdbd5bf525e8.png)
[event registration] sofastack × CSDN jointly held the open source series meetup, which was launched on June 24

力扣之滑动窗口《循序渐进》(209.长度最小的子数组、904. 水果成篮)

Linux MySQL installation

简易学生管理

自定义标签——jsp标签基础

点击添加下拉框

The fourth online workshop review

线性表(SequenceList)的顺序表示与实现----线性结构

Servlet-02 生命周期

“教练,我想打篮球“ —— 给做系统的同学们准备的 AI 学习系列小册
随机推荐
How can I handle the "unable to load" exception when easyplayer plays webrtcs?
JSP入门总结
Implementing an open source app store with swiftui
Combination sum III of leetcode topic analysis
4、 Database design
297. Serialize and Deserialize Binary Tree
Can portals be the next decentraland?
Simple student management
MySQL故障案例 | ERROR 1071 (42000): Specified key was too long
2022.6.22-----leetcode. five hundred and thirteen
Combination sum II of leetcode topic analysis
'coach, I want to play basketball!'—— AI Learning Series booklet for system students
测试-- 自动化测试selenium(关于API)
Which is better, semrush or ahrefs? Which is more suitable for GoogleSEO keyword analysis
Jog运动模式
The results of CDN node and source station are inconsistent
[qnx hypervisor 2.2 user manual]5.6.1 silent device during guest shutdown
A method of realizing video call and interactive live broadcast in small programs
Leetcode topic analysis h-index II
多线程初学