# JTAG and I2C Locking

The new locker objects are recommended as a replacement for some of the itp type of control variables. Specifically, the jtag locker is recommended instead of trying to use the old “itp.cv.manualscans”. The with syntax provided by Python will make sure that an unlock is always called even when there is an exception. The IPC API handles the actual lock and unlock count so that recursive lock/unlock calls are safe.

## JTAG Locking

Commands.device_locker(device=None, queue=None)

  This returns a context manager which ensures that the jtag probe allows access only to the thread within the jtag_lock’s containing block. Use only within a ‘with’ block.

  Parameters

    - device (int) – Optional device id of the jtag interface to execute the lock on. if None is provided (default), then all jtag chains will have the lock called on them.

    - queue (bool) – whether to queue up transactions during the lock so that they get issued all at once.

  Example

      >>> with ipc.device_locker() as lock:
      ...     # no other jtag operations from other windows or Trace32
      ...     # will interrupt the instructions in this block
      ...     itp.irdrscan(...)
      ...     itp.irdrscan(...)

## I2C Locking

Commands.i2c_locker(device=None)

  This returns a context manager which ensures that the i2c bus allows access only to the thread within the i2c_lock’s containing block. It calls the py2ipc i2c Lock and Unlock API. The Lock will force repeated starts between the various SMBUS commands that are within the ‘with’ block.

  Parameters

    device (int) – Optional device id of the i2c interface to execute the lock on. if None is provided (default), then all i2c devices will have the lock called on them.

  Use only within a ‘with’ block.

  Example

      >>> with ipc.i2c_locker() as lock:
      ...     # a repeated stop will be inserted between these two
      ...     itp.i2c_raw_write(...)
      ...     itp.i2c_raw_read(...)