1 // -----------------------------------------------------------------------
3 // Copyright 2004,2006 Tommy Thorn - All Rights Reserved
5 // This program 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, Inc., 53 Temple Place Ste 330,
8 // Bostom MA 02111-1307, USA; either version 2 of the License, or
9 // (at your option) any later version; incorporated herein by reference.
11 // -----------------------------------------------------------------------
15 module rs232out(// Control
20 output wire serial_out
,
23 input wire [7:0] transmit_data
,
27 //parameter bps = 9_600;
28 parameter bps
= 57_600;
29 //parameter bps = 115_200;
30 parameter frequency
= 25_000_000;
32 parameter period
= frequency
/ bps
;
34 // One of the very few simulation artifacts we have to deal with at the source level.
37 parameter TTYCLK_SIGN
= 12; // 2^TTYCLK_SIGN > period * 2
38 parameter COUNT_SIGN
= 4;
40 reg [TTYCLK_SIGN
:0] ttyclk
= 0; // [-4096; 4095]
41 reg [8:0] shift_out
= 0;
42 reg [COUNT_SIGN
:0] count
= 0; // [-16; 15]
44 assign serial_out
= shift_out
[0];
45 assign busy
= ~count
[COUNT_SIGN
] |
~ttyclk
[TTYCLK_SIGN
];
47 always @(posedge clk25MHz
)
52 end else if (~ttyclk
[TTYCLK_SIGN
]) begin
54 end else if (~count
[COUNT_SIGN
]) begin
57 shift_out
<= {1'b1, shift_out
[8:1]};
58 end else if (we
) begin
60 count
<= 9; // 1 start bit + 8 data + 1 stop - 1 due to SIGN trick
61 shift_out
<= {transmit_data
, 1'b0};