cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
psocEmif.vhd
Go to the documentation of this file.
1 -- *******************************************************************************
2 -- * Copyright 2016 -- 2021 IBM Corporation
3 -- *
4 -- * Licensed under the Apache License, Version 2.0 (the "License");
5 -- * you may not use this file except in compliance with the License.
6 -- * You may obtain a copy of the License at
7 -- *
8 -- * http://www.apache.org/licenses/LICENSE-2.0
9 -- *
10 -- * Unless required by applicable law or agreed to in writing, software
11 -- * distributed under the License is distributed on an "AS IS" BASIS,
12 -- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 -- * See the License for the specific language governing permissions and
14 -- * limitations under the License.
15 -- *******************************************************************************
16 
17 -- ******************************************************************************
18 -- *
19 -- * cloudFPGA
20 -- *
21 -- *-----------------------------------------------------------------------------
22 -- *
23 -- * Title : Basic implementation of the PSoC external memory interface.
24 -- * File : psocEmif.vhd
25 -- *
26 -- * Created : Sep. 2017
27 -- * Authors : Francois Abel <fab@zurich.ibm.com>
28 -- * Alex Raimondi
29 -- *
30 -- * Devices : xcku060-ffva1156-2-i
31 -- * Tools : Vivado v2016.4 (64-bit)
32 -- * Depends : None
33 -- *
34 -- * Description : Simplified version of the EMIF interface between the PSoC and
35 -- * the FPGA of the FMKU2595 module.
36 -- *
37 -- * Generics: This design instantiates a register file with a total of
38 -- * 2^gAddrWidth times gDataWidth bits. By default, gAddrWidth=gDataWidth=8
39 -- * which implements a register file of 256 registers times 8 bits.
40 -- *
41 -- *-----------------------------------------------------------------------------
42 -- *
43 -- * Note: The EMIF I/F of the PSOC is expected to be configured as follows:
44 -- * - External Memory Type : Synchronous
45 -- * - Address Width : 8 bits
46 -- * - Data Width : 8 bits
47 -- * - External Memory Speed : 30 ns
48 -- * - Bus Clock Frequency : 24 MHz
49 -- * - Write cycle Length : 166.7 ns (4 cycles)
50 -- * - Read cycle Length : 166.7 ns (4 cycles)
51 -- * - WriteEn Pulse Width : 41.7 ns (1 cycle)
52 -- * - OutputEn Pulse Width : 125 ns (3 cycles)
53 -- *
54 -- ******************************************************************************
55 
56 library IEEE;
57 use IEEE.STD_LOGIC_1164.ALL;
58 use IEEE.NUMERIC_STD.ALL;
59 
60 -- Uncomment the following library declaration if using
61 -- arithmetic functions with Signed or Unsigned values
62 -- use IEEE.NUMERIC_STD.ALL;sBus_
63 
64 -- Uncomment the following library declaration if instantiating
65 -- any Xilinx leaf cells in this code.
66 -- library UNISIM;
67 -- use UNISIM.VComponents.all;
68 
69 --*************************************************************************
70 --** ENTITY
71 --*************************************************************************
72 entity PsocExtMemItf is
73  generic (
74  gAddrWidth : integer := 7;
75  gDataWidth : integer := 8;
76  gDefRegVal : std_logic_vector
77  );
78  port (
79  -- Global Resets input -----------------------
80  piRst : in std_logic;
81  -- CPU/DMA Bus Interface ---------------------
82  piBus_Clk : in std_logic;
83  piBus_Cs_n : in std_logic;
84  piBus_We_n : in std_logic;
85  piBus_Addr : in std_logic_vector(gAddrWidth - 1 downto 0);
86  piBus_Data : in std_logic_vector(gDataWidth - 1 downto 0);
87  poBus_Data : out std_logic_vector(gDataWidth - 1 downto 0);
88  -- Internal FPGA Fabric Interface
89  piFab_Clk : in std_logic;
90  piFab_Data : in std_logic_vector(gDataWidth * (2**gAddrWidth) - 1 downto 0);
91  poFab_Data : out std_logic_vector(gDataWidth * (2**gAddrWidth) - 1 downto 0)
92  );
93 end PsocExtMemItf;
94 
95 
96 --*************************************************************************
97 --** ARCHITECTURE
98 --*************************************************************************
99 architecture Behavioral of PsocExtMemItf is
100 
101  constant cTREG : time := 2 ns;
102  constant cDEPTH : integer := gDataWidth * (2**gAddrWidth);
103 
104  signal sBus_ClkMts : std_logic;
105  signal sBus_ClkReg : std_logic;
106  signal sBus_ClkRegReg : std_logic;
107 
108  -- Emif Bus Interface
109  signal sBus_Cs_n : std_logic;
110  signal sBus_We_n : std_logic;
111  signal sBus_Addr : std_logic_vector(gAddrWidth - 1 downto 0);
112  signal sBus_Data : std_logic_vector(gDataWidth - 1 downto 0);
113 
114  signal sEmifReg : std_logic_vector(cDEPTH - 1 downto 0);
115 
116  -- Fpga Fabric Interface
117  signal sFab_Data : std_logic_vector(cDEPTH - 1 downto 0);
118 
119 begin -- architecture rtl
120 
121  -----------------------------------------------------------------
122  -- SREG: Source Synchronous Registering of the Input Bus Signals
123  -----------------------------------------------------------------
124  pInpBusReg: process (piBus_Clk, piRst) is
125  begin
126  if rising_edge(piBus_Clk) then
127  sBus_Cs_n <= piBus_Cs_n after cTREG;
128  sBus_We_n <= piBus_We_n after cTREG;
129  sBus_Data <= piBus_Data after cTREG;
130  sBus_Addr <= piBus_Addr after cTREG;
131  end if;
132  end process pInpBusReg;
133 
134  ---------------------------------------------------------------
135  -- REG: Clock domain crossing for the incoming bus clock pulse
136  ---------------------------------------------------------------
137  pBusClkToFabClkReg: process (piFab_Clk) is
138  begin
139  if rising_edge(piFab_Clk) then
140  -- Synchronizer to avaoid metastability (Mts)
141  sBus_ClkMts <= piBus_Clk after cTREG;
142  sBus_ClkReg <= sBus_ClkMts after cTREG;
143  end if;
144  end process pBusClkToFabClkReg;
145 
146  ----------------------------------------------------------
147  -- REG: MMIO Write Cycle
148  ----------------------------------------------------------
149  pMmioWrReg : process (piFab_Clk, piRst) is
150  variable vAddr : integer := 0;
151  begin
152  if (piRst = '1') then
153  sEmifReg <= gDefRegVal;
154  elsif rising_edge(piFab_Clk) then
155  sBus_ClkRegReg <= sBus_ClkReg after cTREG;
156  -- On rising edge of the Bus clcok
157  if (sBus_ClkRegReg = '1' and sBus_ClkReg = '0') then
158  if (sBus_Cs_n = '0' and sBus_We_n = '0') then
159  -- Write cycle accesss
160  vAddr := to_integer(unsigned(sBus_Addr));
161  vAddr := vAddr * gDataWidth;
162  sEmifReg(vAddr + 7 downto vAddr) <= sBus_Data;
163  end if;
164  end if;
165  end if;
166  end process pMmioWrReg;
167 
168  ----------------------------------------------------------
169  -- COMB: MMIO Read Cycle
170  ----------------------------------------------------------
171  pMmioRdComb: process (sFab_Data, sBus_Addr) is
172  variable vAddr : integer := 0;
173  begin
174  vAddr := to_integer(unsigned(sBus_Addr));
175  vAddr := vAddr * gDataWidth;
176  poBus_Data <= sFab_Data(vAddr + 7 downto vAddr);
177  end process pMmioRdComb;
178 
179  ----------------------------------------------------------
180  -- REG: Register data signals from the fabric
181  ----------------------------------------------------------
182  pFabInpReg: process (piFab_Clk) is
183  begin
184  if rising_edge(piFab_Clk) then
185  sFab_Data <= piFab_Data after cTREG;
186  end if;
187  end process pFabInpReg;
188 
189  ----------------------------------------------------------
190  -- Output Ports Assignment
191  ----------------------------------------------------------
192  poFab_Data <= sEmifReg;
193 
194 end Behavioral;
gAddrWidthinteger :=7
Definition: psocEmif.vhd:74
in piFab_Datastd_logic_vector( gDataWidth *(2 ** gAddrWidth) - 1 downto 0)
Definition: psocEmif.vhd:90
in piBus_Clkstd_logic
Definition: psocEmif.vhd:82
out poBus_Datastd_logic_vector( gDataWidth- 1 downto 0)
Definition: psocEmif.vhd:87
out poFab_Datastd_logic_vector( gDataWidth *(2 ** gAddrWidth) - 1 downto 0)
Definition: psocEmif.vhd:92
in piBus_Cs_nstd_logic
Definition: psocEmif.vhd:83
gDefRegValstd_logic_vector
Definition: psocEmif.vhd:77
in piFab_Clkstd_logic
Definition: psocEmif.vhd:89
in piBus_We_nstd_logic
Definition: psocEmif.vhd:84
gDataWidthinteger :=8
Definition: psocEmif.vhd:75
in piBus_Datastd_logic_vector( gDataWidth- 1 downto 0)
Definition: psocEmif.vhd:86
in piRststd_logic
Definition: psocEmif.vhd:80
in piBus_Addrstd_logic_vector( gAddrWidth- 1 downto 0)
Definition: psocEmif.vhd:85