산업 제조
산업용 사물 인터넷 | 산업자재 | 장비 유지 보수 및 수리 | 산업 프로그래밍 |
home  MfgRobots >> 산업 제조 >  >> Industrial programming >> verilog

Verilog 계층적 참조 범위

대부분의 프로그래밍 언어에는 scope라는 특징이 있습니다. 변수 및 메서드에 대한 특정 코드 섹션의 가시성을 정의합니다. 범위는 네임스페이스를 정의합니다. 동일한 네임스페이스 내에서 서로 다른 개체 이름 간의 충돌을 방지합니다.

Verilog는 모듈, 기능, 작업, 명명된 블록 및 생성 블록에 대한 새로운 범위를 정의합니다.

  
  
module tb;
	reg signal;
	
	// Another variable cannot be declared with
	// an already existing name in the same scope
	reg signal;
	
	// However, the name 'signal' can be reused inside
	// a task because it belongs to a different scope.
	task display();
		reg signal = 1;
		$display("signal = %0b", signal);
	endtask
	
endmodule

  

신호 이름과 같은 식별자는 주어진 범위에서 한 가지 유형의 항목만 선언하는 데 사용할 수 있습니다. 즉, 데이터 유형이 다르거나 동일한 두 변수는 동일한 이름을 가질 수 없으며, 동일한 이름의 태스크와 변수, 심지어 동일한 범위에서 동일한 이름을 가진 net 및 gate 인스턴스를 가질 수 없습니다.

Verilog의 모든 식별자에는 고유한 계층적 경로 이름이 있으며 각 모듈 인스턴스, 작업, 기능 또는 이름이 begin end입니다. 또는 fork join 블록은 새로운 수준 또는 범위를 정의합니다.

계층적 참조 예

  
  
module tb;

	// Create two instances of different modules
	A uA();
	B uB();
	
	// Create a named block that declares a signal and 
	// prints the value at 10ns from simulation start
	initial begin : TB_INITIAL
		reg signal;
      #10 $display("signal=%0d", signal);      
	end
  
  	// We'll try to access other scopes using hierarchical
  	// references from this initial block
  	initial begin
  	  TB_INITIAL.signal = 0;
      uA.display();
      
      uB.B_INITIAL.B_INITIAL_BLOCK1.b_signal_1 = 1;
      uB.B_INITIAL.B_INITIAL_BLOCK2.b_signal_2 = 0;
    end
endmodule

  
  
  
module A;
	task display();
		$display("Hello, this is A");
	endtask
endmodule

module B;
	initial begin : B_INITIAL
		#50;
		begin : B_INITIAL_BLOCK1
			reg b_signal_1;
          #10 $display("signal_1=%0d", b_signal_1);
          
          
		end
		
		#50;
		begin : B_INITIAL_BLOCK2
			reg b_signal_2;
          #10 $display("signal_2=%0d", b_signal_2);
		end
	end
endmodule

  
시뮬레이션 로그
xcelium> run
Hello, this is A
TB signal=0
signal_1=1
signal_2=0
xmsim: *W,RNQUIE: Simulation is complete.

상향 이름 참조

하위 레벨 모듈은 계층 구조에서 상위 모듈의 항목을 참조할 수 있습니다. 예를 들어, TB_INITIAL 블록의 신호는 A의 디스플레이 작업에서 볼 수 있습니다.

  
  
module A;	
	task display();
		$display("Hello, this is A");
      
        // Upward referencing, TB_INITIAL is visible in this module
      	#5 TB_INITIAL.signal = 1;
	endtask
endmodule

  

모듈 A에 의해 신호에 대한 상향 참조 변경으로 인해 TB 신호는 이제 0 대신 1입니다.

시뮬레이션 로그
xcelium> run
Hello, this is A
TB signal=1
signal_1=1
signal_2=0
xmsim: *W,RNQUIE: Simulation is complete.

다음은 다중 중첩 모듈이 있는 또 다른 예이며 리프 노드는 상향 계층 참조를 통해 위 노드에서 멤버에 직접 액세스할 수 있습니다.

  
  
module tb;
  A a();
  
  function display();
    $display("Hello, this is TB");
  endfunction
endmodule

module A;
  B b();
  function display();
    $display("Hello, this is A");
  endfunction
endmodule

module B;
  C c();  
  function display();
    $display("Hello, this is B");
  endfunction
endmodule

module C;
  D d();
  
  function display();
    $display("Hello, this is C");
  endfunction
endmodule

module D;
  initial begin
    a.display();  // or A.display()
    b.display();  // or B.display()
    c.display();  // or C.display()
    
    a.b.c.display();
  end
endmodule

  
시뮬레이션 로그
xcelium> run
Hello, this is A
Hello, this is B
Hello, this is C
Hello, this is C
xmsim: *W,RNQUIE: Simulation is complete.

컴파일러가 b.display()를 찾으면

  1. b가 정의되었는지 확인하기 위해 모듈 D 내의 현재 범위를 찾습니다. 존재하지 않으면 둘러싸는 범위에서 이름을 찾고 모듈 범위에 도달할 때까지 위쪽으로 이동합니다. 그래도 이름을 찾지 못하면 다음 단계로 넘어갑니다.
  2. 상위 모듈의 가장 바깥쪽 범위를 살펴보고 찾지 못하면 계층 구조 위로 계속 올라갑니다.

verilog

  1. Verilog 튜토리얼
  2. Verilog 연결
  3. Verilog - 호두 껍질에
  4. Verilog 할당
  5. Verilog 차단 및 비 차단
  6. Verilog 기능
  7. Verilog 작업
  8. Verilog 계층적 참조 범위
  9. Verilog 클록 생성기
  10. Verilog 디스플레이 작업