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

Subversion Repositories turbo8051

[/] [turbo8051/] [trunk/] [rtl/] [uart/] [uart_rxfsm.v] - Blame information for rev 58

Go to most recent revision | 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
//////////////////////////////////////////////////////////////////////
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
// UART rx state machine
45
 
46
module uart_rxfsm (
47
             reset_n        ,
48
             baud_clk_16x   ,
49
 
50
             cfg_rx_enable  ,
51
             cfg_stop_bit   ,
52
             cfg_pri_mod    ,
53
 
54
             error_ind      ,
55
 
56
       // FIFO control signal
57
             fifo_aval      ,
58
             fifo_wr        ,
59
             fifo_data      ,
60
 
61
          // Line Interface
62
             si
63
          );
64
 
65
 
66
input             reset_n        ; // active low reset signal
67
input             baud_clk_16x   ; // baud clock-16x
68
 
69
input             cfg_rx_enable  ; // transmit interface enable
70
input             cfg_stop_bit   ; // stop bit 
71
                                   // 0 --> 1 stop, 1 --> 2 Stop
72
input   [1:0]     cfg_pri_mod    ;// Priority Mode
73
                                   // 2'b00 --> None
74
                                   // 2'b10 --> Even priority
75
                                   // 2'b11 --> Odd priority
76
 
77
output [1:0]      error_ind     ; // 2'b00 --> Normal
78
                                  // 2'b01 --> framing error
79
                                  // 2'b10 --> parity error
80
                                  // 2'b11 --> fifo full
81
//--------------------------------------
82
//   FIFO control signal
83
//--------------------------------------
84
input             fifo_aval      ; // fifo empty
85
output            fifo_wr        ; // fifo write, assumed no back to back write
86
output  [7:0]     fifo_data      ; // fifo write data
87
 
88
// Line Interface
89
input             si             ;  // rxd pin
90
 
91
 
92
 
93
reg     [7:0]    fifo_data       ; // fifo write data
94
reg              fifo_wr         ; // fifo write 
95
reg    [1:0]     error_ind       ;
96
reg    [2:0]     cnt             ;
97
reg    [3:0]     offset          ; // free-running counter from 0 - 15
98
reg    [3:0]     rxpos           ; // stable rx position
99
reg    [2:0]     rxstate         ;
100
 
101
 
102
parameter idle_st      = 3'b000;
103
parameter xfr_start    = 3'b001;
104
parameter xfr_data_st  = 3'b010;
105
parameter xfr_pri_st   = 3'b011;
106
parameter xfr_stop_st1 = 3'b100;
107
parameter xfr_stop_st2 = 3'b101;
108
 
109
 
110
always @(negedge reset_n or posedge baud_clk_16x) begin
111
   if(reset_n == 0) begin
112
      rxstate   <= 3'b0;
113
      offset    <= 4'b0;
114
      rxpos     <= 4'b0;
115
      cnt       <= 3'b0;
116
      error_ind <= 2'b0;
117
      fifo_wr   <= 1'b0;
118
      fifo_data <= 8'h0;
119
   end
120
   else begin
121
      offset     <= offset + 1;
122
      case(rxstate)
123
       idle_st   : begin
124
            if(!si) begin // Start indication
125
               if(fifo_aval && cfg_rx_enable) begin
126
                 rxstate   <=   xfr_start;
127
                 cnt       <=   0;
128
                 rxpos     <=   offset + 8; // Assign center rxoffset
129
                 error_ind <= 2'b00;
130
               end
131
               else begin
132
                  error_ind <= 2'b11; // fifo full error indication
133
               end
134
            end else begin
135
               error_ind <= 2'b00; // Reset Error
136
            end
137
         end
138
      xfr_start : begin
139
            // Make Sure that minimum 8 cycle low is detected
140
            if(cnt < 7 && si) begin // Start indication
141
               rxstate <=   idle_st;
142
            end
143
            else if(cnt == 7 && !si) begin // Start indication
144
                rxstate <=   xfr_data_st;
145
                cnt     <=   0;
146
            end else begin
147
              cnt  <= cnt +1;
148
            end
149
         end
150
      xfr_data_st : begin
151
             if(rxpos == offset) begin
152
                fifo_data[cnt] <= si;
153
                cnt            <= cnt+1;
154
                if(cnt == 7) begin
155
                   fifo_wr <= 1;
156
                   if(cfg_pri_mod == 2'b00)  // No Priority
157
                       rxstate <=   xfr_stop_st1;
158
                   else rxstate <= xfr_pri_st;
159
                end
160
             end
161
          end
162
       xfr_pri_st   : begin
163
            fifo_wr <= 0;
164
            if(rxpos == offset) begin
165
               if(cfg_pri_mod == 2'b10)  // even priority
166
                  if( si != ^fifo_data) error_ind <= 2'b10;
167
               else  // Odd Priority
168
                  if( si != ~(^fifo_data)) error_ind <= 2'b10;
169
               rxstate <=   xfr_stop_st1;
170
            end
171
         end
172
       xfr_stop_st1  : begin
173
          fifo_wr <= 0;
174
          if(rxpos == offset) begin
175
             if(si) begin
176
               if(cfg_stop_bit) // Two Stop bit
177
                  rxstate <=   xfr_stop_st2;
178
               else
179
                  rxstate <=   idle_st;
180
             end else begin // Framing error
181
                error_ind <= 2'b01;
182
                rxstate   <=   idle_st;
183
             end
184
          end
185
       end
186
       xfr_stop_st2  : begin
187
          if(rxpos == offset) begin
188
             if(si) begin
189
                rxstate <=   idle_st;
190
             end else begin // Framing error
191
                error_ind <= 2'b01;
192
                rxstate   <=   idle_st;
193
             end
194
          end
195
       end
196
    endcase
197
   end
198
end
199
 
200
 
201
endmodule

powered by: WebSVN 2.1.0

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