;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Basic C66x connect for DRA829/J7ES
; 18 Jun 19 - Richard Woodruff - Add history post wakeup
; 04 May 20 - Richard Woodruff - Add core names & sync
; 28 Sep 20 - Richard Woodruff - Add reset hooks to improve sys.up
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

 LOCAL &emulation
 &emulation="no"
 LOCAL &resetstate
 &resetstate="yes"

 RESet
 SYStem.RESet

 area.create A000 100 1000

; A72 (1x2)  : DRA829 (core.assign 1 2)
; CR5 (3x2)  : DRA829-CR5-MCU DRA829-CR5-MAIN0 DRA829-CR5-MAIN1 (core.assign 1 2)
; CM3 (1x1)  : DRA829-CM3
; PRU (2x3x2): DRA829-ICSS0 DRA829-ICSS0-RTU DRA829-ICSS0-TX (core.assign 1 2)
; C66 (2x1)  : DRA829-C66X (core.assign 1 2)
; C7x (1x1)  : DRA829-C71X

 System.CPU DRA829-C66X
 SYStem.CONFIG CORE 10. 1.

 IF COMBIPROBE()||UTRACE()
    SYStem.CONFIG.CONNECTOR MIPI34 ; because of converter LA-3782

 IF "&emulation"=="yes"
 (
  System.CONFIG DEBUGTIMESCALE 32.  
  System.Option MemStatusCheck ON
  SYStem.POLLING OFF
  setup.urate 2500.ms           ; slow window updates, this can be bigger
  SYStem.polling slow           ; sparse pinging
  SYStem.JTAGCLOCK rtck 100Khz
 )
 ELSE
 (
  SYStem.JTAGCLOCK CTCK 25MHz
  ;SYStem.JTAGCLOCK CTCK 1MHz     ; Alpha board
 )
 SYStem.Option EnReset OFF

; core/s to debug
 core.assign 1.     ; AMP debug C66x core 1
 ;core.assign 2.     ; AMP debug C66x core 2
 
 system.Option.DUALPORT.on
 trace.method onchip
 TPIU.PortMode.Continuous
 AET.OFF
 
 break.select program onchip
 break.select read onchip
 break.select write onchip

 IF "&resetstate"=="yes"
 (
   GOSUB RESET_C66 0
   ;GOSUB RESET_C66 1
 )
 
 SYStem.Mode up
 wait 500mS
 Break
 ;AET.ON

ENDDO


RESET_C66:
(
 ENTRY &core

 SYStem.Mode attach
 break

 ; 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 (&core==0)
 (
    ; Default reset vector is L2 cache
    Data.Set EZAXI:0x4D80800000 %Long %LE 0x0000a120
    Data.Set EZAXI:0x4D80F00000 %Long %LE 0x0000a120

    ; release C66 from reset
    Data.Set EDBG:0x40000338 %Long 0yxxxxxxxxxxxxxx1000xxxxxxxxxxxxxx
 )
 else
 (
    ; Default reset vector is L2 cache
    Data.Set EZAXI:0x4D81800000 %Long %LE 0x0000a120
    Data.Set EZAXI:0x4D81F00000 %Long %LE 0x0000a120

    ; release C66 from reset
    Data.Set EDBG:0x40000334 %Long 0yxxxxxxxxxxxxxx1000xxxxxxxxxxxxxx
 )
 RETURN
)
