[back to the deck]

soundcard: an Intel HD Audio card, written in l8

Hardware: Enclustra Mercury+ KX2 (AMD Kintex-7 XC7K160T FPGA module) on the Enclustra Mercury+ PE1 base board, in a PC's PCIe x4 slot.

Source: what this page distributes is the Verilog exported by the l8 compiler (l8i --emit, comments stripped), with its constraints and Vivado flow -- the design as Vivado builds it. The l8 sources themselves are not published.

The second card of the House of cards. The Mercury+ KX2 on the PE1 in a PC's PCIe slot, seen as an Intel 82801I (ICH9) HD Audio controller (8086:293e rev 3, class 0403) with one output codec, driven by the inbox drivers: snd_hda_intel under Linux, HDAudBus / HdAudio under Windows 10. The controller -- CORB / RIRB, the stream descriptors with their buffer lists, the position buffer, MSI -- and the codec's verbs are written in l8.

Program a new KX2 + PE1 card

The hardware: an Enclustra Mercury+ KX2 module on a Mercury+ PE1 base board, a PC with a free PCIe x4 (or wider) slot, a Xilinx Platform Cable USB II (or a compatible JTAG cable) and Vivado's hardware server (hw_server, Vivado 2026.1 or later) on the machine the cable is plugged into -- the PC itself or another machine on the network.

1. The switches -- set them with the board UNPOWERED and no USB cable plugged in (the PE1's system controller reads CFG B when power first reaches the board). From the Mercury+ PE1 User Manual V08 (sections 5.2-5.5, 6.3) and the Mercury KX2 User Manual V08 (section 3.3):

switch position why
S1900 power slide PCIe (1-2) 12 V from the PC's slot
CFG A 1 (BOOT_MODE0) ON the FPGA boots from its QSPI flash
CFG A 2 (USB_PWR_EN#) OFF no power over USB -- required when the board is powered over PCIe
CFG A 3 (SDIO_SEL) OFF unused
CFG A 4 (PWR_ON#) ON the module powers up with the PC, no PWR button press
CFG B 1 (USB_ID) OFF
CFG B 2 (USB_SEL) OFF (B1 OFF + B2 ON is forbidden)
CFG B 3 (SCMODE0#) OFF ON turns the system controller into a JTAG programmer on the same lines and blocks the external cable
CFG B 4 (SCMODE1#) OFF
USER 1..4 (S1101) any not read by these designs
J2000 jumpers 9-10 and 3-4

2. Into the PC: the card in a PCIe x4 (or wider) slot; the JTAG cable on the PE1's header J1700 (the module's own USB JTAG did not find the device in our tests), its USB end at the machine running hw_server.

3. Power the PC on. A blank card does not show up on the PCIe bus yet -- that is fine.

The soundcard has no flash baseline yet. The archive carries a demo image, images/soundcard_kx2_avb_g2 (the card with RTP, AVB and gPTP on Eth1; images/IMAGES.md), as a bitstream and as a flash file. On the board it was verified loaded over JTAG into the running PC; booting it from the flash at power-on has not been tested on the board yet (the same switch settings boot the network card's baselines from the flash).

4. Write the demo image into the flash (from the unpacked archive, on the machine with Vivado):

sh scripts/flash_baseline.sh avb_g2                    # [host:port] for an hw_server on another machine
sh scripts/flash_baseline.sh --dry-run avb_g2          # only check the files, print the Vivado command

It checks images/SHA256SUMS (nothing is written on a mismatch), saves the flash's first 8 MB to flash_backup/, then erases, programs, verifies and boots the FPGA from the flash.

5. Power the PC OFF and on again (a full power cycle). Linux: lspci -nn -k -d 8086:293e shows the HD Audio controller with snd_hda_intel. If it does not appear, use the way that is verified:

The verified way: a volatile JTAG load while Linux runs. Remove the card's PCI device, load, rescan (as root on the PC; the load on the machine with the cable):

echo 1 > /sys/bus/pci/devices/<BDF>/remove             # <BDF> from lspci -D -d 8086:293e, e.g. 0000:01:00.0
sh scripts/jtag_load.sh images/soundcard_kx2_avb_g2.bit
echo 1 > /sys/bus/pci/rescan

A warm reboot keeps the loaded image, a power cycle loses it (then the flash boots again). On a blank card the first lspci shows nothing to remove: load, then rescan.

6. The demo -- RTP to ffplay, AVB with Hive, gPTP with a software peer: docs/DEMO.md.

The system: RTP / AVB data, control, time and debug paths

How the card, its RTP output and its debug facility meet the network and the laptop: DATA blue, CONTROL orange, TIME green, DEBUG purple; a solid line is built (in simulation or a routed image), a dashed one planned. The RTP stream to the laptop runs on the board today; PTP, the loop back and AVB (with the Hive AVDECC controller) are planned.

The soundcard system: the PC, the card's HDA function, RTP chain, time base and debug facility, the switch or a direct cable, and the laptop's tools

The card inside

What the FPGA holds in the RTP image: the PCIe hard block and the clock crossings into the 200 MHz card clock, the shell, the HD Audio function (CORB / RIRB for the codec verbs, stream DMA over the buffer descriptor list, codec 0 analog 5.1, codec 1 HDMI with its ELD), the PCM lanes to the I2S back end and the three PCM5102A modules, and the audio-over-IP path (pcm_pack, rtp_tx, rtp_node, the link tee on Eth1); the debug facility beside it only looks.

The soundcard inside: PCIe, crossings, shell, the HD Audio function, I2S, the RTP path on Eth1, and the debug facility

Fine phase (DDMTD) on the PE1

How can a board tell how far apart two clocks are, to picoseconds? This is the trick at the heart of White Rabbit (CERN's sub-nanosecond extension of PTP): sample both clocks with a helper clock that runs slightly slower, f x N / (N + 1). Each sample lands a little later on the wave, so each clock turns into a slow square wave, the beat, N + 1 times stretched; the distance between the two beats' edges, counted in helper ticks, is the clocks' phase difference in steps of T / N. At 125 MHz with N = 511 one step is 8 ns / 511 = 15.7 ps; on the soundcard's 100 Mbit link (25 MHz, N = 320) it is 125 ps. The FPGA makes the helper itself, in an MMCM, from the board's crystal; a PI loop then steers a clock (the MMCM's fine phase shift, or the PE1's Si5338B) until the phases agree.

The whole chapter, step by step for a newcomer, with eight diagrams: Fine phase (DDMTD) on the PE1.

The whole picture on the PE1: the KX2 crystal and MMCMs, the Si5338B, the two KSZ9031 PHYs, the DDMTD, the loop, the time base

Status: the blocks (the DDMTD, the PI loop, the trims, the reference choice with holdover, the WR link model and state machine, the phase-exact time stamps) are built and tested in simulation; the card's RTP image takes them as the option WR=1 (the loop on Eth1's received clock), not yet run on the board.

Next: two independent WR nodes in one FPGA prove the synchronization (planned). A real WR link has two nodes -- two boards, or a board and a WR switch. Without a second board, the sync demo puts both on one PE1: node A on the Si5338B's own oscillator, node B on the KX2's crystal, joined by a loopback cable from Eth0 to Eth1; B locking to A, with the offset and its spread read from the card, is the proof. The chapter's section 8 has the setup, the steps and the numbers to expect.

Two boards, one WR node each, against one board running both nodes over a loopback cable

On the road: AVB / Milan and Hive

Today the card streams its audio as RTP (AES67-style) to a laptop, which plays it with ffplay. Next, the same card becomes an AVB / Milan talker, so standard AVB tools see it and route it:

  1. AVB-lite: the audio as IEEE 1722 AVTP AAF frames, and an AVDECC entity (discovery, the entity model as a fixed descriptor tree, connection management) -- enough for the open Hive AVDECC controller to find the card, show its stream and connect it, over an ordinary switch.
  2. gPTP (IEEE 802.1AS): the common time base AVB listeners lock to (a direct cable or an AVB switch).
  3. Full Milan (the AVnu profile): stream reservation (MSRP / MVRP), the credit-based shaper, Milan's descriptors and commands -- so a Milan listener behind an AVB switch plays the card's stream, set up from Hive or RME's AVB Tool.

Everything is built as reusable units (AVTP, AVDECC, the descriptor generator, PTP / gPTP, the media clock), shared with the RTP path.

Step 1 runs on the board. The open Hive controller (built from source) finds the card on an ordinary switch, reads its whole entity model -- with no compatibility warning -- and shows it as IEEE 1722.1:

Hive's Discovered Entities: "l8 soundcard", IEEE 1722.1, and its entity model: configuration "Default", the audio unit, the stream output "l8 Out", the CRF stream input and the AVB interface "Eth1"

While the PC plays a test pattern into the card, the laptop receives the AAF stream bit for bit (30 s: 239,730 frames, none lost, no discontinuity).

Connected from Hive. A software AVB listener on the laptop ("l8 laptop listener", a small entity with one AAF input, raw Ethernet through a tiny helper that keeps only the raw-socket right) shows up in Hive next to the card; clicking the matrix cell connects the card's "l8 Out" to the listener's "AAF In" with the standard ACMP exchange (Hive -> listener -> card -> listener -> Hive), and the audio arrives at the laptop:

Hive: both entities with the card as gPTP grandmaster (domain 0); stream matrix: talker "l8 soundcard" / "l8 Out" connected (green) to listener "l8 laptop listener" / "AAF In"

Through that connection the laptop's listener writes the stream bit for bit: a 25-second test pattern, 1,199,976 frames in a row, none lost, none dropped by the kernel (the listener reads through a 16 MiB receive ring).

Step 2, gPTP, runs on the board too. The card runs IEEE 802.1AS with hardware time stamps at its Ethernet PHY: peer delay, Announce and best-master selection, Sync / Follow_Up as grandmaster or slave, and the AAF presentation time from gPTP time. On the laptop a small software gPTP peer (no hardware stamps needed) answers the card's peer-delay requests and follows its Sync. Result on the board: the card treats the laptop as its gPTP neighbour (asCapable), is the grandmaster and sends 8 Sync a second; the laptop sees the card's grandmaster identity and path and measures the card's clock rate against its own to a few ppm. The standard's link-delay limit is 800 ns, which a software-stamped laptop behind a switch cannot meet (it measures about 0.1--0.2 ms); the card makes the limit a register -- 800 ns by default, as 802.1AS and Milan want, raised only for such a lab peer. A real Milan listener (hardware stamps) needs no change.

In Hive, on one time base. The card's AVDECC announcement advertises gPTP, and the laptop's listener advertises the grandmaster its software gPTP follows -- so Hive shows the same Grandmaster ID and gPTP domain for both and draws the connection green ("connected and no detectable error"; with different time bases Hive marks it red: no audio can flow). The screenshot above is that state: both rows with the card as grandmaster, domain 0, the stream connected, the test pattern arriving bit for bit (1,199,957 frames, none lost).

Next: Milan (step 3).

Status

Linux (snd_hda_intel) plays: ALSA "HDA Intel", codec "QEMU Generic"; speaker-test done; the card's counters: 287952 frames played, 0 underruns, CORB verbs = RIRB responses (442), 9442 MSI
Windows 10 (inbox HDAudBus / HdAudio) plays: controller Status OK, "High Definition Audio Device", no driver install; YouTube in the browser through it: ~964 k frames in 20 s at 48 kHz, 0 underruns
heard not yet: the counters say the samples were taken in time; no D/A board was connected (three PCM5102A modules on J1401: docs/connect_PCM5102.md)
over Ethernet RTP: the card's PCM to a laptop (ffplay), 10 minutes bit for bit; AVB: Hive finds and connects the card, the stream arrives bit for bit; gPTP: the card is grandmaster to a software peer
image no flash baseline yet; a demo image for the AVB / gPTP demo (images/, WNS +0.034 ns at 200 MHz): verified on the board loaded over JTAG, its flash file not yet booted on the board; the design as Verilog; make bit builds it

The Linux and Windows runs above were with the card's debug image (the same card plus the debug link on Eth1; routed at 200 MHz, WNS +0.059 ns, a quick build), the RTP run with the card's RTP image, the AVB and gPTP runs with the AVB images -- the last of them, build_avb_g2, is the archive's demo image -- all loaded over JTAG into the running PC. The board log: docs/BOARD_TEST.md; the demo step by step: docs/DEMO.md.

Download: l8soundcard-dist.tar.gz (4.3M): the design as Verilog with its constraints and Vivado flow, the AVB / gPTP demo image with the scripts to load or flash it, the demo's laptop software (RTP, the AVB listener, gPTP) and its guide docs/DEMO.md, the HOWTO, the board log, the D/A wiring.

tar xzf l8soundcard-dist.tar.gz && cd l8soundcard
make bit              # Vivado: verilog/avb_g2/top.bit (the demo image; NAME=hda: the plain HDA card)

How to

make bit [NAME=avb_g2|hda] builds verilog/<name>/top.bit (Vivado 2026.1 or later, XC7K160T; vivado on the PATH): avb_g2 is the shipped demo image's own design (its bitstream equals images/soundcard_kx2_avb_g2.bit), hda the plain HD Audio card. The card boots in two stages (the PCIe core's Tandem PROM: the link answers the PC from a small first stage while the rest loads), so it goes into the QSPI flash: write an .mcs of it (write_cfgmem -format mcs -size 64 -interface SPIx4 -loadbit "up 0x0 top.bit"), then make flash IMAGE=verilog/<name>/top with the .mcs beside it. The board settings and the steps in the PC are docs/HOWTO.md; the wiring of the D/A modules docs/connect_PCM5102.md.

the three PCM5102A modules on J1401

What is in the archive

path what
verilog/avb_g2/ the demo image's design as Verilog (emitted by the l8 compiler, comments stripped): top.v (the board), soundcard_kx2_avb.v (the card: HDA + RTP + AVB + gPTP), top.xdc, top.tcl (the Vivado flow), pcie7x.cfg, Makefile -- make bit rebuilds images/soundcard_kx2_avb_g2.bit
verilog/hda/ the plain HD Audio card the same way (soundcard_kx2.v) -- make bit NAME=hda
images/ the demo image soundcard_kx2_avb_g2: .bit (JTAG), .mcs / .prm (the flash), SHA256SUMS, IMAGES.md -- a test image, not a flash baseline
scripts/ jtag_load.sh (a bitstream over JTAG, volatile), flash_baseline.sh (an image into the flash: checksums, the flash's first 8 MB saved, program, verify, boot; --dry-run), and the Vivado scripts they run: jtag_prog.tcl, flash_kx2.tcl
host/ the demo's laptop software (docs/DEMO.md): l8/communication/rtp/host (rtp_sdp.py, rtp_sink.py, rtp_reg.py), l8/communication/avb/host (the AVB listener listener.sh / avb_listener.py, avdecc_ctl.py, avb_reg.py, pattern_wav.py, wav_match.py, the raw L2 helper's source rawsock/l2bridge.c), l8/communication/ptp/host (gptp_soft.py, gptp_check.py) -- Python 3, standard library only; host_check.sh (Linux: the card, its driver, a play), l8/bus/pcie/host/pcie_dbg.py with l8net (the debug image's words, --fn sc, and its TLP trace with HD Audio by register name, --trace --regs hda; the card in verilog/ has no debug link)
docs/ DEMO.md (the RTP / AVB / gPTP demo: the image, the mixer, ffplay, Hive built from source, the listener, the bit-exact check, the software gPTP peer), HOWTO.md (the finished sections), BOARD_TEST.md (the board log), connect_PCM5102.md and its figures, soundcard_card.svg (the card inside), finephase.md (the fine-phase chapter) with its figures fp_*.svg

The design's l8 sources are not in the archive; the Verilog is the design as Vivado builds it. Addresses such as 192.168.1.x in the documents are the lab's, examples only.

[back to the deck]