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

Subversion Repositories wiegand_ctl

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 15 jeaander
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  wiegand_tx_top.v                                            ////
4
////                                                              ////
5
////                                                              ////
6
////  This file is part of the Wiegand Protocol Controller        ////
7
////  Wiegand Transmitter 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
////                                                              ////
45
//////////////////////////////////////////////////////////////////////
46
//
47
//  Revisions at end of file
48
//
49
 
50
 
51
// synopsys translate_off
52
`include "timescale.v"
53
// synopsys translate_on
54
`include "wiegand_defines.v"
55
 
56
module wiegand_tx_top(
57
 
58
  one_o,
59
  zero_o,
60
 
61
  wb_clk_i,
62
  wb_rst_i,
63
  wb_dat_i,
64
  wb_dat_o,
65
  wb_cyc_i,
66
  wb_stb_i,
67
  wb_cti_i,
68
  wb_sel_i,
69
  wb_we_i,
70
  wb_adr_i,
71
  wb_ack_o,
72
  wb_err_o,
73
  wb_rty_o
74
);
75
  //to PHY layer
76
  output reg one_o;
77
  output reg zero_o;
78
 
79
  //wishbone interface
80
  input                       wb_clk_i;
81
  input                       wb_rst_i;
82
  input  [`WB_WIDTH-1:0]      wb_dat_i;
83
  output [`WB_WIDTH-1:0]      wb_dat_o;
84
  input                       wb_cyc_i;
85
  input                       wb_stb_i;
86
  input [(`WB_WIDTH/8)-1:0]   wb_sel_i;
87
  input [2:0]                 wb_cti_i;
88
  input                       wb_we_i;
89
  input  [`WB_ADDR_WIDTH-1:0] wb_adr_i;
90
  output                      wb_ack_o;
91
  output                      wb_err_o;
92
  output                      wb_rty_o;
93
 
94
  //intermediate signals
95
wire                      rst;
96
reg                       idle;
97
 
98
wire [`WB_WIDTH-1:0]      dat_o;
99
wire [`WB_WIDTH-1:0]      dat_i;
100
wire [`WB_WIDTH-1:0]      pulsewidth;
101
wire [`WB_WIDTH-1:0]      p2p;
102
reg [4:0]                 p2pCnt;
103
wire [6:0]                msgLength;
104
reg [31:0]                word_out;
105
reg [2:0]                 state, next_state;
106
wire                      clk;
107
reg                       lock_cfg;
108
reg                       full_dly;
109
wire                      full;
110
reg                       bit, tx, data, done;
111
reg [`WB_WIDTH-1:0]       pulseCnt;
112
reg [6:0]                 bitCount, bitCountReg;
113
wire                      start_tx;
114
wire [`WB_WIDTH-1:0]      data_o;
115
wire                      rst_FIFO;
116
 
117
  /***************************** TX logic *********************************************************/
118
  //output registers clocked directly from the state machine
119
  always @(negedge clk or posedge rst) begin
120
    if (rst)  begin
121
      one_o <= 1'b1;
122
      zero_o <= 1'b1;
123
    end
124
    else if (bit) begin
125
      if (word_out[31])
126
        one_o <= 1'b0;
127
      else
128
        zero_o <= 1'b0;
129
    end
130
    else begin
131
      one_o <= 1'b1;
132
      zero_o <= 1'b1;
133
    end
134
  end
135
 
136
  //counters enabled by state machine for programmable wiegand timing
137
 
138
  //pulse to pulse timing
139
  always @(negedge clk or posedge rst) begin
140
    if (rst)      p2pCnt <= 5'h0;
141
    else if (tx)  p2pCnt <= p2pCnt+1;
142
    else          p2pCnt <= 5'h0;
143
  end
144
 
145
  //pulse width timer
146
  always @(negedge clk or posedge rst) begin
147
    if (rst)                pulseCnt <= 5'h0;
148
    else if (bit)           pulseCnt <= pulseCnt+1;
149
    else                    pulseCnt <= 5'h0;
150
  end
151
 
152
  //message bit counter
153
  always @(negedge clk or posedge rst) begin
154
    if (rst)              bitCount <= 7'h0;
155
    else if (done)        bitCount <= bitCount+1;
156
    else if (idle)        bitCount <= 7'h0;
157
  end
158
 
159
  always @(negedge clk or posedge rst) begin
160
    if (rst)              bitCountReg <= 7'h0;
161
    else if (done)        bitCountReg <= bitCountReg+1;
162
    else if (data)        bitCountReg <= 7'h0;
163
  end
164
 
165
  //main state machine for transmitter
166
  always @(posedge clk or posedge rst) begin
167
    if (rst)  state <= `IDLE;
168
    else      state <= next_state;
169
  end
170
 
171
  always @ (*) begin
172
    next_state = `IDLE;
173
    bit = 1'b0;
174
    tx = 1'b0;
175
    data = 1'b0;
176
    done = 1'b0;
177
    idle = 1'b0;
178
    case (state)
179
      `IDLE: begin
180
        idle = 1'b1;
181
        if (start_tx) next_state = `DATA;
182
        else          next_state = `IDLE;
183
      end
184
      `DATA: begin
185
        data = 1'b1;
186
        next_state = `TX;
187
      end
188
      `TX: begin
189
        tx = 1'b1;
190
        if (bitCountReg == 6'h20)
191
          next_state = `DATA;
192
        else if (p2pCnt == p2p) begin
193
          if (bitCount == msgLength)
194
            next_state = `LASTBIT;
195
          else
196
            next_state = `BIT;
197
        end
198
        else  next_state = `TX;
199
      end
200
      `BIT: begin
201
        bit = 1'b1;
202
        if (pulseCnt == pulsewidth) next_state = `DONE;
203
        else                        next_state = `BIT;
204
      end
205
      `LASTBIT: begin
206
        bit = 1'b1;
207
        if (pulseCnt == pulsewidth) next_state = `IDLE;
208
        else                        next_state = `LASTBIT;
209
      end
210
      `DONE: begin
211
        done = 1'b1;
212
        next_state = `TX;
213
      end
214
    endcase
215
  end
216
 
217
  //dont want config being changed during a write cycle
218
  always @(negedge clk or posedge rst) begin
219
    if (rst)      lock_cfg <= 1'b0;
220
    else          lock_cfg <= tx | done | bit | data;
221
  end
222
 
223
  /***************************** output FIFO *******************************************************/
224
  always @(posedge clk or posedge rst) begin
225
    if (rst)        word_out <= 32'h0;
226
    else if (data)  word_out <= data_o;
227
    else if (done)  word_out <= {word_out[30:0],1'b0};
228
  end
229
 
230
  always @(posedge clk or posedge rst) begin
231
    if (rst)    full_dly <= 1'b0;
232
    else        full_dly <= full;
233
  end
234
 
235
  fifo_wieg datafifowrite(~clk,~clk,dat_o,data_o,(rst | rst_FIFO),(~lock_cfg & wb_wr_en),data,full,empty);
236
 
237
 
238
  /***************************** WB interface *******************************************************/
239
  assign dat_i = data_o;
240
  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,
241
                              wb_dat_o,wb_cyc_i,wb_cti_i,wb_err_o,wb_rty_o,rst,dat_o,dat_i,msgLength,start_tx,
242
                              p2p,pulsewidth,clk,full_dly,lock_cfg,wb_wr_en,rst_FIFO,rd_en);
243
 
244
 
245
endmodule
246
 
247
////////////////////////////////////////////////////////////////////
248
// CVS Revision History
249
//
250
// $Log:  $
251
//

powered by: WebSVN 2.1.0

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