Hallo, I must create a memory for a display lcd. This is part of a microcontroller based on a microprocessor.
I thought to do it using a variable, a matrix: display[X][Y] (the software video memory).
This variable should exaclty stay into micrporcessor address space where I have mapped a ram (the hardware video memory) from 0x77200000 to 0x7720FFFF.
In this way, working with my variable I could edit hardware video memory.
I assume that you have mapped the video memory correctly with hardware and now want to know how to use the compiler to map an array to the video memory.
There are different ways to do this based on your compiler. Some compilers have extensions that allow you to specify the location of a variable. For others, you can declare it external and specify the address with the linker. In some, you might specify that the array goes into a separate memory segment (using an extension), then use the linker to specify the load address of the segment. You may be able to specify the absolute address in an assembly module and declare it extern in the C module. Finally, you could use a pointer instead of a directly addressed array and initialize the pointer to the video RAM address.
Use a one dimensional array #define LENGTH (HEIGHT * WIDTH) unsigned char * p_arr =(unsigned char*)0x77200000; if you want to access the cell (x,y) , p_arr[x*HEIGHT + y] = z;
That's not any better than the other inherently unportable solutions suggested a good deal earlier. It's a wild guess what an unknown platform might actually do if you cast a 32-bit integer value to a pointer type. So, since you have to do something unportable anyway, you might as well do it the way that best fits the actual platform.
Anyway, if one really wanted to do it this way, I suggest to forget about trying to hardwire HEIGHT, and use
This generates one redirection operation per access to the array less than Vadim's version, so it has a certain chance of being faster.
Depending on the platform, and the value of WIDTH, the "array of pointers to display rows" may be more efficient:
typedef t_display_row * t_display[HEIGHT];
This uses more memory, but the precomputed row pointers may be faster to use than 2D array indexing, which involves multiplication of one screen coordinate by WIDTH.
--
Hans-Bernhard Broeker (broeker@physik.rwth-aachen.de)
Even if all the snow were burnt, ashes would remain.
ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here.
All logos and trade names are the property of their respective owners.