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++
12748 Discussions

Implementation of ISR in Nios 3.20 SDK environment

Altera_Forum
Honored Contributor II
930 Views

Hello 

Could somebody tell me that the following testisr.c program is correct. The ISR “irq_handler” is installed by “nr_installuserisr” procedure. The parametr “context” is set to pointer to &stab[0] record, which contains four semaphore variables. The “->sema” variable, initially set to 0, is tested in main() subroutine until it is set to 1 in “irq_handler()” after hardware interrupt occurred. Second test is performed on “->semb” variable, which is never touched in ISR. I’m not sure that is correct way to handle critical region in Nios 3.20 environment independently on compiler options. Could you tell me which registers are store on stack when the ISR is invoked. Do I have to be aware of any registers when I use record variables set up by pointer (->) expressions to send data between ISR and main program? 

 

 

There is the Nios testisr.c program. I use Nios 3.20 SDK under Windows 2000. Compilation is performed by invoking nios-build –O2 testisr.c. 

 

Regards 

Chris 

 

typedef struct{ 

int sema; 

int semb ; 

char semc; 

short semd; 

}s_st; 

s_st stab[2]; 

 

int main(){ 

s_st *pst; 

 

pst = &stab[0]; 

pst->sema =0; 

pst->semb =0; 

pst->semc =0; 

pst->semd =0; 

 

nr_installuserisr(IRQ_num,irq_handler,(int)&stab[0]); 

 

//we are waiting for irq... 

laba: 

if(pst->sema == 0) 

goto laba; 

if(pst->sema != 1) 

printf("Something wrong with Nios ISR?"); 

//...at isr semaphore was changed 

// and next we are in infinite loop 

 

labb: 

if(pst->semb == 0) 

goto labb; 

printf("Something wrong with Nios ISR?\n"); 

return 0; 

 

//isr 

void irq_handler(int context){ 

s_st *pst; 

pst = (s_st *)context; 

pst->sema = 1; 

}
0 Kudos
0 Replies
Reply