-
A component can be created from an existing one(clone it):
inv = Component('inv')
inv.add_pin(Input('A'))
inv.add_pin(Output('Z'))
inv_cloned = Component('inv2', inv)
-
Salamandra can use busses also:
and_ = Component('and')
and_.add_pinbus(Bus(Input, 'A', 2)) # arguments: type-input, bus_name-A, width-2.
and_.add_pin(Output('Z'))
nand = Component('nand')
nand.add_pinbus(Bus(Input, 'A', 2))
nand.add_pin(Output('Z'))
nand.add_net(Net('A1A2'))
nand.add_subcomponent(and_, 'i_and')
nand.add_subcomponent(inv, 'i_inv')
nand.connect_bus('A', 'i_and.A') # connect_bus for busses
nand.connect('A1A2', 'i_and.Z')
nand.connect('A1A2', 'i_inv.A')
nand.connect('Z', 'i_inv.Z')
# now the connectivity is:
# //instances
# and i_and(.A({A[1:0]}), .Z(A1A2));
# inv i_inv(.A(A1A2), .Z(Z));
# you can disconnect them also
nand.disconnect('i_inv.Z')
nand.disconnect_bus('i_and.A')
# and after disconnect the connectivity is:
# //instances
# and i_and(.A(), .Z(A1A2));
# inv i_inv(.A(A1A2), .Z());
-
Pins can also be connected to constants like 1'bx, 1'b1 or 1'b0
-
And if you want to map constants('1', '0') to 'tiehi' and 'tielo' driver cells,
it can be done with hilomap function:
tielo = Component('tielo')
tielo.add_pin(Output('Y'))
tiehi = Component('tiehi')
tiehi.add_pin(Output('Y'))
inv.add_pin(Inout('VDD'))
nand.connect("1'b1", 'i_inv.VDD')
# relevant verilog print:
# //instances
# and i_and(.A(), .Z(A1A2));
# inv i_inv(.A(A1A2), .VDD(1'b1), .Z()); # 1'b1 connected to VDD
nand.hilomap(tiehi, tielo)
# relevant verilog print:
# //instances
# and i_and(.A(), .Z(A1A2));
# inv i_inv(.A(A1A2), .VDD(HI), .Z()); # connected VDD to tiehi output
# tiehi tiehi(.Y(HI)); # added tiehi instance to component
-
If you want to uniquify the instances in the netlist,
e.g., every instance of a component will be a new component,
you can do this using the uniq() function:
nand.add_subcomponent(inv, 'i_inv2')
# now there are two instances of inv component: 'i_inv1', 'i_inv2'
# relevant verilog print:
# //instances
# inv i_inv(.A(A1A2), .VDD(HI), .Z());
# inv i_inv2(.A(), .VDD(), .Z());
nand.uniq()
# now there are two components of inv(inv_0, inv_1), one for each instance
# relevant verilog print:
# //instances
# inv_0 i_inv(.A(A1A2), .VDD(HI), .Z());
# inv_1 i_inv2(.A(), .VDD(), .Z());
-
Salamandra also supports assignments using the connect_nets() function:
inv = Component('inv')
inv.add_pin(Input('A'))
inv.add_pin(Output('Z'))
# add_pin also add Net with same name attached to this pin
# you can disable it with add_pin_adds_net in Component
inv.connect_nets('A', 'Z')
# relevant verilog print:
# //assignments
# assign Z = A;
-
You can flatten your netlist using flatten function, this will flatten your
netlist until the physical components (checking with __is_physical flag):
inv.set_is_physical(True)
and_.set_is_physical(True)
# we will add another wrapper to nand(that we saw earlier)
chip = Component('chip')
chip.add_pinbus(Bus(Input, 'A', 2))
chip.add_pin(Output('Z'))
chip.add_subcomponent(nand, 'nand')
chip.connect_bus('A', 'nand.A')
chip.connect('Z', 'nand.Z')
chip.print_verilog()
# relevant verilog print:
# //wires
# wire [1:0] A;
# wire Z;
#
# //instances
# nand nand(.A({A[1:0]}), .Z(Z));
chip.flatten()
chip.print_verilog()
# relevant verilog print:
# //wires
# wire [1:0] A;
# wire Z;
# wire nand__A1A2;
#
# //instances
# and nand__i_and(.A({A[1:0]}), .Z(nand__A1A2));
# inv nand__i_inv(.A(nand__A1A2), .Z(Z));
We can see that it added its inner nets,
subcomponents and their connectivity to itself,
adding the component name as a prefix (e.g., "A1A2" -> "nand__A1A2")
-
You can also add properties to objects (pin/net/bus/component) like add tpd value to pin, or 'is_clk' flag
and after that you can filter pins (or subcomponents/nets...) like this:
inv = Component('inv').set_property('is_optimized', True) # set_property(property, value)
inv.add_pin(Input('A').set_property('tpd', 0.1))
inv.add_pin(Inout('VDD').set_property('is_supp', True))
# now we can get filterd pins as we wish
fast_pins = inv.get_pins(filter=lambda p: p.get_property('tpd') and p.get_property('tpd') < 0.2)
vdd_pins = inv.get_pins(filter=lambda p: p.get_property('is_supp'))
-
If you want to get component's connectivity paths, you can get this with connectivity_paths method
which will return 3 dictionaries, one dict that has all connectivity, forward and backward of pins&nets.
second dict that has forward connectivity, and third backward connectivity.
for example:
all_connectivity_dict:
(('A',Input): [('A',Net)], ('A',Net): [('A',Input),('X.A',Input),..])
forward connectivity dict:
(('A',Input): [('A',Net)], ('A',Net): [('X.A',Input)], ('X.A',Input): [('X.O',Output)],..)
-
Before you export your netlist you can add verilog code to your netlist:
y = Net('y')
nand.add_net(y)
nand.add_verilog_code("\tassign {}=1'b0;".format(y.get_object_name()))
# relevant verilog print:
# //verilog code
# assign y=1'b0;