../src/lowrisc_ip_flash_ctrl_0.1/rtl/flash_erase_ctrl.sv Cov: 100%
1: // Copyright lowRISC contributors.
2: // Licensed under the Apache License, Version 2.0, see LICENSE for details.
3: // SPDX-License-Identifier: Apache-2.0
4: //
5: // Faux Flash Erase Control
6: //
7:
8: module flash_erase_ctrl #(
9: parameter int AddrW = 10,
10: parameter int WordsPerPage = 256,
11: parameter int PagesPerBank = 256,
12: parameter int EraseBitWidth = 1
13: ) (
14: // Software Interface
15: input op_start_i,
16: input [EraseBitWidth-1:0] op_type_i,
17: input [AddrW-1:0] op_addr_i,
18: output logic op_done_o,
19: output logic op_err_o,
20:
21: // Flash Macro Interface
22: output logic flash_req_o,
23: output logic [AddrW-1:0] flash_addr_o,
24: output logic [EraseBitWidth-1:0] flash_op_o,
25: input flash_done_i,
26: input flash_error_i
27: );
28:
29: import flash_ctrl_pkg::*;
30:
31: localparam int WordsBitWidth = $clog2(WordsPerPage);
32: localparam int PagesBitWidth = $clog2(PagesPerBank);
33:
34: // The *AddrMask below masks out the bits that are not required
35: // e.g, assume we have an address 0x5_0004_345C
36: // 0x5 represents bank address
37: // 0x0004 represents page address
38: // PageAddrMask would be 0xF_FFFF_0000
39: // BankAddrMask would be 0xF_0000_0000
40: //
41: localparam logic[AddrW-1:0] PageAddrMask = ~(('h1 << WordsBitWidth) - 1'b1);
42: localparam logic[AddrW-1:0] BankAddrMask = ~(('h1 << (PagesBitWidth + WordsBitWidth)) - 1'b1);
43:
44: // IO assignments
45: assign op_done_o = flash_req_o & flash_done_i;
46: assign op_err_o = flash_req_o & flash_error_i;
47:
48: // Flash Interface assignments
49: assign flash_req_o = op_start_i;
50: assign flash_op_o = op_type_i;
51: assign flash_addr_o = (op_type_i == PageErase) ?
52: op_addr_i & PageAddrMask :
53: op_addr_i & BankAddrMask;
54:
55: // unused bus
56: logic [WordsBitWidth-1:0] unused_addr_i;
57: assign unused_addr_i = op_addr_i[WordsBitWidth-1:0];
58:
59: endmodule // flash_erase_ctrl
60: