📄 tmmon.c
字号:
j = (unsigned long) strtoul(argv[1], NULL, 10);
for (i = 0; i < NumberOfTMs; i++)
{
TMInfo[i].frequency = j;
printf("Frequency for node %d is set to %d (%d MHz)\n",
i, TMInfo[i].frequency, TMInfo[i].frequency / 1000000);
}
break;
case 3: /* Set frequency for specified node. */
n = (unsigned long) strtoul(argv[2], NULL, 10);
if (n < NumberOfTMs)
{
TMInfo[n].frequency = (unsigned long) strtoul(argv[1], NULL, 10);
printf("Frequency for node %d is set to %d (%d MHz)\n",
n, TMInfo[n].frequency, TMInfo[n].frequency / 1000000);
}
else
{
printf("TriMedia node %d doesn't exits.\n", n);
break;
}
break;
}
break;
case 'G': /* run TM-1 code */
/* The current loading scheme requires that you must load the executable
for every execution of a GO command.
*/
if (!codeLoaded)
{
printf("Sorry, but you must (re)load your executable for every GO command.\n");
break;
}
if (numOfArgs == 2) /* Execute specific TM */
{
n = strtoul(argv[1], NULL, 10);
if (n >= nodesLoaded)
{
printf("TriMedia node %d isn't loaded with code.\n", n);
break;
}
}
else /* Execute them all. */
n = ALL_NODES;
RPCServThreadID = 0;
status = NewThread(kCooperativeThread, rpcserv_thread, &n, 0, 0, NULL, &RPCServThreadID);
if (status) {
printf("###Failed to create new thread (%d)\n", status);
break;
}
// let this thread at least initialise things
YieldToThread(RPCServThreadID);
user_interrupt = false;
while (TMRunning())
{
if (UserCancelled()) /* Check for user command-period cancel. */
{
DisposeThread(RPCServThreadID, NULL, true);
user_interrupt = true;
break;
}
YieldToAnyThread();
}
if (!user_interrupt)
{
DisposeThread(RPCServThreadID, NULL, true);
if (n == ALL_NODES)
{
/* Show exit status for all nodes loaded. */
for (i = 0; i < nodesLoaded; i++)
printf("*** Exit for node %d: %d\n", i, TMInfo[i].Exit_Status);
}
else
{
/* Show exit status only for the single node executing. */
printf("*** Exit for node %d: %d\n", n, TMInfo[n].Exit_Status);
}
}
codeLoaded = false;
break;
case 'I': /* Show info on TriMedia chip(s) */
if (numOfArgs == 2) /* Show info on specific TM */
{
n = strtoul(argv[1], NULL, 10);
if (n < NumberOfTMs)
{
PrintTMs(n);
}
else
{
printf("TriMedia node %d doesn't exist.\n", n);
break;
}
}
else /* Show info on them all. */
{
PrintTMs(ALL_NODES);
}
break;
case 'L': /* Load code into TriMedia SDRAM */
/* Check if attempting to load more executables than there are TriMedia's. */
nodesLoaded = 1;
for (i = 2; i < numOfArgs; i++)
{
if (strcmp(argv[i], "-") == 0 )
nodesLoaded++;
}
if (nodesLoaded > NumberOfTMs)
{
printf("Cannot load %d executables into %d TriMedia nodes\n", nodesLoaded, NumberOfTMs);
break;
}
tmstatus = TMDwnLdr_create_shared_section_table(&shared_sections);
if (tmstatus != TMDwnLdr_OK)
{
printf("Failed creating a shared section table.\n");
break;
}
i = 1;
node = 0;
while (i < numOfArgs)
{
int argcForThisNode;
int actualArgc;
char *actualArgv[30];
char actualFilename[FILENAME_MAX];
argcForThisNode = 1;
while (i + argcForThisNode < numOfArgs
&& strcmp(argv[i + argcForThisNode], "-") != 0 )
{
argcForThisNode++;
}
/* We may have to load appshell.out instead of the file specified. */
PrepareToLoad(argv[i], argcForThisNode, &argv[i], actualFilename, &actualArgc, &actualArgv[0]);
LoadTM(nodesLoaded, node, actualFilename, shared_sections, actualArgc, &actualArgv[0]);
i = i + argcForThisNode + 1; /* add one for skipping the "-" */
node++;
}
tmstatus = TMDwnLdr_unload_shared_section_table(shared_sections);
codeLoaded = true;
break;
case 'M' : /* Show information on monitors. */
ShowGDevices();
break;
case 'P': /* Display memory */
arr = (unsigned char*) strtoul(argv[1], NULL, 16);
if (numOfArgs == 2)
{
n = 256;
}
else
{
n = strtol(argv[2], NULL, 16);
}
for (i = 0; i < n; i+=16)
{
if (i%16==0) printf("0x%08x: ", &arr[i]);
for (j = 0; j < 16; j++)
{
printf("%02x", arr[i+j]);
if (j % 4==3) printf(" ");
}
printf(" ");
for (j = 0; j < 16; j++)
{
printf("%c", arr[i+j] < 0x20 || arr[i+j] > 0x7e ? '.' : arr[i+j]);
}
printf("\n");
}
break;
case 'Q': /* Quit */
TMQuit();
exit(0);
break;
case 'R': /* Reset TriMedia chip(s) */
if (numOfArgs == 2) /* Reset specific TM */
{
n = strtoul(argv[1], NULL, 10);
if (n < NumberOfTMs)
{
InitTM(true, n);
ResetTM(n);
}
else
{
printf("TriMedia node %d doesn't exist.\n", n);
break;
}
}
else /* Reset them all. */
{
for (i = 0; i < NumberOfTMs; i++)
{
InitTM(true, i);
ResetTM(i);
printf("TriMedia node %d reset.\n", i);
}
}
codeLoaded = false;
break;
case 'S' :
/*
S commands can be:
SIZE -- set SDRAM size
SI -- set stdin file name
SO -- set stdout file name
SE -- set stderr file name
*/
n = strlen(Command);
if (n > 2 && strstr(Command, "SIZ"))
{
/* Display or set SDRAM size. */
switch(numOfArgs)
{
case 1: /* Display SDRAM size for all nodes. */
for (i = 0; i < NumberOfTMs; i++)
{
printf("SDRAM size for node %d is set to 0x%08x bytes\n", i,
MMIO_M(i, DRAM_LIMIT) - MMIO_M(i, DRAM_BASE));
}
break;
case 2: /* Set SDRAM size for all nodes. */
j = (unsigned long) strtoul(argv[1], NULL, 16);
for (i = 0; i < NumberOfTMs; i++)
{
MMIO_M(i, DRAM_LIMIT) = j + MMIO_M(i, DRAM_BASE);
printf("SDRAM size for node %d is set to 0x%08x bytes\n", i,
MMIO_M(i, DRAM_LIMIT) - MMIO_M(i, DRAM_BASE));
}
break;
case 3: /* Set SDRAM size for specified node. */
n = (unsigned long) strtoul(argv[2], NULL, 10);
if (n < NumberOfTMs)
{
MMIO_M(n, DRAM_LIMIT) = (unsigned long) strtoul(argv[1], NULL, 16) + MMIO_M(n, DRAM_BASE);
printf("SDRAM size for node %d is set to 0x%08x bytes\n", n,
MMIO_M(n, DRAM_LIMIT) - MMIO_M(n, DRAM_BASE));
}
else
{
printf("TriMedia node %d doesn't exits.\n", n);
break;
}
break;
}
}
else if (n == 2 && !strncmp(Command, "SI",n))
{
/* Set stdin file name. */
if (numOfArgs == 2)
strcpy(stdin_file, argv[1]);
else
/* Revert to console. */
stdin_file[0] = '\0';
}
else if (n == 2 && !strncmp(Command, "SO",n))
{
/* Set stdout file name. */
if (numOfArgs == 2)
strcpy(stdout_file, argv[1]);
else
/* Revert to console. */
stdout_file[0] = '\0';
}
else if (n == 2 && !strncmp(Command, "SE",n))
{
/* Set stderr file name. */
if (numOfArgs == 2)
strcpy(stderr_file, argv[1]);
else
/* Revert to console. */
stderr_file[0] = '\0';
}
else
{
printf("Unknown command: %s. Try help.\n", Command);
}
break;
default :
printf("Unknown command: %s. Try help.\n", Command);
break;
}
}
exit( 0 );
}
/*-------------------------------- Unsupported Functions ---------------------------*/
#ifdef __MWERKS__
#define ENOSYS TCS_ENOSYS
static void tm_unimplemented(char *function_name)
{
char str[256];
errno = ENOSYS;
sprintf(str, "Whoa! Function '%s' not implemented", function_name);
exit(1);
}
//#include "WINSOCK.H"
int setsockopt (/* SOCKET s, int level, int optname, const char * optval, int optlen*/ )
{
tm_unimplemented("setsockopt");
return -1;
}
int getsockname (/* SOCKET s, struct sockaddr *name, int * namelen */)
{
tm_unimplemented("getsockname");
return -1;
}
void */* struct protoent * */ getprotobyname(/* const char * name*/)
{
tm_unimplemented("getprotobyname");
return 0;
}
int gethostname (/* char * name, int namelen*/ )
{
tm_unimplemented("gethostname");
return 0;
}
void * /* struct hostent * */ gethostbyname(/* const char * name*/ )
{
tm_unimplemented("gethostbyname");
return 0;
}
void * /* struct hostent * */ gethostbyaddr(/* const char * addr, int len, int type */ )
{
tm_unimplemented("gethostbyaddr");
return 0;
}
int ioctlsocket (/* SOCKET s, long cmd, u_long *argp */)
{
tm_unimplemented("ioctlsocket");
return -1;
}
int bind (/* SOCKET s, const struct sockaddr *addr, int namelen */)
{
tm_unimplemented("bind");
return -1;
}
int connect (/* SOCKET s, const struct sockaddr *name, int namelen */)
{
tm_unimplemented("connect");
return -1;
}
int select (/* int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const struct timeval *timeout */)
{
tm_unimplemented("select");
return -1;
}
int /* SOCKET */ accept (/* SOCKET s, struct sockaddr *addr, int *addrlen */ )
{
tm_unimplemented("accept");
return -1;
}
int closesocket (/* SOCKET s */)
{
tm_unimplemented("closesocket");
return -1;
}
unsigned long inet_addr (/* const char * cp */)
{
tm_unimplemented("inet_addr");
return -1;
}
int listen (/* SOCKET s, int backlog */)
{
tm_unimplemented("listen");
return -1;
}
int send (/* SOCKET s, const char * buf, int len, int flags */)
{
tm_unimplemented("send");
return -1;
}
int recv (/* SOCKET s, char * buf, int len, int flags */)
{
tm_unimplemented("recv");
return -1;
}
int /* SOCKET */ socket (/* int af, int type, int protocol */)
{
tm_unimplemented("socket");
return -1;
}
int closedir(/* DIR * */)
{
tm_unimplemented("closedir");
return -1;
}
void * /* DIR * */ opendir(/* const char * */)
{
tm_unimplemented("opendir");
return 0;
}
void * /* struct dirent * */ readdir(/* DIR * */)
{
tm_unimplemented("dirent");
return (struct dirent *) 0;
}
void rewinddir(/* DIR * */)
{
tm_unimplemented("rewinddir");
}
int access(/* const char *path, int mode */)
{
tm_unimplemented("access");
return -1;
}
int putenv(/* char *string */)
{
tm_unimplemented("putenv");
return -1;
}
int fsync(/* int fd */)
{
tm_unimplemented("fsync");
return -1;
}
int sync(void)
{
tm_unimplemented("sync");
return -1;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -