-
Notifications
You must be signed in to change notification settings - Fork 1
/
Serial.scala
80 lines (66 loc) · 2.28 KB
/
Serial.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package MySpinalHardware
import spinal.core._
import spinal.lib._
import spinal.lib.com.uart._
class uart_rx extends Component {
val io = new Bundle {
val buffer_reset = in Bool()
val serial_in = in Bool()
val en_16_x_baud = in Bool()
val buffer_read = in Bool()
val buffer_data_present = out Bool()
val buffer_half_full = out Bool()
val buffer_full = out Bool()
val data_out = out Bits(8 bits)
}
val g = UartCtrlGenerics()
val uartCtrlRx = new UartCtrlRx(g)
uartCtrlRx.io.configFrame.dataLength := 7 //8 bits
uartCtrlRx.io.configFrame.parity := UartParityType.NONE
uartCtrlRx.io.configFrame.stop := UartStopType.ONE
uartCtrlRx.io.samplingTick := io.en_16_x_baud
uartCtrlRx.io.rxd <> io.serial_in
val streamOut = Stream(Bits(8 bits))
val rxFifo = StreamFifo(
dataType = Bits(8 bits),
depth = 16
)
rxFifo.io.push << uartCtrlRx.io.read
rxFifo.io.pop >> streamOut
streamOut.ready := io.buffer_read
io.buffer_data_present := streamOut.valid
io.data_out := streamOut.payload
io.buffer_half_full :=rxFifo.io.availability < 8
io.buffer_full := rxFifo.io.availability < 2
}
class uart_tx extends Component {
val io = new Bundle {
val buffer_reset = in Bool()
val data_in = in Bits(8 bits)
val en_16_x_baud = in Bool()
val buffer_write = in Bool()
val serial_out= out Bool()
val buffer_half_full = out Bool()
val buffer_full = out Bool()
}
val g = UartCtrlGenerics()
val uartCtrlTx = new UartCtrlTx(g)
uartCtrlTx.io.configFrame.dataLength := 7 //8 bits
uartCtrlTx.io.configFrame.parity := UartParityType.NONE
uartCtrlTx.io.configFrame.stop := UartStopType.ONE
uartCtrlTx.io.samplingTick := io.en_16_x_baud
uartCtrlTx.io.txd <> io.serial_out
uartCtrlTx.io.break := False
uartCtrlTx.io.cts := False
val streamIn= Stream(Bits(8 bits))
val txFifo = StreamFifo(
dataType = Bits(8 bits),
depth = 16
)
txFifo.io.push << streamIn
txFifo.io.pop >> uartCtrlTx.io.write
streamIn.valid := io.buffer_write
streamIn.payload := io.data_in
io.buffer_half_full :=txFifo.io.availability < 8
io.buffer_full := txFifo.io.availability < 2
}