-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from zapta/master
Assorted examples tweaks.
- Loading branch information
Showing
14 changed files
with
133 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Blink all leds |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
A simple clock divider. It produces two clocks with 1/4 of the input frequency. One with the original phase and one shifted by 90 degrees. This divider by itself could run at >200 MHz. | ||
A 1/4 clock divider with 0 and 90 degress outputs. |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Frère Jacques, a two voices melody (see README.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Utility macros for testbenches that are compatible with apio. | ||
|
||
`default_nettype none | ||
|
||
`define DUMP_FILE_NAME(x) `"x.vcd`" | ||
|
||
// Call this macro at the begining of the testbench macro. It defines | ||
// a clk signal and a variable clk_num that indicates the clock num. | ||
`define DEF_CLK \ | ||
reg clk = 0; \ | ||
integer clk_num = 0; \ | ||
always begin \ | ||
#10 clk = ~clk; \ | ||
if (clk) clk_num += 1; \ | ||
end | ||
|
||
// Asserts that the value of 'signal' is 'value'. If not, it prints an error message and aborts | ||
// the simulation. When running under apio sim, the macro INTERACTIVE_SIM is defined | ||
// and the failed assertions does not exist to allow showing the sigmulation results | ||
// in the graphical window. | ||
`define EXPECT(signal, value) \ | ||
if (signal !== (value)) begin \ | ||
$display("*** ASSERTION FAILED in %m (clk_num=%0d): expected (signal == value), actual: 'h%h", (clk_num), (signal)); \ | ||
`ifndef INTERACTIVE_SIM \ | ||
$fatal; \ | ||
`endif \ | ||
end | ||
|
||
// Transition from clock low to clock high. Typically this is not | ||
// called directly and clock is managed using `CLK(). | ||
`define CLK_HIGH \ | ||
begin \ | ||
`EXPECT(clk, 0); \ | ||
@ (posedge clk); \ | ||
#2; \ | ||
`EXPECT(clk, 1); \ | ||
end | ||
|
||
// Transition from clock high to clock low. Typically this is not | ||
// called directly and clock is managed using `CLK(). | ||
`define CLK_LOW \ | ||
begin \ | ||
`EXPECT(clk, 1); \ | ||
@ (negedge clk); \ | ||
#2; \ | ||
`EXPECT(clk, 0); \ | ||
end | ||
|
||
// Simulate one clock. Wait for low to high and then high to low transition. | ||
`define CLK \ | ||
begin \ | ||
`CLK_HIGH \ | ||
`CLK_LOW \ | ||
end | ||
|
||
// Simulate n clocks. | ||
`define CLKS(n) \ | ||
begin \ | ||
repeat(n) begin \ | ||
`CLK \ | ||
end \ | ||
end | ||
|
||
// Place this macro immediatly after the 'initial begin' statement of the testbench. | ||
// 'testbench' is the name of the testbench module. The macro sets the file | ||
// that will contains the simulation results. | ||
// The macro VCD_OUTPUT is defined automatically by the apio commands sim and test | ||
// and contains base name of the expected output file. | ||
`define TEST_BEGIN(testbench) \ | ||
begin \ | ||
`ifdef VCD_OUTPUT \ | ||
$dumpfile(`DUMP_FILE_NAME(`VCD_OUTPUT)); \ | ||
$dumpvars(0, testbench); \ | ||
`else \ | ||
$fatal(1, "Automatic macro VCD_OUTPUT not defined."); \ | ||
`endif \ | ||
end | ||
|
||
// Place this macro at the end of the 'initial begin' block of the testbench. | ||
`define TEST_END \ | ||
begin \ | ||
@ (posedge clk); \ | ||
$display("End of simulation"); \ | ||
$finish; \ | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters