打印
[verilog]

Verilog代码风格

[复制链接]
1529|10
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
Furance|  楼主 | 2016-5-30 14:03 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 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模块后



相关帖子

沙发
xuander| | 2016-6-1 09:04 | 只看该作者

不错,我也是这样的,
但文件说明基本空白。

使用特权

评论回复
板凳
Furance|  楼主 | 2016-6-27 13:08 | 只看该作者
xuander 发表于 2016-6-1 09:04
不错,我也是这样的,
但文件说明基本空白。

留着总有用的

使用特权

评论回复
地板
zhongxon| | 2016-6-27 15:13 | 只看该作者
不错

使用特权

评论回复
5
linfulin| | 2016-6-28 09:16 | 只看该作者
谢谢分享!

使用特权

评论回复
6
so_so_so| | 2016-6-28 15:17 | 只看该作者
受教了,谢谢。

使用特权

评论回复
7
waiter| | 2016-7-1 07:50 | 只看该作者
谁说 “(1)module前必须写'timescale 1ns/1ns”  ?
胡扯!!

使用特权

评论回复
8
玄德| | 2016-7-1 09:29 | 只看该作者

时间单位仿真时才用到。


使用特权

评论回复
9
Furance|  楼主 | 2016-9-6 13:26 | 只看该作者
waiter 发表于 2016-7-1 07:50
谁说 “(1)module前必须写'timescale 1ns/1ns”  ?
胡扯!!

不写的话怎知道时间精度?

使用特权

评论回复
10
1358484518| | 2016-12-3 17:51 | 只看该作者
还有这规矩

使用特权

评论回复
11
会飞的小猪大猪| | 2016-12-24 21:37 | 只看该作者
谢谢楼主分享经验!

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

3

主题

12

帖子

0

粉丝