1. Register a system call
void hello_register()
{
s_vpi_systf_data tf_data;
tf_data.type = vpiSysTask;
tf_data.tfname = "$hello";
tf_data.calltf = hello;
tf_data.compiletf = NULL;
tf_data.sizetf = NULL;
vpi_register_systf(&tf_data);
}
2. Obtain system task arguments
vpiHandle systf_handle, arg_iterator, arg_handle, net_handle;
s_vpi_value current_value;
/* obtain a handle to the system task instance */
systf_handle = vpi_handle(vpiSysTfCall, NULL);
/* obtain handle to system task argument */
arg_iterator = vpi_iterate(vpiArgument, systf_handle);
net_handle = vpi_scan(arg_iterator);
vpi_free_object(arg_iterator); /* free iterator memory */
3/27/2007
3/23/2007
Reset CF GPS receiver
1) Download WinFast Navigator at . Copy and paste this URL onto your browser. ftp://ftp.winfast.com.tw/gps/Tools/WinFast GPS-Install.zip
2) Then, unzip the file but you only need to move/copy "Navigator.ARM.CAB" to your PDA. This file is located in "WinFast Navigator CE" folder.
3) Once you have copied this cab file to your PDA, just use File Explorer to locate it and tap once on it to launch the installtion program.
4) To launch the program, click on Start | Navigator.
5) Insert your CF Card to the CF slot now and observe the Device plug-in! pop up windows and note down the COM number. Click OK to close out of the pop up window.
6) Click on Tools | Port Setting… | tap on OK 3 times to get safely get rid of the error message.
a. GPS Portocol=NMEA,
b. Port=Modem COM X , X is the number you observed on step 5
c. Baud Rate=4800.
7) Click OK
8) Click on Tools | Make sure Factory radio button is selected under Reset Mode, leave everything else as default and click OK.
9) Reset to default completes. Click on View | Signal Level to observe the GPS lock status.
2) Then, unzip the file but you only need to move/copy "Navigator.ARM.CAB" to your PDA. This file is located in "WinFast Navigator CE" folder.
3) Once you have copied this cab file to your PDA, just use File Explorer to locate it and tap once on it to launch the installtion program.
4) To launch the program, click on Start | Navigator.
5) Insert your CF Card to the CF slot now and observe the Device plug-in! pop up windows and note down the COM number. Click OK to close out of the pop up window.
6) Click on Tools | Port Setting… | tap on OK 3 times to get safely get rid of the error message.
a. GPS Portocol=NMEA,
b. Port=Modem COM X , X is the number you observed on step 5
c. Baud Rate=4800.
7) Click OK
8) Click on Tools | Make sure Factory radio button is selected under Reset Mode, leave everything else as default and click OK.
9) Reset to default completes. Click on View | Signal Level to observe the GPS lock status.
3/17/2007
FSM Coding Convention
Two-always blocks with continuous assignment outputs:
module fsm1a (ds, rd, go, ws, clk, rst_n);
output ds, rd;
input go, ws;
input clk, rst_n;
parameter [1:0] IDLE = 2'b00,
READ = 2'b01,
DLY = 2'b10,
DONE = 2'b11;
reg [1:0] state, next;
always @(posedge clk or negedge rst_n)
if (!rst_n) state <= IDLE;
else state <= next;
always @(state or go or ws) begin
next = 2'bx;
case (state)
IDLE: if (go) next = READ;
else next = IDLE;
READ: next = DLY;
DLY: if (ws) next = READ;
else next = DONE;
DONE: next = IDLE;
endcase
end
assign rd = (state==READ state==DLY);
assign ds = (state==DONE);
endmodule
Two-always blocks with combined output assignments:
module fsm1 (ds, rd, go, ws, clk, rst_n);
output ds, rd;
input go, ws;
input clk, rst_n;
reg ds, rd;
parameter [1:0] IDLE = 2'b00,
READ = 2'b01,
DLY = 2'b10,
DONE = 2'b11;
reg [1:0] state, next;
always @(posedge clk or negedge rst_n)
if (!rst_n) state <= IDLE;
else state <= next;
always @(state or go or ws) begin
next = 2'bx;
ds = 1'b0;
rd = 1'b0;
case (state)
IDLE: if (go) next = READ;
else next = IDLE;
READ: begin rd = 1'b1;
next = DLY;
end
DLY: begin rd = 1'b1;
if (ws) next = READ;
else next = DONE;
end
DONE: begin ds = 1'b1;
next = IDLE;
end
endcase
end
endmodule
Three-always block coding style
module fsm1b (ds, rd, go, ws, clk, rst_n);
output ds, rd;
input go, ws;
input clk, rst_n;
reg ds, rd;
parameter [1:0] IDLE = 2'b00,
READ = 2'b01,
DLY = 2'b10,
DONE = 2'b11;
reg [1:0] state, next;
always @(posedge clk or negedge rst_n)
if (!rst_n) state <= IDLE;
else state <= next;
always @(state or go or ws) begin
next = 2'bx;
case (state)
IDLE: if (go) next = READ;
else next = IDLE;
READ: next = DLY;
DLY: if (ws) next = READ;
else next = DONE;
DONE: next = IDLE;
endcase
end
always @(posedge clk or negedge rst_n)
if (!rst_n) begin
ds <= 1'b0;
rd <= 1'b0;
end
else begin
ds <= 1'b0;
rd <= 1'b0;
case (state)
IDLE: if (go) rd <= 1'b1;
READ: rd <= 1'b1;
DLY: if (ws) rd <= 1'b1;
else ds <= 1'b1;
endcase
end
endmodule
module fsm1a (ds, rd, go, ws, clk, rst_n);
output ds, rd;
input go, ws;
input clk, rst_n;
parameter [1:0] IDLE = 2'b00,
READ = 2'b01,
DLY = 2'b10,
DONE = 2'b11;
reg [1:0] state, next;
always @(posedge clk or negedge rst_n)
if (!rst_n) state <= IDLE;
else state <= next;
always @(state or go or ws) begin
next = 2'bx;
case (state)
IDLE: if (go) next = READ;
else next = IDLE;
READ: next = DLY;
DLY: if (ws) next = READ;
else next = DONE;
DONE: next = IDLE;
endcase
end
assign rd = (state==READ state==DLY);
assign ds = (state==DONE);
endmodule
Two-always blocks with combined output assignments:
module fsm1 (ds, rd, go, ws, clk, rst_n);
output ds, rd;
input go, ws;
input clk, rst_n;
reg ds, rd;
parameter [1:0] IDLE = 2'b00,
READ = 2'b01,
DLY = 2'b10,
DONE = 2'b11;
reg [1:0] state, next;
always @(posedge clk or negedge rst_n)
if (!rst_n) state <= IDLE;
else state <= next;
always @(state or go or ws) begin
next = 2'bx;
ds = 1'b0;
rd = 1'b0;
case (state)
IDLE: if (go) next = READ;
else next = IDLE;
READ: begin rd = 1'b1;
next = DLY;
end
DLY: begin rd = 1'b1;
if (ws) next = READ;
else next = DONE;
end
DONE: begin ds = 1'b1;
next = IDLE;
end
endcase
end
endmodule
Three-always block coding style
module fsm1b (ds, rd, go, ws, clk, rst_n);
output ds, rd;
input go, ws;
input clk, rst_n;
reg ds, rd;
parameter [1:0] IDLE = 2'b00,
READ = 2'b01,
DLY = 2'b10,
DONE = 2'b11;
reg [1:0] state, next;
always @(posedge clk or negedge rst_n)
if (!rst_n) state <= IDLE;
else state <= next;
always @(state or go or ws) begin
next = 2'bx;
case (state)
IDLE: if (go) next = READ;
else next = IDLE;
READ: next = DLY;
DLY: if (ws) next = READ;
else next = DONE;
DONE: next = IDLE;
endcase
end
always @(posedge clk or negedge rst_n)
if (!rst_n) begin
ds <= 1'b0;
rd <= 1'b0;
end
else begin
ds <= 1'b0;
rd <= 1'b0;
case (state)
IDLE: if (go) rd <= 1'b1;
READ: rd <= 1'b1;
DLY: if (ws) rd <= 1'b1;
else ds <= 1'b1;
endcase
end
endmodule
Encoding Styles for FSM
- Binary encoding is good for creating small (less than 16 states) FSMs in FPGAs. Larger FSMs require too much Next state logic and perform slower when binary encoded.
- One-Hot encoding is good for building larger FSMs since it requires very little Next state logic. OHE is more reliable than Binary encoding, because fewer bits change at once making the circuit less likely to glitch. OHE leaves a lot of unused states in the FSM and also uses a lot of registers (but there are a lot of registers in FPGAs).
- Gray encoding of your state machine uses less resources than OHE and also gets good speed. Gray encoding is also the most reliable encoding technique, because only one bit changes per transition. However, Gray encoding requires the designer to be very aware of the coding technique chosen when simulating the FSM, and this is often a pain.
Subscribe to:
Posts (Atom)