Skip to content

Commit 64e3d46

Browse files
committed
spi: some renaming
1 parent b3f88df commit 64e3d46

File tree

2 files changed

+21
-32
lines changed

2 files changed

+21
-32
lines changed

src/main/scala/spi/SerialSpiTest.scala renamed to src/main/scala/spi/SerialSpiDriver.scala

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import com.fazecast.jSerialComm._
55
import chiseltest._
66

77
/**
8-
* A simple test for SPI communication.
8+
* A simple driver for SPI communication via the serial port and the debug interface.
9+
* USed from this App, the FlashTest with testing the controller, and should be used by Wildcat in simulation.
910
* @param id (Adx, Flash, SRAM)
1011
*/
11-
class SerialSpiTest(id: Int, portName: String = "/dev/tty.usbserial-210292B408601") {
12+
class SerialSpiDriver(id: Int, portName: String = "/dev/tty.usbserial-210292B408601") {
1213

1314
// TODO: fix the hard coded port name
1415
val port = SerialPort.getCommPort(portName)
@@ -230,31 +231,31 @@ class SerialSpiTest(id: Int, portName: String = "/dev/tty.usbserial-210292B40860
230231
readStatusRegister()
231232
}
232233

233-
def echoPinsOuter(sck: Int, mosi: Int, ncs: Int) = {
234-
// println(s"ncs: $ncs, mosi: $mosi, sck: $sck")
234+
/**
235+
* Watch SPI output pins in simulation and forward them via the serial port debugger to the real Flash.
236+
* And the other way around, read the MISO pin from the Flash and forward it to the SPI input pin in simulation.
237+
* @param spi
238+
*/
239+
def echoPins(spi: SpiIO) = {
240+
val sck = spi.sclk.peekInt().toInt
241+
val mosi = spi.mosi.peekInt().toInt
242+
val ncs = spi.ncs.peekInt().toInt
235243
val bits = (ncs << 2) | (mosi << 1) | sck
236244
val s = "w4" + (bits + '0').toChar + "4\r"
237245
writeReadSerial(s)
238246
val rx = writeReadSerial("r")
239247
// '8' is MISO bit set
240248
val bit = if (rx(8 - 1) == '8') 1 else 0
241-
// println("rx: " + rx)
242-
// println("bit: " + bit)
243-
bit
244-
}
245-
246-
def echoPins(spi: SpiIO) = {
247-
val sck = spi.sclk.peekInt().toInt
248-
val mosi = spi.mosi.peekInt().toInt
249-
val ncs = spi.ncs.peekInt().toInt
250-
val bit = echoPinsOuter(sck, mosi, ncs)
251249
spi.miso.poke(bit)
252250
}
253251
}
254252

255-
object SerialSpiTest extends App {
253+
/**
254+
* Test SPI components and program the Flash.
255+
*/
256+
object SerialSpiDriver extends App {
256257

257-
val spi = new SerialSpiTest(1) // Flash
258+
val spi = new SerialSpiDriver(1) // Flash
258259

259260
spi.csLow()
260261
print(spi.writeReadSerial("r"))
@@ -298,7 +299,7 @@ object SerialSpiTest extends App {
298299

299300

300301
println("SRAM test")
301-
val sram = new SerialSpiTest(2) // SRAM
302+
val sram = new SerialSpiDriver(2) // SRAM
302303
sram.readJedecIdWait()
303304
sram.readMemory(0)
304305
sram.writeSram(0, 0x55)

src/test/scala/spi/FlashTest.scala

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
package spi
22

33
import chisel3._
4-
import chisel3.util._
54
import chiseltest._
65
import org.scalatest.flatspec.AnyFlatSpec
7-
import spi.SerialSpiTest.spi
86

97
class FlashTest() extends AnyFlatSpec with ChiselScalatestTester {
108
behavior of "FlashTest"
119

1210
it should "test the flash" in {
1311

14-
var spiDriver: SerialSpiTest = null
12+
var spiDriver: SerialSpiDriver = null
1513
try {
16-
spiDriver = new SerialSpiTest(1)
14+
spiDriver = new SerialSpiDriver(1)
1715
} catch {
1816
case e: Exception => {
1917
println("Serial port not available")
@@ -23,17 +21,7 @@ class FlashTest() extends AnyFlatSpec with ChiselScalatestTester {
2321

2422
test(new SpiMaster) { c =>
2523

26-
/*
27-
def echoPins() = {
28-
val sck = c.spi.sclk.peekInt().toInt
29-
val mosi = c.spi.mosi.peekInt().toInt
30-
val ncs = c.spi.ncs.peekInt().toInt
31-
val bit = spiDriver.echoPinsOuter(sck, mosi, ncs)
32-
c.spi.miso.poke(bit)
33-
}
34-
35-
*/
36-
def readWord(addr: Int) = {
24+
def readWord(addr: Int): Int = {
3725
c.io.readData.ready.poke(true.B)
3826

3927
c.io.readAddr.valid.poke(true.B)

0 commit comments

Comments
 (0)