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

Subversion Repositories Aquarius

[/] [Aquarius/] [trunk/] [verilog/] [sasc_top.v] - Blame information for rev 12

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 thorn_aitc
/////////////////////////////////////////////////////////////////////
2
////                                                             ////
3
////  Simple Asynchronous Serial Comm. Device                    ////
4
////                                                             ////
5
////                                                             ////
6
////  Author: Rudolf Usselmann                                   ////
7
////          rudi@asics.ws                                      ////
8
////                                                             ////
9
////                                                             ////
10
////  Downloaded from: http://www.opencores.org/cores/sasc/      ////
11
////                                                             ////
12
/////////////////////////////////////////////////////////////////////
13
////                                                             ////
14
//// Copyright (C) 2000-2002 Rudolf Usselmann                    ////
15
////                         www.asics.ws                        ////
16
////                         rudi@asics.ws                       ////
17
////                                                             ////
18
//// This source file may be used and distributed without        ////
19
//// restriction provided that this copyright statement is not   ////
20
//// removed from the file and that any derivative work contains ////
21
//// the original copyright notice and the associated disclaimer.////
22
////                                                             ////
23
////     THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY     ////
24
//// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED   ////
25
//// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS   ////
26
//// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR      ////
27
//// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,         ////
28
//// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    ////
29
//// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE   ////
30
//// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR        ////
31
//// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF  ////
32
//// LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT  ////
33
//// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT  ////
34
//// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE         ////
35
//// POSSIBILITY OF SUCH DAMAGE.                                 ////
36
////                                                             ////
37
/////////////////////////////////////////////////////////////////////
38
 
39
//  CVS Log
40
//
41
//  $Id: sasc_top.v,v 1.1.1.1 2003-07-12 13:19:55 thorn_aitch Exp $
42
//
43
//  $Date: 2003-07-12 13:19:55 $
44
//  $Revision: 1.1.1.1 $
45
//  $Author: thorn_aitch $
46
//  $Locker:  $
47
//  $State: Exp $
48
//
49
// Change History:
50
//               $Log: not supported by cvs2svn $
51
//               Revision 1.1.1.1  2002/09/16 16:16:42  rudi
52
//               Initial Checkin
53
//
54
//
55
//
56
//
57
//
58
//
59
//
60
//
61
 
62
`include "timescale.v"
63
 
64
/*
65
Serial IO Interface
66
===============================
67
RTS I Request To Send
68
CTS O Clear to send
69
TD  I Transmit Data
70
RD  O Receive Data
71
*/
72
 
73
module sasc_top(        clk, rst,
74
 
75
                        // SIO
76
                        rxd_i, txd_o, cts_i, rts_o,
77
 
78
                        // External Baud Rate Generator
79
                        sio_ce, sio_ce_x4,
80
 
81
                        // Internal Interface
82
                        din_i, dout_o, re_i, we_i, full_o, empty_o);
83
 
84
input           clk;
85
input           rst;
86
input           rxd_i;
87
output          txd_o;
88
input           cts_i;
89
output          rts_o;
90
input           sio_ce;
91
input           sio_ce_x4;
92
input   [7:0]    din_i;
93
output  [7:0]    dout_o;
94
input           re_i, we_i;
95
output          full_o, empty_o;
96
 
97
///////////////////////////////////////////////////////////////////
98
//
99
// Local Wires and Registers
100
//
101
 
102
parameter       START_BIT       = 1'b0,
103
                STOP_BIT        = 1'b1,
104
                IDLE_BIT        = 1'b1;
105
 
106
wire    [7:0]    txd_p;
107
reg             load;
108
reg             load_r;
109
wire            load_e;
110
reg     [9:0]    hold_reg;
111
wire            txf_empty;
112
reg             txd_o;
113
reg             shift_en;
114
reg     [3:0]    tx_bit_cnt;
115
reg             rxd_s, rxd_r;
116
wire            start;
117
reg     [3:0]    rx_bit_cnt;
118
reg             rx_go;
119
reg     [9:0]    rxr;
120
reg             rx_valid, rx_valid_r;
121
wire            rx_we;
122
wire            rxf_full;
123
reg             rts_o;
124
reg             txf_empty_r;
125
reg             shift_en_r;
126
reg             rxd_r1, rxd_r2;
127
wire            lock_en;
128
reg             change;
129
reg             rx_sio_ce_d, rx_sio_ce_r1, rx_sio_ce_r2, rx_sio_ce;
130
reg     [1:0]    dpll_state, dpll_next_state;
131
 
132
///////////////////////////////////////////////////////////////////
133
//
134
// IO Fifo's
135
//
136
 
137
sasc_fifo4 tx_fifo(     .clk(           clk             ),
138
                        .rst(           rst             ),
139
                        .clr(           1'b0            ),
140
                        .din(           din_i           ),
141
                        .we(            we_i            ),
142
                        .dout(          txd_p           ),
143
                        .re(            load_e          ),
144
                        .full(          full_o          ),
145
                        .empty(         txf_empty       )
146
                        );
147
 
148
sasc_fifo4 rx_fifo(     .clk(           clk             ),
149
                        .rst(           rst             ),
150
                        .clr(           1'b0            ),
151
                        .din(           rxr[9:2]        ),
152
                        .we(            rx_we           ),
153
                        .dout(          dout_o          ),
154
                        .re(            re_i            ),
155
                        .full(          rxf_full        ),
156
                        .empty(         empty_o         )
157
                        );
158
 
159
///////////////////////////////////////////////////////////////////
160
//
161
// Transmit Logic
162
//
163
always @(posedge clk)
164
        if(!rst)        txf_empty_r <= #1 1'b1;
165
        else
166
        if(sio_ce)      txf_empty_r <= #1 txf_empty;
167
 
168
always @(posedge clk)
169
        load <= #1 !txf_empty_r & !shift_en & !cts_i;
170
 
171
always @(posedge clk)
172
        load_r <= #1 load;
173
 
174
assign load_e = load & sio_ce;
175
 
176
always @(posedge clk)
177
        if(load_e)              hold_reg <= #1 {STOP_BIT, txd_p, START_BIT};
178
        else
179
        if(shift_en & sio_ce)   hold_reg <= #1 {IDLE_BIT, hold_reg[9:1]};
180
 
181
always @(posedge clk)
182
        if(!rst)                                txd_o <= #1 IDLE_BIT;
183
        else
184
        if(sio_ce)
185
                if(shift_en | shift_en_r)       txd_o <= #1 hold_reg[0];
186
                else                            txd_o <= #1 IDLE_BIT;
187
 
188
always @(posedge clk)
189
        if(!rst)                tx_bit_cnt <= #1 4'h9;
190
        else
191
        if(load_e)              tx_bit_cnt <= #1 4'h0;
192
        else
193
        if(shift_en & sio_ce)   tx_bit_cnt <= #1 tx_bit_cnt + 4'h1;
194
 
195
always @(posedge clk)
196
        shift_en <= #1 (tx_bit_cnt != 4'h9);
197
 
198
always @(posedge clk)
199
        if(!rst)        shift_en_r <= #1 1'b0;
200
        else
201
        if(sio_ce)      shift_en_r <= #1 shift_en;
202
 
203
///////////////////////////////////////////////////////////////////
204
//
205
// Recieve Logic
206
//
207
 
208
always @(posedge clk)
209
        rxd_s <= #1 rxd_i;
210
 
211
always @(posedge clk)
212
        rxd_r <= #1 rxd_s;
213
 
214
assign start = (rxd_r == IDLE_BIT) & (rxd_s == START_BIT);
215
 
216
always @(posedge clk)
217
        if(!rst)                rx_bit_cnt <= #1 4'ha;
218
        else
219
        if(!rx_go & start)      rx_bit_cnt <= #1 4'h0;
220
        else
221
        if(rx_go & rx_sio_ce)   rx_bit_cnt <= #1 rx_bit_cnt + 4'h1;
222
 
223
always @(posedge clk)
224
        rx_go <= #1 (rx_bit_cnt != 4'ha);
225
 
226
always @(posedge clk)
227
        rx_valid <= #1 (rx_bit_cnt == 4'h9);
228
 
229
always @(posedge clk)
230
        rx_valid_r <= #1 rx_valid;
231
 
232
assign rx_we = !rx_valid_r & rx_valid & !rxf_full;
233
 
234
always @(posedge clk)
235
        if(rx_go & rx_sio_ce)   rxr <= {rxd_s, rxr[9:1]};
236
 
237
always @(posedge clk)
238
        rts_o <= #1 rxf_full;
239
 
240
///////////////////////////////////////////////////////////////////
241
//
242
// Reciever DPLL
243
//
244
 
245
// Uses 4x baud clock to lock to incoming stream
246
 
247
// Edge detector
248
always @(posedge clk)
249
        if(sio_ce_x4)   rxd_r1 <= #1 rxd_s;
250
 
251
always @(posedge clk)
252
        if(sio_ce_x4)   rxd_r2 <= #1 rxd_r1;
253
 
254
always @(posedge clk)
255
        if(!rst)                change <= #1 1'b0;
256
        else
257
        if(rxd_r != rxd_s)      change <= #1 1'b1;
258
        else
259
        if(sio_ce_x4)           change <= #1 1'b0;
260
 
261
// DPLL FSM
262
  always @(posedge clk or negedge rst)
263
        if(!rst)        dpll_state <= #1 2'h1;
264
        else
265
        if(sio_ce_x4)   dpll_state <= #1 dpll_next_state;
266
 
267
always @(dpll_state or change)
268
   begin
269
        rx_sio_ce_d = 1'b0;
270
        case(dpll_state)
271
           2'h0:
272
                if(change)      dpll_next_state = 3'h0;
273
                else            dpll_next_state = 3'h1;
274
           2'h1:begin
275
                rx_sio_ce_d = 1'b1;
276
                if(change)      dpll_next_state = 3'h3;
277
                else            dpll_next_state = 3'h2;
278
                end
279
           2'h2:
280
                if(change)      dpll_next_state = 3'h0;
281
                else            dpll_next_state = 3'h3;
282
           2'h3:
283
                if(change)      dpll_next_state = 3'h0;
284
                else            dpll_next_state = 3'h0;
285
        endcase
286
   end
287
 
288
// Compensate for sync registers at the input - allign sio 
289
// clock enable to be in the middle between two bit changes ...
290
always @(posedge clk)
291
        rx_sio_ce_r1 <= #1 rx_sio_ce_d;
292
 
293
always @(posedge clk)
294
        rx_sio_ce_r2 <= #1 rx_sio_ce_r1;
295
 
296
always @(posedge clk)
297
        rx_sio_ce <= #1 rx_sio_ce_r1 & !rx_sio_ce_r2;
298
 
299
endmodule
300
 
301
 

powered by: WebSVN 2.1.0

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