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

Subversion Repositories hive

[/] [hive/] [trunk/] [v01.09/] [reg_set_shim.v] - Blame information for rev 3

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

Line No. Rev Author Line
1 2 ericw
/*
2
--------------------------------------------------------------------------------
3
 
4
Module: reg_set_shim.v
5
 
6
Function:
7
- Shim to interface main memory and internal register set.
8
 
9
Instantiates:
10
- (2x) vector_sr.v
11
 
12
Notes:
13
- Address, data, and control I/O optionally registered.
14
- Register set is placed at the top of memory space, main mem at bottom.
15
 
16
--------------------------------------------------------------------------------
17
*/
18
 
19
module reg_set_shim
20
        #(
21
        parameter       integer                                                 REGS_IN                 = 1,            // register option for inputs
22
        parameter       integer                                                 REGS_OUT                        = 1,            // register option for outputs
23
        parameter       integer                                                 DATA_W                  = 16,           // data width (bits)
24
        parameter       integer                                                 ADDR_W                  = 8,            // address width (bits)
25
        parameter       integer                                                 REG_ADDR_W              = 4,            // register set address width (bits)
26
        parameter       integer                                                 IM_ADDR_W               = 4             // immediate address width
27
        )
28
        (
29
        // clocks & resets
30
        input                   wire                                                            clk_i,                                          // clock
31
        input                   wire                                                            rst_i,                                          // async. reset, active high
32
        // data I/O
33
        input                   wire    [DATA_W-1:0]                     a_i,                                                    // operand
34
        input                   wire                                                            ext_i,                                          // 1=extended result
35
        output          wire    [DATA_W/2-1:0]                   wr_data_o,                                      // write data
36
        // address I/O
37
        input                   wire    [DATA_W/2-1:0]                   b_lo_i,                                         // operand
38
        input                   wire    [IM_ADDR_W-1:0]          im_addr_i,                                      // immediate address
39
        input                   wire    [ADDR_W-1:0]                     pc_1_i,                                         // program counter
40
        output          wire    [ADDR_W-1:0]                     addr_o,                                         // address
41
        // bus I/O
42
        input                   wire                                                            wr_i,                                                   // data write enable, active high
43
        input                   wire                                                            rd_i,                                                   // data read enable, active high
44
        output          wire                                                            regs_wr_o,                                      // data write enable, active high
45
        output          wire                                                            regs_rd_o,                                      // data read enable, active high
46
        output          wire                                                            dm_wr_o                                         // data write enable, active high
47
        );
48
 
49
 
50
        /*
51
        ----------------------
52
        -- internal signals --
53
        ----------------------
54
        */
55
        wire                                    [DATA_W-1:0]                     a;
56
        wire                                    [DATA_W/2-1:0]                   b_lo;
57
        wire                                    [IM_ADDR_W-1:0]          im_addr;
58
        wire                                                                                            wr, rd, ext;
59
        wire                                    [ADDR_W-1:0]                     rw_addr, addr;
60
        wire                                                                                            regs_en, regs_wr, regs_rd, dm_wr;
61
        wire                                    [DATA_W/2-1:0]                   wr_data;
62
 
63
 
64
 
65
        /*
66
        ================
67
        == code start ==
68
        ================
69
        */
70
 
71
 
72
        // optional input regs
73
        vector_sr
74
        #(
75
        .REGS                   ( REGS_IN ),
76
        .DATA_W         ( DATA_W+DATA_W/2+IM_ADDR_W+3 ),
77
        .RESET_VAL      ( 0 )
78
        )
79
        in_regs
80
        (
81
        .clk_i          ( clk_i ),
82
        .rst_i          ( rst_i ),
83
        .data_i         ( { a_i, b_lo_i, im_addr_i, wr_i, rd_i, ext_i } ),
84
        .data_o         ( { a,   b_lo,   im_addr,   wr,   rd,   ext   } )
85
        );
86
 
87
 
88
        // read / write address
89
        assign rw_addr = b_lo + im_addr;
90
 
91
        // decode address
92
        assign addr = ( rd | wr ) ? rw_addr : pc_1_i;
93
 
94
        // decode register set address space (all upper bits set)
95
        assign regs_en = &addr[ADDR_W-1:REG_ADDR_W];
96
 
97
        // decode regs read & write
98
        assign regs_wr = wr & regs_en;
99
        assign regs_rd = rd & regs_en;
100
 
101
        // decode dmem write
102
        assign dm_wr = wr & ~regs_en;
103
 
104
        // decode write data
105
        assign wr_data = ( ext ) ? a[DATA_W-1:DATA_W/2] : a[DATA_W/2-1:0];
106
 
107
 
108
        // optional output registers
109
        vector_sr
110
        #(
111
        .REGS                   ( REGS_OUT ),
112
        .DATA_W         ( ADDR_W+DATA_W/2+3 ),
113
        .RESET_VAL      ( 0 )
114
        )
115
        out_regs
116
        (
117
        .clk_i          ( clk_i ),
118
        .rst_i          ( rst_i ),
119
        .data_i         ( { addr,   wr_data,   regs_wr,   regs_rd,   dm_wr   } ),
120
        .data_o         ( { addr_o, wr_data_o, regs_wr_o, regs_rd_o, dm_wr_o } )
121
        );
122
 
123
 
124
endmodule

powered by: WebSVN 2.1.0

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