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

Subversion Repositories ppx16

[/] [ppx16/] [trunk/] [bench/] [vhdl/] [AsyncLog.vhd] - Blame information for rev 22

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jesus
--
2
-- Asynchronous serial input with binary file log
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 AsyncLog is
53
        generic(
54
                FileName                : string;
55
                Baud                    : integer;
56
                Bits                    : integer := 8;         -- Data bits
57
                Parity                  : boolean := false;     -- Enable Parity
58
                P_Odd_Even_n    : boolean := false      -- false => Even Parity, true => Odd Parity
59
        );
60
        port(
61
                RXD                             : in std_logic
62
        );
63
end AsyncLog;
64
 
65
architecture behaviour of AsyncLog is
66
 
67
        function to_char(
68
                constant Byte : std_logic_vector(7 downto 0)
69
        ) return character is
70
        begin
71
                return character'val(to_integer(unsigned(Byte)));
72
        end function;
73
 
74
        signal  Baud16                  : std_logic := '0';
75
 
76
        -- Receive signals
77
        signal  Bit_Phase               : unsigned(3 downto 0) := "0000";
78
        signal  RX_ShiftReg             : std_logic_vector(Bits - 1 downto 0) := (others => '0');
79
        signal  RX_Bit_Cnt              : integer := 0;
80
        signal  ParTmp                  : boolean;
81
 
82
begin
83
 
84
        Baud16 <= not Baud16 after 1000000000 ns / 32 / Baud;
85
 
86
        process (Baud16)
87
                type ChFile is file of character;
88
                file OutFile : ChFile open write_mode is FileName;
89
        begin
90
                if Baud16'event and Baud16 = '1' then
91
                        if RX_Bit_Cnt = 0 and (RXD = '1' or Bit_Phase = "0111") then
92
                                Bit_Phase <= "0000";
93
                        else
94
                                Bit_Phase <= Bit_Phase + 1;
95
                        end if;
96
                        if RX_Bit_Cnt = 0 then
97
                                if Bit_Phase = "0111" then
98
                                        RX_Bit_Cnt <= RX_Bit_Cnt + 1;
99
                                end if;
100
                                ParTmp <= false;
101
                        elsif Bit_Phase = "1111" then
102
                                RX_Bit_Cnt <= RX_Bit_Cnt + 1;
103
                                if (RX_Bit_Cnt = Bits + 1 and not Parity) or
104
                                        (RX_Bit_Cnt = Bits + 2 and Parity) then -- Stop bit
105
                                        RX_Bit_Cnt <= 0;
106
                                        assert RXD = '1'
107
                                                report "Framing error"
108
                                                severity error;
109
                                        write(OutFile, to_char(RX_ShiftReg(7 downto 0)));
110
                                elsif RX_Bit_Cnt = Bits + 1 and Parity then -- Parity bit
111
                                        assert ParTmp xor (RXD = '1') = P_Odd_Even_n
112
                                                report "Parity error"
113
                                                severity error;
114
                                else
115
                                        ParTmp <= ParTmp xor (RXD = '1');
116
                                        RX_ShiftReg(Bits - 2 downto 0) <= RX_ShiftReg(Bits - 1 downto 1);
117
                                        RX_ShiftReg(Bits - 1) <= RXD;
118
                                end if;
119
                        end if;
120
                end if;
121
        end process;
122
 
123
end;
124
 

powered by: WebSVN 2.1.0

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