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

Subversion Repositories thor

[/] [thor/] [trunk/] [software/] [boot_tb/] [Serial.asm] - Blame information for rev 55

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

Line No. Rev Author Line
1 28 robfinch
UART            EQU     0xC0A00
2
UART_TX         EQU     0xC0A00
3
UART_RX         EQU     0xC0A00
4
UART_LS         EQU     0xC0A01
5
UART_MS         EQU     0xC0A02
6
UART_IS         EQU     0xC0A03
7
UART_IE         EQU     0xC0A04
8
UART_FF         EQU     0xC0A05
9
UART_MC         EQU     0xC0A06
10
UART_CTRL       EQU     0xC0A07
11
UART_CM0        EQU     0xC0A08
12
UART_CM1        EQU     0xC0A09
13
UART_CM2        EQU     0xC0A0A
14
UART_CM3        EQU     0xC0A0B
15
UART_SPR        EQU     0xC0A0F
16
 
17
;------------------------------------------------------------------------------
18
;------------------------------------------------------------------------------
19
 
20
;==============================================================================
21
; Serial port
22
;==============================================================================
23
        code
24
;------------------------------------------------------------------------------
25
; Initialize UART
26
;------------------------------------------------------------------------------
27
 
28
                align   8
29
ser_jmp:
30
                jmp             SerialIRQ[c0]
31
 
32
SerialInit:
33
                addui   sp,sp,#-8
34
                sws             c1,[sp]
35
                ldis    hs,#$FFD00000
36
                ldis    hs.lmt,#$100000
37
;               ldi             r1,#$0218DEF4   ; constant for clock multiplier with 18.75MHz clock for 9600 baud
38
;               ldi             r1,#$03254E6E   ; constant for clock multiplier with 12.5MHz clock for 9600 baud
39
                ldi             r1,#$00C9539B   ; constant for clock multiplier with 50.0MHz clock for 9600 baud
40
                shrui   r1,r1,#8          ; drop the LSB (not used)
41
                sb      r1,hs:UART_CM1
42
                shrui   r1,r1,#8
43
                sb      r1,hs:UART_CM2
44
                shrui   r1,r1,#8
45
                sb      r1,hs:UART_CM3
46
                sb      r0,hs:UART_CTRL     ; no hardware flow control
47
                sc              r0,Uart_rxhead          ; reset buffer indexes
48
                sc              r0,Uart_rxtail
49
                ldi             r1,#0x1f0
50
                sc              r1,Uart_foff            ; set threshold for XOFF
51
                ldi             r1,#0x010
52
                sc              r1,Uart_fon                     ; set threshold for XON
53
                ldi             r1,#1
54
                sb              r1,hs:UART_IE           ; enable receive interrupt only
55
                sb              r0,Uart_rxrts           ; no RTS/CTS signals available
56
                sb              r0,Uart_txrts           ; no RTS/CTS signals available
57
                sb              r0,Uart_txdtr           ; no DTR signals available
58
                sb              r0,Uart_rxdtr           ; no DTR signals available
59
                ldi             r1,#1
60
                sb              r1,Uart_txxon           ; for now
61
                ldi             r1,#1
62
;               sb              r1,SERIAL_SEMA
63
                ; setup IRQ vector
64
                lla             r1,cs:ser_jmp
65
                ldi             r2,#199
66
                bsr             set_vector
67
                lws             c1,[sp]
68
                addui   sp,sp,#8
69
                rts
70
 
71
;---------------------------------------------------------------------------------
72
; Get character directly from serial port. Blocks until a character is available.
73
;---------------------------------------------------------------------------------
74
;
75
SerialGetCharDirect:
76
sgc1:
77
                lvb             r1,hs:UART_LS   ; uart status
78
                biti    p0,r1,#1                ; is there a char available ?
79
p0.eq   br              sgc1
80
                lvb             r1,hs:UART_RX
81
                rts
82
 
83
;------------------------------------------------
84
; Check for a character at the serial port
85
; returns r1 = 1 if char available, 0 otherwise
86
;------------------------------------------------
87
;
88
SerialCheckForCharDirect:
89
                lvb             r1,hs:UART_LS                   ; uart status
90
                andi    r1,r1,#rxfull                   ; is there a char available ?
91
                rts
92
 
93
;-----------------------------------------
94
; Put character to serial port
95
; r1 = char to put
96
;-----------------------------------------
97
;
98
SerialPutChar:
99
                addui   sp,sp,#-48
100
                sw              r2,[sp]
101
                sw              r3,8[sp]
102
                sw              r4,16[sp]
103
                sw              r5,24[sp]
104
                sws             p0,32[sp]
105
                sws             lc,40[sp]
106
                lvb             r2,hs:UART_MC
107
                ori             r2,r2,#3                ; assert DTR / RTS
108
                sb              r2,hs:UART_MC
109
                lb              r2,Uart_txrts
110
                tst             p0,r2
111
p0.eq   br              spcb1
112
                lw              r4,Milliseconds
113
                ldis    lc,#999                 ; delay count (1 s)
114
spcb3:
115
                lvb             r2,hs:UART_MS
116
                biti    p0,r2,#$10              ; is CTS asserted ?
117
p0.ne   br              spcb1
118
                lw              r5,Milliseconds
119
                cmp             p0,r4,r5
120
p0.eq   br              spcb3
121
                mov             r4,r5
122
                loop    spcb3
123
                br              spcabort
124
spcb1:
125
                lb              r2,Uart_txdtr
126
                tst             p0,r2
127
p0.eq   br              spcb2
128
                lw              r4,Milliseconds
129
                ldis    lc,#999         ; delay count
130
spcb4:
131
                lvb             r2,hs:UART_MS
132
                biti    p0,r2,#$20              ; is DSR asserted ?
133
p0.ne   br              spcb2
134
                lw              r5,Milliseconds
135
                cmp             p0,r4,r5
136
p0.eq   br              spcb4
137
                mov             r4,r5
138
                loop    spcb4
139
                br              spcabort
140
spcb2:
141
                lb              r2,Uart_txxon
142
                tst             p0,r2
143
p0.eq   br              spcb5
144
spcb6:
145
                lb              r2,Uart_txxonoff
146
                tst             p0,r2
147
p0.eq   br              spcb5
148
                lvb             r4,hs:UART_MS
149
                biti    p0,r4,#0x80             ; DCD ?
150
p0.ne   br              spcb6
151
spcb5:
152
                lw              r4,Milliseconds
153
                ldis    lc,#999         ; wait up to 1s
154
spcb8:
155
                lvb             r2,hs:UART_LS
156
                biti    p0,r2,#0x20                     ; tx not full ?
157
p0.ne   br              spcb7
158
                lw              r5,Milliseconds
159
                cmp             p0,r4,r5
160
p0.eq   br              spcb8
161
                mov             r4,r5
162
                loop    spcb8
163
                br              spcabort
164
spcb7:
165
                sb              r1,hs:UART_TX
166
spcabort:
167
                lw              r2,[sp]
168
                lw              r3,8[sp]
169
                lw              r4,16[sp]
170
                lw              r5,24[sp]
171
                lws             p0,32[sp]
172
                lws             lc,40[sp]
173
                addui   sp,sp,#40
174
                rts
175
 
176
;-------------------------------------------------
177
; Compute number of characters in recieve buffer.
178
; r4 = number of chars
179
;-------------------------------------------------
180
CharsInRxBuf:
181
                lcu             r4,Uart_rxhead
182
                lcu             r3,Uart_rxtail
183
                subu    r4,r4,r3
184
                tst             p0,r4
185
p0.gt   br              cirxb1
186
                ldi             r4,#0x200
187
                addu    r4,r4,r3
188
                lcu             r3,Uart_rxhead
189
                subu    r4,r4,r3
190
cirxb1:
191
                rts
192
 
193
;----------------------------------------------
194
; Get character from rx fifo
195
; If the fifo is empty enough then send an XON
196
;----------------------------------------------
197
;
198
SerialGetChar:
199
                addui   sp,sp,#-40
200
                sw              r2,[sp]
201
                sw              r3,8[sp]
202
                sw              r4,16[sp]
203
                sw              r5,24[sp]
204
                sws             c1,32[sp]
205
                lcu             r3,Uart_rxhead
206
                lcu             r2,Uart_rxtail
207
                cmp             p0,r2,r3
208
p0.eq   br              sgcfifo1                ; is there a char available ?
209
                lbu             r1,Uart_rxfifo[r2]      ; get the char from the fifo into r1
210
                addui   r2,r2,#1                ; increment the fifo pointer
211
                andi    r2,r2,#$1ff
212
                sc              r2,Uart_rxtail
213
                lb              r2,Uart_rxflow          ; using flow control ?
214
                tst             p0,r2
215
p0.eq   br              sgcfifo2
216
                lcu             r3,Uart_fon             ; enough space in Rx buffer ?
217
                bsr             CharsInRxBuf
218
                cmp             p0,r4,r3
219
p0.gt   br              sgcfifo2
220
                sb              r0,Uart_rxflow          ; flow off
221
                lb              r4,Uart_rxrts
222
                tst             p0,r4
223
p0.eq   br              sgcfifo3
224
                lb              r4,hs:UART_MC           ; set rts bit in MC
225
                ori             r4,r4,#2
226
                sb              r4,hs:UART_MC
227
sgcfifo3:
228
                lb              r4,Uart_rxdtr
229
                tst             p0,r4
230
p0.eq   br              sgcfifo4
231
                lb              r4,hs:UART_MC           ; set DTR
232
                ori             r4,r4,#1
233
                sb              r4,hs:UART_MC
234
sgcfifo4:
235
                lb              r4,Uart_rxxon
236
                tst             p0,r4
237
p0.eq   br              sgcfifo5
238
                ldi             r4,#XON
239
                sb              r4,hs:UART
240
sgcfifo5:
241
sgcfifo2:                                       ; return with char in r1
242
                lw              r2,[sp]
243
                lw              r3,8[sp]
244
                lw              r4,16[sp]
245
                lw              r5,24[sp]
246
                lws             c1,32[sp]
247
                addui   sp,sp,#40
248
                rts
249
sgcfifo1:
250
                ldi             r1,#-1                          ; no char available
251
                lw              r2,[sp]
252
                lw              r3,8[sp]
253
                lw              r4,16[sp]
254
                lw              r5,24[sp]
255
                lws             c1,32[sp]
256
                addui   sp,sp,#40
257
                rts
258
 
259
 
260
;-----------------------------------------
261
; Serial port IRQ
262
;-----------------------------------------
263
;
264
SerialIRQ:
265
                sync
266
                addui   r31,r31,#-64
267
                sw              r1,[r31]
268
                sw              r2,8[r31]
269
                sw              r4,16[r31]
270
                sws             p0,24[r31]
271
                sw              r3,32[r31]
272
                sws             c1,40[r31]
273
                sws             hs,48[r31]
274
                sws             hs.lmt,56[r31]
275
                ldis    hs,#$FFD00000
276
                ldis    hs.lmt,#$100000
277
 
278
                lb      r1,hs:UART_IS  ; get interrupt status
279
                tst             p0,r1
280
p0.gt   br              sirq1                   ; no interrupt
281
                andi    r1,r1,#0x7f     ; switch on interrupt type
282
                biti    p0,r1,#4
283
p0.ne   br              srxirq
284
                biti    p0,r1,#$0C
285
p0.ne   br              stxirq
286
                biti    p0,r1,#$10
287
p0.ne   br              smsirq
288
                ; unknown IRQ type
289
sirq1:
290
                lw              r1,[r31]
291
                lw              r2,8[r31]
292
                lw              r4,16[r31]
293
                lws             p0,24[r31]
294
                lw              r3,32[r31]
295
                lws             c1,40[r31]
296
                lws             hs,48[r31]
297
                lws             hs.lmt,56[r31]
298
                addui   r31,r31,#64
299
                sync
300
                rti
301
 
302
; Get the modem status and record it
303
smsirq:
304
                lbu     r1,hs:UART_MS
305
                sb      r1,Uart_ms
306
                br              sirq1
307
 
308
stxirq:
309
                br              sirq1
310
 
311
; Get a character from the uart and store it in the rx fifo
312
srxirq:
313
srxirq1:
314
                lbu     r1,hs:UART_RX      ; get the char (clears interrupt)
315
                lbu     r3,Uart_txxon
316
                tst             p0,r3
317
p0.eq   br              srxirq3
318
                cmpi    p0,r1,#XOFF
319
p0.ne   br              srxirq2
320
                ldi     r1,#1
321
                sb              r1,Uart_txxonoff
322
                br              srxirq5
323
srxirq2:
324
                cmpi    p0,r1,#XON
325
p0.ne   br              srxirq3
326
                sb              r0,Uart_txxonoff
327
                br              srxirq5
328
srxirq3:
329
                sb              r0,Uart_txxonoff
330
                lcu             r4,Uart_rxhead
331
                sb              r1,Uart_rxfifo[r4]  ; store in buffer
332
                addui   r4,r4,#1
333
                andi    r4,r4,#$1ff
334
                sc              r4,Uart_rxhead
335
srxirq5:
336
                lb      r1,hs:UART_LS   ; check for another ready character
337
                biti    p0,r1,#1        ; check rxfull bit
338
p0.ne   br              srxirq1                 ; loop back for another character
339
                lb              r1,Uart_rxflow          ; are we using flow controls?
340
                tst             p0,r1
341
p0.ne   br              srxirq8
342
                bsr             CharsInRxBuf
343
                lb              r1,Uart_foff
344
                cmp             p0,r4,r1
345
p0.lt   br              srxirq8
346
                ldi             r1,#1
347
                sb              r1,Uart_rxflow
348
                lb              r1,Uart_rxrts
349
                tst             p0,r1
350
p0.eq   br              srxirq6
351
                lb              r1,hs:UART_MC
352
                andi    r1,r1,#$FD              ; turn off RTS
353
                sb              r1,hs:UART_MC
354
srxirq6:
355
                lb              r1,Uart_rxdtr
356
                tst             p0,r1
357
 
358
 p0.eq  br              srxirq7
359
                lb              r1,hs:UART_MC
360
                andi    r1,r1,#$FE              ; turn off DTR
361
                sb              r1,hs:UART_MC
362
srxirq7:
363
                lb              r1,Uart_rxxon
364
                tst             p0,r1
365
p0.eq   br              srxirq8
366
                ldi             r1,#XOFF
367
                sb              r1,hs:UART_TX
368
srxirq8:
369
                br              sirq1
370
 

powered by: WebSVN 2.1.0

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