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

Subversion Repositories aoocs

[/] [aoocs/] [trunk/] [tests/] [serial_txd.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 alfik
/*
2
 * Copyright 2010, Aleksander Osman, alfik@poczta.fm. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without modification, are
5
 * permitted provided that the following conditions are met:
6
 *
7
 *  1. Redistributions of source code must retain the above copyright notice, this list of
8
 *     conditions and the following disclaimer.
9
 *
10
 *  2. Redistributions in binary form must reproduce the above copyright notice, this list
11
 *     of conditions and the following disclaimer in the documentation and/or other materials
12
 *     provided with the distribution.
13
 *
14
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
15
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16
 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR
17
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
 */
24
 
25
module serial_txd(
26
        input clk_30,
27
        input reset_n,
28
 
29
        // WISHBONE slave
30
        input [7:0] DAT_I,
31
    output reg ACK_O,
32
 
33
        input CYC_I,
34
        input STB_I,
35
        input WE_I,
36
 
37
        //serial output
38
        input uart_rxd,
39
        input uart_rts,
40
        output reg uart_txd,
41
        output uart_cts
42
);
43
 
44
assign uart_cts = uart_rts;
45
 
46
reg [12:0] counter;
47
 
48
// 115200 baud -> 8680.5555 ns / bit = 260 * 33.333 ns 
49
parameter [9:0] one_bit = 10'd260;
50
 
51
always @(posedge clk_30 or negedge reset_n) begin
52
        if(reset_n == 1'b0) begin
53
                ACK_O <= 1'b0;
54
                uart_txd <= 1'b1;
55
                counter <= 13'd0;
56
        end
57
 
58
        else if(CYC_I == 1'b1 && STB_I == 1'b1 && WE_I == 1'b1 && ACK_O == 1'b0) begin
59
                if(counter < 13'd8191) counter <= counter + 13'd1;
60
 
61
 
62
                if(counter < one_bit*1)                 uart_txd <= 1'b0;
63
                else if(counter < one_bit*2)    uart_txd <= DAT_I[0];
64
                else if(counter < one_bit*3)    uart_txd <= DAT_I[1];
65
                else if(counter < one_bit*4)    uart_txd <= DAT_I[2];
66
                else if(counter < one_bit*5)    uart_txd <= DAT_I[3];
67
                else if(counter < one_bit*6)    uart_txd <= DAT_I[4];
68
                else if(counter < one_bit*7)    uart_txd <= DAT_I[5];
69
                else if(counter < one_bit*8)    uart_txd <= DAT_I[6];
70
                else if(counter < one_bit*9)    uart_txd <= DAT_I[7];
71
                else if(counter < one_bit*10)   uart_txd <= 1'b1;
72
                else begin
73
                        uart_txd <= 1'b1;
74
                        ACK_O <= 1'b1;
75
                end
76
        end
77
        else begin
78
                ACK_O <= 1'b0;
79
                uart_txd <= 1'b1;
80
                counter <= 13'd0;
81
        end
82
end
83
 
84
endmodule
85
 

powered by: WebSVN 2.1.0

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