OpenCores
URL https://opencores.org/ocsvn/light52/light52/trunk

Subversion Repositories light52

[/] [light52/] [trunk/] [test/] [irq_test/] [src/] [irq_test.a51] - Blame information for rev 16

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 16 ja_rd
; irq_test.a51 -- First interrupt service test.
2 3 ja_rd
;
3 16 ja_rd
; This progam is only meant to work in the simulation test bench, because it
4
; requires the external interrupt inputs to be wired to the P1 output port.
5
; They are in the simulation test bench entity but not in the synthesizable
6
; demo top entity.
7
;
8 3 ja_rd
; Its purpose is to demonstrate the working of the interrupt service logic. No
9
; actual tests are performed (other than the co-simulation tests), only checks.
10
;
11
;-------------------------------------------------------------------------------
12
 
13
        ; Include the definitions for the light52 derivative
14
        $nomod51
15
        $include (light52.mcu)
16
 
17
ext_irq_ctr     set     060h        ; Incremented by external irq routine
18
 
19
 
20
        ;-- Macros -------------------------------------------------------------
21
 
22
        ; putc: send character in A to console (UART)
23
putc    macro   character
24
        local   putc_loop
25
        mov     SBUF,character
26
putc_loop:
27
        ;mov     a,SCON
28
        ;anl     a,#10h
29
        ;jz      putc_loop
30
        endm
31
 
32
        ; put_crlf: send CR+LF to console
33
put_crlf macro
34
        putc    #13
35
        putc    #10
36
        endm
37
 
38
 
39
        ;-- Reset & interrupt vectors ------------------------------------------
40
 
41
        org     00h
42
        ljmp    start               ;
43
        org     03h
44
        ljmp    irq_ext
45
        org     0bh
46
        ljmp    irq_timer
47
        org     13h
48
        ljmp    irq_wrong
49
        org     1bh
50
        ljmp    irq_wrong
51
        org     23h
52
        ljmp    irq_wrong
53
 
54
 
55
        ;-- Main test program --------------------------------------------------
56
        org     30h
57
start:
58
 
59
        ; Disable all interrupts.
60
        mov     IE,#00
61
 
62
 
63
        ;---- External interrupt test --------------------------------------
64
 
65 16 ja_rd
        ; We'll be asserting the external interrupt request line 0, making
66
        ; sure the interrupt enable flags work properly. No other interrupt
67
        ; will be asserted simultaneously or while in the interrupt service
68
        ; routine.
69
 
70 3 ja_rd
        ; Trigger external IRQ with IRQs disabled, it should be ignored.
71 16 ja_rd
        mov     P1,#01h             ; Assert external interrupt line 0...
72
        nop                         ; ...give the CPU some time to acknowledge
73
        nop                         ; the interrupt...
74 3 ja_rd
        nop
75 16 ja_rd
        mov     a,ext_irq_ctr       ; ...and then make sure it hasn't.
76 3 ja_rd
        cjne    a,#00,fail_unexpected
77
        setb    EXTINT0.0           ; Clear external IRQ flag
78
 
79
        ; Trigger timer IRQ with external IRQ enabled but global IE disabled
80 16 ja_rd
        mov     IE,#01h             ; Enable external interrupt...
81
        mov     P1,#01h             ; ...and assert interrupt line.
82
        nop                         ; Wait a little...
83 3 ja_rd
        nop
84
        nop
85 16 ja_rd
        mov     a,ext_irq_ctr       ; ...and make sure the interrupt was NOT
86
        cjne    a,#00,fail_unexpected   ; serviced.
87
        setb    EXTINT0.0           ; Clear timer IRQ flag
88 3 ja_rd
 
89
        ; Trigger external IRQ with external and global IRQ enabled
90 16 ja_rd
        mov     P1,#00h             ; Clear the external interrupt line...
91
        mov     IE,#81h             ; ...before enabling interrupts globally.
92
        mov     ext_irq_ctr,#00     ; Reset the interrupt counter...
93
        mov     P1,#01h             ; ...and assert the external interrupt.
94
        nop                         ; Give it some time to be acknowledged...
95 3 ja_rd
        nop
96
        nop
97 16 ja_rd
        mov     a,ext_irq_ctr       ; ...and make sure it has been serviced.
98 3 ja_rd
        cjne    a,#01,fail_expected
99
        setb    EXTINT0.0          ; Clear timer IRQ flag
100
 
101
        ; End of irq test, print message and continue
102
        mov     DPTR,#text2
103
        call    puts
104
 
105
        ;---- Timer test ---------------------------------------------------
106 16 ja_rd
        ; Assume the prescaler is set for a 20us count period.
107 3 ja_rd
 
108 16 ja_rd
        ; All we will do here is make sure the counter changes at the right
109
        ; time, i.e. 20us after being started. We will NOT test the full
110
        ; functionality of the timer (not in this version of the test).
111 3 ja_rd
 
112 16 ja_rd
        mov     IE,#000h            ; Disable all interrupts...
113
                                    ; ...and put timer in
114
        mov     TSTAT,#00           ; Stop timer...
115
        mov     TH,#00              ; ...set counter = 0...
116
        mov     TL,#00              ;
117
        mov     TCH,#0c3h           ; ...and set Compare register = 50000.
118
        mov     TCL,#050h           ; (50000 counts = 1 second)
119
        mov     TSTAT,#030h         ; Start counting.
120 3 ja_rd
 
121
        ; Ok, now wait for a little less than 20us and make sure TH:TL has not
122
        ; changed yet.
123
        mov     r0,#95              ; We need to wait for 950 clock cycles...
124
loop0:                              ; ...and this is a 10-clock loop
125
        nop
126
        djnz    r0,loop0
127
        mov     a,TH
128
        cjne    a,#000h,fail_timer_error
129
        mov     a,TL
130
        cjne    a,#000h,fail_timer_error
131
 
132
        ; Now wait for another 100 clock cycles and make sure TH:TL has already
133
        ; changed.
134
        mov     r0,#10              ; We need to wait for 100 clock cycles...
135
loop1:                              ; ...and this is a 10-clock loop
136
        nop
137
        djnz    r0,loop1
138
        mov     a,TH
139
        cjne    a,#000h,fail_timer_error
140
        mov     a,TL
141
        cjne    a,#001h,fail_timer_error
142
 
143
        ; End of timer test, print message and continue
144
        mov     DPTR,#text5
145
        call    puts
146
 
147
        ;-- End of test program, enter single-instruction endless loop
148
quit:   ajmp    $
149
 
150
 
151
fail_timer_error:
152
        mov     DPTR,#text4
153
        call    puts
154
        mov     IE,#00h
155
        ajmp    $
156
 
157
 
158
        ; Did not get expected IRQ: print failure message and block.
159
fail_expected:
160
        mov     DPTR,#text3
161
        call    puts
162
        mov     IE,#00h
163
        ajmp    $
164
 
165
        ; Got unexpected IRQ: print failure message and block.
166
fail_unexpected:
167
        mov     DPTR,#text1
168
        call    puts
169
        mov     IE,#00h
170
        ajmp    $
171
 
172 16 ja_rd
        ; End of the test code. Now let's define a few utility routines.
173
 
174 3 ja_rd
;-- puts: output to UART a zero-terminated string at DPTR ----------------------
175
puts:
176
        mov     r0,#00h
177
puts_loop:
178
        mov     a,r0
179
        inc     r0
180
        movc    a,@a+DPTR
181
        jz      puts_done
182
 
183
        putc    a
184
        sjmp    puts_loop
185
puts_done:
186
        ret
187
 
188
;-- irq_timer: interrupt routine for timer -------------------------------------
189 16 ja_rd
; Note we don't bother to preserve any registers.
190 3 ja_rd
irq_ext:
191
        mov     P1,#00h             ; Remove the external interrupt request
192
        mov     EXTINT0,#0ffh       ; Clear all external IRQ flags
193
        inc     ext_irq_ctr         ; Increment irq counter
194
        mov     DPTR,#text0         ; Print IRQ message...
195
        call    puts
196
        reti                        ; ...and quit
197
 
198
irq_timer:
199
irq_wrong:
200
        ajmp    irq_wrong
201
 
202 16 ja_rd
        ; End of the utility routines. Define constant data and we're done.
203 3 ja_rd
 
204
text0:  db      '',13,10,00h,00h
205
text1:  db      'Unexpected IRQ',13,10,00h,00h
206
text2:  db      'IRQ test finished, no errors',13,10,0
207
text3:  db      'Missing IRQ',13,10,0
208
text4:  db      'Timer error',13,10,0
209
text5:  db      'Timer test finished, no errors',13,10,0
210
 
211
        end

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.