[英]C++11 atomics: does it make sense, or is it even possible, to use them with memory mapped 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.