From 91e29248273b64a0d662d78ffb8d42bedfd04622 Mon Sep 17 00:00:00 2001 From: Dmitrii Vasilev Date: Mon, 26 Oct 2026 08:34:24 +0700 Subject: [PATCH] fpga: AX7203 board top for the WASM cell, paid by deleting the ported link_node.v (Refs #12456) The one hand-written Verilog file of milestone B: fpga/verilog/wasm_board_ax7203_top.v (34 lines) wraps the generated cell fpga_wasm_board for the ALINX AX7203 (xc7a200tfbg484-2). Ports exactly rst_n, led[3:0], uart_rx, uart_tx (the pinned XDC: T6 / B13 C13 D14 D15 / P20 / N15); the clock is STARTUPE2 CFGMCLK through a BUFG, no board clock pin; two-flop reset and UART synchronisers; the cell runs with en high, rxd is {7'b0, uart_rx}, uart_tx is txd[0], the read-back outputs stay open (FR-001, FR-002). The payment under the foreign-budget rule, in the same commit because the pre-commit hook counts each commit's staged diff on its own: fpga/verilog/link_node.v (132 hand-written lines) is deleted; it was ported to specs/port/fpga/verilog/link_node.t27 and nothing but docs/now prose named it. The gate of the fpga-synth-ax7203 job also fires when the top changes (one regex line in .github/workflows/fpga-build.yml). Owner's approval, 2026-10-25, Claude Code session (translated from Russian): "Yes, write the board top wasm_board_ax7203_top.v for #12456 (up to 40 lines, under owner-approved-foreign, paid by deletions) through a Sonnet subagent on top of #12457, show the frames every run." The exception-list entry is #12483. Lint: yosys read_verilog -lib of cells_sim.v + cells_xtra.v and of the generated cell, hierarchy -check, check -assert: clean, one float-parameter warning on SIM_CCLK_FREQ. gen-verilog cannot instantiate primitives yet (specs/fpga/die_probe.t27), so the top stays foreign until that gap closes; the place-and-route steps of the job (FR-003 to FR-006) follow after #12457 lands. Refs #12411 Refs #9367 Refs #12387 Refs #6198 Co-Authored-By: Claude Fable 5.1 --- .github/workflows/fpga-build.yml | 2 +- fpga/verilog/link_node.v | 132 --------------------------- fpga/verilog/wasm_board_ax7203_top.v | 34 +++++++ 3 files changed, 35 insertions(+), 133 deletions(-) delete mode 100644 fpga/verilog/link_node.v create mode 100644 fpga/verilog/wasm_board_ax7203_top.v diff --git a/.github/workflows/fpga-build.yml b/.github/workflows/fpga-build.yml index 3e3f0f9b26..b24f43f4e8 100644 --- a/.github/workflows/fpga-build.yml +++ b/.github/workflows/fpga-build.yml @@ -647,7 +647,7 @@ jobs: with: { fetch-depth: 0 } - id: gate env: { B: "${{ github.base_ref && format('origin/{0}', github.base_ref) || github.event.before }}" } - run: git diff --name-only "$B...HEAD" | grep -qE '^(specs/fpga/wasm_(board_ax7203|opcodes)\.t27|\.github/workflows/fpga-build\.yml)$' && echo run=true >> "$GITHUB_OUTPUT" || echo run=false >> "$GITHUB_OUTPUT" + run: git diff --name-only "$B...HEAD" | grep -qE '^(specs/fpga/wasm_(board_ax7203|opcodes)\.t27|fpga/verilog/wasm_board_ax7203_top\.v|\.github/workflows/fpga-build\.yml)$' && echo run=true >> "$GITHUB_OUTPUT" || echo run=false >> "$GITHUB_OUTPUT" - if: steps.gate.outputs.run == 'true' uses: actions/download-artifact@v4 with: { name: fpga-verilog, path: build/fpga/generated/ } diff --git a/fpga/verilog/link_node.v b/fpga/verilog/link_node.v deleted file mode 100644 index e0d2dfc72c..0000000000 --- a/fpga/verilog/link_node.v +++ /dev/null @@ -1,132 +0,0 @@ -`default_nettype none -// A ternary-link NODE: JTAG-writable input, JTAG-readable output. Refs #1959 -// -// ROLE = 0 ENCODER. Host writes a 3-bit word v; the node returns on_comb(v), -// the 4-bit ternary codeword (two 2-bit wire symbols). -// ROLE = 2 RELAY. Host writes a 4-bit codeword; the node checks that BOTH -// 2-bit wire symbols are legal ({0,1,2} -- 3 is not a wire -// code) and re-emits the codeword unchanged, or the -// sentinel 4'b1111 if either symbol is illegal. The relay -// does NOT decode: it never learns which data word it is -// carrying, which is what makes it a link layer rather -// than an endpoint. The sentinel is safe because (3,3) is -// itself an illegal codeword and so can never be data. -// ROLE = 1 DECODER. Host writes a 4-bit codeword; the node sweeps v = 0..7 -// through ITS OWN ZeroDSP_TernaryLink instance and returns -// the v whose encoding matches, or `nomatch` if none does. -// -// WHY THE DECODER IS A SEARCH AND NOT A SECOND IMPLEMENTATION. Writing a -// decoder by hand would create a co-authored golden model, and Knight & Leveson -// (1986) is the reason this project does not trust those. Inverting the encoder -// with the encoder cannot disagree with it about the code -- only about whether -// an inverse exists. That is exactly the question worth asking on the wire: -// the delimiter (+1,+1) = 4'b0101 has NO preimage, so a decoder that searches -// must report `nomatch` for it. Sending the delimiter across is therefore a -// silicon test of the theorem, not a round trip. -// -// The BSCANE2 register is bidirectional: CAPTURE loads the reply, SHIFT walks -// it out while the new command walks in, UPDATE latches the command. One -// 32-bit DR pass is one request-and-response. -// -// [31:4] magic 0xA5A5A5A [3:0] payload -// -module link_node #( - parameter integer JTAG_CHAIN_N = 3, - parameter integer ROLE = 0 -); - wire cfgmclk; - STARTUPE2 #(.PROG_USR("FALSE"), .SIM_CCLK_FREQ(10.0)) startup ( - .CFGCLK(), .CFGMCLK(cfgmclk), .EOS(), .PREQ(), - .CLK(1'b0), .GSR(1'b0), .GTS(1'b0), .KEYCLEARB(1'b0), - .PACK(1'b0), .USRCCLKO(1'b0), .USRCCLKTS(1'b0), - .USRDONEO(1'b1), .USRDONETS(1'b1)); - - reg [3:0] rstc = 4'd0; - wire rst_n = (rstc == 4'hF); - always @(posedge cfgmclk) if (rstc != 4'hF) rstc <= rstc + 4'd1; - - // ---- the command latched from JTAG ---- - reg [3:0] cmd = 4'd0; - - // ---- the single shared encoder instance ---- - reg [2:0] probe = 3'd0; - wire [7:0] code; - wire dut_ready; - wire [2:0] enc_in = (ROLE == 0) ? cmd[2:0] : probe; // ROLE 2 leaves it at probe=0 - ZeroDSP_TernaryLink dut ( - .clk(cfgmclk), .rst_n(rst_n), .en(1'b1), - .v({5'b0, enc_in}), .ready(dut_ready), .result(code)); - - reg [3:0] reply = 4'd0; - reg nomatch = 1'b0; - - generate - if (ROLE == 0) begin : g_enc - always @(posedge cfgmclk) reply <= code[3:0]; - end else if (ROLE == 1) begin : g_dec - // Exhaustive inverse: eight cycles, restarted whenever cmd changes. - reg [3:0] last = 4'hF; - reg hit = 1'b0; - reg [2:0] probe_found = 3'd0; - always @(posedge cfgmclk) begin - if (cmd != last) begin - last <= cmd; - probe <= 3'd0; - hit <= 1'b0; - probe_found <= 3'd0; - end else begin - if (code[3:0] == cmd) begin - hit <= 1'b1; - probe_found <= probe; - end - probe <= probe + 3'd1; - end - // W720: `nomatch` MUST reach the wire. Without it the reply 0 means - // both "no preimage" and "recovered v = 0", and the delimiter test - // cannot tell a theorem from a coincidence. Bit 3 is free -- v is - // three bits -- so the reply is {nomatch, v}. - reply <= hit ? {1'b0, probe_found} : 4'b1000; - nomatch <= ~hit; - end - end else begin : g_relay - // Validate without interpreting. The delimiter (+1,+1) is a LEGAL pair - // of symbols and must pass here -- it is the data layer, not the - // physical layer, that has no preimage for it. - wire hi_ok = (cmd[3:2] != 2'b11); - wire lo_ok = (cmd[1:0] != 2'b11); - always @(posedge cfgmclk) begin - reply <= (hi_ok & lo_ok) ? cmd : 4'b1111; - nomatch <= ~(hi_ok & lo_ok); - end - end - endgenerate - - reg [23:0] pre = 24'd0; - reg beat = 1'b0; - always @(posedge cfgmclk) begin - pre <= pre + 24'd1; - if (pre == 24'd0) beat <= ~beat; - end - - // ---- bidirectional BSCANE2 ---- - wire drck, sel, shift, capture, update, tdi; - wire tdo; - BSCANE2 #(.JTAG_CHAIN(JTAG_CHAIN_N)) bscan ( - .CAPTURE(capture), .DRCK(drck), .RESET(), .RUNTEST(), .SEL(sel), - .SHIFT(shift), .TCK(), .TDI(tdi), .TMS(), .UPDATE(update), .TDO(tdo)); - - reg [31:0] sr = 32'hA5A5A5A0; - always @(posedge drck) - if (sel) begin - if (capture) sr <= {28'hA5A5A5A, reply}; - else if (shift) sr <= {tdi, sr[31:1]}; - end - // UPDATE is in the TCK domain; a 2-flop sync is enough at these rates. - reg u1 = 1'b0, u2 = 1'b0; - always @(posedge cfgmclk) begin - u1 <= update; u2 <= u1; - if (u1 & ~u2) cmd <= sr[3:0]; - end - assign tdo = sr[0]; -endmodule -`default_nettype wire diff --git a/fpga/verilog/wasm_board_ax7203_top.v b/fpga/verilog/wasm_board_ax7203_top.v new file mode 100644 index 0000000000..d1ee326ba4 --- /dev/null +++ b/fpga/verilog/wasm_board_ax7203_top.v @@ -0,0 +1,34 @@ +// AX7203 board top of the generated WASM cell fpga_wasm_board (specs/fpga/wasm_board_ax7203.t27). +// Issue #12456, label owner-approved-foreign: the only hand-written Verilog of the WASM build; +// every decision lives in the spec. Pins: gf16_clean_ax7203.xdc of gHashTag/trinity-fpga +// (rst_n T6, led B13 C13 D14 D15, uart_rx P20, uart_tx N15). No clock pin: STARTUPE2 CFGMCLK. +module wasm_board_ax7203_top(input wire rst_n, output wire [3:0] led, input wire uart_rx, output wire uart_tx); + wire cfgmclk, clk, ready; + wire [7:0] txd, responding; + STARTUPE2 #(.PROG_USR("FALSE"), .SIM_CCLK_FREQ(10.0)) startup ( + .CFGCLK(), .CFGMCLK(cfgmclk), .EOS(), .PREQ(), + .CLK(1'b0), .GSR(1'b0), .GTS(1'b0), .KEYCLEARB(1'b0), + .PACK(1'b0), .USRCCLKO(1'b0), .USRCCLKTS(1'b0), + .USRDONEO(1'b1), .USRDONETS(1'b1)); + BUFG bufg_i (.I(cfgmclk), .O(clk)); + + // reset: held low 16 clocks after configuration and while the button is pressed + reg [3:0] rstc = 4'd0; + reg rst_q0 = 1'b0, rst_q1 = 1'b0; + always @(posedge clk) begin + if (rstc != 4'hF) rstc <= rstc + 4'd1; + rst_q0 <= rst_n; + rst_q1 <= rst_q0; + end + wire rst_sync = (rstc == 4'hF) & rst_q1; + + // UART receive pin through two flops, idle high + reg rx_q0 = 1'b1, rx_q1 = 1'b1; + always @(posedge clk) begin rx_q0 <= uart_rx; rx_q1 <= rx_q0; end + assign uart_tx = txd[0]; + + fpga_wasm_board cell_i (.clk(clk), .rst_n(rst_sync), .en(1'b1), .rxd({7'b0, rx_q1}), + .ready(ready), .txd(txd), .responding(responding)); + // LED polarity is informational; the UART answer is the receipt. + assign led = {responding[1:0], ready, rst_sync}; +endmodule