Restrict

restrict can be used in coordination with require to add specific constraints on which pins are valid. We can specify all pins in a bundle to come from a specific IO bank, or that a timer has some advanced feature, or has a specific electrical property.

Notes:

  • The restrict syntax is purposefully verbose.
  • All pins that could be mapped to the restricted bundle pin must have the pin property.

Syntax

The general form of a restrict statement is:

  require <pin>:<bundle>
  restrict(<pin of required bundle>,
    ;Inlining a function.
    ;mypin is the name of the function parameter. It can be named anything.
    fn (mypin) :
      ;A restriction based on a pin property.
      ;This restrict statement ensures that the assigned pin will pin-property > 10.0.
      property(mypin.<pin-property>) > 10.0)
pcb-module restrict-one-pin :
  pin p
  property(p.active) = true

  supports gpio :
    gpio.gpio => p
  
  require g:gpio from self
  restrict(g.gpio,
    fn (mypin) :
      property(mypin.active))

pcb-module restrict-in-option :
  pin p
  pin q

  property(p.active) = true
  property(q.active) = false

  pcb-bundle bund1 :
    pin p

  pcb-bundle bund2 :
    pin x
    pin y

  supports bund2 :
    bund2.x => p
    bund2.y => q

  supports bund1 :
    require my2:bund2 from self
    restrict(my2.x,
      fn (mypin) :
        property(mypin.active))
    bund1.p => my2.x
  
  ;If p and q are swapped above, the pin solver cannot find a solution.
  require my1:bund1 from self

Description

This module supports a gpio, and requires a gpio with a restriction that the pin is active based on the property active.

pcb-module restrict-one-pin :
  pin p
  property(p.active) = true

  supports gpio :
    gpio.gpio => p
  
  require g:gpio from self
  restrict(g.gpio,
    fn (mypin) :
      property(mypin.active))

Restrictions can also be applied on required pins in a support statement. This module supports bund1 and bund2 bundles. bund1 requires a bund2 with the restriction that x pin is active. When bund1 is required, the solver can find a solution. If q was active instead of p, no solution would be found.

pcb-module restrict-in-option :
  pin p
  pin q

  property(p.active) = true
  property(q.active) = false

  pcb-bundle bund1 :
    pin p

  pcb-bundle bund2 :
    pin x
    pin y

  supports bund2 :
    bund2.x => p
    bund2.y => q

  supports bund1 :
    require my2:bund2 from self
    restrict(my2.x,
      fn (mypin) :
        property(mypin.active))
    bund1.p => my2.x
  
  ;If p and q are swapped above, the pin solver cannot find a solution.
  require my1:bund1 from self