1. 程式人生 > 其它 >[SV]SystemVerilog狀態機實現案例

[SV]SystemVerilog狀態機實現案例

技術標籤:UVM

SystemVerilog狀態機實現案例

一、用列舉型變數描述狀態

typedef enum bit [2:0] {TOP_HIB, TOP_BG, TOP_LDO, TOP_NOR} rx_top_fsm_e;

二、狀態機實現

2.1 更新現態暫存器

task top_fsm();
  forever begin
    @(posedge intf_mon.clk_ck or negedge intf_mon.rst_n);
    if(!intf_mon.rst_n) begin
      top_cur_st = TOP_HIB;
      top_nxt_st = TOP_HIB;
    end
    else begin
      top_cur_st = top_cur_st;
    end
  end
endtask : top_fsm

2.2 描述狀態轉移條件

task top_fsm();
  forever begin
    @(posedge intf_mon.clk_ck or negedge intf_mon.rst_n);
    case(top_cur_st)
      TOP_HIB: begin
                 top_bg_timer  = 0;
                 top_ldo_timer = 0;
                 top_bg_stable_time_up  = 0;
                 top_ldo_stable_time_up = 0;
               end
      TOP_BG:  begi