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

Subversion Repositories s80186

[/] [s80186/] [trunk/] [fpga/] [uart/] [Transmitter.sv] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jamieiles
// Copyright Jamie Iles, 2017
2
//
3
// This file is part of s80x86.
4
//
5
// s80x86 is free software: you can redistribute it and/or modify
6
// it under the terms of the GNU General Public License as published by
7
// the Free Software Foundation, either version 3 of the License, or
8
// (at your option) any later version.
9
//
10
// s80x86 is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
// GNU General Public License for more details.
14
//
15
// You should have received a copy of the GNU General Public License
16
// along with s80x86.  If not, see .
17
 
18
module Transmitter(input logic clk,
19
                   input logic reset,
20
                   input logic clken,
21
                   input logic [7:0] din,
22
                   input logic wr_en,
23
                   output logic tx,
24
                   output logic tx_busy);
25
 
26
typedef enum logic [1:0] {
27
    STATE_IDLE,
28
    STATE_START,
29
    STATE_DATA,
30
    STATE_STOP
31
} state_t;
32
 
33
reg [7:0] data;
34
reg [2:0] bitpos;
35
state_t state;
36
 
37
always_ff @(posedge clk or posedge reset) begin
38
    if (reset) begin
39
        state <= STATE_IDLE;
40
        data <= 8'b0;
41
        bitpos <= 3'b0;
42
        tx <= 1'b1;
43
    end else begin
44
        case (state)
45
        STATE_IDLE: begin
46
            if (wr_en) begin
47
                state <= STATE_START;
48
                data <= din;
49
                bitpos <= 3'h0;
50
            end
51
        end
52
        STATE_START: begin
53
            if (clken) begin
54
                tx <= 1'b0;
55
                state <= STATE_DATA;
56
            end
57
        end
58
        STATE_DATA: begin
59
            if (clken) begin
60
                if (bitpos == 3'h7)
61
                    state <= STATE_STOP;
62
                else
63
                    bitpos <= bitpos + 3'h1;
64
                tx <= data[bitpos];
65
            end
66
        end
67
        STATE_STOP: begin
68
            if (clken) begin
69
                tx <= 1'b1;
70
                state <= STATE_IDLE;
71
            end
72
        end
73
        default: begin
74
            tx <= 1'b1;
75
            state <= STATE_IDLE;
76
        end
77
        endcase
78
    end
79
end
80
 
81
assign tx_busy = (state != STATE_IDLE);
82
 
83
endmodule

powered by: WebSVN 2.1.0

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