rtl/lm32_top.v

changeset 24
c336e674a37e
parent 16
5fb37de64edc
child 28
da23ab8ef7b4
     1.1 diff -r 252df75c8f67 -r c336e674a37e rtl/lm32_top.v
     1.2 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 +++ b/rtl/lm32_top.v	Tue Mar 08 09:40:42 2011 +0000
     1.4 @@ -0,0 +1,355 @@
     1.5 +// =============================================================================
     1.6 +//                           COPYRIGHT NOTICE
     1.7 +// Copyright 2006 (c) Lattice Semiconductor Corporation
     1.8 +// ALL RIGHTS RESERVED
     1.9 +// This confidential and proprietary software may be used only as authorised by
    1.10 +// a licensing agreement from Lattice Semiconductor Corporation.
    1.11 +// The entire notice above must be reproduced on all authorized copies and
    1.12 +// copies may only be made to the extent permitted by a licensing agreement from
    1.13 +// Lattice Semiconductor Corporation.
    1.14 +//
    1.15 +// Lattice Semiconductor Corporation        TEL : 1-800-Lattice (USA and Canada)
    1.16 +// 5555 NE Moore Court                            408-826-6000 (other locations)
    1.17 +// Hillsboro, OR 97124                     web  : http://www.latticesemi.com/
    1.18 +// U.S.A                                   email: techsupport@latticesemi.com
    1.19 +// =============================================================================/
    1.20 +//                         FILE DETAILS
    1.21 +// Project          : LatticeMico32
    1.22 +// File             : lm32_top.v
    1.23 +// Title            : Top-level of CPU.
    1.24 +// Dependencies     : lm32_include.v
    1.25 +// Version          : 6.1.17
    1.26 +//                  : removed SPI - 04/12/07
    1.27 +// Version          : 7.0SP2, 3.0
    1.28 +//                  : No Change
    1.29 +// Version          : 3.1
    1.30 +//                  : No Change
    1.31 +// =============================================================================
    1.32 +
    1.33 +`include "lm32_include.v"
    1.34 +
    1.35 +/////////////////////////////////////////////////////
    1.36 +// Module interface
    1.37 +/////////////////////////////////////////////////////
    1.38 +
    1.39 +module lm32_top (
    1.40 +    // ----- Inputs -------
    1.41 +    clk_i,
    1.42 +    rst_i,
    1.43 +    // From external devices
    1.44 +`ifdef CFG_INTERRUPTS_ENABLED
    1.45 +    interrupt,
    1.46 +`endif
    1.47 +    // From user logic
    1.48 +`ifdef CFG_USER_ENABLED
    1.49 +    user_result,
    1.50 +    user_complete,
    1.51 +`endif     
    1.52 +`ifdef CFG_IWB_ENABLED
    1.53 +    // Instruction Wishbone master
    1.54 +    I_DAT_I,
    1.55 +    I_ACK_I,
    1.56 +    I_ERR_I,
    1.57 +    I_RTY_I,
    1.58 +`endif
    1.59 +    // Data Wishbone master
    1.60 +    D_DAT_I,
    1.61 +    D_ACK_I,
    1.62 +    D_ERR_I,
    1.63 +    D_RTY_I,
    1.64 +    // ----- Outputs -------
    1.65 +`ifdef CFG_USER_ENABLED    
    1.66 +    user_valid,
    1.67 +    user_opcode,
    1.68 +    user_operand_0,
    1.69 +    user_operand_1,
    1.70 +`endif    
    1.71 +`ifdef CFG_IWB_ENABLED
    1.72 +    // Instruction Wishbone master
    1.73 +    I_DAT_O,
    1.74 +    I_ADR_O,
    1.75 +    I_CYC_O,
    1.76 +    I_SEL_O,
    1.77 +    I_STB_O,
    1.78 +    I_WE_O,
    1.79 +    I_CTI_O,
    1.80 +    I_LOCK_O,
    1.81 +    I_BTE_O,
    1.82 +`endif
    1.83 +    // Data Wishbone master
    1.84 +    D_DAT_O,
    1.85 +    D_ADR_O,
    1.86 +    D_CYC_O,
    1.87 +    D_SEL_O,
    1.88 +    D_STB_O,
    1.89 +    D_WE_O,
    1.90 +    D_CTI_O,
    1.91 +    D_LOCK_O,
    1.92 +    D_BTE_O
    1.93 +    );
    1.94 +
    1.95 +/////////////////////////////////////////////////////
    1.96 +// Inputs
    1.97 +/////////////////////////////////////////////////////
    1.98 +
    1.99 +input clk_i;                                    // Clock
   1.100 +input rst_i;                                    // Reset
   1.101 +
   1.102 +`ifdef CFG_INTERRUPTS_ENABLED
   1.103 +input [`LM32_INTERRUPT_RNG] interrupt;          // Interrupt pins
   1.104 +`endif
   1.105 +
   1.106 +`ifdef CFG_USER_ENABLED
   1.107 +input [`LM32_WORD_RNG] user_result;             // User-defined instruction result
   1.108 +input user_complete;                            // Indicates the user-defined instruction result is valid
   1.109 +`endif    
   1.110 +
   1.111 +`ifdef CFG_IWB_ENABLED
   1.112 +input [`LM32_WORD_RNG] I_DAT_I;                 // Instruction Wishbone interface read data
   1.113 +input I_ACK_I;                                  // Instruction Wishbone interface acknowledgement
   1.114 +input I_ERR_I;                                  // Instruction Wishbone interface error
   1.115 +input I_RTY_I;                                  // Instruction Wishbone interface retry
   1.116 +`endif
   1.117 +
   1.118 +input [`LM32_WORD_RNG] D_DAT_I;                 // Data Wishbone interface read data
   1.119 +input D_ACK_I;                                  // Data Wishbone interface acknowledgement
   1.120 +input D_ERR_I;                                  // Data Wishbone interface error
   1.121 +input D_RTY_I;                                  // Data Wishbone interface retry
   1.122 +
   1.123 +/////////////////////////////////////////////////////
   1.124 +// Outputs
   1.125 +/////////////////////////////////////////////////////
   1.126 +
   1.127 +`ifdef CFG_USER_ENABLED
   1.128 +output user_valid;                              // Indicates that user_opcode and user_operand_* are valid
   1.129 +wire   user_valid;
   1.130 +output [`LM32_USER_OPCODE_RNG] user_opcode;     // User-defined instruction opcode
   1.131 +reg    [`LM32_USER_OPCODE_RNG] user_opcode;
   1.132 +output [`LM32_WORD_RNG] user_operand_0;         // First operand for user-defined instruction
   1.133 +wire   [`LM32_WORD_RNG] user_operand_0;
   1.134 +output [`LM32_WORD_RNG] user_operand_1;         // Second operand for user-defined instruction
   1.135 +wire   [`LM32_WORD_RNG] user_operand_1;
   1.136 +`endif
   1.137 +
   1.138 +`ifdef CFG_IWB_ENABLED
   1.139 +output [`LM32_WORD_RNG] I_DAT_O;                // Instruction Wishbone interface write data
   1.140 +wire   [`LM32_WORD_RNG] I_DAT_O;
   1.141 +output [`LM32_WORD_RNG] I_ADR_O;                // Instruction Wishbone interface address
   1.142 +wire   [`LM32_WORD_RNG] I_ADR_O;
   1.143 +output I_CYC_O;                                 // Instruction Wishbone interface cycle
   1.144 +wire   I_CYC_O;
   1.145 +output [`LM32_BYTE_SELECT_RNG] I_SEL_O;         // Instruction Wishbone interface byte select
   1.146 +wire   [`LM32_BYTE_SELECT_RNG] I_SEL_O;
   1.147 +output I_STB_O;                                 // Instruction Wishbone interface strobe
   1.148 +wire   I_STB_O;
   1.149 +output I_WE_O;                                  // Instruction Wishbone interface write enable
   1.150 +wire   I_WE_O;
   1.151 +output [`LM32_CTYPE_RNG] I_CTI_O;               // Instruction Wishbone interface cycle type 
   1.152 +wire   [`LM32_CTYPE_RNG] I_CTI_O;
   1.153 +output I_LOCK_O;                                // Instruction Wishbone interface lock bus
   1.154 +wire   I_LOCK_O;
   1.155 +output [`LM32_BTYPE_RNG] I_BTE_O;               // Instruction Wishbone interface burst type 
   1.156 +wire   [`LM32_BTYPE_RNG] I_BTE_O;
   1.157 +`endif
   1.158 +
   1.159 +output [`LM32_WORD_RNG] D_DAT_O;                // Data Wishbone interface write data
   1.160 +wire   [`LM32_WORD_RNG] D_DAT_O;
   1.161 +output [`LM32_WORD_RNG] D_ADR_O;                // Data Wishbone interface address
   1.162 +wire   [`LM32_WORD_RNG] D_ADR_O;
   1.163 +output D_CYC_O;                                 // Data Wishbone interface cycle
   1.164 +wire   D_CYC_O;
   1.165 +output [`LM32_BYTE_SELECT_RNG] D_SEL_O;         // Data Wishbone interface byte select
   1.166 +wire   [`LM32_BYTE_SELECT_RNG] D_SEL_O;
   1.167 +output D_STB_O;                                 // Data Wishbone interface strobe
   1.168 +wire   D_STB_O;
   1.169 +output D_WE_O;                                  // Data Wishbone interface write enable
   1.170 +wire   D_WE_O;
   1.171 +output [`LM32_CTYPE_RNG] D_CTI_O;               // Data Wishbone interface cycle type 
   1.172 +wire   [`LM32_CTYPE_RNG] D_CTI_O;
   1.173 +output D_LOCK_O;                                // Date Wishbone interface lock bus
   1.174 +wire   D_LOCK_O;
   1.175 +output [`LM32_BTYPE_RNG] D_BTE_O;               // Data Wishbone interface burst type 
   1.176 +wire   [`LM32_BTYPE_RNG] D_BTE_O;
   1.177 +  
   1.178 +/////////////////////////////////////////////////////
   1.179 +// Internal nets and registers 
   1.180 +/////////////////////////////////////////////////////
   1.181 + 
   1.182 +`ifdef CFG_JTAG_ENABLED
   1.183 +// Signals between JTAG interface and CPU
   1.184 +wire [`LM32_BYTE_RNG] jtag_reg_d;
   1.185 +wire [`LM32_BYTE_RNG] jtag_reg_q;
   1.186 +wire jtag_update;
   1.187 +wire [2:0] jtag_reg_addr_d;
   1.188 +wire [2:0] jtag_reg_addr_q;
   1.189 +wire jtck;
   1.190 +wire jrstn;
   1.191 +`endif
   1.192 +
   1.193 +// TODO: get the trace signals out
   1.194 +`ifdef CFG_TRACE_ENABLED
   1.195 +// PC trace signals
   1.196 +wire [`LM32_PC_RNG] trace_pc;                   // PC to trace (address of next non-sequential instruction)
   1.197 +wire trace_pc_valid;                            // Indicates that a new trace PC is valid
   1.198 +wire trace_exception;                           // Indicates an exception has occured
   1.199 +wire [`LM32_EID_RNG] trace_eid;                 // Indicates what type of exception has occured
   1.200 +wire trace_eret;                                // Indicates an eret instruction has been executed
   1.201 +`ifdef CFG_DEBUG_ENABLED
   1.202 +wire trace_bret;                                // Indicates a bret instruction has been executed
   1.203 +`endif
   1.204 +`endif
   1.205 +
   1.206 +/////////////////////////////////////////////////////
   1.207 +// Functions
   1.208 +/////////////////////////////////////////////////////
   1.209 +
   1.210 +`include "lm32_functions.v"
   1.211 +/////////////////////////////////////////////////////
   1.212 +// Instantiations
   1.213 +///////////////////////////////////////////////////// 
   1.214 +
   1.215 +// LM32 CPU
   1.216 +lm32_cpu cpu (
   1.217 +    // ----- Inputs -------
   1.218 +    .clk_i                 (clk_i),
   1.219 +`ifdef CFG_EBR_NEGEDGE_REGISTER_FILE
   1.220 +    .clk_n_i               (clk_n),
   1.221 +`endif
   1.222 +    .rst_i                 (rst_i),
   1.223 +    // From external devices
   1.224 +`ifdef CFG_INTERRUPTS_ENABLED
   1.225 +    .interrupt             (interrupt),
   1.226 +`endif
   1.227 +    // From user logic
   1.228 +`ifdef CFG_USER_ENABLED
   1.229 +    .user_result           (user_result),
   1.230 +    .user_complete         (user_complete),
   1.231 +`endif     
   1.232 +`ifdef CFG_JTAG_ENABLED
   1.233 +    // From JTAG
   1.234 +    .jtag_clk              (jtck),
   1.235 +    .jtag_update           (jtag_update),
   1.236 +    .jtag_reg_q            (jtag_reg_q),
   1.237 +    .jtag_reg_addr_q       (jtag_reg_addr_q),
   1.238 +`endif
   1.239 +`ifdef CFG_IWB_ENABLED
   1.240 +     // Instruction Wishbone master
   1.241 +    .I_DAT_I               (I_DAT_I),
   1.242 +    .I_ACK_I               (I_ACK_I),
   1.243 +    .I_ERR_I               (I_ERR_I),
   1.244 +    .I_RTY_I               (I_RTY_I),
   1.245 +`endif
   1.246 +    // Data Wishbone master
   1.247 +    .D_DAT_I               (D_DAT_I),
   1.248 +    .D_ACK_I               (D_ACK_I),
   1.249 +    .D_ERR_I               (D_ERR_I),
   1.250 +    .D_RTY_I               (D_RTY_I),
   1.251 +    // ----- Outputs -------
   1.252 +`ifdef CFG_TRACE_ENABLED
   1.253 +    .trace_pc              (trace_pc),
   1.254 +    .trace_pc_valid        (trace_pc_valid),
   1.255 +    .trace_exception       (trace_exception),
   1.256 +    .trace_eid             (trace_eid),
   1.257 +    .trace_eret            (trace_eret),
   1.258 +`ifdef CFG_DEBUG_ENABLED
   1.259 +    .trace_bret            (trace_bret),
   1.260 +`endif
   1.261 +`endif
   1.262 +`ifdef CFG_JTAG_ENABLED
   1.263 +    .jtag_reg_d            (jtag_reg_d),
   1.264 +    .jtag_reg_addr_d       (jtag_reg_addr_d),
   1.265 +`endif
   1.266 +`ifdef CFG_USER_ENABLED    
   1.267 +    .user_valid            (user_valid),
   1.268 +    .user_opcode           (user_opcode),
   1.269 +    .user_operand_0        (user_operand_0),
   1.270 +    .user_operand_1        (user_operand_1),
   1.271 +`endif    
   1.272 +`ifdef CFG_IWB_ENABLED
   1.273 +    // Instruction Wishbone master
   1.274 +    .I_DAT_O               (I_DAT_O),
   1.275 +    .I_ADR_O               (I_ADR_O),
   1.276 +    .I_CYC_O               (I_CYC_O),
   1.277 +    .I_SEL_O               (I_SEL_O),
   1.278 +    .I_STB_O               (I_STB_O),
   1.279 +    .I_WE_O                (I_WE_O),
   1.280 +    .I_CTI_O               (I_CTI_O),
   1.281 +    .I_LOCK_O              (I_LOCK_O),
   1.282 +    .I_BTE_O               (I_BTE_O),
   1.283 +    `endif
   1.284 +    // Data Wishbone master
   1.285 +    .D_DAT_O               (D_DAT_O),
   1.286 +    .D_ADR_O               (D_ADR_O),
   1.287 +    .D_CYC_O               (D_CYC_O),
   1.288 +    .D_SEL_O               (D_SEL_O),
   1.289 +    .D_STB_O               (D_STB_O),
   1.290 +    .D_WE_O                (D_WE_O),
   1.291 +    .D_CTI_O               (D_CTI_O),
   1.292 +    .D_LOCK_O              (D_LOCK_O),
   1.293 +    .D_BTE_O               (D_BTE_O)
   1.294 +    );
   1.295 +
   1.296 +   wire TRACE_ACK_O;
   1.297 +   wire [`LM32_WORD_RNG] TRACE_DAT_O;
   1.298 +`ifdef CFG_TRACE_ENABLED
   1.299 +   lm32_trace trace_module (.clk_i	(clk_i),
   1.300 +			    .rst_i	(rst_i),
   1.301 +			    .stb_i	(DEBUG_STB_I & DEBUG_ADR_I[13]),
   1.302 +			    .we_i	(DEBUG_WE_I),
   1.303 +			    .sel_i	(DEBUG_SEL_I),
   1.304 +			    .dat_i	(DEBUG_DAT_I),
   1.305 +			    .adr_i	(DEBUG_ADR_I),
   1.306 +			    .trace_pc	(trace_pc),
   1.307 +			    .trace_eid	(trace_eid),
   1.308 +			    .trace_eret (trace_eret),
   1.309 +			    .trace_bret (trace_bret),
   1.310 +			    .trace_pc_valid (trace_pc_valid),
   1.311 +			    .trace_exception (trace_exception),
   1.312 +			    .ack_o	(TRACE_ACK_O),
   1.313 +			    .dat_o 	(TRACE_DAT_O));   
   1.314 +`else
   1.315 +   assign 		 TRACE_ACK_O = 0;
   1.316 +   assign 		 TRACE_DAT_O = 0;   
   1.317 +`endif   
   1.318 +`ifdef DEBUG_ROM
   1.319 +   wire ROM_ACK_O;
   1.320 +   wire [`LM32_WORD_RNG] ROM_DAT_O;
   1.321 +
   1.322 +   assign DEBUG_ACK_O = DEBUG_ADR_I[13] ? TRACE_ACK_O : ROM_ACK_O;
   1.323 +   assign DEBUG_DAT_O = DEBUG_ADR_I[13] ? TRACE_DAT_O : ROM_DAT_O;
   1.324 +   
   1.325 +   // ROM monitor
   1.326 +   lm32_monitor debug_rom (
   1.327 +			   // ----- Inputs -------
   1.328 +			   .clk_i                 (clk_i),
   1.329 +			   .rst_i                 (rst_i),
   1.330 +			   .MON_ADR_I             (DEBUG_ADR_I[10:2]),
   1.331 +			   .MON_STB_I             (DEBUG_STB_I & ~DEBUG_ADR_I[13]),
   1.332 +			   .MON_CYC_I             (DEBUG_CYC_I & ~DEBUG_ADR_I[13]),
   1.333 +			   .MON_WE_I              (DEBUG_WE_I),
   1.334 +			   .MON_SEL_I             (DEBUG_SEL_I),
   1.335 +			   .MON_DAT_I             (DEBUG_DAT_I),
   1.336 +			   // ----- Outputs ------    
   1.337 +			   .MON_RTY_O             (DEBUG_RTY_O),
   1.338 +			   .MON_ERR_O             (DEBUG_ERR_O),
   1.339 +			   .MON_ACK_O             (ROM_ACK_O),
   1.340 +			   .MON_DAT_O             (ROM_DAT_O)
   1.341 +			   );
   1.342 +`endif 
   1.343 +   
   1.344 +`ifdef CFG_JTAG_ENABLED		   
   1.345 +// JTAG cores 
   1.346 +jtag_cores jtag_cores (
   1.347 +    // ----- Inputs -----
   1.348 +    .reg_d                 (jtag_reg_d),
   1.349 +    .reg_addr_d            (jtag_reg_addr_d),
   1.350 +    // ----- Outputs -----
   1.351 +    .reg_update            (jtag_update),
   1.352 +    .reg_q                 (jtag_reg_q),
   1.353 +    .reg_addr_q            (jtag_reg_addr_q),
   1.354 +    .jtck                  (jtck),
   1.355 +    .jrstn                 (jrstn)
   1.356 +    );
   1.357 +`endif        
   1.358 +   
   1.359 +endmodule