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

Subversion Repositories mips32r1

[/] [mips32r1/] [trunk/] [Hardware/] [XUPV5-LX110T_SoC/] [MIPS32-Pipelined-Hw/] [src/] [UART/] [uart_rx.v] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 ayersg
`timescale 1ns / 1ps
2
/*
3
 * File         : uart_rx.v
4
 * Project      : University of Utah, XUM Project MIPS32 core
5
 * Creator(s)   : Grant Ayers (ayers@cs.utah.edu)
6
 *
7
 * Modification History:
8
 *   Rev   Date         Initials  Description of Change
9
 *   1.0   26-May-2010  GEA       Initial design.
10
 *
11
 * Standards/Formatting:
12
 *   Verilog 2001, 4 soft tab, wide column.
13
 *
14
 * Description:
15
 *   Recovers received data from the serial port with 16x clock over-sampling.
16
 *   'data_ready' is a synchronous pulse indicator. 8N1.
17
 */
18
module uart_rx(
19
    input clock,
20
    input reset,
21
    input RxD,
22
    input uart_tick_16x,
23
    output reg [7:0] RxD_data = 0,
24
    output data_ready
25
    );
26
 
27
    /* Synchronize incoming RxD */
28
    reg [1:0] RxD_sync = 2'b11; //0;
29
    always @(posedge clock) RxD_sync <= (uart_tick_16x) ? {RxD_sync[0], RxD} : RxD_sync;
30
 
31
    /* Filter Input */
32
    reg [1:0] RxD_cnt = 0;
33
    reg RxD_bit = 1; //0;
34
    always @(posedge clock) begin
35
        if (uart_tick_16x) begin
36
            case (RxD_sync[1])
37
                0:  RxD_cnt <= (RxD_cnt == 2'b11) ? RxD_cnt : RxD_cnt + 1;
38
                1:  RxD_cnt <= (RxD_cnt == 2'b00) ? RxD_cnt : RxD_cnt - 1;
39
            endcase
40
            RxD_bit <= (RxD_cnt == 2'b11) ? 0 : ((RxD_cnt == 2'b00) ? 1 : RxD_bit);
41
        end
42
        else begin
43
            RxD_cnt <= RxD_cnt;
44
            RxD_bit <= RxD_bit;
45
        end
46
    end
47
 
48
    /* State Definitions */
49
    localparam [3:0] IDLE=0, BIT_0=1, BIT_1=2, BIT_2=3, BIT_3=4, BIT_4=5, BIT_5=6,
50
                     BIT_6=7, BIT_7=8, STOP=9;
51
    reg [3:0] state = IDLE;
52
 
53
    /* Next-bit spacing and clock locking */
54
    reg clock_lock = 0;
55
    reg [3:0] bit_spacing = 4'b1110;   // Enable quick jumping from IDLE to BIT_0 when line was idle.
56
    always @(posedge clock) begin
57
       if (uart_tick_16x) begin
58
          if (~clock_lock) clock_lock <= ~RxD_bit; // We lock on when we detect a filtered 0 from idle
59
          else clock_lock <= ((state == IDLE) && (RxD_bit == 1'b1)) ? 0 : clock_lock;
60
          bit_spacing <= (clock_lock) ? bit_spacing + 1 : 4'b1110;
61
       end
62
       else begin
63
          clock_lock <= clock_lock;
64
          bit_spacing <= bit_spacing;
65
       end
66
    end
67
    wire next_bit = (bit_spacing == 4'b1111);
68
 
69
    /* State Machine */
70
    always @(posedge clock) begin
71
        if (reset) state <= IDLE;
72
        else if (uart_tick_16x) begin
73
            case (state)
74
                IDLE:   state <= (next_bit & (RxD_bit == 1'b0)) ? BIT_0 : IDLE;  // Start bit is 0
75
                BIT_0:  state <= (next_bit) ? BIT_1 : BIT_0;
76
                BIT_1:  state <= (next_bit) ? BIT_2 : BIT_1;
77
                BIT_2:  state <= (next_bit) ? BIT_3 : BIT_2;
78
                BIT_3:  state <= (next_bit) ? BIT_4 : BIT_3;
79
                BIT_4:  state <= (next_bit) ? BIT_5 : BIT_4;
80
                BIT_5:  state <= (next_bit) ? BIT_6 : BIT_5;
81
                BIT_6:  state <= (next_bit) ? BIT_7 : BIT_6;
82
                BIT_7:  state <= (next_bit) ? STOP  : BIT_7;
83
                STOP:   state <= (next_bit) ? IDLE  : STOP;
84
                default: state <= 4'bxxxx;
85
            endcase
86
        end
87
        else state <= state;
88
    end
89
 
90
    /* Shift Register to Collect Rx bits as they come */
91
    wire capture = (uart_tick_16x & next_bit & (state!=IDLE) & (state!=STOP));
92
    always @(posedge clock) RxD_data <= (capture) ? {RxD_bit, RxD_data[7:1]} : RxD_data[7:0];
93
    assign data_ready = (uart_tick_16x & next_bit & (state==STOP));
94
 
95
endmodule
96 3 ayersg
 

powered by: WebSVN 2.1.0

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