wf_cons_outcome.vhd 22.4 KB
Newer Older
1 2
--_________________________________________________________________________________________________
--                                                                                                |
3
--                                         |The nanoFIP|                                          |
4
--                                                                                                |
5
--                                         CERN,BE/CO-HT                                          |
6
--________________________________________________________________________________________________|
7 8

---------------------------------------------------------------------------------------------------
9
--                                                                                                |
10
--                                        wf_cons_outcome                                         |
11
--                                                                                                |
12
---------------------------------------------------------------------------------------------------
13
-- File         wf_cons_outcome.vhd                                                               |
14 15 16 17
--                                                                                                |
-- Description  The unit starts by validating a consumed RP_DAT frame with respect to the         |
--              correctness of:                                                                   |
--                o the CTRL, PDU_TYPE and LGTH bytes; these bytes are received from the          |
18 19 20
--                  wf_consumption unit                                                           |
--                o the CRC, FSS & FES bytes; the rx_fss_crc_fes_ok_p_i pulse, received from the  |
--                  wf_fd_receiver unit, groups these checks                                      |
21 22
--                                                                                                |
--              Then, according to the consumed variable that has been received (var_1, var_2,    |
23 24
--              var_rst, var_4) it generates the signals:                                         |
--                o "nanoFIP User Interface, NON_WISHBONE" output signals VAR1_RDY and VAR2_RDY   |
25
--                o "nanoFIP User Interface, NON_WISHBONE" output signal r_tler_o, also used by   |
26 27 28
--                  the wf_status_bytes_generator unit (nanoFIP status byte, bit 4)               |
--                o rst_nFIP_and_FD_p and assert_RSTON_p, that are inputs to the wf_reset_unit    |
--                o jc_start_p that triggers the start-up of thr wf_jtag_controller unit          |
29 30 31 32 33 34 35 36 37 38
--                                                                                                |
--                                                                                                |
--              Reminder:                                                                         |
--                                                                                                |
--              Consumed RP_DAT frame structure :                                                 |
--   ___________ ______  _______ ______ _________________________ _______  ___________ _______    |
--  |____FSS____|_CTRL_||__PDU__|_LGTH_|_____..Applic-Data.._____|__MPS__||____FCS____|__FES__|   |
--                                                                                                |
--                                     |-----------&LGTH bytes-----------|                        |
--                                     |---------- >0 and <128 ----------|                        |
39
--              |--------------------------&byte_index_i bytes--------------------------------|   |
40 41 42 43 44 45 46
--                                                                                                |
--              The LGTH byte is considered correct if it is coherent with the actual number of   |
--              bytes received in the frame and also respects the frame limits.                   |
--                                                                                                |
--                                                                                                |
-- Authors      Pablo Alvarez Sanchez (Pablo.Alvarez.Sanchez@cern.ch)                             |
--              Evangelia Gousiou     (Evangelia.Gousiou@cern.ch)                                 |
47
-- Date         06/2011                                                                           |
48
---------------------------------------------------------------------------------------------------
49

50
---------------------------------------------------------------------------------------------------
51 52
--                                      SOLDERPAD LICENSE                                         |
--                                   Copyright CERN 2014-2018                                     |
53
--                              ------------------------------------                              |
54 55 56 57 58 59 60
-- Copyright and related rights are licensed under the Solderpad Hardware License, Version 2.0    |
-- (the "License"); you may not use this file except in compliance with the License.              |
-- You may obtain a copy of the License at http://solderpad.org/licenses/SHL-2.0.                 |
-- Unless required by applicable law or agreed to in writing, software, hardware and materials    |
-- distributed under this License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR       |
-- CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language   |
-- governing permissions and limitations under the License.                                       |
61 62 63 64 65 66 67 68 69 70 71 72 73 74
---------------------------------------------------------------------------------------------------



--=================================================================================================
--                                      Libraries & Packages
--=================================================================================================

-- Standard library
library IEEE;
use IEEE.STD_LOGIC_1164.all; -- std_logic definitions
use IEEE.NUMERIC_STD.all;    -- conversion functions
-- Specific library
library work;
75
use work.WF_PACKAGE.all;     -- definitions of types, constants, entities
76

77 78

--=================================================================================================
79
--                           Entity declaration for wf_cons_outcome
80 81
--=================================================================================================

82
entity wf_cons_outcome is port(
83
  -- INPUTS
84
    -- nanoFIP User Interface, General signals
85 86
    uclk_i                 : in std_logic;                     -- 40 MHz clock
    slone_i                : in std_logic;                     -- stand-alone mode
87

88
    -- nanoFIP WorldFIP Settings
89
    subs_i                 : in std_logic_vector (7 downto 0); -- subscriber number coding
90

91
    -- Signal from the wf_reset_unit
92
    nfip_rst_i             : in std_logic;                     -- nanoFIP internal reset
egousiou's avatar
egousiou committed
93

94
    -- Signal from the wf_fd_receiver unit
95 96
    rx_fss_crc_fes_ok_p_i  : in std_logic; -- indication of a frame with correct FSS, FES & CRC;
                                           -- pulse upon FES detection
97

98
    rx_crc_wrong_p_i       : in std_logic; -- indication of a frame with a wrong CRC;
99
                                           -- pulse upon FES detection
100

101
    -- Signals from the wf_consumption unit
102 103
    cons_ctrl_byte_i       : in std_logic_vector (7 downto 0); -- received RP_DAT CTRL byte
    cons_lgth_byte_i       : in std_logic_vector (7 downto 0); -- received RP_DAT LGTH byte
104 105 106
    cons_pdu_byte_i        : in std_logic_vector (7 downto 0); -- received RP_DAT PDU_TYPE byte
    cons_var_rst_byte_1_i  : in std_logic_vector (7 downto 0); -- received var_rst RP_DAT, 1st data-byte
    cons_var_rst_byte_2_i  : in std_logic_vector (7 downto 0); -- received var_rst RP_DAT, 2nd data-byte
107

108
   -- Signals from the wf_engine_control unit
109 110 111
    cons_bytes_excess_i    : in std_logic;                     -- RP_DAT frame with > 133 bytes
    byte_index_i           : in std_logic_vector (7 downto 0); -- index of byte being received
    var_i                  : in t_var;                  -- variable type that is being treated
112 113


egousiou's avatar
egousiou committed
114
  -- OUTPUTS
115
    -- nanoFIP User Interface, NON-WISHBONE outputs
116 117
    var1_rdy_o             : out std_logic; -- signals new data is received and can safely be read
    var2_rdy_o             : out std_logic; -- signals new data is received and can safely be read
egousiou's avatar
egousiou committed
118

119 120
    -- Signal to the wf_jtag_controller unit
    jc_start_p_o           : out std_logic; -- pulse upon the end of a new valid var_4
egousiou's avatar
egousiou committed
121

122
    -- Signal to the wf_status_bytes_gen unit
123
    nfip_status_r_tler_p_o : out std_logic; -- received PDU_TYPE or LGTH error
124
                                            -- nanoFIP status byte bit 4
125

126
    -- Signals to the wf_reset_unit
127 128 129
    assert_rston_p_o       : out std_logic; -- indicates that a var_rst with its 2nd data-byte
                                            -- containing the station's address has been
                                            -- correctly received
130

131
    rst_nfip_and_fd_p_o    : out std_logic);-- indicates that a var_rst with its 1st data-byte
132 133
                                            -- containing the station's address has been
                                            -- correctly received
134
end entity wf_cons_outcome;
135 136 137


--=================================================================================================
138
--                                    architecture declaration
139
--=================================================================================================
140
architecture rtl of wf_cons_outcome is
141

142
  signal s_cons_frame_ok_p                 : std_logic;
143
  signal s_rst_nfip_and_fd, s_assert_rston : std_logic;
egousiou's avatar
egousiou committed
144

145

146
--=================================================================================================
147
--                                       architecture begin
148
--=================================================================================================
149
begin
150

egousiou's avatar
egousiou committed
151

152
---------------------------------------------------------------------------------------------------
153 154 155
--                                Consumed RP_DAT frame Validation                               --
---------------------------------------------------------------------------------------------------

156
-- Sequential process Frame_Validation: validation of a consumed RP_DAT frame, with
157
-- respect to the CTRL, PDU_TYPE and LGTH bytes as well as to the CRC, FSS & FES.
158 159 160 161
-- The bytes cons_ctrl_byte_i, cons_pdu_byte_i, cons_lgth_byte_i that
-- arrive at the beginning of a frame, have been registered and keep their values until the end
-- of it. The signal rx_fss_crc_fes_ok_p_i, is a pulse at the end of the FES that combines
-- the checks of the FSS, CRC & FES.
162 163 164 165
-- To check the correctness of the the RP_DAT.Data.LGTH byte, we compare it to the value of the
-- bytes counter byte_index_i, when the FES is detected (pulse rx_fss_crc_fes_ok_p_i).

-- Note: Upon FES detection the counter byte_index_i should be equal to &cons_lgth_byte_i + 5.
166 167
-- This is because the byte_index_i also counts the: CTRL, PDU_TYPE, LGTH, the 2 CRC and
-- the FES bytes (and counting starts from 0!).
egousiou's avatar
egousiou committed
168

169
  Frame_Validation: process (uclk_i)
egousiou's avatar
egousiou committed
170 171 172
  begin
    if rising_edge (uclk_i) then
      if nfip_rst_i = '1' then
173 174
        s_cons_frame_ok_p          <= '0';

175 176 177
      else
                                                                                  -- only consumed RP_DATs
        if (var_i = var_1) or (var_i = var_2) or (var_i = var_rst) or (var_i = var_4) then
egousiou's avatar
egousiou committed
178

179 180 181 182 183 184 185 186 187 188 189
          if (rx_fss_crc_fes_ok_p_i = '1')                                  and   -- FSS CRC FES check

             ((cons_ctrl_byte_i(5 downto 0) = c_RP_DAT_CTRL_BYTE)         or      -- CTRL byte check
              (cons_ctrl_byte_i(5 downto 0) = c_RP_DAT_MSG_CTRL_BYTE)     or
              (cons_ctrl_byte_i(5 downto 0) = c_RP_DAT_RQ1_CTRL_BYTE)     or
              (cons_ctrl_byte_i(5 downto 0) = c_RP_DAT_RQ2_CTRL_BYTE)     or
              (cons_ctrl_byte_i(5 downto 0) = c_RP_DAT_RQ1_MSG_CTRL_BYTE) or   
              (cons_ctrl_byte_i(5 downto 0) = c_RP_DAT_RQ2_MSG_CTRL_BYTE))    and  
   
             (cons_pdu_byte_i  = c_PDU_TYPE_BYTE)                             and -- PDU_TYPE byte check

190
             (unsigned(byte_index_i ) = (unsigned(cons_lgth_byte_i) + 5)) then    -- LGTH byte check
egousiou's avatar
egousiou committed
191

192
            s_cons_frame_ok_p      <= '1';
193
          else
194
            s_cons_frame_ok_p      <= '0';
egousiou's avatar
egousiou committed
195 196
          end if;

197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
        end if;
      end if;
    end if;
  end process;



---------------------------------------------------------------------------------------------------
--                                       r_tler generation                                       --
---------------------------------------------------------------------------------------------------

-- Gneration of the of the "nanoFIP User Interface, NON_WISHBONE" output signal r_tler_o which
-- indicates a received CTRL or PDU_TYPE byte error or a LGTH byte incoherency.

-- Note: The end of a frame is marked by either the signal rx_fss_crc_fes_ok_p_i or by the
-- rx_crc_wrong_p_i.

  nFIP_statusbyte_bit4: process (uclk_i)
  begin
    if rising_edge (uclk_i) then
      if nfip_rst_i = '1' then
        nfip_status_r_tler_p_o     <= '0';
      else
                                                                                  -- only consumed RP_DATs
        if (var_i = var_1) or (var_i = var_2) or (var_i = var_rst) or (var_i = var_4) then

           if (cons_bytes_excess_i = '1')                                      or -- excess of bytes (without FES detection)
224

225
             (((rx_fss_crc_fes_ok_p_i = '1') or (rx_crc_wrong_p_i = '1'))    and  -- upon FES detection checking of CTRL, PDU_TUPE, LGTH
226

egousiou's avatar
egousiou committed
227
             ((not ((cons_ctrl_byte_i(5 downto 0) = c_RP_DAT_CTRL_BYTE)       or  -- CTRL byte check
228 229 230 231 232 233
                    (cons_ctrl_byte_i(5 downto 0) = c_RP_DAT_MSG_CTRL_BYTE)   or
                    (cons_ctrl_byte_i(5 downto 0) = c_RP_DAT_RQ1_CTRL_BYTE)   or
                    (cons_ctrl_byte_i(5 downto 0) = c_RP_DAT_RQ2_CTRL_BYTE)   or
                    (cons_ctrl_byte_i(5 downto 0) = c_RP_DAT_RQ1_MSG_CTRL_BYTE)or   
                    (cons_ctrl_byte_i(5 downto 0) = c_RP_DAT_RQ2_MSG_CTRL_BYTE)))or 

egousiou's avatar
egousiou committed
234
             (cons_pdu_byte_i /= c_PDU_TYPE_BYTE)                             or  -- PDU_TYPE byte check
235

egousiou's avatar
egousiou committed
236
             (unsigned(byte_index_i ) /= (unsigned(cons_lgth_byte_i) + 5)))) then -- LGTH byte check
egousiou's avatar
egousiou committed
237 238 239 240 241 242 243 244 245 246 247 248 249

            nfip_status_r_tler_p_o <= '1';
          else
            nfip_status_r_tler_p_o <= '0';

          end if;
        end if;
      end if;
    end if;
  end process;



250
---------------------------------------------------------------------------------------------------
251
--                                        VAR_RDY_Generation                                     --
252 253
---------------------------------------------------------------------------------------------------

254
-- Synchronous process VAR_RDY_Generation:
255

256 257 258 259
-- Memory Mode:
  -- Since the three memories (consumed, consumed broadcast, produced) are independent, when a
  -- produced var is being sent, the user can read form the consumed memories; similarly, when a
  -- consumed var is being received the user can read from the consumed broadcast memory.
260

261
  -- VAR1_RDY (for consumed vars)          : signals that the user can safely read from the
262 263
  -- consumed memory. The signal is asserted only after the reception of a correct var_1 RP_DAT
  -- frame. It is de-asserted after the reception of a correct var_1 ID_DAT frame.
264

265 266
  -- VAR2_RDY (for broadcast consumed vars): signals that the user can safely read from the
  -- consumed broadcast memory. The signal is asserted only after the reception of a correct
267 268
  -- consumed broadcast var_2 RP_DAT frame. It is de-asserted after the reception of a correct
  -- var_2 ID_DAT frame.
269 270


271 272 273
-- Stand-alone Mode:
  -- Similarly, in stand-alone mode, the DAT_I and DAT_O buses for the produced and the consumed
  -- bytes are independent. Stand-alone mode though does not treat the consumed broadcast variable.
274

275
  -- VAR1_RDY (for consumed vars)          : signals that the user can safely retrieve data from
276 277
  -- the DAT_O bus. The signal is asserted only after the reception of a correct var_1 RP_DAT frame.
  -- It is de-asserted after the reception of a correct var_1 ID_DAT frame (same as in memory mode).
278

279
  -- VAR2_RDY (for broadcast consumed vars): stays always deasserted.
280

281 282 283
-- Note: A correct consumed RP_DAT frame is signaled by the s_cons_frame_ok_p, which arrives upon
-- FES detection. A correct ID_DAT frame along with the variable it contained is signaled by the
-- var_i. The signal var_i gets its value (var_1, var_2, var_rst) after the reception of a correct
284 285 286
-- ID_DAT and of a correct RP_DAT FSS; var_i retains its value until the FES detection (or the
-- detection of an excess of bytes) of the RP_DAT frame. An example follows:

287 288
-- frames          : ___[ID_DAT,var_1]__[......RP_DAT......]______________[ID_DAT,var_1]___[.....RP_DAT..
-- cons_frame_ok_p : ______________________________________|-|___________________________________________
289 290
-- var_i           :    var_whatever  > <       var_1      > <        var_whatever        > <   var_1
-- VAR1_RDY        : ______________________________________|--------------------------------|____________
291

292
  VAR_RDY_Generation: process (uclk_i)
293
  begin
294
    if rising_edge (uclk_i) then
egousiou's avatar
egousiou committed
295
      if nfip_rst_i = '1' then
296 297
        var1_rdy_o   <= '0';
        var2_rdy_o   <= '0';
298 299 300

      else

301 302 303 304 305
        -- VAR1_RDY --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  -- --  --  --  --  
        if (var_i = var_1) and (s_cons_frame_ok_p = '1') then
                                             -- only if the received var_1 RP_DAT frame is correct
          var1_rdy_o <= '1';                 -- the nanoFIP signals the user to retreive data
                                             -- note: the signal var1_rdy_o remains asserted
306
                                             -- until the beginning of a new var_1
307

308
        elsif (var_i = var_1) then
309

310
          var1_rdy_o <= '0';                 -- while consuming a var_1, VAR1_RDY is '0'
311

312
        end if;      
313 314


315 316 317 318 319 320
        -- VAR2_RDY --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  -- --  --  --  -- 
        if (var_i = var_2) and (s_cons_frame_ok_p = '1') and (slone_i = '0') then
                                             -- only in memory mode and if the received var_2 
          var2_rdy_o <= '1';                 -- RP_DAT is correct the nanoFIP signals the user
                                             -- to retreive data
                                             -- note: the signal var2_rdy_o remains asserted
321
                                             -- until the beginning of a new var_2
322

323
        elsif (var_i = var_2) then
324

325
          var2_rdy_o <= '0';                 -- while consuming a var_2, VAR2_RDY is '0'
326

327
        end if;      
egousiou's avatar
egousiou committed
328

329 330 331 332
      end if;
    end if;
  end process;

333 334


335
---------------------------------------------------------------------------------------------------
336 337 338
--                               var_rst: Reset Signals Generation                               --
---------------------------------------------------------------------------------------------------

339 340 341 342
-- Generation of the signals rst_nfip_and_fd : signals that the 1st byte of a consumed
--                                             var_rst contains the station address
--                          and assert_rston : signals that the 2nd byte of a consumed
--                                             var_rst contains the station address
343

344
  Cons_Reset_Signals: process (uclk_i)
345
  begin
346
    if rising_edge (uclk_i) then
347

egousiou's avatar
egousiou committed
348
      if nfip_rst_i = '1' then
349 350
        s_rst_nfip_and_fd     <= '0';
        s_assert_rston        <= '0';
351

352 353 354
      else

        if var_i = var_rst then
355

356
          if (byte_index_i = c_1st_DATA_BYTE_INDEX) and (cons_var_rst_byte_1_i = subs_i) then
357

358 359
            s_rst_nfip_and_fd <= '1'; -- rst_nFIP_and_FD_o stays asserted until
          end if;                     -- the end of the var_rst RP_DAT frame
360

361
          if (byte_index_i = c_2nd_DATA_BYTE_INDEX) and (cons_var_rst_byte_2_i = subs_i) then
362

363
            s_assert_rston    <= '1'; -- assert_RSTON_o stays asserted until
364 365
          end if;                     -- the end of the var_rst RP_DAT frame

366
        else
367 368
          s_rst_nfip_and_fd   <= '0';
          s_assert_rston      <= '0';
369 370 371 372 373 374
        end if;
      end if;
    end if;
  end process;

  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  -- --  --  --  --  --  --  --  --  --
375 376 377 378 379 380
  rst_nfip_and_fd_p_o         <= '1' when s_rst_nfip_and_fd = '1' and s_cons_frame_ok_p = '1' else '0';
  assert_rston_p_o            <= '1' when s_assert_rston = '1'    and s_cons_frame_ok_p = '1' else '0';



---------------------------------------------------------------------------------------------------
381
--                              var_4: JTAG_contoller startup signal                             --
382 383 384
---------------------------------------------------------------------------------------------------

-- Generation of the signal jc_start_p_o that is a 1 uclk-long pulse after the reception of a
385 386
-- valid JTAG consumed RP_DAT frame (var_4). The pulse triggers the startup of the wf_jtag_controller
-- state machine. 
387 388 389 390 391 392

  jc_start_p_generation: process (uclk_i)
  begin
    if rising_edge (uclk_i) then
      if nfip_rst_i = '1' then
          jc_start_p_o <= '0';
393

394
      else
395
        if (var_i = var_4) and (s_cons_frame_ok_p = '1') then
396 397
 
          jc_start_p_o <= '1';
398

399 400 401 402 403 404 405
        else
          jc_start_p_o <= '0';
        end if;    

      end if;
    end if;
  end process;
406

407 408 409

end architecture rtl;
--=================================================================================================
410
--                                        architecture end
411 412
--=================================================================================================
---------------------------------------------------------------------------------------------------
413
--                                      E N D   O F   F I L E
414
---------------------------------------------------------------------------------------------------