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

Subversion Repositories turbo8051

[/] [turbo8051/] [trunk/] [rtl/] [uart/] [uart_txfsm.v] - Blame information for rev 76

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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