|
发表于 2011-11-21 09:45:49
|
显示全部楼层
本帖最后由 chen.terry 于 2011-11-21 09:47 编辑
`timescale 1ns/1ns
module divider( input clk,
input rst,
input div_start,
input [31:0] div_data1,
input [31:0] div_data2,
output reg div_end,
output reg [31:0] div_dout);
reg inverse_start;
wire inverse_end;
wire[31:0] inverse_result;
parameter IDLE=3'b000,START=3'b001,COMP=3'b010,END1=3'b100;
reg[2:0] state,next_state;
always@(posedge clk or negedge rst)
if(~rst) state<=IDLE;
else state<=next_state;
always@(*)
begin
next_state=state;
div_end=1'b0;
inverse_start=1'b0;
case(state)
IDLE:if(div_start)
begin
next_state=START;
inverse_start=1'b1;
end
START:if(inverse_end)next_state=COMP;
COMP:next_state=END1;
END1:begin
div_end=1'b1;
next_state=IDLE;
end
default:next_state=IDLE;
endcase
end
inverse inverse (.clk(clk),
.rst(rst),
.inv_start(inverse_start),
.inv_data(div_data2),
.inv_end(inverse_end),
.inv_dout(inverse_result));
reg[31:0] inverse_data2;
always@(posedge clk or negedge rst)
if(~rst) inverse_data2<=0;
else if(inverse_end) inverse_data2<=inverse_result;
reg[31:0] data1;
always@(posedge clk or negedge rst)
if(~rst) data1<=0;
else if(div_start) data1<=div_data1;
wire[31:0] m1,m2,result_m;
wire[63:0] result;
assign m1=data1;
assign m2=inverse_data2;
/*
multiply multiply(.a(m1),
.b(m2),
.c(result_m)
);
*/
assign result=m1*m2;
assign result_m=result>>10;
always@(posedge clk or negedge rst)
if(~rst) div_dout<=0;
else div_dout<=result_m;
endmodule
标记为红色的模块是什么?IP核还是自己写的算法模块。 |
|