Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Altera_Forum
Honored Contributor I
667 Views

Problem wid nios ii APIs

Hello all, 

I'm using Quartus v13.1 on my DE2-70 board with the cyclone II fpga. I want to enable interrupts using toggle switches. It worked when using the Altera ehanced interrrupt API (#include"altera_avalon_pio_regs.h"), However I tried using the nios 2 API (because we have some tutorials using it ) and It does not seem to work. For eg: 

 

I tried using the functions such as : __builtin_wrctl(3, 2) and __builtin_wrctl(0, 1) to write into the ienable and status register respectively. When i read the ipending register (ipending = __builtin_rdctl(4)) it shows 0 . I also tried replacing it with the nios 2 macros without much success. Here is the code i used: 

 

#include <stdint.h> 

#include <stdio.h> 

#include <stdlib.h> 

#include <unistd.h> 

#include "system.h" 

#include "nios2.h" 

volatile uint32_t *LED = (volatile uint32_t *) LEDS_BASE; /* Green leds base address*/ 

volatile uint32_t * slides = (volatile uint32_t *) 0x41000; /* slider switches base address*/ 

 

 

void toggle_isr() 

int press; 

press = *(slides+3); /* read the switch edge capture register*/ 

//*(slides+3) = 0; /* clear the interrupt */ 

printf("Hello from Nios 3! \n"); 

while(1) 

printf("Hello from Nios I4! \n"); 

if ((press & (1 << 1)) != 0) /* SW[1] */ 

printf("Hello from Nios II! %d \n", *LED); 

if(*LED == 0xFF) 

*LED = 0; 

(*LED)++; 

usleep(100000); 

void interrupt_handler(void) 

int ipending, status; 

printf("Hi! \n"); 

NIOS2_READ_STATUS(status); 

printf("HhgfghfjhgfghfI! %d \n", status); 

NIOS2_READ_IPENDING(ipending); 

printf("Hello from Nios II! %d \n", ipending); 

//if (((ipending & (1 << 1))) != 0 ) // toggle switches is interrupt level 1 

if (ipending != 0) // checking for enabled interrupts in general*/ 

printf("Hello from Nios 2! %d \n", ipending); 

toggle_isr(); 

// else, ignore the interrupt 

return; 

int main() 

*(slides+2) = 0x3;  

NIOS2_WRITE_IENABLE(0x2);  

NIOS2_WRITE_STATUS(1); /* enable Nios II interrupts*/  

interrupt_handler(); 

return 0; 

 

 

Is there a reason why it is not working (errors in the code above, obsolete functions …)? 

 

 

 

0 Kudos
0 Replies