| 1 |
18 |
dinesha |
//////////////////////////////////////////////////////////////////////
|
| 2 |
|
|
//// ////
|
| 3 |
|
|
//// SPI Master Top Module ////
|
| 4 |
|
|
//// ////
|
| 5 |
|
|
//// This file is part of the YIFive cores project ////
|
| 6 |
|
|
//// http://www.opencores.org/cores/yifive/ ////
|
| 7 |
|
|
//// ////
|
| 8 |
|
|
//// Description ////
|
| 9 |
|
|
//// SPI Master Top module ////
|
| 10 |
|
|
//// ////
|
| 11 |
|
|
//// To Do: ////
|
| 12 |
|
|
//// nothing ////
|
| 13 |
|
|
//// ////
|
| 14 |
|
|
//// Author(s): ////
|
| 15 |
|
|
//// - Dinesh Annayya, dinesha@opencores.org ////
|
| 16 |
|
|
//// ////
|
| 17 |
|
|
//// Revision : ////
|
| 18 |
|
|
//// V.0 - June 8, 2021 ////
|
| 19 |
|
|
//// ////
|
| 20 |
|
|
//////////////////////////////////////////////////////////////////////
|
| 21 |
|
|
//// ////
|
| 22 |
|
|
//// Copyright (C) 2000 Authors and OPENCORES.ORG ////
|
| 23 |
|
|
//// ////
|
| 24 |
|
|
//// This source file may be used and distributed without ////
|
| 25 |
|
|
//// restriction provided that this copyright statement is not ////
|
| 26 |
|
|
//// removed from the file and that any derivative work contains ////
|
| 27 |
|
|
//// the original copyright notice and the associated disclaimer. ////
|
| 28 |
|
|
//// ////
|
| 29 |
|
|
//// This source file is free software; you can redistribute it ////
|
| 30 |
|
|
//// and/or modify it under the terms of the GNU Lesser General ////
|
| 31 |
|
|
//// Public License as published by the Free Software Foundation; ////
|
| 32 |
|
|
//// either version 2.1 of the License, or (at your option) any ////
|
| 33 |
|
|
//// later version. ////
|
| 34 |
|
|
//// ////
|
| 35 |
|
|
//// This source is distributed in the hope that it will be ////
|
| 36 |
|
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
| 37 |
|
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
| 38 |
|
|
//// PURPOSE. See the GNU Lesser General Public License for more ////
|
| 39 |
|
|
//// details. ////
|
| 40 |
|
|
//// ////
|
| 41 |
|
|
//// You should have received a copy of the GNU Lesser General ////
|
| 42 |
|
|
//// Public License along with this source; if not, download it ////
|
| 43 |
|
|
//// from http://www.opencores.org/lgpl.shtml ////
|
| 44 |
|
|
//// ////
|
| 45 |
|
|
//////////////////////////////////////////////////////////////////////
|
| 46 |
|
|
|
| 47 |
|
|
|
| 48 |
|
|
|
| 49 |
|
|
module spim_top
|
| 50 |
|
|
#( parameter WB_WIDTH = 32)
|
| 51 |
|
|
(
|
| 52 |
|
|
input logic mclk,
|
| 53 |
|
|
input logic rst_n,
|
| 54 |
|
|
|
| 55 |
|
|
|
| 56 |
|
|
output logic wbd_stb_i, // strobe/request
|
| 57 |
|
|
output logic [WB_WIDTH-1:0] wbd_adr_i, // address
|
| 58 |
|
|
output logic wbd_we_i, // write
|
| 59 |
|
|
output logic [WB_WIDTH-1:0] wbd_dat_i, // data output
|
| 60 |
|
|
output logic [3:0] wbd_sel_i, // byte enable
|
| 61 |
|
|
input logic [WB_WIDTH-1:0] wbd_dat_o, // data input
|
| 62 |
|
|
input logic wbd_ack_o, // acknowlegement
|
| 63 |
|
|
input logic wbd_err_o, // error
|
| 64 |
|
|
|
| 65 |
|
|
output logic [1:0] events_o,
|
| 66 |
|
|
|
| 67 |
|
|
output logic spi_clk,
|
| 68 |
|
|
output logic spi_csn0,
|
| 69 |
|
|
output logic spi_csn1,
|
| 70 |
|
|
output logic spi_csn2,
|
| 71 |
|
|
output logic spi_csn3,
|
| 72 |
|
|
output logic [1:0] spi_mode,
|
| 73 |
|
|
output logic spi_sdo0,
|
| 74 |
|
|
output logic spi_sdo1,
|
| 75 |
|
|
output logic spi_sdo2,
|
| 76 |
|
|
output logic spi_sdo3,
|
| 77 |
|
|
input logic spi_sdi0,
|
| 78 |
|
|
input logic spi_sdi1,
|
| 79 |
|
|
input logic spi_sdi2,
|
| 80 |
|
|
input logic spi_sdi3,
|
| 81 |
|
|
output logic spi_en_tx
|
| 82 |
|
|
);
|
| 83 |
|
|
|
| 84 |
|
|
|
| 85 |
|
|
|
| 86 |
|
|
logic [7:0] spi_clk_div;
|
| 87 |
|
|
logic spi_clk_div_valid;
|
| 88 |
|
|
logic [7:0] spi_status;
|
| 89 |
|
|
logic [31:0] spi_addr;
|
| 90 |
|
|
logic [5:0] spi_addr_len;
|
| 91 |
|
|
logic [7:0] spi_cmd;
|
| 92 |
|
|
logic [5:0] spi_cmd_len;
|
| 93 |
|
|
logic [7:0] spi_mode_cmd;
|
| 94 |
|
|
logic spi_mode_cmd_enb;
|
| 95 |
|
|
logic [15:0] spi_data_len;
|
| 96 |
|
|
logic [15:0] spi_dummy_rd_len;
|
| 97 |
|
|
logic [15:0] spi_dummy_wr_len;
|
| 98 |
|
|
logic spi_swrst;
|
| 99 |
|
|
logic spi_rd;
|
| 100 |
|
|
logic spi_wr;
|
| 101 |
|
|
logic spi_qrd;
|
| 102 |
|
|
logic spi_qwr;
|
| 103 |
|
|
logic [31:0] spi_wdata;
|
| 104 |
|
|
logic [31:0] spi_rdata;
|
| 105 |
|
|
logic [3:0] spi_csreg;
|
| 106 |
|
|
logic [31:0] spi_data_tx;
|
| 107 |
|
|
logic spi_data_tx_valid;
|
| 108 |
|
|
logic spi_data_tx_ready;
|
| 109 |
|
|
logic [31:0] spi_data_rx;
|
| 110 |
|
|
logic spi_data_rx_valid;
|
| 111 |
|
|
logic spi_data_rx_ready;
|
| 112 |
|
|
logic [7:0] spi_ctrl_status;
|
| 113 |
|
|
logic [31:0] spi_ctrl_data_tx;
|
| 114 |
|
|
logic spi_ctrl_data_tx_valid;
|
| 115 |
|
|
logic spi_ctrl_data_tx_ready;
|
| 116 |
|
|
logic [31:0] spi_ctrl_data_rx;
|
| 117 |
|
|
logic spi_ctrl_data_rx_valid;
|
| 118 |
|
|
logic spi_ctrl_data_rx_ready;
|
| 119 |
|
|
logic [31:0] reg2spi_wdata;
|
| 120 |
|
|
|
| 121 |
|
|
logic s_eot;
|
| 122 |
|
|
|
| 123 |
|
|
|
| 124 |
|
|
|
| 125 |
|
|
|
| 126 |
|
|
|
| 127 |
|
|
spim_regs
|
| 128 |
|
|
#(
|
| 129 |
|
|
.WB_WIDTH(WB_WIDTH)
|
| 130 |
|
|
)
|
| 131 |
|
|
u_spim_regs
|
| 132 |
|
|
(
|
| 133 |
|
|
.mclk (mclk ),
|
| 134 |
|
|
.rst_n (rst_n ),
|
| 135 |
|
|
|
| 136 |
|
|
.wbd_stb_i (wbd_stb_i ), // strobe/request
|
| 137 |
|
|
.wbd_adr_i (wbd_adr_i ), // address
|
| 138 |
|
|
.wbd_we_i (wbd_we_i ), // write
|
| 139 |
|
|
.wbd_dat_i (wbd_dat_i ), // data output
|
| 140 |
|
|
.wbd_sel_i (wbd_sel_i ), // byte enable
|
| 141 |
|
|
.wbd_dat_o (wbd_dat_o ), // data input
|
| 142 |
|
|
.wbd_ack_o (wbd_ack_o ), // acknowlegement
|
| 143 |
|
|
.wbd_err_o (wbd_err_o ), // error
|
| 144 |
|
|
|
| 145 |
|
|
.spi_clk_div (spi_clk_div ),
|
| 146 |
|
|
.spi_clk_div_valid (spi_clk_div_valid ),
|
| 147 |
|
|
.spi_status (spi_status ),
|
| 148 |
|
|
|
| 149 |
|
|
|
| 150 |
|
|
.spi_req (spi_req ),
|
| 151 |
|
|
.spi_addr (spi_addr ),
|
| 152 |
|
|
.spi_addr_len (spi_addr_len ),
|
| 153 |
|
|
.spi_cmd (spi_cmd ),
|
| 154 |
|
|
.spi_cmd_len (spi_cmd_len ),
|
| 155 |
|
|
.spi_mode_cmd (spi_mode_cmd ),
|
| 156 |
|
|
.spi_mode_cmd_enb (spi_mode_cmd_enb ),
|
| 157 |
|
|
.spi_csreg (spi_csreg ),
|
| 158 |
|
|
.spi_data_len (spi_data_len ),
|
| 159 |
|
|
.spi_dummy_rd_len (spi_dummy_rd_len ),
|
| 160 |
|
|
.spi_dummy_wr_len (spi_dummy_wr_len ),
|
| 161 |
|
|
.spi_swrst (spi_swrst ),
|
| 162 |
|
|
.spi_rd (spi_rd ),
|
| 163 |
|
|
.spi_wr (spi_wr ),
|
| 164 |
|
|
.spi_qrd (spi_qrd ),
|
| 165 |
|
|
.spi_qwr (spi_qwr ),
|
| 166 |
|
|
.spi_wdata (spi_wdata ),
|
| 167 |
|
|
.spi_rdata (spi_rdata ),
|
| 168 |
|
|
.spi_ack (spi_ack )
|
| 169 |
|
|
);
|
| 170 |
|
|
|
| 171 |
|
|
spim_ctrl u_spictrl
|
| 172 |
|
|
(
|
| 173 |
|
|
.clk (mclk ),
|
| 174 |
|
|
.rstn (rst_n ),
|
| 175 |
|
|
.eot ( ),
|
| 176 |
|
|
|
| 177 |
|
|
.spi_clk_div (spi_clk_div ),
|
| 178 |
|
|
.spi_clk_div_valid (spi_clk_div_valid ),
|
| 179 |
|
|
.spi_status (spi_ctrl_status ),
|
| 180 |
|
|
|
| 181 |
|
|
.spi_req (spi_req ),
|
| 182 |
|
|
.spi_addr (spi_addr ),
|
| 183 |
|
|
.spi_addr_len (spi_addr_len ),
|
| 184 |
|
|
.spi_cmd (spi_cmd ),
|
| 185 |
|
|
.spi_cmd_len (spi_cmd_len ),
|
| 186 |
|
|
.spi_mode_cmd (spi_mode_cmd ),
|
| 187 |
|
|
.spi_mode_cmd_enb (spi_mode_cmd_enb ),
|
| 188 |
|
|
.spi_csreg (spi_csreg ),
|
| 189 |
|
|
.spi_data_len (spi_data_len ),
|
| 190 |
|
|
.spi_dummy_rd_len (spi_dummy_rd_len ),
|
| 191 |
|
|
.spi_dummy_wr_len (spi_dummy_wr_len ),
|
| 192 |
|
|
.spi_swrst (spi_swrst ),
|
| 193 |
|
|
.spi_rd (spi_rd ),
|
| 194 |
|
|
.spi_wr (spi_wr ),
|
| 195 |
|
|
.spi_qrd (spi_qrd ),
|
| 196 |
|
|
.spi_qwr (spi_qwr ),
|
| 197 |
|
|
.spi_wdata (spi_wdata ),
|
| 198 |
|
|
.spi_rdata (spi_rdata ),
|
| 199 |
|
|
.spi_ack (spi_ack ),
|
| 200 |
|
|
|
| 201 |
|
|
.spi_clk (spi_clk ),
|
| 202 |
|
|
.spi_csn0 (spi_csn0 ),
|
| 203 |
|
|
.spi_csn1 (spi_csn1 ),
|
| 204 |
|
|
.spi_csn2 (spi_csn2 ),
|
| 205 |
|
|
.spi_csn3 (spi_csn3 ),
|
| 206 |
|
|
.spi_mode (spi_mode ),
|
| 207 |
|
|
.spi_sdo0 (spi_sdo0 ),
|
| 208 |
|
|
.spi_sdo1 (spi_sdo1 ),
|
| 209 |
|
|
.spi_sdo2 (spi_sdo2 ),
|
| 210 |
|
|
.spi_sdo3 (spi_sdo3 ),
|
| 211 |
|
|
.spi_sdi0 (spi_sdi0 ),
|
| 212 |
|
|
.spi_sdi1 (spi_sdi1 ),
|
| 213 |
|
|
.spi_sdi2 (spi_sdi2 ),
|
| 214 |
|
|
.spi_sdi3 (spi_sdi3 ),
|
| 215 |
|
|
.spi_en_tx (spi_en_tx )
|
| 216 |
|
|
);
|
| 217 |
|
|
|
| 218 |
|
|
endmodule
|