You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用with_mode方法修改对象数据:ChipModes模式依赖执行异常求助

Hey there! Let's break down what's going on here and fix that clock configuration issue you're facing.

Your core problem is that right now, all your with_mode code blocks are running unconditionally—regardless of what mode the DUT is actually in. That's why the later block always overwrites the clock values set by the earlier one. To fix this, we need to tie your clock configuration logic directly to the DUT's active mode, so it only runs when the mode matches what you intend.

Solutions for Mode-Dependent Operations

1. Explicitly Check the Current Mode First

The most straightforward fix is to first fetch the DUT's current active mode, then use conditional logic to run only the matching clock configuration:

// Assume `get_current_mode()` returns the DUT's active mode
case (get_current_mode())
  :mode1: begin
    // Clock changes that only apply when DUT is in mode1
    set_clock("clk_main", 100MHz);
    set_clock("clk_periph", 50MHz);
  end
  :mode2: begin
    // Clock changes that only apply when DUT is in mode2
    set_clock("clk_main", 150MHz);
    set_clock("clk_periph", 75MHz);
  end
  default: begin
    // Keep default clock values for all other modes (or skip this if not needed)
    set_clock("clk_main", DEFAULT_MAIN_CLK);
    set_clock("clk_periph", DEFAULT_PERIPH_CLK);
  end
endcase

This way, only the block matching the actual DUT mode will execute—no more unwanted overwrites.

2. Use ChipModes' Built-In Mode Binding (If Supported)

If your ChipModes framework offers an API to bind operations directly to specific modes (so they auto-run when the mode switches), this is a cleaner approach:

// Bind clock config to run ONLY when DUT enters mode1
bind_mode_operation(:mode1, begin
  set_clock("clk_main", 100MHz);
  set_clock("clk_periph", 50MHz);
end);

// Bind clock config to run ONLY when DUT enters mode2
bind_mode_operation(:mode2, begin
  set_clock("clk_main", 150MHz);
  set_clock("clk_periph", 75MHz);
end);

// Optional: Bind default config for all other modes
bind_mode_operation(:default, begin
  set_clock("clk_main", DEFAULT_MAIN_CLK);
  set_clock("clk_periph", DEFAULT_PERIPH_CLK);
end);

With this setup, the framework handles checking the mode for you—your clock changes will only trigger when the DUT switches to the corresponding mode.

3. Add Guard Clauses to Your Existing with_mode Blocks

If you want to keep using your existing with_mode syntax, wrap each block in a check that verifies the current mode first:

// Only run this block if DUT is actually in mode1
if (get_current_mode() == :mode1) begin
  with_mode(:mode1) begin
    set_clock("clk_main", 100MHz);
    set_clock("clk_periph", 50MHz);
  end
end

// Only run this block if DUT is actually in mode2
if (get_current_mode() == :mode2) begin
  with_mode(:mode2) begin
    set_clock("clk_main", 150MHz);
    set_clock("clk_periph", 75MHz);
  end
end

This prevents non-matching blocks from running entirely, so no overwriting occurs.

Key Takeaway

The critical rule here is: Never run mode-specific configuration logic without first verifying that the DUT is actually in that mode. Without this check, all your blocks will run in sequence, and the last one will always win.

If you're working in a test framework like UVM, consider placing this logic in the configure_phase or a dedicated mode-switch callback to ensure it runs at the right time during your test flow.


内容的提问来源于stack exchange,提问作者rchitect-of-info

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 08:33:21