Content originally posted in LPCWare by RA1981 on Sat Sep 03 03:44:32 MST 2011
Hi,
I wonder if it's possible to access external devices as if they are internal memory locations.
I know some 8-bit MCU compilers where it's possible to have a additional "memory type" byte. This byte is used as a address extension. Because most 8-bit MCUs have different instructions for accessing code and data memory the address extension is used to determine which instructions have to be used.
This approach enables the developer to create "virtual" memory regions. For accesses to one of these non-predefined memory regions the compiler calls user-defined access functions, where the address extension byte defines which functions have to be called.
So, what's the advantage? For example, if the MCU has a internal EEPROM, access is usually done via modifying some special function registers, etc. Of course it's possible to write some access functions which deal with the register access, but the developer always have to take care about (at least) the address.
Using the above mentioned "virtual" memory and user-defined access functions enables the developer to create a variable in that memory region, but it can be handled like any other variable. The linker takes care of the address, etc. When accessing this variable the user defined access function is called and deals with the access - totally hidden from the developer. And, usually no pointer accesses could be done to such EEPROM contents. The above approach also enables pointer access, which is a big benefit in my opinion.
Another advantage is, when porting the software to a "smaller" MCU with non-internal, but external EEPROM, the access functions could be modified or new ones are created for a different memory region and the variables are moved to that region.
Is this possible in GCC/LPCxpresso?
Regards,
Ralf