Using generated code in CodeWarrior

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

Using generated code in CodeWarrior

4,408 Views
SeanW
Contributor II

  Can you give me any insight into how to get a basic interrupts working? When I auto generate a new MPC5567 project it comes up with these IntCInterrupts.c and Exceptions.c.

 

I am not sure as to how to utilize these files and there are no examples out there. Is there an Appnote or some documentation/example someone knows about?

 

Thanks

Labels (1)
8 Replies

1,119 Views
wernermotz
Contributor II

Hello,

I could need some help implementing an ISR. I am using CW 2.10 for MPC55xx.

Although I did everything Stanislav told, my FLEXRAY_ISR Handler is never called.

Instead always the EXCEP_DefaultExceptionHandler() is called. What did I wrong?

INTC_InitINTCInterrupts();

INTC_InstallINTCInterruptHandler(FLEXRAY_ISR, 352,2);

  

INTC.CPR.R = 0;

asm("wrteei 1");   

Enable_interrupts();

void FLEXRAY_ISR(void)

{

...clear channel interrupt flag....

}

Please help me. I am looking forward to your answers.

0 Kudos

1,119 Views
martinr_
Contributor II

Hi Werner,

better late than never. You've likely already figured this out. It seems like you mixed up the order of your initialisation. This should work:

void FLEXRAY_ISR(void)

{

...clear channel interrupt flag....

}

INTC_InstallINTCInterruptHandler(FLEXRAY_ISR, 352, 2);

INTC_InitINTCInterrupts();     //the default function generated by CW 10.6 for MPC5644A  already enables the external interrupts with asm("wrteei 1"); - it's probably the same in your case

enable_interrupts();

INTC.CPR.R = 0;

0 Kudos

1,119 Views
stanish
NXP Employee
NXP Employee

 

Hello SeanW,


I would suggest you to see  FAQS below:


FAQ-28861: For CodeWarrior for MPC55xx, how do I add an INTC external interrupt service routine into the project generated by the New Project wizard? 


FAQ-28883: For CodeWarrior for MPC55xx, how do I add an INTC external interrupt service routine into the project generated by the New Project wizard?


Stanish

 

 

0 Kudos

1,119 Views
Junjun
Contributor I

Hello Stanish,

 

I have the same problem to use the auto-generated INTC codes for MPC55xx here and the links you provided are not available anymore (FAQ-28861 and FAQ-28863 doesn't exist anymore).

 

I'm wondering if you have any other information (links or examples) for using the INTC.C file generated by CW for MPC55xx?

 

Thank you in advance

 

Roy

0 Kudos

1,119 Views
stanish
NXP Employee
NXP Employee

Hello Junjun,

 

The information below is valid for single core MPC55xx/56xx. In case of dualcore the additional core INTC is initialized  in a bit different way.

 

The project generated by the wizard configures INTC to the software vector mode. In order to use Hw vector mode I'd suggest you to use cookbook example as a template project instead of Wizard generated one: e.g:

 

<CW for MPC55xx and MPC56xx 2.x>\(CodeWarrior_Examples)\555x-CW\INTC-HWvector\ 

 

The CodeWarrior project initializes IVOR4 - External input interrupt during the startup. The default IVOR4 handler is INTC_INTCInterruptHandler(). This handler includes:

 

  1. interrupt prolog
  2. read the Interrupt controller acknowledge register (IACKR)
  3. branch into particular service routine in the interrupt handlers table
  4. signalization of end of the servicing of the interrupt request (EOIR).
  5. interrupt epilog
  6. return from interrupt

The interrupt handlers vector table is located in RAM  - INTCInterruptsHandlerTable[ ] and includes the addresses of the handlers for all the interrupt requests supported by the INTC interrupt controller. The default size of the table is 308*4 ( macro INTC_INTERRUPTS_REQUEST_VECTOR_TABLE_SIZE) for all derivatives. If the real number of external interrupts for the particular derivative is different you can update this macro.

 

In order to assign a custom interrupt handler you should:

 

  1. Initialize particular interrupt handler vector table entry in the code before the interrupts are enabled e.g.:

 

INTC_InstallINTCInterruptHandler(SwIrq4ISR, 4, 2);  //Software Interrupt

 

where

 

SwIrq4ISR is address of  the interrupt handler

4 is interrupt vector number (see the MCU reference manual, INTC Interrupt controller section, "Interrupt vector table")

2 is PSR priority assigned to the interrupt source

 

2.   Enable interrupts by decreasing value of current priority register (CPR) E.g.

 

INTC.CPR.R = 0;

 

 

Hope this will help

 

Stanish

1,119 Views
Junjun
Contributor I

Thank you very much, Stanish,

 

Your reply is very helpful.

 

So for assigning the interrupt, one just need to write the following:

 

INTC_InstallINTCInterruptHandler(,,); 

INTC.CPR.R = 0;

 

in the main function and write down the ISR after the main function? No initialisations for INTC or IrqVector are needed in the main.c?

 

And if more than one interrupt is needed, is it sufficient to just define more than one INTC_InstallINTCInterruptHandler(,,) in the main function and for each handler, write the corresponding ISR at the end?

 

Cheers,

 

Roy

0 Kudos

1,119 Views
stanish
NXP Employee
NXP Employee

Hello Junjun,

 

INTC and the exceptions are initilaized by the startup. Also external interrupts are enabled (wrteei  1) so you have to really only call INTC_InstallINTCInterruptHandler() for each Interrupt source, create the ISRs and set INTC.CPR to 0.

 

You can define the ISR function whereever you need but you need to include a function protoype into a C module where you call INTC_InstallINTCInterruptHandler() (assume it's main.c in your case). You can also add the implementations of the ISRs into main.c. You should then declare a ISR function prototype and then it doesn't matter if the ISR implementation is above or below the function that calls INTC_InstallINTCInterruptHandler()..

 

e.g.

 

void SCI_Isr(void);

void PIT_Isr(void);

void SW_Isr(void);

 

void SCI_Isr(void)

{

...

 clear_int_flag_sci()

}

 

void PIT_Isr(void)

{

...

 clear_int_flag_pit()

}


void SW_Isr(void)

{

...

 clear_int_flag_sw()

}




void main(void)

{

  Initialize_Peripherals();  // cofigure  SCI, PIT, SW + enable interrupts within the peripherals 

 INTC_InstallINTCInterruptHandler(SCI_Isr,,); 

 INTC_InstallINTCInterruptHandler(PIT_Isr,,); 

 INTC_InstallINTCInterruptHandler(SW_Isr,,); 

 INTC.CPR.R = 0;
...

}

 

Note:

The intitialization of INTC + Exceptions  is disabled for "RAM" build target by default. In case you'd like enable intitialization by the startup code you should explicitly add the macro below into your project (e.g. into the prefix files)

 

#define CALL_USR_INIT

 


Stanish




1,119 Views
carlgilbert
Contributor II

This was helpful.  Thanks!

0 Kudos