1.前文提到通过硬件代码描述可以将程序固化到flas中,但是只能实现单一功能,无法实现多功能切换。本文通过调用ise的ip核,固化代码实现流水灯与呼吸灯的切换。
2.这次的联系,主要是为了下次的在线升级的多种功能综合做铺垫。如果只是为了实现这种转换,利用状态机也可以实现,icap可以将flash实现功能分离。实现多个功能不在需要下载器下载。
3.练习代码如下:
module icap_ctrl(
input wire sclk,
input wire rst_n,
input wire key_in
);
reg [3:0] cnt;
reg ce;
reg [15:0] tmp_i;
wire [15:0] i_data;
always@(posedge sclk or negedge rst_n) //cnt14
if(!rst_n)
cnt<=4'd0;
else if(cnt==14)
cnt<=4'd0;
else if (ce==0)
cnt<=cnt+1'b1;
always@(posedge sclk or negedge rst_n) //ce
if(!rst_n)
ce<=1'b1;
else if(cnt==14)
ce<=1'b1;
else if (key_in==1)
ce<=1'b0;
always@(posedge sclk or negedge rst_n)
if(!rst_n)
tmp_i<=16'hffff;
else case(cnt)
0: tmp_i<=16'hffff;
1: tmp_i<=16'haa99;
2: tmp_i<=16'h5566;
3: tmp_i<=16'h3261;
4: tmp_i<=16'h0000; //
5: tmp_i<=16'h3281;
6: tmp_i<=16'h0300; //
7: tmp_i<=16'h32a1;
8: tmp_i<=16'h0000; //
9: tmp_i<=16'h32c1;
10: tmp_i<=16'h030b; //
11: tmp_i<=16'h30a1;
12: tmp_i<=16'h000e;
13: tmp_i<=16'h2000;
14: tmp_i<=16'hffff;
default: tmp_i<=16'hffff;
endcase
assign i_data={tmp_i[8],tmp_i[9],tmp_i[10],tmp_i[11],tmp_i[12],tmp_i[13],tmp_i[14],tmp_i[15],
tmp_i[0],tmp_i[1],tmp_i[2],tmp_i[3],tmp_i[4],tmp_i[5],tmp_i[6],tmp_i[7]};
ICAP_SPARTAN6 #(
.DEVICE_ID(28'h4000093), // Specifies the pre-programmed Device ID value
.SIM_CFG_FILE_NAME("NONE") // Specifies the Raw Bitstream (RBT) file to be parsed by the simulation
// model
)
ICAP_SPARTAN6_inst (
.BUSY(), // 1-bit output: Busy/Ready output
.O(), // 16-bit output: Configuartion data output bus
.CE(ce), // 1-bit input: Active-Low ICAP Enable input
.CLK(sclk), // 1-bit input: Clock input
.I(i_data), // 16-bit input: Configuration data input bus
.WRITE(1'b0) // 1-bit input: Read/Write control input
);
endmodule