Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12600 Discussions

Interrupt on my radar application - what have I been programming ?

Altera_Forum
Honored Contributor II
1,493 Views

Dear Forum users, 

 

I implemented with verilog a simple 32 bit wide COUNTER. Then I read the counter out with 

Nios and I implemented on my radar application two switches - one switch for starting the  

radar pulse and one switch for displaying the result on the RS232. Now the code it functions 

but I do not know what I have been implementing with version 9.1.  

 

The code will look as follows: 

 

//PAVLE DUKANOVIC 

//www.dukelanovic.com 

//Neckarrems,19.10.2014 

//  

//RS232 COMMUNICATIONS 

// 

 

# include<stdio.h># include<string.h># include "altera_avalon_pio_regs.h" # include "alt_types.h"# include "unistd.h" # include "system.h"# include "sys/alt_irq.h" 

 

 

 

# define seg *(volatile unsigned char *) SEG_BASE # define bit *(volatile unsigned char *) BIT_BASE # define RESET *(volatile unsigned char *) RESET_BASE# define TRIG *(volatile unsigned char *) TRIG_BASE# define COUNTER *(volatile alt_u32 *) COUNTER_BASE# define START *(volatile alt_u32 *) START_BASE 

const alt_u8 duan[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; 

// 0 1 2 3 4 5 6 7 8 9 

alt_u8 num[8] = {0,0,0,0,0,0,0,0}; 

alt_u8 number[8]; 

alt_u32 n = 0; 

 

 

alt_u8 key_flag; 

alt_u8 key_flag1; 

 

 

volatile int edge_capture; 

 

 

void key_ISR(void* context, alt_u32 id) 

{  

IOWR_ALTERA_AVALON_PIO_EDGE_CAP(START_BASE,0); 

IORD_ALTERA_AVALON_PIO_EDGE_CAP(START_BASE); 

key_flag = 1;  

 

 

void key3_ISR(void* context, alt_u32 id) 

{  

IOWR_ALTERA_AVALON_PIO_EDGE_CAP(K3_BASE,0); 

IORD_ALTERA_AVALON_PIO_EDGE_CAP(K3_BASE); 

key_flag1 = 1; 

 

 

 

 

 

 

 

 

 

void key_Init() 

IOWR_ALTERA_AVALON_PIO_IRQ_MASK(START_BASE,0xF); 

IOWR_ALTERA_AVALON_PIO_EDGE_CAP(START_BASE,0x0); 

alt_irq_register(START_IRQ,NULL,key_ISR); //START_IRQ 3 

 

 

void key3_Init() 

IOWR_ALTERA_AVALON_PIO_IRQ_MASK(K3_BASE,0xF); 

IOWR_ALTERA_AVALON_PIO_EDGE_CAP(K3_BASE,0x0); 

alt_irq_register(K3_IRQ,NULL,key3_ISR); //START_IRQ 3 

 

 

// This function will display 8 Numbers  

void display(alt_u32 i) 

 

alt_u8 j; 

num[0] = ((((((i % 10000000)%1000000)%100000)%10000)%1000)%100)%10; 

num[1] = ((((((i % 10000000)%1000000)%100000)%10000)%1000)%100)/10;  

num[2] = (((((i % 10000000)%1000000)%100000)%10000)%1000)/100;  

num[3] = ((((i % 10000000)%1000000)%100000)%10000)/1000;  

num[4] = (((i % 10000000)%1000000)%100000)/10000;  

num[5] = ((i % 10000000)%1000000)/100000;  

num[6] = (i % 10000000)/1000000;  

num[7] = i / 10000000;  

 

for(j=0; j<8; j++) 

bit = ~(0x01 << j);  

seg = duan[num[j]]; // here the display is switched on  

usleep(100);  

 

number[7] = ((((((i % 10000000)%1000000)%100000)%10000)%1000)%100)%10+0x30; 

number[6] = ((((((i % 10000000)%1000000)%100000)%10000)%1000)%100)/10+0x30;  

number[5] = (((((i % 10000000)%1000000)%100000)%10000)%1000)/100+0x30;  

number[4] = ((((i % 10000000)%1000000)%100000)%10000)/1000+0x30;  

number[3] = (((i % 10000000)%1000000)%100000)/10000+0x30;  

number[2] = ((i % 10000000)%1000000)/100000+0x30;  

number[1] = (i % 10000000)/1000000+0x30;  

number[0] = i / 10000000+0x30;  

 

 

 

int main () 

 

char* msg = "M01 "; 

FILE* fp; 

 

 

 

key_Init(); 

key3_Init(); 

printf("RS232 DEMO : \n"); 

fp = fopen (UART_NAME, "r+"); // here we initialize the RS232 port 

RESET = 1; 

 

TRIG =1; 

while(1){ 

 

n = COUNTER; 

display(n); 

usleep(100); 

 

if(key_flag){ 

 

TRIG = 0; 

usleep(10); 

fwrite (msg, strlen (msg), 1, fp); // here we write on the RS232 

usleep(40000); 

 

key_flag = 0; 

TRIG = 1; 

 

 

if(key_flag1){ 

fwrite (number, strlen (number), 1, fp); // here we write on the RS232 

key_flag1 = 0; 

 

 

return 0; 

 

 

 

Can you tell me where I can find a good reference about programming and handling interrupts? 

 

What have I been doing with the initialisation of my interrupt? 

 

void key_Init() 

IOWR_ALTERA_AVALON_PIO_IRQ_MASK(START_BASE,0xF); 

IOWR_ALTERA_AVALON_PIO_EDGE_CAP(START_BASE,0x0); 

alt_irq_register(START_IRQ,NULL,key_ISR); //START_IRQ 3 

 

What do those commands mean ? 

 

Please help me.
0 Kudos
2 Replies
Altera_Forum
Honored Contributor II
476 Views

This document has a C code explaining it. The content is present on pg 8-15. 

 

https://www.altera.com/content/dam/altera-www/global/en_us/pdfs/literature/hb/nios2/n2sw_nii5v2.pdf 

 

I hope you enabled interrupts while creating your system in qsys and did give the right priority to the different components.
0 Kudos
Reply