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

Subversion Repositories rf6809

[/] [rf6809/] [trunk/] [software/] [boot/] [serial.asm] - Blame information for rev 14

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

Line No. Rev Author Line
1 8 robfinch
; ============================================================================
2
;        __
3
;   \\__/ o\    (C) 2022  Robert Finch, Waterloo
4
;    \  __ /    All rights reserved.
5
;     \/_//     robfinch@opencores.org
6
;       ||
7
;
8
;
9
; Serial port routines for a WDC6551 compatible circuit.
10
;
11
; This source file is free software: you can redistribute it and/or modify
12
; it under the terms of the GNU Lesser General Public License as published
13
; by the Free Software Foundation, either version 3 of the License, or
14
; (at your option) any later version.
15
;
16
; This source file is distributed in the hope that it will be useful,
17
; but WITHOUT ANY WARRANTY; without even the implied warranty of
18
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
; GNU General Public License for more details.
20
;
21
; You should have received a copy of the GNU General Public License
22
; along with this program.  If not, see .
23
;
24
; ============================================================================
25
;
26
;------------------------------------------------------------------------------
27
; Initialize serial port.
28
;
29
; Clear buffer indexes. Two bytes are used for the buffer index even though
30
; only a single byte is needed. This is for convenience in calculating the
31
; number of characters in the buffer, done later. The upper byte remains at
32
; zero.
33
; The port is initialized for 9600 baud, 1 stop bit and 8 bits data sent.
34
; The internal baud rate generator is used.
35
;
36
; Parameters:
37
;               none
38
; Modifies:
39
;               d
40
; Returns:
41
;               none
42
;------------------------------------------------------------------------------
43
 
44
InitSerial:
45
SerialInit:
46
        clra
47
        clrb
48
        std             SerHeadRcv-1
49
        std             SerTailRcv-1
50
        std             SerHeadXmit-1
51
        std             SerTailXmit-1
52
        clr             SerRcvXon
53
        clr             SerRcvXoff
54
        lda             COREID
55
sini1:
56
        cmpa    IOFocusID
57
        bne             sini1
58
        ldb             #$09                                            ; dtr,rts active, rxint enabled, no parity
59
        stb             ACIA+ACIA_CMD
60 14 robfinch
        ldb             #$1F                                            ; baud 9600, 1 stop bit, 8 bit, internal baud gen
61 8 robfinch
        stb             ACIA+ACIA_CTRL
62
        ldb             #$0A6                                           ; diable fifos, reset fifos
63
        stb             ACIA+ACIA_CTRL2
64
        rts
65
 
66
;------------------------------------------------------------------------------
67
; SerialGetChar
68
;
69
; Check the serial port buffer to see if there's a char available. If there's
70
; a char available then return it. If the buffer is almost empty then send an
71
; XON.
72
;
73
; Stack Space:
74
;               2 words
75
; Parameters:
76
;               none
77
; Modifies:
78
;               none
79
; Returns:
80
;               d = character or -1
81
;------------------------------------------------------------------------------
82
 
83
SerialGetChar:
84
                pshs    x,y
85
                ldy             #0
86
                sei                                                                             ; disable interrupts
87
                bsr             SerialRcvCount                  ; check number of chars in receive buffer
88
                cmpb    #8                                                      ; less than 8?
89
                bhi             sgc2
90
                ldb             SerRcvXon                               ; skip sending XON if already sent
91
                bne       sgc2            ; XON already sent?
92
                ldb             #XON                                            ; if <8 send an XON
93
                clr             SerRcvXoff                      ; clear XOFF status
94
                stb             SerRcvXon                               ; flag so we don't send it multiple times
95
                bsr             SerialPutChar
96
sgc2:
97
                ldb             SerHeadRcv                      ; check if anything is in buffer
98
                cmpb    SerTailRcv
99
                beq             sgcNoChars                      ; no?
100
                ldx             #SerRcvBuf
101
                clra
102
                ldb             b,x                                                     ; get byte from buffer
103
                inc             SerHeadRcv                      ; 4k wrap around
104
                bra             sgcXit
105
sgcNoChars:
106
                ldd             #-1
107
sgcXit:
108
                cli
109
                puls    x,y,pc
110
 
111
;------------------------------------------------------------------------------
112
; SerialPeekChar
113
;
114
; Check the serial port buffer to see if there's a char available. If there's
115
; a char available then return it. But don't update the buffer indexes. No need
116
; to send an XON here.
117
;
118
; Stack Space:
119
;               0 words
120
; Parameters:
121
;               none
122
; Modifies:
123
;               none
124
; Returns:
125
;               d = character or -1
126
;------------------------------------------------------------------------------
127
 
128
SerialPeekChar:
129
        pshs    x,ccr
130
        sei
131
        ldb             SerHeadRcv                              ; check if anything is in buffer
132
        cmpb    SerTailRcv
133
        beq             spcNoChars                              ; no?
134
        ldx             #SerRcvBuf
135
        clra
136
        ldb             b,x                                                             ; get byte from buffer
137
        bra             spcXit
138
spcNoChars:
139
        ldd             #-1
140
spcXit:
141
        puls    x,ccr,pc
142
 
143
;------------------------------------------------------------------------------
144
; SerialPeekChar
145
;               Get a character directly from the I/O port. This bypasses the input
146
; buffer.
147
;
148
; Stack Space:
149
;               0 words
150
; Parameters:
151
;               none
152
; Modifies:
153
;               d
154
; Returns:
155
;               d = character or -1
156
;------------------------------------------------------------------------------
157
 
158
SerialPeekCharDirect:
159
        lda             COREID                                                  ; Ensure we have the IO Focus
160
        cmpa    IOFocusID
161
        bne             spcd0001
162
        ; Disallow interrupts between status read and rx read.
163
        sei
164
        ldb             ACIA+ACIA_STAT
165
        bitb    #8                                                                      ; look for Rx not empty
166
        beq             spcd0001
167
        clra
168
        ldb             ACIA+ACIA_RX
169
        cli
170
        rts
171
spcd0001:
172
        ldd             #-1
173
        cli
174
        rts
175
 
176
;------------------------------------------------------------------------------
177
; SerialPutChar
178
;    Put a character to the serial transmitter. This routine blocks until the
179
; transmitter is empty.
180
;
181
; Stack Space
182
;               0 words
183
; Parameters:
184
;               b = character to put
185
; Modifies:
186
;               none
187
;------------------------------------------------------------------------------
188
 
189
SerialPutChar:
190
        pshs    a,ccr
191
spc0001:
192
        lda             COREID                                  ; Ensure we have the IO Focus
193
        cmpa    IOFocusID
194
        bne             spc0001
195
        cli                                                                             ; provide a window for an interrupt to occur
196
        sei
197
        ; Between the status read and the transmit do not allow an
198
        ; intervening interrupt.
199
        lda             ACIA+ACIA_STAT  ; wait until the uart indicates tx empty
200
        bita    #16                                                     ; bit #4 of the status reg
201
        beq             spc0001                     ; branch if transmitter is not empty
202
        stb             ACIA+ACIA_TX            ; send the byte
203
        puls    a,ccr,pc
204
 
205
;------------------------------------------------------------------------------
206
; Calculate number of character in input buffer
207
;
208
; Parameters:
209
;               y = 0 if current core, otherwise reference to core memory area $Cyxxxx
210
; Returns:
211
;               d = number of bytes in buffer.
212
;------------------------------------------------------------------------------
213
 
214
SerialRcvCount:
215
        clra
216
        ldb             SerTailRcv,y
217
        subb    SerHeadRcv,y
218
        bge             srcXit
219
        ldd             #$1000
220
        subd    SerHeadRcv,y
221
        addd    SerTailRcv,y
222
srcXit:
223
        rts
224
 
225
;------------------------------------------------------------------------------
226
; Serial IRQ routine
227
;
228
; Keeps looping as long as it finds characters in the ACIA recieve buffer/fifo.
229
; Received characters are buffered. If the buffer becomes full, new characters
230
; will be lost.
231
;
232
; Parameters:
233
;               none
234
; Modifies:
235
;               d,x
236
; Returns:
237
;               none
238
;------------------------------------------------------------------------------
239
 
240
SerialIRQ:
241
sirqNxtByte:
242
        ldb             ACIA+ACIA_STAT  ; check the status
243
        bitb    #$08                                            ; bit 3 = rx full
244
        beq             notRxInt
245
        ldb             ACIA+ACIA_RX            ; get data from Rx buffer to clear interrupt
246
        cmpb    #CTRLT                                  ; detect special keystroke
247
        bne     sirq0001
248
;       bsr     DumpTraceQueue
249
sirq0001:
250
        pshs    b
251
        ; Compute receive buffer address
252
        lda             IOFocusID
253
        asla
254
        asla
255
        asla
256
        asla
257
        ora             #$C00
258
        clrb
259
        tfr             d,y
260
        puls    b
261
        lda             SerTailRcv,y                    ; check if recieve buffer full
262
        inca
263
        cmpa    SerHeadRcv,y
264
        beq             sirqRxFull
265
        sta             SerTailRcv,y            ; update tail pointer
266
        deca                                                                    ; backup
267
        exg             a,b
268
        leax    SerRcvBuf,y                     ; x = buffer address
269
        sta             b,x                                                     ; store recieved byte in buffer
270
        tst             SerRcvXoff,y            ; check if xoff already sent
271
        bne             sirqNxtByte
272
        bsr             SerialRcvCount  ; if more than 4080 chars in buffer
273
        cmpb    #4080
274
        blo             sirqNxtByte
275
        ldb             #XOFF                                           ; send an XOFF
276
        clr             SerRcvXon,y                     ; clear XON status
277
        stb             SerRcvXoff,y            ; set XOFF status
278
        stb             ACIA+ACIA_TX
279
        bra             sirqNxtByte     ; check the status for another byte
280
sirqRxFull:
281
notRxInt:
282
        rts
283
 
284
nmeSerial:
285
        fcb             "Serial",0
286
 
287
;------------------------------------------------------------------------------
288
; Put a string to the serial port.
289
;
290
; Parameters:
291
;               d = pointer to string
292
; Modifies:
293
;               none
294
; Returns:
295
;               none
296
;------------------------------------------------------------------------------
297
 
298
SerialPutString:
299
        pshs    d,x
300
        tfr             d,x
301
sps2:
302
        ldb             ,x
303
        beq             spsXit
304
        inx
305
        bsr             SerialPutChar
306
        bra             sps2
307
spsXit:
308
        puls    d,x,pc
309
 
310
;------------------------------------------------------------------------------
311
; A little routine to test serial output.
312
;
313
; Parameters:
314
;               none
315
; Modifies:
316
;               none
317
; Returns:
318
;               none
319
;------------------------------------------------------------------------------
320
 
321
SerialOutputTest:
322
        pshs    d
323
        ldd             #msgSerialTest
324
        lbsr    DisplayString
325
        bsr             SerialInit
326
sotst1:
327
        ldb             #XON
328
        bsr             SerialPutChar
329
        bsr             SerialPutChar
330
        bsr             SerialPutChar
331
        ldd             #msgSerialTest
332
        bsr             SerialPutString
333
        lbsr    INCH
334
        cmpb    #CTRLC
335
        bne             sotst1
336
        puls    d,pc
337
 
338
msgSerialTest:
339
        fcb     "Serial port test",CR,LF,0
340
 

powered by: WebSVN 2.1.0

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