//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
//// ////
|
//// ////
|
//// OMS 8051 cores UART Interface Module ////
|
//// OMS 8051 cores UART Interface Module ////
|
//// ////
|
//// ////
|
//// This file is part of the OMS 8051 cores project ////
|
//// This file is part of the OMS 8051 cores project ////
|
//// http://www.opencores.org/cores/oms8051mini/ ////
|
//// http://www.opencores.org/cores/oms8051mini/ ////
|
//// ////
|
//// ////
|
//// Description ////
|
//// Description ////
|
//// OMS 8051 definitions. ////
|
//// OMS 8051 definitions. ////
|
//// ////
|
//// ////
|
//// To Do: ////
|
//// To Do: ////
|
//// nothing ////
|
//// nothing ////
|
//// ////
|
//// ////
|
//// Author(s): ////
|
//// Author(s): ////
|
//// - Dinesh Annayya, dinesha@opencores.org ////
|
//// - Dinesh Annayya, dinesha@opencores.org ////
|
//// ////
|
//// ////
|
//// Revision : ////
|
|
//// v-0.0 : Nov 26, 2016 ////
|
|
//// 1. Initial version picked from ////
|
|
//// http://www.opencores.org/cores/turbo8051/ ////
|
|
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
|
//// Revision :
|
|
//// v-0.0 : Nov 26, 2016
|
|
//// 1. Initial version picked from
|
|
//// http://www.opencores.org/cores/turbo8051/
|
|
//// v-0.1 : Jan 19, 2017
|
|
/// 1. Lint warning fix for case statement //////////////////////////////////////////////////////////////////////
|
//// ////
|
//// ////
|
//// Copyright (C) 2000 Authors and OPENCORES.ORG ////
|
//// Copyright (C) 2000 Authors and OPENCORES.ORG ////
|
//// ////
|
//// ////
|
//// This source file may be used and distributed without ////
|
//// This source file may be used and distributed without ////
|
//// restriction provided that this copyright statement is not ////
|
//// restriction provided that this copyright statement is not ////
|
//// removed from the file and that any derivative work contains ////
|
//// removed from the file and that any derivative work contains ////
|
//// the original copyright notice and the associated disclaimer. ////
|
//// the original copyright notice and the associated disclaimer. ////
|
//// ////
|
//// ////
|
//// This source file is free software; you can redistribute it ////
|
//// This source file is free software; you can redistribute it ////
|
//// and/or modify it under the terms of the GNU Lesser General ////
|
//// and/or modify it under the terms of the GNU Lesser General ////
|
//// Public License as published by the Free Software Foundation; ////
|
//// Public License as published by the Free Software Foundation; ////
|
//// either version 2.1 of the License, or (at your option) any ////
|
//// either version 2.1 of the License, or (at your option) any ////
|
//// later version. ////
|
//// later version. ////
|
//// ////
|
//// ////
|
//// This source is distributed in the hope that it will be ////
|
//// This source is distributed in the hope that it will be ////
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
//// PURPOSE. See the GNU Lesser General Public License for more ////
|
//// PURPOSE. See the GNU Lesser General Public License for more ////
|
//// details. ////
|
//// details. ////
|
//// ////
|
//// ////
|
//// You should have received a copy of the GNU Lesser General ////
|
//// You should have received a copy of the GNU Lesser General ////
|
//// Public License along with this source; if not, download it ////
|
//// Public License along with this source; if not, download it ////
|
//// from http://www.opencores.org/lgpl.shtml ////
|
//// from http://www.opencores.org/lgpl.shtml ////
|
//// ////
|
//// ////
|
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
|
|
// UART rx state machine
|
// UART rx state machine
|
|
|
module uart_rxfsm (
|
module uart_rxfsm (
|
reset_n ,
|
reset_n ,
|
baud_clk_16x ,
|
baud_clk_16x ,
|
|
|
cfg_rx_enable ,
|
cfg_rx_enable ,
|
cfg_stop_bit ,
|
cfg_stop_bit ,
|
cfg_pri_mod ,
|
cfg_pri_mod ,
|
|
|
error_ind ,
|
error_ind ,
|
|
|
// FIFO control signal
|
// FIFO control signal
|
fifo_aval ,
|
fifo_aval ,
|
fifo_wr ,
|
fifo_wr ,
|
fifo_data ,
|
fifo_data ,
|
|
|
// Line Interface
|
// Line Interface
|
si
|
si
|
);
|
);
|
|
|
|
|
input reset_n ; // active low reset signal
|
input reset_n ; // active low reset signal
|
input baud_clk_16x ; // baud clock-16x
|
input baud_clk_16x ; // baud clock-16x
|
|
|
input cfg_rx_enable ; // transmit interface enable
|
input cfg_rx_enable ; // transmit interface enable
|
input cfg_stop_bit ; // stop bit
|
input cfg_stop_bit ; // stop bit
|
// 0 --> 1 stop, 1 --> 2 Stop
|
// 0 --> 1 stop, 1 --> 2 Stop
|
input [1:0] cfg_pri_mod ;// Priority Mode
|
input [1:0] cfg_pri_mod ;// Priority Mode
|
// 2'b00 --> None
|
// 2'b00 --> None
|
// 2'b10 --> Even priority
|
// 2'b10 --> Even priority
|
// 2'b11 --> Odd priority
|
// 2'b11 --> Odd priority
|
|
|
output [1:0] error_ind ; // 2'b00 --> Normal
|
output [1:0] error_ind ; // 2'b00 --> Normal
|
// 2'b01 --> framing error
|
// 2'b01 --> framing error
|
// 2'b10 --> parity error
|
// 2'b10 --> parity error
|
// 2'b11 --> fifo full
|
// 2'b11 --> fifo full
|
//--------------------------------------
|
//--------------------------------------
|
// FIFO control signal
|
// FIFO control signal
|
//--------------------------------------
|
//--------------------------------------
|
input fifo_aval ; // fifo empty
|
input fifo_aval ; // fifo empty
|
output fifo_wr ; // fifo write, assumed no back to back write
|
output fifo_wr ; // fifo write, assumed no back to back write
|
output [7:0] fifo_data ; // fifo write data
|
output [7:0] fifo_data ; // fifo write data
|
|
|
// Line Interface
|
// Line Interface
|
input si ; // rxd pin
|
input si ; // rxd pin
|
|
|
|
|
|
|
reg [7:0] fifo_data ; // fifo write data
|
reg [7:0] fifo_data ; // fifo write data
|
reg fifo_wr ; // fifo write
|
reg fifo_wr ; // fifo write
|
reg [1:0] error_ind ;
|
reg [1:0] error_ind ;
|
reg [2:0] cnt ;
|
reg [2:0] cnt ;
|
reg [3:0] offset ; // free-running counter from 0 - 15
|
reg [3:0] offset ; // free-running counter from 0 - 15
|
reg [3:0] rxpos ; // stable rx position
|
reg [3:0] rxpos ; // stable rx position
|
reg [2:0] rxstate ;
|
reg [2:0] rxstate ;
|
|
|
parameter idle_st = 3'b000;
|
parameter idle_st = 3'b000;
|
parameter xfr_start = 3'b001;
|
parameter xfr_start = 3'b001;
|
parameter xfr_data_st = 3'b010;
|
parameter xfr_data_st = 3'b010;
|
parameter xfr_pri_st = 3'b011;
|
parameter xfr_pri_st = 3'b011;
|
parameter xfr_stop_st1 = 3'b100;
|
parameter xfr_stop_st1 = 3'b100;
|
parameter xfr_stop_st2 = 3'b101;
|
parameter xfr_stop_st2 = 3'b101;
|
|
|
|
|
always @(negedge reset_n or posedge baud_clk_16x) begin
|
always @(negedge reset_n or posedge baud_clk_16x) begin
|
if(reset_n == 0) begin
|
if(reset_n == 0) begin
|
rxstate <= 3'b0;
|
rxstate <= 3'b0;
|
offset <= 4'b0;
|
offset <= 4'b0;
|
rxpos <= 4'b0;
|
rxpos <= 4'b0;
|
cnt <= 3'b0;
|
cnt <= 3'b0;
|
error_ind <= 2'b0;
|
error_ind <= 2'b0;
|
fifo_wr <= 1'b0;
|
fifo_wr <= 1'b0;
|
fifo_data <= 8'h0;
|
fifo_data <= 8'h0;
|
end
|
end
|
else begin
|
else begin
|
offset <= offset + 1;
|
offset <= offset + 1;
|
case(rxstate)
|
case(rxstate)
|
idle_st : begin
|
idle_st : begin
|
if(!si) begin // Start indication
|
if(!si) begin // Start indication
|
if(fifo_aval && cfg_rx_enable) begin
|
if(fifo_aval && cfg_rx_enable) begin
|
rxstate <= xfr_start;
|
rxstate <= xfr_start;
|
cnt <= 0;
|
cnt <= 0;
|
rxpos <= offset + 8; // Assign center rxoffset
|
rxpos <= offset + 8; // Assign center rxoffset
|
error_ind <= 2'b00;
|
error_ind <= 2'b00;
|
end
|
end
|
else begin
|
else begin
|
error_ind <= 2'b11; // fifo full error indication
|
error_ind <= 2'b11; // fifo full error indication
|
end
|
end
|
end else begin
|
end else begin
|
error_ind <= 2'b00; // Reset Error
|
error_ind <= 2'b00; // Reset Error
|
end
|
end
|
end
|
end
|
xfr_start : begin
|
xfr_start : begin
|
// Make Sure that minimum 8 cycle low is detected
|
// Make Sure that minimum 8 cycle low is detected
|
if(cnt < 7 && si) begin // Start indication
|
if(cnt < 7 && si) begin // Start indication
|
rxstate <= idle_st;
|
rxstate <= idle_st;
|
end
|
end
|
else if(cnt == 7 && !si) begin // Start indication
|
else if(cnt == 7 && !si) begin // Start indication
|
rxstate <= xfr_data_st;
|
rxstate <= xfr_data_st;
|
cnt <= 0;
|
cnt <= 0;
|
end else begin
|
end else begin
|
cnt <= cnt +1;
|
cnt <= cnt +1;
|
end
|
end
|
end
|
end
|
xfr_data_st : begin
|
xfr_data_st : begin
|
if(rxpos == offset) begin
|
if(rxpos == offset) begin
|
fifo_data[cnt] <= si;
|
fifo_data[cnt] <= si;
|
cnt <= cnt+1;
|
cnt <= cnt+1;
|
if(cnt == 7) begin
|
if(cnt == 7) begin
|
fifo_wr <= 1;
|
fifo_wr <= 1;
|
if(cfg_pri_mod == 2'b00) // No Priority
|
if(cfg_pri_mod == 2'b00) // No Priority
|
rxstate <= xfr_stop_st1;
|
rxstate <= xfr_stop_st1;
|
else rxstate <= xfr_pri_st;
|
else rxstate <= xfr_pri_st;
|
end
|
end
|
end
|
end
|
end
|
end
|
xfr_pri_st : begin
|
xfr_pri_st : begin
|
fifo_wr <= 0;
|
fifo_wr <= 0;
|
if(rxpos == offset) begin
|
if(rxpos == offset) begin
|
if(cfg_pri_mod == 2'b10) // even priority
|
if(cfg_pri_mod == 2'b10) // even priority
|
if( si != ^fifo_data) error_ind <= 2'b10;
|
if( si != ^fifo_data) error_ind <= 2'b10;
|
else // Odd Priority
|
else // Odd Priority
|
if( si != ~(^fifo_data)) error_ind <= 2'b10;
|
if( si != ~(^fifo_data)) error_ind <= 2'b10;
|
rxstate <= xfr_stop_st1;
|
rxstate <= xfr_stop_st1;
|
end
|
end
|
end
|
end
|
xfr_stop_st1 : begin
|
xfr_stop_st1 : begin
|
fifo_wr <= 0;
|
fifo_wr <= 0;
|
if(rxpos == offset) begin
|
if(rxpos == offset) begin
|
if(si) begin
|
if(si) begin
|
if(cfg_stop_bit) // Two Stop bit
|
if(cfg_stop_bit) // Two Stop bit
|
rxstate <= xfr_stop_st2;
|
rxstate <= xfr_stop_st2;
|
else
|
else
|
rxstate <= idle_st;
|
rxstate <= idle_st;
|
end else begin // Framing error
|
end else begin // Framing error
|
error_ind <= 2'b01;
|
error_ind <= 2'b01;
|
rxstate <= idle_st;
|
rxstate <= idle_st;
|
end
|
end
|
end
|
end
|
end
|
end
|
xfr_stop_st2 : begin
|
xfr_stop_st2 : begin
|
if(rxpos == offset) begin
|
if(rxpos == offset) begin
|
if(si) begin
|
if(si) begin
|
rxstate <= idle_st;
|
rxstate <= idle_st;
|
end else begin // Framing error
|
end else begin // Framing error
|
error_ind <= 2'b01;
|
error_ind <= 2'b01;
|
rxstate <= idle_st;
|
rxstate <= idle_st;
|
end
|
end
|
end
|
end
|
end
|
end
|
|
default: rxstate <= idle_st;
|
endcase
|
endcase
|
end
|
end
|
end
|
end
|
|
|
|
|
endmodule
|
endmodule
|
|
|