; --------------------------------------------------------------------------------
; @Title: Tracing Vector Timing Hooks via selective Data Trace
; @Description: This script sets up the data trace to trace the events
;   generated by the TRACE32 specific instrumentation of the
;   Vector Timing Hooks (VTH). In particular, tracing of the
;   variables trace32_runnable/arti_rte_trace and
;   trace32_taskevent/arti_os_trace is set.
;
; @Keywords: multi-core
; @Author: DIE
; @Copyright: (C) 1989-2020 Lauterbach GmbH, licensed for use with TRACE32(R) only
; @Props: NoWelcome, NoIndex
; --------------------------------------------------------------------------------
; $Id: vth_data_trace.cmm 14610 2020-04-27 09:37:00Z rdienstbeck $

LOCAL &Addr_runnable &AddrRange_runnable
LOCAL &Addr_taskevent &AddrRange_taskevent
LOCAL &runnableexists

&runnableexists=FALSE()

; Check if variables exist
IF !Var.EXIST(trace32_taskevent)
(
  IF !Var.EXIST(arti_os_trace)
  (
    PRINT %ERROR "Variable trace32_taskevent or arti_os_trace does not exist!"
    ENDDO
  )
)

IF Var.EXIST(trace32_runnable)||Var.EXIST(arti_rte_trace)
(
  &runnableexists=TRUE()
)

IF Var.EXIST(trace32_taskevent)
(
  &Addr_taskevent=Var.ADDRESS(trace32_taskevent)
  &Addr_taskevent=ADDRESS.OFFSET(&Addr_taskevent)
  &AddrRange_taskevent=Var.RANGE(trace32_taskevent)
)
ELSE
(
  &Addr_taskevent=Var.ADDRESS(arti_os_trace)
  &Addr_taskevent=ADDRESS.OFFSET(&Addr_taskevent)
  &AddrRange_taskevent=Var.RANGE(arti_os_trace)
)

IF Var.EXIST(trace32_runnable)
(
  &Addr_runnable=Var.ADDRESS(trace32_runnable)
  &Addr_runnable=ADDRESS.OFFSET(&Addr_runnable)
  &AddrRange_runnable=Var.RANGE(trace32_runnable)
)
ELSE IF Var.EXIST(arti_rte_trace)
(
  &Addr_runnable=Var.ADDRESS(arti_rte_trace)
  &Addr_runnable=ADDRESS.OFFSET(&Addr_runnable)
  &AddrRange_runnable=Var.RANGE(arti_rte_trace)
)


; Check if Analyzer is available
IF !Analyzer()&&!CAnalyzer()&&!Onchip()
(
  PRINT %ERROR "No Trace available!"
  ENDDO
)

; Clear all Trace Breakpoints
Break.Delete /TraceEnable
Break.Delete /TraceData
Break.Delete /TraceON
Break.Delete /TraceOFF
Break.Delete /TraceTrigger

; Set data trace breakpoints
Break.Set &AddrRange_taskevent /Write /TraceEnable
if &runnableexists
    Break.Set &AddrRange_runnable /Write /TraceEnable

ENDDO
