protocol-emulator / all protocols

xy2_100

Drawn: picked from sigrok's decoders by drand round 33346612 (demo/corpus_draw_33346612.json). The drawn and held-out runs are on Flexibility.

Spec source

partdocumentpage
rhothor X7Newson XY2-100 I/O configuration, Rev. 0703Timing specifications table, p.2

Datasheet limits

firmwareparameterlimitbound byneeds (cycles)bound (cycles)bound (ns)resultmarginsheet
xy2_100tDS>= 50 nskernel412250.0oka cycleNewson XY2-100 I/O configuration, Rev. 0703 Timing specifications table, p.2
xy2_100tDH>= 100 nskernel612250.0oka cycleNewson XY2-100 I/O configuration, Rev. 0703 Timing specifications table, p.2

Protocol file and firmware

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

(* Newson rhothor X7 I/O configuration: XY2-100, datasheet revision 0703, p.1-2. A 20-bit
   word: C2-C0, then D15-D0, then even parity, at SENDCK 2 MHz (24 cycles of the 48 MHz
   clock, 12 per half). The host's word is the 16 data bits. The core sends control 001,
   the motor setpoint and the parity, which the CRC unit counts as a 1-bit CRC started at
   1 for the control's one. SENDCK runs on without a break; the last word repeats. *)
let clk_pin = 5
let sync_pin = clk_pin + 1
let data_pin = clk_pin + 2
let pin = clk_pin

(* The 20 bits on the wire for a setpoint, first bit highest. *)
let on_wire ~data =
  if data < 0 || data >= 1 lsl 16
  then raise_s [%message "BUG: data is 16 bits" (data : int)];
  let body = (1 lsl 16) lor data in
  (body lsl 1) lor (Int.popcount body land 1)
;;

let config =
  { Program_config.default with
    side_set_count = 2
  ; side_set_base = clk_pin
  ; out_base = data_pin
  ; out_count = 1
  ; set_base = data_pin
  ; set_count = 1
  ; out_shift = Left
  ; crc_width = 1
  ; crc_poly = 1
  ; crc_init = 1
  ; crc_reflect = false
  }
;;

(* Side-set is SENDCK in bit 0 and SYNC in bit 1. Data changes with each rise, and SYNC
   joins on the first bit and leaves on the last. *)
let firmware =
  [%firmware
    {|
    .side_set 2
    set p, 12 side 0
    wait tx side 0           ; the first setpoint starts SENDCK
    pull side 0
    mov t, now side 0        ; the only anchor
    add t, p side 0
frame:
    mov y, osr side 0        ; kept for the frame after, if the host has no word
    crc_init side 0
    set x, 15 side 0
    wait t+ side 0
    set pins, 0 side 3       ; C2, SYNC rises
    wait t+ side 3
    nop side 2
    wait t+ side 2
    set pins, 0 side 3       ; C1
    wait t+ side 3
    nop side 2
    wait t+ side 2
    set pins, 1 side 3       ; C0
    wait t+ side 3
    nop side 2
bit:
    wait t+ side 2
    out pins, 1 side 3       ; D15 first
    wait t+ side 3
    nop side 2
    jmp x--, bit
    in crc, 16 side 2        ; the parity so far
    wait t+ side 2
    mov pins, isr side 1     ; parity, SYNC falls
    wait t+ side 1
    nop side 0
    jmp tx, next
    mov osr, y side 0        ; the setpoint again
    jmp frame
next:
    pull side 0
    jmp frame
|}
      ~config]
;;

let certified = [ Certified.of_firmware "xy2_100" firmware ]

(* The copy python/bench_firmware.py holds for the bench: two setpoints in a run of two
   frames' time. *)
(* The bench's OUT1 reaches no analyser channel, so all three signals go to analyser B:
   SENDCK and SYNC on OUT3 and OUT4, DATA on OUT6. OUT5, the flash's clock, stays still,
   so the flash takes none of it for a command. *)
let bench =
  { Bench.name = "xy2_100"
  ; what =
      "Xy2_100.firmware: SENDCK at 2 MHz on OUT3, SYNC on OUT4 and DATA on OUT6, a \
       20-bit word every 10 us"
  ; source = Timed_program.source firmware
  ; config = { config with side_set_base = Bench.neopixel; out_base = 11; set_base = 11 }
  ; assumption = Nothing
  ; clock_hz = Bench.clock_hz
  ; load = None
  ; stimulus = Some { bursts = [ [ 0x8000; 0x1234 ] ]; quiet = 0; cycles = 1_200 }
  }
;;

(* DATA changes only in the instruction that raises SENDCK, and is read at its fall. The
   setup is the kernel's spacing from DATA's last change to the fall. The hold runs from
   the fall to the next change, which comes no sooner than the next rise: SENDCK's low
   time. *)
let limits =
  let sheet =
    { Datasheet.Sheet.part = "rhothor X7"
    ; document = "Newson XY2-100 I/O configuration, Rev. 0703"
    ; page = "Timing specifications table, p.2"
    }
  in
  let limit parameter ns bound =
    { Datasheet.firmware = bench.name
    ; parameter
    ; limit = At_least ns
    ; sheet
    ; margin = Cycle
    ; bound
    }
  in
  [ limit
      "tDS"
      50.
      (Datasheet.Bound.Kernel
         (fun config ->
           Datasheet.spacing
             ~apart:(fun ~own ~other:_ -> own)
             ~a:(Datasheet.side_pin config)
             ~b:config.out_base
             ()))
  ; limit "tDH" 100. (Datasheet.level ~pin:Datasheet.side_pin ~high:false ())
  ]
;;

(* The decoder has no timeout, so a frame is read once the next one begins: the last
   setpoint goes out again and is read twice. The positions are signed. *)
let setpoints = [ 0x8000, -32768; 0x0000, 0; 0xffff, -1; 0x1234, 4660 ]
let read = setpoints @ [ List.last_exn setpoints ]

let sigrok =
  { Sigrok.clock_hz = 48_000_000
  ; decoders =
      [ Sigrok.decoder
          "xy2-100"
          ~pins:[ "clk", clk_pin; "sync", sync_pin; "data", data_pin ]
      ]
  ; expect =
      [ ( "xy2-100=type:parity:position"
        , List.concat_map read ~f:(fun (_, position) ->
            [ "xy2-100-1: 16 bit Position Frame"
            ; "xy2-100-1: OK"
            ; sprintf "xy2-100-1: %d" position
            ]) )
      ]
  ; joins_after = None
  ; rejected = None
  ; (* C0 read as 0, then D15 read inverted: parity no longer matches. *)
    teeth =
      [ [ Flip { pin = data_pin; edge = 0; after = 0; cycles = 24 } ]
      ; [ Flip { pin = data_pin; edge = 0; after = 24; cycles = 24 } ]
      ]
  }
;;

(* The four setpoints back to back, then the last again as SENDCK runs on. *)
let scenario =
  { Scenario.name = "xy2_100"
  ; 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, List.map setpoints ~f:fst); Scenario.start; Run 2_800 ]
  ; sigrok = Some sigrok
  }
;;

let protocol =
  { Protocol.name = "xy2_100"
  ; certified
  ; time_triggered = []
  ; bench = [ bench ]
  ; loaded_from_hex = []
  ; limits
  ; unlimited = []
  ; swept = []
  ; not_swept =
      [ "xy2_100", "SENDCK edges 12 cycles apart without a break: the fifo holds 8" ]
  ; scenarios = [ scenario ]
  ; decoded = []
  }
;;
certified firmware xy2_100
    .side_set 2
    set p, 12 side 0
    wait tx side 0           ; the first setpoint starts SENDCK
    pull side 0
    mov t, now side 0        ; the only anchor
    add t, p side 0
frame:
    mov y, osr side 0        ; kept for the frame after, if the host has no word
    crc_init side 0
    set x, 15 side 0
    wait t+ side 0
    set pins, 0 side 3       ; C2, SYNC rises
    wait t+ side 3
    nop side 2
    wait t+ side 2
    set pins, 0 side 3       ; C1
    wait t+ side 3
    nop side 2
    wait t+ side 2
    set pins, 1 side 3       ; C0
    wait t+ side 3
    nop side 2
bit:
    wait t+ side 2
    out pins, 1 side 3       ; D15 first
    wait t+ side 3
    nop side 2
    jmp x--, bit
    in crc, 16 side 2        ; the parity so far
    wait t+ side 2
    mov pins, isr side 1     ; parity, SYNC falls
    wait t+ side 1
    nop side 0
    jmp tx, next
    mov osr, y side 0        ; the setpoint again
    jmp frame
next:
    pull side 0
    jmp frame
bench firmware xy2_100, 48 MHz
    .side_set 2
    set p, 12 side 0
    wait tx side 0           ; the first setpoint starts SENDCK
    pull side 0
    mov t, now side 0        ; the only anchor
    add t, p side 0
frame:
    mov y, osr side 0        ; kept for the frame after, if the host has no word
    crc_init side 0
    set x, 15 side 0
    wait t+ side 0
    set pins, 0 side 3       ; C2, SYNC rises
    wait t+ side 3
    nop side 2
    wait t+ side 2
    set pins, 0 side 3       ; C1
    wait t+ side 3
    nop side 2
    wait t+ side 2
    set pins, 1 side 3       ; C0
    wait t+ side 3
    nop side 2
bit:
    wait t+ side 2
    out pins, 1 side 3       ; D15 first
    wait t+ side 3
    nop side 2
    jmp x--, bit
    in crc, 16 side 2        ; the parity so far
    wait t+ side 2
    mov pins, isr side 1     ; parity, SYNC falls
    wait t+ side 1
    nop side 0
    jmp tx, next
    mov osr, y side 0        ; the setpoint again
    jmp frame
next:
    pull side 0
    jmp frame

Certificate

Proof run stamped in demo/speed.tsv: 2026-10-24T20:05:55+01:00, .

Clock window

firmwareshipped Hzlowest Hzset byhighest Hzset by
xy2_10048000000--110000000tDH >= 100 ns

Time taken

stagetimenote
spec2026-10-24T19:47:57+01:00new-protocol
file2026-10-24T20:05:40+01:00
certificate2026-10-24T20:05:55+01:00
bench2026-10-30T14:59:30+00:00board run, test/board/xy2_100

spec to file: 17.7 min; spec to certificate: 18.0 min; spec to bench: 5.8 days

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

Board witnesses

test/boardtimedemoresultcommitwindows provedteeth
xy2_1002026-11-03T07:58:03xy2_100PASSb938551d482 of 2 (2 spec)DATA inverted over the first D15; a DATA move put on the SENDCK fall after it

CI decodes each capture again and holds it to the bytes sent and the windows, each tooth refused: demo/witness.py check.