protocol-emulator / all protocols

snorble

Invented spec: written for a blind rehearsal on 2026-10-18, with no public datasheet.

Spec source

partdocumentpage
SnorbleSNB-1 Snorble Sensor Beacon Rev. Csection 1, p.1: about 5 kframes/s at most
SnorbleSNB-1 Snorble Sensor Beacon Rev. Csection 4, p.1
SnorbleSNB-1 Snorble Sensor Beacon Rev. Csection 4, p.1, and note 1, p.2: inside a frame
SnorbleSNB-1 Snorble Sensor Beacon Rev. Csection 4, p.1, and note 3, p.2

Datasheet limits

firmwareparameterlimitbound byneeds (cycles)bound (cycles)bound (ns)resultmarginsheet
snorbletSYN>= 7500 nsrun3613848000.0oka cycleSNB-1 Snorble Sensor Beacon Rev. C section 4, p.1
snorbletSYN<= 8500 nsrun4073848000.0oka cycleSNB-1 Snorble Sensor Beacon Rev. C section 4, p.1
snorbletL0>= 1100 nskernel54581208.3oka cycleSNB-1 Snorble Sensor Beacon Rev. C section 4, p.1
snorbletL0<= 1300 nsrun61581208.3oka cycleSNB-1 Snorble Sensor Beacon Rev. C section 4, p.1
snorbletL1>= 2900 nsrun1411443000.0oka cycleSNB-1 Snorble Sensor Beacon Rev. C section 4, p.1
snorbletL1<= 3100 nsrun1471443000.0oka cycleSNB-1 Snorble Sensor Beacon Rev. C section 4, p.1
snorbletH>= 1800 nskernel88962000.0oka cycleSNB-1 Snorble Sensor Beacon Rev. C section 4, p.1
snorbletH<= 4000 nsrun191962000.0oka cycleSNB-1 Snorble Sensor Beacon Rev. C section 4, p.1, and note 1, p.2: inside a frame
snorbletIFG>= 20000 nsrun9618566178458.3oka cycleSNB-1 Snorble Sensor Beacon Rev. C section 4, p.1, and note 3, p.2
snorbleframe rate>= 200000 nsrun960110422217125.0oka cycleSNB-1 Snorble Sensor Beacon Rev. C section 1, p.1: about 5 kframes/s at most

Protocol file and firmware

test/snorble.ml
open! Core
open Protocol_emulator
open Pin_trace
module Reg = Host_port.Reg

(* SNB-1 Snorble Sensor Beacon, Rev. C preliminary: section 4's timing (p.1) and notes 1-3
   (p.2). At 48 MHz: sync 384 cycles (8.0 us), a zero's low 58 (1.208 us), a one's 144
   (3.0 us), every high gap 96 (2.0 us), and 8448 idle cycles after the parity's rise, so
   frames are at least 214 us apart, within section 1's 5 kframes/s. *)

let pin = 5

let config =
  { Program_config.default with
    out_base = pin
  ; out_count = 1
  ; set_base = pin
  ; set_count = 1
  ; in_shift = Left
  ; out_shift = Left
  ; crc_width = 1
  ; crc_poly = 1
  ; crc_init = 1
  ; crc_reflect = false
  }
;;

(* Sends the low byte of each host word MSB first, then odd parity from the CRC; isr is
   built MSB-aligned for osr. p is 24 cycles (half a microsecond). The analyser only knows
   constants that [set] makes, so every width is built from adds of p and immediates. On
   entry to [bit], [t] is the next fall. *)
let firmware =
  [%firmware
    {|
    set pins, 1              ; idle high
    set p, 24
    mov t, now
    add t, 2                 ; a row only reset reaches, which the teeth can move
idle:
    set x, 31
gap:
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    wait t                   ; 32 waits of 264: idle 8448 since the parity's rise
    jmp x--, gap
    wait tx
    pull
    crc_init
    mov isr, null
    in osr, 8
    out null, 8
    out null, 1              ; through the CRC, unrolled: the certificate's induction
    out null, 1              ; cannot see a counted loop's bound across its passes
    out null, 1
    out null, 1
    out null, 1
    out null, 1
    out null, 1
    out null, 1
    in crc, 1
    in null, 7
    mov osr, isr
    mov t, now
    add t, 2
    wait t
    set pins, 0              ; sync
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p                 ; 384
    wait t
    set pins, 1
    add t, p
    add t, p
    add t, p
    add t, p                 ; 96: the gap
    set x, 8                 ; eight data bits and parity
bit:
    wait t
    set pins, 0
    add t, p
    add t, p
    add t, 7
    add t, 3                 ; 58: a zero
    out y, 1
    jmp y--, one
    jmp low
one:
    add t, p
    add t, p
    add t, p
    add t, 7
    add t, 7                 ; 144: a one
low:
    wait t
    set pins, 1
    add t, p
    add t, p
    add t, p
    add t, p                 ; 96: the gap
    jmp x--, bit
    jmp idle
|}
      ~config]
;;

let certified = [ Certified.of_firmware ~no_wrap:true "snorble" firmware ]
let bytes = [ 0xa5; 0x00; 0xff; 0x3c ]
let cycles_a_frame = 11_000

let bench =
  { Bench.name = "snorble"
  ; what =
      "Snorble.firmware: SIG on OUT0, sync 8.0 us, lows 1.208 and 3.0 us, gaps 2.0 us, \
       frames 214 us apart at least"
  ; source = Timed_program.source firmware
  ; config
  ; assumption = Nothing
  ; clock_hz = Bench.clock_hz
  ; load = None
  ; stimulus =
      Some
        { bursts = [ bytes ]
        ; quiet = 0
        ; cycles = (List.length bytes + 1) * cycles_a_frame
        }
  }
;;

(* A low longer than 5 us (between tL1's max and tSYN's min) is a sync, otherwise a bit; a
   bit longer than 2.1 us (between tL0's max and tL1's min) is a one. That is how a
   receiver tells them apart. The highs inside a frame are the ones between two bits,
   which note 1 bounds above. *)
let limits =
  let sheet page =
    { Datasheet.Sheet.part = "Snorble"
    ; document = "SNB-1 Snorble Sensor Beacon Rev. C"
    ; page
    }
  in
  let table = "section 4, p.1" in
  let sync ~clock_hz l = l >= Datasheet.cycles ~clock_hz 5_000. in
  let one ~clock_hz l = l >= Datasheet.cycles ~clock_hz 2_100. in
  let lows f =
    Datasheet.run ~pin:Datasheet.set_pin (fun ~clock_hz levels ->
      List.filter (Datasheet.lows levels) ~f:(f ~clock_hz))
  in
  let in_frame =
    Datasheet.run ~pin:Datasheet.set_pin (fun ~clock_hz levels ->
      List.filter_map
        (List.zip_exn
           (List.drop_last_exn (Datasheet.pairs levels))
           (List.drop (Datasheet.pairs levels) 1))
        ~f:(fun (((before, b), (high, h)), (_, (after, a))) ->
          Option.some_if
            ((not before)
             && high
             && (not after)
             && (not (sync ~clock_hz b))
             && not (sync ~clock_hz a))
            h))
  in
  let idle =
    Datasheet.run ~pin:Datasheet.set_pin (fun ~clock_hz levels ->
      List.filter_map (Datasheet.pairs levels) ~f:(fun ((high, h), (_, l)) ->
        Option.some_if (high && sync ~clock_hz l) h)
      |> Fn.flip List.drop 1)
  in
  (* sync fall to sync fall *)
  let frames =
    Datasheet.run ~pin:Datasheet.set_pin (fun ~clock_hz levels ->
      let _, starts =
        List.fold levels ~init:(0, []) ~f:(fun (at, starts) (high, n) ->
          at + n, if (not high) && sync ~clock_hz n then at :: starts else starts)
      in
      let starts = List.rev starts in
      List.map2_exn (List.drop_last_exn starts) (List.tl_exn starts) ~f:(fun a b -> b - a))
  in
  let limit parameter limit page bound =
    { Datasheet.firmware = "snorble"
    ; parameter
    ; limit
    ; sheet = sheet page
    ; margin = Cycle
    ; bound
    }
  in
  [ limit "tSYN" (At_least 7_500.) table (lows (fun ~clock_hz l -> sync ~clock_hz l))
  ; limit "tSYN" (At_most 8_500.) table (lows (fun ~clock_hz l -> sync ~clock_hz l))
  ; limit
      "tL0"
      (At_least 1_100.)
      table
      (Datasheet.level ~pin:Datasheet.set_pin ~high:false ())
  ; limit "tL0" (At_most 1_300.) table (lows (fun ~clock_hz l -> not (one ~clock_hz l)))
  ; limit
      "tL1"
      (At_least 2_900.)
      table
      (lows (fun ~clock_hz l -> one ~clock_hz l && not (sync ~clock_hz l)))
  ; limit
      "tL1"
      (At_most 3_100.)
      table
      (lows (fun ~clock_hz l -> one ~clock_hz l && not (sync ~clock_hz l)))
  ; limit
      "tH"
      (At_least 1_800.)
      table
      (Datasheet.level ~pin:Datasheet.set_pin ~high:true ())
  ; limit "tH" (At_most 4_000.) "section 4, p.1, and note 1, p.2: inside a frame" in_frame
  ; limit "tIFG" (At_least 20_000.) "section 4, p.1, and note 3, p.2" idle
  ; limit
      "frame rate"
      (At_least 200_000.)
      "section 1, p.1: about 5 kframes/s at most"
      frames
  ]
;;

(* Rebuilds Snorble frames from the pin's levels: a sync, nine lows (a low past 2.1 us is
   a one), then a high of at least 20 us. Gives the byte and whether its parity is odd. *)
let decode ~clock_hz (levels : (bool * int) list) =
  let sync n = n >= Datasheet.cycles ~clock_hz 5_000. in
  let rec frames acc = function
    | [] -> List.rev acc
    | (false, n) :: rest when sync n ->
      let lows =
        List.filter_map (List.take rest 18) ~f:(fun (high, n) ->
          Option.some_if (not high) n)
      in
      if List.length lows < 9
      then List.rev acc
      else (
        let bits =
          List.map lows ~f:(fun n -> Bool.to_int (n >= Datasheet.cycles ~clock_hz 2_100.))
        in
        let byte = List.fold (List.take bits 8) ~init:0 ~f:(fun b x -> (b lsl 1) lor x) in
        let odd = List.sum (module Int) bits ~f:Fn.id % 2 = 1 in
        frames ((byte, odd) :: acc) (List.drop rest 18))
    | _ :: rest -> frames acc rest
  in
  frames [] levels
;;

let sigrok =
  { Sigrok.clock_hz = 48_000_000
  ; decoders = [ Sigrok.decoder "snorble" ~pins:[ "sig", pin ] ]
  ; expect =
      [ ( "snorble=byte:parity-ok"
        , List.concat_map bytes ~f:(fun b -> [ sprintf "%02X" b; "Parity OK" ])
          |> Sigrok.lines "snorble" )
      ]
  ; joins_after = None
  ; rejected = None
  ; (* edges from 0, the rise out of reset: edge 4 ends the first bit's low, a one's 144
       cycles cut to a zero's 58 *)
    teeth = [ [ Shift { pin; edge = 4; cycles = -86 } ] ]
  }
;;

let scenario =
  { Scenario.name = "snorble"
  ; peer = (fun () -> Peer.idle 0)
  ; script =
      Scenario.load
        ~assumptions:(Certified.assumptions (List.hd_exn certified))
        ~config:(Timed_program.config firmware)
        ~program:(Timed_program.words firmware)
        ()
      @ [ Write (Reg.tx, bytes)
        ; Scenario.start
        ; Run ((List.length bytes + 1) * cycles_a_frame)
        ]
  ; sigrok = Some sigrok
  }
;;

let protocol =
  { Protocol.name = "snorble"
  ; certified
  ; time_triggered = []
  ; bench = [ bench ]
  ; loaded_from_hex = []
  ; limits
  ; unlimited = []
  ; swept = []
  ; not_swept = [ "snorble", "idles 8448 cycles a frame, past the sweep's window" ]
  ; scenarios = [ scenario ]
  ; decoded = []
  }
;;
certified firmware snorble
    set pins, 1              ; idle high
    set p, 24
    mov t, now
    add t, 2                 ; a row only reset reaches, which the teeth can move
idle:
    set x, 31
gap:
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    wait t                   ; 32 waits of 264: idle 8448 since the parity's rise
    jmp x--, gap
    wait tx
    pull
    crc_init
    mov isr, null
    in osr, 8
    out null, 8
    out null, 1              ; through the CRC, unrolled: the certificate's induction
    out null, 1              ; cannot see a counted loop's bound across its passes
    out null, 1
    out null, 1
    out null, 1
    out null, 1
    out null, 1
    out null, 1
    in crc, 1
    in null, 7
    mov osr, isr
    mov t, now
    add t, 2
    wait t
    set pins, 0              ; sync
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p                 ; 384
    wait t
    set pins, 1
    add t, p
    add t, p
    add t, p
    add t, p                 ; 96: the gap
    set x, 8                 ; eight data bits and parity
bit:
    wait t
    set pins, 0
    add t, p
    add t, p
    add t, 7
    add t, 3                 ; 58: a zero
    out y, 1
    jmp y--, one
    jmp low
one:
    add t, p
    add t, p
    add t, p
    add t, 7
    add t, 7                 ; 144: a one
low:
    wait t
    set pins, 1
    add t, p
    add t, p
    add t, p
    add t, p                 ; 96: the gap
    jmp x--, bit
    jmp idle
bench firmware snorble, 48 MHz
    set pins, 1              ; idle high
    set p, 24
    mov t, now
    add t, 2                 ; a row only reset reaches, which the teeth can move
idle:
    set x, 31
gap:
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    wait t                   ; 32 waits of 264: idle 8448 since the parity's rise
    jmp x--, gap
    wait tx
    pull
    crc_init
    mov isr, null
    in osr, 8
    out null, 8
    out null, 1              ; through the CRC, unrolled: the certificate's induction
    out null, 1              ; cannot see a counted loop's bound across its passes
    out null, 1
    out null, 1
    out null, 1
    out null, 1
    out null, 1
    out null, 1
    in crc, 1
    in null, 7
    mov osr, isr
    mov t, now
    add t, 2
    wait t
    set pins, 0              ; sync
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p
    add t, p                 ; 384
    wait t
    set pins, 1
    add t, p
    add t, p
    add t, p
    add t, p                 ; 96: the gap
    set x, 8                 ; eight data bits and parity
bit:
    wait t
    set pins, 0
    add t, p
    add t, p
    add t, 7
    add t, 3                 ; 58: a zero
    out y, 1
    jmp y--, one
    jmp low
one:
    add t, p
    add t, p
    add t, p
    add t, 7
    add t, 7                 ; 144: a one
low:
    wait t
    set pins, 1
    add t, p
    add t, p
    add t, p
    add t, p                 ; 96: the gap
    jmp x--, bit
    jmp idle

Certificate

Proof run stamped in demo/speed.tsv: 2026-10-18T22:37:42+01:00, induction failed 22:06 (17 min, an 8-pass loop past depth 20), PASS after unrolling.

Clock window

firmwareshipped Hzlowest Hzset byhighest Hzset by
snorble4800000046774194tL1 <= 3100 ns49310344tL1 >= 2900 ns

Time taken

stagetimenote
spec2026-10-18T21:11:14+01:00rehearsal 10-18, spec.pdf read with pdftotext; limits read twice and agreed 21:12:03
file2026-10-18T22:36:52+01:00first draft 21:38; parity loop unrolled and a reset-only row added for the certificate
certificate2026-10-18T22:37:42+01:00induction failed 22:06 (17 min, an 8-pass loop past depth 20), PASS after unrolling

spec to file: 85.6 min; spec to certificate: 86.5 min; spec to bench: -

Times are the first mark of each stage in demo/speed.tsv; a protocol nobody timed has no row.