00001 --**************************************************************
00002 --* *
00003 --* The source code for the ATLAS BCM "AAA" FPGA is made *
00004 --* available via the GNU General Public License (GPL) *
00005 --* unless otherwise stated below. *
00006 --* *
00007 --* In case of problems/questions/bug reports etc. please *
00008 --* contact michael.niegl@cern.ch *
00009 --* *
00010 --**************************************************************
00011
00012 --**************************************************************
00013 --* *
00014 --* $Source: /local/reps/bcmfpga/bcm_aaa/bcm_aaa/rod/bcm_rod_dp_updown_counter.vhd,v $ *
00015 --* $Revision: 1.13.2.4 $ *
00016 --* $Name: dev $ *
00017 --* $Author: mniegl $ *
00018 --* $Date: 2008/11/03 17:57:48 $ *
00019
00020
00021 --* *
00022 --**************************************************************
00023
00024 library ieee;
00025
00026 use ieee.std_logic_1164.all;
00027
00028 use ieee.std_logic_arith.all;
00029
00030 use ieee.std_logic_unsigned.all;
00031
00032
00033
00034
00035
00036
00037
00038 entity bcm_rod_dp_updown_counter is
00039 port (
00040 -- clocks and synchronus reset
00041 CLK : in ;
00042 CLK_2X : in ;
00043 SCLR : in ;
00044 -- up/down flags
00045 count_up : in ;
00046 count_down : in ;
00047 busy : out ;
00048 data_available : out ;
00049 write_error : out ;
00050 read_error : out
00051 );
00052 end bcm_rod_dp_updown_counter;
00053
00054
00055 architecture bcm_rod_dp_updown_counter_arc of bcm_rod_dp_updown_counter is
00056
00057 signal dp_ram_updown_counter : (8 downto 0) := (others => '0');
00058
00059 begin
00060
00061
00062
00063
00064
00065
00066
00067 ram_fill_counter : process(CLK_2X)
00068 begin
00069 if (CLK_2X'event and CLK_2X = '1') then
00070 if (SCLR = '1') then -- synchronous clear (reset)
00071 dp_ram_updown_counter <= (others => '0');
00072 busy <= '0';
00073 data_available <= '0';
00074 write_error <= '0';
00075 read_error <= '0';
00076 else
00077 if ((count_up = '1' and count_down = '0') or (count_up = '1' and count_down = '1' and CLK = '0')) then -- only counting up
00078 if (dp_ram_updown_counter = "111111111") then -- counter full - data could not be stored in RAM
00079 dp_ram_updown_counter <= dp_ram_updown_counter;
00080 write_error <= '1';
00081 busy <= '1';
00082 else -- counter not full - data could be stored in RAM
00083 dp_ram_updown_counter <= (dp_ram_updown_counter + "01");
00084 write_error <= '0';
00085 if (dp_ram_updown_counter >= "111111101") then
00086 busy <= '1';
00087 else
00088 busy <= '0';
00089 end if;
00090 end if;
00091 data_available <= '1';
00092 read_error <= '0';
00093 elsif (count_up = '0' and count_down = '1' and CLK = '1') then -- only counting down
00094 if (dp_ram_updown_counter = "000000000") then -- counter full - data could not be stored in RAM
00095 dp_ram_updown_counter <= dp_ram_updown_counter;
00096 read_error <= '1';
00097 data_available <= '0';
00098 else -- counter not full - data could be stored in RAM
00099 dp_ram_updown_counter <= (dp_ram_updown_counter - "01");
00100 read_error <= '0';
00101 if (dp_ram_updown_counter <= "000000001") then
00102 data_available <= '0';
00103 else
00104 data_available <= '1';
00105 end if;
00106 end if;
00107 write_error <= '0';
00108 busy <= '0';
00109 else -- counting up and down or no counting at all
00110 dp_ram_updown_counter <= dp_ram_updown_counter;
00111 if (count_down = '0') then
00112 read_error <= '0';
00113 end if;
00114 if (dp_ram_updown_counter = "000000000") then
00115 data_available <= '0';
00116 else
00117 data_available <= '1';
00118 end if;
00119 if (dp_ram_updown_counter >= "111111110") then
00120 busy <= '1';
00121 else
00122 busy <= '0';
00123 end if;
00124 write_error <= '0';
00125 end if;
00126 end if;
00127 end if;
00128 end process;
00129
00130 end bcm_rod_dp_updown_counter_arc;