@@ -5,10 +5,11 @@ import com.fazecast.jSerialComm._
55import 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 )
0 commit comments