Free VHDL library

  • Main Page
  • Related Pages
  • Design Unit List
  • Files
  • File List

lpp_memory/ApbDriver.vhd

Go to the documentation of this file.
00001 ------------------------------------------------------------------------------
00002 --  This file is a part of the LPP VHDL IP LIBRARY
00003 --  Copyright (C) 2009 - 2010, Laboratory of Plasmas Physic - CNRS
00004 --
00005 --  This program is free software; you can redistribute it and/or modify
00006 --  it under the terms of the GNU General Public License as published by
00007 --  the Free Software Foundation; either version 3 of the License, or
00008 --  (at your option) any later version.
00009 --
00010 --  This program is distributed in the hope that it will be useful,
00011 --  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 --  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 --  GNU General Public License for more details.
00014 --
00015 --  You should have received a copy of the GNU General Public License
00016 --  along with this program; if not, write to the Free Software
00017 --  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
00018 ------------------------------------------------------------------------------
00019 --                        Author : Martin Morlot
00020 --                     Mail : martin.morlot@lpp.polytechnique.fr
00021 ------------------------------------------------------------------------------
00022 library ieee;
00023 use ieee.std_logic_1164.all;
00024 library grlib;
00025 use grlib.amba.all;
00026 use grlib.stdlib.all;
00027 use grlib.devices.all;
00028 library lpp;
00029 use lpp.lpp_amba.all;
00030 use lpp.apb_devices_list.all;
00031 
00033 
00034 entity ApbDriver is
00035   generic (
00036     pindex       : integer := 0;
00037     paddr        : integer := 0;
00038     pmask        : integer := 16#fff#;
00039     pirq         : integer := 0;
00040     abits        : integer := 8;
00041     LPP_DEVICE   : integer;
00042     Data_sz      : integer := 16;
00043     Addr_sz      : integer := 8;    
00044     addr_max_int : integer := 256);
00045   port (
00046     clk          : in  std_logic;
00047     rst          : in  std_logic;
00048     ReadEnable   : out std_logic;
00049     WriteEnable  : out std_logic;
00050     FlagEmpty    : in std_logic;
00051     FlagFull     : in std_logic;
00052     DataIn       : out std_logic_vector(Data_sz-1 downto 0);
00053     DataOut      : in std_logic_vector(Data_sz-1 downto 0);
00054     AddrIn       : in std_logic_vector(Addr_sz-1 downto 0);
00055     AddrOut      : in std_logic_vector(Addr_sz-1 downto 0);
00056     apbi         : in  apb_slv_in_type;
00057     apbo         : out apb_slv_out_type
00058     );
00059 end ApbDriver;
00060 
00062 
00063 architecture ar_ApbDriver of ApbDriver is
00064 
00065 constant REVISION : integer := 1;
00066 
00067 constant pconfig : apb_config_type := (
00068   0 => ahb_device_reg (VENDOR_LPP, LPP_DEVICE, 0, REVISION, 0),
00069   1 => apb_iobar(paddr, pmask));
00070 
00071 type DEVICE_ctrlr_Reg is record
00072      DEVICE_Cfg   : std_logic_vector(3 downto 0);
00073      DEVICE_DataW : std_logic_vector(Data_sz-1 downto 0);
00074      DEVICE_DataR : std_logic_vector(Data_sz-1 downto 0);
00075      DEVICE_AddrW : std_logic_vector(Addr_sz-1 downto 0);
00076      DEVICE_AddrR : std_logic_vector(Addr_sz-1 downto 0);
00077 end record;
00078 
00079 signal Rec    : DEVICE_ctrlr_Reg;
00080 signal Rdata  : std_logic_vector(31 downto 0);
00081 
00082 signal FlagRE : std_logic;
00083 signal FlagWR : std_logic;
00084 
00085 begin
00086 
00087 Rec.DEVICE_Cfg(0) <= FlagRE;
00088 Rec.DEVICE_Cfg(1) <= FlagWR;
00089 Rec.DEVICE_Cfg(2) <= FlagEmpty;
00090 Rec.DEVICE_Cfg(3) <= FlagFull;
00091 
00092 DataIn <= Rec.DEVICE_DataW;
00093 Rec.DEVICE_DataR <= DataOut;
00094 Rec.DEVICE_AddrW <= AddrIn;
00095 Rec.DEVICE_AddrR <= AddrOut;
00096 
00097 
00098 
00099     process(rst,clk)
00100     begin
00101         if(rst='0')then
00102             Rec.DEVICE_DataW <= (others => '0');
00103             FlagWR <= '0';
00104             FlagRE <= '0';
00105 
00106         elsif(clk'event and clk='1')then        
00107 
00108     --APB Write OP
00109             if (apbi.psel(pindex) and apbi.penable and apbi.pwrite) = '1' then
00110                case apbi.paddr(abits-1 downto 2) is
00111                     when "000000" =>
00112                          FlagWR <= '1';
00113                          Rec.DEVICE_DataW <= apbi.pwdata(Data_sz-1 downto 0);
00114                     when others =>
00115                          null;
00116                end case;
00117             else
00118                 FlagWR <= '0';
00119             end if;
00120 
00121     --APB Read OP
00122             if (apbi.psel(pindex) and (not apbi.pwrite)) = '1' then
00123                case apbi.paddr(abits-1 downto 2) is
00124                     when "000000" =>
00125                          FlagRE <= '1';
00126                          Rdata(Data_sz-1 downto 0)  <= Rec.DEVICE_DataR;
00127                     when "000001" =>
00128                          Rdata(31 downto 8) <= X"AAAAAA";
00129                          Rdata(7 downto 0)  <= Rec.DEVICE_AddrR;
00130                     when "000101" =>
00131                          Rdata(31 downto 8) <= X"AAAAAA";
00132                          Rdata(7 downto 0)  <= Rec.DEVICE_AddrW;
00133                     when "000010" =>
00134                          Rdata(3 downto 0)   <= "000" & Rec.DEVICE_Cfg(0);
00135                          Rdata(7 downto 4)   <= "000" & Rec.DEVICE_Cfg(1);
00136                          Rdata(11 downto 8)  <= "000" & Rec.DEVICE_Cfg(2);
00137                          Rdata(15 downto 12) <= "000" & Rec.DEVICE_Cfg(3);
00138                          Rdata(31 downto 16) <= X"CCCC";
00139                     when others =>
00140                          Rdata <= (others => '0');
00141                end case;
00142             else
00143                 FlagRE <= '0';
00144             end if;
00145 
00146         end if;
00147         apbo.pconfig <= pconfig;
00148     end process;
00149 
00150 apbo.prdata     <=   Rdata when apbi.penable = '1';
00151 WriteEnable     <=   FlagWR;
00152 ReadEnable      <=   FlagRE;
00153 
00154 end ar_ApbDriver;

© Copyright 2011 LPP-CNRS | Design by Alexis Jeandet