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

Subversion Repositories oms8051mini

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

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

powered by: WebSVN 2.1.0

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