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

Subversion Repositories hive

[/] [hive/] [trunk/] [v01.10/] [pointer_ring.v] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 ericw
/*
2
--------------------------------------------------------------------------------
3
 
4
Module : pointer_ring.v
5
 
6
--------------------------------------------------------------------------------
7
 
8
Function:
9
- Processor stack pointer storage ring.
10
 
11
Instantiates:
12
- (1x) vector_sr.v
13
 
14
Notes:
15
- 8 stage pointer storage ring for four BRAM based LIFOs:
16
 
17
  1 : pop applied
18
  2 : push applied; pop errors output
19
  3 : push errors output
20
  6 : pointers & writes output
21
- Logic assumes pop | push will not be issued simultaneously with clear.
22
- Externally concatenate thread 6 & pointers to form stack memory addresses.
23
- Level width is PTR_W+1 to accomodate 0 to 2^n levels (1 + 2n states).
24
- Empty push is to address 1, full push is to address 0.
25
- Combo pop/push is accomodated with no net fullness/pointer change.
26
- Pop when empty is a pop error.
27
- Push when full is a push error.
28
- Pop/push when full is NOT an error.
29
- Pop/push when empty is a pop error ONLY.
30
- Parameterized stack error handling.  If the associated protection is turned on
31
  then pop/push errors are reported but otherwise not acted upon, i.e. errors
32
  will not corrupt fullness/pointers.
33
 
34
--------------------------------------------------------------------------------
35
*/
36
 
37
module pointer_ring
38
        #(
39
        parameter       integer                                                 THREADS                 = 8,            // threads
40
        parameter       integer                                                 STACKS                  = 4,            // stacks
41
        parameter       integer                                                 PNTR_W                  = 5,            // stack pointer width
42
        parameter       integer                                                 POP_PROT                        = 1,            // 1=error protection, 0=none
43
        parameter       integer                                                 PUSH_PROT               = 1             // 1=error protection, 0=none
44
        )
45
        (
46
        // clocks & resets
47
        input                   wire                                                            clk_i,                                          // clock
48
        input                   wire                                                            rst_i,                                          // async. reset, active high
49
        // control I/O
50
        input                   wire                                                            clr_i,                                          // stacks clear
51
        input                   wire    [STACKS-1:0]                     pop_i,                                          // stacks pop
52
        input                   wire    [STACKS-1:0]                     push_i,                                         // stacks push
53
        // pointers
54
        output          wire    [PNTR_W-1:0]                     pntr0_o,                                                // stack pointer
55
        output          wire    [PNTR_W-1:0]                     pntr1_o,                                                // stack pointer
56
        output          wire    [PNTR_W-1:0]                     pntr2_o,                                                // stack pointer
57
        output          wire    [PNTR_W-1:0]                     pntr3_o,                                                // stack pointer
58
        // write enables
59
        output          wire    [STACKS-1:0]                     wr_o,                                                   // write enables
60
        // errors
61
        output          wire    [STACKS-1:0]                     pop_er_o,                                       // pop when empty, active high 
62
        output          wire    [STACKS-1:0]                     push_er_o                                       // push when full, active high
63
        );
64
 
65
 
66
        /*
67
        ----------------------
68
        -- internal signals --
69
        ----------------------
70
        */
71
        localparam      integer                                                 LEVEL_W                 = PNTR_W+1;  // +1 extra bit
72
        localparam      [LEVEL_W-1:0]                                    EMPTY_VAL               = 'b0;  // empty value
73
        localparam      [LEVEL_W-1:0]                                    FULL_VAL                        = 1'b1 << PNTR_W;  // full value
74
        //
75
        integer                                                                                 s, t;
76
        //
77
        reg                                     [LEVEL_W-1:0]                    level[0:STACKS-1][0:THREADS-1];
78
        //
79
        reg                                     [STACKS-1:0]                     pop_1, push_1, push_2;
80
        reg                                     [STACKS-1:0]                     empty_1, full_2;
81
        wire                                    [STACKS-1:0]                     dec_1, inc_2;
82
        reg                                     [STACKS-1:0]                     pop_er_2, push_er_3;
83
 
84
 
85
        /*
86
        ================
87
        == code start ==
88
        ================
89
        */
90
 
91
 
92
        // pipeline control signals
93
        always @ ( posedge clk_i or posedge rst_i ) begin
94
                if ( rst_i ) begin
95
                        pop_1 <= 'b0;
96
                        push_1 <= 'b0;
97
                        push_2 <= 'b0;
98
                end else begin
99
                        pop_1 <= pop_i;
100
                        push_1 <= push_i;
101
                        push_2 <= push_1;
102
                end
103
        end
104
 
105
        // decode watermarks
106
        always @ ( * ) begin
107
                for ( s=0; s<STACKS; s=s+1 ) begin
108
                        empty_1[s] <= ( level[s][1] == EMPTY_VAL );
109
                        full_2[s] <= ( level[s][2] == FULL_VAL );
110
                end
111
        end
112
 
113
        // prohibit pointer changes @ errors if configured to do so
114
        assign dec_1 = ( POP_PROT ) ? pop_1 & ~empty_1 : pop_1;
115
        assign inc_2 = ( PUSH_PROT ) ? push_2 & ~full_2 : push_2;
116
 
117
        // decode & register errors - pop when empty, push when full
118
        always @ ( posedge clk_i or posedge rst_i ) begin
119
                if ( rst_i ) begin
120
                        pop_er_2 <= 'b0;
121
                        push_er_3 <= 'b0;
122
                end else begin
123
                        pop_er_2 <= pop_1 & empty_1;
124
                        push_er_3 <= push_2 & full_2;
125
                end
126
        end
127
 
128
        // decode & pipeline levels
129
        always @ ( posedge clk_i or posedge rst_i ) begin
130
                if ( rst_i ) begin
131
                        for ( s=0; s<STACKS; s=s+1 ) begin
132
                                for ( t=0; t<THREADS; t=t+1 ) begin
133
                                        level[s][t] <= 'b0;
134
                                end
135
                        end
136
                end else begin
137
                        for ( s=0; s<STACKS; s=s+1 ) begin
138
                                for ( t=0; t<THREADS; t=t+1 ) begin
139
                                        if ( t == 0 ) level[s][t] <= level[s][THREADS-1];  // wrap around
140
                                        else if ( t == 1 ) level[s][t] <= ( clr_i ) ? 1'b0 : level[s][t-1];  // clear
141
                                        else if ( t == 2 ) level[s][t] <= ( dec_1[s] ) ? level[s][t-1] - 1'b1 : level[s][t-1];  // pop
142
                                        else if ( t == 3 ) level[s][t] <= ( inc_2[s] ) ? level[s][t-1] + 1'b1 : level[s][t-1];  // push
143
                                        else level[s][t] <= level[s][t-1];
144
                                end
145
                        end
146
                end
147
        end
148
 
149
 
150
        // decode & pipeline write enables
151
        vector_sr
152
        #(
153
        .REGS                   ( 4 ),
154
        .DATA_W         ( STACKS ),
155
        .RESET_VAL      ( 0 )
156
        )
157
        wr_pipe
158
        (
159
        .clk_i          ( clk_i ),
160
        .rst_i          ( rst_i ),
161
        .data_i         ( inc_2 ),
162
        .data_o         ( wr_o )
163
        );
164
 
165
 
166
        // output pointers
167
        assign pntr0_o = level[0][6][PNTR_W-1:0];
168
        assign pntr1_o = level[1][6][PNTR_W-1:0];
169
        assign pntr2_o = level[2][6][PNTR_W-1:0];
170
        assign pntr3_o = level[3][6][PNTR_W-1:0];
171
 
172
        // output errors
173
        assign pop_er_o = pop_er_2;
174
        assign push_er_o = push_er_3;
175
 
176
 
177
endmodule

powered by: WebSVN 2.1.0

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