Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
13 years ago

Hardware Interrupt

Hello everyone,

i have a simple question but i am a beginner and after searching the web for a day an reading nearly all nios documentations i decided to use a Forum. I hope someone can help me.

Can someone tell me how to initialise a hardware interrupt in assembler? I Tried many things with no result and i just want to programm a counter which counts +1 evry time i press key0 and reset when i press key3 with an interrupt bur nothing works.

(Cyclone II)

hope someone can help me and sry for the bad english

2 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    i have a code example.

    it nearly works, It jumps in the IRS but dont know wicht key were pushed dont know why :-/

    
    	.equ STACK_SIZE, 0x400#  stack size
    	.equ PUSHBUTTON_BASE, 0x10000050
    	.data
    TST_PAK1:
    	.word 0x11112222#  test data
    STACK_END:
    	.word 0xFFFFFFFF#  end of stack
    	.skip STACK_SIZE#  stack area filled with 0
    # #############################################
    # 	Exception# #
    # 		# #
    # #############################################	
    	.section .exceptions, "ax"	#  Fixierung der Routine
    	subi 		sp, sp, 4	#  Stacksicherung
    	stw		r13, (sp)
     	subi		sp, sp, 4
     	stw		r4, (sp)
     	subi		sp, sp, 4
     	stw		r3, (sp)
     	
    ISR:
    	movia 		r5, 0x810
    	rdctl 		et, ctl4 	#  Überprüfung auf Interrupt 
    	beq 		et, r0, SKIP	 #  Interrupt ist weg, raus aus der Exception
    	subi 		ea, ea, 4 	#  PC Anpassung
    	andi 		r13, et, 0b1000
    	bne		r13, r0, IRQ1_ISR#  Test ob es IRQ1 aktiv ist
    	
    	andi 		r13, et, 0b0010
    	bne		r13, r0, IRQ3_ISR#  Test ob es IRQ3 aktiv ist 
    	
    	br		SKIP					
    IRQ1_ISR:				#  Erste Taste gedrückt
    	movia		r4, 15
    	stw		r4, (r5)
    	br 		SKIP					
    IRQ3_ISR:				#  Vierte Taste gedrückt
    	
    	stw		r0, (r5)
    	movia 		r3, 15
    										
    SKIP:					#  Springt zum Ende der interrupt-service routine
    	ldw		r3, (sp)
    	addi		sp, sp, 4
    	ldw		r4,(sp)
    	addi		sp, sp, 4
    	ldw		r13, (sp)
    	addi		sp, sp, 4
    	eret 				#  Raus aus der Exception
    # ##############################################
    # 	End Exception	# 
    # 			# 
    # ##############################################
    # ##############################################
    #  TEXT SECTION
    #  Executable code follows
    # ##############################################
    	.global _start
    	.text
    _start:
    	
    	movia	sp, STACK_END	#  load data section's start address
    	addi	sp, sp, STACK_SIZE	       #  stack start position should
    					               #  begin at end of section
    	
    	subi 	sp, sp, 4		
    	stw 	r15, (sp)
    	subi 	sp, sp, 4
    	stw 	r16, (sp)
    	
    	movi		r16, 0x10#  Interrupt starten
    	movi		r15, 1
    	wrctl		ctl3, r16
    	wrctl		ctl0, r15
    				#  Taster Interrupts aktivieren
    	movia	r16, 0x0840
    	movi		r15, 0x9#  Maske für die Interrupts 1001 => 0x9
    	stw		r15, 8(r16)#  Maske in der Adresse von Tastern reinschreiben um Interrupts aktivieren
    	
    	ldw 	r16, (sp)	#  Stack 
    	addi 	sp, sp, 4
    	ldw 	r15, (sp)
    	addi 	sp, sp, 4
    	
    	br 		endloop
    endloop:
    	br endloop	#  that's it
    .end
    
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Typically with keyboard interrupts you read some registers of the keyboard to figure out which key was pressed. If you are not doing that then you would need to add that to your ISR.

    This might be easier if you wrote your code in C.... just saying :)