I have just started with MyHDL and was able to build a demo ip core with it. https://github.com/bonfireprocessor/bonfire-pwm
The project is a simple PWM driver for RGB LEDs with a Wishbone interface.
The only thing I’m struggling with is, that I don’t find a way to dynamically change the top level ports (my target language is VHDL).
The number of LEDs to support is configurable. I want a red, green, blue output port per LED on the VHDL toplevel.
I have not figured out how to do it. I created a class rgb_bundle
class rgb_bundle:
def __init__(self):
self.red=Signal(bool(0))
self.green=Signal(bool(0))
self.blue=Signal(bool(0))
When I create a single Signal instance of it and pass it to my toplevel block it works fine.
But I want a dynamic number of rgb_bundles which are mapped to ports.
When I pass a list of rgb_bundles it is completely ignored.
My current testcode looks like:
from myhdl import *
from rgb_bundle import *
from bonfire_led_pwm import *
from wishbone_bundle import *
numChannels=4
wb = Wishbone_bundle(False,4,2,32,False,False)
rgb={}
for i in range(4):
rgb["rgb_"+str(i)]=rgb_bundle()
clock = Signal(bool(0))
reset = ResetSignal(0, active=1, isasync=False)
@block
def test(wb,clock,reset,rgb_0,rgb_1, **kwagrs):
@always_seq(clock.posedge,reset=reset)
def dummy():
pass
return instances()
test_01=test(wb,clock,reset,**rgb)
The conversion looks as I want it:
entity test is
port (
clock: in std_logic;
reset: in std_logic;
rgb_0_blue: in std_logic;
rgb_0_green: in std_logic;
rgb_0_red: in std_logic;
rgb_1_blue: in std_logic;
rgb_1_green: in std_logic;
rgb_1_red: in std_logic;
wb_we: in std_logic;
wb_adr: in std_logic_vector(1 downto 0);
wb_stb: in std_logic;
wb_ack: in std_logic;
wb_cyc: in std_logic;
wb_db_read: in std_logic_vector(31 downto 0);
wb_db_write: in std_logic_vector(31 downto 0)
);
end entity test;
It works because I have hard coded the parameters rgb_1 and rgb_2 for testing purposes, but of course this is not the solution.
I must confess that I’m not proficient in Python.
I hope somebody here can help me.
Thomas
Edit: Fixed the block quotes