EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

Microprocessor address space and variables?

Started by Marco June 19, 2005
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


Marco wrote:

> 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?
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
"Thad Smith" <ThadSmith@acm.org> wrote in message 
news:1119240873.cfd6462b219b081c090b327515a0fa8a@teranews...
> Marco wrote: > >> 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? > > 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 >
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

Marco wrote:
> "Thad Smith" <ThadSmith@acm.org> wrote in message > news:1119240873.cfd6462b219b081c090b327515a0fa8a@teranews... > > Marco wrote: > > > >> 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? > > > > 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 > > > > > 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?
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;
On Mon, 20 Jun 2005 15:19:35 +0200, Marco <marcotoschi@_no_spam_email.it> 
wrote:

> unsigned char *display[HEIGHT][WIDTH] = (unsigned char *)0x77200000;
You are declaring display as two-dimensional array of pointers to unsigned char, which I suspect is not your purpouse.
> What could I do?
Possibly this: unsigned char (*display)[HEIGHT][WIDTH] = (void*)0x77200000; Vadim Borshchev
Vadim Borshchev <vadim.borshchev@127.0.0.1> wrote:

> unsigned char (*display)[HEIGHT][WIDTH] = (void*)0x77200000;
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.
On 20 Jun 2005 17:10:20 GMT, Hans-Bernhard Broeker 
<broeker@physik.rwth-aachen.de> wrote:

>> unsigned char (*display)[HEIGHT][WIDTH] = (void*)0x77200000; > > That's not any better than the other inherently unportable solutions > suggested a good deal earlier.
Yes, this is the usual out-of-coffee slip of mind. I shouldn't have posted today :) Vadim Borshchev

The 2024 Embedded Online Conference