Program Block - Examples
Example for Program Block
(a) Ethernet
(i) Example
//Example for program block for Ethernet packet
class Ethernet_field;
rand bit destination_address [47:0];
task fields();
if (destination_address[0] == 0)
begin
$display ("\n Identified the address is individual ");
end
else
$display ("\n Identified the address is group address ");
if (destination_address[1])
$display( "\n Identified the address is local address ");
else
$display("\n Identified the address is global address ");
endtask
endclass
program Ethernet_program;
Ethernet_field packet;
initial
begin
int destination_address[5:0];
packet = new;
repeat(2)
begin
packet.fields();
packet.randomize();
foreach (packet.destination_address[i]);
$display("\nThe value in DA = %h",packet.destination_address[i]);
end
end
endprogram
Output in VCS
Identified the address is individual
Identified the address is global address
The value in DA = 1
The value in DA = 1
The value in DA = 0
The value in DA = 1
The value in DA = 0
The value in DA = 1
Identified the address is group address
Identified the address is global address
The value in DA = 1
The value in DA = 0
The value in DA = 0
The value in DA = 0
The value in DA = 0
The value in DA = 1
(b) Sonet
(i) Example
class frame_start;
rand byte length = 64'habcdabc101023acd123;
rand byte tag_frame_ma;
byte Num;//octal number
integer Tx_en;
task frame();
begin
if ((length/Num) || (length > tag_frame_ma))
$display ("\nReport the Tag frame error length = %d",length);
else
$display("\nReport Tag frame %d",length);
end
endtask
endclass
program main();
frame_start new_frame;
integer transmission_enable = 0;// Transmission of frame. Frame Tx include data encapulation and Media Access Management
task transmit(integer transmission_enable);
if (transmission_enable)
$display("\n@%g, Frame is ready to transmit",$time);
else
$display("\n@%g, Frame is not ready now to transmit",$time);
endtask
initial
begin
new_frame = new;
$display("*******--------*********--------********--------********");
#1 transmit(transmission_enable);
#1 transmission_enable = 1;
#1 transmit(transmission_enable);
#1 new_frame.frame();
#1 new_frame.randomize();
#1 $display("\n@%g, Transmit next frame now...", $time);
#1 $display("\n*******--------*********--------********--------********");
end
endprogram
Output in VCS
*******--------*********--------********--------********
@1, Frame is not ready now to transmit
@3, Frame is ready to transmit
Report the Tag frame error length = 35
@6, Transmit next frame now...
*******--------*********--------********--------********
No comments:
Post a Comment