其他分享
首页 > 其他分享> > SystemVerilog Tutorial

SystemVerilog Tutorial

作者:互联网

来自网站

1.网站说明-tutorial

2.SystemVerilog

Some of the new features in SystemVerilog are as listed below.

2.1Verilog Basic

Verilog介绍

When Verilog arrived, we suddenly had a different way of thinking about logic circuits. The Verilog design cycle is more like a traditional programming one, and it is what this tutorial will walk you through. **Here's how it goes: **

2.2Specifications

For this tutorial, we'll be building a two agent arbiter: a device that selects among two agents competing for mastership. Here are some specs we might write up.

2.3Block diagram of arbiter

2.4Low level design

Each of the circles represents a state that the machine can be in. Each state corresponds to an output. The arrows between the states are state transitions, labeled by the event that causes the transition. For instance, the leftmost orange arrow means that if the machine is in state GNT0 (outputting the signal that corresponds to GNT0) and receives an input of !req_0, the machine moves to state IDLE and outputs the signal that corresponds to that. This state machine describes all the logic of the system that you'll need. The next step is to put it all in Verilog.

Each of the circles represents a state that the machine can be in. Each state corresponds to an output. The arrows between the states are state transitions, labeled by the event that causes the transition. For instance, the leftmost orange arrow means that if the machine is in state GNT0 (outputting the signal that corresponds to GNT0) and receives an input of !req_0, the machine moves to state IDLE and outputs the signal that corresponds to that. This state machine describes all the logic of the system that you'll need.* The next step is to put it all in Verilog.*=详细的介绍看网站,=)

2.5两种设计方法

// 方法2 采用状态机实现
module arbiter_1 (
	input clk,
	input reset,//high activate asynchronous
	input req_0,req_1,//agent 0 having priority over agent 1
	output reg gnt_0,gnt_1
);

reg [2:0] state,next_state;
parameter IDLE = 3'b001,GNT0 = 3'b010,GNT1 = 3'b100;
always @(posedge clk or posedge reset) begin
	if (reset) begin
		state <= IDLE;
	end
	else begin
		state <= next_state;
	end
end	
always @(*) begin
	case (state)
		IDLE: begin if(req_0==1'b1) next_state = GNT0; 
			  else if(req_1==1'b1) next_state = GNT1;
			  else next_state = IDLE; end
		GNT0:begin if(req_0==1'b1) next_state = GNT0; 
			//  else if(req_1==1'b1) next_state = GNT1;
			 else next_state = IDLE;end
		GNT1:begin if(req_1==1'b1) next_state = GNT1; 
			//  else if(req_1==1'b1) next_state = GNT1;
			 else next_state = IDLE;end
		default:begin next_state = IDLE; end
	endcase
end

always @(*) begin
	if(state == GNT0)begin
		gnt_0 = 1'b1;
		gnt_1 = 1'b0;
	end
	else if(state == GNT1)begin
		gnt_1 = 1'b1;
		gnt_0 = 1'b0;
	end
	else begin
		gnt_0 = 1'b0;
		gnt_1 = 1'b0;
	end	
end

endmodule

module arbiter (
	input clk,
	input reset,//high activate asynchronous
	input req_0,req_1,//agent 0 having priority over agent 1
	output reg gnt_0,gnt_1
);
always @(posedge clk or posedge reset) begin
	if (reset==1'b1) begin
		gnt_0 <= 1'b0;
		gnt_1 <= 1'b0;
	end
	else if(req_0==1'b1)begin
		gnt_0 = 1'b1;
		gnt_1 = 1'b0;
	end
	else if(req_1 == 1'b1)begin
		gnt_1= 1'b1;
		gnt_0= 1'b0;
	end
	else begin
	   		gnt_1= 1'b0;
            gnt_0= 1'b0;
	end
	
end
endmodule

标签:agent,machine,state,design,Tutorial,SystemVerilog,Verilog
来源: https://www.cnblogs.com/waqdgstd/p/15304032.html