1 |
9 |
robfinch |
|
2 |
|
|
To use:
|
3 |
|
|
|
4 |
|
|
Set the pClkFreq parameter to the frequency of the system
|
5 |
|
|
clock (clk_i). This can be done when the core is instanced.
|
6 |
|
|
|
7 |
|
|
1) set the baud rate value in the clock multiplier
|
8 |
|
|
registers (CM1,2,3). A default multiplier value may
|
9 |
|
|
be specified using the pClkMul parameter, so it
|
10 |
|
|
doesn't have to be programmed at run time. (Note the
|
11 |
|
|
pBaud parameter may also be set, but it doesn't work
|
12 |
|
|
in all cases due to arithmetic limitations).
|
13 |
|
|
2) enable communication by activating the rts, and
|
14 |
|
|
dtr signals in the modem control register. These
|
15 |
|
|
signals are defaulted to be active on reset, so they
|
16 |
|
|
may not need to be set. The pRts and pDtr parameters
|
17 |
|
|
may be used to change the default setting.
|
18 |
|
|
3) use interrupts or poll the status register to
|
19 |
|
|
determine when to transmit or receive a byte of data
|
20 |
|
|
4) read / write the transmit / recieve data buffer
|
21 |
|
|
for communication.
|
22 |
|
|
|
23 |
|
|
Notes:
|
24 |
|
|
This core only supports a single transmission /
|
25 |
|
|
reception format: 1 start, 8 data, and 1 stop bit (no
|
26 |
|
|
parity).
|
27 |
|
|
The baud rate generator uses a 24 bit harmonic
|
28 |
|
|
frequency synthesizer. Compute the multiplier value
|
29 |
|
|
as if a 32 bit value was needed, then take the upper
|
30 |
|
|
24 bits of the value. (The number of significant bits
|
31 |
|
|
in the value determine the minimum frequency
|
32 |
|
|
resolution or the precision of the value).
|
33 |
|
|
|
34 |
|
|
baud rate * 16
|
35 |
|
|
value = -----------------------
|
36 |
|
|
(clock frequency / 2^32)
|
37 |
|
|
|
38 |
|
|
eg 38400 * 16
|
39 |
|
|
value = -----------------------
|
40 |
|
|
(28.63636MHz / 2^32)
|
41 |
|
|
|
42 |
|
|
= 92149557.65
|
43 |
|
|
= 057E1736 (hex)
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
taking the upper 24 bits
|
47 |
|
|
top 24 = 057E17
|
48 |
|
|
= 359959
|
49 |
|
|
|
50 |
|
|
so the value needed to be programmed into the register
|
51 |
|
|
for 38.4k baud is 57E17 (hex)
|
52 |
|
|
eg CM0 = 0 (not used)
|
53 |
|
|
CM1 = 17 hex
|
54 |
|
|
CM2 = 7E hex
|
55 |
|
|
CM3 = 05 hex
|
56 |
|
|
|
57 |
|
|
|
58 |
|
|
Register Description
|
59 |
|
|
|
60 |
|
|
reg
|
61 |
|
|
|
62 |
|
|
TRB - transmit / receive buffer
|
63 |
|
|
transmit / receive buffer
|
64 |
|
|
write - write to transmit buffer
|
65 |
|
|
read - read from receive buffer
|
66 |
|
|
|
67 |
|
|
1 read only (RO)
|
68 |
|
|
LS - line status register
|
69 |
|
|
bit 0 = receiver not empty, this bit is set if there is
|
70 |
|
|
any data available in the receiver fifo
|
71 |
|
|
bit 1 = overrun, this bit is set if receiver overrun occurs
|
72 |
|
|
bit 3 = framing error, this bit is set if there was a
|
73 |
|
|
framing error with the current byte in the receiver
|
74 |
|
|
buffer.
|
75 |
|
|
bit 5 = transmitter not full, this bit is set if the transmitter
|
76 |
|
|
can accept more data
|
77 |
|
|
bit 6 = transmitter empty, this bit is set if the transmitter is
|
78 |
|
|
completely empty
|
79 |
|
|
|
80 |
|
|
2 MS - modem status register (RO)
|
81 |
|
|
writing to the modem status register clears the change
|
82 |
|
|
indicators, which should clear a modem status interrupt
|
83 |
|
|
bit 3 = change on dcd signal
|
84 |
|
|
bit 4 = cts signal level
|
85 |
|
|
bit 5 = dsr signal level
|
86 |
|
|
bit 6 = ri signal level
|
87 |
|
|
bit 7 = dcd signal level
|
88 |
|
|
|
89 |
|
|
3 IS - interrupt status register (RO)
|
90 |
|
|
bit 0-4 = mailbox number
|
91 |
|
|
bit 0,1 = 00
|
92 |
|
|
bit 2-4 = encoded interrupt value
|
93 |
|
|
bit 5-6 = not used, reserved
|
94 |
|
|
bit 7 = 1 = interrupt pending, 0 = no interrupt
|
95 |
|
|
|
96 |
|
|
4 IE - interrupt enable register (RW)
|
97 |
|
|
bit 0 = receive interrupt (data present)
|
98 |
|
|
bit 1 = transmit interrupt (data empty)
|
99 |
|
|
bit 3 = modem status (dcd) register change
|
100 |
|
|
bit 5-7 = unused, reserved
|
101 |
|
|
|
102 |
|
|
5 FF - frame format register (RW)
|
103 |
|
|
this register doesn't do anything in the simpleUart
|
104 |
|
|
but is reserved for compatiblity with the more
|
105 |
|
|
advanced uart
|
106 |
|
|
|
107 |
|
|
6 MC - modem control register (RW)
|
108 |
|
|
bit 0 = dtr signal level output
|
109 |
|
|
bit 1 = rts signal level output
|
110 |
|
|
|
111 |
|
|
7 - control register
|
112 |
|
|
bit 0 = hardware flow control,
|
113 |
|
|
when this bit is set, the transmitter output is
|
114 |
|
|
controlled by the cts signal line automatically
|
115 |
|
|
|
116 |
|
|
|
117 |
|
|
* Clock multiplier steps the 16xbaud clock frequency
|
118 |
|
|
in increments of 1/2^32 of the clk_i input using a
|
119 |
|
|
harmonic frequency synthesizer
|
120 |
|
|
eg. to get a 9600 baud 16x clock (153.6 kHz) with a
|
121 |
|
|
27.175 MHz clock input,
|
122 |
|
|
value = upper24(9600 * 16 / (27.175MHz / 2^32))
|
123 |
|
|
Higher frequency baud rates will exhibit more jitter
|
124 |
|
|
on the 16x clock, but this will mostly be masked by the
|
125 |
|
|
16x clock factor.
|
126 |
|
|
|
127 |
|
|
8 CM0 - Clock Multiplier byte 0 (RW)
|
128 |
|
|
this is the least significant byte
|
129 |
|
|
of the clock multiplier value
|
130 |
|
|
this register is not used unless the clock
|
131 |
|
|
multiplier is set to contain 32 bit values
|
132 |
|
|
|
133 |
|
|
9 CM1 - Clock Multiplier byte 1 (RW)
|
134 |
|
|
this is the third most significant byte
|
135 |
|
|
of the clock multiplier value
|
136 |
|
|
this register is not used unless the clock
|
137 |
|
|
multiplier is set to contain 24 or 32 bit values
|
138 |
|
|
|
139 |
|
|
10 CM2 - Clock Multiplier byte 2 (RW)
|
140 |
|
|
this is the second most significant byte of the clock
|
141 |
|
|
multiplier value
|
142 |
|
|
|
143 |
|
|
11 CM3 - Clock Multiplier byte 3 (RW)
|
144 |
|
|
this is the most significant byte of the multiplier value
|
145 |
|
|
|
146 |
|
|
12 FC - Fifo control register (RW)
|
147 |
|
|
this register doesnt' do anything in the simpleUart
|
148 |
|
|
but is reserved for compatibility with the more
|
149 |
|
|
advanced uart
|
150 |
|
|
|
151 |
|
|
13-14 reserved registers
|
152 |
|
|
|
153 |
|
|
15 SPR - scratch pad register (RW)
|
154 |
|
|
|
155 |
|
|
|
156 |
|
|
|
157 |
|
|
SAMPLE SOFTWARE USAGE:
|
158 |
|
|
This is an extract of code from Tiny Basic 68000. The UART is in use as the auxilliary
|
159 |
|
|
port for tiny basic. The sample is in 68000 assembly language. The sample uses default
|
160 |
|
|
settings of the UART, which is 19.2k baud, so there is no initialization required.
|
161 |
|
|
|
162 |
|
|
;==============================================================================
|
163 |
|
|
;==============================================================================
|
164 |
|
|
UART EQU 0xFFDC0A00
|
165 |
|
|
UART_LS EQU UART+1
|
166 |
|
|
UART_CTRL EQU UART+7
|
167 |
|
|
|
168 |
|
|
|
169 |
|
|
;*
|
170 |
|
|
;* ===== Output character to the host (Port 2) from register D0
|
171 |
|
|
;* (Preserves all registers.)
|
172 |
|
|
;*
|
173 |
|
|
AUXOUT:
|
174 |
|
|
BTST #5,UART_LS ;is port ready for a character?
|
175 |
|
|
BEQ AUXOUT ;if not, wait for it
|
176 |
|
|
MOVE.B D0,UART ;out it goes.
|
177 |
|
|
RTS
|
178 |
|
|
|
179 |
|
|
;*
|
180 |
|
|
;* ===== Input a character from the host into register D0 (or
|
181 |
|
|
;* return Zero status if there's no character available).
|
182 |
|
|
;*
|
183 |
|
|
AUXIN:
|
184 |
|
|
BTST #0,UART_LS ;is character ready?
|
185 |
|
|
BEQ AXIRET ;if not, return Zero status
|
186 |
|
|
MOVE.B UART,D0 ;else get the character
|
187 |
|
|
AND.B #0x7F,D0 ;zero out the high bit
|
188 |
|
|
AXIRET:
|
189 |
|
|
RTS
|
190 |
|
|
|
191 |
|
|
|
192 |
|
|
;==============================================================================
|
193 |
|
|
;==============================================================================
|
194 |
|
|
EXAMPLE OF CORE INSTANCING:
|
195 |
|
|
The core needs to know the clock rate.
|
196 |
|
|
|
197 |
|
|
|
198 |
|
|
rtfSimpleUart #(16666667) uuart
|
199 |
|
|
(
|
200 |
|
|
// WISHBONE Slave interface
|
201 |
|
|
.rst_i(rst), // reset
|
202 |
|
|
.clk_i(clk25), // eg 100.7MHz
|
203 |
|
|
.cyc_i(sys_cyc), // cycle valid
|
204 |
|
|
.stb_i(sys_stb), // strobe
|
205 |
|
|
.we_i(sys_we), // 1 = write
|
206 |
|
|
.adr_i(cpu_adr), // register address
|
207 |
|
|
.dat_i(dbo[7:0]), // data input bus
|
208 |
|
|
.dat_o(uart_dbo), // data output bus
|
209 |
|
|
.ack_o(uart_ack), // transfer acknowledge
|
210 |
|
|
.vol_o(), // volatile register selected
|
211 |
|
|
.irq_o(), // interrupt request
|
212 |
|
|
//----------------
|
213 |
|
|
.cts_ni(1'b0), // clear to send - active low - (flow control)
|
214 |
|
|
.rts_no(), // request to send - active low - (flow control)
|
215 |
|
|
.dsr_ni(1'b0), // data set ready - active low
|
216 |
|
|
.dcd_ni(1'b0), // data carrier detect - active low
|
217 |
|
|
.dtr_no(), // data terminal ready - active low
|
218 |
|
|
.rxd_i(rxd), // serial data in
|
219 |
|
|
.txd_o(txd), // serial data out
|
220 |
|
|
.data_present_o()
|
221 |
|
|
);
|
222 |
|
|
|
223 |
|
|
|
224 |
|
|
|