2013-04-09 42 views
0

我正在嘗試編寫一個能夠生成Verilog代碼的小型java程序。由於我幾乎不知道Verilog語言,所以在創建一個簡單示例時遇到問題。從Java代碼到Verilog?

我們假設我們有2個輸入a, b和1個輸出c。還有2個州。 State1是初始狀態,並且對於某個條件wire1需要State2,這需要b = 1

我在這個例子中的輸出將有state2 & a作爲條件得到滿足。

問題:使用下面的近似設計,根據我的示例,完整的Verilog代碼將如何查看?

//simplified without inheritance 
class Input { 
    String varname; 
    new Input(String varname); 
} 

class Output { 
    String varname; 
    String condition; 
    new Output(String varname, String condition); 
} 

class State { 
    String varname; 
    new State(String varname); 
} 

class Wire { 
    String condition; 
    Input input; 
    Ouput output; 
    new Wire(Input input, Output output, String condition); 
} 

Input input1 = new Input("a"); 
Input input2 = new Input("b"); 
State state1 = new State("initial"); 
State state2 = new State("following"); 
Wire wire12 = new Wire(state1, state2, "b"); 
Ouput output1 = new Output(c, "state2 & a"); 

Verilog代碼如何基於這個看起來?

module BasicFsm(
    input clock, 
    input reset, 
    input a, 
    input b, 
    output c 
); 

always @(posedge clock) 
//how to continue here? 

回答

2

下面的一些事情對於我認爲可以從輸入規範輕鬆派生的實現來說是一個好的開始。

在使用這樣的東西之前,你需要測試生成的代碼以及有很多免費的模擬器可用於此。有相關的問題免費模擬器here

module BasicFsm(
    input  clock, 
    input  reset, 
    input  a, 
    input  b, 
    output reg c 
); 

reg  state; 
wire  nexstate; 

localparam S_STATE1 = 1'b0; //Could name initial 
localparam S_STATE2 = 1'b1; //Could name following 

always @(posedge clock or posedge reset) begin 
    if(reset) begin 
    state <= S_STATE1; 
    end 
    else begin 
    state <= nextstate 
    end 
end 

//Combinatorial nextstate 
always @* begin 
    case(state) 
    S_STATE1 : 
    if (b == 1'b1) begin 
     nextstate = S_STATE2 ; 
    end 
    else begin 
     nextstate = state ; //Hold state 
    end 
    S_STATE2 : nextstate = state ; //locked up forever if you get here 
    default  : nextstate = S_STATE1; 
    endcase 
end 

//Combinatorial output 
always @* begin 
    c = (state == S_STATE2) && (a == 1'b1); 
end