How CPU communicates with external devices in embededd systems OR Difference between Memory mapped I/O and I/O mapped I/O ?

 There are two different approaches such as Memory-mapped I/O (MMIO) and I/O-mapped I/O  (IOMIO) to interface with peripherals and devices in embedded/computer system from CPU. The external devices like analog devices, sensors, displays, and storage devices etc.

Memory-mapped I/O (MMIO):
In MMIO, devices are treated as if they are memory locations. They are assigned specific memory addresses in the address space, and the CPU can read from or write to these addresses just like it does with regular memory. The memory bus is shared between the main memory and the devices. This approach simplifies programming, as the same load and store instructions used for memory access can be used for device access.

Example code for MMIO ( in C-like system):

    // Define addresses for device registers
    #define DEVICE_CONTROL_REGISTER ((volatile uint32_t *)0x20000000)
    #define DEVICE_DATA_REGISTER    ((volatile uint32_t *)0x20000004)

    // Read data from the device
    uint32_t Data = *DEVICE_DATA_REGISTER;

    // Write data to the device
    *DEVICE_DATA_REGISTER = Data;

    // Control the device
    *DEVICE_CONTROL_REGISTER = 0x1; // Start the device

I/O-mapped I/O (IOMIO):

In IOMIO, devices are accessed through a separate set of I/O addresses that are different from regular memory addresses. These I/O addresses are communicated over a dedicated I/O bus. This approach was more common in older computer architectures but is less in modern systems.

Example code for IOMIO (in C-like system):

    // Read data from the device
    uint32_t data = in32(0x02F0); // Example I/O address

    // Write data to the device
    out32(0x02F2, data); // Example I/O address

    // Control the device
    out32(0x02F0, 0x1); // Start the device

Note: The in32 and out32 functions are actual I/O instructions specific to the architecture, it may different depends on the architecture your going to use.

Previous Post Next Post

Contact Form