MyHDL - это язык описания оборудования (HDL) на основе Python.
Возможности MyHDL включают:
MyHDL разработан Яном Декалуве.
Здесь вы можете увидеть несколько примеров преобразования проектов MyHDL в VHDL и / или Verilog.
Небольшой комбинаторный дизайн
Примером является небольшая комбинаторная конструкция, в частности преобразователь двоичного кода в код Грея:
def bin2gray(B, G, width: int): """Gray encoder. B -- input intbv signal, binary encoded G -- output intbv signal, gray encoded width -- bit width """ @always_comb def logic(): Bext = intbv(0)[width + 1:] Bext[:] = B for i in range(width): G.next[i] = Bext[i + 1] ^ Bext[i] return logic
Вы можете создать экземпляр и преобразовать его в Verilog и VHDL следующим образом:
width = 8 B = Signal(intbv(0)[width:]) G = Signal(intbv(0)[width:]) bin2gray_inst = toVerilog(bin2gray, B, G, width) bin2gray_inst = toVHDL(bin2gray, B, G, width)
Сгенерированный код Verilog выглядит следующим образом:
module bin2gray ( B, G); input [7:0] B; output [7:0] G; reg [7:0] G; always @(B) begin: BIN2GRAY_LOGIC integer i; reg [9-1:0] Bext; Bext = 9'h0; Bext = B; for (i=0; ilt;8; i=i+1) begin G[i] lt;= (Bext[(i + 1)] ^ Bext[i]); end end endmodule
Сгенерированный код VHDL выглядит следующим образом:
library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use std.textio.all; use work.pck_myhdl_06.all; entity bin2gray is port ( B: in unsigned(7 downto 0); G: out unsigned(7 downto 0)); end entity bin2gray; architecture MyHDL of bin2gray is begin BIN2GRAY_LOGIC: process (B) is variable Bext: unsigned(8 downto 0); begin Bext:= to_unsigned(0, 9); Bext:= resize(B, 9); for i in 0 to 8-1 loop G(i) lt;= (Bext((i + 1)) xor Bext(i)); end loop; end process BIN2GRAY_LOGIC; end architecture MyHDL;