2020/10/26 13:40:23
TomasParrado
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;
}
// - * - * - * -
2020/10/27 09:25:23
du00000001
Including the header into InterruptFunctions.c creates one instance, including it into main.c creates another one.
(That the same doesn't happen to the functions (which should better be declared "extern" in the Header as well) is not a mystery but just some convenience. The same convenience cannot be applied to variables (including function pointers).)
 
Make *pstepISR(void) extern in the header and add a duplicate of the current definition to EITHER main.c or InterruptFunctions.c.
2020/10/27 10:27:06
TomasParrado
du00000001 Apologies for the multiple posting, I didn't realised it needed human approving  - I was battling the chrome sign-in error and assumed my post was not getting through. Should i delete the duplicates or will an admin?
2020/10/27 10:41:15
TomasParrado
Yep. Worked as you said.
I didn't need to (or perhaps was allowed not to) do that in XC8.
Thank you!
2020/10/28 01:57:25
du00000001
TomasParrado
Yep. Worked as you said.
I didn't need to (or perhaps was allowed not to) do that in XC8.
Thank you!



It's just the same in XC8.
Might be you didn't include this header into main.c previously - - - or did some other change.
 
P.S.: Suggest to leave the duplicates as they are: seems that threads cannot be deleted, and deleting the content (per editing it) does not make sense.
These's no standard procedure to cope with this - let's try to introduce one: edit the headline of the duplicates - adding "[duplicate - abandoned]" (including the square brackets) to make clear that these are intended to remain dead.
2020/11/04 09:58:27
TomasParrado
du00000001
P.S.: Suggest to leave the duplicates as they are: seems that threads cannot be deleted, and deleting the content (per editing it) does not make sense.
These's no standard procedure to cope with this - let's try to introduce one: edit the headline of the duplicates - adding "[duplicate - abandoned]" (including the square brackets) to make clear that these are intended to remain dead.



Done
© 2021 APG vNext Commercial Version 4.5

Use My Existing Forum Account