 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; TDA4VM/H: Start up R5, call test setup, run & profile test
; 16 Aug 24 - Richard Woodruff - Create
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

 &path=OS.PPD()

 IF COMBIPROBE()||UTRACE()
 (
   IF (ID.WHISKER(0.)==0x12)
     SYStem.CONFIG.CONNECTOR MIPI20T
   ELSE
     SYStem.CONFIG.CONNECTOR MIPI34 ; because of converter LA-3782
 )

 &SOC="TDA4VH"                  ; TDA4VH or TDA4VM
 &bare_metal="yes"              ; if R5 is not yet booted say yes
 &iprobe="no"

 IF "&iprobe"=="yes"
 (
   NAME.RESET
   NAME.SET IProbe.00 FREQ
   IProbe.CSELect.IProbe FREQ
   IProbe.Timing.IProbe.FREQ
   iprobe
   iprobe.off
 )

 IF "&bare_metal"=="yes"
 (
  IF "&SOC"=="TDA4VM"
  (
   DO "&path/../../x_gel_to_cmm_public/j7es_baremetal_setup.cmm" HS:FS
   TITLE "TRACE32 for ARM-CM3 - MASTER"
   DO "&path/../../x_gel_to_cmm_public/j7es_m3.cmm"
   DO "&path/../../x_gel_to_cmm_public/J721E.cmm"
  )
  ELSE
  (
   DO "&path/../../x_gel_to_cmm/_J784S4_baremetal_setup.cmm" HS:FS
   TITLE "TRACE32 for ARM CM4-0 - MASTER"
   DO "&path/../../x_gel_to_cmm/_J784S4_m4.cmm" CM4-0 PREPARE
   DO "&path/../../x_gel_to_cmm/J7AHP.cmm"
  )
  wait 1s
)

 TITLE "TRACE32 for ARM CR5 - MASTER"
 IF "&SOC"=="TDA4VM"
   DO "&path/../../x_gel_to_cmm_public/j7es_r5.cmm" R5-MCU AMP1     ; R5-MCU, R5-MAIN0, ...
 ELSE
   DO "&path/../../x_gel_to_cmm/_J784S4_r5.cmm" R5-MCU AMP1       ; R5-MCU, R5-MAIN0, ...

 GOSUB CACHE_MPU_INIT
 DO ~~~~/1_mem_tda4v-r5_sram_test.cmm

IF "&SOC"=="TDA4VM"
(
  DO "&path/../../x_gel_to_cmm_public/j7es_offchip_trace.cmm" 250MHz
 ;DO "&path/../../cptracer/dra829-cpt-latency.cmm" OFFCHIP 250MHz
 ;DO "&path/../../cptracer/dra829-cpt-throughput.cmm" OFFCHIP 250MHz
 ;DO "&path/../../cptracer/dra829-cpt-transaction.cmm" OFFCHIP 250MHz
)
ELSE
(
  DO "&path/../../x_gel_to_cmm/J784S4_offchip_trace.cmm" 250MHz
 ;DO "&path/../../cptracer/j784s4-cpt-latency.cmm" OFFCHIP 250MHz
 ;DO "&path/../../cptracer/j784s4-cpt-throughput.cmm" OFFCHIP 250MHz
 ;DO "&path/../../cptracer/j784s4-cpt-transaction.cmm" OFFCHIP 250MHz
)

ENDDO

CACHE_MPU_INIT:
(
	PRIVATE &i &tmpReg

	; Enable MPU and disable I and D caches
	&tmpReg=Data.Long(C15:0x1)
	&tmpReg=&tmpReg|0x1             ; enable MPU
	&tmpReg=(&tmpReg&(~(0x1<<2.)))  ; disable D cache
	&tmpReg=(&tmpReg&(~(0x1<<12.))) ; disable I cache
	Data.Set C15:0x1 %long &tmpReg

	; Configure small region setup for flash programming
	PER.Set.SaveIndex C15:0x026 %Long 0x0 C15:0x016 %Long 0x00000000 ; set default
	PER.Set.SaveIndex C15:0x026 %Long 0x0 C15:0x216 %Long 0x0000003F
	PER.Set.SaveIndex C15:0x026 %Long 0x0 C15:0x416 %Long 0x00001310
	PER.Set.SaveIndex C15:0x026 %Long 0x1 C15:0x016 %Long 0x50000000 ; setup flash window
	PER.Set.SaveIndex C15:0x026 %Long 0x1 C15:0x216 %Long 0x00000035
	PER.Set.SaveIndex C15:0x026 %Long 0x1 C15:0x416 %Long 0x00001301
	PER.Set.SaveIndex C15:0x026 %Long 0x2 C15:0x016 %Long 0x41C00000 ; setup buffer space
	PER.Set.SaveIndex C15:0x026 %Long 0x2 C15:0x216 %Long 0x00000027
	PER.Set.SaveIndex C15:0x026 %Long 0x2 C15:0x416 %Long 0x0000030C
	; Reset all other MPU regions
	&i=3.
	while &i<16.
	(
		PER.Set.SaveIndex C15:0x026 %Long &i C15:0x016 %Long 0x0
		PER.Set.SaveIndex C15:0x026 %Long &i C15:0x216 %Long 0x0
		PER.Set.SaveIndex C15:0x026 %Long &i C15:0x416 %Long 0x0
		&i=&i+1.
	)

	RETURN
)

