访问内存映射I/O 我对嵌入式系统编程非常陌生,我只需要学习如何通过C++代码来操纵给定的。p>
鉴于: 电机1映射到0x60000000 电机2映射到0x50000000 以下是当前32位寄存器的定义访问内存映射I/O 我对嵌入式系统编程非常陌生,我只需要学习如何通过C++代码来操纵给定的。p>,c++,embedded,C++,Embedded,鉴于: 电机1映射到0x60000000 电机2映射到0x50000000 以下是当前32位寄存器的定义 REGISTER NAME | BYTE OFFSET | NOTES ---------------------------------------------------------------------- motor_interrupt 0x00 service inter
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++代码,在这里我知道我需要访问RealStestNoX并设置它们的位来执行特定的任务或者读取登记名来获得状态。p>
我认为如果它在C++代码中使用,我会更理解它。给定的是一个自动门系统(我没有写按钮的详细信息)。是否需要访问C++中的RealStestIONE或ByTeTeOffice?p>
非常感谢您的帮助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];
motor1[motor_command] = 0x8000 | (0x12 << 6) | 0x01;
motor2[motor_command] = 0x0;
类似于将32位值写入命令寄存器:
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];
motor1[motor_command] = 0x8000 | (0x12 << 6) | 0x01;
motor2[motor_command] = 0x0;
motor1[motor_command]=0x8000 |(0x12,谢谢你,有什么可以让我更清楚的文章/书吗?有很多关于嵌入式编程的书-在标题中找一些带有“embedded”、“programming”和“C”的东西。最好在地址处找一个结构。struct motor{unsigned int interrupt,status,command}
。让一切看起来更美好。@重复数据消除器:使用结构可能会导致对齐、填充等问题。在这样一个简单的情况下可能会很好,但一般来说,在内存映射I/O方面,我更喜欢上面这样的可预测性和确定性。@fireflieslive非常适合学习微控制器编程,即使您是C/C++的初学者。它使用飞思卡尔HC12作为示例,但所有MCU都以类似的方式工作。