// ****************************************************************************/   
// Actel Corporation Proprietary and Confidential   
// Copyright 2010 Actel Corporation.  All rights reserved.   
//   
// ANY USE OR REDISTRIBUTION IN PART OR IN WHOLE MUST BE HANDLED IN   
// ACCORDANCE WITH THE ACTEL LICENSE AGREEMENT AND MUST BE APPROVED   
// IN ADVANCE IN WRITING.   
//   
// Description: UserIF.v - User IF logic 
//   
// Revision Information:   
// Date            Description   
// ----            -----------------------------------------   
// 16May13         Inital. Ports and Parameters declaration   
//   
// SVN Revision Information:   
// SVN $Revision: 11146 $   
// SVN $Date: 2009-11-21 11:44:53 -0800 (Sat, 21 Nov 2009) $   
//   
// Resolved SARs   
// SAR      Date     Who   Description   
//    
// Notes:   
// 1.    
//   
// ****************************************************************************/   
`timescale 1 ns/10 ps   
 
 
module UserIF (   
                  // Inputs
                  clk,   
                  resetn,   
                  
                  // From User logic
                  ureq_enable_i,   
                  ucmdbyte_req_i,   
                  uoptions_mode_i,
                  ucommblk_int_i,
                  uzer_en_i,   
                  udata_wvalid_i,
                  udata_w_i,  

                  ucrypto_key,
                  ucrypto_iv,
                  ucrypto_mode,
                  ucrypto_nblocks,
                  ucrypto_length, 

                  unrbg_length,   
                  unrbg_handle,   
                  unrbg_addlength,
                  unrbg_prreq,

                  udpa_key_i,
                  udpa_optype_i,  
                  udpa_path_i,    
                  
                  uspi_txreq_en_i,   
                  uspi_txdata_i,   
                  uspi_size_i,   
                  uspi_frmcnt_i,
                  // From Command decoder IF
                  cuspi_rxval_i,   
                  cuspi_rxdata_i,
                  
                  cudata_wrdy_i,
                  cudata_rvalid_i,
                  cudata_r_i,
                  custatus_valid_i,
                  cutrans_done_i,
                  cubusy_i,
                  cuhprior_flushdone_i,
                  custatus_out_en,
                  // Outputs       
                  // To CmdDec IF
                  uccommblk_int_o,
                  uctrig_o,
                  uclatchcmd_o,   
                  uclatchoptions_o,
                  uclatchzer_o,
                  
                  uccrypto_key_o,
                  uccrypto_iv_o,
                  uccrypto_mode_o,
                  uccrypto_nblocks_o,
                  uccrypto_length_o, 

                  ucnrbg_length_o,   
                  ucnrbg_handle_o,   
                  ucnrbg_addlength_o,
                  ucnrbg_prreq_o,
                  
                  ucdpa_key_o,
                  ucdpa_optype_o,  
                  ucdpa_path_o, 
                  
                  ucspi_txreq_en_o,   
                  ucspi_txdata_o,   
                  ucspi_size_o,   
                  ucspi_frmcnt_o,
                  
                  uspi_rxval_o,   
                  uspi_rxdata_o,
                  
                  ucdata_w_o,
                  ucdata_wvalid_o,
                  ucvalid_cmd_o,
                  uchprior_flushreq_o,
                  
                  spilength,
                  
                  // To User logic   
                  ubusy_o,
                  udata_wrdy_o,
                  udata_rvalid_o,
                  udata_r_o,

                  ustatus_valid_o,
                  ustatus_resp_o 

                  );
   
   //------------------------------------------------------------------------------   
   // Parameter declarations   
   //------------------------------------------------------------------------------   

   parameter SNSERVICE        = 0;    
   parameter DSNPTR           = 0;
   parameter UCSERVICE        = 0;    
   parameter USERCODEPTR      = 0;
   parameter DCSERVICE        = 0;    
   parameter DEVICECERTPTR    = 0;
   parameter UDVSERVICE       = 0;    
   parameter DESIGNVERPTR     = 0;
 
   parameter CRYPTOAES128SERVICE    = 0;    
   parameter CRYPTOAES128DATAPTR    = 0;
   parameter CRYPTOAES256SERVICE    = 0;
   parameter CRYPTOAES256DATAPTR    = 0;
   parameter CRYPTOSHA256SERVICE    = 0;
   parameter CRYPTOSHA256DATAPTR    = 0;
   parameter CRYPTORSLTPTR          = 0;
   parameter CRYPTODATAINPPTR       = 0;
   parameter CRYPTOHMACSERVICE      = 0;
   parameter CRYPTOHMACDATAPTR      = 0;
   parameter CRYPTOSRCADPTR         = 0;
   parameter CRYPTODSTADPTR         = 0;
 
   parameter FFSERVICE              = 0;    
 
   parameter KEYTREESERVICE         = 0;
   parameter KEYTREEDATAPTR         = 0;
   parameter PPUFCHRESPSERVICE      = 0;
   parameter PPUFCHRESPPTR          = 0;
   parameter PPUFCHRESPKEYADDR      = 0;
 
   parameter NRBGSERVICE            = 0;    
   parameter NRBGINSTPTR            = 0;
   parameter NRBGPERSTRINGPTR       = 0;
   parameter NRBGGENPTR             = 0;
   parameter NRBGREQDATAPTR         = 0;
   parameter NRBGRESEEDPTR          = 0;
   parameter NRBGADDINPPTR          = 0;
 
   parameter ZERSERVICE             = 0;    
   parameter PROGIAPSERVICE         = 0;
   parameter PROGSPIADR             = 0;
   parameter PROGNVMDISERVICE       = 0;    
   parameter PORDSERVICE            = 0;    
 
   localparam AHB_AWIDTH            = 32;   
   localparam AHB_DWIDTH            = 32;   
    
   //------------------------------------------------------------------------------   
   // Port declarations   
   //------------------------------------------------------------------------------   
    
   // -----------   
   // Inputs   
   // -----------   
   input      clk;   
   input      resetn;   
   // User IF   
   input      ureq_enable_i;   
   input [7:0] ucmdbyte_req_i;   
   input [2:0] uoptions_mode_i;   
   input       ucommblk_int_i;   
   input       uzer_en_i;   

   input       udata_wvalid_i;   
   input [AHB_DWIDTH - 1:0] udata_w_i;
   // Crypto inputs
   input [255:0]            ucrypto_key;
   input [127:0]            ucrypto_iv;
   input [7:0]              ucrypto_mode;
   input [15:0]             ucrypto_nblocks;
   input [31:0]             ucrypto_length;
   
   // NRBG inputs
   input [7:0]              unrbg_length;
   input [7:0]              unrbg_handle;
   input [7:0]              unrbg_addlength;
   input [7:0]              unrbg_prreq;    
   
   // DPA inputs
   input [255:0]            udpa_key_i;
   input [7:0]              udpa_optype_i;
   input [127:0]            udpa_path_i;

   // SPI IF   
   input                    uspi_txreq_en_i;   
   input [7:0]              uspi_txdata_i;   
   input [5:0]              uspi_size_i;   
   input [15:0]             uspi_frmcnt_i;   

   input                    cuspi_rxval_i;   
   input [7:0]              cuspi_rxdata_i;
   
   input                    cudata_wrdy_i;
   input                    cudata_rvalid_i;
   input [AHB_DWIDTH - 1:0] cudata_r_i;
   input                    custatus_valid_i;   
   input                    cutrans_done_i;
   input                    cubusy_i;
   input                    cuhprior_flushdone_i;
   input                    custatus_out_en;
   
   // -----------  
   // Outputs  
   // -----------  
   // User IF   
   output                   ustatus_valid_o;   
   output [7:0]             ustatus_resp_o;   
   output                   ubusy_o;
   
   output                   udata_wrdy_o;
   output                   udata_rvalid_o;
   output [AHB_DWIDTH - 1:0] udata_r_o;
   
   // Burstlen from User IF to Cmd Dec
   output [31:0]            spilength;            
   
   // SPI IF
   output                   uspi_rxval_o;   
   output [7:0]             uspi_rxdata_o;
   // To Command Decoder IF block
   output                   uccommblk_int_o;   

   output                   uctrig_o;
   output [7:0]             uclatchcmd_o;
   output [2:0]             uclatchoptions_o;   
   output                   uclatchzer_o;   

   output [31:0]            ucdata_w_o;
   output                   ucdata_wvalid_o;
   output                   ucvalid_cmd_o;
   output                   uchprior_flushreq_o;
   
   // Crypto inputs
   output [255:0]           uccrypto_key_o;
   output [127:0]           uccrypto_iv_o;
   output [7:0]             uccrypto_mode_o;
   output [15:0]            uccrypto_nblocks_o;
   output [31:0]            uccrypto_length_o;
   
   // NRBG outputs
   output [7:0]             ucnrbg_length_o;
   output [7:0]             ucnrbg_handle_o;
   output [7:0]             ucnrbg_addlength_o;
   output [7:0]             ucnrbg_prreq_o;    

   // DPA Keytree/PPUF outputs
   output [255:0]           ucdpa_key_o;
   output [7:0]             ucdpa_optype_o;
   output [127:0]           ucdpa_path_o;  
   

   // SPI IF   
   output                   ucspi_txreq_en_o;   
   output [7:0]             ucspi_txdata_o;
   output [5:0]             ucspi_size_o;   
   output [15:0]            ucspi_frmcnt_o;   
 
   
   // -----------------  
   // Internal signals  
   // -----------------  
   reg [7:0]                uclatchcmd_o;
   reg [2:0]                uclatchoptions_o;   
   reg [7:0]                ucmdbyte_req_d1;
   reg [2:0]                uclatchoptions_d1;   
   reg                      ubusy_o;
   reg [7:0]                ustatus_resp_o;
   reg                      ustatus_valid_o;   
   reg [7:0]                ustatus_resp_lat;
   reg                      ustatus_valid_lat;   

   reg                      uctrig_o;
   reg                      uclatchzer_o;   
   wire                     uccommblk_int_o;
   wire                     new_serv;
   reg                      new_serv_d1;
   reg                      ucvalid_cmd_o;
   reg                      ucvalid_cmd_int;
   wire                     udata_wrdy_d1;
   reg                      udata_wrdy_d2;
   wire                     udata_wrdy_o;
   wire [31:0]              ucdata_w_o;
   wire                     ucdata_wvalid_o;
   wire                     udata_rvalid_o;
   wire [AHB_DWIDTH - 1:0]  udata_r_o;
   wire                     zer_new_serv;
   reg                      zer_new_serv_d1;   

   reg                      cuhprior_flushdone_d1;
   reg                      cuhprior_flushdone_d2;
   reg                      cuhprior_flushdone_d3;
   reg                      ureq_enable_d1;
   reg                      ureq_enable_d2;   

   // Crypto inputs
   reg [255:0]           uccrypto_key_o;
   reg [127:0]           uccrypto_iv_o;
   reg [7:0]             uccrypto_mode_o;
   reg [15:0]            uccrypto_nblocks_o;
   reg [31:0]            uccrypto_length_o;
   
   // NRBG outputs
   reg [7:0]             ucnrbg_length_o;
   reg [7:0]             ucnrbg_handle_o;
   reg [7:0]             ucnrbg_addlength_o;
   reg [7:0]             ucnrbg_prreq_o;    

   // DPA Keytree/PPUF outputs
   reg [255:0]           ucdpa_key_o;
   reg [7:0]             ucdpa_optype_o;
   reg [127:0]           ucdpa_path_o;  


   //////////////////////////////////////////////////////////////////////////////  
   //                           Start-of-Code                                  //  
   //////////////////////////////////////////////////////////////////////////////  

   assign                   ucspi_txreq_en_o  = uspi_txreq_en_i;   
   assign                   ucspi_txdata_o    = uspi_txdata_i;
   assign                   ucspi_size_o      = uspi_size_i;
   assign                   ucspi_frmcnt_o    = uspi_frmcnt_i;

   //---------------------------------------------------------------------------
   // udata_wrdy_d1:Registered cudata_wrdy_i
   // Register the data ready received from Cmd Decoder block
   //---------------------------------------------------------------------------
   assign                   udata_wrdy_d1  = cudata_wrdy_i;

   //---------------------------------------------------------------------------
   // udata_wrdy_d2: Registered udata_wrdy_d1
   //---------------------------------------------------------------------------
   always @(posedge clk or negedge resetn) begin
      if(resetn == 1'b0) begin
         udata_wrdy_d2  <= 1'b0;
      end
      else begin
         udata_wrdy_d2  <= udata_wrdy_d1;
      end
   end

   //---------------------------------------------------------------------------
   // udata_wrdy_o: Generate the data ready pulse to the user logic.
   // This is generated to indicate to the user logic that the DUT is ready to 
   // accept write data along with write enable asserted.
   //---------------------------------------------------------------------------
   assign udata_wrdy_o = udata_wrdy_d1 & !udata_wrdy_d2;
   
   //---------------------------------------------------------------------------
   // ucdata_w_o: Pass the write data to the Cmd Decoder block from the user 
   // ucdata_wvalid_o: Pass the write data valid to the Cmd Decoder block from
   // the user
   //---------------------------------------------------------------------------
   assign ucdata_w_o      = udata_w_i;
   assign ucdata_wvalid_o = udata_wvalid_i;

   //---------------------------------------------------------------------------
   // udata_rvalid_o: Pass the read data valid from the Cmd Decoder block to the
   // user 
   // ucdata_r_o: Pass the read data from the Cmd Decoder block to the user
   // Pass the only the handle value in instantiate service(3rd byte)
   //---------------------------------------------------------------------------
   assign udata_rvalid_o  = cudata_rvalid_i;
   assign udata_r_o       = ((uclatchcmd_o == 8'h29) & cudata_rvalid_i) ? {24'h000000, cudata_r_i[23:16]} : cudata_r_i;

   //---------------------------------------------------------------------------
   // Pass the COMM BLK interrupt to the Command Decoder FSM for polling
   // purpose
   //---------------------------------------------------------------------------
   assign uccommblk_int_o = ucommblk_int_i;

   always @(posedge clk or negedge resetn) begin
      if(resetn == 1'b0) begin
         uclatchzer_o  <= 1'b0;
      end
      else begin
         uclatchzer_o  <= uzer_en_i;
      end
   end
   
   // --------------------------------------------------------------------------
   // ubusy_o: Send the busy output back to the user logic
   // It is asserted as long as the requested service has not been serviced.
   // --------------------------------------------------------------------------
   always @(posedge clk or negedge resetn) begin
      if(resetn == 1'b0) begin
         ubusy_o     <= 1'b0;
      end
      else begin
         if(ureq_enable_i == 1'b1 || ureq_enable_d1 == 1'b1 || ureq_enable_d2 == 1'b1 || uchprior_flushreq_o == 1'b1 || 
            (cuhprior_flushdone_d2) || cuhprior_flushdone_d3 == 1'b1 || cubusy_i == 1'b1) begin
            ubusy_o     <= 1'b1;
         end
         else if(cubusy_i == 1'b0) begin
            ubusy_o     <= 1'b0;
         end
      end
   end

   // --------------------------------------------------------------------------
   // ureq_enable_d1: Delayed ureq_enable_i
   // --------------------------------------------------------------------------
   always @(posedge clk or negedge resetn) begin
      if(resetn == 1'b0) begin
         ureq_enable_d1     <= 1'b0;
         ureq_enable_d2     <= 1'b0;
      end
      else begin
         ureq_enable_d1     <= ureq_enable_i;
         ureq_enable_d2     <= ureq_enable_d1;
      end
   end
   
   // --------------------------------------------------------------------------
   // ustatus_resp_o: Send the status for the command back to the user logic
   // --------------------------------------------------------------------------
   always @(posedge clk or negedge resetn) begin
      if(resetn == 1'b0) begin
         ustatus_resp_lat     <= 8'h00;
      end
      else begin
         if(custatus_valid_i == 1'b1) begin
            ustatus_resp_lat     <= cudata_r_i;
         end
      end
   end // always @ (posedge clk or negedge resetn)
   
   // --------------------------------------------------------------------------
   // ustatus_valid_o: Indicates valid status response to the User logic
   // --------------------------------------------------------------------------
   always @(posedge clk or negedge resetn) begin
      if(resetn == 1'b0) begin
         ustatus_valid_lat     <= 1'b0;
      end
      else begin
         if(ubusy_o == 1'b0) begin
            ustatus_valid_lat     <= 1'b0;
         end
         else if(custatus_valid_i == 1'b1) begin
            ustatus_valid_lat     <= 1'b1;
         end
      end
   end // always @ (posedge clk or negedge resetn)
   
   // --------------------------------------------------------------------------
   // ustatus_resp_o: Send the status for the command back to the user logic
   // --------------------------------------------------------------------------
   always @(posedge clk or negedge resetn) begin
      if(resetn == 1'b0) begin
         ustatus_resp_o     <= 8'h00;
      end
      else begin
         if(custatus_out_en == 1'b1) begin
            ustatus_resp_o     <= ustatus_resp_lat;
         end
      end
   end // always @ (posedge clk or negedge resetn)
   
   // --------------------------------------------------------------------------
   // ustatus_valid_o: Indicates valid status response to the User logic
   // --------------------------------------------------------------------------
   always @(posedge clk or negedge resetn) begin
      if(resetn == 1'b0) begin
         ustatus_valid_o     <= 1'b0;
      end
      else begin
         if(custatus_out_en == 1'b1) begin
            ustatus_valid_o     <= ustatus_valid_lat;
         end
         else begin
            ustatus_valid_o     <= 1'b0;
         end
      end
   end // always @ (posedge clk or negedge resetn)
   


   // --------------------------------------------------------------------------
   // Latch the incoming command byte and buffer pointer/descriptor and prog.
   // options mode for programming services.
   // Also, generate the busy when the incoming command is latched indicating
   // that the system service is active and no other system service is active.
   // --------------------------------------------------------------------------
   always @(posedge clk or negedge resetn) begin
      if(resetn == 1'b0) begin
         uclatchcmd_o     <= 8'h00;
         uclatchoptions_o <= 3'b000;
      end
      else begin
         if(new_serv_d1 == 1'b1) begin
            uclatchcmd_o     <= ucmdbyte_req_d1;
            uclatchoptions_o <= uclatchoptions_d1;
         end
         else if(PORDSERVICE == 1'b1) begin
            uclatchcmd_o     <= 8'hF1;
         end
      end
   end

   always @(posedge clk or negedge resetn) begin
      if(resetn == 1'b0) begin
         ucmdbyte_req_d1   <= 8'h00;
         uclatchoptions_d1 <= 3'b000;
      end
      else begin
         if(ureq_enable_i == 1'b1) begin
            ucmdbyte_req_d1   <= ucmdbyte_req_i;
            uclatchoptions_d1 <= uoptions_mode_i;
         end
      end
   end

   // -------------------------------------------------------------------------
   // new_serv: Accept new service only when the busy is de-asserted and new 
   // request is requested.
   // -------------------------------------------------------------------------
   assign new_serv = !ubusy_o & ureq_enable_i;

   // -------------------------------------------------------------------------
   // new_serv_d1: Delayed new_seerv
   // -------------------------------------------------------------------------
   always @(posedge clk or negedge resetn) begin
      if(resetn == 1'b0) begin
         new_serv_d1     <= 1'b0;
      end
      else begin
         new_serv_d1     <= new_serv;
      end
   end
   
   // -------------------------------------------------------------------------
   // zer_new_serv: Assert on receiving high priority Zeroization service req
   // and service request enable pulse.
   // -------------------------------------------------------------------------
   assign zer_new_serv = !ubusy_o & uzer_en_i & ureq_enable_i & 
                         (ZERSERVICE == 1);

   assign uchprior_flushreq_o = ubusy_o & uzer_en_i & ureq_enable_i & 
                                (ZERSERVICE == 1);
   
   // -------------------------------------------------------------------------
   // zer_new_serv_d1: Delayed zer_new_serv
   // -------------------------------------------------------------------------
   always @(posedge clk or negedge resetn) begin
      if(resetn == 1'b0) begin
         zer_new_serv_d1     <= 1'b0;
      end
      else begin
         if((cuhprior_flushdone_d2 == 1'b1) || 
            (zer_new_serv == 1'b1)) begin
            zer_new_serv_d1     <= 1'b1;
         end
         else begin
            zer_new_serv_d1     <= 1'b0;
         end
      end

   end

   // -------------------------------------------------------------------------
   // cuhprior_flushdone_d1: delayed cuhprior_flushdone_i
   // -------------------------------------------------------------------------
   always @(posedge clk or negedge resetn) begin
      if(resetn == 1'b0) begin
         cuhprior_flushdone_d1     <= 1'b0;
         cuhprior_flushdone_d2     <= 1'b0;
         cuhprior_flushdone_d3     <= 1'b0;
      end
      else begin
         cuhprior_flushdone_d1     <= cuhprior_flushdone_i;
         cuhprior_flushdone_d2     <= cuhprior_flushdone_d1;
         cuhprior_flushdone_d3     <= cuhprior_flushdone_d2;
      end
   end


   // -------------------------------------------------------------------------
   // ucvalid_cmd_o: Generate command valid output to Cmd Decoder
   // De-assert when high priority zeroization service request is received OR
   // when busy is de-asserted.
   // -------------------------------------------------------------------------
   always @(posedge clk or negedge resetn) begin
      if(resetn == 1'b0) begin
         ucvalid_cmd_o     <= 1'b0;
      end
      else begin
         if((ubusy_o == 1'b0 && ucvalid_cmd_int == 1'b0)) begin
            ucvalid_cmd_o   <= 1'b0;
         end
         else if(ucvalid_cmd_int == 1'b1) begin
            ucvalid_cmd_o   <= 1'b1;
         end
      end
   end

   always @(*) begin
      if(new_serv == 1'b1) begin
         ucvalid_cmd_int = 1'b0;
         case(ucmdbyte_req_i)
           8'h01 : begin  // Device and Design Information services
              if(SNSERVICE == 1) begin
                 ucvalid_cmd_int = 1'b1;
              end
             end
           8'h04 : begin  // Device and Design Information services
              if(UCSERVICE == 1) begin
                 ucvalid_cmd_int = 1'b1;
              end
           end
           8'h00 : begin  // Device and Design Information services
              if(DCSERVICE == 1) begin
                 ucvalid_cmd_int = 1'b1;
              end
           end
           8'h05 : begin  // Device and Design Information services
              if(UDVSERVICE == 1) begin
                 ucvalid_cmd_int = 1'b1;
              end
           end
           8'h02 : begin                       // F*F services
              if(FFSERVICE == 1) begin
                 ucvalid_cmd_int = 1'b1;
              end
           end
           8'h03: begin   // AES128 services
              if(CRYPTOAES128SERVICE == 1) begin
                 ucvalid_cmd_int = 1'b1;
              end
           end
           8'h06: begin   // AES256 services
              if(CRYPTOAES256SERVICE == 1) begin
                 ucvalid_cmd_int = 1'b1;
              end
           end
           8'h0A: begin   // SHA256 services
              if(CRYPTOSHA256SERVICE == 1) begin
                 ucvalid_cmd_int = 1'b1;
              end
           end
           8'h0C: begin   // HMAC services
              if(CRYPTOHMACSERVICE == 1) begin
                 ucvalid_cmd_int = 1'b1;
              end
           end
           8'h09: begin                 // Key Tree services
              if(KEYTREESERVICE == 1) begin
                 ucvalid_cmd_int = 1'b1;
                end
           end
           8'h0E: begin                 // PUF services
              if(PPUFCHRESPSERVICE == 1) begin
                 ucvalid_cmd_int = 1'b1;
              end
           end
           8'h28, 8'h29, 8'h2A, 8'h2B,8'h2C, 8'h2D: begin      // NRBG services
              if(NRBGSERVICE == 1) begin
                 ucvalid_cmd_int = 1'b1;
              end
           end
           8'hF0: begin                 // Zeroization service
              if(ZERSERVICE == 1) begin
                 ucvalid_cmd_int = 1'b1;
              end
           end
           8'h14: begin                 // IAP service
              if(PROGIAPSERVICE == 1) begin
                 ucvalid_cmd_int = 1'b1;
              end
           end
           8'h17: begin                 // NVMData Integrity service
              if(PROGNVMDISERVICE == 1) begin
                 ucvalid_cmd_int = 1'b1;
              end
           end
           default: begin
              ucvalid_cmd_int = 1'b1;
           end
         endcase // case (ucmdbyte_req_i)
      end // if (new_serv == 1'b1)     
      else if(PORDSERVICE == 1) begin   // PORD Service 
         ucvalid_cmd_int = 1'b1;
      end
      else begin
         ucvalid_cmd_int = 1'b0;
      end // else: !if(new_serv == 1'b1)     
   end // always @ (*)

   // --------------------------------------------------------------------------
   // uctrig_o: Generate the trigger to the command decoder IF on the busy
   // pulse.
   // --------------------------------------------------------------------------
   always @(posedge clk or negedge resetn) begin
      if(resetn == 1'b0) begin
         uctrig_o <= 1'b0;
      end
      else begin
         if(ucvalid_cmd_o == 1'b0) begin
            uctrig_o <= 1'b0;            
         end
         else begin
            uctrig_o <= (new_serv_d1);
         end
      end         
   end

   // --------------------------------------------------------------------------
   // Pass the descriptors for crypto service to Cmd Decoder block
   // --------------------------------------------------------------------------
   always @(posedge clk or negedge resetn) begin
      if(resetn == 1'b0) begin
         uccrypto_key_o     <= {256{1'b0}};
         uccrypto_iv_o      <= {128{1'b0}};
         uccrypto_mode_o    <= {8{1'b0}};      
         uccrypto_nblocks_o <= {16{1'b0}};
         uccrypto_length_o  <= {32{1'b0}};  
      end
      else begin
         if(ureq_enable_i == 1'b1) begin 
            uccrypto_key_o     <= ucrypto_key;        
            uccrypto_iv_o      <= ucrypto_iv;          
            uccrypto_mode_o    <= ucrypto_mode;      
            uccrypto_nblocks_o <= ucrypto_nblocks;
            uccrypto_length_o  <= ucrypto_length;  
         end
      end         
   end

   // --------------------------------------------------------------------------
   // Pass the descriptors for nrbg service to Cmd Decoder block
   // --------------------------------------------------------------------------
   always @(posedge clk or negedge resetn) begin
      if(resetn == 1'b0) begin
         ucnrbg_length_o    <= {8{1'b0}};
         ucnrbg_handle_o    <= {8{1'b0}};
         ucnrbg_addlength_o <= {8{1'b0}};
         ucnrbg_prreq_o     <= {8{1'b0}};
      end
      else begin
         if(ureq_enable_i == 1'b1) begin   
            ucnrbg_length_o    <= unrbg_length;        
            ucnrbg_handle_o    <= unrbg_handle;          
            ucnrbg_addlength_o <= unrbg_addlength;      
            ucnrbg_prreq_o     <= unrbg_prreq;
         end
      end         
   end

   // --------------------------------------------------------------------------
   // Pass the descriptors for dpa service to Cmd Decoder block
   // --------------------------------------------------------------------------
   always @(posedge clk or negedge resetn) begin
      if(resetn == 1'b0) begin
         ucdpa_key_o    <= {16{1'b0}};
         ucdpa_optype_o <= {8{1'b0}};
         ucdpa_path_o   <= {8{1'b0}};      
      end
      else begin
         if(ureq_enable_i == 1'b1) begin 
            ucdpa_key_o    <= udpa_key_i;   
            ucdpa_optype_o <= udpa_optype_i;
            ucdpa_path_o   <= udpa_path_i;              
         end
      end         
   end

         
endmodule // UserIF


