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

Subversion Repositories oms8051mini

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

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
//// Copyright (C) 2000 Authors and OPENCORES.ORG                 ////
24
////                                                              ////
25
//// This source file may be used and distributed without         ////
26
//// restriction provided that this copyright statement is not    ////
27
//// removed from the file and that any derivative work contains  ////
28
//// the original copyright notice and the associated disclaimer. ////
29
////                                                              ////
30
//// This source file is free software; you can redistribute it   ////
31
//// and/or modify it under the terms of the GNU Lesser General   ////
32
//// Public License as published by the Free Software Foundation; ////
33
//// either version 2.1 of the License, or (at your option) any   ////
34
//// later version.                                               ////
35
////                                                              ////
36
//// This source is distributed in the hope that it will be       ////
37
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
38
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
39
//// PURPOSE.  See the GNU Lesser General Public License for more ////
40
//// details.                                                     ////
41
////                                                              ////
42
//// You should have received a copy of the GNU Lesser General    ////
43
//// Public License along with this source; if not, download it   ////
44
//// from http://www.opencores.org/lgpl.shtml                     ////
45
////                                                              ////
46
//////////////////////////////////////////////////////////////////////
47
 
48
// UART rx state machine
49
 
50
module uart_rxfsm (
51
             reset_n        ,
52
             baud_clk_16x   ,
53
 
54
             cfg_rx_enable  ,
55
             cfg_stop_bit   ,
56
             cfg_pri_mod    ,
57
 
58
             error_ind      ,
59
 
60
       // FIFO control signal
61
             fifo_aval      ,
62
             fifo_wr        ,
63
             fifo_data      ,
64
 
65
          // Line Interface
66
             si
67
          );
68
 
69
 
70
input             reset_n        ; // active low reset signal
71
input             baud_clk_16x   ; // baud clock-16x
72
 
73
input             cfg_rx_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
output [1:0]      error_ind     ; // 2'b00 --> Normal
82
                                  // 2'b01 --> framing error
83
                                  // 2'b10 --> parity error
84
                                  // 2'b11 --> fifo full
85
//--------------------------------------
86
//   FIFO control signal
87
//--------------------------------------
88
input             fifo_aval      ; // fifo empty
89
output            fifo_wr        ; // fifo write, assumed no back to back write
90
output  [7:0]     fifo_data      ; // fifo write data
91
 
92
// Line Interface
93
input             si             ;  // rxd pin
94
 
95
 
96
 
97
reg     [7:0]    fifo_data       ; // fifo write data
98
reg              fifo_wr         ; // fifo write 
99
reg    [1:0]     error_ind       ;
100
reg    [2:0]     cnt             ;
101
reg    [3:0]     offset          ; // free-running counter from 0 - 15
102
reg    [3:0]     rxpos           ; // stable rx position
103
reg    [2:0]     rxstate         ;
104
 
105
parameter idle_st      = 3'b000;
106
parameter xfr_start    = 3'b001;
107
parameter xfr_data_st  = 3'b010;
108
parameter xfr_pri_st   = 3'b011;
109
parameter xfr_stop_st1 = 3'b100;
110
parameter xfr_stop_st2 = 3'b101;
111
 
112
 
113
always @(negedge reset_n or posedge baud_clk_16x) begin
114
   if(reset_n == 0) begin
115
      rxstate   <= 3'b0;
116
      offset    <= 4'b0;
117
      rxpos     <= 4'b0;
118
      cnt       <= 3'b0;
119
      error_ind <= 2'b0;
120
      fifo_wr   <= 1'b0;
121
      fifo_data <= 8'h0;
122
   end
123
   else begin
124
      offset     <= offset + 1;
125
      case(rxstate)
126
       idle_st   : begin
127
            if(!si) begin // Start indication
128
               if(fifo_aval && cfg_rx_enable) begin
129
                 rxstate   <=   xfr_start;
130
                 cnt       <=   0;
131
                 rxpos     <=   offset + 8; // Assign center rxoffset
132
                 error_ind <= 2'b00;
133
               end
134
               else begin
135
                  error_ind <= 2'b11; // fifo full error indication
136
               end
137
            end else begin
138
               error_ind <= 2'b00; // Reset Error
139
            end
140
         end
141
      xfr_start : begin
142
            // Make Sure that minimum 8 cycle low is detected
143
            if(cnt < 7 && si) begin // Start indication
144
               rxstate <=   idle_st;
145
            end
146
            else if(cnt == 7 && !si) begin // Start indication
147
                rxstate <=   xfr_data_st;
148
                cnt     <=   0;
149
            end else begin
150
              cnt  <= cnt +1;
151
            end
152
         end
153
      xfr_data_st : begin
154
             if(rxpos == offset) begin
155
                fifo_data[cnt] <= si;
156
                cnt            <= cnt+1;
157
                if(cnt == 7) begin
158
                   fifo_wr <= 1;
159
                   if(cfg_pri_mod == 2'b00)  // No Priority
160
                       rxstate <=   xfr_stop_st1;
161
                   else rxstate <= xfr_pri_st;
162
                end
163
             end
164
          end
165
       xfr_pri_st   : begin
166
            fifo_wr <= 0;
167
            if(rxpos == offset) begin
168
               if(cfg_pri_mod == 2'b10)  // even priority
169
                  if( si != ^fifo_data) error_ind <= 2'b10;
170
               else  // Odd Priority
171
                  if( si != ~(^fifo_data)) error_ind <= 2'b10;
172
               rxstate <=   xfr_stop_st1;
173
            end
174
         end
175
       xfr_stop_st1  : begin
176
          fifo_wr <= 0;
177
          if(rxpos == offset) begin
178
             if(si) begin
179
               if(cfg_stop_bit) // Two Stop bit
180
                  rxstate <=   xfr_stop_st2;
181
               else
182
                  rxstate <=   idle_st;
183
             end else begin // Framing error
184
                error_ind <= 2'b01;
185
                rxstate   <=   idle_st;
186
             end
187
          end
188
       end
189
       xfr_stop_st2  : begin
190
          if(rxpos == offset) begin
191
             if(si) begin
192
                rxstate <=   idle_st;
193
             end else begin // Framing error
194
                error_ind <= 2'b01;
195
                rxstate   <=   idle_st;
196
             end
197
          end
198
       end
199
    endcase
200
   end
201
end
202
 
203
 
204
endmodule

powered by: WebSVN 2.1.0

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