LogoEjk

emilkhatib.com

Bringing some order in the PSiN PHY layer

May 7, 2026

We achieved basic communication in the last entries. Now, we want to have a MAC layer, and for that, we need to sort out some details of the PHY layer.

As I stated in my last entry, before moving to building the MAC, I have changed the PHY layer a bit. It now uses pullups, and the receive starts when a 0 is detected. This will allow us something that should not be intentionally sought: collisions. But remember, the PSiN is not meant to be good, it's meant to be educative.

Another aspect that the PHY layer did was that the packet length determined when the PHY layer stopped reading. This is fine for a simple protocol, but not very representative of the OSI division of functions. So I had to think of a way to have the PHY layer know when to stop without knowing the packet length. Several ways to do this:

Since the idea of PSiN from the very beginning was to transmit simple data, a very fitting idea would be to restrict the data to ASCII characters. ASCII already has characters designed for start (STX) and end (ETX/EOT), and even ACK, which will be nice to have later on. If we limit the data to ASCII characters, we are sure that STX and ETX will not be present in the data, they have a single purpose. At PHY layer, anyhow, we cannot call them characters, but signals. Therefore, the redesign of the PHY layer includes code for detecting start (already there) and end (new, using the CLOSING constant in receive() ).

I have also modified the code to include some useful output over serial, which in the future will be optional. The serial shows the read bits, shows in real time when a packet is being received and summarizes the data in the end. With all these, here is an example of a couple of receptions:

New PHY layer working

Note that the first byte of the data shows the length of the rest of the packet (2 bytes), which will be processed in the future by the MAC layer, therefore constituting a header of the preliminary protocol. The PHY layer reads 3 bytes (header + data at MAC layer). Also note that the sequence 00000010, which reads 2 in decimal, also matches the STX character, which should not be possible. That is a problem for when we design the MAC layer header.

Furthermore, the code has been improved, commented and simplified ... to complicate it later with MAC.

Return to blog