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

Subversion Repositories openverifla

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

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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