Skip to content

Instantly share code, notes, and snippets.

@philpem
Last active September 16, 2024 16:55
Show Gist options
  • Save philpem/b1b5b39da51e1b07f20507918812a581 to your computer and use it in GitHub Desktop.
Save philpem/b1b5b39da51e1b07f20507918812a581 to your computer and use it in GitHub Desktop.
SDLC in Pi 2040 PIO
; This is a first pass attempt at making a Pi Zero PIO module handle zero-bit stuffing and flag transmission
; It will need cycle delays adding, etc. to turn it into usable code.
; I got half-way through it, then realised it wasn't going to work for my use case (NABU Adaptor packet generation) because
; the NABU Adaptor has a LFSR-based bitstream randomizer (scrambler) after the SDLC block.
;
; Set up autopull, and a bit length of 9 (if such a thing is possible, I haven't checked).
; The first bit shifted is a 0 for normal data, or a 1 for 'raw' sending, which is used to send flags (0x17E).
.program sdlc
.side_set 1
; Pin assignments:
; - SCK is side-set pin 0
; - DATA is OUT pin 0 and SET pin 0
public entry_point:
; autopull on, shiftcount 9
byteloop:
out x side 0 ; Get first bit of our 9-bit word
jmp !x cooked ; If bit low then do cooked write
; RAW WRITE - used for FLAGs. Resets one-counter (yreg) to zero.
set y, 0 ; Assume we're sending a flag, which ends with a zero
set x, 7 ; Preload bit counter (8 bits)
raw_bitloop:
out pins, 1 side 0
jmp x-- raw_bitloop side 1
jmp byteloop
; COOKED WRITE -- inserts zeroes as needed
cooked:
set x, 7 ; Preload bit counter (8 bits)
cooked_bitloop:
out y, 1 side 0 ; Shift 1 bit out and write it to Y, sideset the clock
jmp x-- cooked_bitloop side 1 ; sideset the clock and go around
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment