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

Subversion Repositories blue

[/] [blue/] [trunk/] [blue8/] [rcvr.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 wd5gnr
/*
2
    This file is part of Blue8.
3
 
4
    Foobar is free software: you can redistribute it and/or modify
5
    it under the terms of the GNU Lesser General Public License as published by
6
    the Free Software Foundation, either version 3 of the License, or
7
    (at your option) any later version.
8
 
9
    Foobar is distributed in the hope that it will be useful,
10
    but WITHOUT ANY WARRANTY; without even the implied warranty of
11
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
    GNU Lesser General Public License for more details.
13
 
14
    You should have received a copy of the GNU Lesser General Public License
15
    along with Blue8.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
    Blue8 by Al Williams alw@al-williams.com
18
 
19
*/
20
 
21
 `default_nettype none
22
 
23
// async receiver -- Williams
24
 
25
module rcvr (input wire clk,input wire clke,input wire rst,input wire rxd,
26
  output [7:0] dout, output reg data_ready, input wire rdn,output reg framing_error, output reg overrun_error);
27
//input clk;      // main clock coming in
28
//input clke;   // 16x baud rate clock enable
29
//input rst;      // reset
30
//input rxd;   // serial input
31
//output [7:0] dout;  // output bus
32
//output data_ready;    // high when data is ready  
33
//input rdn;          // put data on dout when high
34
//output framing_error;  // high if frame error occurs
35
//output overrun_error;  // detects overrun
36
//reg overrun_error;
37
 
38
 
39
reg rxd1;        // these two used to sync incoming data
40
reg rxd2;
41
 
42
reg clk1xe;   // clock enable for 1x clock
43
reg clk1x_enable;     // generate the 1x receive clock (that is, character reception in progress)
44
reg [3:0] clkdiv=0;  // divide 16x clock to 1x clock
45
reg [7:0] rsr;            // shift register
46
reg [7:0] rbr;            // buffer register
47
reg [3:0] no_bits_rcvd;  // counter
48
 
49
assign dout = (rdn & !rst) ? rbr : 8'bz;   // data bus output
50
 
51
always @(posedge clk or posedge rst)     // synchronize incoming signal
52
begin
53
if (rst)
54
begin
55
  rxd1 <= 1'b1;
56
  rxd2 <= 1'b1;
57
end
58
else
59
if (clke)
60
begin
61
  rxd1 <= rxd;
62
  rxd2 <= rxd1;
63
end
64
end
65
 
66
always @(posedge clk or posedge rst)                            // go to 1x clock  until 9 (include stop) bits read
67
begin
68
if (rst)
69
  clk1x_enable <= 1'b0;
70
else if (clke)
71
  begin
72
    if (!rxd2 & !rxd1 & !rxd)                              // detect start bit
73
       clk1x_enable <= 1'b1;                                                      // turn on clk1x
74
    if (no_bits_rcvd == 4'b1010)                                  // or if done (no_bits_rcvd only increments during rcv)
75
       clk1x_enable <= 1'b0;                                                      // turn off
76
  end
77
end
78
 
79
always @(posedge clk or posedge rst)         // if rdn is 1 then clear data ready, set it when all bits read
80
 begin                                                                                            // note, the dout assign "uses" rdn
81
  if (rst)
82
     data_ready = 1'b0;
83
  else
84
  begin
85
    if (rdn) data_ready = 1'b0;
86
    if (clke)
87
           if (no_bits_rcvd == 4'b1010)
88
        data_ready = 1'b1;
89
  end
90
end
91
 
92
always @(posedge clk or posedge rst)        // generate 1x rate clock
93
begin
94
  if (rst)
95
  begin
96
    clkdiv <= 4'b0000;
97
  end
98
  else
99
  begin
100
    if (clke)
101
           if (clk1x_enable)
102
                begin
103
            clkdiv<=clkdiv+1;
104
      end
105
           else
106
                begin
107
            clkdiv<=4'b1000;   // ensure correct delay after start bit
108
      end
109
  end
110
end
111
 
112
 
113
always @(posedge clk or posedge rst)            // generate 1x clock enable
114
begin
115
 if (rst) clk1xe=1'b0;
116
 else
117
   if (clke & clk1x_enable & clkdiv==4'b1111) clk1xe=1'b1; else clk1xe=1'b0;
118
end
119
 
120
 
121
 
122
always @(posedge clk or posedge rst)                      // depending on number of bits, take actions
123
if (rst)
124
begin
125
  rsr = 8'b0;
126
  rbr = 8'b0;
127
  framing_error = 1'b0;
128
  overrun_error = 1'b0;
129
end
130
else if (clk1xe)
131
begin
132
   if (no_bits_rcvd >= 4'b0000 && no_bits_rcvd <= 4'b1000)        // some # of bits until 8 bits
133
   begin
134
     rsr[6:0]=rsr[7:1];
135
     rsr[7] = rxd2;         // shift bits in LSB first
136
     if (no_bits_rcvd==4'b1000)
137
            begin
138
                   if (data_ready)
139
                          overrun_error=1'b1;
140
         else
141
                          begin
142
                          overrun_error=1'b0;
143
                     rbr=rsr;     // copy shift register to data register
144
           end
145
       end
146
                 if ((no_bits_rcvd == 4'b1000) && (rxd2 != 1'b1))                // check for framing error
147
         framing_error = 1'b1;
148
       else
149
         framing_error = 1'b0;
150
   end
151
end
152
 
153
 
154
always @(posedge clk or posedge rst)                     // count bits while 1x clock is running
155
if (rst)
156
  no_bits_rcvd = 4'b0000;
157
else
158
  begin
159
  if (!clk1x_enable)                                                     // and reset count when 1x clock turns off
160
    no_bits_rcvd = 4'b0000;
161
  else
162
     if (clk1xe) no_bits_rcvd = no_bits_rcvd + 1;
163
 end
164
 
165
endmodule
166
 

powered by: WebSVN 2.1.0

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