How to use src code with on-chip register data type definitions that differ from rest of project

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

How to use src code with on-chip register data type definitions that differ from rest of project

Jump to solution
2,444 Views
AndersJ
Contributor IV
I am trying to use code from AN2720, designed for use with HCS12 stationery,
and its header files, but my project is based on Processor Expert and its header files.
 
This means that datatypes, in this case flash memory data types, are not recognized
by my PE based datatypes.
 
I have imported som stationery headers and finally managed to compile correctly,
but the linker protests since I am trying to overlay my flash register on memory space
already defined by PE, at 0x100 + REG_BASE)
 
Q1. What is needed to locate a variable of one datatype at the same adress as another?
Q2. What is the best and correct way to use HCS12 stationery based sw, in a otherwise PE based environment?
 
Thanks,
Anders J
 
 
 
 
 
 
 
The c
 
 
 
 
Labels (1)
Tags (1)
0 Kudos
1 Solution
816 Views
CrasyCat
Specialist III
Hello
You have two solutions to do that:
  1- Use a macro, which will just be an alternate name for the register defined by processor expert:
       For example
         #define MyAltData PORTA
   2- You can remap the error message about overlap allocation to a warning or information message.
        - Start IDE
        - Open your project
        - Open the target setting dialog
        - Switch to "Linker for HC12" panel
        - Click on Messages
        - Go to the Error Tab, search for your error message (You should have got a message identification number)
        - Select the message and press Information or Warning. The message is redefined as a warning or information.
 
I do not like the second solution as it may hide some other un-wanted overlap allocation.
 
CrasyCat

View solution in original post

0 Kudos
3 Replies
816 Views
AndersJ
Contributor IV
Thanks for your comments on the issue.
 
1-I have tried the define suggestion.
 It seems to work up and until I get to a point where
 my original register name includes periods which the
 compiler possibly dislikes.
 
 Original source code: 
   Flash.fclkdiv.byte = Flash.fclkdiv.byte | fclk_val| FDIV8;
 
 Attempt to define:
 #define Flash.fclkdiv.byte FCLKDIV
 
(FCLKDIV is how PE defines this particular register.)
 
 This line compiles OK, but later on when the substitiution needs
 to take place, there is a a complaint about '}' missing error C2801,
 and fclkdiv not declared, error C1815.
 
 I have hardcoded this instead, and tried the same method with FDIV
 which works OK. The only difference between them seem to be the
 periods in the "Flash.fclkdiv.byte" line.
 
2-I also dislike ignoring warnings and errors.
  I want clean compiles/links.
 
The define method seems to be best, if I could make it work.
Can you figure out what is wrong?
 
Thanks,
Anders
 
Source cutout follows:
// Attempt to redefine offending defintions, but it seems the periods are disliked.......
#define Flash.fclkdiv.byte FCLKDIV
#define FDIV8 PRDIV8
extern DoOnStack(unsigned int *far address);
//*****************************************************************************
//* Function Name : Flash_Init
//* Description  : Initialize Flash NVM for HC9S12 by programming
//*          FCLKDIV based on passed oscillator frequency, then
//*             uprotect the array, and finally ensure PVIOL and
//*             ACCERR are cleared by writing to them.
//*
//*****************************************************************************
void Flash_Init(unsigned long oscclk)
{
unsigned char fclk_val;
unsigned long temp;
 
/* Next, initialize FCLKDIV register to ensure we can program/erase */
 temp = oscclk;
 if (oscclk >= 12000) {
  fclk_val = oscclk/8/200 - 1; /* FDIV8 set since above 12MHz clock */
  Flash.fclkdiv.byte = Flash.fclkdiv.byte | fclk_val| FDIV8;
//    FCLKDIV = FCLKDIV | fclk_val| FDIV8;      // WORKS!!!!!!!!!!
//  FCLKDIV = FCLKDIV | fclk_val| FCLKDIV_PRDIV8;    // WORKS!!!!!!!!!!
 }
 else
 {
  fclk_val = oscclk/8/200 - 1;
  Flash.fclkdiv.byte = Flash.fclkdiv.byte | fclk_val;
 }
 Flash.fprot.byte = 0xFF; /* Disable all protection (only in special modes)*/
 Flash.fstat.byte = Flash.fstat.byte | (PVIOL|ACCERR);/* Clear any errors  */
  
}
0 Kudos
816 Views
CrasyCat
Specialist III
Hello
 
According to ANSI C definition you cannot have dots in macro names.
Additionally the two register definition are not compatible at all (there is one level ore in the definition of AN2720.
 
Here the only choice you have is to either disable the linker message or rewrite the source code to use register names according to Processor Expert definition.
 
Sorry about that.
 
CrasyCat
817 Views
CrasyCat
Specialist III
Hello
You have two solutions to do that:
  1- Use a macro, which will just be an alternate name for the register defined by processor expert:
       For example
         #define MyAltData PORTA
   2- You can remap the error message about overlap allocation to a warning or information message.
        - Start IDE
        - Open your project
        - Open the target setting dialog
        - Switch to "Linker for HC12" panel
        - Click on Messages
        - Go to the Error Tab, search for your error message (You should have got a message identification number)
        - Select the message and press Information or Warning. The message is redefined as a warning or information.
 
I do not like the second solution as it may hide some other un-wanted overlap allocation.
 
CrasyCat
0 Kudos