// bringup.sv: a first design for a new board, built to answer three // questions on real hardware: // led[0] heartbeat: is the bitstream loaded and the clock running? // led[1] button: does the input pin reach the logic? // led[2] sticky: has the button ever been seen high since configuration? // The sticky flag catches events too short to see on an LED. `timescale 1ns/1ps module bringup #( parameter int unsigned HB_WIDTH = 27 // 2^26 cycles per toggle at 100 MHz ) ( input logic clk, input logic btn, // asynchronous: from a push-button output logic [2:0] led ); // Power-up values come from the bitstream (FPGA idiom, see lesson 3). /* verilator lint_off PROCASSINIT */ logic [HB_WIDTH-1:0] hb_count = '0; logic [1:0] btn_meta = '0; logic seen = 1'b0; /* verilator lint_on PROCASSINIT */ // mark_debug keeps the net through synthesis so an ILA can probe it. (* mark_debug = "true" *) logic btn_sync; // Heartbeat counter always_ff @(posedge clk) begin hb_count <= hb_count + 1'b1; end // Two-flop synchroniser for the asynchronous button (lesson 11) always_ff @(posedge clk) begin btn_meta <= {btn_meta[0], btn}; end assign btn_sync = btn_meta[1]; // Sticky flag: set once, cleared only by reconfiguring the FPGA always_ff @(posedge clk) begin if (btn_sync) seen <= 1'b1; end assign led[0] = hb_count[HB_WIDTH-1]; assign led[1] = btn_sync; assign led[2] = seen; endmodule