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

Subversion Repositories usb2uart

[/] [usb2uart/] [trunk/] [rtl/] [uart_core/] [uart_txfsm.v] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 dinesha
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  Tubo 8051 cores UART Interface Module                       ////
4
////                                                              ////
5
////  This file is part of the Turbo 8051 cores project           ////
6
////  http://www.opencores.org/cores/turbo8051/                   ////
7
////                                                              ////
8
////  Description                                                 ////
9
////  Turbo 8051 definitions.                                     ////
10
////                                                              ////
11
////  To Do:                                                      ////
12
////    nothing                                                   ////
13
////                                                              ////
14
////  Author(s):                                                  ////
15
////      - Dinesh Annayya, dinesha@opencores.org                 ////
16
////                                                              ////
17
//////////////////////////////////////////////////////////////////////
18
////                                                              ////
19
//// Copyright (C) 2000 Authors and OPENCORES.ORG                 ////
20
////                                                              ////
21
//// This source file may be used and distributed without         ////
22
//// restriction provided that this copyright statement is not    ////
23
//// removed from the file and that any derivative work contains  ////
24
//// the original copyright notice and the associated disclaimer. ////
25
////                                                              ////
26
//// This source file is free software; you can redistribute it   ////
27
//// and/or modify it under the terms of the GNU Lesser General   ////
28
//// Public License as published by the Free Software Foundation; ////
29
//// either version 2.1 of the License, or (at your option) any   ////
30
//// later version.                                               ////
31
////                                                              ////
32
//// This source is distributed in the hope that it will be       ////
33
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
34
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
35
//// PURPOSE.  See the GNU Lesser General Public License for more ////
36
//// details.                                                     ////
37
////                                                              ////
38
//// You should have received a copy of the GNU Lesser General    ////
39
//// Public License along with this source; if not, download it   ////
40
//// from http://www.opencores.org/lgpl.shtml                     ////
41
////                                                              ////
42
//////////////////////////////////////////////////////////////////////
43
 
44
 
45
// UART tx state machine
46
 
47
module uart_txfsm (
48
             reset_n        ,
49
             baud_clk_16x   ,
50
 
51
             cfg_tx_enable  ,
52
             cfg_stop_bit   ,
53
             cfg_pri_mod    ,
54
 
55
       // FIFO control signal
56
             fifo_empty     ,
57
             fifo_rd        ,
58
             fifo_data      ,
59
 
60
          // Line Interface
61
             so
62
          );
63
 
64
 
65
input             reset_n        ; // active low reset signal
66
input             baud_clk_16x   ; // baud clock-16x
67
 
68
input             cfg_tx_enable  ; // transmit interface enable
69
input             cfg_stop_bit   ; // stop bit 
70
                                   // 0 --> 1 stop, 1 --> 2 Stop
71
input   [1:0]     cfg_pri_mod    ;// Priority Mode
72
                                   // 2'b00 --> None
73
                                   // 2'b10 --> Even priority
74
                                   // 2'b11 --> Odd priority
75
 
76
//--------------------------------------
77
//   FIFO control signal
78
//--------------------------------------
79
input             fifo_empty     ; // fifo empty
80
output            fifo_rd        ; // fifo read, assumed no back to back read
81
input  [7:0]      fifo_data      ; // fifo read data
82
 
83
// Line Interface
84
output            so             ;  // txd pin
85
 
86
 
87
reg  [2:0]         txstate       ; // tx state
88
reg                so            ; // txd pin
89
reg  [7:0]         txdata        ; // local txdata
90
reg                fifo_rd       ; // Fifo read enable
91
reg  [2:0]         cnt           ; // local data cont
92
reg  [3:0]         divcnt        ; // clock div count
93
 
94
parameter idle_st      = 3'b000;
95
parameter xfr_data_st  = 3'b001;
96
parameter xfr_pri_st   = 3'b010;
97
parameter xfr_stop_st1 = 3'b011;
98
parameter xfr_stop_st2 = 3'b100;
99
 
100
 
101
always @(negedge reset_n or posedge baud_clk_16x)
102
begin
103
   if(reset_n == 1'b0) begin
104
      txstate  <= idle_st;
105
      so       <= 1'b1;
106
      cnt      <= 3'b0;
107
      txdata   <= 8'h0;
108
      fifo_rd  <= 1'b0;
109
      divcnt   <= 4'b0;
110
   end
111
   else begin
112
      divcnt <= divcnt+1;
113
      if(divcnt == 4'b0000) begin // Do at once in 16 clock
114
         case(txstate)
115
          idle_st      : begin
116
               if(!fifo_empty && cfg_tx_enable) begin
117
                  so       <= 1'b0 ; // Start bit
118
                  cnt      <= 3'b0;
119
                  fifo_rd  <= 1'b1;
120
                  txdata   <= fifo_data;
121
                  txstate  <= xfr_data_st;
122
               end
123
            end
124
 
125
          xfr_data_st  : begin
126
              fifo_rd  <= 1'b0;
127
              so   <= txdata[cnt];
128
              cnt  <= cnt+1;
129
              if(cnt == 7) begin
130
                 if(cfg_pri_mod == 2'b00) begin // No Priority
131
                    txstate  <= xfr_stop_st1;
132
                 end
133
                 else begin
134
                    txstate <= xfr_pri_st;
135
                 end
136
              end
137
           end
138
 
139
          xfr_pri_st   : begin
140
               if(cfg_pri_mod == 2'b10)  // even priority
141
                   so <= ^txdata;
142
               else begin // Odd Priority
143
                   so <= ~(^txdata);
144
               end
145
               txstate  <= xfr_stop_st1;
146
            end
147
 
148
          xfr_stop_st1  : begin // First Stop Bit
149
               so <= 1;
150
               if(cfg_stop_bit == 0)  // 1 Stop Bit
151
                    txstate <= idle_st;
152
               else // 2 Stop Bit 
153
                  txstate  <= xfr_stop_st2;
154
            end
155
 
156
          xfr_stop_st2  : begin // Second Stop Bit
157
               so <= 1;
158
               txstate <= idle_st;
159
            end
160
         endcase
161
      end
162
     else begin
163
        fifo_rd  <= 1'b0;
164
     end
165
   end
166
end
167
 
168
 
169
endmodule

powered by: WebSVN 2.1.0

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