Skip to content

Instantly share code, notes, and snippets.

@shtaxxx
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shtaxxx/952b448de043498f95e2 to your computer and use it in GitHub Desktop.
Save shtaxxx/952b448de043498f95e2 to your computer and use it in GitHub Desktop.
Blinking LED on PyMTL
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
//-----------------------------------------------------------------------------
// 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
from pymtl import *
from ledRTL import LedRTL
def test_simple( test_verilog ):
model = LedRTL()
if test_verilog:
model = TranslationTool( model )
model.elaborate()
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