Get and Set Variable on RAM1 segmen

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

Get and Set Variable on RAM1 segmen

Jump to solution
1,665 Views
Laxs
Contributor I

Dear All,

 

I am new on code warior and need you help.

 

my problem is get and set variable when the variable are on the RAM1 segmen.

 

this are my code:

 

derivarive.h

 

#pragma DATA_SEG  Myuse
  volatile far unsigned char SCIBUF[35];
#pragma DATA_SEG default

 

project.prm

/* This is a linker parameter file for the mc9rs08la8 */

NAMES END /* CodeWarrior will pass all the needed files to the linker by command line. But here you may add your own files too. */

SEGMENTS /* Here all RAM/ROM areas of the device are listed. Used in PLACEMENT below. */
    TINY_RAM                 =  READ_WRITE   0x0005 TO 0x000D;
    RAM                      =  READ_WRITE   0x0050 TO 0x00BF;
    RAM1                     =  NO_INIT      0x0100 TO 0x017F;
    RESERVED_RAM             =  NO_INIT      0x0000 TO 0x0004;
    ROM                      =  READ_ONLY    0x2000 TO 0x3F00;
    CONST_PAGE               =  READ_ONLY     0x3f01 TO 0x3FF9;
END

PLACEMENT /* Here all predefined and user segments are placed into the SEGMENTS defined above. */
    RESERVED                 INTO RESERVED_RAM;
    TINY_RAM_VARS            INTO TINY_RAM;
    DIRECT_RAM_VARS          INTO RAM, TINY_RAM;
   
    Myuse                    INTO RAM1;
   
    DEFAULT_RAM              INTO RAM, TINY_RAM;
    DEFAULT_ROM              INTO ROM;
    CONST_ROM               INTO CONST_PAGE;
END

STACKSIZE 0x00 /* no stack for RS08 */

//VECTOR 0 _Startup     /* Reset vector: this is the default entry point for an application. */
 

 

main.c

#include <hidef.h> /* for EnableInterrupts macro */  
#include "derivative.h" /* include peripheral declarations */

#include "QA_Features.h"
#include "QA_Function.h"

.

.

.

.

#ifdef __Test_Simulation__
         
          //E91020237676615F75CF//
          SCIBUF[0] = 0xE9;
          SCIBUF[1] = 0x10;
          SCIBUF[2] = 0x20;
          SCIBUF[3] = 0x23;
          SCIBUF[4] = 0x76;
          SCIBUF[5] = 0x76;
          SCIBUF[6] = 0x61;
          SCIBUF[7] = 0x5F;
          SCIBUF[8] = 0x75;
          SCIBUF[9] = 0xCF;
          
          // i want to get correct address of SCIBUF - i am have problem in here //

         TestSimulation((unsigned int *)&SCIBUF[0],5);
                  
#endif

 

QA_Function.c

void QA_Decryptor(unsigned int * uchStartAddress,unsigned char uchDataLength)
{
    volatile unsigned int *uintpTemporaryAddress = 0;   
    unsigned char uchLoop = 0;
    //unsigned char uchEncryption_key1 = 0;
    //unsigned char uchEncryption_key2 = 0;
    unsigned char uchTemporaryByte1 = 0;                
    unsigned char uchTemporaryByte2 = 0;

    //-------------------------------------------//
    // Input Form:
    // ID Key1 Key2 Length Data[Length] Checksum
    //-------------------------------------------//

    uchEncryption_key1 = *uchStartAddress; // get key1 at first Byte
    ++uchStartAddress;
    uchEncryption_key2 = *uchStartAddress; // get key2 at second Byte
    ++uchStartAddress;

.


.

.

.

}

void TestSimulation(unsigned int * DataAddress,unsigned char DataLength){
 
    QA_Decryptor(DataAddress,DataLength);
    QA_Encryptor(DataAddress,DataLength);   
}

 

My question is how i can get  uchEncryption_key1 = SCIBUF[1]???

 

Best Regards,

Hari

Labels (1)
Tags (1)
0 Kudos
1 Solution
699 Views
Navidad
Contributor III

RS08 can access any address within its address space, which is not limited to 256 bytes of course, but if your data is located above 0xFF you have to provide this information to the compiler by using the pragmas mantioned in my previous post.

 

If you want to use SCIBUFfrom different C modules you should define it in one module only and declare it as external in the other modules (but keep the pragmas for the external declarations also !).

View solution in original post

0 Kudos
5 Replies
699 Views
Lundin
Senior Contributor IV
You write just like that:

uchEncryption_key1 = SCIBUF[1];

though index 0 might be what you are after.

Why have you declared SCIBUF as far though? There is no far memory on RS08...
0 Kudos
699 Views
Navidad
Contributor III

On RS08 using data above 0xFF is a bit more complicated, since inherently, the core supports only 8-bit addressing (if you don't take into account the paging mechanism). If you have variables placed above this boundary, then it has to be accessed either as "far" or "paged". The difference between far and paged is that if you have an object (variable, array, etc) that crosses a page boundary then this object has to be far, not paged. With paged variables, the compiler assumes that the object is entirely stored in one page only, so it does not issue code for updating the PAGESEL register when accessing consecutive bytes within that object. For this particular problem, the solution is:

 

 

#pragma DATA_SEG __PAGED_SEG Myuse
volatile unsigned char SCIBUF[35];
#pragma DATA_SEG DEFAULT

 


If SCIBUF crosses a page boundary (the linker will issue a warning if so), then the declaration should contain __FAR_SEG instead of __PAGED_SEG. If this is the case, consider re-placing the object to avoid far addressing since it is very inefficient.

Another possible solution would be switching to the banked memory model. This means that the compiler will consider every data object as paged, which is also inefficient.

0 Kudos
699 Views
Laxs
Contributor I

Dear Lundin,

 

i try that's way because i when i try to include "derivative.h" into another *.c file

the compiler complain as an error. ok i understand.

 

so another way to know where the address of SCIBUF. but when i try it i can't find

correct address.

 

Dear Navidad,

 

I saw on the disassembler window, PAGESEL always sey to 0x04H to access the High Page RAM. when i try set/get SCIBUF on main.c (#included derivetive.h where SCIBUF was defined).

 

Ehm ic ic this is like mentioned on RS08 datasheet about The 8-bit register X contains the address that is used when register D[X] is accessed.

 

so it's mean i couldn't get the XXXX address of SCIBUF since the address register

is only 8 bit, is it?

 

when i try to include the derivetive.h into another *.C (my function) it's error...

it said the *.h file already used on main.o...

so my problem i can't use SCIBUF[1] = 0; or ecryption_key1 = SCIBUF[1]...

that way i try to get the address.... but the problem is RS08 isn't support 16 bit addressing.... is it?

 

Am I miss understod Navidad?

 

Need your help my friends.

Thx

 

0 Kudos
700 Views
Navidad
Contributor III

RS08 can access any address within its address space, which is not limited to 256 bytes of course, but if your data is located above 0xFF you have to provide this information to the compiler by using the pragmas mantioned in my previous post.

 

If you want to use SCIBUFfrom different C modules you should define it in one module only and declare it as external in the other modules (but keep the pragmas for the external declarations also !).

0 Kudos
699 Views
Laxs
Contributor I

Dear Navidad,

 

it working now.

Thank you very much All.

 

Cheers

0 Kudos