For the '299 USR, not latching puts you on the knife edge, where the USR and the SPI bus device must shift at the same time. Otherwise, if the USR shifts before the SPI Bus Device, MISO will be available from the bus and MOSI must be latched ... if the USR shifts after the SPI Bus Device, MOSI will be available from the bus and MISO must be latched.
I think the ideal SPLD SPI chip for a 65xx bus would be internally a Mode 3 SCLK and would be quite like a USR except that it latched MISO (DS0) and MOSI (Q7) on the downward clock tick, and had CS1, /CS2 and R/W, and did the logic internally to convert an internal Mode 3 SCLK into the desired SCLK for the SPI bus.
I think starting with Mode 3 USR SCLK and either passing it on as a Mode 3 SPI_SCLK or converting it to Mode 0 SPI_SCLK may be easier direction. In the Mode 0 conversion, that requires masking the high internal SCLK and putting a low idle SCLK on the SPI bus, removing the mask when the Mode 3 SCLK goes low for the first time, and then restoring the mask after the final upward transition of the Mode 3 internal SCLK.
So get the SPI_SCLK by filtering the Internal_SCLK using an AND gate that has inputs of a Mode 3 SCLK and a state. For Mode 0, the State is /reset to 0 before pulling down the /Select line, which which holds the idle clock low. The /set input to the state is the Mode 3 SCLK, so that when the Mode 3 SCLK goes low for its Phi1 clock phase, the State line goes high. However, now the Mode 3 SCLK input to the AND gate is low, so the Mode 0 SCLK output remains low until the first upward transition of the Internal SCLK. After 8 bits, the Mode 3 SCLK ends high, and then the read of the input byte can reset the Mode 0.
So when running Mode 0, it is necessary to read the MISO byte even if the MISO byte is not used, but the whole process of write, NOP, NOP, NOP, read will be 14 clock cycles, which is such a big win over bit-banging that I would not begrudge it the 4 clock overhead for redundant reads.
The /SELECT_RD line can be OR'd with a Mode select input as the /reset input to the /s /r state latch, and if you want a Mode 0 SCLK, you pull the Mode Select input low and do a dummy read of MISO before you pull /SPI_SELECT low. If you want a Mode 3 SCLK, you pull the Mode Select input high, and do a dummy write of MOSI before you pull /SPI_SELECT low.
If it is possible to refrain from doing a read during the SPI SCLK cycle, that means that the state machine can be a simple /S /R latch from cross connecting two NAND gates. I guess that means you either only use the SPI bus during NMI interrupt handling or never use the SPI bus during NMI interrupt handling.
If you generate Mode 0 from Mode 3 by filtering the serial clock to bring it low for idle, that means the clock polarity and phase are both inverted at the same time. So if you want a two line, four mode SCLK mode select, use SPI_PHASE as the Mode Select input, and use SPI_POLARITY to selectively invert the result of the above circuit: XOR(SPI_2MODE,XOR(SPI_POLARITY,SPI_PHASE)), so that when SPI_POLARITY and SPI_PHASE are equal, the SPI_2MODE serial clock is left alone, and when they are different, the SPI_2MODE serial clock is inverted.
Note that with the USR, you don't need to generate the /SELECT_RD line for the USR from /Select and /RD, since you can simply connect /SELECT to /OE1 and /RD to /OE2 for the read select itself. So the mode 0 /reset input can be a three input OR gate, OR(/SELECT,/RD,Mode), if preferred to the two stage OR(Mode,OR(/Select,/RD)).
|