|
|
View previous topic :: View next topic |
Author |
Message |
hamzamahmood96
Joined: 15 Jul 2019 Posts: 1
|
Pointer to Function in Interrupt |
Posted: Mon Jul 15, 2019 3:47 am |
|
|
Hello there.
I am using 2 external interrupts as of now. The ISR has to execute different functions, hence a pointer to function is incorporated into the code.
But when I try to build it, it tells me that I haven't defined the function (pointer to function), in contrast I have done so in the previous line itself(for debugging). The error being
Quote: | *** Error 112 "......\project_file.c" Line 180(1,1): Function used but not defined: ... p 874 SCR=13091 |
If I place a if(false) before executing the INT1_InterruptHandler(); call, it compiles. However, If I enter voltaitle static bool flag = false; and add if(flag) before executing the INT1_InterruptHandler(); call, it fails, with the same error.
Can you please help me in understanding this problem and the workaround for this ?
Provided is a MWE of the code. In this example INT2 is causing the problem. In my original code both external interrupts 1 and 2 are being problematic.
Pointer to functions are new to me, so please be generous with the explanation.
My compiler version is 5.081
Code: | #include "main.h"
#include <stdio.h>
void (*INT1_InterruptHandler)(void); //pointers to INT functions
void (*INT2_InterruptHandler)(void);
//
//INT 1 STUFF
//
typedef void (*_fnptr1)(void);
void INT1_SetInterruptHandler(_fnptr1 InterruptHandler){
INT1_InterruptHandler = InterruptHandler;
}
void INT1_DefaultInterruptHandler(void){
}
#INT_EXT1
void EXT1_ISR(void)
{
INT1_SetInterruptHandler(INT1_DefaultInterruptHandler);
INT1_InterruptHandler();
}
//
//INT 2 STUFF
//
typedef void (*_fnptr2)(void);
void INT2_SetInterruptHandler(_fnptr2 InterruptHandler){
INT2_InterruptHandler = InterruptHandler;
}
void INT2_DefaultInterruptHandler(void){
}
#INT_EXT2
void EXT2_ISR(void)
{
INT2_SetInterruptHandler(INT1_DefaultInterruptHandler);
INT2_InterruptHandler();
}
void main()
{
//INT 1 Setup
clear_interrupt(INT_EXT1);
ext_int_edge(INT_EXT1, L_TO_H);
INT1_SetInterruptHandler(INT1_DefaultInterruptHandler);
enable_interrupts(INT_EXT1);
//INT 2 Setup
clear_interrupt(INT_EXT2);
ext_int_edge(INT_EXT2, L_TO_H);
INT2_SetInterruptHandler(INT2_DefaultInterruptHandler);
enable_interrupts(INT_EXT2);
while(TRUE)
{
//TODO: User Code
}
} |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19518
|
|
Posted: Mon Jul 15, 2019 4:17 am |
|
|
Your syntax to call the function is not right.
What you are typing, says there is a function called INT1_InterruptHandler
to be called. There isn't (hence it is not defined)....
The syntax to call a function defined by the pointer, is:
(*INT1_InterruptHandler)();
This says to call the function pointed to _by_ INT1_InterruptHandler.
This is standard C.
Using the name without explicitly dereferencing, is a shortcut, that is
allowed in a lot of C's, but wasn't in the original C standard and is not
supported in CCS. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9229 Location: Greensville,Ontario
|
|
Posted: Mon Jul 15, 2019 5:02 am |
|
|
I don't understand why you're making it so complicated ? The PIC/Compiler have interrupt handlers for both external interrupts, so put the code inside the ISR.
ISRs are supposed to be short and fast. Having the PIC to jump out of the ISR to another location adds time to execute, which defeats what the ISR is supposed to do. It also makes it very hard to understand what should be happening...
Jay |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|