1 |
2 |
dimamali |
------------------------------------------------------------------------------
|
2 |
|
|
-- This file is a part of the GRLIB VHDL IP LIBRARY
|
3 |
|
|
-- Copyright (C) 2003, Gaisler Research
|
4 |
|
|
--
|
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; either version 2 of the License, or
|
8 |
|
|
-- (at your option) any later version.
|
9 |
|
|
--
|
10 |
|
|
-- This program is distributed in the hope that it will be useful,
|
11 |
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
|
|
-- GNU General Public License for more details.
|
14 |
|
|
--
|
15 |
|
|
-- You should have received a copy of the GNU General Public License
|
16 |
|
|
-- along with this program; if not, write to the Free Software
|
17 |
|
|
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
18 |
|
|
-----------------------------------------------------------------------------
|
19 |
|
|
-- Package: libdcom
|
20 |
|
|
-- File: libdcom.vhd
|
21 |
|
|
-- Author: Jiri Gaisler - Gaisler Research
|
22 |
|
|
-- Description: Types, functions and components for DSU uart
|
23 |
|
|
-----------------------------------------------------------------------------
|
24 |
|
|
|
25 |
|
|
library ieee;
|
26 |
|
|
use ieee.std_logic_1164.all;
|
27 |
|
|
library grlib;
|
28 |
|
|
use grlib.amba.all;
|
29 |
|
|
use grlib.stdlib.all;
|
30 |
|
|
library gaisler;
|
31 |
|
|
use gaisler.uart.all;
|
32 |
|
|
use gaisler.misc.all;
|
33 |
|
|
|
34 |
|
|
package libdcom is
|
35 |
|
|
|
36 |
|
|
type dcom_uart_in_type is record
|
37 |
|
|
read : std_ulogic;
|
38 |
|
|
write : std_ulogic;
|
39 |
|
|
data : std_logic_vector(7 downto 0);
|
40 |
|
|
end record;
|
41 |
|
|
|
42 |
|
|
type dcom_uart_out_type is record
|
43 |
|
|
dready : std_ulogic;
|
44 |
|
|
tsempty : std_ulogic;
|
45 |
|
|
thempty : std_ulogic;
|
46 |
|
|
lock : std_ulogic;
|
47 |
|
|
enable : std_ulogic;
|
48 |
|
|
data : std_logic_vector(7 downto 0);
|
49 |
|
|
end record;
|
50 |
|
|
|
51 |
|
|
component dcom_uart
|
52 |
|
|
generic (
|
53 |
|
|
pindex : integer := 0;
|
54 |
|
|
paddr : integer := 0;
|
55 |
|
|
pmask : integer := 16#fff#
|
56 |
|
|
);
|
57 |
|
|
port (
|
58 |
|
|
rst : in std_ulogic;
|
59 |
|
|
clk : in std_ulogic;
|
60 |
|
|
ui : in uart_in_type;
|
61 |
|
|
uo : out uart_out_type;
|
62 |
|
|
apbi : in apb_slv_in_type;
|
63 |
|
|
apbo : out apb_slv_out_type;
|
64 |
|
|
uarti : in dcom_uart_in_type;
|
65 |
|
|
uarto : out dcom_uart_out_type
|
66 |
|
|
);
|
67 |
|
|
end component;
|
68 |
|
|
|
69 |
|
|
component dcom
|
70 |
|
|
port (
|
71 |
|
|
rst : in std_ulogic;
|
72 |
|
|
clk : in std_ulogic;
|
73 |
|
|
dmai : out ahb_dma_in_type;
|
74 |
|
|
dmao : in ahb_dma_out_type;
|
75 |
|
|
uarti : out dcom_uart_in_type;
|
76 |
|
|
uarto : in dcom_uart_out_type;
|
77 |
|
|
ahbi : in ahb_mst_in_type
|
78 |
|
|
);
|
79 |
|
|
end component;
|
80 |
|
|
|
81 |
|
|
|
82 |
|
|
-- pragma translate_off
|
83 |
|
|
|
84 |
|
|
procedure rxc(signal rxd : in std_logic; d: out std_logic_vector;
|
85 |
|
|
txperiod : time);
|
86 |
|
|
|
87 |
|
|
procedure rxi(signal rxd : in std_logic; d: out std_logic_vector;
|
88 |
|
|
txperiod : time; lresp : boolean);
|
89 |
|
|
|
90 |
|
|
procedure txc(signal txd : out std_logic; td : integer;
|
91 |
|
|
txperiod : time);
|
92 |
|
|
|
93 |
|
|
procedure txa(signal txd : out std_logic; td1, td2, td3, td4 : integer;
|
94 |
|
|
txperiod : time);
|
95 |
|
|
|
96 |
|
|
procedure txi(signal rxd : in std_logic; signal txd : out std_logic;
|
97 |
|
|
td1, td2, td3, td4 : integer; txperiod : time;
|
98 |
|
|
lresp : boolean);
|
99 |
|
|
|
100 |
|
|
-- pragma translate_on
|
101 |
|
|
|
102 |
|
|
end;
|
103 |
|
|
|
104 |
|
|
-- pragma translate_off
|
105 |
|
|
|
106 |
|
|
package body libdcom is
|
107 |
|
|
|
108 |
|
|
procedure rxc(signal rxd : in std_logic; d: out std_logic_vector;
|
109 |
|
|
txperiod : time) is
|
110 |
|
|
variable rxdata : std_logic_vector(7 downto 0);
|
111 |
|
|
begin
|
112 |
|
|
wait until rxd = '0'; wait for TXPERIOD/2;
|
113 |
|
|
for i in 0 to 7 loop wait for TXPERIOD; rxdata(i):= rxd; end loop;
|
114 |
|
|
wait for TXPERIOD ;
|
115 |
|
|
d := rxdata;
|
116 |
|
|
end;
|
117 |
|
|
|
118 |
|
|
procedure rxi(signal rxd : in std_logic; d: out std_logic_vector;
|
119 |
|
|
txperiod : time; lresp : boolean) is
|
120 |
|
|
variable rxdata : std_logic_vector(31 downto 0);
|
121 |
|
|
variable resp : std_logic_vector(7 downto 0);
|
122 |
|
|
begin
|
123 |
|
|
for i in 3 downto 0 loop
|
124 |
|
|
rxc(rxd, rxdata((i*8 +7) downto i*8), txperiod);
|
125 |
|
|
end loop;
|
126 |
|
|
d := rxdata;
|
127 |
|
|
if LRESP then
|
128 |
|
|
rxc(rxd, resp, txperiod);
|
129 |
|
|
-- print("RESP : 0x" & tosth(resp));
|
130 |
|
|
end if;
|
131 |
|
|
end;
|
132 |
|
|
|
133 |
|
|
procedure txc(signal txd : out std_logic; td : integer;
|
134 |
|
|
txperiod : time) is
|
135 |
|
|
variable txdata : std_logic_vector(10 downto 0);
|
136 |
|
|
begin
|
137 |
|
|
txdata := "11" & conv_std_logic_vector(td, 8) & '0';
|
138 |
|
|
for i in 0 to 10 loop wait for TXPERIOD ; txd <= txdata(i); end loop;
|
139 |
|
|
end;
|
140 |
|
|
|
141 |
|
|
procedure txa(signal txd : out std_logic; td1, td2, td3, td4 : integer;
|
142 |
|
|
txperiod : time) is
|
143 |
|
|
variable txdata : std_logic_vector(43 downto 0);
|
144 |
|
|
begin
|
145 |
|
|
txdata := "11" & conv_std_logic_vector(td4, 8) & '0'
|
146 |
|
|
& "11" & conv_std_logic_vector(td3, 8) & '0'
|
147 |
|
|
& "11" & conv_std_logic_vector(td2, 8) & '0'
|
148 |
|
|
& "11" & conv_std_logic_vector(td1, 8) & '0';
|
149 |
|
|
for i in 0 to 43 loop wait for TXPERIOD ; txd <= txdata(i); end loop;
|
150 |
|
|
end;
|
151 |
|
|
|
152 |
|
|
procedure txi(signal rxd : in std_logic; signal txd : out std_logic;
|
153 |
|
|
td1, td2, td3, td4 : integer; txperiod : time;
|
154 |
|
|
lresp : boolean) is
|
155 |
|
|
variable txdata : std_logic_vector(43 downto 0);
|
156 |
|
|
begin
|
157 |
|
|
txdata := "11" & conv_std_logic_vector(td4, 8) & '0'
|
158 |
|
|
& "11" & conv_std_logic_vector(td3, 8) & '0'
|
159 |
|
|
& "11" & conv_std_logic_vector(td2, 8) & '0'
|
160 |
|
|
& "11" & conv_std_logic_vector(td1, 8) & '0';
|
161 |
|
|
for i in 0 to 43 loop wait for TXPERIOD ; txd <= txdata(i); end loop;
|
162 |
|
|
if LRESP then
|
163 |
|
|
rxc(rxd, txdata(7 downto 0), txperiod);
|
164 |
|
|
-- print("RESP : 0x" & tosth(txdata(7 downto 0)));
|
165 |
|
|
end if;
|
166 |
|
|
end;
|
167 |
|
|
|
168 |
|
|
end;
|
169 |
|
|
|
170 |
|
|
-- pragma translate_on
|