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