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

Subversion Repositories uart6551

[/] [uart6551/] [trunk/] [trunk/] [software/] [serial.asm] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 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
        ldb             #$09                                            ; dtr,rts active, rxint enabled, no parity
55
        stb             ACIA+ACIA_CMD
56
        ldb             #$1E                                            ; baud 9600, 1 stop bit, 8 bit, internal baud gen
57
        stb             ACIA+ACIA_CTRL
58
        ldb             #$0A6                                           ; diable fifos, reset fifos
59
        stb             ACIA+ACIA_CTRL2
60
        rts
61
 
62
;------------------------------------------------------------------------------
63
; SerialGetChar
64
;
65
; Check the serial port buffer to see if there's a char available. If there's
66
; a char available then return it. If the buffer is almost empty then send an
67
; XON.
68
;
69
; Stack Space:
70
;               2 words
71
; Parameters:
72
;               none
73
; Modifies:
74
;               none
75
; Returns:
76
;               d = character or -1
77
;------------------------------------------------------------------------------
78
 
79
SerialGetChar:
80
                pshs    x
81
                sei                                                                             ; disable interrupts
82
                bsr             SerialRcvCount                  ; check number of chars in receive buffer
83
                cmpb    #8                                                      ; less than 8?
84
                bhi             sgc2
85
                ldb             SerRcvXon                               ; skip sending XON if already sent
86
                bne       sgc2            ; XON already sent?
87
                ldb             #XON                                            ; if <8 send an XON
88
                clr             SerRcvXoff                      ; clear XOFF status
89
                stb             SerRcvXon                               ; flag so we don't send it multiple times
90
                stb             ACIA+ACIA_TX
91
sgc2:
92
                ldb             SerHeadRcv                      ; check if anything is in buffer
93
                cmpb    SerTailRcv
94
                beq             sgcNoChars                      ; no?
95
                ldx             #SerRcvBuf
96
                abx
97
                clra
98
                ldb             ,x                                                      ; get byte from buffer
99
                inc             SerHeadRcv                      ; 4k wrap around
100
                bra             sgcXit
101
sgcNoChars:
102
                ldd             #-1
103
sgcXit:
104
                cli
105
                puls    x,pc
106
 
107
;------------------------------------------------------------------------------
108
; SerialPeekChar
109
;
110
; Check the serial port buffer to see if there's a char available. If there's
111
; a char available then return it. But don't update the buffer indexes. No need
112
; to send an XON here.
113
;
114
; Stack Space:
115
;               0 words
116
; Parameters:
117
;               none
118
; Modifies:
119
;               none
120
; Returns:
121
;               d = character or -1
122
;------------------------------------------------------------------------------
123
 
124
SerialPeekChar:
125
        pshs    x
126
        sei
127
        ldb             SerHeadRcv                              ; check if anything is in buffer
128
        cmpb    SerTailRcv
129
        beq             spcNoChars                              ; no?
130
        ldx             #SerRcvBuf
131
        abx
132
        clra
133
        ldb             ,x                                                              ; get byte from buffer
134
        bra             spcXit
135
spcNoChars:
136
        ldd             #-1
137
spcXit:
138
        cli
139
        puls    x,pc
140
 
141
;------------------------------------------------------------------------------
142
; SerialPeekChar
143
;               Get a character directly from the I/O port. This bypasses the input
144
; buffer.
145
;
146
; Stack Space:
147
;               0 words
148
; Parameters:
149
;               none
150
; Modifies:
151
;               d
152
; Returns:
153
;               d = character or -1
154
;------------------------------------------------------------------------------
155
 
156
SerialPeekCharDirect:
157
        ; Disallow interrupts between status read and rx read.
158
        sei
159
        ldb             ACIA+ACIA_STAT
160
        bitb    #8                                                                      ; look for Rx not empty
161
        beq             spcd0001
162
        clra
163
        ldb             ACIA+ACIA_RX
164
        cli
165
        rts
166
spcd0001:
167
        ldd             #-1
168
        cli
169
        rts
170
 
171
;------------------------------------------------------------------------------
172
; SerialPutChar
173
;    Put a character to the serial transmitter. This routine blocks until the
174
; transmitter is empty.
175
;
176
; Stack Space
177
;               0 words
178
; Parameters:
179
;               b = character to put
180
; Modifies:
181
;               none
182
;------------------------------------------------------------------------------
183
 
184
SerialPutChar:
185
        pshs    a
186
spc0001:
187
        cli                                                                             ; provide a window for an interrupt to occur
188
        sei
189
        ; Between the status read and the transmit do not allow an
190
        ; intervening interrupt.
191
        lda             ACIA+ACIA_STAT  ; wait until the uart indicates tx empty
192
        bita    #16                                                     ; bit #4 of the status reg
193
        beq             spc0001                     ; branch if transmitter is not empty
194
        stb             ACIA+ACIA_TX            ; send the byte
195
        cli
196
        puls    a
197
        rts
198
 
199
;------------------------------------------------------------------------------
200
; Calculate number of character in input buffer
201
;
202
; Returns:
203
;               d = number of bytes in buffer.
204
;------------------------------------------------------------------------------
205
 
206
SerialRcvCount:
207
        clra
208
        ldb             SerTailRcv
209
        subb    SerHeadRcv
210
        bge             srcXit
211
        ldd             #$1000
212
        subd    SerHeadRcv
213
        addd    SerTailRcv
214
srcXit:
215
        rts
216
 
217
;------------------------------------------------------------------------------
218
; Serial IRQ routine
219
;
220
; Keeps looping as long as it finds characters in the ACIA recieve buffer/fifo.
221
; Received characters are buffered. If the buffer becomes full, new characters
222
; will be lost.
223
;
224
; Parameters:
225
;               none
226
; Modifies:
227
;               d,x
228
; Returns:
229
;               none
230
;------------------------------------------------------------------------------
231
 
232
SerialIRQ:
233
sirqNxtByte:
234
        ldb             ACIA+ACIA_STAT  ; check the status
235
        bitb    #$08                                            ; bit 3 = rx full
236
        beq             notRxInt
237
        ldb             ACIA+ACIA_RX            ; get data from Rx buffer to clear interrupt
238
        cmpb    #CTRLT                                  ; detect special keystroke
239
        bne     sirq0001
240
;       bsr     DumpTraceQueue
241
sirq0001:
242
        lda             SerTailRcv                      ; check if recieve buffer full
243
        inca
244
        cmpa    SerHeadRcv
245
        beq             sirqRxFull
246
        sta             SerTailRcv                      ; update tail pointer
247
        deca                                                                    ; backup
248
        exg             a,b
249
        ldx             #SerRcvBuf                      ; x = buffer address
250
        abx
251
        sta             ,x                                                      ; store recieved byte in buffer
252
        tst             SerRcvXoff                      ; check if xoff already sent
253
        bne             sirqNxtByte
254
        bsr             SerialRcvCount  ; if more than 4080 chars in buffer
255
        cmpb    #4080
256
        blo             sirqNxtByte
257
        ldb             #XOFF                                           ; send an XOFF
258
        clr             SerRcvXon                               ; clear XON status
259
        stb             SerRcvXoff                      ; set XOFF status
260
        stb             ACIA+ACIA_TX
261
        bra             sirqNxtByte     ; check the status for another byte
262
sirqRxFull:
263
notRxInt:
264
        rts
265
 
266
nmeSerial:
267
        fcb             "Serial",0
268
 
269
;------------------------------------------------------------------------------
270
; Put a string to the serial port.
271
;
272
; Parameters:
273
;               d = pointer to string
274
; Modifies:
275
;               none
276
; Returns:
277
;               none
278
;------------------------------------------------------------------------------
279
 
280
SerialPutString:
281
        pshs    d,x
282
        tfr             d,x
283
sps2:
284
        ldb             ,x
285
        beq             spsXit
286
        inx
287
        bsr             SerialPutChar
288
        bra             sps2
289
spsXit:
290
        puls    d,x,pc
291
 
292
;------------------------------------------------------------------------------
293
; A little routine to test serial output.
294
;
295
; Parameters:
296
;               none
297
; Modifies:
298
;               none
299
; Returns:
300
;               none
301
;------------------------------------------------------------------------------
302
 
303
SerialOutputTest:
304
        pshs    d
305
        ldd             #msgSerialTest
306
        lbsr    DisplayString
307
        bsr             SerialInit
308
sotst1:
309
        ldb             #XON
310
        bsr             SerialPutChar
311
        bsr             SerialPutChar
312
        bsr             SerialPutChar
313
        ldd             #msgSerialTest
314
        bsr             SerialPutString
315
        lbsr    INCH
316
        cmpb    #CTRLC
317
        bne             sotst1
318
        puls    d,pc
319
 
320
msgSerialTest:
321
        fcb     "Serial port test",CR,LF,0
322
 

powered by: WebSVN 2.1.0

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