c++ - Access Memory Mapped I/O -


i new embedded system programming, need learn how manipulate given via c++ code.

given:

motor 1 mapped 0x60000000

motor 2 mapped 0x50000000

the following definitions of current 32-bit registers

register name            |     byte offset        |     notes ---------------------------------------------------------------------- motor_interrupt               0x00                 service interrupts  motor_status                  0x01                 enable on demand access status elements motor_command                 0x02                 enable command of motor    register name           |   name   |  bits   | access type   | desc  ----------------------------------------------------------------------------------  motor_interrupt_register                            closed      0          r/w         high when motor transitions closed position                            open        1          r/w         high when motor transitions open position                            reserved    2.31       n/a         reserved 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 motor                            reserved    14.31       n/a         reserved future use 

i find hard see sample c++ code using given, @ point know need access register_name , set bits perform specific task or read register name status example.

i think can understand more if used in c++ code. given automatic door system ( didnt write button details). need access register_name or byte_offset in c++?

your appreciated

c/c++ example read interrupt/status registers:

volatile uint32_t * const motor1 = (uint32_t *)0x60000000; // base addresses motors 1 , 2 volatile uint32_t * const motor2 = (uint32_t *)0x50000000;  enum  // register offsets base address {     motor_interrupt, // 0x00 - service interrupts     motor_status,    // 0x01 - enable on demand access status elements     motor_command    // 0x02 - enable command of 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 write 32 bit values to command registers:

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

Comments

Popular posts from this blog

php - Magento - Deleted Base url key -

javascript - Tooltipster plugin not firing jquery function when button or any click even occur -

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -