Use of #pragma interrupt

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Use of #pragma interrupt

12,244 次查看
mariano
Contributor I
Hello all,
 
I'm working with 56F801 DSP for AC motor control. In my current software, several functions are being called from an ISR. This is what I have:
 
-----------
From vector jumps:
 ...  jsr ISR_Function   // jump to ISR function  ...
-----------
void ISR_Function{
#pragma interrupt warn
    SecondFunction();    // call SecondFunction
}
-----------
#pragma interrupt called
void SecondFunction{
   AsmFunction();       // call assembly function
}
-----------
#pragma interrupt called
asm void AsmFunction{
    nop       // do something
}
 
Questions:
1) are the pragmas correctly used? For some reason, I'm still getting warnings that a non-interrupt function is being called from an interrupt function.
2) what happens if I call SecondFunction from a non-interrupt function (say MainBackgroundTask)?
3) Is there any special requirement for interrupt-called assembly functions?
 
Thanks!
Mariano
标签 (1)
0 项奖励
回复
3 回复数

2,179 次查看
pittbull
Contributor III
Hello,
I think "#pragma interrupt" is only for ISRs. It instructs the compiler to generate code for interrupt functions (context saving/restoring, put an RTI instruction at the end...). Functions called from an ISR don't need "#pragma interrupt" because they behave like normal functions.
Correct me if i'm wrong,
pittbull
0 项奖励
回复

2,179 次查看
mariano
Contributor I
According to the "Build Tools Reference" manual, regarding #pragma interrupt called:
 
You should use this pragma for all functions called from #pragma interrupt enabled ISRs. This is optional for #pragma interrupt saveall enabled ISRs, since for this case, the entire context is saved.
 
The idea is that the compiler saves the registers used by all the functions called by the ISR. Another option is using #pragma interrupt saveall, but don't want to save extra registers if I don't need that.
 
Thanks
0 项奖励
回复

2,179 次查看
mariano
Contributor I

Found my problem... The compiler needed to have the "#pragma interrupt called" before the very first prototype declaration. I had my first declaration in the header file as 'extern'.

I checked the code and the compiler generates RTIs and RTSs where needed.

Summary:
-----------
From vector table:
 ...  jsr ISR_Function()   // jump to ISR function  ...
-----------
void ISR_Function(void){   // my ISR function
#pragma interrupt warn  *** THIS ONE NEEDS TO BE HERE,
                            NOT BEFORE PROTOTYPE ***
   SecondFunction();    // call SecondFunction
}                     *** COMPILER ISSUES AN RTI HERE ***
-----------
From header file:        // header file of SecondFunction
#pragma interrupt called
extern void SecondFunction(void);  *** FOR SOME REASON,
                               PRAGMA GOES BEFORE THIS
                               DECLARATION ***
-----------
From c file:
void SecondFunction(void);  *** PRAGMA DOES NOT WORK
                        BEFORE THIS DECLARATION ***

void SecondFunction(void){
*** PRAGMA DOES NOT WORK INSIDE THIS FUNCTION *** 
 .....
} *** COMPILER ISSUES AN RTS ***

Does this make any sense? I find it a bit strange to have to use the #pragma in the declaration that has an 'extern'. Build manual does not seem to specify this. Moreover, I could never make the #pragma work inside the function body, as explained in the manual.

Thanks for all help
Mariano

0 项奖励
回复