Handling Multiple Exceptions

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

Handling Multiple Exceptions

2,246 Views
Kirilian
Contributor I

Processor:  MPC5554

Codewarrior:  5.9.0 (ver 2.2.1 for MPC55xx)

 

What is the correct way to handle multiple exceptions such as the decrementer and fixed interval timer?  I can get each one to work by themselves just fine, but if I enable both the DEC and FIT interrupts, things don't work.

 

I am using the sample Exceptions.c file that is auto-generated by Codewarrior.  Instead of having all exceptions use the EXCEP_DefaultExceptionHandler function, I have created seperate functions for both the DEC and FIT and updated IVORx registers accordingly.

 

Do I need to use additional tags in the "__declspec(interrupt)" command?

 

Thanks!

Labels (1)
0 Kudos
4 Replies

503 Views
stanish
NXP Employee
NXP Employee

Hi Kirilian,

 

1) Your DEC and FIT exception routines should have both following pragmas (see FitISR example):

  

/* main.c */

#pragma push /* Save the current state */
#pragma force_active on
#pragma function_align 16 /* We use 16 bytes alignment for Exception handlers */
__declspec(interrupt)
#pragma section RX ".__exception_handlers"
__declspec (section ".__exception_handlers")
void FitISR(void)
{ 
  FITctr++;    /* Increment interrupt counter */
  SIU.GPDO[114].R = ~SIU.GPDI[114].R; /* Toggle GPIO output */ 
  ClrFitFlag();    /* Clear FIT's flag */  }
#pragma force_active off
#pragma pop

 

 2) export these ISRs into exception.c and use them to init IVOR10 and IVOR11

 

exceptions.c
------------
...
extern void FitISR();
...
_asm void EXCEP_InitExceptionHandlers(void){
...   
  /* IVOR11 Fixed-interval timer interrupt (SPR 411) */
  lis     r0, FitISR@h   
  ori     r0, r0, FitISR@l       
  mtivor11 r0
...

3) Check that FIT and DEC are correctly initialized. Especially TCR register that is common for both timers.

  

void DecFitInit(void)   
... 
  lis           r0, 0x05C1  /* Enable DEC interrupt and auto-reload */ 
  ori  r0, r0, 0x4000  /* FP=0, FPEXT=A for 0.7 sec timeout */ 
  mttcr  r0     
...

 

 You might init FIT and DEC in sequence so e.g. Fit TCR register configuration was overwritten  by DEC config.   

 

Note:

I'd suggest you to install latest CodeWarrior for MPC55xx v2.5 

(http://www.freescale.com/lgfiles/devsuites/PowerPC/CW55xx_v2_5_SE_Build_91008.exe) 

 

Stanish 

Message Edited by stanish on 2010-01-11 06:54 PM
0 Kudos

503 Views
alG
Contributor I

I am able to get the Decrementer CW Example to work fine on an MPC5554 eval board, but the Handler for that is in assembler and handles the Prolog and Epilog in the code.  I want to use C, but mostly I want the compiler to handle the prolog and epilog automatically. So I replaced the handlers.s in the example with the attached handlers.c, and even left the decrementer code as it was rather than coding it in C.  As far as I can tell, both files are identical except for the use of pragmas and declspec in the .c version.  The .s version works fine, but the .c version goes to an illegal instruction the first time it interrupts.  All I did was remove the file handlers.s and add handlers.c in the Decrementer CW Example project.  Can anyone see what is wrong ?

0 Kudos

503 Views
ronco
NXP Employee
NXP Employee

This should work.  You didn't say but are you working with code examples outlined in Application Note AN2865, "MPC5500 & MPC5600 Simple Cookbook"?  If not, please refer to it, along with the code-base in AN2865SW (search for these two IDs in the www.freescale.com "Enter keyword" search field.)

 

If you are already working with this App Note then, referring to Examples 2 and 3, just copy/paste the appropriate source code from one example into the other example.  These two interrupts should be able to operate in unison.  I hope this helps.

 

-Ron

0 Kudos

503 Views
admin
Specialist II

Hi ronco.

I have a similar problem Kirilian has.

I need to operate dual timer using Decrementer and FIT.

I used to two timer handlers independently using 20ms-timeout Decrementer and 5ms(about)-timeout FIT as if MPC5554 Cook book shows.

 

However, I’ll use complex dual timer.

For instance, at the start time, I only initialize the Decrementer(20ms-timeout).

Once taking Decrementer exception, FIT(5ms-timeout) is set in the Decrementer Interrupt handler.

Then, after 5ms, It will be occurred FIT exception. In the FIT Interrupt handler, I disable FIT.

 

With this concept, I made two timer handler toggling each GPIO.

I expected the result like attached jpg image.

 

but FIT exception timing is very unstable.

That means FIT exception must occur after every 5ms from Decrementer exception.

But it doesn’t work.

 

Would you check my pseudo code attached txt file?

Please give me your comment~

Thanks a lot.

Message Edited by zozzoo on 2009-12-18 02:33 AM
0 Kudos