繁体   English   中英

访问内存映射的I / O

[英]Access Memory Mapped I/O

我对嵌入式系统编程非常陌生,我只需要学习如何通过c ++代码操纵给定的代码即可。

鉴于:

电机1映射到0x60000000

电机2映射到0x50000000

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

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

我发现很难使用给定​​的示例代码查看C ++代码,这时我知道我需要访问register_name并将其位设置为执行特定任务,或者读取寄存器名称以获取状态。

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

非常感谢您的帮助

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

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];

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM