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 15

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

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

powered by: WebSVN 2.1.0

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