Microprocessor address space and variables?

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.

But I'm not able... how may I do it?

Many Thanks in Advance Marco Toschi

Reply to
Marco
Loading thread data ...

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.

Thad

Reply to
Thad Smith

I have tried doing this:

#define HEIGHT ... #define WIDTH ...

unsigned char *display[HEIGHT][WIDTH] = (unsigned char *)0x77200000;

display[y][x] = ...

But during compilation I receive an error message:

invalid initialize

What could I do?

Many Thanks Marco

Reply to
Marco

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;

Reply to
Lanarcam

You are declaring display as two-dimensional array of pointers to unsigned char, which I suspect is not your purpouse.

Possibly this:

unsigned char (*display)[HEIGHT][WIDTH] = (void*)0x77200000;

Vadim Borshchev

Reply to
Vadim Borshchev

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

unsigned char (*display)[WIDTH] = (void *)0x77200000;

instead, or, to express the same thing in a more verbose fashion:

typedef unsigned char t_display_row[WIDTH]; typedef t_display_row * t_display;

t_display display = (void *) 0x77200000;

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.
Reply to
Hans-Bernhard Broeker

Yes, this is the usual out-of-coffee slip of mind. I shouldn't have posted today :)

Vadim Borshchev

Reply to
Vadim Borshchev

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.