; --------------------------------------------------------------------------------
; @Title: Cross-connect PowerView instances with SYnch
; @Description:
;   This script configures SYnch.Connect and SYnch.XTRACK to cross-connect
;   all PowerView instances which are currently connected to the same
;   debug module as the local PowerView isntance.
;
;   Note: INTERCOM must be enabled for all connected PowerView instances.
;
;   Usage: Call without parameter
;   DO ~~/demo/practice/intercom/synch_xconnect.cmm
;
; @Author: REI
; @Copyright: (C) 1989-2014 Lauterbach GmbH, licensed for use with TRACE32(R) only
; --------------------------------------------------------------------------------
; $Id: synch_xconnect.cmm 8581 2015-08-17 14:15:21Z wwbenayed $


; get command line parameters
  LOCAL &command &index &port
  ENTRY &command

; called without command -> run this  script with parameter COMMAND_CONNECT
  IF "&command"==""
  (
  ; iterate through all PowerView instances to run cross-connect script
    &index=0
    WHILE &index<INTERCOM.PODPORTNUMBER()
    (
      IF INTERCOM.PODPORT(&index)==INTERCOM.PORT() ;port of local instance?
        DO "~~/demo/practice/intercom/synch_xconnect.cmm" COMMAND_CONNECT    
      ELSE
      (
        &port=INTERCOM.PODPORT(&index)
        INTERCOM.EXECUTENoWait &port DO "~~/demo/practice/intercom/synch_xconnect.cmm" COMMAND_CONNECT
      )

      &index=&index+1
    )
    ENDDO
  )

; called with COMMAND_CONNECT -> cross-connect instances
  IF "&command"=="COMMAND_CONNECT"
  (
  ; enumerate all INTERCOM ports and cross-connect all instances
    LOCAL &portlist
    &portlist=""

  ; generate port list (excluding local port)
    &index=0
    WHILE &index<INTERCOM.PODPORTNUMBER()
    (
      LOCAL &port
      &port=INTERCOM.PODPORT(&index)
      IF &port!=INTERCOM.PORT()
        &portlist="&portlist "+FORMAT.DECIMAL(1.,&port)
      &index=&index+1
    )

    PRINT "Found PowerView instances on INTERCOM ports: &portlist"

  ; connect to all instances
    SYnch.Connect &portlist
    SYnch.XTrack  &portlist
    
    ENDDO
  )

ENDDO
