0

我有一个指针,它被传递给这样的函数:

unsigned char globalvar;

int functionexp(unsigned char *buff){
    globalvar = buff;
    //start interrupt
    //wait for end of interrupt
    //pass original pointer back with updated results
}

void __attribute__((interrupt, no_auto_psv)) _DMA2Interrupt(void) {
    globalvar = somedata;
}

我有一个中断,它收集我需要传递给所述指针的数据。我想要做的是创建一个全局虚拟变量并将原始指针(bufF)地址复制到这个全局变量中,所以当我将数据写入可以在中断中访问的全局变量时(因为我无法传递原始指向中断的指针)它还会更新原始指针中的值。

我的示例显示了我想要做的基础,但没有指针语法。有人可以告诉我如何做到这一点,拜托!

4

1 回答 1

2

你的问题并不完全清楚。我对我认为你正在尝试做的事情的第一个解释是这样的:

unsigned char **buffptr;

int functionexp(unsigned char *buff){
    buffptr = &buff;
    //start interrupt
    //wait for end of interrupt
    //pass original pointer back with updated results
    // after this point, the value of buffptr is completely useless,
    // since buff doesn't exist any more!
}

void __attribute__((interrupt, no_auto_psv)) _DMA2Interrupt(void) {
    *buffptr = somedata;  
    // this changes the 'buff' variable in functionexp
}

另一方面,您可以简单地说:

unsigned char *globalbuff;

int functionexp(unsigned char *buff){
    globalbuff = buff;
    //start interrupt
    //wait for end of interrupt
    //pass original pointer back with updated results
}

void __attribute__((interrupt, no_auto_psv)) _DMA2Interrupt(void) {
    globalbuff[0] = somedata;
    // this changes data inside the buffer pointed to by the 'buff' 
    // variable in functionexp
}
于 2013-07-11T22:35:09.513 回答