Reputation: 79
Can any one explains me clearly, what is mapping? Port mapping? Memory mapping? In firmware development.
I gone through many other sites, still the question is not clear.
Asked in an interview for Firmware Developer.
The actual question is "How does you access data holding in the register/memory of a controller using C?" (and he given clue do you know memory mapped I/O, port mapped I/O? like that.
I understood the question may be like this,
If there is data in SPI/I2C/ADC such memory buffers of a microcontroller, how do you access that data? The question asked by Graphene Semiconductors.
thank you
Upvotes: 2
Views: 1376
Reputation: 11
Port mapping and memory mapping are totally different. Port mapping is to assign which port to use. For example, which port you want to use for serial communication, UART1 or UART2 or USB?
Memory mapped IO shares same memory address space for IO(same space but unique address). But, Memory isolated IO has separated space for memory & IO.
*gpio_for_led = 1; // mem mapped io
gpio_for_led = 0x1234; //isolated io(assembly code has in, out instruction)
outportb(gpio_for_led, 1);
Does this make you clear?
Upvotes: 1
Reputation: 12263
For port mapped IO you need an extra driver for the interface. That would define completely how to address the external device. It can be as simple as a GPIO just driving an external register with a strobe, or SPI. All this is mostly software-defined or given by the interface. However, it has no relation to the CPU address and data bus.
Memory mapped IO is just as if the register was a variable in the normal address space. However, you need to ensure the compiler does neither optimize away accesses, nor reorder them (either to the same variable or to other such registers). As the address for such a register is fixed by the hardware, one might either set that by the linker(-script) or as follows (for a 16 bit read/write register at address 0x1234):
#define REGX (*(volatile uint16_t *)0x1234)
Upvotes: 0
Reputation: 11648
Memory mapped I/O allows writing/reading to I/O devices the same as reading/writing to normal memory (using the same machine code/asm). You use up physical memory address space for your memory mapped I/O devices.
Usually there is some address decoding logic between CPU and RAM so when you hit a memory location which belongs to an I/O device the address decoding logic kicks in and connect the CPU address lines to that I/O device (instead of RAM).
It's a neat way to access I/O but it consumes memory space.
Port mapping I/O allows writing/reading to I/O devices using special asm instructions (in
and out
in x86 assembly). You don't consume memory address space.
Upvotes: 3