1.1 diff -r 000000000000 -r cd0b58aa6f83 lm32_top.v 1.2 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.3 +++ b/lm32_top.v Sun Apr 04 20:40:03 2010 +0100 1.4 @@ -0,0 +1,395 @@ 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_n, 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 + // Debug Slave port WishboneInterface 1.65 + DEBUG_ADR_I, 1.66 + DEBUG_DAT_I, 1.67 + DEBUG_SEL_I, 1.68 + DEBUG_WE_I, 1.69 + DEBUG_CTI_I, 1.70 + DEBUG_BTE_I, 1.71 + DEBUG_LOCK_I, 1.72 + DEBUG_CYC_I, 1.73 + DEBUG_STB_I, 1.74 + // ----- Outputs ------- 1.75 +`ifdef CFG_USER_ENABLED 1.76 + user_valid, 1.77 + user_opcode, 1.78 + user_operand_0, 1.79 + user_operand_1, 1.80 +`endif 1.81 +`ifdef CFG_IWB_ENABLED 1.82 + // Instruction Wishbone master 1.83 + I_DAT_O, 1.84 + I_ADR_O, 1.85 + I_CYC_O, 1.86 + I_SEL_O, 1.87 + I_STB_O, 1.88 + I_WE_O, 1.89 + I_CTI_O, 1.90 + I_LOCK_O, 1.91 + I_BTE_O, 1.92 +`endif 1.93 + // Data Wishbone master 1.94 + D_DAT_O, 1.95 + D_ADR_O, 1.96 + D_CYC_O, 1.97 + D_SEL_O, 1.98 + D_STB_O, 1.99 + D_WE_O, 1.100 + D_CTI_O, 1.101 + D_LOCK_O, 1.102 + D_BTE_O, 1.103 + // Debug Slave port WishboneInterface 1.104 + DEBUG_ACK_O, 1.105 + DEBUG_ERR_O, 1.106 + DEBUG_RTY_O, 1.107 + DEBUG_DAT_O 1.108 + ); 1.109 + 1.110 +///////////////////////////////////////////////////// 1.111 +// Inputs 1.112 +///////////////////////////////////////////////////// 1.113 + 1.114 +input clk_i; // Clock 1.115 +input rst_i; // Reset 1.116 + 1.117 +`ifdef CFG_INTERRUPTS_ENABLED 1.118 +input [`LM32_INTERRUPT_RNG] interrupt_n; // Interrupt pins, active-low 1.119 +`endif 1.120 + 1.121 +`ifdef CFG_USER_ENABLED 1.122 +input [`LM32_WORD_RNG] user_result; // User-defined instruction result 1.123 +input user_complete; // Indicates the user-defined instruction result is valid 1.124 +`endif 1.125 + 1.126 +`ifdef CFG_IWB_ENABLED 1.127 +input [`LM32_WORD_RNG] I_DAT_I; // Instruction Wishbone interface read data 1.128 +input I_ACK_I; // Instruction Wishbone interface acknowledgement 1.129 +input I_ERR_I; // Instruction Wishbone interface error 1.130 +input I_RTY_I; // Instruction Wishbone interface retry 1.131 +`endif 1.132 + 1.133 +input [`LM32_WORD_RNG] D_DAT_I; // Data Wishbone interface read data 1.134 +input D_ACK_I; // Data Wishbone interface acknowledgement 1.135 +input D_ERR_I; // Data Wishbone interface error 1.136 +input D_RTY_I; // Data Wishbone interface retry 1.137 + 1.138 +input [`LM32_WORD_RNG] DEBUG_ADR_I; // Debug monitor Wishbone interface address 1.139 +input [`LM32_WORD_RNG] DEBUG_DAT_I; // Debug monitor Wishbone interface write data 1.140 +input [`LM32_BYTE_SELECT_RNG] DEBUG_SEL_I; // Debug monitor Wishbone interface byte select 1.141 +input DEBUG_WE_I; // Debug monitor Wishbone interface write enable 1.142 +input [`LM32_CTYPE_RNG] DEBUG_CTI_I; // Debug monitor Wishbone interface cycle type 1.143 +input [`LM32_BTYPE_RNG] DEBUG_BTE_I; // Debug monitor Wishbone interface burst type 1.144 +input DEBUG_LOCK_I; // Debug monitor Wishbone interface locked transfer 1.145 +input DEBUG_CYC_I; // Debug monitor Wishbone interface cycle 1.146 +input DEBUG_STB_I; // Debug monitor Wishbone interface strobe 1.147 + 1.148 +///////////////////////////////////////////////////// 1.149 +// Outputs 1.150 +///////////////////////////////////////////////////// 1.151 + 1.152 +`ifdef CFG_USER_ENABLED 1.153 +output user_valid; // Indicates that user_opcode and user_operand_* are valid 1.154 +wire user_valid; 1.155 +output [`LM32_USER_OPCODE_RNG] user_opcode; // User-defined instruction opcode 1.156 +reg [`LM32_USER_OPCODE_RNG] user_opcode; 1.157 +output [`LM32_WORD_RNG] user_operand_0; // First operand for user-defined instruction 1.158 +wire [`LM32_WORD_RNG] user_operand_0; 1.159 +output [`LM32_WORD_RNG] user_operand_1; // Second operand for user-defined instruction 1.160 +wire [`LM32_WORD_RNG] user_operand_1; 1.161 +`endif 1.162 + 1.163 +`ifdef CFG_IWB_ENABLED 1.164 +output [`LM32_WORD_RNG] I_DAT_O; // Instruction Wishbone interface write data 1.165 +wire [`LM32_WORD_RNG] I_DAT_O; 1.166 +output [`LM32_WORD_RNG] I_ADR_O; // Instruction Wishbone interface address 1.167 +wire [`LM32_WORD_RNG] I_ADR_O; 1.168 +output I_CYC_O; // Instruction Wishbone interface cycle 1.169 +wire I_CYC_O; 1.170 +output [`LM32_BYTE_SELECT_RNG] I_SEL_O; // Instruction Wishbone interface byte select 1.171 +wire [`LM32_BYTE_SELECT_RNG] I_SEL_O; 1.172 +output I_STB_O; // Instruction Wishbone interface strobe 1.173 +wire I_STB_O; 1.174 +output I_WE_O; // Instruction Wishbone interface write enable 1.175 +wire I_WE_O; 1.176 +output [`LM32_CTYPE_RNG] I_CTI_O; // Instruction Wishbone interface cycle type 1.177 +wire [`LM32_CTYPE_RNG] I_CTI_O; 1.178 +output I_LOCK_O; // Instruction Wishbone interface lock bus 1.179 +wire I_LOCK_O; 1.180 +output [`LM32_BTYPE_RNG] I_BTE_O; // Instruction Wishbone interface burst type 1.181 +wire [`LM32_BTYPE_RNG] I_BTE_O; 1.182 +`endif 1.183 + 1.184 +output [`LM32_WORD_RNG] D_DAT_O; // Data Wishbone interface write data 1.185 +wire [`LM32_WORD_RNG] D_DAT_O; 1.186 +output [`LM32_WORD_RNG] D_ADR_O; // Data Wishbone interface address 1.187 +wire [`LM32_WORD_RNG] D_ADR_O; 1.188 +output D_CYC_O; // Data Wishbone interface cycle 1.189 +wire D_CYC_O; 1.190 +output [`LM32_BYTE_SELECT_RNG] D_SEL_O; // Data Wishbone interface byte select 1.191 +wire [`LM32_BYTE_SELECT_RNG] D_SEL_O; 1.192 +output D_STB_O; // Data Wishbone interface strobe 1.193 +wire D_STB_O; 1.194 +output D_WE_O; // Data Wishbone interface write enable 1.195 +wire D_WE_O; 1.196 +output [`LM32_CTYPE_RNG] D_CTI_O; // Data Wishbone interface cycle type 1.197 +wire [`LM32_CTYPE_RNG] D_CTI_O; 1.198 +output D_LOCK_O; // Date Wishbone interface lock bus 1.199 +wire D_LOCK_O; 1.200 +output [`LM32_BTYPE_RNG] D_BTE_O; // Data Wishbone interface burst type 1.201 +wire [`LM32_BTYPE_RNG] D_BTE_O; 1.202 + 1.203 +output DEBUG_ACK_O; // Debug monitor Wishbone ack 1.204 +wire DEBUG_ACK_O; 1.205 +output DEBUG_ERR_O; // Debug monitor Wishbone error 1.206 +wire DEBUG_ERR_O; 1.207 +output DEBUG_RTY_O; // Debug monitor Wishbone retry 1.208 +wire DEBUG_RTY_O; 1.209 +output [`LM32_WORD_RNG] DEBUG_DAT_O; // Debug monitor Wishbone read data 1.210 +wire [`LM32_WORD_RNG] DEBUG_DAT_O; 1.211 + 1.212 +///////////////////////////////////////////////////// 1.213 +// Internal nets and registers 1.214 +///////////////////////////////////////////////////// 1.215 + 1.216 +`ifdef CFG_JTAG_ENABLED 1.217 +// Signals between JTAG interface and CPU 1.218 +wire [`LM32_BYTE_RNG] jtag_reg_d; 1.219 +wire [`LM32_BYTE_RNG] jtag_reg_q; 1.220 +wire jtag_update; 1.221 +wire [2:0] jtag_reg_addr_d; 1.222 +wire [2:0] jtag_reg_addr_q; 1.223 +wire jtck; 1.224 +wire jrstn; 1.225 +`endif 1.226 + 1.227 +`ifdef CFG_TRACE_ENABLED 1.228 +// PC trace signals 1.229 +wire [`LM32_PC_RNG] trace_pc; // PC to trace (address of next non-sequential instruction) 1.230 +wire trace_pc_valid; // Indicates that a new trace PC is valid 1.231 +wire trace_exception; // Indicates an exception has occured 1.232 +wire [`LM32_EID_RNG] trace_eid; // Indicates what type of exception has occured 1.233 +wire trace_eret; // Indicates an eret instruction has been executed 1.234 +`ifdef CFG_DEBUG_ENABLED 1.235 +wire trace_bret; // Indicates a bret instruction has been executed 1.236 +`endif 1.237 +`endif 1.238 + 1.239 +///////////////////////////////////////////////////// 1.240 +// Functions 1.241 +///////////////////////////////////////////////////// 1.242 + 1.243 +`include "lm32_functions.v" 1.244 +///////////////////////////////////////////////////// 1.245 +// Instantiations 1.246 +///////////////////////////////////////////////////// 1.247 + 1.248 +// LM32 CPU 1.249 +lm32_cpu cpu ( 1.250 + // ----- Inputs ------- 1.251 + .clk_i (clk_i), 1.252 +`ifdef CFG_EBR_NEGEDGE_REGISTER_FILE 1.253 + .clk_n_i (clk_n), 1.254 +`endif 1.255 + .rst_i (rst_i), 1.256 + // From external devices 1.257 +`ifdef CFG_INTERRUPTS_ENABLED 1.258 + .interrupt_n (interrupt_n), 1.259 +`endif 1.260 + // From user logic 1.261 +`ifdef CFG_USER_ENABLED 1.262 + .user_result (user_result), 1.263 + .user_complete (user_complete), 1.264 +`endif 1.265 +`ifdef CFG_JTAG_ENABLED 1.266 + // From JTAG 1.267 + .jtag_clk (jtck), 1.268 + .jtag_update (jtag_update), 1.269 + .jtag_reg_q (jtag_reg_q), 1.270 + .jtag_reg_addr_q (jtag_reg_addr_q), 1.271 +`endif 1.272 +`ifdef CFG_IWB_ENABLED 1.273 + // Instruction Wishbone master 1.274 + .I_DAT_I (I_DAT_I), 1.275 + .I_ACK_I (I_ACK_I), 1.276 + .I_ERR_I (I_ERR_I), 1.277 + .I_RTY_I (I_RTY_I), 1.278 +`endif 1.279 + // Data Wishbone master 1.280 + .D_DAT_I (D_DAT_I), 1.281 + .D_ACK_I (D_ACK_I), 1.282 + .D_ERR_I (D_ERR_I), 1.283 + .D_RTY_I (D_RTY_I), 1.284 + // ----- Outputs ------- 1.285 +`ifdef CFG_TRACE_ENABLED 1.286 + .trace_pc (trace_pc), 1.287 + .trace_pc_valid (trace_pc_valid), 1.288 + .trace_exception (trace_exception), 1.289 + .trace_eid (trace_eid), 1.290 + .trace_eret (trace_eret), 1.291 +`ifdef CFG_DEBUG_ENABLED 1.292 + .trace_bret (trace_bret), 1.293 +`endif 1.294 +`endif 1.295 +`ifdef CFG_JTAG_ENABLED 1.296 + .jtag_reg_d (jtag_reg_d), 1.297 + .jtag_reg_addr_d (jtag_reg_addr_d), 1.298 +`endif 1.299 +`ifdef CFG_USER_ENABLED 1.300 + .user_valid (user_valid), 1.301 + .user_opcode (user_opcode), 1.302 + .user_operand_0 (user_operand_0), 1.303 + .user_operand_1 (user_operand_1), 1.304 +`endif 1.305 +`ifdef CFG_IWB_ENABLED 1.306 + // Instruction Wishbone master 1.307 + .I_DAT_O (I_DAT_O), 1.308 + .I_ADR_O (I_ADR_O), 1.309 + .I_CYC_O (I_CYC_O), 1.310 + .I_SEL_O (I_SEL_O), 1.311 + .I_STB_O (I_STB_O), 1.312 + .I_WE_O (I_WE_O), 1.313 + .I_CTI_O (I_CTI_O), 1.314 + .I_LOCK_O (I_LOCK_O), 1.315 + .I_BTE_O (I_BTE_O), 1.316 + `endif 1.317 + // Data Wishbone master 1.318 + .D_DAT_O (D_DAT_O), 1.319 + .D_ADR_O (D_ADR_O), 1.320 + .D_CYC_O (D_CYC_O), 1.321 + .D_SEL_O (D_SEL_O), 1.322 + .D_STB_O (D_STB_O), 1.323 + .D_WE_O (D_WE_O), 1.324 + .D_CTI_O (D_CTI_O), 1.325 + .D_LOCK_O (D_LOCK_O), 1.326 + .D_BTE_O (D_BTE_O) 1.327 + ); 1.328 + 1.329 + wire TRACE_ACK_O; 1.330 + wire [`LM32_WORD_RNG] TRACE_DAT_O; 1.331 +`ifdef CFG_TRACE_ENABLED 1.332 + lm32_trace trace_module (.clk_i (clk_i), 1.333 + .rst_i (rst_i), 1.334 + .stb_i (DEBUG_STB_I & DEBUG_ADR_I[13]), 1.335 + .we_i (DEBUG_WE_I), 1.336 + .sel_i (DEBUG_SEL_I), 1.337 + .dat_i (DEBUG_DAT_I), 1.338 + .adr_i (DEBUG_ADR_I), 1.339 + .trace_pc (trace_pc), 1.340 + .trace_eid (trace_eid), 1.341 + .trace_eret (trace_eret), 1.342 + .trace_bret (trace_bret), 1.343 + .trace_pc_valid (trace_pc_valid), 1.344 + .trace_exception (trace_exception), 1.345 + .ack_o (TRACE_ACK_O), 1.346 + .dat_o (TRACE_DAT_O)); 1.347 +`else 1.348 + assign TRACE_ACK_O = 0; 1.349 + assign TRACE_DAT_O = 0; 1.350 +`endif 1.351 +`ifdef DEBUG_ROM 1.352 + wire ROM_ACK_O; 1.353 + wire [`LM32_WORD_RNG] ROM_DAT_O; 1.354 + 1.355 + assign DEBUG_ACK_O = DEBUG_ADR_I[13] ? TRACE_ACK_O : ROM_ACK_O; 1.356 + assign DEBUG_DAT_O = DEBUG_ADR_I[13] ? TRACE_DAT_O : ROM_DAT_O; 1.357 + 1.358 + // ROM monitor 1.359 + lm32_monitor debug_rom ( 1.360 + // ----- Inputs ------- 1.361 + .clk_i (clk_i), 1.362 + .rst_i (rst_i), 1.363 + .MON_ADR_I (DEBUG_ADR_I), 1.364 + .MON_STB_I (DEBUG_STB_I & ~DEBUG_ADR_I[13]), 1.365 + .MON_CYC_I (DEBUG_CYC_I & ~DEBUG_ADR_I[13]), 1.366 + .MON_WE_I (DEBUG_WE_I), 1.367 + .MON_SEL_I (DEBUG_SEL_I), 1.368 + .MON_DAT_I (DEBUG_DAT_I), 1.369 + .MON_CTI_I (DEBUG_CTI_I), 1.370 + .MON_BTE_I (DEBUG_BTE_I), 1.371 + .MON_LOCK_I (DEBUG_LOCK_I), 1.372 + // ----- Outputs ------ 1.373 + .MON_RTY_O (DEBUG_RTY_O), 1.374 + .MON_ERR_O (DEBUG_ERR_O), 1.375 + .MON_ACK_O (ROM_ACK_O), 1.376 + .MON_DAT_O (ROM_DAT_O) 1.377 + ); 1.378 +`endif 1.379 + 1.380 +`ifdef CFG_JTAG_ENABLED 1.381 +// JTAG cores 1.382 +jtag_cores jtag_cores ( 1.383 + // ----- Inputs ----- 1.384 +`ifdef INCLUDE_LM32 1.385 + .reg_d (jtag_reg_d), 1.386 + .reg_addr_d (jtag_reg_addr_d), 1.387 +`endif 1.388 + // ----- Outputs ----- 1.389 +`ifdef INCLUDE_LM32 1.390 + .reg_update (jtag_update), 1.391 + .reg_q (jtag_reg_q), 1.392 + .reg_addr_q (jtag_reg_addr_q), 1.393 +`endif 1.394 + .jtck (jtck), 1.395 + .jrstn (jrstn) 1.396 + ); 1.397 +`endif 1.398 + 1.399 +endmodule