학습 주제
- SystemVerilog 개요
- 데이터 타입
- 모듈, 인터페이스, 패키지
- 절차적 프로그래밍 (tasks, functions)
- Class 및 객체 지향 프로그래밍
학습 목표
- SystemVerilog의 기본 구조와 문법 이해
- 다양한 데이터 타입과 모듈 설계
- Class와 객체 지향 프로그래밍 개념 적용
학습 자료
- IEEE Std 1800-2017 : SystemVerilog 표준 문서의 기본 개념 부분
- SystemVerilog 온라인 튜토리얼 : 다양한 튜토리얼 사이트에서 기본 문법과 예제 학습
- 강의 비디오 : 유투브 또는 다른 교육 플랫폼에서 제공하는 SystemVerilog 강의
학습 활동
- 기초 문법 연습 : 간단한 SystemVerilog 코드 작성 및 Simulation
- Data type 실습 : 다양한 data type을 사용하는 예제 코드 작성
- 모듈 설계 : 기본 모듈을 설계하고 인터페이스와 패키지를 활용한 간단한 프로젝트 수행
1. SystemVerilog 개요
SystemVerilog는 HW 설계와 검증을 위한 언어로, Verilog를 확장하여 더 강력한 기능을 제공합니다. 주요 특징으로는 Data type extension, class와 객체 지향 프로그래밍(OOP : Object-Oriented Programming), assertion, coverage, constraint randomization 등이 있습니다.
2. Data type
SystemVerilog는 다양한 data type을 제공합니다. 기본 data type과 사용자 정의 data type을 사용하여 더 유연한 설계를 할 수 있습니다.
기본 data type :
- bit : 0 or 1 값을 가질 수 있는 data type
- logic : 4가지 상태 (0, 1, x, z)를 가질 수 있는 data type
- reg : register type, 기본 verilog type
- int: 32bit 정수 타입
- shortint : 16bit int type
- longint : 64bit int type
- integer : basic int type
- byte: 8bit int type
User define date type:
- enum : 열거형 타입으로, 특정 값의 집합으로 정의할 수 있습니다.
- struct: 구조체 타입으로, 여러 변수를 묶어서 사용할 수 있습니다.
- union: 공용체 타입으로, 여러 변수를 하나의 메모리 공간에 할당할 수 있습니다.
module data_types_example;
// 기본 데이터 타입
bit a;
logic b;
reg c;
int d;
byte e;
// 사용자 정의 데이터 타입
typedef enum {RED, GREEN, BLUE} color_t;
color_t my_color;
typedef struct {
int id;
string name;
} person_t;
person_t person;
typedef union {
int i;
byte b[4];
} data_t;
data_t data;
initial begin
// 기본 데이터 타입 할당
a = 1;
b = '0;
c = 1'bx;
d = -12345;
e = 8'hFF;
// 사용자 정의 데이터 타입 할당
my_color = RED;
person = '{id: 1, name: "Alice"};
data.i = 32'hAABBCCDD;
// 출력
$display("a = %b, b = %b, c = %b, d = %d, e = %h", a, b, c, d, e);
$display("my_color = %0d", my_color);
$display("person.id = %0d, person.name = %s", person.id, person.name);
$display("data.i = %h, data.b = %h %h %h %h", data.i, data.b[3], data.b[2], data.b[1], data.b[0]);
end
endmodule
3. Module, Interface, Package
Module :
SystemVerilog에서 모듈은 설계의 기본단위 입니다. 모듈은 입력, 출력, 내부 신호등을 포함하여, 다른 모듈을 인스턴스화할 수 있습니다.
module simple_module(input logic a, b, output logic c);
assign c = a & b;
endmodule
module top_module;
logic a, b, c;
// 모듈 인스턴스화
simple_module u1 (.a(a), .b(b), .c(c));
initial begin
a = 1;
b = 0;
#10;
$display("c = %b", c);
end
endmodule
Interface:
Interface는 모듈 간의 신호 연결을 정의하고 관리 할 수 있는 방법 입니다.
interface simple_if;
logic a, b, c;
endinterface
module simple_module(input simple_if intf);
assign intf.c = intf.a & intf.b;
endmodule
module top_module;
simple_if intf();
// 모듈 인스턴스화
simple_module u1 (.intf(intf));
initial begin
intf.a = 1;
intf.b = 0;
#10;
$display("c = %b", intf.c);
end
endmodule
Package:
Package는 여러 module에서 공통적으로 사용할 수 있는 상수, 타입, 함수 등을 정의하는데 사용됩니다.
package my_pkg;
typedef enum {RED, GREEN, BLUE} color_t;
function void print_color(color_t color);
$display("Color: %0d", color);
endfunction
endpackage
module top_module;
import my_pkg::*;
initial begin
color_t my_color = RED;
print_color(my_color);
end
endmodule
4. 절차적 프로그래밍 (tasks, functions)
tasks & functions:
SystemVerilog에서 task와 function은 절차적 프로그래밍을 위해 사용됩니다.
function을 값을 반환하고, task는 반환하지 않습니다.
module tasks_functions_example;
function int add(int a, int b);
return a + b;
endfunction
task display_sum(int a, int b);
$display("Sum: %0d", add(a, b));
endtask
initial begin
int x = 10;
int y = 20;
display_sum(x, y);
end
endmodule
5. Class와 OOP
SystemVerilog는 객체 지향 프로그래밍을 지원하여 복잡한 설계와 검증을 더욱 효율적으로 할 수 있습니다. Class를 사용하여 데이터의 기능을 캡슐화하고 재사용할 수 있습니다.
class MyClass;
int a;
function new(int a);
this.a = a;
endfunction
function void display();
$display("a = %0d", a);
endfunction
endclass
module top_module;
initial begin
MyClass obj = new(10);
obj.display();
end
endmodule
'HW > SystemVerilog' 카테고리의 다른 글
[SystemVerilog] Data tpye and Module design (0) | 2024.05.25 |
---|---|
SystemVerilog 및 UVM 공부 계획 (0) | 2024.05.25 |
[SystemVerilog]Verification Guidelines (0) | 2024.04.21 |