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

Subversion Repositories oms8051mini

[/] [oms8051mini/] [trunk/] [rtl/] [uart/] [uart_txfsm.v] - Blame information for rev 36

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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