I have a dsPIC33 and programming it using MPLAB X.
I have three files: main.c
ADC.c
ADC.h
In ADC.h I do a bunch of variable initialisation as follows:
typedef struct pinPair{
unsigned CH0:5,CH123:1,STAT:8,:2;
unsigned I:16;
unsigned V0:16;
unsigned V1:16;
unsigned V2:16;
}pinPair;
typedef pinPair PINPAIRS [5];
extern PINPAIRS pinPairs __attribute__((space(dma)));
then in my main.c file I realise the pinPairs variable:
//Define pinPairs data buffers
PINPAIRS pinPairs __attribute__((space(dma),aligned(256)));
int main(void) {
...
}
Now in my ADC.c file comes the confusing part, The variable pinPair is clearly aligned somewhere in the dam memory because if I do this:
DMA0STA=__builtin_dmaoffset(pinPairs);
the compiler just does its thing but if I do it in the way I was intending:
DMA0STA=__builtin_dmaoffset(pinPairs[pairCounter]);
I get the error:
error: Argument to __builtin_dmaoffset() is not the address of an object in a dma section;
But it is though !!!
Does anyone know what it is that this error means and how I could use the variable in the way I want ?
I can imagine multiple possibilities
The subentities of the array don't have the proper attributes set, and the compiler doesn't lift pinpairs[pairCounter] (a pinpair struct)
due to Paircounter being a variable, the compiler can't compute a compiletime address for value.
If the latter, a fixed value would work, if the former, then a compiler limitation that is pretty hard to workaround.
I'd try something like
DMA0STA=__dmaoffset(pinpairs)+dmacounter*uint16(&pinpairs[1]-&pinpairs[0])
(plus maybe some typecasts to get it assigned)