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/] [uartTrans.v] - Diff between revs 3 and 10

Only display areas with differences | Details | Blame | View Log

Rev 3 Rev 10
 
////////////////////////////////////////////////////////////////////////////////////////////////
 
////                                                                                                                    ////
 
////                                                                                                                    ////
 
////    This file is part of the project                                                                                        ////
 
////    "instruction_list_pipelined_processor_with_peripherals"                                                         ////
 
////                                                                                                                    ////
 
////  http://opencores.org/project,instruction_list_pipelined_processor_with_peripherals        ////
 
////                                                                                                                    ////
 
////                                                                                                                    ////
 
////                             Author:                                                                                ////
 
////                            - Mahesh Sukhdeo Palve                                                                                                  ////
 
////                                                                                                                                                                            ////
 
////////////////////////////////////////////////////////////////////////////////////////////////
 
////////////////////////////////////////////////////////////////////////////////////////////////
 
////                                                                                                                                                                            ////
 
////                                                                                                                                                            ////
 
////                                                                                                                    ////
 
////                                    This source file may be used and distributed without                    ////
 
////                                    restriction provided that this copyright statement is not               ////
 
////                                    removed from the file and that any derivative work contains             ////
 
////                                    the original copyright notice and the associated disclaimer.            ////
 
////                                                                                                                    ////
 
////                                    This source file is free software; you can redistribute it              ////
 
////                                    and/or modify it under the terms of the GNU Lesser General              ////
 
////                                    Public License as published by the Free Software Foundation;            ////
 
////                                    either version 2.1 of the License, or (at your option) any              ////
 
////                                    later version.                                                          ////
 
////                                                                                                                    ////
 
////                                    This source is distributed in the hope that it will be                  ////
 
////                                    useful, but WITHOUT ANY WARRANTY; without even the implied              ////
 
////                                    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR                 ////
 
////                                    PURPOSE.  See the GNU Lesser General Public License for more            ////
 
////                                    details.                                                                ////
 
////                                                                                                                    ////
 
////                                    You should have received a copy of the GNU Lesser General               ////
 
////                                    Public License along with this source; if not, download it              ////
 
////                                    from http://www.opencores.org/lgpl.shtml                                ////
 
////                                                                                                                    ////
 
////////////////////////////////////////////////////////////////////////////////////////////////
 
 
`include "timescale.v"
`include "timescale.v"
`include "defines.v"
`include "defines.v"
 
 
 
 
module uartTrans (clk, reset, sTick, txDoneTick, din, tx, txStart);
module uartTrans (clk, reset, sTick, txDoneTick, din, tx, txStart);
 
 
                parameter dataBits = `dataBits;
                parameter dataBits = `dataBits;
                parameter sbTick = `sbTick;
                parameter sbTick = `sbTick;
 
 
                input [dataBits-1 :0] din;
                input [dataBits-1 :0] din;
                input clk, reset, sTick, txStart;
                input clk, reset, sTick, txStart;
                output tx, txDoneTick;
                output tx, txDoneTick;
 
 
                reg txDoneTick;
                reg txDoneTick;
 
 
/*
/*
should be impleneted as a 4-state FSM : idle, start, data, stop;
should be impleneted as a 4-state FSM : idle, start, data, stop;
 
 
*/
*/
 
 
        localparam [1:0] idle = 2'b00, start = 2'b01, data = 2'b10, stop = 2'b11;
        localparam [1:0] idle = 2'b00, start = 2'b01, data = 2'b10, stop = 2'b11;
 
 
                reg [1:0] stateReg, stateNext;   // current and next states
                reg [1:0] stateReg, stateNext;   // current and next states
                reg [3:0] sReg, sNext;           //      counter
                reg [3:0] sReg, sNext;           //      counter
                reg [2:0] nReg, nNext;           // counter
                reg [2:0] nReg, nNext;           // counter
                reg [7:0] bReg, bNext;           // perhaps keeps data to be sent
                reg [7:0] bReg, bNext;           // perhaps keeps data to be sent
                reg              txReg, txNext; // current bit being transferred
                reg              txReg, txNext; // current bit being transferred
 
 
 
 
                //      reset and non-reset conditions:
                //      reset and non-reset conditions:
 
 
                always @ (posedge clk or posedge reset)
                always @ (posedge clk or posedge reset)
                begin
                begin
                        if (reset)
                        if (reset)
                        begin
                        begin
                                stateReg <= idle;
                                stateReg <= idle;
                                sReg <= 1'b0;
                                sReg <= 1'b0;
                                bReg <= 1'b0;
                                bReg <= 1'b0;
                                nReg <= 1'b0;
                                nReg <= 1'b0;
                                txReg <= 1'b1;
                                txReg <= 1'b1;
                        end     // end if
                        end     // end if
 
 
                        else
                        else
                        begin
                        begin
                                stateReg <= stateNext;
                                stateReg <= stateNext;
                                sReg <= sNext;
                                sReg <= sNext;
                                bReg <= bNext;
                                bReg <= bNext;
                                nReg <= nNext;
                                nReg <= nNext;
                                txReg <= txNext;
                                txReg <= txNext;
                        end     // end else
                        end     // end else
 
 
                end     // end always
                end     // end always
 
 
                // FSM:
                // FSM:
 
 
                always @ *
                always @ *
                begin
                begin
                                stateNext = stateReg;
                                stateNext = stateReg;
                                sNext = sReg;
                                sNext = sReg;
                                bNext = bReg;
                                bNext = bReg;
                                nNext = nReg;
                                nNext = nReg;
                                txNext = txReg;
                                txNext = txReg;
 
 
                                txDoneTick = 1'b0;              // not done yet!
                                txDoneTick = 1'b0;              // not done yet!
 
 
                        case    (stateReg)
                        case    (stateReg)
 
 
                                idle    :       begin
                                idle    :       begin
                                                                txNext = 1'b1;  // start bit '0'; thus, send '1' in idle
                                                                txNext = 1'b1;  // start bit '0'; thus, send '1' in idle
 
 
                                                                if (txStart)
                                                                if (txStart)
                                                                begin
                                                                begin
                                                                        txDoneTick = 1'b1;      // generate rd for fifo **
                                                                        txDoneTick = 1'b1;      // generate rd for fifo **
                                                                        stateNext = start;      // should go into start state
                                                                        stateNext = start;      // should go into start state
                                                                        sNext = 0;
                                                                        sNext = 0;
                                                                end     // end if txStart
                                                                end     // end if txStart
                                                        // in idle state unless txStart...
                                                        // in idle state unless txStart...
                                                        end     // end idle case
                                                        end     // end idle case
 
 
                                start   :       begin
                                start   :       begin
                                                                txNext = 0;
                                                                txNext = 0;
                                                                txDoneTick = 1'b0;              // **
                                                                txDoneTick = 1'b0;              // **
                                                                bNext = din;            // take din into bReg
                                                                bNext = din;            // take din into bReg
                                                                if (sTick)
                                                                if (sTick)
                                                                        if (sReg == 15)
                                                                        if (sReg == 15)
                                                                        begin
                                                                        begin
                                                                                stateNext = data;
                                                                                stateNext = data;
                                                                                sNext = 1'b0;
                                                                                sNext = 1'b0;
                                                                                nNext = 1'b0;
                                                                                nNext = 1'b0;
                                                                        end     // end if sReg==15
                                                                        end     // end if sReg==15
 
 
                                                                        else
                                                                        else
                                                                                sNext = sReg + 1;       // keep incrementing sNext (sReg)
                                                                                sNext = sReg + 1;       // keep incrementing sNext (sReg)
                                                                                // sReg = sNext on each clk edge !!
                                                                                // sReg = sNext on each clk edge !!
                                                        end     // end start case
                                                        end     // end start case
 
 
                                data    :       begin
                                data    :       begin
                                                                txNext = bReg[0];        // keep sending LSB of bReg
                                                                txNext = bReg[0];        // keep sending LSB of bReg
 
 
                                                                if (sTick)
                                                                if (sTick)
                                                                        if (sReg == 15)
                                                                        if (sReg == 15)
                                                                        begin
                                                                        begin
                                                                                sNext = 0;       // reset counter
                                                                                sNext = 0;       // reset counter
                                                                                bNext = bReg >> 1;      // shift word to be sent
                                                                                bNext = bReg >> 1;      // shift word to be sent
 
 
                                                                                if (nReg == (dataBits-1))
                                                                                if (nReg == (dataBits-1))
                                                                                        stateNext = stop;
                                                                                        stateNext = stop;
                                                                                else
                                                                                else
                                                                                        nNext = nReg +1;
                                                                                        nNext = nReg +1;
                                                                        end     // end if sReg==15
                                                                        end     // end if sReg==15
                                                                else
                                                                else
                                                                        sNext = sReg + 1;
                                                                        sNext = sReg + 1;
 
 
                                                        end     // end data state
                                                        end     // end data state
 
 
                                stop    :       begin
                                stop    :       begin
                                                                txNext = 1'b1;
                                                                txNext = 1'b1;
 
 
                                                                if (sTick)
                                                                if (sTick)
                                                                        if (sReg == sbTick-1)
                                                                        if (sReg == sbTick-1)
                                                                        begin
                                                                        begin
                                                                                stateNext = idle;
                                                                                stateNext = idle;
                                                                                //txDoneTick = 1'b1; it's working as read signal to
                                                                                //txDoneTick = 1'b1; it's working as read signal to
                                                                                // fifo, so, used at starting . . .
                                                                                // fifo, so, used at starting . . .
                                                                        end //end if sReg==15
                                                                        end //end if sReg==15
                                                                        else
                                                                        else
                                                                                sNext = sReg + 1;
                                                                                sNext = sReg + 1;
                                                        end     // end stop state
                                                        end     // end stop state
 
 
                        endcase
                        endcase
 
 
                end     // end always combinatorial
                end     // end always combinatorial
 
 
 
 
                // output bit-stream
                // output bit-stream
 
 
                assign tx = txReg;
                assign tx = txReg;
 
 
endmodule
endmodule
 
 

powered by: WebSVN 2.1.0

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