访问内存映射I / O [英] Access Memory Mapped I/O

查看:138
本文介绍了访问内存映射I / O的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我非常新的嵌入式系统编程,我只需要学习如何通过c ++代码操作给定的。



给定:



电机1映射到0x60000000



电机2映射到0x50000000



以下是当前32位寄存器的定义

  REGISTER NAME | BYTE OFFSET |注意
--------------------------------------------- -------------------------
motor_interrupt 0x00服务中断

motor_status 0x01启用按需访问状态元素
motor_command 0x02启用电机命令



注册名称| NAME | BITS |访问类型| DESC
--------------------------------------------- -------------------------------------

motor_interrupt_register
关闭0当电机转换到关闭位置时,R / W为高电平
OPEN 1当电机转换到OPEN位置时,R / W为高电平
RESERVED 2.31 N / A保留以备将来使用

motor_status

速度0.2 R速度计数/秒
状态3 R电机的当前状态
POSITION 4.13 R电机的当前位置
RESERVED 14.31 n / a保留为未来使用

我发现使用给定的C ++代码很难看到,在这一点上我是知道我需要访问regi ster_name并将其位设置为执行特定任务或读取注册名称以获取状态。



如果在c ++代码中使用它,我想我可以理解它。给定的是一个自动门系统(我没有写出按钮的细节)。我需要访问register_name或c ++中的byte_offset吗?



您的帮助将非常欣赏

解决方案

C / C ++例如读取中断/状态寄存器:

  volatile uint32_t * const motor1 =(uint32_t *)0x60000000; //电机1和2的基址
volatile uint32_t * const motor2 =(uint32_t *)0x50000000;

枚举//从基址寄存器偏移
{
motor_interrupt,// 0x00 - 服务中断
motor_status,// 0x01 - 启用按需访问状态元素
motor_command // 0x02 - 启用电机命令
}

//读状态/中断寄存器

uint32_t current_int_1 = motor1 [motor_interrupt];
uint32_t current_int_2 = motor2 [motor_interrupt];

uint32_t current_status_1 = motor1 [motor_status];
uint32_t current_status_2 = motor2 [motor_status];

类似于将32位值写入命令寄存器:

  motor1 [motor_command] = 0x8000 | (0x12 <6)| 0×01; 
motor2 [motor_command] = 0x0;


I am very new to embedded system programming, I just need to learn how to manipulate the given via c++ code.

Given:

Motor 1 is mapped to 0x60000000

Motor 2 is mapped to 0x50000000

the following are the definitions of current 32-bit registers

REGISTER NAME            |     BYTE OFFSET        |     NOTES
----------------------------------------------------------------------
motor_interrupt               0x00                 service interrupts

motor_status                  0x01                 enable on demand access to status elements
motor_command                 0x02                 enable command of the motor



REGISTER NAME           |   NAME   |  BITS   | ACCESS TYPE   | DESC 
----------------------------------------------------------------------------------

motor_interrupt_register
                           CLOSED      0          R/W         high when motor transitions to CLOSED position
                           OPEN        1          R/W         high when motor transitions to OPEN position
                           RESERVED    2.31       N/A         reserved for future use

motor_status        

                           SPEED       0.2         R          speed in counts/seconds
                           STATE        3          R          current state of motor
                           POSITION    4.13        R          current position of the motor
                           RESERVED    14.31       n/a         reserved for future use

I find it hard to see a sample c++ code using the given, At this point what i know is I need to access the register_name and set their bits to perform specific task or read the register name to get the status for example.

I think I can understand it more if it is used in a c++ code. The given is a automatic door system ( i didnt write the button details). Will I need to access the register_name or the byte_offset in c++?

Your help would be very much appreciated

解决方案

C/C++ example to read interrupt/status registers:

volatile uint32_t * const motor1 = (uint32_t *)0x60000000; // base addresses for motors 1 and 2
volatile uint32_t * const motor2 = (uint32_t *)0x50000000;

enum  // register offsets from base address
{
    motor_interrupt, // 0x00 - service interrupts
    motor_status,    // 0x01 - enable on demand access to status elements
    motor_command    // 0x02 - enable command of the motor
}

// read status/interrupt registers

uint32_t current_int_1 = motor1[motor_interrupt];
uint32_t current_int_2 = motor2[motor_interrupt];

uint32_t current_status_1 = motor1[motor_status];
uint32_t current_status_2 = motor2[motor_status];

Similarly to write 32 bit values to to the command registers:

motor1[motor_command] = 0x8000 | (0x12 << 6) | 0x01;
motor2[motor_command] = 0x0;

这篇关于访问内存映射I / O的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆