IDCODE:
[c4m-jtag.git] / rtl / vhdl / c4m_jtag_tap_controller.vhdl
index a6f0f15f13dae393c4eee452989a3f4e88bb3c88..57a86256513cc2226c4811d00b62229a80828cc6 100644 (file)
@@ -8,10 +8,12 @@ use work.c4m_jtag.ALL;
 
 entity c4m_jtag_tap_controller is
   generic (
-    IR_WIDTH:   integer := 2;
-    IOS:        integer := 1;
+    IR_WIDTH:           integer := 2;
+    IOS:                integer := 1;
 
-    VERSION:    std_logic_vector(3 downto 0)
+    MANUFACTURER:       std_logic_vector(10 downto 0) := "10001111111";
+    PART_NUMBER:        std_logic_vector(15 downto 0) := "0000000000000001";
+    VERSION:            std_logic_vector(3 downto 0) := "0000"
   );
   port (
     -- The TAP signals
@@ -19,6 +21,7 @@ entity c4m_jtag_tap_controller is
     TMS:        in std_logic;
     TDI:        in std_logic;
     TDO:        out std_logic;
+    TDO_EN:     out std_logic;
     TRST_N:     in std_logic;
 
     -- The FSM state indicators
@@ -44,14 +47,17 @@ end c4m_jtag_tap_controller;
 architecture rtl of c4m_jtag_tap_controller is
   signal S_STATE:       TAPSTATE_TYPE;
   signal S_NEXT_STATE:  TAPSTATE_TYPE;
-  signal S_IRSTATE:       std_logic;
-  signal S_DRSTATE:       std_logic;
+  signal S_IRSTATE:     std_logic;
+  signal S_DRSTATE:     std_logic;
   signal S_IR:          std_logic_vector(IR_WIDTH-1 downto 0);
 
-  -- TODO: Automate PART_NUMBER generation
-  constant PART_NUMBER: std_logic_vector(15 downto 0) := "0000000010001001";
-  -- TODO: Get manufacturer ID
-  constant MANUFACTURER: std_logic_vector(10 downto 0) := "00000000000";
+  signal IR_TDO:        std_logic;
+  signal IR_TDO_EN:     std_logic;
+  signal ID_TDO:        std_logic;
+  signal ID_TDO_EN:     std_logic;
+  signal IO_TDO:        std_logic;
+  signal IO_TDO_EN:     std_logic;
+  signal EN:            std_logic_vector(2 downto 0) := "000";
 begin
   STATE <= S_STATE;
   NEXT_STATE <= S_NEXT_STATE;
@@ -78,7 +84,8 @@ begin
     port map (
       TCK => TCK,
       TDI => TDI,
-      TDO => TDO,
+      TDO => IR_TDO,
+      TDO_EN => IR_TDO_EN,
       STATE => S_STATE,
       NEXT_STATE => S_NEXT_STATE,
       IRSTATE => S_IRSTATE,
@@ -95,7 +102,8 @@ begin
     port map (
       TCK => TCK,
       TDI => TDI,
-      TDO => TDO,
+      TDO => ID_TDO,
+      TDO_EN => ID_TDO_EN,
       STATE => S_STATE,
       NEXT_STATE => S_NEXT_STATE,
       DRSTATE => S_DRSTATE,
@@ -111,7 +119,8 @@ begin
     port map (
       TCK => TCK,
       TDI => TDI,
-      TDO => TDO,
+      TDO => IO_TDO,
+      TDO_EN => IO_TDO_EN,
       STATE => S_STATE,
       NEXT_STATE => S_NEXT_STATE,
       DRSTATE => S_DRSTATE,
@@ -123,6 +132,17 @@ begin
       PAD_IN => PAD_IN,
       PAD_EN => PAD_EN
     );
+
+  TDO <= IR_TDO when IR_TDO_EN = '1' else
+         ID_TDO when ID_TDO_EN = '1' else
+         IO_TDO when IO_TDO_EN = '1' else
+         '0';
+  TDO_EN <= IR_TDO_EN or ID_TDO_EN or IO_TDO_EN;
+
+  EN <= IR_TDO_EN & ID_TDO_EN & IO_TDO_EN;
+  assert EN = "000" or EN = "100" or EN = "010" or EN = "001"
+    report "TDO conflict in c4m_jtag_tap_controller"
+    severity ERROR;
 end rtl;