lm32_jtag.v

changeset 18
cc945f778cd7
parent 14
54dd95f89113
     1.1 diff -r 50bf3061dbff -r cc945f778cd7 lm32_jtag.v
     1.2 --- a/lm32_jtag.v	Sun Mar 06 19:49:17 2011 +0000
     1.3 +++ b/lm32_jtag.v	Sun Mar 06 21:03:32 2011 +0000
     1.4 @@ -170,13 +170,15 @@
     1.5  // Internal nets and registers 
     1.6  /////////////////////////////////////////////////////
     1.7  
     1.8 -reg rx_toggle;                          // Clock-domain crossing registers
     1.9 -reg rx_toggle_r;                        // Registered version of rx_toggle
    1.10 -reg rx_toggle_r_r;                      // Registered version of rx_toggle_r
    1.11 -reg rx_toggle_r_r_r;                    // Registered version of rx_toggle_r_r
    1.12 +reg rx_update;                          // Clock-domain crossing registers
    1.13 +reg rx_update_r;                        // Registered version of rx_update
    1.14 +reg rx_update_r_r;                      // Registered version of rx_update_r
    1.15 +reg rx_update_r_r_r;                    // Registered version of rx_update_r_r
    1.16  
    1.17 -reg [`LM32_BYTE_RNG] rx_byte;   
    1.18 -reg [2:0] rx_addr;
    1.19 +// These wires come from the JTAG clock domain.
    1.20 +// They have been held unchanged for an entire JTAG clock cycle before the jtag_update toggle flips
    1.21 +wire [`LM32_BYTE_RNG] rx_byte;   
    1.22 +wire [2:0] rx_addr;
    1.23  
    1.24  `ifdef CFG_JTAG_UART_ENABLED                 
    1.25  reg [`LM32_BYTE_RNG] uart_tx_byte;      // UART TX data
    1.26 @@ -229,36 +231,26 @@
    1.27  // Sequential Logic
    1.28  /////////////////////////////////////////////////////
    1.29  
    1.30 -// Toggle a flag when a JTAG write occurs
    1.31 - 
    1.32 -always @(negedge jtag_update `CFG_RESET_SENSITIVITY)
    1.33 -begin
    1.34 -if (rst_i == `TRUE)
    1.35 -  rx_toggle <= 1'b0;
    1.36 -else 
    1.37 -  rx_toggle <= ~rx_toggle;
    1.38 -end
    1.39 +assign rx_byte = jtag_reg_q;
    1.40 +assign rx_addr = jtag_reg_addr_q;
    1.41  
    1.42 -always @(*)
    1.43 -begin
    1.44 -    rx_byte = jtag_reg_q;
    1.45 -    rx_addr = jtag_reg_addr_q;
    1.46 -end
    1.47 -
    1.48 -// Clock domain crossing from JTAG clock domain to CPU clock domain
    1.49 +// The JTAG latched jtag_reg[_addr]_q at least one JTCK before jtag_update is raised
    1.50 +// Thus, they are stable (and safe to sample) when jtag_update is high
    1.51  always @(posedge clk_i `CFG_RESET_SENSITIVITY)
    1.52  begin
    1.53      if (rst_i == `TRUE)
    1.54      begin
    1.55 -        rx_toggle_r <= 1'b0;
    1.56 -        rx_toggle_r_r <= 1'b0;
    1.57 -        rx_toggle_r_r_r <= 1'b0;
    1.58 +        rx_update <= 1'b0;
    1.59 +        rx_update_r <= 1'b0;
    1.60 +        rx_update_r_r <= 1'b0;
    1.61 +        rx_update_r_r_r <= 1'b0;
    1.62      end
    1.63      else
    1.64      begin
    1.65 -        rx_toggle_r <= rx_toggle;
    1.66 -        rx_toggle_r_r <= rx_toggle_r;
    1.67 -        rx_toggle_r_r_r <= rx_toggle_r_r;
    1.68 +        rx_update <= jtag_update;
    1.69 +        rx_update_r <= rx_update;
    1.70 +        rx_update_r_r <= rx_update_r;
    1.71 +        rx_update_r_r_r <= rx_update_r_r;
    1.72      end
    1.73  end
    1.74  
    1.75 @@ -319,7 +311,7 @@
    1.76          `LM32_JTAG_STATE_READ_COMMAND:
    1.77          begin
    1.78              // Wait for rx register to toggle which indicates new data is available
    1.79 -            if (rx_toggle_r_r != rx_toggle_r_r_r)
    1.80 +            if ((~rx_update_r_r_r & rx_update_r_r) == `TRUE)
    1.81              begin
    1.82                  command <= rx_byte[7:4];                
    1.83                  case (rx_addr)
    1.84 @@ -384,7 +376,7 @@
    1.85  `ifdef CFG_HW_DEBUG_ENABLED
    1.86          `LM32_JTAG_STATE_READ_BYTE_0:
    1.87          begin
    1.88 -            if (rx_toggle_r_r != rx_toggle_r_r_r)
    1.89 +            if ((~rx_update_r_r_r & rx_update_r_r) == `TRUE)
    1.90              begin
    1.91                  jtag_byte_0 <= rx_byte;
    1.92                  state <= `LM32_JTAG_STATE_READ_BYTE_1;
    1.93 @@ -392,7 +384,7 @@
    1.94          end
    1.95          `LM32_JTAG_STATE_READ_BYTE_1:
    1.96          begin
    1.97 -            if (rx_toggle_r_r != rx_toggle_r_r_r)
    1.98 +            if ((~rx_update_r_r_r & rx_update_r_r) == `TRUE)
    1.99              begin
   1.100                  jtag_byte_1 <= rx_byte;
   1.101                  state <= `LM32_JTAG_STATE_READ_BYTE_2;
   1.102 @@ -400,7 +392,7 @@
   1.103          end
   1.104          `LM32_JTAG_STATE_READ_BYTE_2:
   1.105          begin
   1.106 -            if (rx_toggle_r_r != rx_toggle_r_r_r)
   1.107 +            if ((~rx_update_r_r_r & rx_update_r_r) == `TRUE)
   1.108              begin
   1.109                  jtag_byte_2 <= rx_byte;
   1.110                  state <= `LM32_JTAG_STATE_READ_BYTE_3;
   1.111 @@ -408,7 +400,7 @@
   1.112          end
   1.113          `LM32_JTAG_STATE_READ_BYTE_3:
   1.114          begin
   1.115 -            if (rx_toggle_r_r != rx_toggle_r_r_r)
   1.116 +            if ((~rx_update_r_r_r & rx_update_r_r) == `TRUE)
   1.117              begin
   1.118                  jtag_byte_3 <= rx_byte;
   1.119                  if (command == `LM32_DP_READ_MEMORY)
   1.120 @@ -419,7 +411,7 @@
   1.121          end
   1.122          `LM32_JTAG_STATE_READ_BYTE_4:
   1.123          begin
   1.124 -            if (rx_toggle_r_r != rx_toggle_r_r_r)
   1.125 +            if ((~rx_update_r_r_r & rx_update_r_r) == `TRUE)
   1.126              begin
   1.127                  jtag_byte_4 <= rx_byte;
   1.128                  state <= `LM32_JTAG_STATE_PROCESS_COMMAND;