--------------------------------------------------------------------------------
-- Company:
--
-- File			: Accumulator_88bit.vhd
-- File history	: VER 1.0
--      
-- Description: 
--		This design illustrates the implementation of 88-bit addition using
--      two mathblocks.
--
--      88-bit input is fed to the two  Math blocks with 44-bit MSB to one math block and  
--		44-bit LSB to another mathblock.

-- 		Targeted device: <Family :: SmartFusion2>
--					   		<Die :: M2S050> 
--						<Package :: 896 FBGA>
-- Author	: PHANIKIRAN T
--------------------------------------------------------------------------------


LIBRARY IEEE;

USE IEEE.std_logic_1164.all;
USE IEEE.std_logic_unsigned.all;
USE IEEE.std_logic_arith.all;

ENTITY Accumulator_88bit IS
PORT (
    CLK 		: IN STD_LOGIC;
    RSTN 		: IN STD_LOGIC;

-- Input
	LD_88b_IN	: IN STD_LOGIC_VECTOR(87 DOWNTO 0);

-- Output
   	RESULT	 	: OUT STD_LOGIC_VECTOR(87 DOWNTO 0)
	
	);
END Accumulator_88bit;


ARCHITECTURE  Acc88bit_Arch OF Accumulator_88bit IS

 -- COMPONENT DECLARATIONS

COMPONENT MultAdder IS
    -- Port list
    port(
        -- Inputs
        A0        : in  std_logic_vector(17 downto 0);
        A0_ACLR_N : in  std_logic;
        A0_EN     : in  std_logic;
        A0_SCLR_N : in  std_logic;
        B0        : in  std_logic_vector(17 downto 0);
        B0_ACLR_N : in  std_logic;
        B0_EN     : in  std_logic;
        B0_SCLR_N : in  std_logic;
        C         : in  std_logic_vector(43 downto 0);
        CLK       : in  std_logic;
        C_ACLR_N  : in  std_logic;
        C_EN      : in  std_logic;
        C_SCLR_N  : in  std_logic;
        P_ACLR_N  : in  std_logic;
        P_EN      : in  std_logic;
        P_SCLR_N  : in  std_logic;
        -- Outputs
        CARRYOUT  : out std_logic;
        CDOUT     : out std_logic_vector(43 downto 0);
        P         : out std_logic_vector(43 downto 0)
        );
END COMPONENT MultAdder;
  

COMPONENT MultAdder_w_Din is
    -- Port list
    port(
        -- Inputs
        A0        : in  std_logic_vector(17 downto 0);
        A0_ACLR_N : in  std_logic;
        A0_EN     : in  std_logic;
        A0_SCLR_N : in  std_logic;
        B0        : in  std_logic_vector(17 downto 0);
        B0_ACLR_N : in  std_logic;
        B0_EN     : in  std_logic;
        B0_SCLR_N : in  std_logic;
        C         : in  std_logic_vector(43 downto 0);
		CARRYIN   : in  std_logic;
        CLK       : in  std_logic;
        C_ACLR_N  : in  std_logic;
        C_EN      : in  std_logic;
        C_SCLR_N  : in  std_logic;
        P_ACLR_N  : in  std_logic;
        P_EN      : in  std_logic;
        P_SCLR_N  : in  std_logic;
        -- Outputs
        CDOUT     : out std_logic_vector(43 downto 0);
        P         : out std_logic_vector(43 downto 0)
        );
END COMPONENT MultAdder_w_Din;

 -- SIGNAL DECLARATIONS

SIGNAL C_in0	: STD_LOGIC_VECTOR(43 DOWNTO 0);
SIGNAL C_in		: STD_LOGIC_VECTOR(43 DOWNTO 0);

SIGNAL RES1		: STD_LOGIC_VECTOR(43 DOWNTO 0);
SIGNAL RES1_r0	: STD_LOGIC_VECTOR(43 DOWNTO 0);
SIGNAL RES1_r1	: STD_LOGIC_VECTOR(43 DOWNTO 0);
SIGNAL RES2		: STD_LOGIC_VECTOR(43 DOWNTO 0);
SIGNAL CARRYIN	: STD_LOGIC;




BEGIN

PROCESS(CLK,RSTN)
BEGIN
	IF(RSTN ='0')THEN
		C_in	<= (OTHERS =>'0');
		C_in0	<= (OTHERS =>'0');
	ELSE
		IF(rising_edge(CLK))THEN
			C_in0	<= LD_88b_IN(87 DOWNTO 44);
			C_in	<= C_in0;
		END IF;
	END IF;
END PROCESS;




-- Port list
 U0 : MultAdder
		port map
		(
        A0        => (OTHERS => '0'),
        A0_ACLR_N => RSTN,
        A0_EN     => '1',
        A0_SCLR_N => '1',
        B0        => (OTHERS => '0'),
        B0_ACLR_N => RSTN,
        B0_EN     => '1',
        B0_SCLR_N => '1',
        C         => LD_88b_IN(43 DOWNTO 0),
        CLK       => CLK,
		C_ACLR_N  => RSTN,
        C_EN      => '1',
        C_SCLR_N  => '1',

        P_ACLR_N  => RSTN,
        P_EN      => '1',
        P_SCLR_N  => '1',
        -- Outputs
        CARRYOUT  => CARRYIN,
        CDOUT     => OPEN,
        P         => RES1
        );



U1:MultAdder_w_Din
	port map(
        -- Inputs
    	A0        => (OTHERS => '0'),
        A0_ACLR_N => RSTN,
        A0_EN     => '1',
        A0_SCLR_N => '1',
        B0        => (OTHERS => '0'),
        B0_ACLR_N => RSTN,
        B0_EN     => '1',
        B0_SCLR_N => '1',
        C         => C_in,
		CARRYIN	  => CARRYIN,
        CLK       => CLK,
		C_ACLR_N  => RSTN,
        C_EN      => '1',
        C_SCLR_N  => '1',

        P_ACLR_N  => RSTN,
        P_EN      => '1',
        P_SCLR_N  => '1',
        -- Outputs
        CDOUT     => OPEN,
        P         => RES2
        );



PROCESS(CLK,RSTN)
BEGIN
	IF(RSTN ='0')THEN
		RES1_r0 <= (OTHERS =>'0');
		RES1_r1 <= (OTHERS =>'0');
	ELSE
		IF(rising_edge(CLK))THEN
			RES1_r0 <= RES1;
			RES1_r1 <= RES1_r0;
		END IF;
	END IF;
END PROCESS;


RESULT <= RES2 & RES1_r1;


END Acc88bit_Arch;
