← ProblemsCircuits / Sequential Logic / Finite State Machines

PS/2 packet parser and datapath

15%fsmdatapathserial-protocols

Extend the PS/2 packet parser with a datapath that outputs the message bytes. The framing FSM is unchanged:

  • Bytes arrive one per clock on in[7:0]; a message is three bytes; byte 1 is the first byte seen with in[3] = 1 while searching; bytes 2 and 3 follow unconditionally.
  • done is asserted for one cycle, the cycle after byte 3 arrives. The byte seen during the done cycle may be byte 1 of the next message.
  • Active-high synchronous reset returns the FSM to searching.

New output out_bytes[23:0]: when done is high it must hold the complete message — byte 1 in out_bytes[23:16], byte 2 in [15:8], byte 3 in [7:0].

To keep the behavior fully specified, implement the datapath as a 24-bit shift register that captures every byte on every rising clock edge, unconditionally (including during reset and while searching): out_bytes <= {out_bytes[15:0], in}. The last three bytes received are then automatically the message bytes whenever done is high.