;------------------------------------------------------------------------------------
; 14 May 21 - Richard Woodruff - Example for FreeRTOS.
; 24 Jan 22 - Richard Woodruff - Update for SDK8 firmware name change
; 14 Nov 22 - Richard Woodruff - Adjust reset setup
; 27 Jan 23 - Richard Woodruff - Adjust for 02.2023 path handling
;------------------------------------------------------------------------------------
; Launch for DSP C6000 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

 &tst="gpioblink"     ; {"ut","ts", "gpioblink"}
 &SCIR5="SCIR5"

 &subcore="C66-1"  ; "C66-0" or "C66-1"

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

 LOCAL &cpu &tst &tst_src &tst_nam &RTOS

 &RTOS="FREERTOS"     ; Used for SDK8 binary rename

; 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"
 &gp_src="&freertos_src/test/freertos/gp"                 ; need update

 &freertos_bin="&opath/syms/freertos/j7es"
 &tst_prefix="freertos_test_"

 IF "&tst"=="ts"
 (
   &tst_src="&ut_src"
   &tst_nam="task_switch"
 )
 ELSE IF "&tst"=="ut"
 (
   &tst_src="&ts_src"
   &tst_nam="ut"
 )
 ELSE
 (
   &tst_src="&gp_src"
   &tst_nam=""
   &tst_prefix="GPIO_LedBlink_TestApp_freertos"
   &freertos_bin="&opath/syms/j721e"
 )

 &cpu="DRA829-C66X"
 IF ("&subcore"=="C66-0")
     &tst="&freertos_bin/"+"&tst_prefix"+"&tst_nam"+"_c66xdsp_1_release.xe66"
 ELSE
     &tst="&freertos_bin/"+"&tst_prefix"+"&tst_nam"+"_c66xdsp_2_release.xe66"

 ; Add parameter  ICEPICk  to enable Icepick handling
 DO "~~~~/pdk_launch_js_common.cmm" ICEPICK &SCIR5 &RTOS

 IF !INTERCOM.PING(C66)
        TargetSystem.NewInstance C66 /ARCHitecture C6000
 InterCom C66 TITLE "TRACE32 for J721E-C6x - SLAVE"
 InterCom C66 DO "&path/../j7es_c66.cmm" "&subcore"
 InterCom.WAIT C66

 ; Catch C66 in reset vector by setting an infinite loop
 ; Avoids illegal memory accesses by the C6000 core
 ; Access to C66 L1 and L2 memory/cache via main domain address space:
 ; C66_COREPAC[0|1]_C66_SDMA_L2SRAM_0  0x4D8[0|1]800000 0x4D8183FFFF 256 KB
 ; C66_COREPAC[0|1]_C66_SDMA_L1DSRAM   0x4D8[0|1]F00000 0x4D81F07FFF  32 KB
 if ("&subcore"=="C66-0")
 (                                                                     
   Data.Set EZAXI:0x4D:0x80800000 %Long %LE 0x0001e000                 ; idle
   Data.Set EZAXI:0x4D:0x80F00000 %Long %LE 0x0001e000                 ; idle
   Data.Set EDBG:0x40000338 %Long 0yxxxxxxxxxxxxxx1000xxxxxxxxxxxxxx  ; rel reset
 )
 else
 (
   Data.Set EZAXI:0x4D:0x81800000 %Long %LE 0x0001e000               ; idle
   Data.Set EZAXI:0x4D:0x81F00000 %Long %LE 0x0001e000               ; idle
   Data.Set EDBG:0x40000334 %Long 0yxxxxxxxxxxxxxx1000xxxxxxxxxxxxxx ; rel reset
 )
   
 InterCom C66 SYStem.Up
 InterCom.WAIT C66
 InterCom C66 Break
 InterCom.WAIT C66
 InterCom C66 TRACE.Method.onchip
 InterCom C66 tpiu.PortMode.Continuous
 InterCom C66 AET.ON
 InterCom.WAIT C66

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

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

 InterCom C66 Register /sl
 InterCom C66 data.list

 ;InterCom C66 b.s exit /onchip

 InterCom C66 FramePOS ,,,, Top
 InterCom C66 wintop uart

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

 ; Load FreeRTOS awareness
 InterCom C66 task.config ~~/demo/c6000/kernel/freertos/freertos.t32
 InterCom C66 menu.reprogram ~~/demo/c6000/kernel/freertos/freertos.men
 InterCom C66 HELP.FILTER.Add rtosfreertos
 ;InterCom C66 TASK.STacK.PATtern 0xa5      ; stack fill pattern
 InterCom C66 Break.Set task.config(magic) /Write /TraceData    ; pid track
 
 ; open up semi-host term for debug output
 ;InterCom C66 TERM.size #2 80. 24. 500.
 ;InterCom C66 TERM.METHOD #2 CCIO C$$IO$$ __CIOBUF_
 ;InterCom C66 WinPOS ,,,,,, semihost, Normal "SemiHost Console"
 ;InterCom C66 TERM.GATE #2
 ;InterCom C66 Break.Set C$$IO$$

 InterCom C66 go

 enddo

