在我看来,你的问题是一个相当好的问题。
首先是无赖:t32rem不适合等待脚本执行。事实上 t32rem 在使用 T32_Stop() 执行命令之前取消任何正在运行的脚本。(您可以在“C:\T32\demo\api\capi\test\t32rem.c”的TRACE32安装中找到t32rem的源代码)
所以你的使用建议t32rem localhost wait STATE.RUN()
肯定行不通,因为它会取消正在运行的脚本。此外STATE.RUN()
返回被调试 CPU 的运行状态,而不是 PRACTICE 解释器的运行状态。
所以实际上你必须使用 T32_GetPractice() 来等待 PRACTICE 脚本终止。要使用 T32_GetPractice(),您必须将“C 中用于远程控制和 JTAG 访问的 API”静态或动态链接到启动脚本的应用程序。
对于动态链接(例如从 Python 脚本)加载“C:\T32\demo\api\capi\dll\t32api.dll”。(根据您的主机操作系统,您可能需要 t32api64.dll、t32api.so 或 t32api64.so。)
对于静态链接(例如,来自用 C 编写的二进制应用程序),将“C:\T32\demo\api\capi\src”中的文件添加到您的项目中。
下面是编写命令行应用程序t32do的代码,它启动 PRACTICE 脚本并等待脚本终止:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "t32.h"
int main(int argc, char *argv[])
{
int pstate;
const char *script;
if (argc == 4 && !strncmp(argv[2],"port=", 5)) {
if ( T32_Config( "PORT=", argv[2]+5 ) == -1 ) {
printf("Port number %s not accepted\n", argv[2] );
exit(2);
}
script = argv[3];
} else {
if (argc != 3) {
printf( "Usage: t32do <host> [port=<n>] <script>\n" );
exit(2);
}
script = argv[2];
}
if ( T32_Config( "NODE=", argv[1] ) == -1 ) {
printf( "Hostname %s not accepted\n", argv[1] );
exit(2);
}
if ( T32_Init() != 0 || T32_Attach(1) != 0){
printf( "Failed to connect to TRACE32\n" );
exit(2);
}
if ( T32_Cmd_f("DO \"%s\"", script) != 0 ){ // Launch PRACTICE script
printf( "Failed to start PRACTICE script\n" );
T32_Exit();
exit(1);
}
while (T32_GetPracticeState(&pstate) == 0 && pstate != 0){ // Wait until PRACTICE script terminates
usleep(10000);
}
T32_Exit();
return 0;
}
将源代码放在“C:\T32\demo\api\capi\src”中名为 t32do.c 的文件中,并使用以下 makefile 构建应用程序,该文件适用于 Windows(通过使用 Cygwin 的 MinGW 编译器)和 Linux :
BIN := t32do
OBJ := t32do.o hremote.o hlinknet.o
OS := $(shell uname -s)
ifneq ($(findstring CYGWIN,$(OS)),)
CC := x86_64-w64-mingw32-gcc
LOPT := -lws2_32
COPT := -DT32HOST_LE
endif
ifneq ($(findstring Linux,$(OS)),)
CC := gcc
COPT := -DT32HOST_LE
endif
all: $(BIN)
$(BIN): $(OBJ)
$(CC) $^ -s -o $@ $(LOPT)
%.o: %.c t32.h
$(CC) -c $(COPT) -o $@ $<
clean:
-rm $(OBJ) $(BIN)
如果编译和链接正常,您将获得一个应用程序 t32do.exe。以下列形式使用它:t32do <host> [port=<n>] <practice script>
我上面的示例代码在Creative Commons Zero 1.0下获得许可。以任何你想要的方式使用它,在你想要的任何代码中。