--/******************************************************************************
--    Company      		: MICROSEMI

--    File Name    		: heart_beat.vhd 
                   		
--    Description  		: This module implements FPGA alive status on LED

--    Targeted device 	: Family           Die          Package
--                   	  PolarFire     MPF300T_ES      MPF300T_ES

--    Author          	: India Solutions Team

--
-- SVN Revision Information:
-- SVN $Revision: 
-- SVN $Date:  $  
-- COPYRIGHT 2018 BY MICROSEMI 
-- THE INFORMATION CONTAINED IN THIS DOCUMENT IS SUBJECT TO LICENSING RESTRICTIONS 
-- FROM MICROSEMI CORP.  IF YOU ARE NOT IN POSSESSION OF WRITTEN AUTHORIZATION FROM 
-- MICROSEMI FOR USE OF THIS FILE, THEN THE FILE SHOULD BE IMMEDIATELY DESTROYED AND 
-- NO BACK-UP OF THE FILE SHOULD BE MADE. 
-- 

--******************************************************************************/
library IEEE;
use IEEE.std_logic_1164.all;
use ieee.numeric_std.all;

entity heart_beat is
        generic( 
              g_TOP  : integer := 25;                   -- counter width
              g_BEAT : integer := 23                    -- on/off duration   
           );
        port (
               nreset_i       : in  std_logic;          -- Input Asynchronous reset signal
               clock_i        : in  std_logic;          -- Input Clock signal 
               HB_o	          : out std_logic           -- Output heart beat signal
        );
end heart_beat;
architecture arch of heart_beat is
---------------------------------------------------------------------------------------------------------------------------
-- Signals declaration
---------------------------------------------------------------------------------------------------------------------------  
signal   s_hb_count         :   unsigned(g_TOP downto 0);

begin

--************************************************************************************************
--** process id  : p_Counter
--** Description : This process counts the clock pulses after which HeartBeat LED should glow
--************************************************************************************************
    p_Counter: PROCESS(clock_i,nreset_i)
                 BEGIN
                        if nreset_i = '0' then
                            s_hb_count <= (others => '0');
                        elsif rising_edge(clock_i) then
                            s_hb_count <= s_hb_count + 1;
                        end if;
                END PROCESS p_Counter;

--************************************************************************************************
--** process id  : p_HB
--** Description : This process generates HeartBeat to keep LED  toggling(ON/OFF)
--************************************************************************************************  
   p_HB : PROCESS(clock_i,nreset_i)
                 BEGIN
                       if nreset_i = '0' then
                           HB_o <= '0';
                       elsif rising_edge(clock_i) then
                          HB_o <= not( not(s_hb_count(g_TOP)) and s_hb_count(g_BEAT));
                       end if;
                    END PROCESS p_HB;

 
end;
