?? tmmprun.c
字號:
tmmanDSPUnmapSDRAM(DSPHandle);
return Status;
}
int
main(int argc, char *argv[])
{
TMDwnLdr_SharedSectionTab_Handle SharedSections;
TMStatus Status;
tmmanVersion Version;
tmmanDSPInfo DSPCaps;
int wIdxArg;
DWORD i;
DWORD CRTHandle[MAXIMUM_NODES];
DWORD DSPHandle[MAXIMUM_NODES];
DWORD ArgumentCountArray[MAXIMUM_NODES];
PVOID ArgumentVectorArray[MAXIMUM_NODES];
DWORD MMIOPhysicalAddressArray[MAXIMUM_NODES];
CHAR* ArgumentVector[MAXIMUM_COMMAND_LINE_ARGS];
DWORD ArgumentCount;
if (argc < 2) {
goto mainUsage;
}
/*
* check for compatible driver version
*/
Version.Major = constTMManDefaultVersionMajor;
Version.Minor = constTMManDefaultVersionMinor;
tmmanNegotiateVersion(constTMManDefault, &Version);
if ((Version.Major != constTMManDefaultVersionMajor) ||
(Version.Minor != constTMManDefaultVersionMinor)) {
fprintf(stderr,
"TMMPRun : ERROR : tmmprun.exe Version[%d.%d] is INCOMPATIBLE "
"With TMMan32.dll Version[%d.%d]\n",
constTMManDefaultVersionMajor,
constTMManDefaultVersionMinor,
Version.Major, Version.Minor);
goto mainExit1;
}
/*
* install a control C handler so that we can perform cleanup before exit.
*/
if (SetConsoleCtrlHandler(tmrunControlHandler, TRUE) != TRUE) {
fprintf(stderr,
"TMMPRun : ERROR : Win32 SetConsoleCtrlHandler failed [0x%x]",
GetLastError());
goto mainExit1;
}
/*
* count the number of DSPs we have to download into
* this corresponds to the number of "-exec" in the command line
*/
for (wIdxArg = 1; wIdxArg < argc; wIdxArg++) {
/*
* "-exec" indicates start of target executable name and arguments
*/
if (_stricmp(argv[wIdxArg], "-exec") == 0) {
DSPCount++;
if (DSPCount > MAXIMUM_NODES) {
fprintf(stderr,
"TMMPRun : ERROR : Maximum nodes (%d) exceeded",
MAXIMUM_NODES);
goto mainExit1;
}
}
}
/*
* initialize the arrays
*/
for (i = 0; i < DSPCount; i++) {
DSPHandle[i] = 0;
CRTHandle[i] = 0;
ArgumentVectorArray[i] = NULL;
EventArray[i] = NULL;
}
/*
* open all the DSPs
*/
for (i = 0; i < DSPCount; i++) {
Status = tmmanDSPOpen(i, &DSPHandle[i]);
if (Status != statusSuccess) {
fprintf(stderr,
"TMMPRun : ERROR : tmmanDSPOpen failed [0x%x](%s)\n",
Status, tmmanGetErrorString(Status));
goto mainExit2;
}
Status = tmmanDSPGetInfo(DSPHandle[i] , &DSPCaps);
if (Status != statusSuccess) {
fprintf(stderr,
"TMMPRun : ERROR : tmmanDSPGetInfo failed [0x%x](%s)\n",
Status, tmmanGetErrorString(Status));
goto mainExit3;
}
MMIOPhysicalAddressArray[i] = DSPCaps.MMIO.PhysicalAddress;
}
/*
* process the generic command line parameters here
*/
for (wIdxArg = 1; wIdxArg < argc; wIdxArg++) {
/*
* "-exec" indicates start of target executable name and arguments
*/
if (_stricmp(argv[wIdxArg], "-exec") == 0) {
/*
* the next argument should be the name of the executable , point to it.
*/
wIdxArg++;
break;
}
switch (toupper(argv[wIdxArg][1])) {
case 'B': /* interactive off option */
Interactive = FALSE;
break;
case 'W': /* no of lines in console window */
{
DWORD dwWindowLines;
COORD ConsoleSize;
if (sscanf(&argv[wIdxArg][2], "%d", &dwWindowLines) != 1) {
goto mainUsage;
}
ConsoleSize.X = 80;
ConsoleSize.Y = (USHORT)dwWindowLines;
SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), ConsoleSize);
}
break;
case '?': /* add other command line optons here */
default:
goto mainUsage;
}
}
/*
* create an empty shared section table, for use in multiprocessing downloading
*/
TMDwnLdr_create_shared_section_table(&SharedSections);
/*
* Initializes the C Run Time server to serve multiple nodes.
*/
cruntimeInit();
/*
* initialize the C runtime for each DSP
*/
for (i = 0; i < DSPCount; i++) {
CRunTimeParameterBlock CRTParam;
/*
* create an event for this node
*/
EventArray[i] = CreateEvent(NULL, /* default security descriptor in NT, not used in Windows 95 */
FALSE, /* auto reset event */
FALSE, /*initial state is not signalled */
NULL);
if (EventArray[i] == INVALID_HANDLE_VALUE) {
fprintf(stderr,
"TMMPRun : ERROR : Win32 CreateEvent failed [0x%x]\n",
GetLastError());
goto mainExit4;
}
CRTParam.OptionBitmap = 0;
CRTParam.StdInHandle = (DWORD)GetStdHandle(STD_INPUT_HANDLE);
CRTParam.StdOutHandle = (DWORD)GetStdHandle(STD_OUTPUT_HANDLE);
CRTParam.StdErrHandle = (DWORD)GetStdHandle(STD_ERROR_HANDLE);
/*
* process target specific command line arguments here
* this parameter should be the executable filename
*/
TargetExecutableName = argv[wIdxArg];
ArgumentCount = 0;
ArgumentVector[ArgumentCount++] = argv[wIdxArg];
for (wIdxArg++; wIdxArg < argc; wIdxArg++) {
/*
* "-exec" indicates start of target executable name and arguments
*/
if (_stricmp(argv[wIdxArg], "-exec") == 0) {
wIdxArg++;
break;
}
ArgumentVector[ArgumentCount++] = argv[wIdxArg];
}
ArgumentVector[ArgumentCount] = NULL;
/*
* we have to allocate persistent storage for these values
*/
ArgumentCountArray[i] = ArgumentCount;
if ((ArgumentVectorArray[i] =
malloc(sizeof(PVOID) * (ArgumentCount + 1))) == NULL) {
fprintf(stderr, "TMMPRun : ERROR : malloc(Argument Array) failed\n");
goto mainExit5;
}
memcpy(ArgumentVectorArray[i] ,
ArgumentVector,
sizeof(PVOID) * (ArgumentCount + 1));
/*
* PERFORM RELOCATION HERE
*/
Status = tmDSPExecutableLoadEx(DSPHandle[i],
TargetExecutableName,
DSPCount,
SharedSections,
MMIOPhysicalAddressArray);
if (Status != statusSuccess) {
fprintf(stderr,
"TMMPRun : ERROR : tmDSPExecutableLoadEx(%s) failed [0x%x](%s)\n",
TargetExecutableName,
Status,
tmmanGetErrorString(Status));
goto mainExit6;
}
CRTParam.OptionBitmap |= constCRunTimeFlagsUseSynchObject;
CRTParam.SynchronizationObject = (DWORD)EventArray[i];
CRTParam.VirtualNodeNumber = i;
if (!Interactive) {
CRTParam.OptionBitmap |= constCRunTimeFlagsNonInteractive;
}
/*
* allocate resources for this TriMedia processor.
*/
if (cruntimeCreate(i, /* the physical DSP Number */
ArgumentCountArray[i],
ArgumentVectorArray[i],
&CRTParam,
&CRTHandle[i]) != True) {
fprintf(stdout,
"TMMPRun : ERROR : Cannot Initialize C Run Time Server :"
"CRT I/O calls will not work\n");
goto mainExit6;
}
}
/*
* at this time, code has been copied to the memory of the
* TriMedia boards and C runtime has been created
* start executing the code on each DSP
*/
for (i = 0; i < DSPCount; i++) {
Status = tmmanDSPStart(DSPHandle[i]);
if (Status != statusSuccess) {
fprintf(stderr,
"TMMPRun : ERROR : tmmanDSPStart failed [0x%x](%s)\n",
Status, tmmanGetErrorString(Status));
goto mainExit7;
}
}
/*
* wait until all objects in the EventArray array are signaled
*/
WaitForMultipleObjects(DSPCount, EventArray, TRUE, INFINITE);
for (i = 0; i < DSPCount; i++) {
if (DSPHandle[i])
tmmanDSPStop(DSPHandle[i]);
}
mainExit7:
for (i = 0; i < DSPCount; i++) {
if (CRTHandle[i])
cruntimeDestroy(CRTHandle[i], &GlobalExitCode);
}
mainExit6:
for (i = 0; i < DSPCount; i++) {
if (ArgumentVectorArray[i])
free(ArgumentVectorArray[i]);
}
mainExit5:
for (i = 0; i < DSPCount; i++) {
if (EventArray[i])
CloseHandle(EventArray[i]);
}
mainExit4:
cruntimeExit();
TMDwnLdr_unload_shared_section_table(SharedSections);
mainExit3:
for (i = 0; i < DSPCount; i++) {
if (DSPHandle[i])
tmmanDSPClose(DSPHandle[i]);
}
mainExit2:
SetConsoleCtrlHandler(tmrunControlHandler, FALSE);
mainExit1:
if (Interactive) {
fprintf(stdout, "\nTMMPRun:Press [ENTER] to close server >>");
getchar();
}
return GlobalExitCode;
mainUsage:
fprintf(stderr,
"usage: TMMPRun [-wWindowSize] [-b] "
"-exec ExecutableImageName [Arg1] [Arg2] ... "
"-exec ExecutableImageName [Arg1] [Arg2] ...\n");
goto mainExit1;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -