Verilog HDL
2007/06/13 13:35
http://blog.naver.com/PostPrint.nhn?blogId=babojay&logNo=40038683067#
Chapter3
Basic Concepts
±âº»ÀûÀÎ ±¸Á¶¿Í ¹®¹ý±ÔÄ¢¿¡ ´ëÇؼ ¾Ë¾Æº»´Ù.
*Objectives
- ¹®¹ý±ÔÄ¢ (Operator,
comment, whitespace, number, string, identifier)
- Logic value
& data type ( net, register, vector, number, simulation time, array,
parameter, memory, string
- System task ( $display, $monitor,
$stop, $finish ..)
- Compile directives ('define, 'include
..)
3.1 Lexical Conventions
Verilog´Â C ÇÁ·Î±×·¡¹Ö°ú ¸Å¿ì À¯»çÇÏ´Ù. ¸ðµç ¿¹¾à¾î´Â ¼Ò¹®ÀÚ·Î ¾´´Ù.
3.1.1 Whitespace : \b, \t, \nµî
3.1.2 Comment : //, /*, */ C¿Í °°´Ù.
3.1.3 Operator
- Unary :
a =
~b;
- Binary : a = b &&
c;
- Ternary : a
= b ? c : d;
3.1.4 Number Specification
-
Sized number
ex) 4'b1111 : 4-bit ÀÌÁø¼ö
1111
12'habc : 12-bit 16Áø¼ö abc ->
1010_1011_1100
16'd255
: 16-bit 10Áø¼ö 255 -> 0000_0000_1111_1111
- Unsized number : Å©±â¸¦ Á¤ÇÏÁö ¾ÊÀº ¼ö·Î ÄÄÆÄÀÏ·¯³ª ½Ã¹Ä·¹ÀÌÅÍ¿¡ µû¶ó ´Ù¸£Áö¸¸ º¸Åë 32bitÀÌ´Ù.
ex) 'd235 : 32-bit 10Áø¼ö
235
24535 : 32-bit 10Áø¼ö 24535 ('d, 'D´Â »ý·«µÉ ¼ö
ÀÖ´Ù.)
'hc3 : 32-bit 16Áø¼ö c3
- Unknown (x), High Impedance (z)
12'h13x ->
0001_0011_xxxx
6'hx -> xx_xxxx
9'o36z ->011_110_zzz
- Negative number :À½¼ö¸¦
³ªÅ¸³½´Ù.
6'd3 -> -6'd3
- Underscore & ?
12'b1111_0000_1010 Àбâ ÆíÇϵµ·Ï '_'¸¦
³Ö¾îÁØ´Ù.
4'b10?? -> 4'b10zz¿Í µ¿ÀÏ ÇÏ´Ù.
3.1.5 Strings
Å« µû¿ÈÇ¥(")·Î µÑ·¯ ½×ÀÎ ÇÑ Á٠¥¸® ¹®ÀÚ¿À»
ÀǹÌÇÑ´Ù. StringÀÇ °¢ ¹®ÀÚ´Â 8 bit ASCIIÀÇ °ª¿¡ ÇØ´çÇÑ´Ù.
3.1.6 Identifier & Keyword
- keyword : ¼Ò¹®Àڷθ¸ »ç¿ë
-
identifier : ´ë¼Ò¹®ÀÚ ±¸º°ÇÑ´Ù. a~z, A~Z, 0~9, $, _ »ç¿ë
3.1.7 Escaped identifier
- \(backslash)·Î
½ÃÀÛÇÏ´Â identifier
3.2 Data Type
3.2.1 Value Set
- Strength level : ½ÅÈ£µé °£ÀÇ Ãæµ¹ÀÌ ÀÖÀ» ¶§ ½ÅÈ£µéÀÇ ¼¼±â¿¡ µû¶ó¼ ±× °á°ú°¡ ´Þ¶óÁø´Ù. Value level '0', '1'Àº ´ÙÀ½ÀÇ Strength levelÀ» °®´Â´Ù.
* Ãæµ¹ÇÏ´Â µÎ ½ÅÈ£ Áß °ÇÑ ½ÅÈ£ÂÊÀ¸·Î °áÁ¤µÇ¸ç, ¼¼±âÀÇ °°´Ù¸é °á°ú´Â 'X'(unknown)ÀÌ µÈ´Ù.
** Large, Medium, Small µîÀº trireg, net¿¡¼¸¸ °®À» ¼ö ÀÖ´Â Strength levelÀÌ´Ù.
3.3.3 Nets
- Net : H/W ¿ä¼Òµé °£ÀÇ ¿¬°áÀ» ÀǹÌÇÑ´Ù. ¼ÒÀÚ¿¡¼ Áö¼ÓÀûÀ¸·Î »óŸ¦ ³»º¸³»´Â Ãâ·ÂÀ» °®´Â´Ù.
-
wire : NetÀ» Á¤ÀÇÇÏ´Â Keyword. Á¤ÀÇÇÏÁö ¾ÊÀº netÀÇ ±âº» value´Â
'z'ÀÌ´Ù.
ex)
wire
a;
wire a, b;
wire d =
1'b0;
3.2.3 Registers
- Register : ´Ù¸¥ °ªÀ¸·Î ´ëüµÉ ¶§±îÁö °ªÀ» À¯ÁöÇÏ´Â µ¥ÀÌÅÍ ÀúÀå¼ÒÀÌ´Ù. ½ÇÁ¦È¸·ÎÀÇ register(F/F, Latch µî)¿Í´Â ´Ù¸¥ °³³äÀÌ´Ù. ClockÀÌ ÇÊ¿äÇÏÁö ¾ÊÀ¸¸ç Driverµµ ÇÊ¿äÇÏÁö ¾Ê´Ù, ¾ðÁ¦µçÁö »õ·Î¿î °ªÀ» ³ÖÀ» ¼ö ÀÖ´Â º¯¼ö(Variable)ÀÇ °³³äÀÌ´Ù.
- reg : Register¸¦ Á¤ÀÇ ÇÏ´Â Keyword, Ãʱ⠱⺻°ªÀº 'x'ÀÌ´Ù.
ex)
reg
reset; // º¯¼ö resetÀ» ¼±¾ð
initial
begin
reset =
1'b1; // '1'·Î
ÃʱâÈ
#100 reset =
1'b0; // 100ÃÊ ÈÄ '0'À¸·Î º¯°æ
end
3.2.4 Vectors
- Vector : ´Ù¼öÀÇ NetÀ̳ª Reg¸¦ ´Ù¹ß·Î ¼±¾ðÇÑ´Ù.
ex)
wire[7:0]
bus;
reg[0:40] virtual_addr;
* º¤Åͼ±¾ð¿¡¼ ¾Õ¿¡ ¿À´Â ¼ýÀÚ°¡ MSB(Most Significant Bit)ÀÌ µÈ´Ù.
3.2.5 Integer, Real, Time Register Data Type
- Integer : Á¤¼ö ÀúÀå¿ë data typeÀ̸ç, signed intergerÀÌ´Ù.
cf.) reg : unsigned quantity
- Real : ½Ç¼ö ÀúÀå¿ë data typeÀ¸·Î ¼Ò¼öÁ¡Ç¥Çö(2.13)°ú Áö¼öÇü Ç¥Çö(4e10)ÀÌ
°¡´ÉÇÏ´Ù.
½Ç¼öÇü µ¥ÀÌÅ͸¦ Á¤¼öÇü¿¡ ÀúÀåÇÏ´Â °æ¿ì °¡Àå °¡±î¿î Á¤¼ö·Î ¹Ý¿Ã¸²µÈ´Ù.
ex)
real
delta;
initial
begin
delta =
4e10;
delta =
2.13;
end
integer i;
initial
i =
delta; // i = 2
- Time : ½Ã¹Ä·¹ÀÌ¼Ç Å¸ÀÓ ÀúÀå¿ë data typeÀÌ´Ù. ½Ã¹Ä·¹ÀÌ¼Ç ÃÊ(Simulation seconds)·Î¼ Ä«¿îÆ® µÇ¸ç, ±× ´ÜÀ§´Â ÃÊ(s)ÀÌ´Ù. ½Ã¹Ä·¹ÀÌ¼Ç ÃÊ¿Í Çö½Ç ½Ã°£(ÃÊ)¿ÍÀÇ °ü°è´Â ¼³°èÀÚ°¡ Á¤Çϱ⠳ª¸§ÀÌ´Ù.
time : ¼±¾ð
keyword, $time : ÇöÀç ½Ã¹Ä·¹ÀÌ¼Ç Å¸ÀÓÀ» return
ex)
time save_sim_time;
initial
save_sim_time =
$time; // ÇöÀç ½Ã¹Ä·¹ÀÌ¼Ç Å¸ÀÓÀ» save_sim_time¿¡ ÀúÀå
3.2.6 Arrays
- reg, integer, time, vector¿¡ »ç¿ëÇÏ¸ç ´ÙÂ÷¿ø ¹è¿À» Çã¿ëµÇÁö ¾Ê´Â´Ù.
ex)
integer
count[0:7]; //count[0] ... count[7],
8°³ÀÇ Á¤¼öÇü count
reg
bool[31:0]:
// 32°³ÀÇ 1-bit boolean register
time
chk_point[1:100];
reg [4:0] port_id [0:7]; // 8°³ÀÇ
5-bit port_id ·¹Áö½ºÅÍ
3.2.7 Memories
- Array¸¦ ÀÌ¿ëÇØ ½±°Ô Register file, RAM, ROM µîÀ» ±¸ÇöÇÒ ¼ö ÀÖ´Ù.
ex)
reg
membit[0:1023];
// 1KÀÇ 1-bit word
reg [7:0] membyte [0:1023] // 1KBÀÇ
¸Þ¸ð¸®
3.2.8 Parameters
- »ó¼ö¸¦ Á¤ÀÇ ÇÒ ¶§ »ç¿ëÇÑ´Ù. Compile°úÁ¤¿¡¼ »ç¿ëµÈ ÆĶó¸ÞÅ͵éÀ»
overrideÇÑ´Ù. º¯¼öó·³ »ç¿ëÇÒ ¼ö ¾ø´Ù.
3.2.9 Strings
- reg·Î Á¤ÀÇÇÏ¿© ÀúÀåÇÑ´Ù. ¿À¸¥ÂʺÎÅÍ Ã¤¿öÁö¸ç ³²´Â °ø°£Àº '0'À¸·Î ä¿öÁö°í ¸ðÀÚ¸£¸é ¿ÞÂÊÀÌ
À߸°´Ù.
ex)
reg
[8*18:1] string_value;
initial
string_value ; "Hello
Verilog World!"; // string_value = "llo Verilog World!"
3.3 System Tasks & Compiler Directives
3.3.1 System Tasks
- $display : ¹®ÀÚ¿À» Ãâ·Â, CÀÇ printf¿Í À¯»çÇÏ´Ù. ±âº»ÀûÀ¸·Î ¸¶Áö¸·¿¡
'\n'(newline)À» Ãâ·ÂÇÑ´Ù.
ex)
$display("Hello Verilog World");
-- Hello Verilog
World
$display($time);
-- 230
reg [0:40]
vertual_addr;
$display("At time %d virtual address is %h",
$time, vertual_addr);
-- At Time 200 virtual address is
1fe0000001c
reg[4:0]
port_id;
$display("ID of the port is %b",
port_id);
-- ID of the port is 00101
reg [3:0]
bus;
$display("Bus value is %b",
bus);
-- Bus value is 10xx
$display("This string
is diplayed from %m level of hierachy");
-- This string is
displayed from top.p1 level of hierachy
$display("This is a
\n multiline string with a %% sign");
-- This is
a
-- multiline string with a % sign
- $monitor : ½ÅÈ£ÀÇ º¯È¸¦ ¸ð´ÏÅÍ ÇÒ ¶§ »ç¿ëÇÑ´Ù, parameter ¸®½ºÆ®¿¡ ÀÖ´Â º¯¼ö³ª ½ÅÈ£ÀÇ »óÅ°¡ ¹Ù²ð¶§¸¶´Ù ½ÇÇàµÈ´Ù. Çѹø¿¡ ÇϳªÀÇ $monitor ¸¸ ½ÇÇàµÈ´Ù. ¿©·¯°³ÀÇ $monitor°¡ ÀÖ´Â °æ¿ì ¸Ç ¸¶Áö¸· °Í¸¸ÀÌ À¯È¿ÇÏ´Ù
- $monitoron, $monitoroff : ½Ã¹Ä·¹ÀÌ¼Ç Áß°£¿¡ $monitor¸¦ Á¦¾îÇÑ´Ù.
ex)
// clockÀº ¸Å
5¸¶´Ù ¹Ù²ñ, resetÀº 10¿¡¼ '1'¿¡¼ '0'·Î ¹Ù²ñ
initial
begin
$monitor($time, "Value of
signals clock = %b reset = %b", clock, reset);
end
-- 0 Value of signals
clock = 0 reset = 1
-- 5 Value of signals clock = 1 reset
= 1
-- 10 Value of signals clock = 0 reset =
0
-- 15 Value of signals clock = 1 reset =
0
:
- $stop : ½Ã¹Ä·¹À̼ÇÀ» ÁßÁöÇÏ°í interactive¸ðµå·Î ÀüȯÇÑ´Ù (debug °¡´É¸ðµå·Î)
-
$finish : ½Ã¹Ä·¹À̼ÇÀ» Á¾·áÇÑ´Ù.
3.3.2 Compiler Directives
- 'define : text macro. C¿¡¼ #difine°ú À¯»çÇÏ´Ù
ex)
'define WORD_SIZE
32
'define S
$stop
- 'include : ÄÄÆÄÀϽà ´Ù¸¥ verilog ÆÄÀÏ Àüü¸¦ Æ÷ÇÔ½ÃŲ´Ù. CÀÇ #include¿Í À¯»çÇÏ´Ù.
ex)
'include
header.v