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

Subversion Repositories scarts

[/] [scarts/] [trunk/] [processor/] [workspace/] [terasic_de2-115/] [VHDL/] [top_tb.vhd] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 jlechner
-----------------------------------------------------------------------
2
-- This file is part of SCARTS.
3
-- 
4
-- SCARTS is free software: you can redistribute it and/or modify
5
-- it under the terms of the GNU General Public License as published by
6
-- the Free Software Foundation, either version 3 of the License, or
7
-- (at your option) any later version.
8
-- 
9
-- SCARTS is distributed in the hope that it will be useful,
10
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
11
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
-- GNU General Public License for more details.
13
-- 
14
-- You should have received a copy of the GNU General Public License
15
-- along with SCARTS.  If not, see <http://www.gnu.org/licenses/>.
16
-----------------------------------------------------------------------
17
 
18
 
19
library ieee;
20
use ieee.std_logic_1164.all;
21
use ieee.numeric_std.all;
22
 
23
use work.scarts_pkg.all;
24
use work.pkg_dis7seg.all;
25
 
26
use std.textio.all;
27
 
28
entity top_tb is
29
end top_tb;
30
 
31
architecture behaviour of top_tb is
32
 
33
  constant  cc    : TIME := 20 ns;
34
  constant  bittime    : integer := 434; --8.681 us / 20 ns ;
35
 
36
  type parity_type is (none, even, odd);
37
 
38
  signal clk      : std_ulogic;
39
  signal rst      : std_ulogic;
40
  signal D_RxD    : std_logic;
41
  signal D_TxD    : std_logic;
42
  signal digits   : digit_vector_t(7 downto 0);
43
  file appFile : text  open read_mode is "app.srec";
44
 
45
  component top
46
    port (
47
      db_clk      : in    std_ulogic;
48
      rst      : in    std_ulogic;
49
      D_RxD    : in    std_logic;
50
      D_TxD    : out   std_logic;
51
      digits   : out digit_vector_t(7 downto 0));
52
 
53
  end component;
54
 
55
 
56
begin
57
 
58
  top_1: top
59
    port map (
60
      db_clk      => clk,
61
      rst      => rst,
62
      D_RxD    => D_RxD,
63
      D_TxD    => D_TxD,
64
      digits   => digits);
65
 
66
  clkgen : process
67
  begin
68
    clk <= '1';
69
    wait for cc/2;
70
    clk <= '0';
71
    wait for cc/2;
72
  end process clkgen;
73
 
74
 
75
  test: process
76
 
77
    procedure icwait(cycles: Natural) is
78
    begin
79
      for i in 1 to cycles loop
80
        wait until clk= '0' and clk'event;
81
      end loop;
82
    end ;
83
 
84
    procedure ser_send(send: Natural; parity: parity_type) is
85
      variable parityBit : std_logic;
86
    begin
87
      parityBit := '0';
88
      D_RxD <= '0';-- startbit(0)
89
      icwait(bittime);
90
 
91
      -- send data bits
92
      for i in 0 to 7 loop
93
        D_RxD <= to_unsigned(send,8)(i); icwait(bittime);
94
        parityBit := parityBit xor to_unsigned(send,8)(i);
95
      end loop;
96
 
97
      -- optional parity bit
98
      if parity /= none then
99
        if parity = odd then
100
          parityBit := not parityBit;
101
        end if;
102
        D_Rxd <= parityBit;
103
        icwait(bittime);
104
      end if;
105
 
106
      -- Stop1
107
      D_Rxd <= '1';
108
      icwait(bittime);
109
    end;
110
 
111
    variable l : line;
112
    variable c : character;
113
    variable neol : boolean;
114
 
115
  begin
116
 
117
    rst <= RST_ACT;
118
    D_Rxd <= '1';
119
    icwait(100);
120
    rst <= not RST_ACT;
121
 
122
    -- wait until bootloader is ready to receive program
123
    icwait(2000);
124
 
125
    while not endfile(appFile) loop
126
      readline(appFile, l);
127
      loop
128
        read(l, c, neol);
129
        exit when not neol;
130
        ser_send(character'pos(c), even);
131
      end loop;
132
      -- newline
133
      ser_send(10, even);
134
    end loop;
135
 
136
    wait;
137
 
138
  end process test;
139
 
140
 
141
 
142
end behaviour;
143
 

powered by: WebSVN 2.1.0

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