Line 1... |
Line 1... |
; irq_test.a51 -- First interrupt srvice test.
|
; irq_test.a51 -- First interrupt service test.
|
|
;
|
|
; This progam is only meant to work in the simulation test bench, because it
|
|
; requires the external interrupt inputs to be wired to the P1 output port.
|
|
; They are in the simulation test bench entity but not in the synthesizable
|
|
; demo top entity.
|
;
|
;
|
; This program is meant to run on a light53 MCU with the 16-bit timer. It can be
|
|
; run on simulation or in actual hardware.
|
|
; Its purpose is to demonstrate the working of the interrupt service logic. No
|
; Its purpose is to demonstrate the working of the interrupt service logic. No
|
; actual tests are performed (other than the co-simulation tests), only checks.
|
; actual tests are performed (other than the co-simulation tests), only checks.
|
;
|
;
|
;-------------------------------------------------------------------------------
|
;-------------------------------------------------------------------------------
|
|
|
Line 57... |
Line 60... |
mov IE,#00
|
mov IE,#00
|
|
|
|
|
;---- External interrupt test --------------------------------------
|
;---- External interrupt test --------------------------------------
|
|
|
|
; We'll be asserting the external interrupt request line 0, making
|
|
; sure the interrupt enable flags work properly. No other interrupt
|
|
; will be asserted simultaneously or while in the interrupt service
|
|
; routine.
|
|
|
; Trigger external IRQ with IRQs disabled, it should be ignored.
|
; Trigger external IRQ with IRQs disabled, it should be ignored.
|
mov P1,#01h
|
mov P1,#01h ; Assert external interrupt line 0...
|
nop
|
nop ; ...give the CPU some time to acknowledge
|
|
nop ; the interrupt...
|
nop
|
nop
|
nop
|
mov a,ext_irq_ctr ; ...and then make sure it hasn't.
|
mov a,ext_irq_ctr
|
|
cjne a,#00,fail_unexpected
|
cjne a,#00,fail_unexpected
|
setb EXTINT0.0 ; Clear external IRQ flag
|
setb EXTINT0.0 ; Clear external IRQ flag
|
|
|
; Trigger timer IRQ with external IRQ enabled but global IE disabled
|
; Trigger timer IRQ with external IRQ enabled but global IE disabled
|
mov IE,#01h
|
mov IE,#01h ; Enable external interrupt...
|
mov P1,#01h
|
mov P1,#01h ; ...and assert interrupt line.
|
nop
|
nop ; Wait a little...
|
nop
|
nop
|
nop
|
nop
|
mov a,ext_irq_ctr
|
mov a,ext_irq_ctr ; ...and make sure the interrupt was NOT
|
cjne a,#00,fail_unexpected
|
cjne a,#00,fail_unexpected ; serviced.
|
setb EXTINT0.0 ; Clear timer IRQ flag
|
setb EXTINT0.0 ; Clear timer IRQ flag
|
|
|
; Trigger external IRQ with external and global IRQ enabled
|
; Trigger external IRQ with external and global IRQ enabled
|
mov P1,#00h
|
mov P1,#00h ; Clear the external interrupt line...
|
mov IE,#81h
|
mov IE,#81h ; ...before enabling interrupts globally.
|
mov ext_irq_ctr,#00
|
mov ext_irq_ctr,#00 ; Reset the interrupt counter...
|
mov P1,#01h
|
mov P1,#01h ; ...and assert the external interrupt.
|
|
nop ; Give it some time to be acknowledged...
|
nop
|
nop
|
nop
|
nop
|
nop
|
mov a,ext_irq_ctr ; ...and make sure it has been serviced.
|
mov a,ext_irq_ctr
|
|
cjne a,#01,fail_expected
|
cjne a,#01,fail_expected
|
setb EXTINT0.0 ; Clear timer IRQ flag
|
setb EXTINT0.0 ; Clear timer IRQ flag
|
|
|
|
|
; End of irq test, print message and continue
|
; End of irq test, print message and continue
|
mov DPTR,#text2
|
mov DPTR,#text2
|
call puts
|
call puts
|
|
|
;---- Timer test ---------------------------------------------------
|
;---- Timer test ---------------------------------------------------
|
; Assume the prescaler is set for a 20ms count period
|
; Assume the prescaler is set for a 20us count period.
|
|
|
mov IE,#000h
|
|
|
|
mov TSTAT,#00
|
; All we will do here is make sure the counter changes at the right
|
mov TH,#00
|
; time, i.e. 20us after being started. We will NOT test the full
|
mov TL,#00
|
; functionality of the timer (not in this version of the test).
|
mov TCH,#0c3h ; Compare register = 50000 = 1 second
|
|
mov TCL,#050h
|
mov IE,#000h ; Disable all interrupts...
|
mov TSTAT,#030h ; Start counting
|
; ...and put timer in
|
|
mov TSTAT,#00 ; Stop timer...
|
|
mov TH,#00 ; ...set counter = 0...
|
|
mov TL,#00 ;
|
|
mov TCH,#0c3h ; ...and set Compare register = 50000.
|
|
mov TCL,#050h ; (50000 counts = 1 second)
|
|
mov TSTAT,#030h ; Start counting.
|
|
|
; Ok, now wait for a little less than 20us and make sure TH:TL has not
|
; Ok, now wait for a little less than 20us and make sure TH:TL has not
|
; changed yet.
|
; changed yet.
|
mov r0,#95 ; We need to wait for 950 clock cycles...
|
mov r0,#95 ; We need to wait for 950 clock cycles...
|
loop0: ; ...and this is a 10-clock loop
|
loop0: ; ...and this is a 10-clock loop
|
Line 156... |
Line 167... |
mov DPTR,#text1
|
mov DPTR,#text1
|
call puts
|
call puts
|
mov IE,#00h
|
mov IE,#00h
|
ajmp $
|
ajmp $
|
|
|
|
; End of the test code. Now let's define a few utility routines.
|
|
|
;-- puts: output to UART a zero-terminated string at DPTR ----------------------
|
;-- puts: output to UART a zero-terminated string at DPTR ----------------------
|
puts:
|
puts:
|
mov r0,#00h
|
mov r0,#00h
|
puts_loop:
|
puts_loop:
|
mov a,r0
|
mov a,r0
|
Line 171... |
Line 184... |
sjmp puts_loop
|
sjmp puts_loop
|
puts_done:
|
puts_done:
|
ret
|
ret
|
|
|
;-- irq_timer: interrupt routine for timer -------------------------------------
|
;-- irq_timer: interrupt routine for timer -------------------------------------
|
; Note we don't bother to preserve any registers
|
; Note we don't bother to preserve any registers.
|
irq_ext:
|
irq_ext:
|
mov P1,#00h ; Remove the external interrupt request
|
mov P1,#00h ; Remove the external interrupt request
|
mov EXTINT0,#0ffh ; Clear all external IRQ flags
|
mov EXTINT0,#0ffh ; Clear all external IRQ flags
|
inc ext_irq_ctr ; Increment irq counter
|
inc ext_irq_ctr ; Increment irq counter
|
mov DPTR,#text0 ; Print IRQ message...
|
mov DPTR,#text0 ; Print IRQ message...
|
Line 184... |
Line 197... |
|
|
irq_timer:
|
irq_timer:
|
irq_wrong:
|
irq_wrong:
|
ajmp irq_wrong
|
ajmp irq_wrong
|
|
|
|
; End of the utility routines. Define constant data and we're done.
|
|
|
|
|
text0: db '',13,10,00h,00h
|
text0: db '',13,10,00h,00h
|
text1: db 'Unexpected IRQ',13,10,00h,00h
|
text1: db 'Unexpected IRQ',13,10,00h,00h
|
text2: db 'IRQ test finished, no errors',13,10,0
|
text2: db 'IRQ test finished, no errors',13,10,0
|
text3: db 'Missing IRQ',13,10,0
|
text3: db 'Missing IRQ',13,10,0
|