Exact memory location for Interrupt Service Routines

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

Exact memory location for Interrupt Service Routines

2,263 Views
CyrilG_
Contributor I
Hello,

I am trying to program my interrupts services routines (ISR) always at the same memory location. I know I have to use the prm file for this but I don't know exactly how to proceed. Right now, I put a pragma line before each ISR that looks like this:

#pragma CODE_SEG ISR_ADDRESSES
    __interrupt void ShootCurInterrupt(void);   

and I added this line to prm file.
ISR_ADDRESSES                 INTO FLASH1_SPECIAL1;

However I have more than one ISR and they will always be in FLASH1_SPECIAL1 but probably at differents locations if the link order of the files change (which might happens if somebody takes over the project or use another version of CodeWarrior). Is there a keyword I can use in my prm file to ensure that the ISR will always be at the same exact location ? (the size of the ISR will not change) In mnemonics, that would look like this

__interrupt void ShootCurInterrupt AT 0xE000 for instance

I read about some  PRAGMA options such as DIRECT, NEAR,... can they work in my case? Everytime I look for information about theses options, it is specified that their definition is backend dependent . What is the backend?, the compiler, the microcontroller ?

Thanks

Cyril


Message Edited by Cyril G. on 2008-06-11 10:52 AM
Labels (1)
Tags (1)
0 Kudos
5 Replies

634 Views
dkelly
Contributor I
I asked almost exactly the same question in http://forums.freescale.com/freescale/board/message?board.id=CW816COMM&thread.id=4301 where I needed to place a routine at a known address that it could be called from an older bootloader.

The solution was to create a section just for that routine. This is an HC12. Put this #pragma immediately prior to the C routine's definition:

#pragma CODE_SEG MUST_BE_0x40a2

and followed with

#pragma CODE_SEG DEFAULT

Now that there is only one routine in MUST_BE_0x40a2 you can accurately control its location in the PLACEMENT section of your .prm file.

Another method to consider if more than one routine is involved, such as the entire vector table, would be to put an array of jump indirects in a known ROM location. Jump indirect based on the value found in a RAM table. The ROM jump indirect table code size will not change so you can use the above technique to place the whole thing in the right place.
0 Kudos

635 Views
Lundin
Senior Contributor IV
The easist way to solve this is to check in the map file how much space a particular ISR takes, then reserve a chunk of memory in the flash for every ISR. They typically take at most 20 bytes of the flash, so if you give them a bit of margin, say 10 more bytes or so, you will be able to do modifications on them without getting linker errors.

Or if you are cheap, you could allocate the exact amount each function takes up, but it will be a pain to maintain them afterwards.
0 Kudos

635 Views
ARG_Raiker
Contributor I
you could use constant pointers to the functions that get resolved at compile time and work from there, but i dont know why you need those functions in the same place all the time, all that matters is the isr table entry...
0 Kudos

635 Views
Lundin
Senior Contributor IV
I can think of several reasons why you'd want them at a fixed address: bootloaders, flash programming algorithms, customized interrupt behavior in an app with limited flash etc etc.
0 Kudos

635 Views
CyrilG_
Contributor I
Thanks a lot for the information, I am going to try that I need to have constant address to implement some flash1 programmability from flash2.
 
Thanks
Cyril
0 Kudos