;------------------------------------------------------------------------------------
; 14 Jun 22 - Richard Woodruff - Adapt J721S2 for J784S4.
; 14 Nov 22 - Richard Woodruff - Change DSP reset unmask
; 27 Jan 23 - Richard Woodruff - Adjust for 02.2023 path handling
; 12 Dec 23 - Richard Woodruff - Add CLEC claim option for C7x PBIST test in SDK9
;------------------------------------------------------------------------------------
; Launch TEST on C7000 core for FreeRTOS
;
; 1: Update Paths & core selection to match what test should be loaded.
; 2: Launch a t32marm 32-bit PowerView instance to run the script
; !! Make sure to include debug symbols in any compile or FreeRTOS will not show up

 &tst="ipc"     ; {"ut","ts","ipc"}

; Add Linux or Windows paths to component symbols
 &path=OS.PPD()
 &opath="d:"
;&opath="/opt"

 LOCAL &clust &tst &tst_src &tst_nam &RTOS

 &RTOS="FREERTOS"
 &CCLEC=""         ; "CCLEC"

 &clust="C71X-1" ; C71X-0, C71X-1, C71X-2, C71X-3

; Add paths to component symbols
 &sdk_base="&opath/syms/dra829/pdk"
 &freertos_src="&sdk_base/packages/ti/kernel/freertos"
 &ts_src="&freertos_src/test/freertos/task_switch"
 &ut_src="&freertos_src/test/freertos/ut"
 &ipc_src="&freertos_src/test/freertos/ipc_echo_test"                 ; need update

 &freertos_bin="&opath/syms/j784s4"

 &tst_prefix="freertos_test_"

 IF "&tst"=="ut"
 (
   &tst_src="&ut_src"
   &tst_nam="ut"
 )
 ELSE IF "&tst"=="ts"
 (
   &tst_src="&ts_src"
   &tst_nam="task_switch"
 )
 ELSE
 (
   &tst_src="&ipc_src"
   &tst_nam=""
   &tst_prefix="ipc_echo_test_freertos"
   &freertos_bin="&opath/syms/j784s4"
 )

 IF "&clust"=="C71X-0"
   &nm="1"
 ELSE IF "&clust"=="C71X-1"
   &nm="2"
 ELSE IF "&clust"=="C71X-2"
   &nm="2"
 ELSE IF "&clust"=="C71X-3"
   &nm="3"
 &tst="&freertos_bin/"+"&tst_prefix"+"&tst_nam"+"_c7x_"+"&nm"+"_release.xe71"
;&tst="&freertos_bin/"+"&tst_prefix"+"&tst_nam"+"_c7x_+"&nm"+_debug.xe71"   ; has RTOS aware sysmbols

 DO "~~~~/pdk_launch_js_common.cmm" &RTOS &CCLEC

 IF !INTERCOM.PING(C71)
        TargetSystem.NewInstance C71 /ARCHitecture C7000
 InterCom.WAIT C71
 InterCom C71 TITLE "TRACE32 for J784S4-C71 - SLAVE"

 ; release C71 from reset
 IF "&clust"=="C71X-0"
   Data.Set EDBG:0x40000320 %Long 0yxxxxxxxxxxxxxx10001xxxxxxxxxxxxx
 ELSE IF "&clust"=="C71X-1"
   Data.Set EDBG:0x40000324 %Long 0yxxxxxxxxxxxxxx10001xxxxxxxxxxxxx
 ELSE IF "&clust"=="C71X-2"
   Data.Set EDBG:0x40000328 %Long 0yxxxxxxxxxxxxxx10001xxxxxxxxxxxxx
 ELSE
   Data.Set EDBG:0x4000032c %Long 0yxxxxxxxxxxxxxx10001xxxxxxxxxxxxx

 InterCOM C71 DO "&path/../_J784S4_c7x.cmm" "&clust"
 InterCom.WAIT C71

;Load PDK test
 InterCom C71 Data.LOAD.elf "&tst" /plusvm
 InterCom.WAIT C71

; load up source paths
 ;InterCom C71 symbol.sourcepath.setrecursedir &freertos_src
 ;InterCom C71 symbol.sourcepath.setrecursedir + &tst_src
 ;InterCom C71 symbol.sourcepath.setrecursedir + &ndk_base

 InterCom C71 data.list

 ;InterCom C71 b.s exit /onchip

 InterCom C71 FramePOS ,,,, Top
 InterCom C71 wintop uart

 InterCom C71 go main /onchip   ; Run till main and stop
 InterCom.WAIT C71 !RUN()

 ; Load FreeRTOS awareness
 InterCom C71 task.config ~~/demo/c7000/kernel/freertos/freertos.t32
 InterCom C71 menu.reprogram ~~/demo/c7000/kernel/freertos/freertos.men
 InterCom C71 HELP.FILTER.Add rtosfreertos
 ;InterCom C71 TASK.STacK.PATtern 0xa5      ; stack fill pattern
 ;InterCom C71 Break.Set task.config(magic) /Write /TraceData /onchip   ; pid track

 ; open up semi-host term for debug output
 ;InterCom C71 SYStem.Option IMASKASM ON
 ;InterCom C71 TERM.size #2 80. 24. 500.
 ;InterCom C71 TERM.METHOD #2 CCIO C$$IO$$ __CIOBUF_
 ;InterCom C71 WinPOS ,,,,,, semihost, Normal "SemiHost Console"
 ;InterCom C71 TERM.GATE #2
 ;InterCom C71 Break.Set C$$IO$$

 InterCom C71 go
 InterCom C71 trace.Chart.sYmbol /Sort ratio
 ;InterCom C71 trace.Chart.task

 enddo

