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

Subversion Repositories wiegand_ctl

[/] [wiegand_ctl/] [trunk/] [rtl/] [verilog/] [wiegand_rx_top.v] - Blame information for rev 15

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 15 jeaander
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  wiegand_rx_top.v                                            ////
4
////                                                              ////
5
////                                                              ////
6
////  This file is part of the Wiegand Protocol Controller        ////
7
////  Wiegand Receiver IP core                                    ////
8
////  http://www.opencores.org/projects/wiegand/                  ////
9
////                                                              ////
10
////                                                              ////
11
////  Author(s):                                                  ////
12
////       Jeff Anderson                                          ////
13
////       jeaander@opencores.org                                 ////
14
////                                                              ////
15
////                                                              ////
16
////  All additional information is available in the README.txt   ////
17
////  file.                                                       ////
18
////                                                              ////
19
//////////////////////////////////////////////////////////////////////
20
////                                                              ////
21
//// Copyright (C) 2014 Authors                                   ////
22
////                                                              ////
23
//// This source file may be used and distributed without         ////
24
//// restriction provided that this copyright statement is not    ////
25
//// removed from the file and that any derivative work contains  ////
26
//// the original copyright notice and the associated disclaimer. ////
27
////                                                              ////
28
//// This source file is free software; you can redistribute it   ////
29
//// and/or modify it under the terms of the GNU Lesser General   ////
30
//// Public License as published by the Free Software Foundation; ////
31
//// either version 2.1 of the License, or (at your option) any   ////
32
//// later version.                                               ////
33
////                                                              ////
34
//// This source is distributed in the hope that it will be       ////
35
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
36
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
37
//// PURPOSE.  See the GNU Lesser General Public License for more ////
38
//// details.                                                     ////
39
////                                                              ////
40
//// You should have received a copy of the GNU Lesser General    ////
41
//// Public License along with this source; if not, download it   ////
42
//// from http://www.opencores.org/lgpl.shtml                     ////
43
////                                                              ////
44
//// The wiegand protocol is maintained by                        ////
45
//// This product has been tested to interoperate with certified  ////
46
//// devices, but has not been certified itself.  This product    ////
47
//// should be certified through prior to claiming strict         ////
48
//// adherence to the standard.                                   ////
49
////                                                              ////
50
//////////////////////////////////////////////////////////////////////
51
//
52
//  Revisions at end of file
53
//
54
 
55
 
56
// synopsys translate_off
57
`include "timescale.v"
58
// synopsys translate_on
59
`include "wiegand_defines.v"
60
 
61
module wiegand_rx_top(
62
  one_i,
63
  zero_i,
64
 
65
  wb_clk_i,
66
  wb_rst_i,
67
  wb_dat_i,
68
  wb_dat_o,
69
  wb_cyc_i,
70
  wb_stb_i,
71
  wb_cti_i,
72
  wb_sel_i,
73
  wb_we_i,
74
  wb_adr_i,
75
  wb_ack_o,
76
  wb_err_o,
77
  wb_rty_o
78
);
79
  //to PHY layer
80
  input one_i;
81
  input zero_i;
82
 
83
  //wishbone interface
84
  input                       wb_clk_i;
85
  input                       wb_rst_i;
86
  input  [`WB_WIDTH-1:0]      wb_dat_i;
87
  output [`WB_WIDTH-1:0]      wb_dat_o;
88
  input                       wb_cyc_i;
89
  input                       wb_stb_i;
90
  input                       wb_we_i;
91
  input [(`WB_WIDTH/8)-1:0]   wb_sel_i;
92
  input [2:0]                 wb_cti_i;
93
  input  [`WB_ADDR_WIDTH-1:0] wb_adr_i;
94
  output                      wb_ack_o;
95
  output                      wb_err_o;
96
  output                      wb_rty_o;
97
 
98
  //intermediate signals
99
wire                          rst;
100
reg [`WB_WIDTH:0]             data;
101
 
102
wire [`WB_WIDTH-1:0]          dat_i;
103
wire [`WB_WIDTH-1:0]          dat_o;
104
wire [`WB_WIDTH-1:0]          data_o;
105
wire [`WB_WIDTH-1:0]      pulsewidth;
106
wire [`WB_WIDTH-1:0]      p2p;
107
reg  [(`WB_ADDR_WIDTH/2)-1:0] sampleCnt;
108
wire [6:0]                    msgLength;
109
reg [`WB_ADDR_WIDTH-1:0]      word_in;
110
reg [`WB_ADDR_WIDTH-1:0]      fifo_out;
111
reg [1:0]                     zero_edge, one_edge;
112
reg [1:0]                     zero_det, one_det;
113
wire                          clk;
114
reg                           lock_cfg;
115
reg [3:0]                     filter1;
116
reg [3:0]                     filter0;
117
reg [1:0]                     filterCnt;
118
reg                           sampleTime;
119
reg                           filterEn;
120
reg [5:0]                     bitCount,tpiCnt;
121
wire                          start_tx;
122
wire [5:0]                    tpi;
123
wire                          errorClr;
124
reg                           msgDone, msgError,msgDoneDly;
125
 
126
  /***************************** RX logic **********************************************************/
127
  //negedge detectors for each line
128
  assign zero = ~zero_det[0] & zero_det[1];
129
  always @(posedge clk or posedge rst) begin
130
    if (rst)  zero_det <= 2'b11;
131
    else      zero_det <= {zero_det[0],zero_i};
132
  end
133
 
134
  assign one = ~one_det[0] & one_det[1];
135
  always @(posedge clk or posedge rst) begin
136
    if (rst)  one_det <= 2'b11;
137
    else      one_det <= {one_det[0],one_i};
138
  end
139
 
140
  //posedge detectors for each line
141
  assign notzero = zero_det[0] & ~zero_det[1];
142
  assign notone = one_det[0] & ~one_det[1];
143
 
144
  //@ negedge, filter for noise on teh line; filtering for noise by taking samples during the PW
145
  //starting the sampling at halfway through teh pulse to ensure dampening occurs before sample
146
  assign filtered1 = (~|filter1) & ~one_det[1];
147
  assign filtered0 = (~|filter0) & ~zero_det[1];
148
  always @(posedge clk or posedge rst) begin
149
    if (rst)  begin
150
      filter1 <= 4'h0;
151
      filter0 <= 4'h0;
152
      filterCnt <= 2'h0;
153
    end
154
    else if (sampleTime)   begin
155
      filter1 <= {filter1[2:0],one_det[0]};
156
      filter0 <= {filter0[2:0],zero_det[0]};
157
      filterCnt <= filterCnt+1;
158
    end
159
  end
160
 
161
  always @(posedge clk or posedge rst) begin
162
    if (rst)            sampleCnt <= 3'h0;
163
    else if (filterEn)  sampleCnt <= sampleCnt+1;
164
  end
165
 
166
  always @(posedge clk or posedge rst) begin
167
    if (rst)                                  sampleTime <= 1'b0;
168
    else  sampleTime <= ((sampleCnt == {pulsewidth[2:0]}) || (sampleCnt == {1'h0,pulsewidth[2:1]}) || (sampleCnt == {2'h0,pulsewidth[2]}));
169
  end
170
 
171
  always @(negedge clk or posedge rst) begin
172
    if (rst)                    filterEn <= 1'b0;
173
    else if (one | zero)        filterEn <= 1'b1;
174
    else if (filterCnt == 2'h3) filterEn <= 1'b0;
175
  end
176
 
177
  //then write bit to appropriate data register sub-bit; increment counter
178
  always @(negedge clk or posedge rst) begin
179
    if (rst)                        word_in <= 32'h0;
180
    else if (filtered1 | filtered0) word_in <= {word_in[30:0],filtered1};
181
  end
182
 
183
  always @(negedge clk or posedge rst) begin
184
    if (rst)                        bitCount <= 6'h0;
185
    else if (filtered1 | filtered0) bitCount <= bitCount+1;
186
    else if (msgDoneDly)            bitCount <= 6'h0;
187
  end
188
 
189
  //when linesa re not being driven, check to see that tpi is not exceeded;
190
  //exceeded tpi means data transfer is done, and packet length should be checked
191
  assign tpi = p2p[5:0];
192
  always @(negedge clk or posedge rst) begin
193
    if (rst)                                tpiCnt <= 6'h0;
194
    else if (~|{notzero,notone,zero,one})   tpiCnt <= tpiCnt+1;
195
    else                                    tpiCnt <= 6'h0;
196
  end
197
 
198
  always @(posedge clk or posedge rst) begin
199
    if (rst)  msgDone <= 1'b0;
200
    else      msgDone <= ~|(tpiCnt ^ tpi);
201
  end
202
 
203
  always @(posedge clk or posedge rst) begin
204
    if (rst)  msgDoneDly <= 1'b0;
205
    else      msgDoneDly <= msgDone;
206
  end
207
 
208
  //configuration is locked at start_tx/start_rx until a message error is found
209
  always @(posedge clk or posedge rst) begin
210
    if (rst)            lock_cfg <= 1'b0;
211
    else if (start_tx)  lock_cfg <= 1'b1;
212
    else if (msgError)  lock_cfg <= 1'b0;
213
  end
214
 
215
  //if rx msglength does not match expected msglength, then flag an error
216
  assign errorClr = p2p[6];
217
  always @(negedge clk or posedge rst) begin
218
    if (rst)            msgError <= 1'b0;
219
    else if (errorClr)  msgError <= 1'b0;
220
    else                msgError <= msgDone & |(bitCount ^ msgLength);
221
  end
222
 
223
 
224
  /***************************** input FIFO *******************************************************/
225
  fifo_wieg datafifowrite(~clk,~clk,dat_i,data_o,(rst | rst_FIFO),wr_en,rd_en,full,empty);
226
 
227
  always @(posedge clk or posedge rst) begin
228
    if (rst)        fifo_out <= `WB_WIDTH'h0;
229
    else if (rd_en) fifo_out <= data_o;
230
  end
231
 
232
 
233
 
234
  /***************************** WB interface *******************************************************/
235
  assign dat_i = fifo_out;
236
  wb_interface_wieg wb_interface(wb_rst_i,wb_clk_i,wb_stb_i,wb_ack_o,wb_adr_i,wb_we_i,wb_dat_i,wb_sel_i,
237
                              wb_dat_o,wb_cyc_i,wb_cti_i,wb_err_o,wb_rty_o,rst,dat_o,dat_i,msgLength,start_tx,
238
                              p2p,pulsewidth,clk,full_dly,lock_cfg,wb_wr_en,rst_FIFO,rd_en);
239
 
240
endmodule
241
 
242
////////////////////////////////////////////////////////////////////
243
// CVS Revision History
244
//
245
// $Log:  $
246
//

powered by: WebSVN 2.1.0

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