*

byte_counter.vhd


--------------------------------------------------------------------------

-- FILENAME : byte_counter.vhd
--
-- Counts the number of bytes in the data and address fields.
--
-- AUTHOR : Craig Dunn
-- DATE STARTED : 20 December 2003
-- TAB SETTING : 4
-- RESET : Async (active low)
-- CLOCK : DPLL_CLK
-- KNOWN BUGS : None
-- VERSION : 1.0
--
-- All of the design and code in this module is my own work. No design or
-- code has been borrowed or copied from any source.
--------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity byte_counter is
port ( RST : in std_logic;
DPLL_CLK : in std_logic;
AF_AM : in std_logic;
DF_AM : in std_logic;
NEW_BYTE : out std_logic;
COUNT : out std_logic_vector(9 downto 0)
);
end byte_counter;

architecture byte_counter_arch of byte_counter is
signal af_bit_count : integer range 0 to 448;
signal byte_count : integer range 0 to 514;
signal df_bit_count : integer range 0 to 8224;

-- The constants are the number of DPLL_CLK pulses
-- per address field. To get the bytes divide each
-- value by 16.
constant DF_LENGTH : integer := 8224;
constant AF_LENGTH : integer := 448;
begin

NEW_BYTE <= '1' when (af_bit_count > 0 and af_bit_count mod 16 = 0) or
(df_bit_count > 0 and df_bit_count mod 16 = 0) else '0';

byte_count <= af_bit_count / 16 when (af_bit_count > 0 and af_bit_count mod 16 = 0) else
df_bit_count / 16 when (df_bit_count > 0 and df_bit_count mod 16 = 0) else 0;

COUNT <= conv_std_logic_vector(byte_count, 10);

af_bit_counter : process(RST, DPLL_CLK)
begin
if RST = '0' then
af_bit_count <= 0;
elsif rising_edge(DPLL_CLK) then
if AF_AM = '1' or af_bit_count > 0 then
if af_bit_count = AF_LENGTH then
af_bit_count <= 0;
else
af_bit_count <= af_bit_count + 1;
end if;
end if;
end if;
end process af_bit_counter;

df_bit_counter : process(RST, DPLL_CLK)
begin
if RST = '0' then
df_bit_count <= 0;
elsif rising_edge(DPLL_CLK) then
if DF_AM = '1' or df_bit_count > 0 then
if df_bit_count = DF_LENGTH then
df_bit_count <= 0;
else
df_bit_count <= df_bit_count + 1;
end if;
end if;
end if;
end process df_bit_counter;

end byte_counter_arch;


BackHome