本帖最后由 Furance 于 2017-4-10 19:41 编辑
1、文件头编写规范
对于大的工程,需要有一个规范的头文件,可以清楚的看到版本的修改、更新等问题。这里,参考CrazyBingo学长的头文件,提供一个头文件的标准格式
/*__________________________________________________________________
This confidential and proprietary software may be only used as authorized
by a licensing agreement from Furance.
In the event of publication,the following notice is applicable:
Copyright 2016-2016 Furance Corporation
The entire notice above must be reproduced on all authorized copies.
Author: Furance
Email Address: liangjia1002@sina.com
Filename:
Date:
Description:
Modification History:
Date By Version Change Description
====================================================================
____________________________________________________________________*/
2、Module列表编写规范
'timescale 1ns/1ns
module Verilog_Template
(
//global clock
input clk, //50MHz
input rst_n, //global reset
//user interface
output [7:0] led_data //board test led
);
endmodule
此处,将信号输入/输出列表直接放入module中。可读性更好,减少了累赘操作。需遵循以下原则:
(1)在TestBench中,module前必须写'timescale 1ns/1ns
(2)全局时钟和复位写在最前面,各个相关的信号根据时钟、复位、使能、控制端的顺序规划在一起,且需要有注释。
(3)所有的输入/输出、信号名、注释等必须严格对齐
(4)禁止使用中文注释
3、always模块编写规范
//____________________________________________________________________
//Generate for 1s delay signal,according to the global clock
localparam DELAY_TOP=28'd50_000000; //1s
reg[27:0] delay_cnt;
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
delay_cnt=0;
else if(delay_cnt<DELAY_TOP-1'b1)
delay_cnt<=delay_cnt+1'b1;
else
delay_cnt=0;
end
//counter for 1s delay is completed
wire delay_1s=(delay_cnt=DELAY_TOP-1'b1)?1'b1:1'b0;
(1)每个always模块都必须有功能介绍
(2)相关寄存器和宏定义必须卸载always模块前
(3)信号位宽必须写完整
(4)单/总线连出,写在always模块后
|