Skip to content

Commit b3f88df

Browse files
committed
spi: a bit of refactor
1 parent 6dcaea4 commit b3f88df

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/main/scala/spi/SerialSpiTest.scala

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package spi
22

33
import com.fazecast.jSerialComm._
44

5+
import chiseltest._
6+
57
/**
68
* A simple test for SPI communication.
79
* @param id (Adx, Flash, SRAM)
@@ -228,7 +230,7 @@ class SerialSpiTest(id: Int, portName: String = "/dev/tty.usbserial-210292B40860
228230
readStatusRegister()
229231
}
230232

231-
def echoPins(sck: Int, mosi: Int, ncs: Int) = {
233+
def echoPinsOuter(sck: Int, mosi: Int, ncs: Int) = {
232234
// println(s"ncs: $ncs, mosi: $mosi, sck: $sck")
233235
val bits = (ncs << 2) | (mosi << 1) | sck
234236
val s = "w4" + (bits + '0').toChar + "4\r"
@@ -240,6 +242,14 @@ class SerialSpiTest(id: Int, portName: String = "/dev/tty.usbserial-210292B40860
240242
// println("bit: " + bit)
241243
bit
242244
}
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)
251+
spi.miso.poke(bit)
252+
}
243253
}
244254

245255
object SerialSpiTest extends App {

src/test/scala/spi/FlashTest.scala

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ class FlashTest() extends AnyFlatSpec with ChiselScalatestTester {
1111

1212
it should "test the flash" in {
1313

14-
var spi: SerialSpiTest = null
14+
var spiDriver: SerialSpiTest = null
1515
try {
16-
spi = new SerialSpiTest(1)
16+
spiDriver = new SerialSpiTest(1)
1717
} catch {
1818
case e: Exception => {
1919
println("Serial port not available")
@@ -23,19 +23,22 @@ class FlashTest() extends AnyFlatSpec with ChiselScalatestTester {
2323

2424
test(new SpiMaster) { c =>
2525

26+
/*
2627
def echoPins() = {
2728
val sck = c.spi.sclk.peekInt().toInt
2829
val mosi = c.spi.mosi.peekInt().toInt
2930
val ncs = c.spi.ncs.peekInt().toInt
30-
val bit = spi.echoPins(sck, mosi, ncs)
31+
val bit = spiDriver.echoPinsOuter(sck, mosi, ncs)
3132
c.spi.miso.poke(bit)
3233
}
34+
35+
*/
3336
def readWord(addr: Int) = {
3437
c.io.readData.ready.poke(true.B)
3538

3639
c.io.readAddr.valid.poke(true.B)
3740
c.io.readAddr.bits.poke(addr.U)
38-
echoPins()
41+
spiDriver.echoPins(c.spi)
3942
c.clock.step()
4043
/*
4144
while(!c.io.readAddr.ready.peekBoolean()) {
@@ -49,7 +52,7 @@ class FlashTest() extends AnyFlatSpec with ChiselScalatestTester {
4952
var ready = false
5053
var v = 0
5154
while(!ready) {
52-
echoPins()
55+
spiDriver.echoPins(c.spi)
5356
c.clock.step()
5457
if (c.io.readData.valid.peekBoolean()) {
5558
ready = true

0 commit comments

Comments
 (0)