1 |
29 |
ns32kum |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
2 |
9 |
ns32kum |
//
|
3 |
|
|
// This file is part of the M32632 project
|
4 |
|
|
// http://opencores.org/project,m32632
|
5 |
|
|
//
|
6 |
23 |
ns32kum |
// Filename: TOP_MISC.v
|
7 |
29 |
ns32kum |
// Version: 3.0
|
8 |
23 |
ns32kum |
// History: 1.0 first release of 30 Mai 2015
|
9 |
29 |
ns32kum |
// Date: 2 December 2018
|
10 |
9 |
ns32kum |
//
|
11 |
29 |
ns32kum |
// Copyright (C) 2018 Udo Moeller
|
12 |
9 |
ns32kum |
//
|
13 |
|
|
// This source file may be used and distributed without
|
14 |
|
|
// restriction provided that this copyright statement is not
|
15 |
|
|
// removed from the file and that any derivative work contains
|
16 |
|
|
// the original copyright notice and the associated disclaimer.
|
17 |
|
|
//
|
18 |
|
|
// This source file is free software; you can redistribute it
|
19 |
|
|
// and/or modify it under the terms of the GNU Lesser General
|
20 |
|
|
// Public License as published by the Free Software Foundation;
|
21 |
|
|
// either version 2.1 of the License, or (at your option) any
|
22 |
|
|
// later version.
|
23 |
|
|
//
|
24 |
|
|
// This source is distributed in the hope that it will be
|
25 |
|
|
// useful, but WITHOUT ANY WARRANTY; without even the implied
|
26 |
|
|
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
27 |
|
|
// PURPOSE. See the GNU Lesser General Public License for more
|
28 |
|
|
// details.
|
29 |
|
|
//
|
30 |
|
|
// You should have received a copy of the GNU Lesser General
|
31 |
|
|
// Public License along with this source; if not, download it
|
32 |
|
|
// from http://www.opencores.org/lgpl.shtml
|
33 |
|
|
//
|
34 |
29 |
ns32kum |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
35 |
9 |
ns32kum |
//
|
36 |
|
|
// Modules contained in this file:
|
37 |
|
|
// 1. IO_SWITCH Switch between ICACHE and DCACHE to IO Path
|
38 |
|
|
// 2. MAKE_STAT Generate Statistic Signals
|
39 |
|
|
//
|
40 |
11 |
ns32kum |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
41 |
9 |
ns32kum |
|
42 |
11 |
ns32kum |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
43 |
9 |
ns32kum |
//
|
44 |
|
|
// 1. IO_SWITCH Switch between ICACHE and DCACHE to IO Path
|
45 |
|
|
//
|
46 |
11 |
ns32kum |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
47 |
|
|
module IO_SWITCH ( BCLK, BRESET, I_IOA, D_IOA, I_IORD, D_IORD, D_IOWR, IO_READY, GENSTAT, D_IOBE, ILO_SIG, DCWACC,
|
48 |
9 |
ns32kum |
IO_A, IO_RD, IO_WR, IO_BE, I_IORDY, D_IORDY, STATUS, ILO );
|
49 |
|
|
|
50 |
|
|
input BCLK,BRESET;
|
51 |
|
|
input [31:0] I_IOA,D_IOA;
|
52 |
|
|
input I_IORD;
|
53 |
|
|
input D_IORD,D_IOWR;
|
54 |
|
|
input [3:0] D_IOBE;
|
55 |
|
|
input IO_READY;
|
56 |
|
|
input [2:0] GENSTAT;
|
57 |
|
|
input ILO_SIG;
|
58 |
|
|
input [1:0] DCWACC;
|
59 |
|
|
|
60 |
|
|
output [31:0] IO_A;
|
61 |
|
|
output IO_RD,IO_WR;
|
62 |
|
|
output [3:0] IO_BE;
|
63 |
|
|
output I_IORDY;
|
64 |
|
|
output D_IORDY;
|
65 |
|
|
output [3:0] STATUS;
|
66 |
|
|
output ILO;
|
67 |
|
|
|
68 |
|
|
reg [3:0] STATUS;
|
69 |
|
|
reg [1:0] select;
|
70 |
|
|
reg ilo_flag;
|
71 |
|
|
|
72 |
|
|
wire daten;
|
73 |
|
|
wire sel_dp;
|
74 |
|
|
wire interrupt;
|
75 |
|
|
wire ilo_keep;
|
76 |
|
|
|
77 |
|
|
assign daten = D_IORD | D_IOWR;
|
78 |
|
|
|
79 |
|
|
// DCACHE has priority.
|
80 |
|
|
always @(posedge BCLK or negedge BRESET)
|
81 |
|
|
if (!BRESET) select <= 2'b0;
|
82 |
|
|
else
|
83 |
|
|
casex ({I_IORD,D_IORD,D_IOWR,IO_READY,ilo_keep,select})
|
84 |
|
|
7'b000xx_00 : select <= 2'b00;
|
85 |
|
|
7'b1000x_00 : select <= 2'b11;
|
86 |
|
|
7'bx100x_00 : select <= 2'b10;
|
87 |
|
|
7'bxx10x_00 : select <= 2'b10;
|
88 |
|
|
// the access has in the same cycle a READY !
|
89 |
|
|
7'b1001x_00 : select <= 2'b00;
|
90 |
|
|
7'bx101x_00 : select <= 2'b00;
|
91 |
|
|
7'bxx11x_00 : select <= 2'b00;
|
92 |
|
|
// Datea Access
|
93 |
|
|
7'bxxx0x_10 : select <= 2'b10;
|
94 |
|
|
7'bxxx11_10 : select <= 2'b10; // keep because of Interlocked
|
95 |
|
|
7'bxxx10_10 : select <= 2'b00;
|
96 |
|
|
// Instruction Access
|
97 |
|
|
7'bxxx0x_11 : select <= 2'b11;
|
98 |
|
|
7'bxxx1x_11 : select <= 2'b00;
|
99 |
|
|
default : select <= 2'b00;
|
100 |
|
|
endcase
|
101 |
|
|
|
102 |
|
|
assign sel_dp = (select == 2'b10) | ((select == 2'b00) & daten);
|
103 |
|
|
|
104 |
|
|
assign IO_RD = sel_dp ? D_IORD : I_IORD;
|
105 |
|
|
assign IO_WR = sel_dp ? D_IOWR : 1'b0;
|
106 |
|
|
assign IO_A = sel_dp ? D_IOA : I_IOA;
|
107 |
|
|
assign IO_BE = sel_dp ? D_IOBE : 4'b1111; // Instruction read always 32 Bit
|
108 |
|
|
|
109 |
|
|
assign D_IORDY = sel_dp & IO_READY;
|
110 |
29 |
ns32kum |
assign I_IORDY = ~sel_dp & IO_READY & I_IORD;
|
111 |
9 |
ns32kum |
|
112 |
|
|
assign interrupt = GENSTAT[1] | GENSTAT[0];
|
113 |
|
|
|
114 |
|
|
always @(*)
|
115 |
|
|
casex ({sel_dp,daten,interrupt,I_IORD})
|
116 |
|
|
4'b110x : STATUS = 4'hA; // Daten
|
117 |
|
|
4'b111x : STATUS = GENSTAT[1] ? 4'h4 : 4'h6; // Int Ack. : End of Int
|
118 |
|
|
4'b0xx1 : STATUS = 4'h8; // Programm
|
119 |
|
|
default : STATUS = {3'd0,GENSTAT[2]}; // WAIT or Inactive
|
120 |
|
|
endcase
|
121 |
|
|
|
122 |
|
|
// +++++++++++ ILO Control ++++++++++++++++++
|
123 |
|
|
|
124 |
|
|
always @(posedge BCLK)
|
125 |
|
|
if (!ILO_SIG) ilo_flag <= 1'b0; // Flag is set at read and cleared with write
|
126 |
|
|
else ilo_flag <= (D_IORD & sel_dp) | DCWACC[0] | ilo_keep;
|
127 |
|
|
|
128 |
|
|
assign ilo_keep = ilo_flag & ~D_IOWR & ~DCWACC[1];
|
129 |
|
|
|
130 |
|
|
assign ILO = ILO_SIG & ((D_IORD & sel_dp) | DCWACC[0] | ilo_flag | D_IOWR | DCWACC[1]);
|
131 |
|
|
|
132 |
|
|
endmodule
|
133 |
|
|
|
134 |
11 |
ns32kum |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
135 |
9 |
ns32kum |
//
|
136 |
|
|
// 2. MAKE_STAT Generate Statistic Signals
|
137 |
|
|
//
|
138 |
11 |
ns32kum |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
139 |
|
|
module MAKE_STAT ( BCLK, READ, DACC_OK, DC_ACC, DPTE_ACC, DC_MDONE, DRAM_WR, IC_READ, IACC_OK, DATA_HOLD,
|
140 |
9 |
ns32kum |
IC_ACC, IPTE_ACC, IC_MDONE, KOLLISION, STATSIGS );
|
141 |
|
|
|
142 |
|
|
input BCLK;
|
143 |
|
|
input READ,DACC_OK;
|
144 |
|
|
input DC_ACC,DPTE_ACC,DC_MDONE;
|
145 |
|
|
input DRAM_WR;
|
146 |
|
|
input IC_READ,IACC_OK,DATA_HOLD;
|
147 |
|
|
input IC_ACC,IPTE_ACC,IC_MDONE;
|
148 |
|
|
input KOLLISION;
|
149 |
|
|
|
150 |
|
|
output reg [7:0] STATSIGS;
|
151 |
|
|
|
152 |
|
|
always @(posedge BCLK)
|
153 |
|
|
begin
|
154 |
|
|
STATSIGS[7] <= KOLLISION; // 7 : from ICACHE : collisions
|
155 |
|
|
STATSIGS[6] <= IPTE_ACC; // 6 : Instruction PTE access
|
156 |
|
|
STATSIGS[5] <= IC_ACC & IC_MDONE; // 5 : Instruction Memory read
|
157 |
|
|
STATSIGS[4] <= IC_READ & IACC_OK & ~DATA_HOLD; // 4 : Instruction read , can be IO-Port too !
|
158 |
|
|
STATSIGS[3] <= DRAM_WR; // 3 : Data write
|
159 |
|
|
STATSIGS[2] <= DPTE_ACC; // 2 : Data PTE access
|
160 |
|
|
STATSIGS[1] <= DC_ACC & DC_MDONE; // 1 : Data Memory read
|
161 |
|
|
STATSIGS[0] <= READ & DACC_OK; // 0 : Data read , can be IO-Port too !
|
162 |
|
|
end
|
163 |
|
|
|
164 |
|
|
endmodule
|
165 |
|
|
|