I am writing a C program on NIOS II SBT for Eclplise to deal with Pushbuttons interrupts on a DE2 board, not that it matters but I keep running into this error 'keys_irq' undeclared(first use in this function) error. I dont know what I am doing wrong.
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;
}
CodePudding user response:
The function keys_int_init
is calling a reference to keys_irq
. Since keys_irq
is not yet defined, the compiler doesn't know what the function is. In order to avoid this, you can add something called a prototype at the beginning of the file, before keys_int_init
is defined.
void keys_irq(void* context);
This tells the compiler what type the function is so it knows how to handle it.