I’m trying to port over an old program I wrote for an an 8bit PIC in XC8 to a dsPIC in XC16 and it won’t compile. I’ve used 8bit PIC for several years, but this is my first time using the XC16 so I’m sure I’m being dumb.
The program (simplified version below) has a function pointer as an ISR, whereby consequent calls jump to different functions. AKA apart from an initial default function, every time the ISR runs it changes the function to be run next interrupt based on the logic of this one.
I keep getting the following compiler error;
“...production/InterruptFuctions.o(.nbss+0x0): In function `stepISR_AA':”
“...InterruptFuctions.c:18: multiple definition of `_pStepISR'”
But I don’t get why XC16 its complaining about multiple definitions. As far as I can see I have declarations in the .h and definitions in the .c as I believe it should be. I don’t think it’s needed, but I did try adding
void (*pStepISR)(void) = @stepISR_AA();
into the InterruptFunction.c, but that didn’t seem to help.
Other info: I’m using MPLABX 5.4, XC16 1.6 and the PIC I’m attempting to use is a dsPIC33CK64MP102.
Any help would be appreciated, thank you
// - - main.c - -
#include "InterruptFuctions.h"
#include <xc.h>
int main(void) {
initialiseStepInt();
while (1); //do nothing forever
}
void __attribute__((__interrupt__,no_auto_psv)) _PWM1Interrupt(void) {
pStepISR();
IFS4bits.PWM1IF = 0; //Clear flag at end
}
// - - InterruptFuctions.h - -
#ifndef _INTERRUPTFUCTIONSH
#define _INTERRUPTFUCTIONSH
#include <xc.h> //Compiler
#include <stdint.h> //Defines exact width integer types...
#include <stdbool.h> //Defines a boolean data type
#include <math.h>
void initialiseStepInt(void);
// - * - * - * -
void (*pStepISR)(void);
// - * - * - * -
void stepISR_AA(void);
// - * - * - * -
void stepISR_AB(void);
// - * - * - * -
void stepISR_BA(void);
// - * - * - * -
void stepISR_BB(void);
#endif
// - - InterruptFuctions.c - -
#include "InterruptFuctions.h"
void initialiseStepInt() {
// - INTERRUPT PRIORITY 6 -
IPC16bits.PWM1IP = 6; //PWM1 IntPrority -> 6
IFS4bits.PWM1IF = 0; //PWM1 clear IntFlag
IEC4bits.PWM1IE = 1; //PWM1 enable Int
pStepISR = stepISR_AA;
__builtin_enable_interrupts();
}
//void (*pStepISR)(void) = @stepISR_AA();
void stepISR_AA() {
//do AA stuff
// work out next interrupt type
if (1) pStepISR = stepISR_AB;
else pStepISR = stepISR_BB;
}
// - * - * - * -
void stepISR_AB() {
//do AB stuff
// work out next interrupt type
if (1) pStepISR = stepISR_BA;
else pStepISR = stepISR_AA;
}
// - * - * - * -
void stepISR_BA() {
//do AA stuff
// work out next interrupt type
if (1) pStepISR = stepISR_BB;
else pStepISR = stepISR_AB;
}
// - * - * - * -
void stepISR_BB() {
//do AA stuff
// work out next interrupt type
if (1) pStepISR = stepISR_AA;
else pStepISR = stepISR_BA;
}
// - * - * - * -