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

Subversion Repositories mpmc8

[/] [mpmc8/] [trunk/] [rtl/] [mpmc8_ch_prioritize.sv] - Blame information for rev 8

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

Line No. Rev Author Line
1 2 robfinch
`timescale 1ns / 1ps
2
// ============================================================================
3
//        __
4
//   \\__/ o\    (C) 2015-2022  Robert Finch, Waterloo
5
//    \  __ /    All rights reserved.
6
//     \/_//     robfinch@finitron.ca
7
//       ||
8
//
9
// BSD 3-Clause License
10
// Redistribution and use in source and binary forms, with or without
11
// modification, are permitted provided that the following conditions are met:
12
//
13
// 1. Redistributions of source code must retain the above copyright notice, this
14
//    list of conditions and the following disclaimer.
15
//
16
// 2. Redistributions in binary form must reproduce the above copyright notice,
17
//    this list of conditions and the following disclaimer in the documentation
18
//    and/or other materials provided with the distribution.
19
//
20
// 3. Neither the name of the copyright holder nor the names of its
21
//    contributors may be used to endorse or promote products derived from
22
//    this software without specific prior written permission.
23
//
24
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
//
35
// ============================================================================
36
//
37
import mpmc8_pkg::*;
38
 
39
module mpmc8_ch_prioritize(clk, state,
40
        cs0, cs1, cs2, cs3, cs4, cs5, cs6, cs7,
41
        we0, we1, we2, we3, we4, we5, we6, we7,
42
        ch0_taghit, ch1_taghit, ch2_taghit, ch3_taghit,
43
        ch4_taghit, ch5_taghit, ch6_taghit, ch7_taghit,
44
        ch);
45
input clk;
46
input [3:0] state;
47
input cs0;
48
input cs1;
49
input cs2;
50
input cs3;
51
input cs4;
52
input cs5;
53
input cs6;
54
input cs7;
55
input we0;
56
input we1;
57
input we2;
58
input we3;
59
input we4;
60
input we5;
61
input we6;
62
input we7;
63
input ch0_taghit;
64
input ch1_taghit;
65
input ch2_taghit;
66
input ch3_taghit;
67
input ch4_taghit;
68
input ch5_taghit;
69
input ch6_taghit;
70
input ch7_taghit;
71
output reg [3:0] ch;
72
 
73
// This counter used to periodically reverse channel priorities to help ensure
74
// that a particular channel isn't permanently blocked by other higher priority
75
// ones.
76
reg [5:0] elevate_cnt = 'd0;
77
reg elevate = 1'b0;
78
 
79
always_ff @(posedge clk)
80
if (state==PRESET1) begin
81
        elevate_cnt <= elevate_cnt + 6'd1;
82
        elevate <= elevate_cnt == 6'd63;
83
end
84
 
85
 
86
// Select the channel
87
// This prioritizes the channel during the IDLE state.
88
// During an elevate cycle the channel priorities are reversed.
89
always_ff @(posedge clk)
90
begin
91
        if (elevate) begin
92
                if (cs7 & we7)
93
                        ch <= 4'd7;
94
                else if (cs6 & we6)
95
                        ch <= 4'd6;
96
                else if (cs5 & we5)
97
                        ch <= 4'd5;
98
                else if (cs4 & we4)
99
                        ch <= 4'd4;
100
                else if (cs3 & we3)
101
                        ch <= 4'd3;
102
                else if (cs2 & we2)
103
                        ch <= 4'd2;
104
                else if (cs1 & we1)
105
                        ch <= 4'd1;
106
                else if (cs0 & we0)
107
                        ch <= 4'd0;
108
                else if (cs7 & ~ch7_taghit)
109
                        ch <= 4'd7;
110
                else if (cs6 & ~ch6_taghit)
111
                        ch <= 4'd6;
112
                else if (cs5 & ~ch5_taghit)
113
                        ch <= 4'd5;
114
                else if (cs4 & ~ch4_taghit)
115
                        ch <= 4'd4;
116
                else if (cs3 & ~ch3_taghit)
117
                        ch <= 4'd3;
118
                else if (cs2 & ~ch2_taghit)
119
                        ch <= 4'd2;
120
                else if (cs1 & ~ch1_taghit)
121
                        ch <= 4'd1;
122
                else if (cs0 & ~ch0_taghit)
123
                        ch <= 4'd0;
124
                else
125
                        ch <= 4'hF;
126
        end
127
        // Channel 0 read or write takes precedence
128
        else if (cs0 & we0)
129
                ch <= 4'd0;
130
        else if (cs0 & ~ch0_taghit)
131
                ch <= 4'd0;
132
        else if (cs1 & we1)
133
                ch <= 4'd1;
134
        else if (cs2 & we2)
135
                ch <= 4'd2;
136
        else if (cs3 & we3)
137
                ch <= 4'd3;
138
        else if (cs4 & we4)
139
                ch <= 4'd4;
140
        else if (cs6 & we6)
141
                ch <= 4'd6;
142
        else if (cs7 & we7)
143
                ch <= 4'd7;
144
        // Reads, writes detected above
145
        else if (cs1 & ~ch1_taghit)
146
                ch <= 4'd1;
147
        else if (cs2 & ~ch2_taghit)
148
                ch <= 4'd2;
149
        else if (cs3 & ~ch3_taghit)
150
                ch <= 4'd3;
151
        else if (cs4 & ~ch4_taghit)
152
                ch <= 4'd4;
153
        else if (cs5 & ~ch5_taghit)
154
                ch <= 4'd5;
155
        else if (cs6 & ~ch6_taghit)
156
                ch <= 4'd6;
157
        else if (cs7 & ~ch7_taghit)
158
                ch <= 4'd7;
159
        // Nothing selected
160
        else
161
                ch <= 4'hF;
162
end
163
 
164
endmodule

powered by: WebSVN 2.1.0

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