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

Subversion Repositories uart6551

[/] [uart6551/] [trunk/] [trunk/] [software/] [uart6551demo.asm] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 robfinch
XON                                     equ             $11
2
XOFF                            equ             $13
3
LEDS                            equ             $FFDC0600
4
UART                            equ             $FFDC0A00
5
 
6
                code    18 bits
7
                org             $FFFC0000
8
start:
9
                ldi             $sp,#$80000-4           ; setup system mode stack pointer
10
                ; Switch to user mode
11
.0004:
12
                eret
13
                ; When an ECALL instruction is executed it'll start here.
14
                bra             .0004
15
 
16
;------------------------------------------------------------------------------
17
; User mode code starts here
18
;------------------------------------------------------------------------------
19
                org             $FFFC0100
20
 
21
                ldi             $sp,#$80000-1028                ; setup user mode stack pointer
22
                add             $t0,$x0,#$AB                            ; turn on the LED
23
                stt             $t0,LEDS
24
                call    SerialInit
25
                ldi             $t2,#16                                                 ; send an XON just in case
26
                ldi             $a0,#XON
27
.0004:
28
                call    SerialPutChar
29
                sub             $t2,$t2,#1
30
                bne             $t2,$x0,.0004
31
                ldi             $a0,#'A'                                                ; Try sending the letter 'A'
32
                call    SerialPutChar
33
.0002:
34
                ldi             $a0,#msgStart                           ; spit out a startup message
35
                call    SerialPutString
36
 
37
                ; Now a loop to recieve and echo back characters
38
.0003:
39
                call    SerialPeekChar
40
                blt             $v0,$x0,.0003
41
                mov             $a0,$v0
42
                call    SerialPutChar
43
                bra             .0003
44
 
45
;------------------------------------------------------------------------------
46
; SerialPeekChar
47
;
48
; Check the serial port status to see if there's a char available. If there's
49
; a char available then return it.
50
;
51
; Modifies:
52
;               $t0
53
; Returns:
54
;               $v0 = character or -1
55
;------------------------------------------------------------------------------
56
 
57
SerialPeekChar:
58
                ldb             $t0,UART+4
59
                and             $t0,$t0,#8                      ; look for Rx not empty
60
                beq             $t0,$x0,.0001
61
                ldb             $v0,UART
62
                ret
63
.0001:
64
                ldi             $v0,#-1
65
                ret
66
 
67
;------------------------------------------------------------------------------
68
; SerialPutChar
69
;    Put a character to the serial transmitter. This routine blocks until the
70
; transmitter is empty.
71
;
72
; Parameters:
73
;               $a0 = character to put
74
; Modifies:
75
;               $t0
76
;------------------------------------------------------------------------------
77
 
78
SerialPutChar:
79
.0001:
80
                ldb             $t0,UART+4                              ; wait until the uart indicates tx empty
81
                and             $t0,$t0,#16                             ; bit #4 of the status reg
82
                beq             $t0,$x0,.0001                   ; branch if transmitter is not empty
83
                stb             $a0,UART                                        ; send the byte
84
                ret
85
 
86
;------------------------------------------------------------------------------
87
; SerialPutString
88
;    Put a string of characters to the serial transmitter. Calls the
89
; SerialPutChar routine, so this routine also blocks if the transmitter is not
90
; empty.
91
;
92
; Parameters:
93
;               $a0 = pointer to null terminated string to put
94
; Modifies:
95
;               $t0 and $t1
96
; Stack Space:
97
;               2 words
98
;------------------------------------------------------------------------------
99
 
100
SerialPutString:
101
                sub             $sp,$sp,#8                              ; save link register
102
                stt             $ra,[$sp]
103
                stt             $a0,4[$sp]                              ; and argument
104
                mov             $t1,$a0                                         ; t1 = pointer to string
105
.0001:
106
                ldb             $a0,[$t1]
107
                add             $t1,$t1,#1                              ; advance pointer to next byte
108
                beq             $a0,$x0,.done                   ; branch if done
109
                call    SerialPutChar                   ; output character
110
                bra             .0001
111
.done:
112
                ldt             $ra,[$sp]                                       ; restore return address
113
                ldt             $a0,4[$sp]                              ; and argument
114
                add             $sp,$sp,#8
115
                ret
116
 
117
;------------------------------------------------------------------------------
118
; Initialize serial port.
119
;
120
; Modifies:
121
;               $t0
122
;------------------------------------------------------------------------------
123
 
124
SerialInit:
125
                ldi             $t0,#$0B                                                ; dtr,rts active, rxint disabled, no parity
126
                stt             $t0,UART+8
127
                ldi             $t0,#$08070012                  ; reset the fifo's
128
                stt             $t0,UART+12
129
                ldi             $t0,#$08010012                  ; baud 115200, 1 stop bit, 8 bit, internal baud gen
130
                stt             $t0,UART+12
131
                ret
132
 
133
;------------------------------------------------------------------------------
134
; Message strings
135
;------------------------------------------------------------------------------
136
 
137
msgStart:
138
                db              "uart6551 Demo Starting.",13,10,0

powered by: WebSVN 2.1.0

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