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 : Alexis Jeandet 00020 -- Mail : alexis.jeandet@lpp.polytechnique.fr 00021 ---------------------------------------------------------------------------- 00022 library IEEE; 00023 use IEEE.STD_LOGIC_1164.ALL; 00024 use ieee.numeric_std.all; 00025 library grlib; 00026 use grlib.amba.all; 00027 use grlib.stdlib.all; 00028 use grlib.devices.all; 00029 library lpp; 00030 use lpp.lpp_ad_conv.all; 00031 use lpp.lpp_amba.all; 00032 use lpp.apb_devices_list.all; 00033 use lpp.general_purpose.Clk_divider; 00034 00035 entity lpp_apb_ad_conv is 00036 generic( 00037 pindex : integer := 0; 00038 paddr : integer := 0; 00039 pmask : integer := 16#fff#; 00040 pirq : integer := 0; 00041 abits : integer := 8; 00042 ChanelCount : integer := 1; 00043 clkkHz : integer := 50000; 00044 smpClkHz : integer := 100; 00045 ADCref : integer := AD7688); 00046 Port ( 00047 clk : in STD_LOGIC; 00048 reset : in STD_LOGIC; 00049 apbi : in apb_slv_in_type; 00050 apbo : out apb_slv_out_type; 00051 AD_in : in AD7688_in(ChanelCount-1 downto 0); 00052 AD_out : out AD7688_out); 00053 end lpp_apb_ad_conv; 00054 00055 00056 architecture ar_lpp_apb_ad_conv of lpp_apb_ad_conv is 00057 constant REVISION : integer := 1; 00058 00059 constant pconfig : apb_config_type := ( 00060 0 => ahb_device_reg (VENDOR_LPP, LPP_APB_ADC, 0, REVISION, 0), 00061 1 => apb_iobar(paddr, pmask)); 00062 00063 signal Rdata : std_logic_vector(31 downto 0); 00064 signal smpout : Samples_out(ChanelCount-1 downto 0); 00065 signal smplClk : STD_LOGIC; 00066 signal DataReady : STD_LOGIC; 00067 00068 type lpp_apb_ad_conv_Reg is record 00069 CTRL_Reg : std_logic_vector(31 downto 0); 00070 sample : Samples_out(ChanelCount-1 downto 0); 00071 end record; 00072 00073 signal r : lpp_apb_ad_conv_Reg; 00074 00075 begin 00076 00077 00078 caseAD7688: if ADCref = AD7688 generate 00079 AD7688: AD7688_drvr 00080 generic map(ChanelCount,clkkHz) 00081 Port map(clk,reset,smplClk,DataReady,smpout,AD_in,AD_out); 00082 end generate; 00083 00084 caseADS786: if ADCref = ADS7886 generate 00085 ADS7886: ADS7886_drvr 00086 generic map(ChanelCount,clkkHz) 00087 Port map(clk,reset,smplClk,DataReady,smpout,AD_in,AD_out); 00088 end generate; 00089 00090 00091 clkdivider: Clk_divider 00092 generic map(clkkHz*1000,smpClkHz) 00093 Port map( clk ,reset,smplClk); 00094 00095 00096 00097 r.CTRL_Reg(0) <= DataReady; 00098 00099 r.sample <= smpout; 00100 00101 00102 process(reset,clk) 00103 begin 00104 if reset = '0' then 00105 --r.CTRL_Reg(9 downto 0) <= (others => '0'); 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(7 downto 2) is 00111 when "000000" => 00112 --r.CTRL_Reg(9 downto 0) <= apbi.pwdata(9 downto 0); 00113 when others => 00114 end case; 00115 end if; 00116 00117 --APB READ OP 00118 if (apbi.psel(pindex) and (not apbi.pwrite)) = '1' then 00119 case apbi.paddr(7 downto 2) is 00120 when "000000" => 00121 Rdata <= r.CTRL_Reg; 00122 when others => 00123 readC: for i in 1 to ChanelCount loop 00124 if TO_INTEGER(unsigned(apbi.paddr(abits-1 downto 2))) =i then 00125 Rdata(15 downto 0) <= r.sample(i-1)(15 downto 0); 00126 end if; 00127 end loop; 00128 end case; 00129 end if; 00130 end if; 00131 apbo.pconfig <= pconfig; 00132 end process; 00133 00134 apbo.prdata <= Rdata when apbi.penable = '1' ; 00135 00136 00137 end ar_lpp_apb_ad_conv; 00138 00139 00140 00141 00142 00143 00144 00145 00146
© Copyright 2011 LPP-CNRS | Design by Alexis Jeandet