@echo off
rem
rem Debugger command file for the RTA-OS HelloWorld Sample Application for GenericZynqUSA53
rem
rem ---------------------------------------------------------------------------
rem Create the test.log
@echo . > test.log

if not @%T32% == @ goto got_t32
@echo You need to set the env variable T32 to something like c:\t32 so I can find the debugger...
goto exit

:got_t32
set T32_BIN=%T32%\bin\windows
if exist %T32_BIN%\t32marm.exe goto prep
set T32_BIN=%T32%\bin\windows64
if exist %T32_BIN%\t32marm.exe goto prep
set T32_BIN=%T32%
if exist %T32_BIN%\t32marm.exe goto prep
echo Can't find t32marm.exe in '%T32%' or '%T32%\bin\windows' or '%T32%\bin\windows64'
goto exit

:prep
if exist "..\Debug\*.out" goto canrun
echo .elf is missing!
pause
goto exit

:canrun
@echo Starting > test.log


rem if exist t32.cmm del t32.cmm
rem copy "Samples\Debugger\GenericZynqUSR5_TCM.cmm" GenericZynqUSR5_TCM.cmm

rem find elf file
for /r "..\Debug" %%a in (*) do (
if "%%~xa"==".out" (
set TestApp=%%~nxa 
set TestAppFullPath=%%~dpnxa
)
) 

if defined TestApp (
echo Launching the following application in Trace32:
@echo Test Application: %TestApp%
@echo Test Application FullPath: %TestAppFullPath%
) else (
echo Elf file not found in Debug folder
pause
goto exit
)


@echo Launching debugger with test app %TestApp% 
REM START /B %T32_BIN%\t32marm.exe -c %T32%\config.t32 -s ZynqUSR5_TCM_BitFile.cmm "%TestAppFullPath%" test.log "debug" "" %BitFileFullPath% %FSBLFileFullPath%
START /B %T32_BIN%\t32marm.exe -c %T32%\config_usb.t32 -s tms570ls31xx_flash.cmm "%TestAppFullPath%"
		

goto exit

:exit


