always@(negedge ENA or negedge RST_B)
begin
if(!RST_B)
ADDR<=0;
else
ADDR<=ADD;
end
reg[4:0] CNT; //ENA信号时间滤波
reg[4:0]CNT_N;
reg EN_FLAG; //ENA有效信号
reg EN_FLAG_N;
always@(posedge SYSCLK or negedge RST_B)
begin
if(!RST_B)
CNT<=0;
else
CNT<=CNT_N;
end
always@(*)
begin
if(CNT=='d10)
CNT_N<=0;
else if(!ENA)
CNT_N<=CNT+1'b1;
else if(ENA)
CNT_N<=0;
else
CNT_N<=CNT;
end
always@(posedge SYSCLK or negedge RST_B)
begin
if(!RST_B)
EN_FLAG<=0;
else
EN_FLAG<=EN_FLAG_N;
end
always@(*)
begin
if(ENA)
EN_FLAG_N<=0;
else if(CNT=='d10)
EN_FLAG_N<=1'b1;
else
EN_FLAG_N<=EN_FLAG;
end
always@(posedge SYSCLK or negedge RST_B)
begin
if(!RST_B)
WR<=IDLE;
else if((!IOW)&(IOR)&(EN_FLAG))
WR<=WRITE;
else if((IOW)&(!IOR)&(EN_FLAG))
WR<=READ;
else
WR<=IDLE;
end
module brg(
SYSCLK,
RST_B,
ENA,
IOW,
IOR,
ADD,
WR,
ADDR
);
//====================================================================
// IO定义
//====================================================================
input SYSCLK;
input RST_B;
input ENA;
input IOW;
input IOR;
input[8:0] ADD;
output[1:0] WR;
output[8:0] ADDR;
//=====================================================================
// IO类型定义
//=====================================================================
wire SYSCLK;
wire RST_B;
wire ENA;
wire IOW;
wire IOR;
wire[8:0] ADD;
reg[1:0] WR;
reg[8:0] ADDR;
//======================================================================
// 逻辑描述
//======================================================================
parameter IDLE= 2'b00;
parameter READ= 2'b01;
parameter WRITE= 2'b10;
always@(negedge ENA or negedge RST_B)
begin
if(!RST_B)
ADDR<=0;
else
ADDR<=ADD;
end
reg[4:0] CNT; //ENA信号时间滤波
reg[4:0]CNT_N;
reg EN_FLAG; //ENA有效信号
reg EN_FLAG_N;
always@(posedge SYSCLK or negedge RST_B)
begin
if(!RST_B)
CNT<=0;
else
CNT<=CNT_N;
end
always@(*)
begin
if(CNT=='d10)
CNT_N<=0;
else if(!ENA)
CNT_N<=CNT+1'b1;
else if(ENA)
CNT_N<=0;
else
CNT_N<=CNT;
end
always@(posedge SYSCLK or negedge RST_B)
begin
if(!RST_B)
EN_FLAG<=0;
else
EN_FLAG<=EN_FLAG_N;
end
always@(*)
begin
if(ENA)
EN_FLAG_N<=0;
else if(CNT=='d10)
EN_FLAG_N<=1'b1;
else
EN_FLAG_N<=EN_FLAG;
end
always@(posedge SYSCLK or negedge RST_B)
begin
if(!RST_B)
WR<=IDLE;
else if((!IOW)&(IOR)&(EN_FLAG))
WR<=WRITE;
else if((IOW)&(!IOR)&(EN_FLAG))
WR<=READ;
else
WR<=IDLE;
end
endmodule
一周热门 更多>