Copying info between RAM pages

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Copying info between RAM pages

2,496 Views
dborras
Contributor I
Hello
 
I wondering if someone can help me, i have a big problem withe the Paged RAM
 
I have two different structures, each on different RAM pages, one (StructureA) in RPAGE 0xF8 and the other (SturctureB) in RPAGE 0xFD. I need to copy some information from StructureB into StructureA.
 
I check at my compiler options and everything looks just fine, i set StructureA at RPAGE 0xF8 using the #PRAGMA directive and the memory map shows it in correct location.
 
However..... i have tried several ways to do this operation and i haven't been able to do so, i'm not quite an expert on 9s12x so i don't know if i'm doing this fine? Can someone explain me how to do this?
 
Maybe a quick example on how to implement it?
Labels (1)
0 Kudos
6 Replies

542 Views
dborras
Contributor I
I tried that and didn't work,

I made work by doing the following

void foo(unsigned char indexA, unsigned char indexB)
  _far unsigned char *pointerStructA = (_far unsigned char*) 0xf8000;
 
unsigned char        *pointerStructB = 0;
 
unsigned char         data = 0;

  pointerStructB = (unsigned char*)&StructB;

  data = pointerStructB[indexB];
  pointerStructA[indexA] = data;

end


However, i have another question, i tried to assign the address where pointerStructA should be just like a did for pointerStructB and i was not able to do it, it should be 0xf8000 but everytime i did i was always setting it to a flash address, i can't recall which one was it.

Why is that? how do i make the system able to extract the global address where a variable is allocated and not the logical one? i tried declaring the variable as far instead of using the pragma directive but didn't work!
0 Kudos

542 Views
CompilerGuru
NXP Employee
NXP Employee
Both the #pragma and the __far qualifiers are needed as they serve a different purpose.
The "#prgama DATA_SEG __RPAGE_SEG XYZ" places the variable in the corresponding section and it also tells the compiler to access the variable with rpage access.
The __far pointer qualifier (should be after the * for every pointer) tells the compiler that this is a pointer capable of accessing __far objects.

With the assumption that  StructB is allocated correspondingly in a #pragma with a __RPAGE_SEG  or __GPAGE_SEG qualifier, I would write it like this.
StructA should be just the same.


Code:
void foo(unsigned char indexA, unsigned char indexB)  unsigned char * __far pointerStructA = (unsigned char* __far) 0xf8000;  unsigned char *__far pointerStructB;  unsigned char         data = 0;  pointerStructB = (unsigned char*__far)&StructB;  data = pointerStructB[indexB];  pointerStructA[indexA] = data;}




Of course it's a lot simpler to write StructA.fielda= StructB.fieldb, if the pragmas are correct, that should work fine too. If it does not for you, please show a complete sample. Also consider using two arrays, if that is the normal way accessing your data. Then ArrayA[indexA]= ArrayB[indexB] should work just fine.

Note that in your sample, you did not use a __far pointer for the pointerStructB, I wonder why that actually worked.

Also things I would really suggest to look into are the following two technical notes:

TN 238- HCS12X - Data Definition
TN 240- HCS12X - Accessing Data

TN's can be downloaded separately, they are not in the default installation, as far as I know.

Daniel


0 Kudos

542 Views
dborras
Contributor I
The problem i got before using a regular assigment like you suggested (StructA.fielda= StructB.fieldb) is that the RPAGE switching is being done only once so the system was ready to write into page 0xF8 it was trying to read the value of StructB also from this page and not from 0xFD.

I realized that by assigning the value of the StructA to a local variable it would keep this value in the stack before switching to RPAGE = 0xF8, and then the system switchs to page 0xF8 and extracts the value to be written from the stack and not from a RAM access, however this forced me to set the RPAGE back to 0xFD once the assigment is done or the code will get lost.

As i told you, i was able to make it work with the example i gave you before, but now
what i would like to do is that instead of giving the address as a magic number ( 0xf8000) i want to do it with the "&" operator, something like this:

"unsigned char * __far pointerStructA = (unsigned char* __far) &StructA;"

However, when i do this, pointerStructA is set to 0x7FC000 and not to the 0xF8000 as it should be.
0 Kudos

542 Views
CompilerGuru
NXP Employee
NXP Employee
If the simple assignment did not work and if the address gets set to a flash one when you use the address operator, then I suspect that something in the way you define or declare the StructA/StructB variables is wrong, or that there is a problem in the prm file.
Can you provide a complete sample showing the problem? I understand that it does not work for you so far, but the parts you showed so far did look ok, but there is plenty of not shown stuff which may really contain the problem. Did you look up the TNs?

Also I don't understand this part:
>however this forced me to set the RPAGE back to 0xFD once the assignment is done or the code will get lost.
How can the code get lost by changing RPAGE?
If that code gets executed by an interrupt handler, make sure it generates the needed staking of the page registers (I think by using the -CRPGAGE option)
For the compiler the RPAGE register content is volatile, its undefined after any function call, so normally RPAGE does not need to be backed up (with the exception being interrupt handlers).

Daniel
0 Kudos

542 Views
kef
Specialist I
  unsigned char * far pointerStructA = (unsigned char * far)0xf8000;
0 Kudos

542 Views
CompilerGuru
NXP Employee
NXP Employee
A simple assignment should do it.
Either assign all the fileds you need or just assign a complete struct if all the fields have to be copied.

Can you show a complete sample of what you tried?
Best if the sample is compilable on its own.

Daniel
0 Kudos