../src/lowrisc_ip_flash_ctrl_pkg_0.1/rtl/flash_ctrl_pkg.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: // Flash Controller module.
   6: //
   7: 
   8: package flash_ctrl_pkg;
   9: 
  10:   // parameters for flash macro properties
  11:   localparam int NumBanks        = top_pkg::FLASH_BANKS;
  12:   localparam int PagesPerBank    = top_pkg::FLASH_PAGES_PER_BANK;
  13:   localparam int WordsPerPage    = top_pkg::FLASH_WORDS_PER_PAGE;  //Number of bus words per page
  14:   localparam int BytesPerWord    = top_pkg::FLASH_BYTES_PER_WORD;
  15:   localparam int BankW           = $clog2(NumBanks);
  16:   localparam int PageW           = $clog2(PagesPerBank);
  17:   localparam int WordW           = $clog2(WordsPerPage);
  18:   localparam int AddrW           = BankW + PageW + WordW; // all flash range
  19:   localparam int BankAddrW       = PageW + WordW;         // 1 bank of flash range
  20:   localparam int DataWidth       = 64;
  21:   localparam int FlashTotalPages = NumBanks * PagesPerBank;
  22:   localparam int AllPagesW       = BankW + PageW;
  23: 
  24:   // bus interface
  25:   localparam int BusWidth        = top_pkg::TL_DW;
  26: 
  27:   // flash controller protection regions
  28:   localparam int MpRegions       = 8;
  29: 
  30:   // fifo parameters
  31:   localparam int FifoDepth       = 16;
  32:   localparam int FifoDepthW      = $clog2(FifoDepth+1);
  33: 
  34: 
  35:   // Flash Operations Supported
  36:   typedef enum logic [1:0] {
  37:     FlashRead      = 2'h0,
  38:     FlashProg      = 2'h1,
  39:     FlashErase     = 2'h2
  40:   } flash_op_e;
  41: 
  42:   // Flash Erase Operations Supported
  43:   typedef enum logic  {
  44:     PageErase     = 0,
  45:     BankErase     = 1
  46:   } flash_erase_op_e;
  47: 
  48:   // Flash tlul to fifo direction
  49:   typedef enum logic  {
  50:     WriteDir     = 1'b0,
  51:     ReadDir      = 1'b1
  52:   } flash_flfo_dir_e;
  53: 
  54:   // Flash controller to memory
  55:   typedef struct packed {
  56:     logic                req;
  57:     logic                rd;
  58:     logic                prog;
  59:     logic                pg_erase;
  60:     logic                bk_erase;
  61:     logic [AddrW-1:0]    addr;
  62:     logic [BusWidth-1:0] prog_data;
  63:   } flash_req_t;
  64: 
  65:   // default value of flash_req_t (for dangling ports)
  66:   parameter flash_req_t FLASH_REQ_DEFAULT = '{
  67:     req:       1'b0,
  68:     rd:        1'b0,
  69:     prog:      1'b0,
  70:     pg_erase:  1'b0,
  71:     bk_erase:  1'b0,
  72:     addr:      '0,
  73:     prog_data: '0
  74:   };
  75: 
  76:   // memory to flash controller
  77:   typedef struct packed {
  78:     logic                rd_done;
  79:     logic                prog_done;
  80:     logic                erase_done;
  81:     logic [BusWidth-1:0] rd_data;
  82:     logic                init_busy;
  83:   } flash_rsp_t;
  84: 
  85:   // default value of flash_rsp_t (for dangling ports)
  86:   parameter flash_rsp_t FLASH_RSP_DEFAULT = '{
  87:     rd_done:    1'b0,
  88:     prog_done:  1'b0,
  89:     erase_done: 1'b0,
  90:     rd_data:    '0,
  91:     init_busy:  1'b0
  92:   };
  93: 
  94: endpackage : flash_ctrl_pkg
  95: