I am using MPC5604S and eclipse based code warrior. I have enabled ADC and System timer using interrupt. ADC should have lowest priority and system timer should have highest priority.
Can anyone share me the code for the same. I need MPC5604S code only because am facing issue in priority. ADC interrupt gets called frequently than system timer interrupt. kindly guide me.
CW has pre-prepared everything what is needed to handle interrupts and exceptions.
Generated stationery contains files Exceptions.c and IntcInterrupts.c.
These files includes required initialization and also function INTC_InstallINTCInterruptHandler that is intended to create interrupt vector table and has 3 parameters (name of the function, vector and priority).
You can add function like this to your project:
static void Interrupts_init(void)
{
// Initialize interrupts and exceptions
EXCEP_InitExceptionHandlers();
INTC_InitINTCInterrupts();
// Create interrupt vector table
INTC_InstallINTCInterruptHandler(handler_1,103,2);
NTC_InstallINTCInterruptHandler(handler_2,102,1);
/* Lower INTC's current priority */
INTC.CPR.B.PRI = 0;
}
Also pay attention to interrupt nesting:
If INTC_NESTED_INTERRUPT == 0
then interrupt handler is called directly, interrupts are disabled during ISR execution and ISR cannot be affected by interrupt with higher priority
If INTC_NESTED_INTERRUPT == 1
then interrupt handler contains necessary prolog and epilog and interrupts are enabled during prolog allowing interrupt with higher priority to be handled first
Good luck and have a nice day.
thanks for the input. but i can explain u what is the issue am facing. I have 3 interrupts
a. ADC - low priority
b. System Timer - highest Priority
c. 2 CAN RX interrupts. - medium priority
So during ADC initialization am using this below code
INTC_InstallINTCInterruptHandler(ADC0_EOC_isr,62,2);
INTC.CPR.R = 2;.
- During System Timer initialization am using this below code
INTC_InstallINTCInterruptHandler(STM0_interrupt_isr,30,15);
INTC.CPR.R = 15;
- During CAN initialization am using this below code
INTC_InstallINTCInterruptHandler(FCAN0_ReceiveInt_isr,72,9);
INTC.CPR.R = 15;
INTC_InstallINTCInterruptHandler(FCAN1_ReceiveInt_isr,92,10);
INTC.CPR.R = 15;
Now the issue is the interrupts are not working based on priority. ADC interrupt is continuously invoked and not allowing it to go to other interrupts.
So I gave INTC.CPR.R in all the initialization because from the datasheet am not clear how to use it. so can u explain me what is the relation between INTC.CPR.R and INTC.PSR[vectorNum].B.PRI register. It will be great if u share me a sample code with all these functionalities I mentioned above.
Thanks in advance. :smileyhappy:
Have you tried it this way?
INTC_InstallINTCInterruptHandler(ADC0_EOC_isr,62,2);
INTC_InstallINTCInterruptHandler(STM0_interrupt_isr,30,15);
INTC_InstallINTCInterruptHandler(FCAN0_ReceiveInt_isr,72,9);
INTC_InstallINTCInterruptHandler(FCAN1_ReceiveInt_isr,92,10);
INTC.CPR.R = 0;
The INTC_CPR masks any peripheral or software settable interrupt request set at the same or lower
priority as the current value of the INTC_CPR[PRI] field from generating an interrupt request to the
processor.
Actually the issues was with the CAN interrupt configuration. After re-configuring the interrupt it was working fine.
Thanks for the support :smileyhappy:.