---------------------------------------------------------------------------
-- NDT Solutions Ltd. Proprietary Information
-- Company Confidential
-- Copyright 2007
--
-- Filename: SystemFpgaPkg.vhd
-- Language: VHDL '93
-- Project:  NDTS2100 System FPGA
--
-- Design Description:
-- VHDL package for System FPGA
---------------------------------------------------------------------------


library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_arith.all;
use work.SystemMonitorPkg.all;

package SystemFpgaPkg is

  -- cFpgaRevision should be updated with the current revision number
  constant cFpgaRevision: std_logic_vector(11 downto 0) := X"001";  -- From 0.01 to F.FF

  -----------------------------------------------------------------------------
  -- Record to define the parameters for a register
  type tRegParam is record
    Address: std_logic_vector(31 downto 0);
    ResetVal: std_logic_vector(31 downto 0);
    WriteMask: std_logic_vector(31 downto 0);
    ReadMask: std_logic_vector(31 downto 0);
    RegCount: integer;
  end record;

  -- Register indexes
  constant cSysBase             : integer := 0;
  constant cCheck               : integer := 1;
  constant cSysControl          : integer := 2;
  constant cFPGAConfigData      : integer := 3;
  constant cSystemMonitorCtrl   : integer := 4;
  constant cUnderRangeFlags     : integer := 5;
  constant cOverRangeFlags      : integer := 6;
  constant cUnderRangeDLedEn    : integer := 7;
  constant cOverRangeDLedEn     : integer := 8;
  constant cUnderRangeOKLedEn   : integer := 9;
  constant cOverRangeOKLedEn    : integer := 10;
  constant cSysMonitorADCVal    : integer := 11;
  constant cSysMonitorTempVal   : integer := 12;
  constant cSysMonitorADCMin    : integer := 13;
  constant cSysMonitorTempMin   : integer := 14;
  constant cSysMonitorADCMax    : integer := 15;
  constant cSysMonitorTempMax   : integer := 16;
  constant cSysFpgaVer          : integer := 17;
  constant cLastReg             : integer := cSysFpgaVer;

  -- Register Addresses
  constant cSysBaseAddr             : std_logic_vector(31 downto 0) := x"00300000";
  constant cCheckAddr               : std_logic_vector(31 downto 0) := x"00300000";
  constant cSysControlAddr          : std_logic_vector(31 downto 0) := x"00300004";
  constant cFPGAConfigDataAddr      : std_logic_vector(31 downto 0) := x"00300008";
  constant cSystemMonitorCtrlAddr   : std_logic_vector(31 downto 0) := x"00300010";
  constant cUnderRangeFlagsAddr     : std_logic_vector(31 downto 0) := x"00300014";
  constant cOverRangeFlagsAddr      : std_logic_vector(31 downto 0) := x"00300018";
  constant cUnderRangeDLedEnAddr    : std_logic_vector(31 downto 0) := x"0030001C";  -- 5 registers
  constant cOverRangeDLedEnAddr     : std_logic_vector(31 downto 0) := x"00300030";  -- 5 registers
  constant cUnderRangeOKLedEnAddr   : std_logic_vector(31 downto 0) := x"00300044";
  constant cOverRangeOKLedEnAddr    : std_logic_vector(31 downto 0) := x"00300048";
  constant cSysMonitorADCValAddr    : std_logic_vector(31 downto 0) := x"00300080";  -- 24 registers
  constant cSysMonitorTempValAddr   : std_logic_vector(31 downto 0) := x"003000E0";
  constant cSysMonitorADCMinAddr    : std_logic_vector(31 downto 0) := x"00300100";  -- 24 registers
  constant cSysMonitorTempMinAddr   : std_logic_vector(31 downto 0) := x"00300160";
  constant cSysMonitorADCMaxAddr    : std_logic_vector(31 downto 0) := x"00300180";  -- 24 registers
  constant cSysMonitorTempMaxAddr   : std_logic_vector(31 downto 0) := x"003001E0";
  --
  constant cSysFpgaVerAddr          : std_logic_vector(31 downto 0) := x"00300FFC";

  constant cSysRegMask              : std_logic_vector(31 downto 0) := x"FFFFF000";
  constant cSysRegOffsetBits        : integer := 12;

  -- Type to hold array of registers
  type tRegSet is array(0 to cLastReg) of tRegParam;

  -- Constant definitions for registers                    Reset        Write        Read       RegCount
  constant cRegSet: tRegSet := ((cSysBaseAddr,           x"00000000", x"00000000", x"00000000", 0), 
                                (cCheckAddr,             x"00000000", x"FFFFFFFF", x"FFFFFFFF", 1), 
                                (cSysControlAddr,        x"00000000", x"00000001", x"C0000000", 1),
                                (cFPGAConfigDataAddr,    x"00000000", x"FFFFFFFF", x"FFFFFFFF", 1),
                                (cSystemMonitorCtrlAddr, x"00000001", x"00000001", x"00000001", 1),
                                (cUnderRangeFlagsAddr,   x"00000000", x"01FFFFFF", x"01FFFFFF", 1),
                                (cOverRangeFlagsAddr,    x"00000000", x"01FFFFFF", x"01FFFFFF", 1),
                                (cUnderRangeDLedEnAddr,  x"00000000", x"01FFFFFF", x"01FFFFFF", 5),
                                (cOverRangeDLedEnAddr,   x"00000000", x"01FFFFFF", x"01FFFFFF", 5),
                                (cUnderRangeOKLedEnAddr, x"00000000", x"01FFFFFF", x"01FFFFFF", 1),
                                (cOverRangeOKLedEnAddr,  x"00000000", x"01FFFFFF", x"01FFFFFF", 1),
                                (cSysMonitorADCValAddr,  x"00000000", x"00000000", x"00000FFF", 24),
                                (cSysMonitorTempValAddr, x"00000000", x"00000000", x"000003FF", 1),
                                (cSysMonitorADCMinAddr,  x"00000000", x"00000FFF", x"00000FFF", 24),
                                (cSysMonitorTempMinAddr, x"00000" & "00" & cSysMonTempMax,
                                                                      x"000003FF", x"000003FF", 1),
                                (cSysMonitorADCMaxAddr,  x"00000000", x"00000FFF", x"00000FFF", 24),
                                (cSysMonitorTempMaxAddr, x"00000" & "00" & cSysMonTempMin,
                                                                      x"000003FF", x"000003FF", 1),
                                (cSysFpgaVerAddr,        x"00000" & cFpgaRevision,
                                                                      x"00000000", x"00000FFF", 1));

end package SystemFpgaPkg;
