; --------------------------------------------------------------------------------
; @Title: WinCE 6.0 Demo for TRACE32 OS Awareness on phyCORE-i.MX350 Board
; @Description:
;
;   This batchfile demonstrates the use of the OS Awareness for Windows CE 6
;
;   The example is generated for the phyCORE-i.MX350 board using an ICD.
;   It will NOT run on any other board, but may be used as a template
;   for others.
;   The Windows CE image is downloaded via the ICD.
;
; @Keywords: awareness, Windows
; @Author: DIE
; @Board: phyCORE-i.MX350
; @Chip: IMX35
; @Copyright: (C) 1989-2019 Lauterbach GmbH, licensed for use with TRACE32(R) only
; --------------------------------------------------------------------------------
; $Id: wince.cmm 15223 2019-11-05 16:29:45Z bschroefel $


; Starting WinCE example with TRACE32:
; - Start TRACE32
; - Switch on the board
; - TRACE32: "do wince"
; - Start control panel on target

; For Bootloader communication:
; - Terminal on Serial 1 (upper jack): 115200, 8N1N

; For debugging with TRACE32 we recommend to disable demand paging
; by setting bit one of ROMFLAGS in PLATFORM\M6R2\FILES\config.bib


&reldir="C:\WINCE600\OSDesigns\iMX35PhytecBinary\iMX35PhytecBinary\RelDir\iMX35Phytec_ARMV4I_Debug"


 SCREEN.ON


; Debugger Reset

 WinPAGE.RESet
 AREA.RESet
 WinPOS 0. 24. 75. 8.
 AREA.view

 PRINT "resetting..."

 RESet


; setup of ICD

 PRINT "initializing..."
 SYStem.CPU IMX35
 SYStem.JtagClock RTCK
 SYStem.CONFIG.L2CACHE.Base 0x30000000
 SYStem.Option ResBreak OFF     ; hardware dependent (see manual)
 SYStem.Option DACR ON          ; give Debugger global write permissions
 TrOnchip.Set DABORT OFF        ; used by wince for page miss!
 TrOnchip.Set PABORT OFF        ; used by wince for page miss!
 TrOnchip.Set UNDEF OFF         ; used to detect not present FPU
 SYStem.Option MMUSPACES ON     ; enable space ids to virtual addresses

 SYStem.Up

 SETUP.IMASKASM ON              ; lock interrupts while single stepping


; Target Setup: initialize DRAM controller and peripherals

 ; Either let the boot monitor setup the board
    Go
    PRINT "target setup..."
    WAIT 2.s
    Break
 ; or use the debugger to initialize it
    ;print "target setup..."
    ;do init_phycore_imx35      ; do basic setup


; Load the Windows CE image

 ; Use the next lines only to load the image into
 ; RAM using the debugger.

 PRINT "loading Windows CE image..."

 ; Prepare for direct download: disable MMU!
 PER.Set.simple C15:0x1 %Long Data.Long(c15:1)&~1    ; switch off MMU
 Register.RESet

 ; download the image to physical address
 Data.LOAD.eXe &reldir\nk.bin 0x80200000-0x80200000

 ; set PC to physical start address
 Register.Set PC 0x80200000


; We'd like to see something, open a code window.
 WinPOS 0. 0. 77. 22.
 List.auto


; Declare the MMU format to the debugger

 ; table format is "WINCE6"
 ; skip root table (0)
 ; declare default translation for kernel
 MMU.FORMAT WINCE6 0 0x80000000--0x87ffffff 0x80000000

 ; ROM DLL, shared heap and kernel addresses are common to all processes
 TRANSlation.COMMON 0x40000000--0x5fffffff 0x70000000--0xffffffff

 ; debugger uses a table walk to decode virtual addresses
 TRANSlation.TableWalk ON

 ; switch on debugger(!) address translation
 TRANSlation.ON


; Initialize RTOS Support

 PRINT "initializing Windows CE support..."
 TASK.CONFIG ../wince6          ; loads WinCE awareness (wince6.t32)
 MENU.ReProgram ../wince6       ; loads WinCE menu (wince6.men)
 HELP.FILTER.Add rtoswince      ; add WinCE awareness manual to help

 ; switch on autoloader and add path to symbol files to source path list
 sYmbol.AutoLoad.CHECKWINCE "do "+OS.PPD()+"/../autoload "
 sYmbol.SourcePATH.Set &reldir

 ; Group kernel area to be displayed with red bar
 GROUP.Create "winceos" 0x80000000--0xffffffff /RED


; The power saving WFI mode of the CPU doesn't work with JTAG attached.
; Either remove it from the OAL source code (recommended) or patch the
; code like this:

 Go
 PRINT "bootstrapping for patch..."
 WAIT 3.s
 Break
 TASK.sYmbol.LoadRM "nk.exe"            ; load symbols of OAL
 Data.Assemble OALCPUEnterWFI bx r14    ; patch WFI routine to no-op


; Now let's boot and start Windows CE!

 Go
 PRINT "booting Windows CE... (please wait)"
 WAIT 6.s
 Break


 PRINT "done."


; --------------------------------------------------------------------------------
; Application Debugging
; e.g. "control"

 DO ../app_debug control

 ENDDO

