我正在為 Eclplise 在 NIOS II SBT 上撰寫一個 C 程式來處理 DE2 板上的按鈕中斷,這并不重要,但我一直遇到這個錯誤 'keys_irq' undeclared(first use in this function) 錯誤。我不知道我做錯了什么。
volatile int keys_edge_capture;
static void keys_int_init() {
void* keys_edge_capture_ptr = (void*) &keys_edge_capture;
// Enable all three keys as interrupt
IOWR_ALTERA_AVALON_PIO_IRQ_MASK(PUSH_BUTTONS_BASE, 0x0F);
// Reset edge capture register
IOWR_ALTERA_AVALON_PIO_EDGE_CAP(PUSH_BUTTONS_BASE, 0x00);
// Register ISR and place it on the interrupt table
alt_ic_isr_register(PUSH_BUTTONS_IRQ_INTERRUPT_CONTROLLER_ID, PUSH_BUTTONS_IRQ,keys_irq, keys_edge_capture_ptr, 0x00);
}
void keys_irq(void* context) {
// Recast context to keys_edge_capture type
volatile int* keys_edge_capture_ptr = (volatile int*) context;
// Read the edge capture to determine what triggered the interrupt
*keys_edge_capture_ptr = IORD_ALTERA_AVALON_PIO_EDGE_CAP(PUSH_BUTTONS_BASE);
if (*keys_edge_capture_ptr & 0b0100) // extract KEY2
*(red_leds) = *(switches);
else if (*keys_edge_capture_ptr & 0b1000) { // extract KEY3
//do something
}
// clear the edge capture register
IOWR_ALTERA_AVALON_PIO_EDGE_CAP(PUSH_BUTTONS_BASE, 0x00);
// dummy instruction to synchronize the handler
IORD_ALTERA_AVALON_PIO_EDGE_CAP(PUSH_BUTTONS_BASE);
return;
}
int main()
{
int SW_Value,Keys_Val;
int mask = 0xF;
while(1){
SW_Value = *(switches) & mask;
*(green_leds) = SW_Value;
keys_int_init();
}
return 0;
}
uj5u.com熱心網友回復:
該函式keys_int_init正在呼叫對 的參考keys_irq。由于keys_irq尚未定義,編譯器不知道該函式是什么。為了避免這種情況,您可以在檔案開頭添加一些稱為原型keys_int_init的東西,之前定義。
void keys_irq(void* context);
這告訴編譯器該函式是什么型別,因此它知道如何處理它。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/457190.html
上一篇:CSV檔案中用于初始化結構的字串
下一篇:從結構創建BST節點時的編譯錯誤
