资讯详情

gvim 模板(ab命令快速生成常用Verilog模板)

提示:文章完成后,目录可以自动生成,如何生成可以参考右边的帮助文档

文章目录

  • 前言
  • 一、模板制作方法
  • 二、使用步骤
  • 总结


前言

gvim在编写Verilog特定的代码模块可以通过预设的模板快速生成,提高代码编写效率。


一、模板制作方法

1.Windows下面:将以下代码复制到 "_vimrc"在安装目录中,如果文件不知道安装目录在哪里,可以在末行模式下输入:echo $VIM可显示安装位置。 2.Linux下面:将以下代码复制到 ".vimrc"该文件一般在/home在目录中,该文件属于隐藏文件,使用命令ls -a” 可见。

二、使用步骤

请注意:以下模板的映射名具有灵活性,可根据自己的需要修改相应的代码。我的命名规格一般是模块名英文翻译是单个单词,所以它被映射成首字母大写的英文拼写。如果翻译超过一个单词,它被命名为每个单词的首字母和大写。例如:以最常见的例子为例:Verilog对于模块中的计数器模块,我的重命名是:Counter,若有多个计数器模块,可在后面添加数字区。例如,时序逻辑块(sequential logic),我的重命名是:SL,如果有多个时序逻辑块,则在其名称后添加数字区分。其他的都差不多。 模板如下:

" 显示语法高亮度 syntax on  "取消自动备份和生产swp文件 "set noundofile "set nobackup "set nowb "set noswapfile  "自动保存 "set autowrite  "当文件被更改时,自动载入  set autoread  "与windows共享剪贴板 set clipboard =unnamed  "代码补全   set completeopt=preview,menu   "搜索匹配亮点 set hlsearch  set cuc set cul " 设置行号 set nu  "防止中文注释乱码 set fileencoding=utf-8 set fenc=utf-8 set fencs=utf-8,usc-bom,euc-jp,gb18030,gbk,gb2312,cp936,big-5                     set enc=utf-8 let &termencoding=&encoding  "设置字体 "set guifont=Monospace\ 13  " 设置tab4个空格 "set tabstop=4 "set expandtab  "当空格数自动缩进程序时 "set shiftwidth=4  "一次删除4个空4个空间 "set softtabstop=4 "autocmd FileType make set noexpandtab  " 在编辑过程中,在右下角显示光标位置的状态下 set ruler  " 搜索忽略了大小写  set ignorecase   " vim使用自动对起,即将当前对起格式应用到下一行 "set autoindent  " 根据上述对起格式,智能选择对起格式,类似C语言的编写非常有用 "set smartindent  " 目前执行的指令显示在状态列中 set showcmd  " 设置颜色主题 colorscheme koehler  set nocompatible set backspace=indent,eol,start  "###################    set file head start  ######################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################## "autocmd自动调用创建新文件setfilehead()函数 autocmd BufNewFile *.v,*.sv,*.cpp,*.c,*.h exec ":call Setfilehead()" func Setfilehead()     call append(0, '/***********************************************')     call append(1, '#')     call append(2, '# Filename: '.expand("%"))     call append(3, '#')     call append(4, '#   Author: Bright - zhishigexianren@163.com')     call append(5, '#   Description: ---')     call append(6, '#   Create: '.strftime("%Y-%m-%d %H:%M:%S"))     call append(7, '# Last Modified: '.strftime("%Y-%m-%d %H:%M:%S"))     call append(8, '***********************************************/') "    call append(9, '') endfunc  "map F2 to creat file head comment "映射F2快捷键,生成后跳转到第10行,然后用o进入vim的插入模式 map <F2> :call Setfilehead()<CR>:10<CR>o "##########################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################    set file head end   #################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################   " Annote the line where the cursor is :map <F6> l0<ESC>i//<ESC>  " Cut-off Line :ab COL //------------------------------Cut-off-Line----------------------------------------------------  " Note :ab Note /*******************************Annotation****************************************************/  " Parameter :ab Parameter <Tab>parameter<Tab><Tab>DATA_W<Tab><Tab>=<Tab>8;  " Localparam :ab Localparam <Tab>localparam<Tab><Tab>P_ST_IDLE<Tab>=<Tab>8'b0000_0001<Tab><Tab>;  " Assign :ab Assign <Tab>assign<Tab><Tab>o_<Tab><Tab>=<Tab>r_<Tab><Tab>;  " Initial :ab Initial <tab>initial begin<Enter><Tab><Tab>#1;<Enter><Tab>end  " Sequential Logic :ab SL1 <Tab>always  @(posedge i_clk or negedge i_rstn)<Enter><Tab><Tab>if(!i_rstn)<Enter><Tab>else<Enter> :ab SL2 <Tab>always  @(posedge i_clk or negedge i_rstn)<Enter><Tab><Tab>if(!i_rstn)<Enter><Tab>else<Tab> if()<Enter> :ab SL3 <Tab>always  @(posedge i_clk or negedge i_rstn)<Enter><Tab><Tab>if(!i_rstn)<Enter><Tab>else<Tab> if()<Enter><Tab>else<Tab> if()<Enter>  " Combinatorial Logic :ab CL1 <Tab>always  @(*)<Enter><Tab><Tab>if(!i_rstn)<Enter><Tab>else<Enter> :ab CL2 <Tab>always  @(*)<Enter><Tab><Tab>if(!i_rstn)<Enter><Tab>else<Tab>if()<Enter><Enter> :ab CL3 <Tab>always  @(*)<Enter><Tab><Tab>if(!i_rstn)<Enter><Tab>else<Tab>if()<Enter><Tab>else<Tab>if()<Enter>  " Module :ab Module module module_name(<Enter><Tab>input<Tab><Tab><Tab>i_clk<Tab>&ltTab>,<Enter><Tab>input<Tab><Tab><Tab>i_rstn<Tab><Tab>,<Enter><Tab>output<Tab>[15: 0]<Tab><Tab>o_out<Enter>);<Enter><Enter><Tab>// Parameter<Enter><Tab>parameter<Tab>DATA_W<Tab><Tab>=<Tab>8<Tab>;<Enter><Enter>endmodule

" Top
:ab Top module top_name(<Enter><Tab>input<Tab><Tab><Tab>i_clk<Tab><Tab>,<Enter><Tab>input<Tab><Tab><Tab>i_rstn<Tab><Tab>,<Enter><Tab>input<Tab>[15: 0]<Tab><Tab>i_in<Tab><Tab>,<Enter><Tab>output<Tab>[15: 0]<Tab><Tab>o_out<Tab><Tab><Enter>);<Enter><Tab>//Instantiation<Enter><Tab>module_name u_module_name(<Enter><Tab><Tab>.i_clk<Tab><Tab><Tab>(i_clk<Tab><Tab>),<Enter><Tab><Tab>.i_rstn<Tab><Tab><Tab>(i_rstn<Tab><Tab>),<Enter><Tab><Tab>.i_in<Tab><Tab><Tab>(i_in<Tab><Tab>),<Enter><Tab><Tab>.o_out<Tab><Tab><Tab>(o_out<Tab><Tab>)<Enter><Tab>);<Enter>endmodule    

" Instantiation
:ab Instantiation <Tab>//Instantiation<Enter><Tab>module_name u_module_name(<Enter><Tab><Tab>.i_clk<Tab><Tab><Tab>(i_clk<Tab><Tab>),<Enter><Tab><Tab>.i_rstn<Tab><Tab><Tab>(i_rstn<Tab><Tab>),<Enter><Tab><Tab>.i_in<Tab><Tab><Tab>(i_in<Tab><Tab>),<Enter><Tab><Tab>.o_out<Tab><Tab><Tab>(o_out<Tab><Tab>)<Enter><Tab>);<Enter>

" Testbench
:ab Testbench `timescale 1 ns/1 ns<Enter><Enter>module testbench_name();<Enter><Enter><Tab>// Clock and reset signals <Enter><Tab>reg<Tab><Tab><Tab>i_clk<Tab><Tab>;<Enter><Tab>reg<Tab><Tab><Tab>i_rstn<Tab><Tab>;<Enter><Enter><Tab>// Input signals<Enter><Tab>reg<Tab>[15: 0]<Tab><Tab>din0<Tab><Tab>;<Enter><Tab>reg<Tab>[15: 0]<Tab><Tab>din1<Tab><Tab>;<Enter><Enter><Tab>// Output signals<Enter><Tab>wire<Tab>[15: 0]<Tab><Tab>dout0<Tab><Tab>;<Enter><Tab>wire<Tab>[15: 0]<Tab><Tab>dout1<Tab><Tab>;<Enter><Enter><Tab>// Clock period<Enter><Tab>parameter<Tab><Tab>CYCLE<Tab><Tab>=<Tab>20<Tab>;<Enter><Enter><tab>// Reset time<Enter><Tab>parameter<Tab><Tab>RST_TIME<Tab>=<Tab>3<Tab>;<Enter><Enter><Tab>// DUT<Enter><Tab>module_name<Enter><Tab>u_instatiation_name(<Enter><Tab><Tab>.i_clk<Tab><Tab>(i_clk<Tab><Tab>), <Enter><Tab><Tab>.i_rstn<Tab><Tab>(i_rstn<Tab><Tab>),<Enter><Tab><Tab>.din0<Tab><Tab>(din0<Tab><Tab>),<Enter><Tab><Tab>.din1<Tab><Tab>(din1<Tab><Tab>),<Enter><Tab><Tab>.dout0<Tab><Tab>(dout0<Tab><Tab>),<Enter><Tab><Tab>.dout1<Tab><Tab>(dout1<Tab><Tab>)<Enter><Tab>);<Enter><Enter><Tab>// Generate system clock<Enter><Tab>initial begin<Enter><Tab><Tab>i_clk = 0;<Enter><Tab><Tab>forever<Enter><Tab><Tab>#(CYCLE/2)<Tab>i_clk<Tab>=<Tab>~i_clk;<Enter><Tab>end<Enter><Enter><Tab>// Generate reset signal<Enter><Tab>initial begin<Enter><Tab><tab>i_rstn = 1;<Enter><tab><Tab>#2;<Enter><Tab><tab>i_rstn = 0;<Enter><Tab><tab>#(CYCLE*RST_TIME);<Enter><Tab><tab>i_rstn = 1;<Enter><Tab>end<Enter><Enter><Tab>// Input singals assignment<Enter><Tab>initial begin<Enter><Tab><Tab>#1;<Enter><Tab><Tab>//Initial value assignment<Enter><Tab><Tab>din0<Tab>=<Tab>0;<Enter><Tab><Tab>#(10*CYCLE);<Enter><Tab><Tab>// Start the assignment<Enter><Tab>end<Enter><Enter>endmodule

" State Machine
:ab SM <Tab>localparam<Tab>[2:0]<Tab>P_ST_IDLE<Tab>=<Tab>3'b000<Tab>;<enter><Tab>localparam<tab>[2:0]<tab>P_ST_S1<tab><Tab>=<Tab>3'b001<Tab>;<enter><Tab>localparam<Tab>[2:0]<Tab>P_ST_S2<Tab><Tab>=<Tab>3'b010<Tab>;<Enter><enter><Tab>reg<Tab><Tab>[2:0]<Tab>r_state_c<Tab>;<enter><Tab>reg<Tab><Tab>[2:0]<Tab>r_state_n<Tab>;<enter><Tab>always @( posedge i_clk or negedge i_rstn )<enter><Tab><Tab>if ( !i_rstn )<Tab>r_state_c<Tab><=<Tab>P_ST_IDLE<Tab>;<enter><Tab>else<Tab><Tab><Tab>r_state_c<Tab><=<Tab>r_state_n<tab>;<enter><enter><Tab>always @( * ) begin<enter><Tab><Tab>r_state_n = P_ST_IDLE;<enter><Tab>case ( r_state_c )<enter><Tab><Tab>IDLE: begin<enter><Tab><Tab><Tab>if (  )<Tab><Tab>r_state_n = P_ST_S1;<enter><Tab><Tab>else<Tab>if (  )<Tab><Tab>r_state_n = P_ST_S2;<enter><Tab><Tab>else<Tab><Tab><Tab>r_state_n = P_ST_IDLE;<Enter><Tab><Tab>end<enter><Tab><Tab>P_ST_S1: begin<enter><Tab><Tab><Tab>if (  )<Tab><Tab>r_state_n = P_ST_IDLE;<enter><Tab><Tab>else<Tab>if (  )<Tab><Tab>r_state_n = P_ST_S2;<enter><Tab><Tab>else<Tab><Tab><Tab>r_state_n = P_ST_S1;<enter><Tab><Tab>end<enter><Tab><Tab>P_ST_S2: begin<enter><Tab><Tab><Tab>if (  )<Tab><Tab>r_state_n = P_ST_IDLE;<enter><Tab><Tab>else<Tab>if (  )<Tab><Tab>r_state_n = P_ST_S1;<enter><Tab><Tab>else<Tab><Tab><Tab>r_state_n = P_ST_S2;<enter><Tab><Tab>end<enter><Tab><Tab>default:<Tab><Tab>r_state_n = P_ST_IDLE; <enter><Tab>endcase<enter><Tab>end<enter><enter><Tab>always @( posedge i_clk or negedge i_rstn )<enter><Tab><Tab>if ( !i_rstn )<enter><Tab>else begin <enter><Tab><Tab><Tab>case ( r_state_n )<enter><Tab><Tab><Tab>endcase <enter><Tab>end 

" Counter
:ab Counter    <Tab>reg<Tab>[15:0]<Tab><Tab>r_cnt<Tab><Tab>;<Enter><Tab>wire<Tab><Tab>w_cnt_clr<Tab><Tab>=<Tab><Tab>;<Enter><Enter><Tab>wire<Tab><Tab>w_cnt_inc<Tab><Tab>=<Tab><Tab>;<Tab>always @(posedge i_clk or negedge i_rstn)<Enter><Tab><Tab>if(!i_rstn)<Tab><Tab>cnt <= 'h0;<Enter><Tab>else<Tab>if(w_cnt_clr)<Tab><Tab>r_cnt <= 'h0;<Enter><Tab>else<Tab>if(w_cnt_inc)r_cnt <= r_cnt + 1'b1;<Enter>   

" Output
:ab Output32 <Tab>output<Tab>[31: 0]<Tab><Tab>o_<Tab><Tab>;
:ab Output16 <Tab>output<Tab>[15: 0]<Tab><Tab>o_<Tab><Tab>;
:ab Output8  <Tab>output<Tab>[ 7: 0]<Tab><Tab>o_<Tab><Tab>;
:ab Output4  <Tab>output<Tab>[ 3: 0]<Tab><Tab>o_<Tab><Tab>;
:ab Output3  <Tab>output<Tab>[ 2: 0]<Tab><Tab>o_<Tab><Tab>;
:ab Output2  <Tab>output<Tab>[ 1: 0]<Tab><Tab>o_<Tab><Tab>;
:ab Output1  <Tab>output<Tab>       <Tab><Tab>o_<Tab><Tab>;

" Input
:ab Input32 <Tab>input<Tab>[31: 0]<Tab><Tab>i_<Tab><Tab>;
:ab Input16 <Tab>input<Tab>[15: 0]<Tab><Tab>i_<Tab><Tab>;
:ab Input8  <Tab>input<Tab>[ 7: 0]<Tab><Tab>i_<Tab><Tab>;
:ab Input4  <Tab>input<Tab>[ 3: 0]<Tab><Tab>i_<Tab><Tab>;
:ab Input3  <Tab>input<Tab>[ 2: 0]<Tab><Tab>i_<Tab><Tab>;
:ab Input2  <Tab>input<Tab>[ 1: 0]<Tab><Tab>i_<Tab><Tab>;
:ab Input1  <Tab>input<Tab>       <Tab><Tab>i_<Tab><Tab>;

" Wire
:ab Wire32 <Tab>wire<Tab>[31: 0]<Tab><Tab>w_<Tab><Tab>;
:ab Wire16 <Tab>wire<Tab>[15: 0]<Tab><Tab>w_<Tab><Tab>;
:ab Wire8  <Tab>wire<Tab>[ 7: 0]<Tab><Tab>w_<Tab><Tab>;
:ab Wire4  <Tab>wire<Tab>[ 3: 0]<Tab><Tab>w_<Tab><Tab>;
:ab Wire3  <Tab>wire<Tab>[ 2: 0]<Tab><Tab>w_<Tab><Tab>;
:ab Wire2  <Tab>wire<Tab>[ 1: 0]<Tab><Tab>w_<Tab><Tab>;
:ab Wire1  <Tab>wire<Tab>       <Tab><Tab>w_<Tab><Tab>;

" Register
:ab Reg32 <Tab>reg<Tab>[31: 0]<Tab><Tab>r_<Tab><Tab>;
:ab Reg16 <Tab>reg<Tab>[15: 0]<Tab><Tab>r_<Tab><Tab>;
:ab Reg8  <Tab>reg<Tab>[ 7: 0]<Tab><Tab>r_<Tab><Tab>;
:ab Reg4  <Tab>reg<Tab>[ 3: 0]<Tab><Tab>r_<Tab><Tab>;
:ab Reg3  <Tab>reg<Tab>[ 2: 0]<Tab><Tab>r_<Tab><Tab>;
:ab Reg2  <Tab>reg<Tab>[ 1: 0]<Tab><Tab>r_<Tab><Tab>;
:ab Reg1  <Tab>reg<Tab>       <Tab><Tab>r_<Tab><Tab>;


总结

例如:在使用的过程如果遇到更好用的模板还会继续更新。

标签: sl2继电器线路板底座

锐单商城拥有海量元器件数据手册IC替代型号,打造 电子元器件IC百科大全!

锐单商城 - 一站式电子元器件采购平台