Glade Reference


Callbacks are python functions associated with properties. They provide a way of updating some properties when others change. For example, consider a finfet nmos transistor. The user is allowed to enter the number of fins as a parameter; the device width will be a function of this number.

We can define a callback python function, as:

          # Example callback for nmos device. To use, set the property
          # callback on the nmos symbol.
          # The callback is always passed a parameter 'pyDBObject'
          # which is the dbObj we have set the callback on.
          # This code just sets a w/l property based on the fingers/fins properties.
          # We assume they are integer types...
          def nmos_cb(pyDBObject) :
              ##print('callback : nmos_cb()')
              # We only want to apply this callback to instances.
              # Cast the object to an inst:
              inst = pyDBObject.toInst()
              if inst is not None :
                  fins = inst.dbGetIntProp('fins')
                  if fins < 2 :
                  print('fins must be > 1 (got ', fins, ')')
                  raise ValueError
                  fingers = inst.dbGetIntProp('fingers')
                  if fingers < 1 :
                  print('fingers must be > 0 (got ', fingers, ')')
                  raise ValueError 
                  # Width is based on number of fins...
                  width = fingers * ((fins-1) * 0.040) + 0.08
                  # Length is fixed...
                  length = 0.020 
                  # Convert the l/w values to a string.
                  # We should use dbU from instance, not 1000
                  w = str(int(width*1000)) + 'n'
                  l = str(int(length*1000)) + 'n'
                  # We use dbAddProp rather than dbReplaceProp 
                  # in case the property does not exist. If the
                  # property does exist, dbAddProp will replace
                  # it.
                  inst.dbAddProp('w', w)
                  inst.dbAddProp('l', l)
              # if inst
          # def

Note in the above we give the function a variable name 'pyDBObject' as argument. The value of this will be the object the property is set on. Normally this would be an instance, but it could be any object derived from a dbObj including a cellView, rectangle etc.


We then query the properties of the nmos symbol and add the callback function name to the parameters 'fins' and 'fingers':


Note that we just specify the callback function name. We do not include the parenthesis or argument.


Now, if we place an instance of this symbol in a schematic and set its properties using the Query property dialog or the Create Instance property dialog, if we change either the fins or fingers property values and apply or OK the dialog, the w/l property values are updated accordingly.



The callback functions must be present in the PYTHONPATH env var, as is the case with PCells, so Glade can find them. Their file names must match the function name also.




Copyright © Peardrop Design 2024.