今天在寫I2C接口,分析和綜合代碼時,出現了一個以前沒見過或者很少見的警告,這裏記錄一下:
先看代碼:
//設備地址
always @(posedge clk or negedge rst_n)begin
if(rst_n==1'b0)begin
device_addr_a <= {4'b1010,device_addr,1'b0};
end
else if(wr_flag) begin
device_addr_a <= {4'b1010,device_addr,1'b0};
end
else if(rd_flag) begin
device_addr_a <= {4'b1010,device_addr,1'b1};
end
else begin
device_addr_a <= {4'b1010,device_addr,1'b0};
end
end
警告:
Warning (13004): Presettable and clearable registers converted to equivalent circuits with latches. Registers power-up to an undefined state, and DEVCLRn places the registers in an undefined state.
Warning (13310): Register "device_addr_a[2]" is converted into an equivalent circuit using register "device_addr_a[2]~_emulated" and latch "device_addr_a[2]~1"
Warning (13310): Register "device_addr_a[1]" is converted into an equivalent circuit using register "device_addr_a[1]~_emulated" and latch "device_addr_a[1]~5"
Warning (13310): Register "device_addr_a[3]" is converted into an equivalent circuit using register "device_addr_a[3]~_emulated" and latch "device_addr_a[3]~9"
在這個警告中,大體意思是:可預置且可清除的寄存器已轉換爲帶鎖存器的等效電路。
意思反正是生成了鎖存器,打架都知道,FPGA設計中要儘量避免鎖存器,防止佔用過多資源,影響電路穩定。
原因:
代碼中在復位時將這個信號給了一個特定的寄存數據,電路復位時,應該將信號清零或者預置確定的常數。
解決:
將復位下的信號改成確定值:
//設備地址
always @(posedge clk or negedge rst_n)begin
if(rst_n==1'b0)begin
device_addr_a <= 0;
end
else if(wr_flag) begin
device_addr_a <= {4'b1010,device_addr,1'b0};
end
else if(rd_flag) begin
device_addr_a <= {4'b1010,device_addr,1'b1};
end
else begin
device_addr_a <= {4'b1010,device_addr,1'b0};
end
end
這樣,重新編譯就不會再出錯。