Sponsored Content
Top Forums Shell Programming and Scripting Vim function to generate RTL Code(finite state machine) in verilog Post 302903629 by dll_fpga on Wednesday 28th of May 2014 04:17:21 PM
Old 05-28-2014
Vim function to generate RTL Code(finite state machine) in verilog

Hi I wanted to call the AutoFsm function (given below) in vim to generate a code something like:


**********verilog code to generate *************
always @(posedge clk or negedge rst_n) begin
if(!rst_n) begin
state_r <= #1 next_stateascii_r;
end else begin
state_r <= #1 next_stateascii_r;
end
end

always @(state_r) begin
next_stateascii_r = state_r
casex ({state_r})
SM_IDLE: next_stateascii_r = "idle ";
SM_SEND: next_stateascii_r = "send ";
SM_WAIT1: next_stateascii_r = "wait1";
default: next_stateascii_r = "%Erro";
endcase
end

**********end of verilog code to generate *************


function AutoFsm() "{{{2
let aft_fsm = []
call KillAutoFsm()
for line in getline(1, line("$"))
if line =~ '/\*\<autofsm\>'
call add(aft_fsm, line)
call add(aft_fsm, "// Define fsm here")
let line = substitute(line,'^.*\<autofsm\>\s*','','')
let line = substitute(line,'\s*\*/.*$','','')
let paras = split(line,'\s\+')
let state = paras[0]
let inst_state = paras[1]
let autoparaline = s:GetSpecAutoParaLine(state)
let paras = s:GetAutoParas(autoparaline)

let first_st = ''
for key in keys(paras[0])
let first_st = key
endfor
call add(aft_fsm, "always @(posedge clk or negedge rst_n) begin")
call add(aft_fsm, s:indent . "if(!rst_n) begin")
call add(aft_fsm, s:indent . s:indent . inst_state . ' <= #1 ' . first_st . ';')
call add(aft_fsm, s:indent . "end else begin")
call add(aft_fsm, s:indent . s:indent . inst_state . ' <= #1 ' . 'next_' . inst_state . ';')
call add(aft_fsm, s:indent . "end")
call add(aft_fsm, "end")

call add(aft_fsm, "always @(*) begin")
call add(aft_fsm, s:indent . 'next_' . inst_state . ' = ' . inst_state . ';')
call add(aft_fsm, s:indent . 'case(' . inst_state . ')')

for para in paras
for key in keys(para)
call add(aft_fsm, s:indent . s:indent . key . ': begin')
call add(aft_fsm, s:indent . s:indent . 'end')
endfor
endfor
call add(aft_fsm, s:indent . s:indent . 'default' . ': begin')
call add(aft_fsm, s:indent . s:indent . 'end')

call add(aft_fsm, s:indent . 'endcase')
call add(aft_fsm, "end")

call add(aft_fsm, "// End of automatic fsm")
elseif line =~ '^\s*\<endmodule\>'
call add(aft_fsm, line)
break
else
call add(aft_fsm, line)
endif
endfor
call s:UpdateBuf(aft_fsm,-1)
endfunction "}}}2


Please let me know the arguments & their format which i need to give so as to generate the verilog code using AutoFsm function.

Last edited by dll_fpga; 05-28-2014 at 05:30 PM..
 

2 More Discussions You Might Find Interesting

1. Programming

Function in a blocked state.

Hi, How do you write a function which has to stay blocked in a wait state till an event occurs? The event could be the arrival of a message/updation of a database etc .. Regards, VJ (2 Replies)
Discussion started by: vjsony
2 Replies

2. Programming

Bitwise operation for state machine

Hello All, I am writing basic state machine which maintains 8 different states and there is posibility that system may be in multiple states at a time (Except for state1 to state3. menas only once state can be active at a time from state1 to state3). I have declared... (9 Replies)
Discussion started by: anand.shah
9 Replies
VIMTUTOR(1)						      General Commands Manual						       VIMTUTOR(1)

NAME
vimtutor - the Vim tutor SYNOPSIS
vimtutor [-g] [language] DESCRIPTION
Vimtutor starts the Vim tutor. It copies the tutor file first, so that it can be modified without changing the original file. The Vimtutor is useful for people that want to learn their first Vim commands. The optional argument -g starts vimtutor with gvim rather than vim, if the GUI version of vim is available, or falls back to Vim if gvim is not found. The optional [language] argument is the two-letter name of a language, like "it" or "es". If the [language] argument is missing, the lan- guage of the current locale will be used. If a tutor in this language is available, it will be used. Otherwise the English version will be used. Vim is always started in Vi compatible mode. FILES
/usr/share/vim/vim80/tutor/tutor[.language] The Vimtutor text file(s). /usr/share/vim/vim80/tutor/tutor.vim The Vim script used to copy the Vimtutor text file. AUTHOR
The Vimtutor was originally written for Vi by Michael C. Pierce and Robert K. Ware, Colorado School of Mines using ideas supplied by Charles Smith, Colorado State University. E-mail: bware@mines.colorado.edu. It was modified for Vim by Bram Moolenaar. For the names of the translators see the tutor files. SEE ALSO
vim(1) 2001 April 2 VIMTUTOR(1)
All times are GMT -4. The time now is 01:48 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy