Last active
August 29, 2015 14:23
-
-
Save shtaxxx/952b448de043498f95e2 to your computer and use it in GitHub Desktop.
Blinking LED on PyMTL
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
from pymtl import * | |
class LedRTL( Model ): | |
def __init__( s ): | |
s.led = OutPort( 8 ) | |
s.count = Wire( 32 ) | |
s.led_count = Wire( 8 ) | |
@s.tick_rtl | |
def seq(): | |
if s.count == 1023: | |
s.count.next = 0 | |
s.led_count.next = s.led_count + 1 | |
else: | |
s.count.next = s.count + 1 | |
@s.combinational | |
def comb(): | |
s.led.value = s.led_count |
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
//----------------------------------------------------------------------------- | |
// LedRTL_0x791afe0d4d8c | |
//----------------------------------------------------------------------------- | |
// dump-vcd: False | |
`default_nettype none | |
module LedRTL_0x791afe0d4d8c | |
( | |
input wire [ 0:0] clk, | |
output reg [ 7:0] led, | |
input wire [ 0:0] reset | |
); | |
// register declarations | |
reg [ 31:0] count; | |
reg [ 7:0] led_count; | |
// PYMTL SOURCE: | |
// | |
// @s.tick_rtl | |
// def seq(): | |
// if s.count == 1023: | |
// s.count.next = 0 | |
// s.led_count.next = s.led_count + 1 | |
// else: | |
// s.count.next = s.count + 1 | |
// logic for seq() | |
always @ (posedge clk) begin | |
if ((count == 1023)) begin | |
count <= 0; | |
led_count <= (led_count+1); | |
end | |
else begin | |
count <= (count+1); | |
end | |
end | |
// PYMTL SOURCE: | |
// | |
// @s.combinational | |
// def comb(): | |
// s.led.value = s.led_count | |
// logic for comb() | |
always @ (*) begin | |
led = led_count; | |
end | |
endmodule // LedRTL_0x791afe0d4d8c | |
`default_nettype wire | |
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
from pymtl import * | |
from ledRTL import LedRTL | |
def test_simple( test_verilog ): | |
model = LedRTL() | |
if test_verilog: | |
model = TranslationTool( model ) | |
model.elaborate() |
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
VERILATOR=~/prog/pymtl/verilator/ | |
source ./bin/activate | |
export PATH=$VERILATOR/bin/:$PATH | |
export PYMTL_VERILATOR_INCLUDE_DIR=$VERILATOR/include | |
export VERILATOR_ROOT=$VERILATOR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment