Package: pygears
HW Design: A Functional ApproachPyGearsis a free framework that lets you design hardware using high-level Python constructs and compile it to synthesizable SystemVerilog or Verilog code. There is a built-in simulator that lets you use arbitrary Python code with its vast set of libraries to verify your hardware modules.PyGearsmakes connecting modules easy, and has built-in synchronization mechanisms that help you build correct parallel systems.@geardefecho(samples:Fixp,*,feedback_gain,sample_rate,delay):sample_dly_len=round(sample_rate*delay)fifo_depth=ceil_pow2(sample_dly_len)feedback_gain_fixp=samples.dtype(feedback_gain)dout=Intf(samples.dtype)feedback=decouple(dout,depth=fifo_depth)\|prefill(dtype=samples.dtype,num=sample_dly_len)feedback_attenuated=(feedback*feedback_gain_fixp)\|samples.dtypedout|=(samples+feedback_attenuated)|samples.dtypereturndoutPython functions model hardware modules, where function arguments represent module inputs and parameters. Exampleechomodule has a single input port calledsampleswhere data of arbitrary signed fixed-point typeFixpcan be received. Other three parametersfeedback_gain,sample_rateanddelayare compile time parameters.@geardefecho(samples:Fixp,*,feedback_gain,sample_rate,delay):...Arbitrary Python code can be used in modules at compile time, for an example to transform input parameters:sample_dly_len=round(sample_rate*delay)fifo_depth=ceil_pow2(sample_dly_len)feedback_gain_fixp=samples.dtype(feedback_gain)Rest of theechofunction code describes the hardware module for applying echo audio effect to the input stream.Modules are instantiated using function calls:decouple(dout, depth=fifo_depth), which return module output interfaces that can in turn be passed as arguments to other module functions in order to make a connection between the modules. For conveniance the pipe"|"operator can be used to pass output of one function as argument to the next one. This was used to connect the output ofdecoupletoprefill("\"is used just to split the line visually):feedback=decouple(dout,depth=fifo_depth)\|prefill(dtype=samples.dtype,num=sample_dly_len)Again, theechofunction returns its output interfaces which is then used to establish the connection with the next module that received theechooutput stream:@geardefecho(...):...returndoutBuilt-in simulator makes it easy to test and verify the modules while drawing power from the Python vast ecosystem of libraries. For an example, use Python built-inaudiooplibrary to read WAV files into an input samples stream for theechomodule, and then visualise the input and output waveforms usingmatplotlib:Speedup the simulation by configuringPyGearssimulator to use open-sourceVerilatorto simulate hardware modules, or some of the proprietary simulators like Questa, NCSim or Xsim. Implement any part of the system in a standard HDL and debug your design by inspecting the waveforms for an example in open-source wave viewerGTKWaveCheckoutEcho example descriptionfor more in depth information about theechoexample.Installation instructionsInstallPyGearspackage with the Python package manager. On Linux distributions, depending on how your Python was installed you might get an error and need to prefix the command withsudo:pip3installpygearsFor more detailed installation instructions (including how to install additional software) checkoutInstallationpage.Read the documentationPyGears documentationCheckout the examplesLibrary of standard modulesEcho: Hardware module that applies echo audio effect to a continuous audio stream.RISC-V processor:PyGearsimplementation. Checkout also theRISC-V implementation blog series.Tests: Contain many examples on how individualPyGearscomponents operateContributionsSpecial thanks to the people that helped develop this framework:Andrea ErdeljanDamjan RakanovićNemanja KajtezRisto PejašinovićStefan TamburVladimir NikićVladimir VrbaškiIn order to contribute, pull your copy fromgithub repositoryand create a pull request.