<@U016EM8L91B> I'm new to magic and trying to writ...
# magic
y
@User I'm new to magic and trying to write some customized tcl codes based on sky130.tcl. Below is my functions.tcl
Copy code
proc shift_to_center {} {
    set res1 [box size]
    move [expr {-[lindex $res1 0] / 2}]i [expr {-[lindex $res1 1] / 2}]i
}

proc place_pmos {x_center y_center index {m 1}} {
    select clear
    puts "index: $index"
    puts "m: $m"
    puts "x_center: $x_center"
    puts "y_center: $y_center"
    box [expr $x_center]um [expr $y_center]um [expr $x_center]um [expr $y_center]um  
    set parameters [sky130::sky130_fd_pr__pfet_01v8_lvt_defaults]
    # customize m
    if {$m} {dict set paramete m $m}
    puts "cell_parameter: $parameters"
    magic::gencell sky130_fd_pr__pfet_01v8_lvt [format "xm%d" $index] $parameters
    shift_to_center
}
While source functions.tcl and put in "place_pmos 100 100 1 2", I got below error in magic, I wonder why default parameters couldn't work. Do you have any suggestions?
t
Because you have a typo in the line
if {$m} {dict set paramete m $m}
.
y
Sorry for my typo, while actually the typo is made when I was debugging, even there is
if {$m} {dict set parameters m $m}
, the same error persists
t
Ah, sorry, I didn't look past the immediate error. This is a tricky aspect of Tcl/Tck. The
gencell(...)
call has arguments
gencell_name instance_name parameter0_name value0 parameter1_name value1 . . .
, so the parameters are given to the function in expanded form, not as a dictionary. If you have a dictionary already, then you want to expand it by doing:
eval magic::gencell sky130::sky130_fd_pr__ pfet_01v8_lvt [format "xm$d" $index] $parameters
. Note that in addition to needing to preface the statement with
eval
, I also need to give the fully-qualified name with namespace
sky130::
, because the routine picks up the library name from that prefix.
y
Thank you so much, it works now. Btw do you know where could I find those magic layout related tcl/python (example) codes/docs? I don't want to trouble you too much about similar errors I might make in the future. So far I only find below related links: http://opencircuitdesign.com/magic/ https://www.tcl.tk/man/tcl8.5/TclCmd/contents.html https://github.com/RTimothyEdwards/magic/tree/a5e0de031cc425dd4f6015d30bdf5b183fa69392/tcltk and some scripts under open-pdks/magic directory. I'd appreciate a lot if you could recommend other repos/docs that write code to generate layout (PnR) in the Magic :)
t
I have not written any comprehensive how-to for the PDK toolkit extensions to magic. The best resource is some of the code in the Tcl scripts. In the magic repository under
tclck/tookit.tcl
(the same script that defines the
gencell
procedure), there is a procedure called
netlist_to_layout
that is probably the most relevant. The Sky130 PDK for magic installs the
File -> Import SPICE
menu item, which invokes the
netlist_to_layout
procedure, which places cells, creates pins, and generates a subcircuit hierarchy from a SPICE netlist.
y
Got it, thank you so much!