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

Subversion Repositories oms8051mini

[/] [oms8051mini/] [trunk/] [rtl/] [uart/] [uart_rxfsm.v] - Blame information for rev 2

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

powered by: WebSVN 2.1.0

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