| 1 |
14 |
nussgipfel |
-- GECKO3COM IP Core
|
| 2 |
|
|
--
|
| 3 |
|
|
-- Copyright (C) 2009 by
|
| 4 |
|
|
-- ___ ___ _ _
|
| 5 |
|
|
-- ( _ \ ( __)( ) ( )
|
| 6 |
|
|
-- | (_) )| ( | |_| | Bern University of Applied Sciences
|
| 7 |
|
|
-- | _ < | _) | _ | School of Engineering and
|
| 8 |
|
|
-- | (_) )| | | | | | Information Technology
|
| 9 |
|
|
-- (____/ (_) (_) (_)
|
| 10 |
|
|
--
|
| 11 |
|
|
-- This program is free software: you can redistribute it and/or modify
|
| 12 |
|
|
-- it under the terms of the GNU General Public License as published by
|
| 13 |
|
|
-- the Free Software Foundation, either version 3 of the License, or
|
| 14 |
|
|
-- (at your option) any later version.
|
| 15 |
|
|
--
|
| 16 |
|
|
-- This program is distributed in the hope that it will be useful,
|
| 17 |
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 18 |
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 19 |
|
|
-- GNU General Public License for more details.
|
| 20 |
|
|
-- You should have received a copy of the GNU General Public License
|
| 21 |
|
|
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 22 |
|
|
--
|
| 23 |
|
|
-- URL to the project description:
|
| 24 |
|
|
-- http://labs.ti.bfh.ch/gecko/wiki/systems/gecko3com/start
|
| 25 |
18 |
nussgipfel |
--------------------------------------------------------------------------------
|
| 26 |
14 |
nussgipfel |
--
|
| 27 |
|
|
-- Author: Christoph Zimmermann
|
| 28 |
|
|
-- Date of creation: 8. April 2009
|
| 29 |
|
|
-- Description:
|
| 30 |
18 |
nussgipfel |
-- First test scenario for the GECKO3com IP core.
|
| 31 |
|
|
-- This module (to be implemented as top module) is used to test the
|
| 32 |
14 |
nussgipfel |
-- low-level communication between the GPIF from the EZ-USB and the FPGA.
|
| 33 |
|
|
-- For this, it instantiates the the gpif_com module, reads all the
|
| 34 |
|
|
-- received data from the FIFO (and puts them to nowhere) and writes a pre
|
| 35 |
|
|
-- defined USB TMC response packet to the send FIFO.
|
| 36 |
|
|
--
|
| 37 |
|
|
-- If you would like to change the USB TMC response, you have to change the
|
| 38 |
|
|
-- ROM content in this file (don't forget to adjust the the transfer size
|
| 39 |
|
|
-- field AND the counter limit).
|
| 40 |
|
|
--
|
| 41 |
18 |
nussgipfel |
-- Target Devices: Xilinx Spartan3 FPGA's (usage of BlockRam in the
|
| 42 |
|
|
-- Datapath)
|
| 43 |
|
|
-- Tool versions: 11.1
|
| 44 |
14 |
nussgipfel |
-- Dependencies:
|
| 45 |
|
|
--
|
| 46 |
18 |
nussgipfel |
--------------------------------------------------------------------------------
|
| 47 |
14 |
nussgipfel |
|
| 48 |
11 |
nussgipfel |
library ieee;
|
| 49 |
|
|
use ieee.std_logic_1164.all;
|
| 50 |
18 |
nussgipfel |
use ieee.std_logic_unsigned.all;
|
| 51 |
11 |
nussgipfel |
|
| 52 |
|
|
library work;
|
| 53 |
14 |
nussgipfel |
use work.GECKO3COM_defines.all;
|
| 54 |
11 |
nussgipfel |
|
| 55 |
14 |
nussgipfel |
entity gpif_com_test is
|
| 56 |
11 |
nussgipfel |
port (
|
| 57 |
18 |
nussgipfel |
i_nReset : in std_logic;
|
| 58 |
|
|
i_IFCLK : in std_logic; -- GPIF CLK (GPIF is Master and provides the clock)
|
| 59 |
|
|
i_SYSCLK : in std_logic; -- FPGA System CLK
|
| 60 |
|
|
i_WRU : in std_logic; -- write from GPIF
|
| 61 |
|
|
i_RDYU : in std_logic; -- GPIF is ready
|
| 62 |
|
|
o_WRX : out std_logic; -- To write to GPIF
|
| 63 |
|
|
o_RDYX : out std_logic; -- IP Core is ready
|
| 64 |
|
|
b_gpif_bus : inout std_logic_vector(SIZE_DBUS_GPIF-1 downto 0); -- bidirect data bus
|
| 65 |
|
|
o_LEDrx : out std_logic; -- controll LED rx
|
| 66 |
|
|
o_LEDtx : out std_logic; -- controll LED tx
|
| 67 |
|
|
o_LEDrun : out std_logic; -- controll LED running signalisation
|
| 68 |
|
|
o_dummy : out std_logic -- dummy output for RX data consumer
|
| 69 |
|
|
);
|
| 70 |
14 |
nussgipfel |
end gpif_com_test;
|
| 71 |
11 |
nussgipfel |
|
| 72 |
|
|
|
| 73 |
|
|
|
| 74 |
18 |
nussgipfel |
architecture behaviour of gpif_com_test is
|
| 75 |
11 |
nussgipfel |
|
| 76 |
|
|
|
| 77 |
|
|
-----------------------------------------------------------------------------
|
| 78 |
|
|
-- controll bus
|
| 79 |
|
|
-----------------------------------------------------------------------------
|
| 80 |
18 |
nussgipfel |
signal s_EMPTY, s_FULL : std_logic;
|
| 81 |
|
|
signal s_RX_DATA : std_logic_vector(SIZE_DBUS_GPIF-1 downto 0);
|
| 82 |
|
|
signal s_RD_EN, s_WR_EN : std_logic;
|
| 83 |
|
|
signal s_TX_DATA : std_logic_vector(SIZE_DBUS_GPIF-1 downto 0);
|
| 84 |
|
|
|
| 85 |
|
|
signal s_ABORT, s_ABORT_TMP : std_logic;
|
| 86 |
11 |
nussgipfel |
|
| 87 |
18 |
nussgipfel |
signal s_RX_DATA_TMP : std_logic_vector(SIZE_DBUS_GPIF-1 downto 0);
|
| 88 |
|
|
signal s_EMPTY_TMP, s_FULL_TMP : std_logic;
|
| 89 |
11 |
nussgipfel |
|
| 90 |
18 |
nussgipfel |
signal s_rom_adress : std_logic_vector(4 downto 0);
|
| 91 |
|
|
|
| 92 |
|
|
|
| 93 |
|
|
-----------------------------------------------------------------------------
|
| 94 |
14 |
nussgipfel |
-- COMPONENTS
|
| 95 |
18 |
nussgipfel |
-----------------------------------------------------------------------------
|
| 96 |
|
|
|
| 97 |
14 |
nussgipfel |
component gpif_com
|
| 98 |
18 |
nussgipfel |
port (
|
| 99 |
|
|
i_nReset : in std_logic;
|
| 100 |
|
|
i_SYSCLK : in std_logic;
|
| 101 |
|
|
o_ABORT : out std_logic;
|
| 102 |
|
|
o_RX : out std_logic;
|
| 103 |
|
|
o_TX : out std_logic;
|
| 104 |
|
|
i_RD_EN : in std_logic;
|
| 105 |
|
|
o_EMPTY : out std_logic;
|
| 106 |
|
|
o_RX_DATA : out std_logic_vector(SIZE_DBUS_GPIF-1 downto 0);
|
| 107 |
|
|
i_WR_EN : in std_logic;
|
| 108 |
|
|
o_FULL : out std_logic;
|
| 109 |
|
|
i_TX_DATA : in std_logic_vector(SIZE_DBUS_GPIF-1 downto 0);
|
| 110 |
|
|
i_IFCLK : in std_logic;
|
| 111 |
|
|
i_WRU : in std_logic;
|
| 112 |
|
|
i_RDYU : in std_logic;
|
| 113 |
|
|
o_WRX : out std_logic;
|
| 114 |
|
|
o_RDYX : out std_logic;
|
| 115 |
|
|
b_gpif_bus : inout std_logic_vector(SIZE_DBUS_GPIF-1 downto 0));
|
| 116 |
|
|
end component;
|
| 117 |
11 |
nussgipfel |
|
| 118 |
18 |
nussgipfel |
component message_rom
|
| 119 |
|
|
port (
|
| 120 |
|
|
A : in std_logic_vector(4 downto 0);
|
| 121 |
|
|
D : out std_logic_vector(15 downto 0));
|
| 122 |
|
|
end component;
|
| 123 |
11 |
nussgipfel |
|
| 124 |
18 |
nussgipfel |
begin -- behaviour
|
| 125 |
11 |
nussgipfel |
|
| 126 |
18 |
nussgipfel |
GPIF_INTERFACE: gpif_com
|
| 127 |
|
|
port map (
|
| 128 |
|
|
i_nReset => i_nReset,
|
| 129 |
|
|
i_SYSCLK => i_SYSCLK,
|
| 130 |
|
|
o_ABORT => s_ABORT,
|
| 131 |
|
|
o_RX => o_LEDrx,
|
| 132 |
|
|
o_TX => o_LEDtx,
|
| 133 |
|
|
i_RD_EN => s_RD_EN,
|
| 134 |
|
|
o_EMPTY => s_EMPTY,
|
| 135 |
|
|
o_RX_DATA => s_RX_DATA,
|
| 136 |
|
|
i_WR_EN => s_WR_EN,
|
| 137 |
|
|
o_FULL => s_FULL,
|
| 138 |
|
|
i_TX_DATA => s_TX_DATA,
|
| 139 |
|
|
--i_IFCLK => i_SYSCLK,
|
| 140 |
|
|
i_IFCLK => i_IFCLK,
|
| 141 |
|
|
i_WRU => i_WRU,
|
| 142 |
|
|
i_RDYU => i_RDYU,
|
| 143 |
|
|
o_WRX => o_WRX,
|
| 144 |
|
|
o_RDYX => o_RDYX,
|
| 145 |
|
|
b_gpif_bus => b_gpif_bus);
|
| 146 |
11 |
nussgipfel |
|
| 147 |
|
|
|
| 148 |
18 |
nussgipfel |
|
| 149 |
|
|
o_LEDrun <= '1';
|
| 150 |
11 |
nussgipfel |
|
| 151 |
18 |
nussgipfel |
|
| 152 |
11 |
nussgipfel |
-----------------------------------------------------------------------------
|
| 153 |
18 |
nussgipfel |
-- RX DATA CONSUMER WITH THROTLING
|
| 154 |
|
|
-----------------------------------------------------------------------------
|
| 155 |
11 |
nussgipfel |
|
| 156 |
18 |
nussgipfel |
-- purpose: activates the read enable signal of the receive FIFO as slow as
|
| 157 |
|
|
-- you want.
|
| 158 |
|
|
-- type : sequential
|
| 159 |
|
|
-- inputs : i_SYSCLK
|
| 160 |
|
|
-- outputs: s_RX_DATA_TMP
|
| 161 |
|
|
rx_throtling: process (i_SYSCLK, i_nReset)
|
| 162 |
19 |
nussgipfel |
-- counter variable
|
| 163 |
|
|
variable v_rx_throtle_count : std_logic_vector(6 downto 0);
|
| 164 |
18 |
nussgipfel |
begin
|
| 165 |
|
|
if i_nReset = '0' then
|
| 166 |
|
|
v_rx_throtle_count := (others => '0');
|
| 167 |
|
|
s_RD_EN <= '0';
|
| 168 |
|
|
elsif i_SYSCLK = '1' and i_SYSCLK'event then
|
| 169 |
19 |
nussgipfel |
if v_rx_throtle_count >= 2 then
|
| 170 |
18 |
nussgipfel |
s_RD_EN <= '1';
|
| 171 |
|
|
v_rx_throtle_count := (others => '0');
|
| 172 |
|
|
else
|
| 173 |
|
|
v_rx_throtle_count := v_rx_throtle_count + 1;
|
| 174 |
|
|
s_RD_EN <= '0';
|
| 175 |
|
|
end if;
|
| 176 |
|
|
end if;
|
| 177 |
|
|
end process rx_throtling;
|
| 178 |
11 |
nussgipfel |
|
| 179 |
18 |
nussgipfel |
-- purpose: reads the receive data from the GPIF interface
|
| 180 |
|
|
-- type : sequential
|
| 181 |
|
|
-- inputs : i_SYSCLK
|
| 182 |
|
|
-- outputs: s_RX_DATA_TMP
|
| 183 |
|
|
rx_consumer: process (i_SYSCLK)
|
| 184 |
|
|
begin -- process rx_consumer
|
| 185 |
|
|
if i_SYSCLK = '1' and i_SYSCLK'event then
|
| 186 |
|
|
s_RX_DATA_TMP <= s_RX_DATA;
|
| 187 |
|
|
s_EMPTY_TMP <= s_EMPTY;
|
| 188 |
|
|
s_FULL_TMP <= s_FULL;
|
| 189 |
|
|
s_ABORT_TMP <= s_ABORT;
|
| 190 |
|
|
end if;
|
| 191 |
|
|
end process rx_consumer;
|
| 192 |
11 |
nussgipfel |
|
| 193 |
|
|
|
| 194 |
18 |
nussgipfel |
-- dummy logic to "use" these signals and avoid that they are removed by
|
| 195 |
|
|
-- the optimizer
|
| 196 |
19 |
nussgipfel |
process(s_RX_DATA_TMP, s_EMPTY_TMP, s_FULL_TMP, s_ABORT_TMP)
|
| 197 |
18 |
nussgipfel |
variable result : std_logic := '0';
|
| 198 |
|
|
begin
|
| 199 |
|
|
result := '0';
|
| 200 |
|
|
for i in s_RX_DATA_TMP'range loop
|
| 201 |
|
|
result := result or s_RX_DATA_TMP(i);
|
| 202 |
|
|
end loop;
|
| 203 |
|
|
o_dummy <= result or s_EMPTY_TMP or s_FULL_TMP or s_ABORT_TMP;
|
| 204 |
|
|
end process;
|
| 205 |
11 |
nussgipfel |
|
| 206 |
18 |
nussgipfel |
-----------------------------------------------------------------------------
|
| 207 |
|
|
-- RESPONSE MESSAGE GENERATOR
|
| 208 |
|
|
-----------------------------------------------------------------------------
|
| 209 |
|
|
|
| 210 |
|
|
message_rom_1: message_rom
|
| 211 |
|
|
port map (
|
| 212 |
|
|
A => s_rom_adress,
|
| 213 |
|
|
D => s_TX_DATA);
|
| 214 |
|
|
|
| 215 |
|
|
-- purpose: counts up the rom adress lines to read out the response message
|
| 216 |
|
|
-- type : sequential
|
| 217 |
|
|
-- inputs : i_SYSCLK
|
| 218 |
|
|
-- outputs: s_RX_DATA_TMP
|
| 219 |
|
|
rom_adress_counter: process (i_SYSCLK, i_nReset)
|
| 220 |
|
|
begin
|
| 221 |
|
|
if i_nReset = '0' then
|
| 222 |
|
|
s_rom_adress <= (others => '0');
|
| 223 |
19 |
nussgipfel |
--s_WR_EN <= '1';
|
| 224 |
18 |
nussgipfel |
s_WR_EN <= '0';
|
| 225 |
|
|
elsif i_SYSCLK = '1' and i_SYSCLK'event then
|
| 226 |
|
|
if s_rom_adress = 24 then
|
| 227 |
|
|
s_rom_adress <= s_rom_adress;
|
| 228 |
|
|
s_WR_EN <= '0';
|
| 229 |
|
|
else
|
| 230 |
|
|
s_rom_adress <= s_rom_adress + 1;
|
| 231 |
19 |
nussgipfel |
--s_WR_EN <= '1';
|
| 232 |
18 |
nussgipfel |
s_WR_EN <= '0';
|
| 233 |
11 |
nussgipfel |
end if;
|
| 234 |
18 |
nussgipfel |
end if;
|
| 235 |
|
|
end process rom_adress_counter;
|
| 236 |
|
|
|
| 237 |
|
|
end behaviour;
|