1 |
15 |
jeaander |
//////////////////////////////////////////////////////////////////////
|
2 |
|
|
//// ////
|
3 |
|
|
//// wb_interface.v ////
|
4 |
|
|
//// ////
|
5 |
|
|
//// ////
|
6 |
|
|
//// This file is part of the Weigand Controller ////
|
7 |
|
|
//// http://www.opencores.org/projects/wiegand/ ////
|
8 |
|
|
//// ////
|
9 |
|
|
//// ////
|
10 |
|
|
//// Author(s): ////
|
11 |
|
|
//// Jeff Anderson ////
|
12 |
|
|
//// jeaander@opencores.org ////
|
13 |
|
|
//// ////
|
14 |
|
|
//// ////
|
15 |
|
|
//// All additional information is available in the README.txt ////
|
16 |
|
|
//// file. ////
|
17 |
|
|
//// ////
|
18 |
|
|
//////////////////////////////////////////////////////////////////////
|
19 |
|
|
//// ////
|
20 |
|
|
//// Copyright (C) 2013 Authors ////
|
21 |
|
|
//// ////
|
22 |
|
|
//// This source file may be used and distributed without ////
|
23 |
|
|
//// restriction provided that this copyright statement is not ////
|
24 |
|
|
//// removed from the file and that any derivative work contains ////
|
25 |
|
|
//// the original copyright notice and the associated disclaimer. ////
|
26 |
|
|
//// ////
|
27 |
|
|
//// This source file is free software; you can redistribute it ////
|
28 |
|
|
//// and/or modify it under the terms of the GNU Lesser General ////
|
29 |
|
|
//// Public License as published by the Free Software Foundation; ////
|
30 |
|
|
//// either version 2.1 of the License, or (at your option) any ////
|
31 |
|
|
//// later version. ////
|
32 |
|
|
//// ////
|
33 |
|
|
//// This source is distributed in the hope that it will be ////
|
34 |
|
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
35 |
|
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
36 |
|
|
//// PURPOSE. See the GNU Lesser General Public License for more ////
|
37 |
|
|
//// details. ////
|
38 |
|
|
//// ////
|
39 |
|
|
//// You should have received a copy of the GNU Lesser General ////
|
40 |
|
|
//// Public License along with this source; if not, download it ////
|
41 |
|
|
//// from http://www.opencores.org/lgpl.shtml ////
|
42 |
|
|
//// ////
|
43 |
|
|
//// ////
|
44 |
|
|
//////////////////////////////////////////////////////////////////////
|
45 |
|
|
//
|
46 |
|
|
// Revisions at end of file
|
47 |
|
|
//
|
48 |
|
|
|
49 |
|
|
|
50 |
|
|
// synopsys translate_off
|
51 |
|
|
`include "timescale.v"
|
52 |
|
|
// synopsys translate_on
|
53 |
|
|
|
54 |
|
|
//WB interface definitions imported from wiegand_defines
|
55 |
|
|
`include "wiegand_defines.v"
|
56 |
|
|
|
57 |
|
|
module wb_interface_wieg (
|
58 |
|
|
// WB bus
|
59 |
|
|
wb_rst_i,
|
60 |
|
|
wb_clk_i,
|
61 |
|
|
|
62 |
|
|
wb_stb_i,
|
63 |
|
|
wb_ack_o,
|
64 |
|
|
wb_addr_i,
|
65 |
|
|
wb_we_i,
|
66 |
|
|
wb_dat_i,
|
67 |
|
|
wb_sel_i,
|
68 |
|
|
wb_dat_o,
|
69 |
|
|
wb_cyc_i,
|
70 |
|
|
wb_cti_i,
|
71 |
|
|
wb_err_o,
|
72 |
|
|
wb_rty_o,
|
73 |
|
|
|
74 |
|
|
rst_o,
|
75 |
|
|
dat_o,
|
76 |
|
|
dat_i,
|
77 |
|
|
msgLength,
|
78 |
|
|
start_tx,
|
79 |
|
|
p2p,
|
80 |
|
|
pulsewidth,
|
81 |
|
|
clk_o,
|
82 |
|
|
full,
|
83 |
|
|
lock_cfg_i,
|
84 |
|
|
wb_wr_en,
|
85 |
|
|
rst_FIFO,
|
86 |
|
|
wb_rd_en
|
87 |
|
|
);
|
88 |
|
|
|
89 |
|
|
//--------------------------------------
|
90 |
|
|
// Wish Bone Interface
|
91 |
|
|
// -------------------------------------
|
92 |
|
|
input wb_rst_i;
|
93 |
|
|
input wb_clk_i;
|
94 |
|
|
input wb_stb_i;
|
95 |
|
|
output wb_ack_o;
|
96 |
|
|
input [`WB_ADDR_WIDTH-1:0] wb_addr_i;
|
97 |
|
|
input wb_we_i; // 1 - Write , 0 - Read
|
98 |
|
|
input [`WB_WIDTH-1:0] wb_dat_i;
|
99 |
|
|
input [(`WB_WIDTH/8)-1:0] wb_sel_i; // Byte enable
|
100 |
|
|
output [`WB_WIDTH-1:0] dat_o;
|
101 |
|
|
input [`WB_WIDTH-1:0] dat_i; //data to and from WB interface, but not on WB
|
102 |
|
|
output [`WB_WIDTH-1:0] wb_dat_o;
|
103 |
|
|
input wb_cyc_i;
|
104 |
|
|
input [2:0] wb_cti_i;
|
105 |
|
|
output wb_err_o;
|
106 |
|
|
output wb_rty_o;
|
107 |
|
|
|
108 |
|
|
//----------------------------------------
|
109 |
|
|
// interface to Weigand control logic
|
110 |
|
|
//----------------------------------------
|
111 |
|
|
output rst_o;
|
112 |
|
|
wire rst;
|
113 |
|
|
wire rty_int;
|
114 |
|
|
wire err_int;
|
115 |
|
|
|
116 |
|
|
output reg [`WB_WIDTH-1:0] pulsewidth;
|
117 |
|
|
output reg [`WB_WIDTH-1:0] p2p;
|
118 |
|
|
output [6:0] msgLength;
|
119 |
|
|
output start_tx;
|
120 |
|
|
output clk_o;
|
121 |
|
|
input full;
|
122 |
|
|
input lock_cfg_i;
|
123 |
|
|
output wb_wr_en;
|
124 |
|
|
output rst_FIFO;
|
125 |
|
|
output wb_rd_en;
|
126 |
|
|
|
127 |
|
|
wire [`WB_WIDTH-1:0] wb_dat_rdbk;
|
128 |
|
|
reg [8:0] size;
|
129 |
|
|
assign msgLength = size[6:0];
|
130 |
|
|
/************************ standard WB stuff ***************************/
|
131 |
|
|
reg ack,err,rty;
|
132 |
|
|
assign wb_ack_o = ack;
|
133 |
|
|
assign wb_err_o = err;
|
134 |
|
|
assign wb_rty_o = rty;
|
135 |
|
|
assign rst_o = wb_rst_i;
|
136 |
|
|
assign rst = wb_rst_i;
|
137 |
|
|
assign dat_o = wb_dat_i;
|
138 |
|
|
assign ack_o = ack;
|
139 |
|
|
assign stb_o = wb_stb_i;
|
140 |
|
|
assign cyc_o = wb_cyc_i;
|
141 |
|
|
assign we_o = wb_we_i;
|
142 |
|
|
|
143 |
|
|
//ACK logic
|
144 |
|
|
always @(posedge wb_clk_i or posedge rst) begin
|
145 |
|
|
if (rst) ack <= 1'b0;
|
146 |
|
|
else ack <= (~|(`WIEG_ADDR_MASK & wb_addr_i) & wb_stb_i & wb_cyc_i & ~lock_cfg_i & ~err_int & ~rty_int);
|
147 |
|
|
end
|
148 |
|
|
|
149 |
|
|
//ERR logic if the FIFO is full
|
150 |
|
|
assign err_int = (~(wb_addr_i ^ `WIEGAND_ADDR) & wb_stb_i & wb_cyc_i & wb_we_i & full);
|
151 |
|
|
always @(posedge wb_clk_i or posedge rst) begin
|
152 |
|
|
if (rst) err <= 1'b0;
|
153 |
|
|
else err <= err_int;
|
154 |
|
|
end
|
155 |
|
|
|
156 |
|
|
//retry if we're in the middle of a write cycle
|
157 |
|
|
assign rty_int = (~|(`WIEG_ADDR_MASK & wb_addr_i) & wb_stb_i & wb_cyc_i & wb_we_i & lock_cfg_i);
|
158 |
|
|
always @(posedge wb_clk_i or posedge rst) begin
|
159 |
|
|
if (rst) rty <= 1'b0;
|
160 |
|
|
else rty <= rty_int;
|
161 |
|
|
end
|
162 |
|
|
|
163 |
|
|
//pass-thru clock
|
164 |
|
|
assign clk_o = wb_clk_i;
|
165 |
|
|
|
166 |
|
|
/************************ configuration registers *************************/
|
167 |
|
|
//defines the pulse width of the controller
|
168 |
|
|
always @(negedge wb_clk_i or posedge rst) begin
|
169 |
|
|
if (rst) pulsewidth <= `WB_WIDTH'hA;
|
170 |
|
|
else if ((wb_addr_i == `WB_CNFG_PW) && (wb_stb_i & wb_cyc_i & wb_we_i & ~lock_cfg_i)) pulsewidth <= wb_dat_i;
|
171 |
|
|
end
|
172 |
|
|
|
173 |
|
|
|
174 |
|
|
//defines the pulse to pulse delayof the controller
|
175 |
|
|
always @(negedge wb_clk_i or posedge rst) begin
|
176 |
|
|
if (rst) p2p <= `WB_WIDTH'h0;
|
177 |
|
|
else if ((wb_addr_i == `WB_CNFG_P2P) && (wb_stb_i & wb_cyc_i & wb_we_i & ~lock_cfg_i)) p2p <= wb_dat_i;
|
178 |
|
|
end
|
179 |
|
|
|
180 |
|
|
//defines the message size (in bits) and starts the message tx process (MSB)
|
181 |
|
|
//assign msgLength = size[6:0];
|
182 |
|
|
//clears TX start bit and reset bit a clock after is they asserted by WB
|
183 |
|
|
assign start_tx = size[7];
|
184 |
|
|
assign rst_FIFO = size[8];
|
185 |
|
|
always @(negedge wb_clk_i or posedge rst) begin
|
186 |
|
|
if (rst) size <= 9'h0;
|
187 |
|
|
else if ((wb_addr_i == `WB_CNFG_MSGSIZE) && (wb_stb_i & wb_cyc_i & wb_we_i & ~lock_cfg_i)) size <= wb_dat_i[8:0];
|
188 |
|
|
else size <= size & 9'h7F;
|
189 |
|
|
end
|
190 |
|
|
|
191 |
|
|
//readback registers on valid WB read cycle
|
192 |
|
|
assign wb_dat_rdbk = (wb_addr_i == `WB_CNFG_MSGSIZE)? size : ((wb_addr_i == `WB_CNFG_P2P)? p2p : pulsewidth);
|
193 |
|
|
assign wb_dat_o = (wb_stb_i & wb_cyc_i & ~wb_we_i)? wb_dat_rdbk : `WB_WIDTH'hz;
|
194 |
|
|
|
195 |
|
|
/******************************* DATA FIFO ********************************************/
|
196 |
|
|
|
197 |
|
|
//fifo for TX data.
|
198 |
|
|
assign wb_wr_en = (wb_addr_i == `WIEGAND_ADDR) && (wb_stb_i & wb_cyc_i & wb_we_i & ~full);
|
199 |
|
|
assign wb_rd_en = (wb_addr_i == `WIEGAND_ADDR) && (wb_stb_i & wb_cyc_i & ~wb_we_i);
|
200 |
|
|
endmodule
|
201 |
|
|
|
202 |
|
|
//////////////////////////////////////////////////////////////////////
|
203 |
|
|
//
|
204 |
|
|
// CVS Revision History
|
205 |
|
|
//
|
206 |
|
|
// $Log: $
|
207 |
|
|
//
|