




Preview text:
SystemVerilog Complete Reference Algo Science Lab
Complete SystemVerilog Reference Guide
Comprehensive Coverage with Examples
Author: Shahrear Hossain Shawon Algo Science Lab 1 Data Types 11
// A s s o c i a t i v e a r r a y 12
int a s s o c _ a r r [ s t r i n g ]; 1.1 Logic and Bit Types 13
SystemVerilog provides 4-state (0,1,X,Z) and 2-state14 // Queue 15 int q u e u e [ $ ];
(0,1) data types for hardware modeling. 16
q u e u e . p u s h _ b a c k (5) ; 1 // 4 - s t a t e t y p e s 2 l o g i c [ 7 : 0 ] d a t a ; // 8 - bit 3
l o g i c s i g n e d [ 1 5 : 0 ] s ; // s i g n e d 2 Modules and Interfaces 4
reg [ 3 : 0 ] o l d _ s t y l e ; // l e g a c y 5 2.1 Module with Parameters 6 // 2 - s t a t e t y p e s
Modules are the basic building blocks with optional pa- 7
bit [ 7 : 0 ] f a s t _ d a t a ;
// f a s t e r s i m u l a t i o n 8
b y t e s i g n e d _ b y t e ; // 8 - bit s i g n e d rameters for configurability. 9 s h o r t i n t si ; // 16 - bit s i g n e d 10 int i ; // 32 - bit s i g n e d 1 m o d u l e a d d e r #( 11 l o n g i n t li ; // 64 - bit s i g n e d 2
p a r a m e t e r W I D T H = 8 3 ) ( 4 i n p u t
l o g i c [ WIDTH - 1 : 0 ] a , b , 1.2 Enumerated Types 5 i n p u t l o g i c cin ,
Enumerations provide named values for better readabil- 6
o u t p u t l o g i c [ WIDTH - 1 : 0 ] sum , ity and type safety. 7 o u t p u t l o g i c c o u t 8 ) ; 9
a s s i g n { cout , sum } = a + b + cin ; 1
t y p e d e f e n u m l o g i c [ 1 : 0 ] { 10 e n d m o d u l e 2 I D L E = 2 ’ b00 , 3 R E A D = 2 ’ b01 , 4 W R I T E = 2 ’ b10 , 2.2 Interface 5 E R R O R = 2 ’ b11 6 } s t a t e _ t ;
Interfaces encapsulate communication signals between 7 modules. 8
s t a t e _ t c u r r e n t _ s t a t e , n e x t _ s t a t e ; 1
i n t e r f a c e a x i _ i f #( 1.3 Structures and Unions 2
p a r a m e t e r A D D R _ W I D T H = 32 ,
Structures group related data, unions save space by 3
p a r a m e t e r D A T A _ W I D T H = 32 4 ) ( overlapping members. 5
i n p u t l o g i c clk , r s t _ n 6 ) ; 1 // S t r u c t u r e 7
l o g i c [ A D D R _ W I D T H - 1 : 0 ] a w a d d r ; 2
t y p e d e f s t r u c t p a c k e d { 8
l o g i c awvalid , a w r e a d y ; 3
l o g i c [ 7 : 0 ] o p c o d e ; 9
l o g i c [ D A T A _ W I D T H - 1 : 0 ] w d a t a ; 4
l o g i c [ 1 5 : 0 ] a d d r ; 10
l o g i c wvalid , w r e a d y ; 5
l o g i c [ 3 1 : 0 ] d a t a ; 11 6 } i n s t r u c t i o n _ t ; 12 m o d p o r t m a s t e r ( 7 13
o u t p u t awaddr , awvalid , wdata , wvalid , 8
i n s t r u c t i o n _ t i n s t r ; 14 i n p u t awready , w r e a d y 9 15 ) ; 10 // U n i o n 16 11
t y p e d e f u n i o n p a c k e d { 17 m o d p o r t s l a v e ( 12
l o g i c [ 3 1 : 0 ] w o r d ; 18 i n p u t
awaddr , awvalid , wdata , wvalid , 13
l o g i c [ 1 5 : 0 ] h a l f [ 2 ] ; 19
o u t p u t awready , w r e a d y 14
l o g i c [ 7 : 0 ] b y t e [ 4 ] ; 20 ) ; 15 } d a t a _ u ; 21 e n d i n t e r f a c e 1.4 Arrays 2.3 Module with Interface
SystemVerilog supports packed, unpacked, dynamic, associative, and queue arrays. 1
m o d u l e a x i _ m a s t e r ( 1 // P a c k e d a r r a y 2 a x i _ i f . m a s t e r bus 2
l o g i c [ 7 : 0 ] [ 3 : 0 ] p a c k e d _ a r r ; 3 ) ; 3 4
a l w a y s _ f f @ ( p o s e d g e bus . clk ) b e g i n 4 // U n p a c k e d a r r a y 5 if (! bus . r s t _ n ) 5
l o g i c [ 7 : 0 ] mem [ 0 : 2 5 5 ] ; 6 bus . a w v a l i d <= 0; 6 7
e l s e if ( bus . a w r e a d y ) 7 // D y n a m i c a r r a y 8 bus . a w v a l i d <= 1; 8 int d y n _ a r r []; 9 end 9
i n i t i a l d y n _ a r r = new [ 1 0 ] ; 10 e n d m o d u l e 10 1
SystemVerilog Complete Reference Algo Science Lab 3 Sequential Logic 16 end 17 e n d m o d u l e 3.1 Always FF Blocks
Use always ff for synthesizable sequential logic. 5 State Machines 1 m o d u l e dff ( 5.1 FSM with Enum 2 i n p u t l o g i c clk , rst_n , 3 i n p u t l o g i c d ,
Finite state machines are fundamental in digital design. 4 o u t p u t l o g i c q 5 ) ; 1 m o d u l e fsm ( 6
a l w a y s _ f f @ ( p o s e d g e clk or n e g e d g e r s t _ n ) 2 i n p u t l o g i c clk , rst_n , b e g i n 3 i n p u t l o g i c start , done , 7 if (! r s t _ n ) 4 o u t p u t l o g i c b u s y 8 q <= 1 ’ b0 ; 5 ) ; 9 e l s e 6
t y p e d e f e n u m l o g i c [ 1 : 0 ] { 10 q <= d ; 7
IDLE , ACTIVE , WAIT , C O M P L E T E 11 end 8 } s t a t e _ t ; 12 e n d m o d u l e 9 10
s t a t e _ t state , n e x t ; 3.2 Counter Example 11 12 // S t a t e r e g i s t e r 13
a l w a y s _ f f @ ( p o s e d g e clk or n e g e d g e r s t _ n ) 1 m o d u l e c o u n t e r #( b e g i n 2
p a r a m e t e r W I D T H = 8 14 if (! r s t _ n ) 3 ) ( 15 s t a t e <= I D L E ; 4 i n p u t l o g i c clk , rst_n , en , 16 e l s e 5
o u t p u t l o g i c [ WIDTH - 1 : 0 ] c o u n t 17 s t a t e <= n e x t ; 6 ) ; 18 end 7
a l w a y s _ f f @ ( p o s e d g e clk or n e g e d g e r s t _ n ) 19 b e g i n 20 // N e x t s t a t e l o g i c 8 if (! r s t _ n ) 21
a l w a y s _ c o m b b e g i n 9 c o u n t <= ’0; 22 n e x t = s t a t e ; 10 e l s e if ( en ) 23 c a s e ( s t a t e ) 11 c o u n t <= c o u n t + 1; 24
I D L E : if ( s t a r t ) n e x t = A C T I V E ; 12 end 25
A C T I V E : n e x t = W A I T ; 13 e n d m o d u l e 26
W A I T : if ( d o n e ) n e x t = C O M P L E T E ; 27
C O M P L E T E : n e x t = I D L E ; 4 Combinational Logic 28 e n d c a s e 29 end 4.1 Always Comb Blocks 30 31 // O u t p u t l o g i c
Use always comb for combinational logic. 32
a s s i g n b u s y = ( s t a t e != I D L E ) ; 33 e n d m o d u l e 1 m o d u l e m u x 4 t o 1 ( 2 i n p u t l o g i c [ 1 : 0 ] sel , 3 i n p u t l o g i c [ 3 : 0 ] in , 6 Functions and Tasks 4 o u t p u t l o g i c out 5 ) ; 6.1 Functions 6
a l w a y s _ c o m b b e g i n 7 c a s e ( sel )
Functions return a single value and execute in zero sim- 8 2 ’ b00 : out = in [ 0 ] ; ulation time. 9 2 ’ b01 : out = in [ 1 ] ; 10 2 ’ b10 : out = in [ 2 ] ; 1
f u n c t i o n a u t o m a t i c int p a r i t y ( 11 2 ’ b11 : out = in [ 3 ] ; 2
i n p u t l o g i c [ 7 : 0 ] d a t a 12 e n d c a s e 3 ) ; 13 end 4
p a r i t y = ^ d a t a ; // XOR r e d u c t i o n 14 e n d m o d u l e 5 e n d f u n c t i o n 6 7
f u n c t i o n a u t o m a t i c l o g i c [ 7 : 0 ] r e v e r s e ( 4.2 Priority and Unique 8
i n p u t l o g i c [ 7 : 0 ] in
priority and unique provide synthesis and simulation 9 ) ; checks. 10 for ( int i =0; i <8; i ++) 11
r e v e r s e [ i ] = in [7 - i ]; 1 m o d u l e d e c o d e r ( 12 e n d f u n c t i o n 2 i n p u t l o g i c [ 2 : 0 ] in , 3
o u t p u t l o g i c [ 7 : 0 ] out 6.2 Tasks 4 ) ; 5
a l w a y s _ c o m b b e g i n
Tasks can have multiple outputs and consume simula- 6 u n i q u e c a s e ( in ) tion time. 7
3 ’ d0 : out = 8 ’ b 0 0 0 0 0 0 0 1 ; 8
3 ’ d1 : out = 8 ’ b 0 0 0 0 0 0 1 0 ; 1
t a s k a u t o m a t i c r e a d _ m e m ( 9
3 ’ d2 : out = 8 ’ b 0 0 0 0 0 1 0 0 ; 2 i n p u t l o g i c [ 7 : 0 ] addr , 10
3 ’ d3 : out = 8 ’ b 0 0 0 0 1 0 0 0 ; 3
o u t p u t l o g i c [ 3 1 : 0 ] data , 11
3 ’ d4 : out = 8 ’ b 0 0 0 1 0 0 0 0 ; 4 ref l o g i c [ 3 1 : 0 ] mem [] 12
3 ’ d5 : out = 8 ’ b 0 0 1 0 0 0 0 0 ; 5 ) ; 13
3 ’ d6 : out = 8 ’ b 0 1 0 0 0 0 0 0 ; 6 #10 d a t a = mem [ a d d r ]; 14
3 ’ d7 : out = 8 ’ b 1 0 0 0 0 0 0 0 ; 7 e n d t a s k 15 e n d c a s e 8 2
SystemVerilog Complete Reference Algo Science Lab 9
t a s k a u t o m a t i c w r i t e _ m e m ( 18 10
i n p u t l o g i c [ 7 : 0 ] addr , 19
f u n c t i o n v o i d d i s p l a y () ; 11
i n p u t l o g i c [ 3 1 : 0 ] data , 20
$display (" Addr =%h Data =%h Type =%b", 12 ref l o g i c [ 3 1 : 0 ] mem [] 21 addr , data , p t y p e ) ; 13 ) ; 22 e n d f u n c t i o n 14
#10 mem [ a d d r ] = d a t a ; 23 e n d c l a s s 15 e n d t a s k 24 25 m o d u l e t e s t ; 26 i n i t i a l b e g i n 7 Assertions 27 p a c k e t pkt = new () ; 28 r e p e a t (5) b e g i n 7.1 Immediate Assertions 29
a s s e r t ( pkt . r a n d o m i z e () ) ;
Checked immediately like a procedural statement. 30 pkt . d i s p l a y () ; 31 end 1
m o d u l e a s s e r t _ e x a m p l e ( 32 end 2
i n p u t l o g i c clk , rst_n , 33 e n d m o d u l e 3 i n p u t l o g i c req , gnt 4 ) ; 9 Coverage 5
// I m m e d i a t e a s s e r t i o n 6
a l w a y s _ c o m b b e g i n 9.1 Covergroups 7
a s s e r t (!( req && ! gnt ) || gnt ) 8
e l s e $error ( " Grant without request " ) ;
Functional coverage to track test completeness. 9 end 10 e n d m o d u l e 1
m o d u l e c o v e r a g e _ e x a m p l e ( 2 i n p u t l o g i c clk , 3
i n p u t l o g i c [ 2 : 0 ] opcode , 7.2 Concurrent Assertions 4
i n p u t l o g i c [ 7 : 0 ] d a t a
Checked based on clock edges, using sequences and 5 ); properties. 6
c o v e r g r o u p cg @ ( p o s e d g e clk ) ; 7
c p _ o p c o d e : c o v e r p o i n t o p c o d e { 1
m o d u l e s v a _ e x a m p l e ( 8
b i n s add = {3 ’ b 0 0 0 }; 2
i n p u t l o g i c clk , rst_n , 9
b i n s sub = {3 ’ b 0 0 1 }; 3
i n p u t l o g i c req , gnt , d o n e 10
b i n s mul = {3 ’ b 0 1 0 }; 4 ) ; 11
b i n s div = {3 ’ b 0 1 1 }; 5
// P r o p e r t y : g r a n t f o l l o w s r e q u e s t 12
b i n s o t h e r s = d e f a u l t ; 6
p r o p e r t y p _ r e q _ g n t ; 13 } 7
@ ( p o s e d g e clk ) d i s a b l e iff (! r s t _ n ) 14 8
req | - > # # [ 1 : 3 ] gnt ; 15
c p _ d a t a : c o v e r p o i n t d a t a { 9 e n d p r o p e r t y 16
b i n s low = { [ 0 : 6 3 ] } ; 10 17
b i n s mid = { [ 6 4 : 1 9 1 ] } ; 11
a s s e r t p r o p e r t y ( p _ r e q _ g n t ) 18
b i n s h i g h = { [ 1 9 2 : 2 5 5 ] } ; 12
e l s e $error ( " Grant not received " ) ; 19 } 13 20 14
// S e q u e n c e : d o n e a f t e r g r a n t 21
c r o s s _ o p _ d a t a : c r o s s c p _ o p c o d e , c p _ d a t a ; 15
s e q u e n c e s _ g n t _ d o n e ; 16 gnt # # [ 1 : 5 ] d o n e ; 22 e n d g r o u p 17 e n d s e q u e n c e 23 18 24 cg c g _ i n s t = new () ; 19 a s s e r t p r o p e r t y ( 25 e n d m o d u l e 20
@ ( p o s e d g e clk ) d i s a b l e iff (! r s t _ n ) 21
gnt | - > s _ g n t _ d o n e 10 Clocking Blocks 22 ) ; 23 e n d m o d u l e 10.1 Synchronous Testbench
Clocking blocks provide synchronous drive and sample 8 Constrained Random timing. 8.1 Classes with Constraints 1
i n t e r f a c e b u s _ i f ( i n p u t l o g i c clk ) ;
Object-oriented features for verification. 2 l o g i c [ 7 : 0 ] d a t a ; 3 l o g i c valid , r e a d y ; 1 c l a s s p a c k e t ; 4 2
r a n d bit [ 7 : 0 ] a d d r ; 5
c l o c k i n g cb @ ( p o s e d g e clk ) ; 3
r a n d bit [ 1 5 : 0 ] d a t a ; 6
d e f a u l t i n p u t #1 s t e p o u t p u t #2; 4
r a n d bit [ 1 : 0 ] p t y p e ; 7 o u t p u t data , v a l i d ; 5 8 i n p u t r e a d y ; 6
c o n s t r a i n t c _ a d d r { 9 e n d c l o c k i n g 7
a d d r i n s i d e {[8 ’ h00 :8 ’ h7F ]}; 10 8 } 11
m o d p o r t TB ( c l o c k i n g cb ) ; 9 12 e n d i n t e r f a c e 10
c o n s t r a i n t c _ t y p e { 13 11 p t y p e d i s t { 14
p r o g r a m t e s t ( b u s _ i f . TB bus ) ; 12 2 ’ b00 := 40 , 15 i n i t i a l b e g i n 13 2 ’ b01 := 30 , 16
bus . cb . d a t a <= 8 ’ hAA ; 14 2 ’ b10 := 20 , 17 bus . cb . v a l i d <= 1; 15 2 ’ b11 := 10 18 @ ( bus . cb ) ; 16 }; 19
w a i t ( bus . cb . r e a d y == 1) ; 17 } 20 end 3
SystemVerilog Complete Reference Algo Science Lab 21 e n d p r o g r a m 11 12
i n i t i a l b e g i n // C o n s u m e r 13 int d a t a ; 11 Virtual Interfaces 14 r e p e a t ( 1 0 ) b e g i n 15 mbx . get ( d a t a ) ; 11.1 Polymorphism in Verification 16
$display (" Received : %0d", data );
Virtual interfaces enable dynamic interface binding. 17 end 18 end 1 c l a s s d r i v e r ; 19 e n d m o d u l e 2
v i r t u a l b u s _ i f vif ; 3 13.2 Semaphore 4
f u n c t i o n new ( v i r t u a l b u s _ i f vif ) ; 5 t h i s . vif = vif ; 6 e n d f u n c t i o n 1
m o d u l e s e m a p h o r e _ e x a m p l e ; 7 2
s e m a p h o r e sem = new (1) ; 8 t a s k run () ; 3 9 f o r e v e r b e g i n 4
t a s k a c c e s s _ r e s o u r c e ( int id ) ; 10 @ ( vif . cb ) ; 5 sem . get () ; 11
vif . cb . d a t a <= $random ; 6
$display (" Task %0d accessing ", id); 12 vif . cb . v a l i d <= 1; 7 # 2 0 ; 13 @ ( vif . cb ) ; 8
$display (" Task %0d done ", id); 14 vif . cb . v a l i d <= 0; 9 sem . put () ; 15 end 10 e n d t a s k 16 e n d t a s k 11 17 e n d c l a s s 12 i n i t i a l f o r k 18 13
a c c e s s _ r e s o u r c e (1) ; 19 m o d u l e top ; 14
a c c e s s _ r e s o u r c e (2) ; 20 l o g i c clk ; 15 j o i n 21 b u s _ i f bus ( clk ) ; 16 e n d m o d u l e 22 23 i n i t i a l b e g i n 24
d r i v e r drv = new ( bus ) ; 14 DPI (Direct Programming Inter- 25 f o r k face) 26 drv . run () ; 27 j o i n _ n o n e 14.1 Importing C Functions 28 end 29 e n d m o d u l e 1 // C f u n c t i o n 2
i m p o r t " DPI - C " f u n c t i o n int c _ a d d ( 12 Parameterized Classes 3
i n p u t int a , i n p u t int b 4 ) ; 12.1 Generic Components 5 6 m o d u l e d p i _ t e s t ; 7 i n i t i a l b e g i n 1
c l a s s q u e u e #( t y p e T = int ) ; 8 int r e s u l t ; 2 T i t e m s [ $ ]; 9
r e s u l t = c _ a d d (5 , 3) ; 3 10
$display (" Result = %0d", result ); 4
f u n c t i o n v o i d p u s h ( T i t e m ) ; 11 end 5
i t e m s . p u s h _ b a c k ( i t e m ) ; 12 e n d m o d u l e 6 e n d f u n c t i o n 7 8 f u n c t i o n T pop () ; 15 Advanced Memory Modeling 9
r e t u r n i t e m s . p o p _ f r o n t () ; 10 e n d f u n c t i o n 15.1 Associative Array with Methods 11 12
f u n c t i o n int s i z e () ; 13
r e t u r n i t e m s . s i z e () ; 1
m o d u l e m e m _ m o d e l ; 14 e n d f u n c t i o n 2 int mem [ bit [ 1 5 : 0 ] ] ; 15 e n d c l a s s 3 16 4 i n i t i a l b e g i n 17 // U s a g e 5
mem [16 ’ h 0 0 0 0 ] = 32 ’ h D E A D B E E F ; 18
q u e u e #( int ) i n t _ q = new () ; 6
mem [16 ’ h 0 1 0 0 ] = 32 ’ h C A F E B A B E ; 19
q u e u e #( b y t e ) b y t e _ q = new () ; 7 8 // I t e r a t e 9
f o r e a c h ( mem [ a d d r ]) b e g i n 13 Interprocess Communication 10
$display (" Addr =%h Data =%h", 11 addr , mem [ a d d r ]) ; 13.1 Mailbox 12 end 13 1
m o d u l e i p c _ e x a m p l e ; 14 // C h e c k e x i s t e n c e 2
m a i l b o x #( int ) mbx = new () ; 15
if ( mem . e x i s t s (16 ’ h 0 0 0 0 ) ) 3 16 $display (" Address exists "); 4
i n i t i a l b e g i n // P r o d u c e r 17 5
for ( int i =0; i < 1 0 ; i ++) b e g i n 18 // D e l e t e 6 mbx . put ( i ) ; 19
mem . d e l e t e (16 ’ h 0 0 0 0 ) ; 7 $display (" Sent : %0d", i); 20
$display (" Size : %0d", mem . size ()); 8 # 1 0 ; 21 end 9 end 22 e n d m o d u l e 10 end 4
SystemVerilog Complete Reference Algo Science Lab 16 Practical Examples 18 s t a t e _ t s t a t e ; 19
l o g i c [ 7 : 0 ] t x _ d a t a ; 16.1 FIFO Design 20
l o g i c [ $clog2 ( C L K S _ P E R _ B I T ) -1:0] clk_cnt ; 21
l o g i c [ 2 : 0 ] b i t _ c n t ; 1 m o d u l e f i f o #( 22 2
p a r a m e t e r D E P T H = 16 , 23
a s s i g n b u s y = ( s t a t e != I D L E ) ; 3
p a r a m e t e r W I D T H = 8 24 4 ) ( 25
a l w a y s _ f f @ ( p o s e d g e clk or n e g e d g e r s t _ n ) 5 i n p u t l o g i c clk , rst_n , b e g i n 6 i n p u t l o g i c wr_en , rd_en , 26 if (! r s t _ n ) b e g i n 7 i n p u t
l o g i c [ WIDTH - 1 : 0 ] wr_data , 27 s t a t e <= I D L E ; 8
o u t p u t l o g i c [ WIDTH - 1 : 0 ] rd_data , 28 tx <= 1; 9
o u t p u t l o g i c full , e m p t y 29 c l k _ c n t <= 0; 10 ) ; 30 b i t _ c n t <= 0; 11
l o g i c [ WIDTH - 1 : 0 ] mem [ D E P T H ]; 31 end e l s e b e g i n 12
l o g i c [ $clog2 ( DEPTH ) :0] wr_ptr , rd_ptr ; 32 c a s e ( s t a t e ) 13 33 I D L E : b e g i n 14
a s s i g n f u l l = ( w r _ p t r [ $clog2 ( DEPTH ) ] != 34 tx <= 1; 15
r d _ p t r [ $clog2 ( DEPTH ) ]) && 35 if ( s t a r t ) b e g i n 16
( w r _ p t r [ $clog2 ( DEPTH ) -1:0] 36 t x _ d a t a <= d a t a ; == 37 s t a t e <= S T A R T ; 17
r d _ p t r [ $clog2 ( DEPTH ) -1:0]) ; 38 c l k _ c n t <= 0; 18
a s s i g n e m p t y = ( w r _ p t r == r d _ p t r ) ; 39 end 19 40 end 20
a l w a y s _ f f @ ( p o s e d g e clk or n e g e d g e r s t _ n ) 41 b e g i n 42 S T A R T : b e g i n 21 if (! r s t _ n ) b e g i n 43 tx <= 0; 22 w r _ p t r <= ’0; 44 if ( c l k _ c n t == 23 r d _ p t r <= ’0;
C L K S _ P E R _ B I T -1) b e g i n 24 end e l s e b e g i n 45 s t a t e <= D A T A ; 25
if ( w r _ e n && ! f u l l ) 46 c l k _ c n t <= 0; 26 w r _ p t r <= w r _ p t r + 1; 47 b i t _ c n t <= 0; 27
if ( r d _ e n && ! e m p t y ) 48 end e l s e 28 r d _ p t r <= r d _ p t r + 1; 49 c l k _ c n t <= c l k _ c n t + 29 end 1; 30 end 50 end 31 51 32
a l w a y s _ f f @ ( p o s e d g e clk ) b e g i n 52 D A T A : b e g i n 33
if ( w r _ e n && ! f u l l ) 53
tx <= t x _ d a t a [ b i t _ c n t ]; 34
mem [ w r _ p t r [ $clog2 ( DEPTH ) -1:0]] <= 54 if ( c l k _ c n t == 35 w r _ d a t a ;
C L K S _ P E R _ B I T -1) b e g i n 36 end 55 c l k _ c n t <= 0; 37 56 if ( b i t _ c n t == 7) 38 a s s i g n r d _ d a t a = 57 s t a t e <= S T O P ; 39
mem [ r d _ p t r [ $clog2 ( DEPTH ) -1:0]]; 58 e l s e 40 e n d m o d u l e 59 b i t _ c n t <= b i t _ c n t + 1; 16.2 UART Transmitter 60 end e l s e 61 c l k _ c n t <= c l k _ c n t + 1; 1 m o d u l e u a r t _ t x #( 62 end 2
p a r a m e t e r C L K _ F R E Q = 50 _ 0 0 0 _ 0 0 0 , 63 3
p a r a m e t e r B A U D _ R A T E = 1 1 5 2 0 0 64 S T O P : b e g i n 4 ) ( 65 tx <= 1; 5 i n p u t l o g i c clk , rst_n , 66 if ( c l k _ c n t == 6 i n p u t l o g i c [ 7 : 0 ] data , C L K S _ P E R _ B I T -1) 7 i n p u t l o g i c start , 67 s t a t e <= I D L E ; 8 o u t p u t l o g i c tx , 68 e l s e 9 o u t p u t l o g i c b u s y 69 c l k _ c n t <= c l k _ c n t + 10 ) ; 1; 11
l o c a l p a r a m C L K S _ P E R _ B I T = 70 end 12
C L K _ F R E Q / B A U D _ R A T E ; 71 e n d c a s e 13 72 end 14
t y p e d e f e n u m l o g i c [ 2 : 0 ] { 73 end 15 IDLE , START , DATA , S T O P 74 e n d m o d u l e 16 } s t a t e _ t ; 17 Conclusion
This reference covers the essential SystemVerilog constructs for both RTL design and verification. SystemVerilog
combines the best of Verilog with modern programming concepts, making it the industry standard for digital design and verification.
Algo Science Lab - SystemVerilog Reference v1.0
Author: Shahrear Hossain Shawon 5