1 |
2 |
jesus |
--
|
2 |
|
|
-- Asynchronous serial generator with input from binary file
|
3 |
|
|
--
|
4 |
|
|
-- Version : 0146
|
5 |
|
|
--
|
6 |
|
|
-- Copyright (c) 2001 Daniel Wallner (jesus@opencores.org)
|
7 |
|
|
--
|
8 |
|
|
-- All rights reserved
|
9 |
|
|
--
|
10 |
|
|
-- Redistribution and use in source and synthezised forms, with or without
|
11 |
|
|
-- modification, are permitted provided that the following conditions are met:
|
12 |
|
|
--
|
13 |
|
|
-- Redistributions of source code must retain the above copyright notice,
|
14 |
|
|
-- this list of conditions and the following disclaimer.
|
15 |
|
|
--
|
16 |
|
|
-- Redistributions in synthesized form must reproduce the above copyright
|
17 |
|
|
-- notice, this list of conditions and the following disclaimer in the
|
18 |
|
|
-- documentation and/or other materials provided with the distribution.
|
19 |
|
|
--
|
20 |
|
|
-- Neither the name of the author nor the names of other contributors may
|
21 |
|
|
-- be used to endorse or promote products derived from this software without
|
22 |
|
|
-- specific prior written permission.
|
23 |
|
|
--
|
24 |
|
|
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
25 |
|
|
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
26 |
|
|
-- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
27 |
|
|
-- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
|
28 |
|
|
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
29 |
|
|
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
30 |
|
|
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
31 |
|
|
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
32 |
|
|
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
33 |
|
|
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
34 |
|
|
-- POSSIBILITY OF SUCH DAMAGE.
|
35 |
|
|
--
|
36 |
|
|
-- Please report bugs to the author, but before you do so, please
|
37 |
|
|
-- make sure that this is not a derivative work and that
|
38 |
|
|
-- you have the latest version of this file.
|
39 |
|
|
--
|
40 |
|
|
-- The latest version of this file can be found at:
|
41 |
|
|
-- http://www.opencores.org/cvsweb.shtml/t51/
|
42 |
|
|
--
|
43 |
|
|
-- Limitations :
|
44 |
|
|
--
|
45 |
|
|
-- File history :
|
46 |
|
|
--
|
47 |
|
|
|
48 |
|
|
library IEEE;
|
49 |
|
|
use IEEE.std_logic_1164.all;
|
50 |
|
|
use IEEE.numeric_std.all;
|
51 |
|
|
|
52 |
|
|
entity AsyncStim is
|
53 |
|
|
generic(
|
54 |
|
|
FileName : string;
|
55 |
|
|
Baud : integer;
|
56 |
|
|
InterCharDelay : time := 0 ns;
|
57 |
|
|
Bits : integer := 8; -- Data bits
|
58 |
|
|
Parity : boolean := false; -- Enable Parity
|
59 |
|
|
P_Odd_Even_n : boolean := false -- false => Even Parity, true => Odd Parity
|
60 |
|
|
);
|
61 |
|
|
port(
|
62 |
|
|
TXD : out std_logic
|
63 |
|
|
);
|
64 |
|
|
end AsyncStim;
|
65 |
|
|
|
66 |
|
|
architecture behaviour of AsyncStim is
|
67 |
|
|
|
68 |
|
|
signal TX_ShiftReg : std_logic_vector(Bits - 1 downto 0);
|
69 |
|
|
signal TX_Bit_Cnt : integer range 0 to 15 := 0;
|
70 |
|
|
signal ParTmp : boolean;
|
71 |
|
|
|
72 |
|
|
begin
|
73 |
|
|
|
74 |
|
|
process
|
75 |
|
|
type ChFile is file of character;
|
76 |
|
|
file InFile : ChFile open read_mode is FileName;
|
77 |
|
|
variable Inited : boolean := false;
|
78 |
|
|
variable CharTmp : character;
|
79 |
|
|
variable IntTmp : integer;
|
80 |
|
|
begin
|
81 |
|
|
if not Inited then
|
82 |
|
|
Inited := true;
|
83 |
|
|
TXD <= '1';
|
84 |
|
|
end if;
|
85 |
|
|
wait for 1000000000 ns / Baud;
|
86 |
|
|
TX_Bit_Cnt <= TX_Bit_Cnt + 1;
|
87 |
|
|
case TX_Bit_Cnt is
|
88 |
|
|
when 0 =>
|
89 |
|
|
TXD <= '1';
|
90 |
|
|
wait for InterCharDelay;
|
91 |
|
|
when 1 => -- Start bit
|
92 |
|
|
read(InFile, CharTmp);
|
93 |
|
|
IntTmp := character'pos(CharTmp);
|
94 |
|
|
TX_ShiftReg(Bits - 1 downto 0) <= std_logic_vector(to_unsigned(IntTmp, Bits));
|
95 |
|
|
TXD <= '0';
|
96 |
|
|
ParTmp <= P_Odd_Even_n;
|
97 |
|
|
when others =>
|
98 |
|
|
TXD <= TX_ShiftReg(0);
|
99 |
|
|
ParTmp <= ParTmp xor (TX_ShiftReg(0) = '1');
|
100 |
|
|
TX_ShiftReg(Bits - 2 downto 0) <= TX_ShiftReg(Bits - 1 downto 1);
|
101 |
|
|
if (TX_Bit_Cnt = Bits + 1 and not Parity) or
|
102 |
|
|
(TX_Bit_Cnt = Bits + 2 and Parity) then -- Stop bit
|
103 |
|
|
TX_Bit_Cnt <= 0;
|
104 |
|
|
end if;
|
105 |
|
|
if Parity and TX_Bit_Cnt = Bits + 2 then
|
106 |
|
|
if ParTmp then
|
107 |
|
|
TXD <= '1';
|
108 |
|
|
else
|
109 |
|
|
TXD <= '0';
|
110 |
|
|
end if;
|
111 |
|
|
end if;
|
112 |
|
|
end case;
|
113 |
|
|
end process;
|
114 |
|
|
|
115 |
|
|
end;
|