This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Dear C2000 expert,
I used C function as ISR entrance, and would like to call assembly function in C ISR. But I found that if I used ASP instruction at the beginning of assembly function, and NASP at the end of it, then the PC can't be restored to the value that before interrupting. Can you please let me know why? And what is the limitation of using ASP/NASP instruction?
Here is what my code looks like:
1. C function for ISR entrance:
//
// epwm1_timer_isr - Interrupt routines uses in this example
//
__interrupt void
epwm1_timer_isr(void)
{
EPwm1TimerIntCount++;
assembly_func();
//
// Clear INT flag for this timer
//
EPwm1Regs.ETCLR.bit.INT = 1;
//
// Acknowledge this interrupt to receive more interrupts from group 3
//
PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
}
2. Assembly function code: if the ASP and NASP instructions are in the function, then PC can't be restored into correct value after ISR execute completely.
; label to _assembly_func function
.def _assembly_func
.text
_assembly_func:
;context save
ASP
PUSH AR1H:AR0H
PUSH XAR2
PUSH XAR3
PUSH XAR4
PUSH XAR5
PUSH XAR6
PUSH XAR7
PUSH XT
;-----------------------
; full context restore
POP XT
POP XAR7
POP XAR6
POP XAR5
POP XAR4
POP XAR3
POP XAR2
POP AR1H:AR0H
NASP
LRETR ;Long Return Using RPC
Regards,
Jack
Jack,
I wanted to add that by using
PUSH AR0H:AR1H
...you are only protecting the upper 16-bits of those registers. This is normally done in an ISR because the automatic interrupt context save takes care of the low 16-bits of both registers. In a function call from C, the compiler will protect XAR0 anyway, but you'll need to protect XAR1 (if you use it) with:
PUSH XAR1
Similarly on context restore. See section 7.2 of the C compiler user's guide for details on which registers need to be protected on an assembly function call.
Regards,
Richard
Hi Richard,
It's very clear for me. Thanks for your great support.
Regards,
Jack