Friday, March 02, 2012

Processes - Examples

Processes - Examples

Example for Process

(a) Ethernet

(i) Example using always_comb

module always_combex();
parameter true =1'b1;
parameter false =1'b0;
reg receiveSucceeding;
reg receiving;
always_comb //illustrates the behavior of combinational logic
begin :ETHER
$display("\nfunction of link management\n");
receiveSucceeding = true;
receiving = false;
$display("receiveSucceeding=%0d\treceiving=%0d\n ",receiveSucceeding,receiving);
$display("1. when receiving is high : waits for frame to arrive, calculate excess bits and truncate to octet boundary after receiving frame\n");
$display("2. when receive succeeding is high and frame size is greater minframesize : reject collision\n");
$display("\n repeat the above two steps till receiveSucceeding is true\n");
end
endmodule

Output in VCS

function of link management
receiveSucceeding=1
receiving=0
1. when receiving is high : waits for frame to arrive, calculate excess bits and truncate to octet boundary after receiving frame
2. when receive succeeding is high and frame size is greater minframesize : reject collision
repeat the above two steps till receiveSucceeding is true
function of link management
receiveSucceeding=1
receiving=0
1. when receiving is high : waits for frame to arrive, calculate excess bits and truncate to octet boundary after receiving frame
2. when receive succeeding is high and frame size is greater minframesize : reject collision
repeat the above two steps till receiveSucceeding is true

(ii) Example using always_latch

//Example for always latch in Sonet

module always_lat();
parameter true =1'b1;
parameter false =1'b0;
parameter jamSize =6'b100000;
reg collisionDetect = 1,extendError = 0;
reg [5:0] interFrameTotal ;
reg bursting,interFrameCount ;
always_latch //for modelling latched logic behavior
begin : ADDER
if (collisionDetect && (!extendError)) //checking for collision detection signal
begin
bursting = false; //actions taken after collision detection and assigning values
extendError = true;
interFrameCount = 0;
interFrameTotal = jamSize;
$display("when there is a collision detection then:\n ") ;
$display("bursting=%0b\nextendError=%0b\ninterFrameCount=%0d\ninterFrameTotal=%0d",bursting,extendError,interFrameCount,interFrameTotal);
end
end
endmodule

Output in VCS

when there is a collision detection then:
bursting=0
extendError=1
interFrameCount=0
interFrameTotal=32


(iii) Example using fork_join

module fork_joinany_joinnone();
parameter true = 1'b1;
parameter false = 1'b0;
parameter headerSize = 7'b1000000; //header size is 64 bits
parameter slotTime = 10'b1000000000; //slot time is 512 bit times
parameter currentTransmitBit = 10'b1000000001 ; //assuming current transmit bit as 513

task automatic WatchForCollision;
reg transmitSucceeding= 1'd1,collisionDetect=1'd1,lateCollisionError,newCollision;
begin
if (transmitSucceeding && collisionDetect)
begin
if (currentTransmitBit > (slotTime - headerSize))
begin
lateCollisionError = true;
newCollision = true;
transmitSucceeding = false;
$display ("@%g lateCollisionError=%0d newCollision=%0d transmitSucceeding=%0d\n", $time, lateCollisionError,newCollision,transmitSucceeding);
end
end
end
endtask

initial
begin
$display ("inside fork join any block\n");
fork //comes to the statement after join_any,if any one of the process completes execution
begin
#(5);
$display ("@%g inside 1st block\n",$time); //comes out to the next statement if any one of the process is completed
#1 WatchForCollision;
end
begin
#(7);
$display ("@%g inside 2nd block\n",$time);
#2 $display( "inside fork block:block2\n");
end
begin
#(6);
$display ("@%g inside 3rd block\n",$time);
#4 WatchForCollision;
end
join_any
#8 $finish;
#4 $display ("\noutside process join any block\n");
end

initial
begin
#10 $display ("inside fork joinnone block\n");
fork //fork join_none - does not wait for process to complete
begin
#(100);
$display( "@%g inside 4th block\n",$time); //comes out to the next statement if any one of the process is completed
#1 WatchForCollision;
end
begin
#(130);
$display ("@%g inside 5th block\n",$time);
#2 $display ("inside fork block");
end
begin
#(111);
$display ("@%g inside 6th block\n",$time);
#4 WatchForCollision;
end
join_none
#4 $display ("\noutside process join none\n");
end
endmodule

Output in VCS

inside fork join any block
@5 inside 1st block
@6 inside 3rd block
@6 lateCollisionError=1 newCollision=1 transmitSucceeding=0
@7 inside 2nd block
inside fork block:block2
inside fork joinnone block
@10 lateCollisionError=1 newCollision=1 transmitSucceeding=0




(b) Sonet

(i) Example using always_comb

module always_comb();
reg data_prsnt,data_prev;
reg bip;
initial begin
$monitor ("@%g data_present = %b data_previous = %b bit_interleaved_parity = %b", $time, data_prsnt, data_prev, bip);
#1 data_prsnt = 1;
#1 data_prev = 1;
#5 data_prsnt = 0;
#1 $finish
end
always_comb
begin : PARITY
bip = data_prsnt ^data_prev;
end
endmodule

Output in VCS

@0 data_present = x data_previous = x bit_interleaved_parity = x
@1 data_present = 1 data_previous = x bit_interleaved_parity = x
@2 data_present = 1 data_previous = 1 bit_interleaved_parity = 0
@7 data_present = 0 data_previous = 1 bit_interleaved_parity = 1


(ii) Example using always_latch

module LOH
( input reset,
input logic enable,
output logic data_out );
reg H1_indic,data_in;
logic H1_indic = 1'b1;
logic data_in = 8'h26;
always_latch
begin
if (!reset)
data_out <= 8'h00;
else if (enable)
data_out <= data_in;
#2 $display("H1_indic= %b,data_out= %h",H1_indic,data_out);
#5 $finish;
end
endmodule

Output in VCS

H1_indic= x,data_out= x


(iii) Example using fork_join (any_none)

//This example explains the fork-join for STS-1 SONET frame.

module sonet_STS1();
initial
begin
fork
for ( int H1_pointer = 0 ; H1_pointer < 4; H1_pointer ++)
begin
#1 $display ("H -> Current value of H1 = %g", H1_pointer);
end
for ( int D1_channel = 4 ; D1_channel > 0; D1_channel --)
begin
#1 $display ("D -> Current value of D1 = %g", D1_channel);
end
join_any //like join_any, use join_none, join and see the output
$display("@%g Came out of fork-join\n", $time);
#1 $finish;
end
endmodule

Output in VCS for fork join

H -> Current value of H1 = 0
D -> Current value of D1 = 4
H -> Current value of H1 = 1
D -> Current value of D1 = 3
H -> Current value of H1 = 2
D -> Current value of D1 = 2
H -> Current value of H1 = 3
D -> Current value of D1 = 1
@4 Came out of fork-join

Output in VCS for fork join_any

H -> Current value of H1 = 0
D -> Current value of D1 = 4
H -> Current value of H1 = 1
D -> Current value of D1 = 3
H -> Current value of H1 = 2
D -> Current value of D1 = 2
H -> Current value of H1 = 3
@4 Came out of fork-join
D -> Current value of D1 = 1

Output in VCS for fork join_none

@0 Came out of fork-join
H -> Current value of H1 = 0
D -> Current value of D1 = 4
H -> Current value of H1 = 1
D -> Current value of D1 = 3


No comments:

Post a Comment

Popular Posts