Im trying to write a 'library' for an SSC interface. Sending data is working well, but I don't understand how receiving data may work in this case.
Setup is the following:
- Data needs to be read from a bus (1,2,4or8 bits wide).
- Data is sent in 16 bit wide words
- Each data line provides one word serialized, so after 16 clock cycles a transfer of n = 1,2,4or8 (depending on bus width) words is completed.
- Input port is clocked by an external clock.
- Clock is generated permanently
- Start of a new word transmit is indicated by an additional SYNC signal on a 1-bit-port being set to high for the first valid clock cycle
From reading documentation I understood that clocked, buffered inputs will right-shift (resulting in an LSB first transmission) the input values into a shift register on a falling port clock edge. If the shift register is filled, it is copied to another register the CPU can read from (correct?). If the previous value has not been read by the CPU, its lost.
Was thinking about adding a flag and use a conditional port input event that is triggered by the SYNC signal being high. If the flag is set, data is read from the input port (case flag => port :> bla:) and reset on having read (16*n, n = bus width) bits to then wait for another SYNC. But if the data sampling/shift registers work as I think, then its undefined how much of the shift register is filled on receiving the SYNC signal and i will read invalid data.
Is there a way to react to the SYNC signal with reading for exactly 16 clock cycles, including the clock cycle the SYNC signal is set to 'high' on?