Timer Interrupt For Serial Bootloader for S12(X) App AN4258

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

Timer Interrupt For Serial Bootloader for S12(X) App AN4258

723 Views
ashkhu
Contributor II

Hello. I'm trying to implement the Serial Bootloader for S12(X) AN4258 using a S12GA240/S12G240 microcontroller. We have an external watchdog which needs to be reset every 1o to  50 ms. I would like to use the timer interrupt module to set the external watchdog. I have this working on my main application code, not the bootloader though. I'm not able to do this right now, so the micro keeps getting reset. I'm trying to implement the watchdog reset without the interrupt and it will most likely work but using the timer interrupt module would be much easier.

 

Below is my code for setting up the timer interrupt module. We have a 8MHz resonator. Bus speed is set to 16MHz.

void Timer_Interrupt_Configure(void)

{

   // Function to configure the timer interrupt module

 

   // Configuration for timer overflow interrupt

    TSCR1_PRNT    = 0;         // Enable legacy timer. PR0, PR1, and PR2 bits of the TSCR2 register are used for timer counter prescaler selection.

    TSCR1_TFFCA   = 0;         // Allow the timer flag clearing to function normally

    TSCR1_TSFRZ   = 0;         // Allow the timer counter to continue running while in freeze mode

    TSCR1_TSWAI   = 0;         // Allow the timer module to continue running during wait

    TSCR1_TEN     = 1;         // Enable timer

 

   // Timer Clock Selection

   // Timer Clock = Bus Clock / 1

    TSCR2_PR2     = 0;

    TSCR2_PR1     = 0;

    TSCR2_PR0     = 0;

  

    TSCR2_TOI     = 1;         // Enable timer overflow interrupt

  

    TFLG2         = 0x80;      // Clear timer interrupt flag

}

 

interrupt void TOI_ISR(void)
{
  TFLG2 = 0x80; // Clear interrupt flag
}

 

 

 

If anyone can provide some helpful information I would appreciate it. Thank You.

Labels (1)
0 Kudos
1 Reply

388 Views
RadekS
NXP Employee
NXP Employee

Hi Ashiful,

I would like to note, that implementing of watchdog service code into ISR is not best idea. We do not have information whether main code works or not (therefore such watchdog is almost useless). However I am sure that you are aware about that risk and you are right, interrupt implementing could be simpler.

There could be problem with TSFRZ bit and your debugging method. I would like to recommend set that bit in this case for avoid situation when debugger blocks timer overflow.

I didn’t test it, but it is possible that counter stays in power save mode since all channels are in input capture mode and all channels are disabled.

I suppose that you defined TOI_ISR vector number as 16 in prm file (VECTOR 16 TOI_ISR). I am right?

Timer output compare example code could be found in S12G example pack. See G240-TIM_50us_period-CW51 example code:

https://community.freescale.com/docs/DOC-93792

Alternatively you could use also RTI or API (could run also in stop mode).


I hope it helps you.

Have a great day,
RadekS

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos