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

Subversion Repositories openverifla

[/] [openverifla/] [trunk/] [openverifla_2.4/] [verilog/] [verifla/] [u_rec_of_verifla.v] - Blame information for rev 46

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 46 laurentiud
 
2
/*
3
Update: Laurentiu Duca, 20180808_1200:
4
        - consider baud_clk_posedge
5
Update: Laurentiu Duca, 20180724_1550:
6
   - removed "rdy_o   <= 1'b0;" from idle state
7
        and moved to STA_CHECK_START_BIT.
8
        - sample in the middle of the data bit
9
        - correct init values and sizes
10
*/
11
 
12
/////////////////////////////////////////////////////////////////////
13
////  Author: Zhangfeifei                                        ////
14
////                                                             ////
15
////  Advance Test Technology Laboratory,                        ////
16
////  Institute of Computing Technology,                         ////
17
////  Chinese Academy of Sciences                                ////
18
////                                                             ////
19
////  If you encountered any problem, please contact :           ////
20
////  Email: zhangfeifei@ict.ac.cn or whitewill@opencores.org    ////
21
////  Tel: +86-10-6256 5533 ext. 5673                            ////
22
////                                                             ////
23
////  Downloaded from:                                           ////
24
////     http://www.opencores.org/pdownloads.cgi/list/ucore      ////
25
/////////////////////////////////////////////////////////////////////
26
////                                                             ////
27
//// Copyright (C) 2005-2006 Zhangfeifei                         ////
28
////                         zhangfeifei@ict.ac.cn               ////
29
////                                                             ////
30
////                                                             ////
31
//// This source file may be used and distributed freely without ////
32
//// restriction provided that this copyright statement is not   ////
33
//// removed from the file and any derivative work contains the  ////
34
//// original copyright notice and the associated disclaimer.    ////
35
////                                                             ////
36
//// Please let the author know if it is used                    ////
37
//// for commercial purpose.                                     //// 
38
////                                                             ////
39
////     THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY     ////
40
//// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED   ////
41
//// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS   ////
42
//// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR      ////
43
//// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,         ////
44
//// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    ////
45
//// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE   ////
46
//// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR        ////
47
//// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF  ////
48
//// LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT  ////
49
//// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT  ////
50
//// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE         ////
51
//// POSSIBILITY OF SUCH DAMAGE.                                 ////
52
////                                                             ////
53
/////////////////////////////////////////////////////////////////////
54
////                                                             ////
55
////                                                             ////
56
//// Date of Creation: 2005.12.3                                 ////
57
////                                                             ////
58
//// Version: 0.0.1                                              ////
59
////                                                             ////
60
//// Description: rx module of the uart module,data format is    ////
61
////              8bits data,1 bits stop bit,and no parity check ////
62
////                                                             ////
63
/////////////////////////////////////////////////////////////////////
64
////                                                             ////
65
//// Change log:                                                 ////
66
////                                                             ////
67
/////////////////////////////////////////////////////////////////////
68
 
69
module u_rec_of_verifla(
70
                clk_i,rst_i,//system signal
71
                baud_clk_posedge,
72
                rxd_i,//serial data in
73
                rdy_o,data_o //data ready and parallel data out signal
74
                );
75
 
76
  parameter // state difinition
77
     STA_IDLE = 0,
78
     STA_CHECK_START_BIT = 1,
79
     STA_RECEIVE = 2;
80
 
81
  input clk_i;
82
  input rst_i;
83
  input baud_clk_posedge;
84
  input rxd_i;
85
 
86
  output rdy_o;
87
  output [7:0] data_o;
88
 
89
  reg rdy_o;
90
  reg [7:0] data_o;
91
 
92
  reg [7:0] rsr;//reciving shift register
93
  reg [3:0] num_of_rec;
94
 
95
  reg [1:0] reg_sta;
96
 
97
  //the counter to count the clk in
98
  reg [3:0] count;
99
  reg count_c;//the carry of count
100
 
101
  always @(posedge clk_i or posedge rst_i)
102
  begin
103
    if(rst_i)
104
    begin
105
      data_o     <= 8'b0;
106
      rdy_o      <= 1'b0;
107
      rsr        <= 8'h0;
108
      num_of_rec <= 4'b0;
109
      count      <= 4'b0;
110
      count_c    <= 1'b0;
111
      reg_sta    <= STA_IDLE;
112
    end
113
    else begin
114
                if(baud_clk_posedge)
115
                        case (reg_sta)
116
                        STA_IDLE:
117
                        begin
118
                          num_of_rec <= 4'd0;
119
                          count      <= 4'd0;
120
                          if(!rxd_i)
121
                                 reg_sta  <= STA_CHECK_START_BIT;//recive a start bit
122
                          else
123
                                 reg_sta  <= STA_IDLE;
124
                        end
125
                        STA_CHECK_START_BIT:
126
                        begin
127
                          if(count >= 7)
128
                          begin
129
                                 count   <= 0;
130
                                 if(!rxd_i) begin
131
                                        //has passed 8 clk and rxd_i is still zero,then start bit has been confirmed
132
                                        rdy_o   <= 1'b0;
133
                                        reg_sta <= STA_RECEIVE;
134
                                 end
135
                                 else
136
                                        reg_sta <= STA_IDLE;
137
                          end
138
                          else begin
139
                                 reg_sta <= STA_CHECK_START_BIT;
140
                                 count   <= count +1;
141
                          end
142
                        end
143
                        STA_RECEIVE:
144
                        begin
145
                          {count_c,count} <= count +1;
146
                          //has passed 16 clk after the last bit has been checked,sampling a bit
147
                          if(count_c)
148
                          begin
149
                                 if(num_of_rec <=4'd7)
150
                                 begin //sampling the received bit
151
                                        rsr        <= {rxd_i,rsr[7:1]};
152
                                        num_of_rec <= num_of_rec +1;
153
                                        reg_sta    <= STA_RECEIVE;
154
                                 end
155
                                 else begin//sampling the stop bit
156
                                        //if(rxd_i)//if stop bit exist
157
                                        //begin
158
                                                data_o  <= rsr;
159
                                                rdy_o   <= 1'b1;
160
                                        //end
161
                                        reg_sta    <= STA_IDLE;
162
                                 end
163
                          end
164
                        end
165
                        endcase
166
    end
167
  end
168
 
169
endmodule

powered by: WebSVN 2.1.0

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