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

Subversion Repositories yacc

[/] [yacc/] [trunk/] [syn/] [xilinx/] [uart_write_cyclone.v] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 tak.sugawa
`include "define.h"
2
//Apr.5.2005 Tak.Sugawara
3
//Jul.14.2004
4
 
5
 
6
module  uart_write( sync_reset, clk, txd, data_in , write_request,write_done,write_busy);
7
        input sync_reset,clk;
8
        input [7:0] data_in;
9
        input write_request;
10
        output txd,write_done;
11
        output write_busy;
12
 
13
 
14
 
15
        wire            queue_full;
16
        wire    queing, read_request;
17
        wire [7:0] queue_data;
18
        reg read_request_ff;
19
 
20
 
21
//________|--|___write_request (upper  module :     its period should be 1clock time.)
22
//__________________________|-|______write_done    (Responds by this module posedge interrupt)
23
//With 512Bytes FIFO.
24
//No error handling is supported.
25
 
26
        reg             [8:0] clk_ctr;
27
        reg             [2:0] bit_ctr;
28
        reg             [2:0] ua_state;
29
        reg             [7:0] tx_sr;
30
        reg             write_done_n;
31
        reg             txd;
32
 
33
        wire     clk_ctr_equ15, clk_ctr_equ31,  bit_ctr_equ7,
34
                           clk_ctr_enable_state, bit_ctr_enable_state  ;
35
        wire    tx_state;
36
        wire empty;
37
        assign write_busy=queue_full;//Apr.2.2005
38
 
39
        always @ (posedge clk) begin
40
                if (sync_reset) read_request_ff<=1'b0;
41
                else                    read_request_ff<=read_request;
42
        end
43
 
44
        assign queing=  !empty;
45
        assign read_request      = queing && ua_state==3'b000;//Jul.14.2004 
46
 
47
        assign write_done=ua_state==3'b101;
48
 
49
`ifdef ALTERA
50
 fifo512_cyclone  fifo(
51
        .data(data_in),
52
        .wrreq(write_request),
53
        .rdreq(read_request),
54
        .clock(clk),
55
        .q(queue_data),
56
        .full(queue_full),
57
        .empty(empty));
58
`else//XILINX coregen
59
 
60
 fifo    fifo(
61
        .clk(clk),
62
        .sinit(sync_reset),
63
        .din(data_in),
64
        .wr_en(write_request),
65
        .rd_en(read_request),
66
        .dout(queue_data),
67
        .full(queue_full),
68
        .empty(empty));
69
 
70
 
71
`endif
72
 
73
 
74
 
75
// 7bit counter
76
        always @(posedge clk ) begin
77
                if (sync_reset)
78
                        clk_ctr <= 0;
79
                else if (clk_ctr_enable_state && clk_ctr_equ31)  clk_ctr<=0;
80
                else if (clk_ctr_enable_state)                   clk_ctr <= clk_ctr + 1;
81
                else    clk_ctr <= 0;
82
        end
83
 
84
 
85
        assign  clk_ctr_equ15 = clk_ctr==`COUNTER_VALUE1;
86
        assign  clk_ctr_equ31 = clk_ctr==`COUNTER_VALUE2;
87
 
88
        // 3bit counter
89
        always @(posedge clk) begin
90
                if (sync_reset)
91
                        bit_ctr <= 0;
92
                else if (bit_ctr_enable_state) begin
93
                        if (clk_ctr_equ15)
94
                                bit_ctr <= bit_ctr + 1;
95
                end
96
                else
97
                        bit_ctr <= 0;
98
        end
99
 
100
        assign  bit_ctr_equ7 = (bit_ctr==7);
101
 
102
 
103
 
104
        assign  clk_ctr_enable_state = bit_ctr_enable_state ||  ua_state==3'b001 ||  ua_state==3'b100 ;
105
        assign  bit_ctr_enable_state =  ua_state==3'b010 || ua_state==3'b011;
106
 
107
 
108
        always @(posedge clk ) begin
109
                if (sync_reset) ua_state <= 3'b000;
110
                else begin
111
                        case (ua_state)
112
                                3'b000: if (queing)  ua_state <= 3'b001;        //wait write_request
113
                                3'b001: if ( clk_ctr_equ15) ua_state <= 3'b010; // write start bit
114
                                3'b010: if (bit_ctr_equ7 & clk_ctr_equ15) ua_state <= 3'b011;           // start bit, bit0-7 data  send
115
                                3'b011: if (clk_ctr_equ15) ua_state <= 3'b100;                                  // bit7 data send
116
                                3'b100: if (clk_ctr_equ15) ua_state <= 3'b101;  // stop bit                             // stop bit send
117
                                3'b101:  ua_state <= 3'h0;      // TAK                                  // byte read cycle end
118
                                default: ua_state <= 3'h0;
119
                        endcase
120
                end
121
        end
122
 
123
 
124
 
125
 
126
 
127
 
128
 
129
 
130
 
131
 
132
 
133
 
134
// tx shift reg.
135
        always @(posedge clk ) begin
136
                if (sync_reset) tx_sr<=0;
137
                else if (read_request_ff) tx_sr <= queue_data[7:0]; //data_in[7:0]; // load
138
                else if (tx_state ) tx_sr <= {1'b0, tx_sr[7:1]};
139
        end
140
 
141
        assign  tx_state=(  ua_state==3'h2 || ua_state==3'h3)           &&      clk_ctr_equ15;
142
 
143
 
144
// tx
145
        always @(posedge clk ) begin
146
                if (sync_reset) txd <=1'b1;
147
                else if (sync_reset)                      txd<=1'b1;
148
                else if (ua_state==3'h0)                  txd<=1'b1;
149
                else if (ua_state==3'h1 && clk_ctr_equ15) txd<=1'b0;    // start bit
150
                else if (ua_state==3'h2 && clk_ctr_equ15) txd<=tx_sr[0];
151
                else if (ua_state==3'h3 && clk_ctr_equ15) txd<=1'b1;     // stop bit
152
        end
153
endmodule

powered by: WebSVN 2.1.0

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