protocol-emulator / all protocols
Held out: sealed in test/heldout.sha256 on 2026-10-02 and opened on 2026-11-02 (test/heldout.txt). The drawn and held-out runs are on Flexibility.
| part | document | page |
|---|---|---|
| DMX512 | Wikipedia, DMX512, oldid 1380777110 | page 1, line 291 |
| DMX512 | Wikipedia, DMX512, oldid 1380777110 | page 1, line 301 |
| DMX512 | Wikipedia, DMX512, oldid 1380777110 | page 1, line 312 |
| DMX512 | Wikipedia, DMX512, oldid 1380777110 | page 1, line 313 |
| DMX512 | Wikipedia, DMX512, oldid 1380777110 | page 1, table, lines 303, 308-309 |
| DMX512 | Wikipedia, DMX512, oldid 1380777110 | page 1, table, lines 303-306 |
| DMX512 | Wikipedia, DMX512, oldid 1380777110 | page 1, table, lines 304, 308, 310 |
| DMX512 | Wikipedia, DMX512, oldid 1380777110 | page 1, table, lines 304-305, 307 |
| firmware | parameter | limit | bound by | needs (cycles) | bound (cycles) | bound (ns) | result | margin | sheet |
|---|---|---|---|---|---|---|---|---|---|
| dmx512 | bit at 250 kbit/s, shortest low | >= 4000 ns | kernel | 192 | 192 | 4000.0 | ok | 0 ns, the rate has no tolerance: a bit is 192 cycles at 48 MHz | Wikipedia, DMX512, oldid 1380777110 page 1, line 291 |
| dmx512 | bit at 250 kbit/s, shortest high | >= 4000 ns | kernel | 192 | 192 | 4000.0 | ok | 0 ns, the rate has no tolerance: a bit is 192 cycles at 48 MHz | Wikipedia, DMX512, oldid 1380777110 page 1, line 291 |
| dmx512 | bit at 250 kbit/s, longest channel low | <= 4000 ns | run | 192 | 192 | 4000.0 | ok | 0 ns, the rate has no tolerance: a bit is 192 cycles at 48 MHz | Wikipedia, DMX512, oldid 1380777110 page 1, line 291 |
| dmx512 | BREAK transmitted | >= 92000 ns | run | 4417 | 4800 | 100000.0 | ok | a cycle | Wikipedia, DMX512, oldid 1380777110 page 1, table, lines 303-306 |
| dmx512 | BREAK receiver recognized | >= 88000 ns | run | 4225 | 4800 | 100000.0 | ok | a cycle | Wikipedia, DMX512, oldid 1380777110 page 1, table, lines 303, 308-309 |
| dmx512 | MAB transmitted | >= 12000 ns | run | 577 | 768 | 16000.0 | ok | a cycle | Wikipedia, DMX512, oldid 1380777110 page 1, table, lines 304-305, 307 |
| dmx512 | MAB receiver recognized | >= 8000 ns | run | 385 | 768 | 16000.0 | ok | a cycle | Wikipedia, DMX512, oldid 1380777110 page 1, table, lines 304, 308, 310 |
| dmx512 | MAB since 1990 | >= 8000 ns | run | 385 | 768 | 16000.0 | ok | a cycle | Wikipedia, DMX512, oldid 1380777110 page 1, line 301 |
| dmx512 | break to break transmitted | >= 1.204e+06 ns | run | 57793 | 1092101 | 22752104.2 | ok | a cycle | Wikipedia, DMX512, oldid 1380777110 page 1, line 313 |
| dmx512 | break to break receivers handle | >= 1.196e+06 ns | run | 57409 | 1092101 | 22752104.2 | ok | a cycle | Wikipedia, DMX512, oldid 1380777110 page 1, line 313 |
| dmx512 | refresh rate of 512 channels, at most 44 Hz | >= 2.27273e+07 ns | run | 1090911 | 1092101 | 22752104.2 | ok | a cycle | Wikipedia, DMX512, oldid 1380777110 page 1, line 312 |
open! Core
open Protocol_emulator
open Pin_trace
module Reg = Host_port.Reg
(* DMX512, Wikipedia oldid 1380777110, one page; numbers are its line numbers. 250 kbit/s;
a slot is a start bit, 8 bits LSB first and two stop bits (line 291). A packet is a
break, a mark after break, the start code and 512 channels (lines 292-297); the timing
table is at lines 303-310. Bits are 192 cycles at 48 MHz. *)
let pin = 5
(* The bit at 48 MHz, which the host loads first: [set] reaches only 31. *)
let period = 48_000_000 / 250_000
let config =
{ Program_config.default with
out_base = pin
; out_count = 1
; set_base = pin
; set_count = 1
}
;;
(* The bit's cycles once, then per packet a host word with the start code in its low byte,
then 256 words of two channels, low byte first. Break is 25 bits (100 us), mark after
break 4 (16 us). A late word stretches the mark before a channel's start bit, which the
spec leaves free (line 311). *)
let firmware =
[%firmware
{|
set pins, 1 ; mark while idle
wait tx ; the bit in cycles
pull
mov p, osr
packet:
wait tx ; the start code's word
pull
mov t, now
set pins, 0 ; break
add t, p
set x, 23
break:
wait t+
jmp x--, break
wait t+
set pins, 1 ; mark after break
wait t+
wait t+
wait t+
wait t+
set pins, 0 ; the start code's start bit
set x, 7
code:
wait t+
out pins, 1
jmp x--, code
wait t+
set pins, 1 ; two stop bits
out null, 8 ; the word's high byte is not sent
set y, 16
add y, y
add y, y
add y, y
add y, y
add y, y
sub y, 1 ; 512 channels
wait t+
wait t
channel:
jmp !osre, slot ; the word's second channel
wait tx
pull
slot:
mov t, now
set pins, 0 ; start bit
add t, p
set x, 7
bit:
wait t+
out pins, 1
jmp x--, bit
wait t+
set pins, 1 ; two stop bits
wait t+
wait t
jmp y--, channel
jmp packet
|}
~config
~period]
;;
(* [wait tx] can hold the core indefinitely, far behind its last deadline *)
let certified = [ Certified.of_firmware ~no_wrap:true "dmx512" firmware ]
(* the start code, then the 512 channels two a word, low byte first *)
let packet ~start_code channels =
let rec pairs = function
| lo :: hi :: rest -> (lo lor (hi lsl 8)) :: pairs rest
| _ -> []
in
if List.length channels <> 512
then raise_s [%message "BUG: a packet has 512 channels" (List.length channels : int)];
start_code :: pairs channels
;;
let channels = List.init 512 ~f:(fun n -> ((n * 37) + 11) land 0xff)
(* The copy python/bench_firmware.py holds: a packet of channels 0x55, every low a bit,
and the next packet's break. *)
let bench =
{ Bench.name = "dmx512"
; what =
[%string
"Dmx512.firmware: the host sends the bit, %{period#Int} cycles for 250 kbit/s, \
then a packet of 512 channels on OUT0 and the next packet's break"]
; source = Timed_program.source firmware
; config
; assumption = Period period
; clock_hz = Bench.clock_hz
; load = Some period
; stimulus =
Some
{ bursts =
[ packet ~start_code:0x00 (List.init 512 ~f:(Fn.const 0x55)) @ [ 0x00 ] ]
; quiet = 0
; cycles = 1_110_000
}
}
;;
(* Bits of the line in the run. No slot is low longer than a start bit plus eight zeros,
so a longer low is a break. A low short enough to pass for a slot leaves no break, so
the row has no bound. Packet time, about 23 ms (line 312), is typical, so no row. *)
let limits =
let sheet line =
{ Datasheet.Sheet.part = "DMX512"
; document = "Wikipedia, DMX512, oldid 1380777110"
; page = [%string "page 1, %{line}"]
}
in
let is_break ~clock_hz n = n * 250_000 > 10 * clock_hz in
let breaks ~clock_hz levels =
List.filter (Datasheet.lows levels) ~f:(is_break ~clock_hz)
in
let marks_after_break ~clock_hz levels =
List.filter_map (Datasheet.pairs levels) ~f:(fun ((high, n), (_, mark)) ->
Option.some_if ((not high) && is_break ~clock_hz n) mark)
in
let break_to_break ~clock_hz levels =
let starts =
List.folding_map levels ~init:0 ~f:(fun at (high, n) ->
at + n, Option.some_if ((not high) && is_break ~clock_hz n) at)
|> List.filter_opt
in
List.map2_exn (List.drop_last_exn starts) (List.tl_exn starts) ~f:(fun a b -> b - a)
in
(* the lows of the channels, each one bit of 0x55; a start code is not one *)
let channel_lows ~clock_hz levels =
List.folding_map levels ~init:false ~f:(fun after_code (high, n) ->
match high with
| true -> after_code, None
| false when is_break ~clock_hz n -> false, None
| false -> true, Option.some_if after_code n)
|> List.filter_opt
in
let row ?(margin = Datasheet.Margin.Cycle) parameter ~line limit bound =
{ Datasheet.firmware = bench.name
; parameter
; limit
; sheet = sheet line
; margin
; bound
}
in
let run widths = Datasheet.run ~pin:Datasheet.set_pin widths in
let exact =
Datasheet.Margin.Ns
{ ns = 0.; why = "the rate has no tolerance: a bit is 192 cycles at 48 MHz" }
in
[ row
"bit at 250 kbit/s, shortest low"
~line:"line 291"
~margin:exact
(At_least 4_000.)
(Datasheet.level ~pin:Datasheet.set_pin ~high:false ())
; row
"bit at 250 kbit/s, shortest high"
~line:"line 291"
~margin:exact
(At_least 4_000.)
(Datasheet.level ~pin:Datasheet.set_pin ~high:true ())
; row
"bit at 250 kbit/s, longest channel low"
~line:"line 291"
~margin:exact
(At_most 4_000.)
(run channel_lows)
; row "BREAK transmitted" ~line:"table, lines 303-306" (At_least 92_000.) (run breaks)
; row
"BREAK receiver recognized"
~line:"table, lines 303, 308-309"
(At_least 88_000.)
(run breaks)
; row
"MAB transmitted"
~line:"table, lines 304-305, 307"
(At_least 12_000.)
(run marks_after_break)
; row
"MAB receiver recognized"
~line:"table, lines 304, 308, 310"
(At_least 8_000.)
(run marks_after_break)
; row "MAB since 1990" ~line:"line 301" (At_least 8_000.) (run marks_after_break)
; row
"break to break transmitted"
~line:"line 313"
(At_least 1_204_000.)
(run break_to_break)
; row
"break to break receivers handle"
~line:"line 313"
(At_least 1_196_000.)
(run break_to_break)
; row
"refresh rate of 512 channels, at most 44 Hz"
~line:"line 312"
(At_least (1e9 /. 44.))
(run break_to_break)
]
;;
(* What sigrok's dmx512 decoder reads of the packet. The line is low from reset until the
firmware starts, longer than a break, so the decoder only joins once the line has idled
high (from reset it would read that low as a break). The teeth cut the break to 83 us,
under the 88 a receiver recognises, and flip channel 1's first bit. *)
let sigrok =
let line = sprintf "dmx512-1: %s" in
let byte b = line (sprintf "%d / 0x%x" b b) in
let opening = [ line "Break"; line "MAB"; line "Start code"; byte 0x00 ] in
{ Sigrok.clock_hz = 48_000_000
; decoders = [ Sigrok.decoder "dmx512" ~pins:[ "dmx", pin ] ]
; expect =
[ ( "dmx512=break:mab:startcode:channel:interpacket:data"
, opening
@ List.concat_mapi channels ~f:(fun n b ->
[ line (sprintf "Channel %d" (n + 1)); byte b ])
@ (line "Interpacket" :: opening) )
]
; joins_after =
Some
( 1_000
, { why =
"the line is low from reset until the firmware starts, which sigrok takes \
for a break and reads the real one as the start code, framing the \
channels on the wrong edges"
; first_difference = 5
; reads = "dmx512-1: 7 / 0x7"
} )
; rejected = None
; teeth =
[ [ Shift { pin; edge = 2; cycles = -(4 * period) } ]
; [ Flip { pin; edge = 5; after = period; cycles = period } ]
]
}
;;
(* The host writes eight words, then waits out the bits they take: 194 for the first with
the break, 176 for the rest, and a few more. The mark stretches before every eighth
word. Then the next packet's start code. *)
let scenario =
let words = packet ~start_code:0x00 channels @ [ 0x00 ] in
let writes =
List.chunks_of words ~length:8
|> List.concat_mapi ~f:(fun n chunk ->
[ Step.Write (Reg.tx, chunk); Run ((if n = 0 then 200 else 180) * period) ])
in
{ Scenario.name = "dmx512"
; 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)
()
@ [ Step.Write (Reg.tx, [ period ]); Scenario.start; Run 2_000 ]
@ writes
; sigrok = Some sigrok
}
;;
let protocol =
{ Protocol.name = "dmx512"
; certified
; time_triggered = []
; bench = [ bench ]
; loaded_from_hex = []
; limits
; unlimited = []
; swept = []
; not_swept =
[ "dmx512", "a packet is 1092101 cycles, past the 65536 a stamp tells apart" ]
; scenarios = [ scenario ]
; decoded = []
}
;;
set pins, 1 ; mark while idle
wait tx ; the bit in cycles
pull
mov p, osr
packet:
wait tx ; the start code's word
pull
mov t, now
set pins, 0 ; break
add t, p
set x, 23
break:
wait t+
jmp x--, break
wait t+
set pins, 1 ; mark after break
wait t+
wait t+
wait t+
wait t+
set pins, 0 ; the start code's start bit
set x, 7
code:
wait t+
out pins, 1
jmp x--, code
wait t+
set pins, 1 ; two stop bits
out null, 8 ; the word's high byte is not sent
set y, 16
add y, y
add y, y
add y, y
add y, y
add y, y
sub y, 1 ; 512 channels
wait t+
wait t
channel:
jmp !osre, slot ; the word's second channel
wait tx
pull
slot:
mov t, now
set pins, 0 ; start bit
add t, p
set x, 7
bit:
wait t+
out pins, 1
jmp x--, bit
wait t+
set pins, 1 ; two stop bits
wait t+
wait t
jmp y--, channel
jmp packet
set pins, 1 ; mark while idle
wait tx ; the bit in cycles
pull
mov p, osr
packet:
wait tx ; the start code's word
pull
mov t, now
set pins, 0 ; break
add t, p
set x, 23
break:
wait t+
jmp x--, break
wait t+
set pins, 1 ; mark after break
wait t+
wait t+
wait t+
wait t+
set pins, 0 ; the start code's start bit
set x, 7
code:
wait t+
out pins, 1
jmp x--, code
wait t+
set pins, 1 ; two stop bits
out null, 8 ; the word's high byte is not sent
set y, 16
add y, y
add y, y
add y, y
add y, y
add y, y
sub y, 1 ; 512 channels
wait t+
wait t
channel:
jmp !osre, slot ; the word's second channel
wait tx
pull
slot:
mov t, now
set pins, 0 ; start bit
add t, p
set x, 7
bit:
wait t+
out pins, 1
jmp x--, bit
wait t+
set pins, 1 ; two stop bits
wait t+
wait t
jmp y--, channel
jmp packet
dmx512: proved in CI by inductive_certificate, ocaml.yamlProof run stamped in demo/speed.tsv: 2026-11-02T18:54:52+00:00, .
| firmware | shipped Hz | lowest Hz | set by | highest Hz | set by |
|---|---|---|---|---|---|
| dmx512 | 48000000 | 48000000 | bit at 250 kbit/s, longest channel low <= 4000 ns | 48000000 | bit at 250 kbit/s, shortest low >= 4000 ns |
| stage | time | note |
|---|---|---|
| spec | 2026-11-02T18:13:40+00:00 | new-protocol |
| file | 2026-11-02T18:37:26+00:00 | |
| certificate | 2026-11-02T18:54:52+00:00 |
spec to file: 23.8 min; spec to certificate: 41.2 min; spec to bench: -
Times are the first mark of each stage in demo/speed.tsv; a protocol nobody timed has no row.
| test/board | time | demo | result | commit | windows proved | teeth |
|---|---|---|---|---|---|---|
| dmx512 | 2026-11-18T14:53:37 | dmx512 | PASS | 5160bcb3c7 | 10 of 12 (8 spec, 2 own) | half of the first packet's channel 1 bit 0 inverted; the first break 10 us short |
CI decodes each capture again and holds it to the bytes sent and the windows, each tooth refused: demo/witness.py check.