conv_ttl_rs485.vhd 23.4 KB
Newer Older
1
--------------------------------------------------------------------------------
2
-- CERN (BE-CO-HT)
3 4 5
-- CONV-TTL-RS485 gateware
-- URL https://www.ohwr.org/projects/conv-ttl-rs485-hw/wiki/wiki/
--------------------------------------------------------------------------------
6
--
7
-- Top-level design for CONV-TTL-RS485
8
--
9
-- Dependencies:
10 11
--    general-cores repository [1]
--
12
-- References:
13 14 15 16 17
--   [1] Platform-independent core collection webpage on OHWR,
--       http://www.ohwr.org/projects/general-cores/repository
--   [2] ELMA, Access to board data using SNMP and I2C
--       http://www.ohwr.org/documents/227
--
18 19 20
--------------------------------------------------------------------------------
-- Copyright (c) 2018 CERN
--------------------------------------------------------------------------------
21
-- GNU LESSER GENERAL PUBLIC LICENSE
22
--------------------------------------------------------------------------------
23 24 25 26 27 28 29 30 31
-- This source file is free software; you can redistribute it and/or modify it
-- under the terms of the GNU Lesser General Public License as published by the
-- Free Software Foundation; either version 2.1 of the License, or (at your
-- option) any later version. This source is distributed in the hope that it
-- will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
-- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-- See the GNU Lesser General Public License for more details. You should have
-- received a copy of the GNU Lesser General Public License along with this
-- source; if not, download it from http://www.gnu.org/licenses/lgpl-2.1.html
32
--------------------------------------------------------------------------------
33 34 35 36 37 38 39 40 41 42 43

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

use work.gencores_pkg.all;
use work.wishbone_pkg.all;

use work.conv_common_gw_pkg.all;

entity conv_ttl_rs485 is
44 45 46 47
  generic (g_SIMUL          : boolean   := false;
           -- Reset time: 50ns * 2 * (10**6) = 100 ms
           g_RST_TIME       : positive  := 2*(10**6)
            );
48 49 50
  port
  (
    -- Clocks
51 52 53
    clk_20_i                : in    std_logic;
    clk_125_p_i             : in    std_logic;
    clk_125_n_i             : in    std_logic;
54 55

    -- I2C interface
56 57 58 59 60 61
    scl_i                   : in    std_logic;
    scl_o                   : out   std_logic;
    scl_en_o                : out   std_logic;
    sda_i                   : in    std_logic;
    sda_o                   : out   std_logic;
    sda_en_o                : out   std_logic;
62 63

    -- VME interface
64 65 66
    vme_sysreset_n_i        : in    std_logic;
    vme_ga_i                : in    std_logic_vector(4 downto 0);
    vme_gap_i               : in    std_logic;
67

68
    -- PCB version recognition
69
    pcbrev_i                : in    std_logic_vector(5 downto 0);
70

71
    -- Channel enable
72 73 74 75
    global_oen_o            : out   std_logic;
    ttl_oen_o               : out   std_logic;
    inv_oen_o               : out   std_logic;
    rs485_oen_o             : out   std_logic;
76 77

    -- Front panel channels
78 79 80 81
    ttl_n_i                 : in    std_logic_vector(5 downto 0);
    ttl_o                   : out   std_logic_vector(5 downto 0);
    inv_n_i                 : in    std_logic_vector(3 downto 0);
    inv_o                   : out   std_logic_vector(3 downto 0);
82 83

    -- Rear panel channels
84 85 86
    rs485_n_i               : in    std_logic_vector(5 downto 0);
    rs485_fs_n_i            : in    std_logic_vector(5 downto 0);
    rs485_o                 : out   std_logic_vector(5 downto 0);
87 88

    -- Rear input and output termination lines
89 90
    iterm_en_o              : out   std_logic_vector(5 downto 0);
    oterm_en_o              : out   std_logic_vector(5 downto 0);
91 92

    -- Channel leds
93 94 95
    led_front_n_o           : out   std_logic_vector(5 downto 0);
    led_front_inv_n_o       : out   std_logic_vector(3 downto 0);
    led_rear_n_o            : out   std_logic_vector(5 downto 0);
96 97

    -- SPI interface to on-board flash chip
98 99 100 101
    flash_cs_n_o            : out   std_logic;
    flash_sclk_o            : out   std_logic;
    flash_mosi_o            : out   std_logic;
    flash_miso_i            : in    std_logic;
102 103 104

    -- PLL DACs
    -- 20 MHz VCXO control
105 106 107
    dac20_din_o             : out   std_logic;
    dac20_sclk_o            : out   std_logic;
    dac20_sync_n_o          : out   std_logic;
108
    -- 125 MHz clock generator control
109 110 111
    dac125_din_o            : out   std_logic;
    dac125_sclk_o           : out   std_logic;
    dac125_sync_n_o         : out   std_logic;
112 113 114 115 116 117 118 119 120 121 122 123 124 125

    -- SFP lines
    sfp_los_i               : in    std_logic;
    sfp_present_i           : in    std_logic;
    sfp_rate_select_o       : out   std_logic;
    sfp_scl_b               : inout std_logic;
    sfp_sda_b               : inout std_logic;
    sfp_tx_disable_o        : out   std_logic;
    sfp_tx_fault_i          : in    std_logic;

    -- Thermometer data port
    thermometer_b           : inout std_logic;

    -- Switches
126 127
    sw_gp_n_i               : in    std_logic_vector(7 downto 0);
    sw_multicast_n_i        : in    std_logic_vector(3 downto 0);
128 129

    -- RTM lines
130 131
    rtmm_i                  : in    std_logic_vector(2 downto 0);
    rtmp_i                  : in    std_logic_vector(2 downto 0);
132 133

    -- Front panel bicolor LEDs
134 135 136 137 138 139 140 141 142 143
    led_ctrl0_o             : out   std_logic;
    led_ctrl0_oen_o         : out   std_logic;
    led_ctrl1_o             : out   std_logic;
    led_ctrl1_oen_o         : out   std_logic;
    led_gp_2_4_o            : out   std_logic;
    led_gp_1_3_o            : out   std_logic;
    led_oterm_wr_o          : out   std_logic;
    led_iterm_syserror_o    : out   std_logic;
    led_gf_syspw_o          : out   std_logic;
    led_ttl_i2c_o           : out   std_logic
144 145 146 147 148 149 150 151 152 153
  );
end entity conv_ttl_rs485;


architecture arch of conv_ttl_rs485 is

  --============================================================================
  -- Constant declarations
  --============================================================================
  -- Number of repetition channels
154 155
  constant c_NR_CHANS          : integer  := 6;
  constant c_NR_INV_CHANS      : integer  := 4;
156 157

  -- Number of bicolor LED lines & columns
158 159
  constant c_BICOLOR_LED_LINES : integer  := 2;
  constant c_BICOLOR_LED_COLS  : integer  := 6;
160 161

  -- Board ID - ASCII string "T485"
162
  constant c_BOARD_ID : std_logic_vector(31 downto 0) := x"54343835";
163 164

  -- Gateware version
165
  constant c_GWVERS   : std_logic_vector(7 downto 0) := x"20";
166 167 168 169

  --============================================================================
  -- Type declarations
  --============================================================================
170 171
  type t_ttlbar_nosig_cnt is array (c_NR_CHANS-1 downto 0) of unsigned(10 downto 0);
  type t_led_inv_cnt is array(c_NR_CHANS-1 downto 0) of unsigned(18 downto 0);
172 173 174 175 176 177 178 179

  --============================================================================
  -- Signal declarations
  --============================================================================
  -- Reset signal
  signal rst_20_n               : std_logic;

  -- TTL & RS485 signals
180 181 182 183 184 185 186 187 188
  signal rs485_fs               : std_logic_vector(c_NR_CHANS-1 downto 0);
  signal pulse_in               : std_logic_vector(c_NR_CHANS-1 downto 0);
  signal pulse_out              : std_logic_vector(c_NR_CHANS-1 downto 0);
  signal inv_pulse_in_n         : std_logic_vector(c_NR_INV_CHANS-1 downto 0);
  signal inv_pulse_out          : std_logic_vector(c_NR_INV_CHANS-1 downto 0);
  signal pulse_ttl              : std_logic_vector(c_NR_CHANS-1 downto 0);
  signal pulse_rs485            : std_logic_vector(c_NR_CHANS-1 downto 0);
  signal rs485_phy_n_i         : std_logic_vector(c_NR_CHANS-1 downto 0);
  signal rs485_fs_phy_n_i         : std_logic_vector(c_NR_CHANS-1 downto 0);
189 190 191 192 193
  signal inhibit_first_pulse    : std_logic;
  signal inhibit_first_pulse_d0 : std_logic;
  signal inhibit_cnt            : unsigned(10 downto 0);

  -- Line signals -- for reflection in line status register of conv_common_gw
194
  signal line_ttl               : std_logic_vector(c_NR_CHANS-1 downto 0);
195
  signal line_invttl            : std_logic_vector(3 downto 0);
196
  signal line_rs485             : std_logic_vector(c_NR_CHANS-1 downto 0);
197 198 199 200 201 202 203 204 205 206

  -- Switch signals (for inverting switch inputs to the common g/w)
  signal sw_ttl                 : std_logic;
  signal sw_iterm_en            : std_logic;
  signal sw_oterm_en            : std_logic;
  signal sw_gp                  : std_logic_vector(7 downto 0);
  signal sw_other               : std_logic_vector(31 downto 0);

  -- No signal on TTL-BAR
  signal ttlbar_nosig_cnt       : t_ttlbar_nosig_cnt;
207
  signal ttlbar_nosig           : std_logic_vector(c_NR_CHANS-1 downto 0);
208 209 210

  -- INV-TTL internal signals
  signal inv_n                  : std_logic_vector(3 downto 0);
211
  -- signal inv_n_d0               : std_logic_vector(3 downto 0);
212 213 214
  signal inv_n_fedge_p          : std_logic_vector(3 downto 0);

  -- Channel LED signals
215 216
  signal led_pulse              : std_logic_vector(c_NR_CHANS-1 downto 0);
  signal led_inv_pulse          : std_logic_vector(c_NR_INV_CHANS-1 downto 0);
217 218 219 220 221 222 223 224 225 226
  -- I2C LEDs
  signal led_i2c                : std_logic;
  signal led_i2c_err            : std_logic;
  signal led_inv                : std_logic_vector(3 downto 0);
  signal led_inv_cnt            : t_led_inv_cnt;

  -- System error (ERR) LED control
  signal led_syserr             : std_logic;

  -- Bicolor LED signals
227 228 229 230
  signal bicolor_led_state      : std_logic_vector(2*c_BICOLOR_LED_COLS*c_BICOLOR_LED_LINES-1 downto 0);
  signal bicolor_led_col        : std_logic_vector(c_BICOLOR_LED_COLS-1 downto 0);
  signal bicolor_led_line       : std_logic_vector(c_BICOLOR_LED_LINES-1 downto 0);
  signal bicolor_led_line_oen   : std_logic_vector(c_BICOLOR_LED_LINES-1 downto 0);
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249

--==============================================================================
--  architecture begin
--==============================================================================
begin

  --============================================================================
  -- Channel input logic
  --============================================================================
  -- TTL switch
  sw_ttl <= not sw_gp_n_i(7);

  -- The "no signal detect" block
  --
  -- If the signal line is high for 100 us, the ttlbar_nosig lines disable
  -- the input to the TTL side MUX and the OR gate.
  --
  -- The counter is disabled if the switch is set for TTL signals, to avoid
  -- unnecessary power consumption by the counter.
250

251 252 253
  p_ttlbar_nosig : process(clk_20_i)
  begin
    if rising_edge(clk_20_i) then
254
      for i in 0 to c_NR_CHANS-1 loop
255 256 257
        if (rst_20_n = '0') or (ttl_n_i(i) = '0') then
          ttlbar_nosig(i)     <= '0';
          ttlbar_nosig_cnt(i) <= (others => '0');
258
        elsif sw_ttl = '0' then
259
          ttlbar_nosig_cnt(i) <= ttlbar_nosig_cnt(i) + 1;
260
          if ttlbar_nosig_cnt(i) = 1999 then
261 262 263 264 265 266 267 268 269 270 271 272
            ttlbar_nosig(i)     <= '1';
            ttlbar_nosig_cnt(i) <= (others => '0');
          end if;
        end if;
      end loop;
    end if;
  end process p_ttlbar_nosig;

  -- TTL and blocking inputs
  pulse_ttl <= not ttl_n_i when sw_ttl = '1' else
               ttl_n_i and (not ttlbar_nosig);

273

274 275
  -- Pulse input on RS-485 side valid only when failsafe not high
  -- see Texas slyt257 for implementation details
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
  gen_rs485_input : for i in 0 to c_NR_CHANS-1 generate

  -- physical signal re-assignement for 2-channel rtm type (DB9 RTM) with code 101
    rs485_phy_n_i(0)     <= rs485_n_i(0);
    rs485_phy_n_i(1)     <= rs485_n_i(4)  when rtmp_i = "101" else rs485_n_i(1);
    rs485_phy_n_i(2)     <= rs485_n_i(2)  when rtmp_i = "101" else rs485_n_i(2);
    rs485_phy_n_i(3)     <= rs485_n_i(3)  when rtmp_i = "101" else rs485_n_i(3);
    rs485_phy_n_i(4)     <= rs485_n_i(1)  when rtmp_i = "101" else rs485_n_i(4);
    rs485_phy_n_i(5)     <= rs485_n_i(5)  when rtmp_i = "101" else rs485_n_i(5);

    rs485_fs_phy_n_i(0)  <= rs485_fs_n_i(0);
    rs485_fs_phy_n_i(1)  <= rs485_fs_n_i(4)  when rtmp_i = "101" else rs485_fs_n_i(1);
    rs485_fs_phy_n_i(2)  <= rs485_fs_n_i(2)  when rtmp_i = "101" else rs485_fs_n_i(2);
    rs485_fs_phy_n_i(3)  <= rs485_fs_n_i(3)  when rtmp_i = "101" else rs485_fs_n_i(3);
    rs485_fs_phy_n_i(4)  <= rs485_fs_n_i(1)  when rtmp_i = "101" else rs485_fs_n_i(4);
    rs485_fs_phy_n_i(5)  <= rs485_fs_n_i(5)  when rtmp_i = "101" else rs485_fs_n_i(5);

  -- Failsafe RS485 implementation for no-signal-detect functionality
    rs485_fs(i)    <= rs485_phy_n_i(i) nor rs485_fs_phy_n_i(i);
    pulse_rs485(i) <= (not rs485_phy_n_i(i)) when rs485_fs(i) = '0' else '0';

297 298 299 300 301
  end generate gen_rs485_input;

  -- This process has the effect of extending the reset an extra 100 us, to avoid
  -- a pulse being generated or erroneously counted during the period of no signal
  -- detect
302

303 304 305
  p_inhibit_first_pulse : process (clk_20_i)
  begin
    if rising_edge(clk_20_i) then
306
      if rst_20_n = '0' then
307 308
        inhibit_cnt         <= (others => '0');
        inhibit_first_pulse <= '1';
309
      elsif inhibit_first_pulse = '1' then
310
        inhibit_cnt <= inhibit_cnt + 1;
311
        if inhibit_cnt = 1999 then
312 313 314 315 316 317 318 319
          inhibit_first_pulse <= '0';
        end if;
      end if;
    end if;
  end process p_inhibit_first_pulse;

  -- Delay inhibit first pulse signal, use this to enable input, thus avoiding
  -- internal reset states of conv_common_gw
320

321 322 323
  p_inhibit_first_pulse_d0 : process (clk_20_i)
  begin
    if rising_edge(clk_20_i) then
324
      if rst_20_n = '0' then
325 326 327 328 329
        inhibit_first_pulse_d0 <= '1';
      else
        inhibit_first_pulse_d0 <= inhibit_first_pulse;
      end if;
    end if;
330
  end process p_inhibit_first_pulse_d0;
331 332

  -- Pulse input valid only after inhibit period is over
333 334

  pulse_in <= (pulse_ttl or pulse_rs485) when inhibit_first_pulse_d0 = '0'
335
                                         else (others => '0');
336 337 338 339

  -- Line inputs for reflection in status register
  line_ttl    <= not ttl_n_i;
  line_invttl <= not inv_n_i;
340
  line_rs485  <= not rs485_phy_n_i;
341 342 343 344 345 346 347 348 349 350 351 352

  -- Switch inputs for reflection in status register
  sw_gp                 <= not sw_gp_n_i;
  sw_other( 3 downto 0) <= not sw_multicast_n_i;
  sw_other(31 downto 4) <= (others => '0');

  --============================================================================
  -- Instantiate common generic gateware for converter boards
  --============================================================================
  cmp_conv_common : conv_common_gw
    generic map
    (
353 354 355 356 357 358
      g_SIMUL                 => g_SIMUL,
      g_RST_TIME              => g_RST_TIME,
      g_nr_chans              => c_NR_CHANS,
      g_board_id              => c_BOARD_ID,
      g_gwvers                => c_GWVERS,
      g_PGEN_FIXED_WIDTH      => false,
359
      g_pgen_gf_len           => 1,
360 361 362
      g_with_pulse_cnt        => false,
      g_with_pulse_timetag    => false,
      g_with_man_trig         => false,
363
      g_man_trig_pwidth       => 24,
364
      g_with_thermometer      => false,
365 366
      g_bicolor_led_columns   => c_BICOLOR_LED_COLS,
      g_bicolor_led_lines     => c_BICOLOR_LED_LINES
367 368 369 370 371 372 373 374 375 376 377 378 379
    )
    port map
    (
      -- Clocks
      clk_20_i                => clk_20_i,
      clk_125_p_i             => clk_125_p_i,
      clk_125_n_i             => clk_125_n_i,

      -- Reset output signal, synchronous to 20 MHz clock
      rst_n_o                 => rst_20_n,

      -- Glitch filter active-low enable signal
      gf_en_n_i               => sw_gp_n_i(0),
380

381
      -- Burst mode enable signal. Disabled in conv-ttl-rs485
382
      burst_en_n_i            => '1',
383 384

    -- Pulse width selection, port low means 250ns, high means 1.2us.
385 386 387
    -- Switch to determine short or long pulse mode.
    -- ON switch means SHORT 250ns pulse repetition with max frequency 2MHz
    -- OFF switch means LONG 1.2us pulse repetition with max freq ~104kHz
388
    -- In conv-ttl-rs485 this switch is not meaningful
389

390
      pulse_width_sel_n_i     => '0',
391

392 393 394 395 396 397 398 399
      -- Channel enable
      global_ch_oen_o         => global_oen_o,
      pulse_front_oen_o       => ttl_oen_o,
      pulse_rear_oen_o        => rs485_oen_o,
      inv_oen_o               => inv_oen_o,

      -- Front panel channels
      pulse_i                 => pulse_in,
400 401
      pulse_front_i           => pulse_ttl,
      pulse_rear_i            => pulse_rs485,
402
      pulse_o                 => pulse_out,
403

404
      -- Inverted pulse I/O
405
      inv_pulse_n_i           => inv_pulse_in_n,
406
      inv_pulse_o             => inv_pulse_out,
407 408 409

      -- Channel leds
      led_pulse_o             => led_pulse,
410

411
      -- inverted channel leds
412
      led_inv_pulse_o         => led_inv_pulse,
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444

      -- I2C interface
      scl_i                   => scl_i,
      scl_o                   => scl_o,
      scl_en_o                => scl_en_o,
      sda_i                   => sda_i,
      sda_o                   => sda_o,
      sda_en_o                => sda_en_o,

      -- VME interface
      vme_sysreset_n_i        => vme_sysreset_n_i,
      vme_ga_i                => vme_ga_i,
      vme_gap_i               => vme_gap_i,

      -- SPI interface to on-board flash chip
      flash_cs_n_o            => flash_cs_n_o,
      flash_sclk_o            => flash_sclk_o,
      flash_mosi_o            => flash_mosi_o,
      flash_miso_i            => flash_miso_i,

      -- PLL DACs
      -- 20 MHz VCXO control
      dac20_din_o             => dac20_din_o,
      dac20_sclk_o            => dac20_sclk_o,
      dac20_sync_n_o          => dac20_sync_n_o,
      -- 125 MHz clock generator control
      dac125_din_o            => dac125_din_o,
      dac125_sclk_o           => dac125_sclk_o,
      dac125_sync_n_o         => dac125_sync_n_o,

      -- SFP lines
      sfp_los_i               => sfp_los_i,
445
      sfp_present_i           => sfp_present_i,
446
      sfp_rate_select_o       => sfp_rate_select_o,
447
      sfp_sda_b               => sfp_scl_b,
448
      sfp_scl_b               => sfp_sda_b,
449 450
      sfp_tx_disable_o        => sfp_tx_disable_o,
      sfp_tx_fault_i          => sfp_tx_fault_i,
451

452 453 454 455 456 457 458 459
      -- I2C LED signals -- conect to a bicolor LED of choice
      -- led_i2c_o pulses four times on I2C transfer
      led_i2c_o               => led_i2c,

      -- Switch inputs (for readout from converter status register)
      sw_gp_i                 => sw_gp,
      sw_other_i              => sw_other,

460 461
      -- PCB Version information
      hwvers_i                => pcbrev_i,
462

463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490
      -- RTM lines
      rtmm_i                  => rtmm_i,
      rtmp_i                  => rtmp_i,

      -- TTL, INV-TTL and rear-panel channel inputs, for reflection in line status register
      line_front_i            => line_ttl,
      line_inv_i              => line_invttl,
      line_rear_i             => line_rs485,
      line_front_fs_i         => ttlbar_nosig,
      line_inv_fs_i           => (others => '0'),
      line_rear_fs_i          => rs485_fs,

      -- Thermometer line
      thermometer_b           => thermometer_b,

      -- System error LED, active-high on system error
      -- ERR bicolor LED should light red when led_syserr_o = '1'
      led_syserr_o            => led_syserr,

      -- Bicolor LED signals
      bicolor_led_state_i     => bicolor_led_state,
      bicolor_led_col_o       => bicolor_led_col,
      bicolor_led_line_o      => bicolor_led_line,
      bicolor_led_line_oen_o  => bicolor_led_line_oen
    );

  ttl_o   <= pulse_out when sw_ttl = '1' else
             not pulse_out;
491
  -- rs485_o (1 downto 0) <= pulse_out (1 downto 0);
492

493 494
  -- Channels 3 and 4 output copies of chans 1 and 2 respectively
  -- depending on RTMP Id of RTM connected.
495 496
    -- *RTM with DB9 connectors has only 2 o/p channels in rs485 RTMP = Gnd Open Gnd
    -- *Optical RTM only 2 o/p channels in optical RTMP= Open Open Gnd
497
  -- in these cases channel 3 copies channel 1
498
                 -- channel 4 copies channel 2
499

500 501
  -- rs485_o (3 downto 2) <= pulse_out (1 downto 0) when rtmp_i = "101" or rtmp_i = "100"
  -- rs485_o (5 downto 4) <= pulse_out (5 downto 4);
502

503 504 505 506 507 508 509 510 511 512
  --============================================================================
  -- Channel output logic
  --============================================================================
  -- Front and rear panel outputs
  rs485_o(0) <= pulse_out(0);
  rs485_o(1) <= pulse_out(0) when rtmp_i = "101" else pulse_out(1);
  rs485_o(2) <= pulse_out(2);
  rs485_o(3) <= pulse_out(3);
  rs485_o(4) <= pulse_out(1) when rtmp_i = "101" else pulse_out(4);
  rs485_o(5) <= pulse_out(1) when rtmp_i = "101" else pulse_out(5);
513

514
  -- LED outputs
515
  -- Boards earlier than v4 do not use -ve logic for LEDs.
516 517 518
  -- For these LED pulse signals are still in +ve logic.
  -- Rear pulses are negative logic on all boards

519 520
  led_front_n_o <= led_pulse when pcbrev_i (5 downto 0) = "000000"
                    else not led_pulse;
521

522 523
  led_front_inv_n_o <= led_inv_pulse when pcbrev_i (5 downto 0) = "000000"
                    else not led_inv_pulse;
524 525 526 527 528 529 530

  led_rear_n_o(0)  <= not led_pulse(0);
  led_rear_n_o(1)  <= not led_pulse(4) when rtmp_i = "101" else not led_pulse(1);
  led_rear_n_o(2)  <= not led_pulse(2) when rtmp_i = "101" else not led_pulse(2);
  led_rear_n_o(3)  <= not led_pulse(3) when rtmp_i = "101" else not led_pulse(3);
  led_rear_n_o(4)  <= not led_pulse(1) when rtmp_i = "101" else not led_pulse(4);
  led_rear_n_o(5)  <= not led_pulse(5) when rtmp_i = "101" else not led_pulse(5);
531 532 533 534

  -- INV-TTL outputs
  inv_pulse_in_n <= inv_n_i;
  inv_o <= inv_pulse_out;
535

536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558
  -- Channel terminations
  sw_iterm_en <= sw_gp(1);
  sw_oterm_en <= sw_gp(2);
  iterm_en_o <= (others => sw_iterm_en);
  oterm_en_o <= (others => sw_oterm_en);


  --============================================================================
  -- External logic for bicolor LED control
  --============================================================================
  -- Assign bicolor LED lines & columns to outputs
  led_ttl_i2c_o        <= bicolor_led_col(0);
  led_oterm_wr_o       <= bicolor_led_col(1);
  led_iterm_syserror_o <= bicolor_led_col(2);
  led_gf_syspw_o       <= bicolor_led_col(3);
  led_gp_2_4_o         <= bicolor_led_col(4);
  led_gp_1_3_o         <= bicolor_led_col(5);
  led_ctrl0_o          <= bicolor_led_line(0);
  led_ctrl1_o          <= bicolor_led_line(1);
  led_ctrl0_oen_o      <= bicolor_led_line_oen(0);
  led_ctrl1_oen_o      <= bicolor_led_line_oen(1);

  -- TTL mode (state of TTL switch)
559
  bicolor_led_state( 1 downto  0) <= c_LED_GREEN when sw_ttl = '1' else
560 561 562
                                     c_LED_OFF;

  -- Output termination enabled
563
  bicolor_led_state( 3 downto  2) <= c_LED_GREEN when sw_oterm_en = '1' else
564 565 566
                                     c_LED_OFF;

  -- Input termination enabled
567
  bicolor_led_state( 5 downto  4) <= c_LED_GREEN when sw_iterm_en = '1' else
568 569 570
                                     c_LED_OFF;

  -- Glitch filter enabled
571
  bicolor_led_state( 7 downto  6) <= c_LED_GREEN when sw_gp(0) = '1' else
572 573 574 575 576 577 578 579 580
                                     c_LED_OFF;

  -- General-purpose 4
  bicolor_led_state( 9 downto  8) <= c_LED_OFF;

  -- General-purpose 3
  bicolor_led_state(11 downto 10) <= c_LED_OFF;

  -- I2C
581
  bicolor_led_state(13 downto 12) <= c_LED_GREEN when led_i2c = '1' else
582 583 584 585 586 587 588
                                     c_LED_OFF;

  -- White Rabbit LED
  bicolor_led_state(15 downto 14) <= c_LED_OFF;

  -- System error
  bicolor_led_state(17 downto 16) <= c_LED_RED when (led_syserr = '1') or
589
                                                    (c_GWVERS(7 downto 4) = "0000" ) else
590 591 592 593 594 595 596 597 598 599 600 601
                                     c_LED_OFF;

  -- System power
  bicolor_led_state(19 downto 18) <= c_LED_GREEN;

  -- General-purpose 2
  bicolor_led_state(21 downto 20) <= c_LED_OFF;

  -- General-purpose 1
  bicolor_led_state(23 downto 22) <= c_LED_OFF;

end architecture arch;
602

603 604 605
--==============================================================================
--  architecture end
--==============================================================================