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

Subversion Repositories instruction_list_pipelined_processor_with_peripherals

[/] [instruction_list_pipelined_processor_with_peripherals/] [trunk/] [hdl/] [uartRec.v] - Blame information for rev 10

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 10 maheshpalv
////////////////////////////////////////////////////////////////////////////////////////////////
2
////                                                                                                                    ////
3
////                                                                                                                    ////
4
////    This file is part of the project                                                                                        ////
5
////    "instruction_list_pipelined_processor_with_peripherals"                                                         ////
6
////                                                                                                                    ////
7
////  http://opencores.org/project,instruction_list_pipelined_processor_with_peripherals        ////
8
////                                                                                                                    ////
9
////                                                                                                                    ////
10
////                             Author:                                                                                ////
11
////                            - Mahesh Sukhdeo Palve                                                                                                  ////
12
////                                                                                                                                                                            ////
13
////////////////////////////////////////////////////////////////////////////////////////////////
14
////////////////////////////////////////////////////////////////////////////////////////////////
15
////                                                                                                                                                                            ////
16
////                                                                                                                                                            ////
17
////                                                                                                                    ////
18
////                                    This source file may be used and distributed without                    ////
19
////                                    restriction provided that this copyright statement is not               ////
20
////                                    removed from the file and that any derivative work contains             ////
21
////                                    the original copyright notice and the associated disclaimer.            ////
22
////                                                                                                                    ////
23
////                                    This source file is free software; you can redistribute it              ////
24
////                                    and/or modify it under the terms of the GNU Lesser General              ////
25
////                                    Public License as published by the Free Software Foundation;            ////
26
////                                    either version 2.1 of the License, or (at your option) any              ////
27
////                                    later version.                                                          ////
28
////                                                                                                                    ////
29
////                                    This source is distributed in the hope that it will be                  ////
30
////                                    useful, but WITHOUT ANY WARRANTY; without even the implied              ////
31
////                                    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR                 ////
32
////                                    PURPOSE.  See the GNU Lesser General Public License for more            ////
33
////                                    details.                                                                ////
34
////                                                                                                                    ////
35
////                                    You should have received a copy of the GNU Lesser General               ////
36
////                                    Public License along with this source; if not, download it              ////
37
////                                    from http://www.opencores.org/lgpl.shtml                                ////
38
////                                                                                                                    ////
39
////////////////////////////////////////////////////////////////////////////////////////////////
40 3 maheshpalv
 
41
`include "timescale.v"
42
`include "defines.v"
43
 
44
 
45
module uartRec(clk, reset, sTick, rx, rxDoneTick, dOut);
46
 
47
                parameter dataBits = `dataBits;
48
                parameter sbTick = `sbTick;
49
 
50
                input clk, reset, sTick, rx;
51
                output rxDoneTick;
52
                output [dataBits-1:0] dOut;
53
 
54
                reg rxDoneTick;
55
                // states:
56
 
57
        localparam idle = 2'b00, start = 2'b01, data = 2'b10, stop = 2'b11;
58
 
59
                reg [1:0] stateReg, stateNext;   // current and next states
60
                reg [3:0] sReg, sNext;           //      counter
61
                reg [2:0] nReg, nNext;           // counter
62
                reg [7:0] bReg, bNext;           // data recieved in this..
63
 
64
 
65
                always @ (posedge clk or posedge reset)
66
                begin
67
                        if (reset)
68
                        begin
69
                                stateReg <= idle;
70
                                sReg <= 1'b0;
71
                                bReg <= 1'b0;
72
                                nReg <= 1'b0;
73
                        end     // end if
74
 
75
                        else
76
                        begin
77
                                stateReg <= stateNext;
78
                                sReg <= sNext;
79
                                bReg <= bNext;
80
                                nReg <= nNext;
81
                        end     // end else
82
 
83
                end     // end always
84
 
85
 
86
 
87
                // FSM next state logic:
88
 
89
                always @ *
90
                begin
91
 
92
                                stateNext = stateReg;
93
                                sNext = sReg;
94
                                bNext = bReg;
95
                                nNext = nReg;
96
                                rxDoneTick = 1'b0;
97
 
98
                        case (stateReg)
99
 
100
                        idle    :       if (~rx)
101
                                                begin
102
                                                        stateNext = start;      // start when rx is activated
103
                                                        sNext = 0;       // initialize sampling counter
104
                                                end     // end if rx
105
 
106
                        start   :       if (sTick)
107
                                                        if (sReg == 7)
108
                                                        begin
109
                                                                stateNext = data;               // at middle of oversampled start
110
                                                                                                        // bit, go to data state
111
                                                                sNext = 0;
112
                                                                nNext = 0;
113
                                                        end     // end if sReg==7
114
 
115
                                                        else
116
                                                                sNext = sReg + 1;       // otherwise keep increment sReg upto 7
117
 
118
                        data    :       if (sTick)
119
                                                        if (sReg == 15) // if reached middle of next bit
120
                                                        begin
121
                                                                sNext = 0;       // reset counter
122
                                                                bNext = {rx, bReg[7:1]};        // LSB first, and the
123
                                                                                                                //data recieved in bReg
124
                                                                if (nReg == (dataBits-1))       // if all data recvd,
125
                                                                        stateNext = stop;       // go to stop bit(s) state
126
                                                                else
127
                                                                        nNext = nReg + 1;
128
                                                        end     // end if sReg==15
129
 
130
                                                        else
131
                                                                sNext = sReg + 1;       // otherwise keep increment sReg upto 15
132
 
133
                        stop    :       if (sTick)
134
                                                        if (sReg == (sbTick-1))
135
                                                        begin
136
                                                                stateNext = idle;               // done reception, go to idle state
137
                                                                rxDoneTick = 1'b1;      // raise done tick!
138
                                                        end     // end if sReg==sbTick-1
139
 
140
                                                        else
141
                                                                sNext = sReg + 1;               // otherwise keep increment sReg 
142
                                                                                                                        //upto (sbTick-1)
143
                        endcase
144
 
145
                end     // end always combinatorial
146
 
147
 
148
                // recvd data output
149
 
150
                assign dOut = bReg;
151
 
152
 
153
endmodule

powered by: WebSVN 2.1.0

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