OpenCores
URL https://opencores.org/ocsvn/amber/amber/trunk

Subversion Repositories amber

[/] [amber/] [trunk/] [hw/] [vlog/] [system/] [test_module.v] - Blame information for rev 32

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 csantifort
//////////////////////////////////////////////////////////////////
2
//                                                              //
3
//  Test Module                                                 //
4
//                                                              //
5
//  This file is part of the Amber project                      //
6
//  http://www.opencores.org/project,amber                      //
7
//                                                              //
8
//  Description                                                 //
9
//  Contains a random number generator and a couple of timers   //
10
//  that connect to interrupt lines. Used for testing the       //
11
//  ssytem.                                                     //
12
//                                                              //
13
//  Author(s):                                                  //
14
//      - Conor Santifort, csantifort.amber@gmail.com           //
15
//                                                              //
16
//////////////////////////////////////////////////////////////////
17
//                                                              //
18
// Copyright (C) 2010 Authors and OPENCORES.ORG                 //
19
//                                                              //
20
// This source file may be used and distributed without         //
21
// restriction provided that this copyright statement is not    //
22
// removed from the file and that any derivative work contains  //
23
// the original copyright notice and the associated disclaimer. //
24
//                                                              //
25
// This source file is free software; you can redistribute it   //
26
// and/or modify it under the terms of the GNU Lesser General   //
27
// Public License as published by the Free Software Foundation; //
28
// either version 2.1 of the License, or (at your option) any   //
29
// later version.                                               //
30
//                                                              //
31
// This source is distributed in the hope that it will be       //
32
// useful, but WITHOUT ANY WARRANTY; without even the implied   //
33
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
34
// PURPOSE.  See the GNU Lesser General Public License for more //
35
// details.                                                     //
36
//                                                              //
37
// You should have received a copy of the GNU Lesser General    //
38
// Public License along with this source; if not, download it   //
39
// from http://www.opencores.org/lgpl.shtml                     //
40
//                                                              //
41
//////////////////////////////////////////////////////////////////
42
 
43
 
44
module test_module (
45
input                       i_clk,
46
 
47
output                      o_irq,
48
output                      o_firq,
49 11 csantifort
output                      o_mem_ctrl,  // 0=128MB, 1=32MB
50 2 csantifort
input       [31:0]          i_wb_adr,
51
input       [3:0]           i_wb_sel,
52
input                       i_wb_we,
53
output      [31:0]          o_wb_dat,
54
input       [31:0]          i_wb_dat,
55
input                       i_wb_cyc,
56
input                       i_wb_stb,
57
output                      o_wb_ack,
58
output                      o_wb_err
59
 
60
 
61
);
62
 
63
`include "register_addresses.v"
64
 
65
 
66
reg [7:0]       firq_timer          = 'd0;
67
reg [7:0]       irq_timer           = 'd0;
68
reg [7:0]       random_num          = 8'hf3;
69
 
70
//synopsys translate_off
71
reg [1:0]       tb_uart_control_reg = 'd0;
72
reg [1:0]       tb_uart_status_reg  = 'd0;
73
reg             tb_uart_push        = 'd0;
74
reg [7:0]       tb_uart_txd_reg     = 'd0;
75
//synopsys translate_on
76
 
77 11 csantifort
reg [2:0]       sim_ctrl_reg        = 'd0; // 0 = fpga, other values for simulations
78
reg             mem_ctrl_reg        = 'd0; // 0 = 128MB, 1 = 32MB main memory
79 2 csantifort
reg [31:0]      test_status_reg     = 'd0;
80
reg             test_status_set     = 'd0; // used to terminate tests
81 32 csantifort
reg [31:0]      cycles_reg          = 'd0;
82 2 csantifort
 
83
wire            wb_start_write;
84
wire            wb_start_read;
85
reg             wb_start_read_d1    = 'd0;
86
reg  [31:0]     wb_rdata            = 'd0;
87
 
88
// Can't start a write while a read is completing. The ack for the read cycle
89
// needs to be sent first
90
assign wb_start_write = i_wb_stb && i_wb_we && !wb_start_read_d1;
91
assign wb_start_read  = i_wb_stb && !i_wb_we && !o_wb_ack;
92
 
93
always @( posedge i_clk )
94
    wb_start_read_d1 <= wb_start_read;
95
 
96 11 csantifort
assign o_wb_ack   = i_wb_stb && ( wb_start_write || wb_start_read_d1 );
97
assign o_wb_err   = 1'd0;
98
assign o_wb_dat   = wb_rdata;
99
assign o_mem_ctrl = mem_ctrl_reg;
100 2 csantifort
 
101
// ========================================================
102
// Register Reads
103
// ========================================================
104
always @( posedge i_clk )
105
    if ( wb_start_read )
106
        case ( i_wb_adr[15:0] )
107
            AMBER_TEST_STATUS:           wb_rdata <= test_status_reg;
108 11 csantifort
            AMBER_TEST_FIRQ_TIMER:       wb_rdata <= {24'd0, firq_timer};
109 2 csantifort
            AMBER_TEST_IRQ_TIMER:        wb_rdata <= {24'd0, irq_timer};
110
            AMBER_TEST_RANDOM_NUM:       wb_rdata <= {24'd0, random_num};
111
 
112
            /* Allow access to the random register over
113
               a 16-word address range to load a series
114
               of random numbers using lmd instruction. */
115
            AMBER_TEST_RANDOM_NUM00: wb_rdata <= {24'd0, random_num};
116
            AMBER_TEST_RANDOM_NUM01: wb_rdata <= {24'd0, random_num};
117
            AMBER_TEST_RANDOM_NUM02: wb_rdata <= {24'd0, random_num};
118
            AMBER_TEST_RANDOM_NUM03: wb_rdata <= {24'd0, random_num};
119
            AMBER_TEST_RANDOM_NUM04: wb_rdata <= {24'd0, random_num};
120
            AMBER_TEST_RANDOM_NUM05: wb_rdata <= {24'd0, random_num};
121
            AMBER_TEST_RANDOM_NUM06: wb_rdata <= {24'd0, random_num};
122
            AMBER_TEST_RANDOM_NUM07: wb_rdata <= {24'd0, random_num};
123
            AMBER_TEST_RANDOM_NUM08: wb_rdata <= {24'd0, random_num};
124
            AMBER_TEST_RANDOM_NUM09: wb_rdata <= {24'd0, random_num};
125
            AMBER_TEST_RANDOM_NUM10: wb_rdata <= {24'd0, random_num};
126
            AMBER_TEST_RANDOM_NUM11: wb_rdata <= {24'd0, random_num};
127
            AMBER_TEST_RANDOM_NUM12: wb_rdata <= {24'd0, random_num};
128
            AMBER_TEST_RANDOM_NUM13: wb_rdata <= {24'd0, random_num};
129
            AMBER_TEST_RANDOM_NUM14: wb_rdata <= {24'd0, random_num};
130
            AMBER_TEST_RANDOM_NUM15: wb_rdata <= {24'd0, random_num};
131
 
132
            //synopsys translate_off
133
            AMBER_TEST_UART_CONTROL:     wb_rdata <= {30'd0, tb_uart_control_reg};
134
            AMBER_TEST_UART_STATUS:      wb_rdata <= {30'd0, tb_uart_status_reg};
135
            AMBER_TEST_UART_TXD:         wb_rdata <= {24'd0, tb_uart_txd_reg};
136
            //synopsys translate_on
137
 
138 11 csantifort
            AMBER_TEST_SIM_CTRL:         wb_rdata <= {29'd0, sim_ctrl_reg};
139
            AMBER_TEST_MEM_CTRL:         wb_rdata <= {31'd0, mem_ctrl_reg};
140 32 csantifort
 
141
            AMBER_TEST_CYCLES:           wb_rdata <=  cycles_reg;
142 2 csantifort
            default:                     wb_rdata <= 32'haabbccdd;
143
 
144
        endcase
145
 
146
 
147
// ======================================
148
// Simulation bit
149
// ======================================
150
 
151
// This register bit is a 1 in simulation but a 0 in the real fpga
152
// Used by software to tell the difference    
153
//synopsys translate_off
154
 
155
`ifndef AMBER_SIM_CTRL
156
    `define AMBER_SIM_CTRL 0
157
`endif
158
 
159
always @( posedge i_clk )
160
    begin
161
    // Value reads as 1 in simulation, and zero in the FPGA
162 11 csantifort
    sim_ctrl_reg <= 3'd `AMBER_SIM_CTRL ;
163 2 csantifort
    end
164
//synopsys translate_on
165
 
166
 
167
// ======================================
168
// Interrupts
169
// ======================================
170
assign o_irq  = irq_timer  == 8'd1;
171
assign o_firq = firq_timer == 8'd1;
172
 
173
 
174
// ======================================
175
// FIRQ Timer Register
176
// ======================================
177
    // Write a value > 1 to set the firq timer
178
    // Write 0 to clear it
179
always @( posedge i_clk )
180
    if ( wb_start_write && i_wb_adr[15:0] == AMBER_TEST_FIRQ_TIMER )
181
        firq_timer <= i_wb_dat[7:0];
182
    else if ( firq_timer > 8'd1 )
183
        firq_timer <= firq_timer - 1'd1;
184
 
185
 
186
// ======================================
187
// IRQ Timer Register
188
// ======================================
189
    // Write a value > 1 to set the irq timer
190
    // Write 0 to clear it
191
always @( posedge i_clk )
192
    if ( wb_start_write && i_wb_adr[15:0] == AMBER_TEST_IRQ_TIMER )
193
        irq_timer <= i_wb_dat[7:0];
194
    else if ( irq_timer > 8'd1 )
195
        irq_timer <= irq_timer - 1'd1;
196
 
197
 
198
// ======================================
199
// Random Number Generator Register
200
// ======================================
201
// Write a value > 1 to set the irq timer
202
// Write 0 to clear it
203
always @( posedge i_clk )
204
    begin
205
    if ( wb_start_write && i_wb_adr[15:8] == AMBER_TEST_RANDOM_NUM[15:8] )
206
        random_num <= i_wb_dat[7:0];
207
 
208
    // generate a new random number on every read access
209
    else if ( wb_start_read && i_wb_adr[15:8] == AMBER_TEST_RANDOM_NUM[15:8] )
210
        random_num <= { random_num[3]^random_num[1],
211
                        random_num[0]^random_num[5],
212
                        ~random_num[7]^random_num[4],
213
                        ~random_num[2],
214
                        random_num[6],
215
                        random_num[4]^~random_num[3],
216
                        random_num[7]^~random_num[1],
217
                        random_num[7]
218
                      };
219
    end
220
 
221
 
222
// ======================================
223
// Test Status Write
224
// ======================================
225
always @( posedge i_clk )
226
    if ( wb_start_write && i_wb_adr[15:0] == AMBER_TEST_STATUS )
227
        test_status_reg <= i_wb_dat;
228
 
229
 
230
// ======================================
231
// Test Status Write
232
// ======================================
233
always @( posedge i_clk )
234
    if ( wb_start_write && i_wb_adr[15:0] == AMBER_TEST_STATUS )
235
        test_status_set <= 1'd1;
236
 
237
 
238
// ======================================
239 32 csantifort
// Cycles counter
240
// ======================================
241
always @( posedge i_clk )
242
    cycles_reg <= cycles_reg + 1'd1;
243
 
244
 
245
// ======================================
246 11 csantifort
// Memory Configuration Register Write
247
// ======================================
248
always @( posedge i_clk )
249
    if ( wb_start_write && i_wb_adr[15:0] == AMBER_TEST_MEM_CTRL )
250
        mem_ctrl_reg <= i_wb_dat[0];
251
 
252
 
253
// ======================================
254 2 csantifort
// Test UART registers
255
// ======================================
256
// These control the testbench UART, not the real
257
// UART in system
258
 
259
//synopsys translate_off
260
always @( posedge i_clk )
261
    begin
262
    if ( wb_start_write && i_wb_adr[15:0] == AMBER_TEST_UART_CONTROL )
263
        tb_uart_control_reg <= i_wb_dat[1:0];
264
 
265
    if ( wb_start_write && i_wb_adr[15:0] == AMBER_TEST_UART_TXD )
266
        begin
267
        tb_uart_txd_reg   <= i_wb_dat[7:0];
268
        tb_uart_push      <= !tb_uart_push;
269
        end
270
    end
271
//synopsys translate_on
272
 
273
 
274
 
275
endmodule
276
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.