; --------------------------------------------------------------------------------
; @Title: PikeOS Demo for TRACE32 OS Awareness
; @Description:
;
;   This batchfile demonstrates the use of the OS Awareness for PikeOS.
;
;   The example is generated for the Freescale T2080QDS evaluation board.
;   It will NOT run on any other board, but may be used as a template
;   for others.
;   PikeOS is downloaded to the board via TRACE32 and started with u-boot.
;
; @Keywords: Awareness, PikeOS, RTOS
; @Author: DIE
; @Board: T2080QDS
; @Chip: T2080
; @Copyright: (C) 1989-2014 Lauterbach GmbH, licensed for use with TRACE32(R) only
; --------------------------------------------------------------------------------
; $Id: pikeos-hello.cmm 13419 2018-10-30 15:24:34Z hlohn $

; Starting PikeOS "hello" example with TRACE32:
; - Connect serial cable for terminal
;   - 115200 baud, 8/N/1, no(!) handshake
; - Start TRACE32
; - Switch on the board
; - TRACE32: "do pikeos-hello"


;&workspace="X:\RTOS\PikeOS\workspace\v4.2"
&workspace="./workspace"

; BSP see project.mk, PIKEOS_TARGET_FILES
;&bsp="/opt/pikeos-4.2/target/ppc/e500mc/object/bsp"
&bsp="&workspace/bsp/ppc/e500mc"

; set terminal connection
;&term="COM COM5 115200."
&term="TCP test-eth2serial-b.intern.lauterbach.com 14701."


; Debugger Reset

RESet


; Open Area window

WinPAGE.RESet
AREA.RESet
WinPOS 0. 32. 80. 17.
AREA.view
PRINT
PRINT "=== PikeOS 4.2 ""hello"" demo on T2080QDS (32bit) ==="
PRINT "reseting debugger..."


; Open serial terminal window

TERM.METHOD &term
TERM.SIZE 80. 1000.
TERM.SCROLL ON
WinPOS 91. 0. 80. 25.
TERM.view
SCREEN.ALWAYS      ; allow window update while script is running


; Configure debugger

SYStem.BdmClock 18.MHz     ; try lower debug frequencies if problems occur
SYStem.CPU T2080

CORE.ASSIGN 1. 3. 5. 7.
;CORE.ASSIGN 1. 2. 3. 4. 5. 6. 7. 8.

SYStem.Option IMASKASM ON   ; disable insterrupts for assembler single steps
SYStem.Option FREEZE ON     ; stop time base when in debug mode
SYStem.Option SLOWRESET ON
SYStem.Option KeyCode 0xfeedfacecafebff9
SYStem.MemAccess CPU        ; allow non-intrusive run-time memory access

SYStem.Option MMUSPACES ON


; Connect and reset target

PRINT "connecting debugger..."
SYStem.Up


; Open List window

WinPOS 0. 0. 86. 26.
List.auto


; Initialize target with uboot

Go
print "initializing target..."
wait 4.s
TERM.OUT 0x20   ; halt u-boot autostart
wait 1.s
Break


; Prepare download

; prepare external trace
;DO ~~\demo\powerpc64bit\hardware\qoriq_t2\t2080qds\qixis_config_serdes_aurora_mux.cmm


; Download PikeOS image

PRINT "downloading PikeOS image..."
Data.LOAD.Binary &workspace/hello-t2080qds-32.int/boot/simple-pikeos-t2080qds-uboot_unc D:0x00100000 /verify


; Load kernel symbols

PRINT "loading kernel and application symbols..."
; See project.rbx, <romimage> <psp> resource
Data.LOAD.Elf &bsp/p4080-e6500/kernel-tracesys-smp.unstripped /nocode /noclear


; Start PikeOS with u-boot

Go P4Main /Onchip
PRINT "initilizing PikeOS..."
TERM.OUT "bootm 0x00100000 - 0xe8800000" 0x0a
WAIT !run()


; Declare MMU Format

PRINT "initializing debugger translation..."
MMU.FORMAT PIKEOS.E500MC
TRANSlation.Create 0x80000000--0xbfffffff 0x0   ; kernel (see BAT)
TRANSlation.COMMON 0x80000000--0xffffffff
TRANSlation.TableWalk ON
TRANSlation.ON


; Initialize PikeOS Support

PRINT "initializing PikeOS support..."
TASK.CONFIG ~~/demo/powerpc/kernel/pikeos/v4.x/pikeos.t32       ; load PikeOS awareness
MENU.ReProgram ~~/demo/powerpc/kernel/pikeos/v4.x/pikeos.men    ; load PikeOS specific menu
TASK.STacK.PATtern %Long 0xdeadbeef

; Switch on autoloader
sYmbol.AutoLoad.CHECKCoMmanD "do ~~/demo/powerpc/kernel/pikeos/v4.x/autoload.cmm "

; Group kernel area to be displayed with red bar
GROUP.Create "kernel" 0x80000000--0xffffffff /RED


; Starting "hello" task

sYmbol.SourcePATH.Set "&workspace/hello-e500mc.app"             ; set path to hello.unstripped
DO ~~/demo/powerpc/kernel/pikeos/v4.x/app_debug.cmm hello   ; wait for "hello" to be started


; That's it!

PRINT "done."


ENDDO
