Generated by EASE/HDL for peterj on Mon Jul 02 10:55:24 2007

Documentation for architecture MGTEVB/MuxControl/a0

Contents Side Data Generated HDL

VHDL Contents

    1  -- EASE/HDL begin --------------------------------------------------------------
    2  -- 
    3  -- Architecture 'a0' of entity 'MuxControl'.
    4  -- 
    5  --------------------------------------------------------------------------------
    6  -- 
    7  -- Copy of the interface declaration:
    8  -- 
    9  --   port(
   10  --     ChanEn        : in     std_logic_vector(7 downto 0);
   11  --     ChanSts       : in     std_logic_vector(31 downto 0);
   12  --     Channel       : out    std_logic_vector(3 downto 0);
   13  --     Ctrlbit       : in     std_logic;
   14  --     EBData        : in     std_logic_vector(31 downto 0);
   15  --     EBEmpty       : in     std_logic;
   16  --     EBMGTtest     : in     std_logic;
   17  --     EBValid       : in     std_logic;
   18  --     EBviaMGT      : in     std_logic;
   19  --     EXData        : in     std_logic_vector(31 downto 0);
   20  --     EXEmpty       : in     std_logic;
   21  --     EXValid       : in     std_logic;
   22  --     EnFilter      : out    std_logic;
   23  --     EvDataRdy     : in     std_logic;
   24  --     EvtAv         : in     std_logic;
   25  --     FullD         : in     std_logic;
   26  --     HFile         : in     std_logic_vector(31 downto 0);
   27  --     HFull         : in     std_logic;
   28  --     HValid        : in     std_logic;
   29  --     LRD           : out    std_logic_vector(31 downto 0);
   30  --     LastW         : in     std_logic;
   31  --     LastX         : in     std_logic;
   32  --     MROD_X_Debug  : in     std_logic;
   33  --     MatchBOEF     : in     std_logic;
   34  --     MatchLWC      : in     std_logic;
   35  --     MatchTWC      : in     std_logic;
   36  --     NDE           : out    std_logic_vector(15 downto 0);
   37  --     NextEvt       : out    std_logic;
   38  --     ReqD          : out    std_logic;
   39  --     ReqX          : out    std_logic;
   40  --     Rst_n         : in     std_logic;
   41  --     SClk          : in     std_logic;
   42  --     SLCtrl        : out    std_logic;
   43  --     SLWEN         : out    std_logic;
   44  --     SpyEventFull  : in     std_logic;
   45  --     SpyLengthFull : in     std_logic;
   46  --     SxHead        : out    std_logic;
   47  --     SxTrail       : out    std_logic);
   48  -- 
   49  -- EASE/HDL end ----------------------------------------------------------------
   50  
   51  architecture a0 of MuxControl is
   52  
   53    type states_c is (init, nextev, pause0, head1, head2, head3, data, pause1, pause2, trail1, trail2);
   54    signal statecon   : states_c;
   55  
   56    signal HFullSL    : std_logic;                        -- half full Slink
   57    signal EventRdy   : std_logic;                        -- event available
   58    signal ChanActive : std_logic_vector(7 downto 0);     -- active MGT channels
   59    signal EvtCur     : std_logic_vector(11 downto 0);    -- current event number (debug)
   60  
   61  begin
   62  
   63    ChanActive <= ChanEn and ChanSts(7 downto 0); -- only work with active channels
   64  
   65    -- the full condition is: HFull (SLink) OR Full (MGT backchannel) ...
   66    -- OR (MROD_X_Debug and (SpyEventFull or SpyLengthFull))
   67    -- HFull is SLink half full; SpyEventFull = spy event fifo almost full.
   68  
   69    HFullSL <= '1' when (HFull = '1' or FullD = '1'
   70      or (MROD_X_Debug = '1' and (SpyEventFull = '1' or SpyLengthFull = '1' )))
   71      else '0';
   72    --
   73    EventRdy <= '1' when
   74      ( (EBMGTtest = '0' and EvtAv = '1') or (EBMGTtest = '1' and EvDataRdy = '1') )
   75      else '0';
   76  
   77    --------------------------------------------------------------------------
   78  
   79    prConT:
   80    process (SClk, Rst_n)
   81      variable cntw : unsigned(15 downto 0);
   82      variable dats : std_logic_vector(31 downto 0);
   83      variable dtav : std_logic;
   84      variable chan : unsigned(3 downto 0);
   85      variable mask : std_logic_vector(7 downto 0);
   86    begin
   87      if (Rst_n = '0') then
   88        statecon <= init;
   89        chan := "0000";
   90        mask := x"01";
   91        dats := (others => '0');
   92        dtav := '0';
   93        cntw := x"0002";                          -- clear wordcounter
   94        ReqD <= '0';                              -- no evt.data from MGTs
   95        ReqX <= '0';                              -- no Ext.data from MGTs
   96        SxHead <= '0';                            -- no more event header
   97        SxTrail <= '0';                           -- no trailer yet
   98        NextEvt <= '0';                           -- no next event from TTC
   99        SLCtrl <= '0';
  100        EvtCur <= (others => '0');                -- (debug)
  101      elsif (rising_edge(SClk)) then
  102        case statecon is
  103        when init =>
  104          chan := "0000";
  105          mask := x"01";
  106          dats := (others => '0');
  107          dtav := '0';
  108          cntw := x"0002";                        -- clear wordcounter
  109          ReqD <= '0';                            -- no evt.data from MGTs
  110          ReqX <= '0';                            -- no Ext.data from MGTs
  111          SxHead <= '0';                          -- no more event header
  112          SxTrail <= '0';                         -- no trailer yet
  113          if (EBviaMGT = '1' and HFullSL = '0' and EventRdy = '1') then
  114            NextEvt  <= '1';                      -- event available from TTC
  115            statecon <= nextev;                   -- ask for TTC data and build next event
  116          else
  117            NextEvt  <= '0';                      -- wait ...
  118            statecon <= init;
  119          end if;
  120        when nextev =>
  121          NextEvt <= '0';                         -- no more TTC data
  122          SxHead <= '0';                          -- no more event header
  123          statecon <= pause0;
  124        when pause0 =>
  125          NextEvt <= '0';                         -- no more TTC data
  126          SxHead <= '1';                          -- get event header
  127          statecon <= head1;
  128        when head1 =>
  129          SxHead <= '0';                          -- no more event header
  130          if (HValid = '1') then                  -- no HFullSL check !
  131            dats := HFile;                        -- header words
  132            dtav := '1';
  133          --cntw := cntw + 1;
  134            statecon <= head2;
  135          else
  136            dtav := '0';
  137            statecon <= head1;
  138          end if;
  139        when head2 =>
  140          ReqD <= '0';                            -- no evt.data from MGTs
  141          if (HValid = '1') then                  -- no HFullSL check
  142            dats := HFile;                        -- header words
  143            dtav := '1';
  144          --cntw := cntw + 1;                     -- do not count header words
  145            ReqX <= '0';                          -- no Ext.data from MGTs
  146            statecon <= head2;
  147          elsif (HFullSL = '1') then              -- wait when HFullSL is on
  148            dtav := '0';
  149            ReqX <= '0';
  150            statecon <= head2;
  151          else
  152            dtav := '0';
  153            if ((mask and ChanActive) /= x"00") then
  154            --if (LastX = '1' or EXempty = '0') then
  155              if (EXempty = '0') then
  156                ReqX <= '1';                      -- read one word (evt#,wct#)
  157                statecon <= head3;
  158              else
  159                ReqX <= '0';
  160                statecon <= head2;
  161              end if;
  162            else
  163              mask := mask(6 downto 0) & '0';
  164              chan := chan + 1;
  165              ReqX <= '0';                        -- no Ext.data from MGTs
  166              statecon <= pause1;
  167            end if;
  168          end if;
  169        when head3 =>
  170          ReqX <= '0';                            -- no more Ext.data from MGTs
  171          if (LastW = '1' or EBempty = '0') then
  172            ReqD <= '1';                          -- ask for event data from MGTs
  173            statecon <= data;
  174          else
  175            ReqD <= '0';
  176            statecon <= head3;
  177          end if;
  178        when data =>
  179          ReqX <= '0';                            -- no more Ext.data from MGTs
  180          if (EBvalid = '1' or LastW = '1') then
  181            if (MatchLWC = '1') then
  182              dats := EBdata(31 downto 24)        -- copy LWC identifier
  183              & x"0"                              -- unused type
  184              & EXdata(15 downto 12)              -- event ID nibble
  185              & x"0"                              -- unused nibble of wordcount
  186              & EXdata(11 downto 0);              -- real event wordcount value
  187              dtav := '1';                        -- send valid word
  188              cntw := cntw + 1;                   --
  189            elsif (MatchTWC  = '1') then
  190              dats := EBdata;                     -- trailer word
  191              dtav := '1';                        -- send valid word
  192              cntw := cntw + 1;                   --
  193            elsif (MatchBOEF = '1') then
  194              EvtCur <= EBdata(11 downto 0);      -- copy magic word (debug: is ECnt?)
  195              dtav := '0';                        -- do NOT store in event ! 
  196            else
  197              dats := EBdata;                     -- event data words
  198              dtav := '1';                        -- send valid word
  199              cntw := cntw + 1;                   --
  200            end if;
  201          else
  202            dtav := '0';                          -- no data
  203          end if;
  204          if (MatchTWC = '1') then
  205            ReqD <= '0';                          -- no more data from MGTs
  206            mask := mask(6 downto 0) & '0';       -- select next channel
  207            chan := chan + 1;
  208            statecon <= pause1;
  209          elsif (HFullSL = '1') then              -- wait when HFullSL is on
  210            ReqD <= '0';                          -- no more data from MGTs
  211            statecon <= pause2;                   -- not pause1
  212          else
  213            ReqD <= '1';                          -- ask for data from MGTs
  214            statecon <= data;                     -- copy more data from this MGT
  215          end if;
  216        when pause1 =>
  217          dtav := '0';
  218          ReqD <= '0';                            -- no more data from MGTs
  219          if (HFullSL = '1') then                 -- wait when HFullSL is on
  220            statecon <= pause1;                   -- just wait here
  221          elsif (chan = 8) then                   -- all channels done ?
  222            SxTrail <= '1';                       -- get event trailer
  223            statecon <= trail1;
  224          elsif ((mask and ChanActive) /= x"00") then
  225          --if (LastX = '1' or EXempty = '0') then
  226            if (EXempty = '0') then
  227              ReqX <= '1';                        -- read one word (evt#,wct#)
  228              statecon <= head3;
  229            else
  230              ReqX <= '0';
  231              statecon <= pause1;                 -- wait until word available
  232            end if;
  233          else
  234            mask := mask(6 downto 0) & '0';       -- select next channel
  235            chan := chan + 1;
  236            statecon <= pause1;
  237          end if;
  238        when pause2 =>
  239          dtav := '0';
  240          if (HFullSL = '1') then                 -- wait when HFullSL is on
  241            ReqD <= '0';                          -- no more data from MGTs
  242            statecon <= pause2;
  243          else
  244            ReqD <= '1';                          -- ask for data from MGTs
  245            statecon <= data;
  246          end if;
  247        when trail1 =>
  248          SxTrail <= '0';                         -- no more event trailer
  249          ReqD <= '0';                            -- no more data from MGTs
  250          if (HValid = '1') then                  -- no HFullSL check !
  251            dats := HFile;                        -- trailer words
  252            dtav := '1';
  253            cntw := cntw + 1;
  254            statecon <= trail2;
  255          else
  256            dtav := '0';
  257            statecon <= trail1;
  258          end if;
  259        when trail2 =>
  260          if (HValid = '1') then                  -- no HFullSL check !
  261            dats := HFile;                        -- trailer words
  262            dtav := '1';
  263            cntw := cntw + 1;
  264            statecon <= trail2;
  265          else
  266            dtav := '0';
  267            statecon <= init;
  268          end if;
  269        when others =>
  270          dtav := '0';
  271          statecon <= init;
  272        end case;
  273        SLCtrl <= Ctrlbit;                        -- pipeline (like LRD,SLWEN)
  274      end if;
  275      Channel <= std_logic_vector(chan(3 downto 0));
  276      NDE     <= std_logic_vector(cntw);          -- Number of Data Elements
  277      LRD   <= dats;
  278      SLWEN <= dtav;
  279    end process;
  280  
  281    prError:
  282    process (SClk, Rst_n)
  283    begin
  284      if (Rst_n = '0') then
  285        EnFilter <= '0';
  286      elsif (rising_edge(SClk)) then
  287        case statecon is
  288        when init =>
  289          EnFilter <= '0';
  290        when head3 | data =>
  291          EnFilter <= '1';                -- turn on ECNT/BCNT check
  292          --                              -- turn on TDC/GOL parity error check
  293        when others =>
  294          null;
  295        end case;
  296      end if;
  297    end process;
  298  
  299  end architecture a0 ; -- of MuxControl
  300  
  301