soc-hub-fi / headsail-vp

Headsail — Virtual Platform
0 stars 3 forks source link

Improving the SPI-M #91

Open hegza opened 3 weeks ago

hegza commented 3 weeks ago

@Aisha-KM @RHamalainen

Some questions based on the current implementation

Writing on RX (SOLVED)

Does it ever make sense to write on the RX line? I.e., is this method redundant?

Solved: I was misinterpreting the source code.

Reading from the RX

How would one read from the RX. Looking at the UART RX code, something like this might work:

// Block until SPI-M reports data is available
while !spim.read_ready() {}

// SPI-Ms RX channel
let rx = spim.rx();

// Block until device reports ability to enqueue
while !rx.can_enqueue() {}

// Read the buffer from device
unsafe { rx.enqueue(buf) }

// Block again until the transfer is complete
while rx.saddr().read().bits() != 0 {}

Now the main question is, how to determine when data is ready to be read (read_ready).

Aisha-KM commented 3 weeks ago

we can't implement the same functionality as read_ready() for SPIM since it does not have a VALID register to check for the data validity, however we can rely on can_enqueue() to some degree as it reads the transfer "pending" status in a channel.

Aisha-KM commented 3 weeks ago

The changes are already done by @hegza , they are essentially similar to mine.

I added the check for enqueue here. please check it and let me know if there is issues with it.

hegza commented 3 weeks ago

It looks like the current version at main might work. I added deprecation warning to the method, imploring that it should be tested.