/* * flash_lock.v * * vim: ts=4 sw=4 * * Copyright (C) 2019-2020 Sylvain Munaut * SPDX-License-Identifier: CERN-OHL-P-2.0 */ `default_nettype none module flash_lock #( // Lock sequence parameter LOCK_DATA = { 2'b01, 8'h50, // WRITE_ENABLE_VOLATILE 2'b00, 8'h01, // WRITE_SR 2'b00, 8'h28, // SR1 value 2'b11, 8'h03 // SR2 value } )( // SPI output reg spi_mosi, input wire spi_miso, output reg spi_clk, output reg spi_cs_n, // Control input wire go, output wire rdy, // Clock / Reset input wire clk, input wire rst ); localparam LOCK_N = $bits(LOCK_DATA) / 10; // Signals // ------- // Lock sequence memory reg [9:0] im_mem[0:LOCK_N-1]; reg [3:0] im_raddr; (* keep *) wire [9:0] im_rdata; // FSM localparam ST_IDLE = 0, ST_CMD_START = 1, ST_CMD_SHIFT_LO = 2, ST_CMD_SHIFT_HI = 3, ST_CMD_PAUSE = 4; reg [2:0] state; reg [2:0] state_nxt; // Counters reg [3:0] bit_cnt; wire bit_last; // Current command byte wire cmd_load; reg [7:0] cmd_byte_data; reg cmd_byte_last; reg cmd_last; // Lock sequence ROM // ----------------- initial begin : im_mem_init integer i; for (i=0; i