Interrupt Vector Question - Mod Help Please

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

Interrupt Vector Question - Mod Help Please

Jump to solution
1,606 Views
Jjarro
Contributor I

Hello,

   Currently using the HCS12C128 and Code Warrior

 

I have a question regarding interrupt vectors.

 

As a quick set up I have the following program folder/file set up

Sources

    -isr_vectors.c

    -main.c

    -datapage.c

 

Includes

    -derivate.h

    -MC9S12C128.h

 

Project Settings

    -Startup Code

        =Start12.c

    -Linker Files

        =burner.bbl

        =Project.prm

        =Project.map

 

The ISR_vectors file is the one present in the Code Warrior examples.

Lets say I want to use my RTI interrupt to be initialized as follows above my main call in my main.c file

 

#pragma CODE_SEG  __NEAR_SEG NON_BANKED

interrupt void RTI_ISR(void) {

 

//Do something

 

}

 

#pragma CODE_SEG DEFAULT

 

This portion declares my function RTI_ISR as an interrupt routine in nearby memory.

 

My question is as follows :

If in my ISR_VECTORS.C file I change Vector 7's(RTI INTERRUPT VECTOR) name from UnimplementedISR to

my function name and include the prototype function at the start of my ISR_VECTORS.C file, my Interrupt should be correctly implemented ?

 

using the declaration below extern void near _Startup(void) at the top of the ISR_VECTORS.h file

 

extern void near RTI_ISR(void);

 

OR

 

Do I need to also go into my Projectt.prm file and add something to the vector table at the bottom of that file ?

 

Thanks for your help.

Labels (1)
0 Kudos
1 Solution
570 Views
kef
Specialist I

If you are using vectors table defined in *.c file, then

1) you should remove or comment all VECTOR N nnn entries from your PRM file.

2) If you don't reference your vectors table from other C routines, then most likely it won't be linked. To fix that add your vector table to ENTRIES section in prm file:

 

ENTRIES /* keep the following unreferenced variables */
   VectorsTable // VectorsTable is the name of your vectors table
END

View solution in original post

0 Kudos
5 Replies
571 Views
kef
Specialist I

If you are using vectors table defined in *.c file, then

1) you should remove or comment all VECTOR N nnn entries from your PRM file.

2) If you don't reference your vectors table from other C routines, then most likely it won't be linked. To fix that add your vector table to ENTRIES section in prm file:

 

ENTRIES /* keep the following unreferenced variables */
   VectorsTable // VectorsTable is the name of your vectors table
END

0 Kudos
570 Views
Jjarro
Contributor I

Thankyou for the quick response and help Kef.

 

 

The .prm file is a paramater file to load initial locations and settings ?

 

I am a little confused on what this file does, it was not covered in any texts I have read either by Huang or other university HCS12 textbook writers or my instructors, and not being a dedicated Comp Science student, am a little lost.

 

I was browing and a Moderator Crassy Cat informed another user that they could add the interrupt vector to their .prm file using the following code segment

 

VECTOR ADDRESS HEX_INTERRUPT_ADDRESS INTERRUPT_SUBROUTINE_FUNCTION_NAME

 

Example :

VECTOR ADDRESS 0xFFF0 MY_Int

 

But instead of manually inputting the vector address for each interrupt vector, I am simply telling my parameters file to look at ISR_VECTORS.c when it initializes/compiles my program and it will load the information into ram ?

 

Therefore I would have the following total solution to fully implement my Interrupt vectors/functions :

Main.c

 

#pragma CODE_SEG  __NEAR_SEG NON_BANKED

interrupt void RTI_ISR(void) {

//Do something

}

#pragma CODE_SEG DEFAULT

 

ISR_vectors.c is an included file in my project folder present in the freescale included software which creates an easy

table for vectors present at a certain place in memory (INTERRUPT VECTORS).  I replace the correct vector if using the RTI

(Vector 7) with the name of my interrupt sub routine, in this case RTI_ISR.

 

I must also include the following declariation in ISR_vectors.c in order to link the vector name to a function, that can be used outside of ISR_vectors.c using the follow declariation at  the top of my ISR_vectors.c file

 

extern void near RTI_ISR(void);

 

I then link this ISR_vectors.c file to my main.c not using any #include but altering my .prm file (PARAMETER FILE)

in the ENTRIES SECTION to include the following

 

ENTRIES /* keep the following unreferenced variables */
   ISR_Vectors.c // VectorsTable is the name of your vectors table
END

 

Thanks for help again guys, I am trying to be really clear and provide as much information as possible, I float around these forums often, just recently registered :smileyhappy:

 

0 Kudos
570 Views
kef
Specialist I
  • The .prm file is a paramater file to load initial locations and settings ?

+-yes. You can change there stack size or initial stack pointer, define custom memory segments etc.

 

 

  • I am a little confused on what this file does, it was not covered in any texts I have read either by Huang or other university HCS12 textbook writers or my instructors, and not being a dedicated Comp Science student, am a little lost.

It is not a part of any standard, so IMO it's OK to not talk about that in the book, leaving your mind open for different tool suites, which are using different ways to specify stack addresses or memory segments. Every compiler vendor has it different. GNU, Imagecraft, Cosmic, IAR etc

 

 

  • VECTOR ADDRESS HEX_INTERRUPT_ADDRESS INTERRUPT_SUBROUTINE_FUNCTION_NAME
  •  
  • Example :
  • VECTOR ADDRESS 0xFFF0 MY_Int

There are different ways to specify interrupt vectors in Codewarrior. It could be done in C code like this:

 

interrupt 5 void isr(void)

{

}

 

where 5 is vector number counting down from the topmost. The topmost vector number is 0, and it's reset vector at 0xFFFE.

 

 

  • But instead of manually inputting the vector address for each interrupt vector, I am simply telling my parameters file to look at ISR_VECTORS.c when it initializes/compiles my program and it will load the information into ram ?

Not at all. Adding something to ENTRIES section forces linker to not optimize away not referenced objects. Since vectors table defined in your C file most likely is not refereced, you need to tell linker to not ignore it.  

 

 

  • Therefore I would have the following total solution to fully implement my Interrupt vectors/functions :
  • Main.c
  •  
  • #pragma CODE_SEG  __NEAR_SEG NON_BANKED
  • interrupt void RTI_ISR(void) {
  • //Do something
  • }
  • #pragma CODE_SEG DEFAULT
  •  
  • ISR_vectors.c is an included file in my project folder present in the freescale included software which creates an easy table for vectors present at a certain place in memory (INTERRUPT VECTORS).  I replace the correct vector if using the RTI (Vector 7) with the name of my interrupt sub routine, in this case RTI_ISR.

 

yes 

 

 

  • I must also include the following declariation in ISR_vectors.c in order to link the vector name to a function, that can be used outside of ISR_vectors.c using the follow declariation at  the top of my ISR_vectors.c file
  •  
  • extern void near RTI_ISR(void);

 

yes

 

  • I then link this ISR_vectors.c file to my main.c not using any #include but altering my .prm file (PARAMETER FILE)
  • in the ENTRIES SECTION to include the following
  •  
  • ENTRIES /* keep the following unreferenced variables */
  •    ISR_Vectors.c // VectorsTable is the name of your vectors table
  • END

 

No. ENTRIES section contains list of objects, not list of files. How is called your vectors table in ISR_Vetors.c? Say it is myvecttable[]. Then you add myvecttable to ENTRIES section.

 

0 Kudos
570 Views
Jjarro
Contributor I

Thanks again Kef, I was busy during the day but I read your response, and of course it generates a few more questions, I hope you don't mind.  This thread is very helpful to me and I hope to others.

 

If I choose to use

interrupt 5 void isr(void)

{

}

 

I would replace


#pragma CODE_SEG  __NEAR_SEG NON_BANKED
interrupt void RTI_ISR(void) {
//Do something
}
#pragma CODE_SEG DEFAULT

 

Your syntax works based on CW seeing the interrupt keyword, knowing to look for a numerical value to know WHICH interrupt vector the function would work with, then assigning a void return type, the ISR's name, then a void parameter pass

 

Using this I would still need to update my ISR_Vectors.c  to have the vector associated with interrupt 5 associated with the same function name ? Or does it not matter if I change the name because my HCS header file dictates that 5 = Interrupt 5 no matter what I change the label to in my ISR_Vectors.c file ?

 

Then because I have included the ISR_vectors OBJECT in my prm file, my program will know that the interrupt 5 is associated with the correct address as dictated by my ISR_Vectors.c file.   Should I also include a prototype extern declaration in my ISR_Vectors.c as I did with  my previous ISR subroutines ? Example using new syntax at top of ISR_Vectors.c would read

 

extern interrupt 5 void isr(void);

 

Thanks again Kef

0 Kudos
570 Views
kef
Specialist I

1)#pragma CODE_SEG  pragmas are still required (at least using banked memory model).

2) interrupt vector numbers are defined in derivastive header files. For example VectorNumber_Vrti for RTI vector.

3) interrupt keyword is not part of standard. Array of interrupt vectors in pure C is better solution.

 

Using "interrupt N" method you don't need ISR_Vectors.c file. If you have ISR_Vectors.c added, then you should not use other methods to specify vectors, and you should remove all vector definitions from prm file and all instances of interrupt N.

 

Name of ISR can be any. Matters only where each vector is pointing to.

 

Yes, ISR prototypes should be visible in ISR_vectors.c, along with CODE_SEG __NEAR_SEG NON_BANKED pragmas.

0 Kudos