⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tmmprun.c

📁 wince host 和 target PCI驱动程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/* *  copyright (c) 1997-2000 by Philips Semiconductors * *   +-----------------------------------------------------------------+ *   | This software is furnished under a license and may only be used | *   | and copied in accordance with the terms and conditions of such  | *   | a license and with the inclusion of the this copy right notice. | *   | this software or any other copies of this software may not be   | *   | provided or otherwise made available to any other person. The   | *   | ownership and title of this software is not transferred.        | *   +-----------------------------------------------------------------+ * *  Revision history: *	961026 CJP		Tested and basically working. *				More error checking and reporting added. *	970106 Tilakraj Roy	Added support for the TMCons in tmDSPRunExecutable. *				Commenetd the use of tmDSPRunExecutable. *	970114 Tilakraj Roy	Added command line processing of windows size. *	970128 Tilakraj Roy	Added tmDSPExecutableStop in exit function. *	970327 Tilakraj Roy	Revamped the entire code for proper error handling. *				Added the ExitEvent for proper cleanup. *	970630 Tilakraj Roy	Added multiprocessor support. *	970631 Tilakraj Roy	Added new cruntime support. *	970728 Tilakraj Roy	Fixed exit code error bug. *	991124 Rudy Wang	Up the max node to 256, added error checking for *				exceeding the max node.  Also cleaned up all the *				compiler warnings and reformatted the source. * *  Description: * *	This module is driver for the host part of the PC version of the *	Level 2 Remote Procedure Call Server.  An implementation of this *	is needed for each particular host of a TM-1 board which uses TCS's *	generic ANSI C library. * *	In its current form this module is intended to run as an independent *	executable that must be started from a PC command line.  Its first *	argument must be the name of a TM-1 executable which is to be downloaded, *	started, and which is passed all additional command line arguments. *	Between starting the executable and receiving its termination message, *	this module behaves as a server for the HostCall interface. */#include <windows.h>#include <stdio.h>#include <winioctl.h>#include "tmmanapi.h"#include "tmcrt.h"#include "tmif.h"#include "TMDownLoader.h"#define MAXIMUM_NODES			256#define MAXIMUM_COMMAND_LINE_ARGS	100#define DEFAULT_CLOCK_SPEED		100000000#define tmmanDownloaderStatusToTMManStatus(x) \		(((x) != TMDwnLdr_OK) ? ((x)+0x70) : statusSuccess)DWORD		DSPCount		= 0;DWORD		GlobalExitCode		= (~0x0);BOOL		Interactive		= TRUE;PCHAR		TargetExecutableName	= NULL;DWORD		TargetArgumentOffset;HANDLE		EventArray[MAXIMUM_NODES];TCHAR		szTemp[2048];extern HANDLE	tmmanGetDriverHandle(void);/* * For details on TMDwnLdr functions, refer to the chapter * "TriMedia Downloader API" in the book "Software Library APIs" * * For details on tmman and cruntime functions, refer to the chapter * "TriMedia Manager API" in the book "Software Library APIs" */voidWarningBox(TCHAR* ErrorString){  MessageBox(NULL,	     ErrorString,	     TEXT("TriMedia Manager : tmmprun.exe : WARNING"),	     MB_OK | MB_ICONWARNING | MB_DEFBUTTON1 | MB_APPLMODAL);}/* * control C handler */BOOL WINAPItmrunControlHandler(DWORD dwCtrlType){  DWORD i;  fprintf(stderr, "\nTMMPRun:Control C Detected : Performing Cleanup\n");  for (i = 0; i < DSPCount; i++) {    SetEvent(EventArray[i]);  }  return TRUE;}/* * download the memory image to DSP */TMStatustmDSPExecutableLoadEx(  DWORD		DSPHandle,  PCHAR		pszImagePath,  DWORD		NumberOfDSPs,  TMDwnLdr_SharedSectionTab_Handle SharedSections,  PDWORD	MMIOPhysicalAddressArray){  TMDwnLdr_Object_Handle ObjectHandle;  tmmanDSPInternalInfo DSPInternalInfo;  tmmanDSPInfo	DSPInfo;  TMStatus	Status;  tmifDSPLoad	TMIF;  UInt32	ImageSize;  UInt32	Alignment;  DWORD		AlignedDownloadAddress;  UInt32	dlStatus;  Endian	endian;  UInt32	BytesReturned;  UInt32	TargetVersion;  UInt32	HostType	= tmWinNTHost;  UInt32	ClockSpeed	= DEFAULT_CLOCK_SPEED;  UInt32	CacheOption	= TMDwnLdr_LeaveCachingToDownloader;  /* default cache option */  UInt32	INIEndianess	= True;  /* little endian */  HKEY		RegistryHandle;  HKEY		RegistryHandleDevice;  TCHAR		szDeviceName[0x10];  /*   * map SDRAM into the Operating System and Process virtual address space   */  Status = tmmanDSPMapSDRAM(DSPHandle);  if (Status != statusSuccess) {    OutputDebugString(TEXT("TMMPRun:tmmanDSPMapSDRAM:FAIL\n"));    return Status;  }  tmmanDSPGetInfo(DSPHandle, &DSPInfo);  tmmanDSPGetInternalInfo(DSPHandle, &DSPInternalInfo);  if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE,				    constTMManRegistryPath,				    0,				    KEY_READ,				    &RegistryHandle)) {    ULONG BytesXfered = sizeof(ULONG);    if (ERROR_SUCCESS != RegQueryValueEx(RegistryHandle,					 TEXT("DefaultEndianness"),					 NULL,					 NULL,					 (BYTE*)&INIEndianess,					 &BytesXfered)) {      INIEndianess = True;    }    wsprintf(szDeviceName, TEXT("Device%x"), DSPInfo.DSPNumber);    if (ERROR_SUCCESS == RegOpenKeyEx(RegistryHandle,				      szDeviceName,				      0,				      KEY_READ,				      &RegistryHandleDevice)) {      BytesXfered = sizeof(ULONG);      if (ERROR_SUCCESS != RegQueryValueEx(RegistryHandleDevice,					   TEXT("ClockSpeed"),					   NULL,					   NULL,					   (BYTE*)&ClockSpeed,					   &BytesXfered)) {	ClockSpeed = DEFAULT_CLOCK_SPEED;      }      BytesXfered = sizeof(ULONG);      if (ERROR_SUCCESS != RegQueryValueEx(RegistryHandleDevice,					   TEXT("CacheOption"),					   NULL,					   NULL,					   (BYTE*)&CacheOption,					   &BytesXfered)) {	CacheOption = TMDwnLdr_LeaveCachingToDownloader;      }      RegCloseKey(RegistryHandleDevice);    }    RegCloseKey(RegistryHandle);  }  /*   * read the executable from file into memory, and use   * the handle returned for subsequent operations   */  dlStatus = TMDwnLdr_load_object_from_file(pszImagePath,					    SharedSections,					    &ObjectHandle);  if (dlStatus != TMDwnLdr_OK) {    Status = tmmanDownloaderStatusToTMManStatus(dlStatus);    goto tmDSPExecutableLoadExit2;  }  /*   * BEGIN symbol patching   */  dlStatus = TMDwnLdr_resolve_symbol(ObjectHandle,				     "_TMManShared",				     DSPInternalInfo.TMManSharedPhysicalAddress);  if (dlStatus != TMDwnLdr_OK) {    OutputDebugString(TMDwnLdr_get_last_error(dlStatus));    HostType = tmNoHost;    WarningBox(TEXT("Target Executable has not been linked with "		    "[-host WinNT] or [-host Windows]\n"));  }  /*   * get the extracted image size, and its required alignment in SDRAM   */  dlStatus = TMDwnLdr_get_image_size(ObjectHandle, &ImageSize, &Alignment);  if (dlStatus != TMDwnLdr_OK) {    Status = tmmanDownloaderStatusToTMManStatus(dlStatus);    OutputDebugString(TMDwnLdr_get_last_error(dlStatus));  }  else {    AlignedDownloadAddress = ((DSPInfo.SDRAM.PhysicalAddress + Alignment - 1) &			      (~(Alignment - 1)));    /*     * relocate the loaded executable into a specified TM1 address range,     * with specified values for MMIO_base and TM1_frequency.     */    dlStatus = TMDwnLdr_multiproc_relocate(ObjectHandle,					   HostType,					   (Address*)MMIOPhysicalAddressArray,					   DSPInfo.DSPNumber,					   NumberOfDSPs,					   ClockSpeed,					   (Address)AlignedDownloadAddress,					   DSPInfo.SDRAM.Size,					   CacheOption);    if (dlStatus != TMDwnLdr_OK) {      OutputDebugString(TMDwnLdr_get_last_error(dlStatus));      Status = tmmanDownloaderStatusToTMManStatus(dlStatus);      goto tmDSPExecutableLoadExit3;    }    /*     * Get the endianness of the specified loaded object     */    dlStatus = TMDwnLdr_get_endian(ObjectHandle, &endian);    if (dlStatus != TMDwnLdr_OK) {      OutputDebugString(TMDwnLdr_get_last_error(dlStatus));      Status = tmmanDownloaderStatusToTMManStatus(dlStatus);      goto tmDSPExecutableLoadExit3;    }    if ((Endian)INIEndianess != endian) {      Status = statusExecutableFileWrongEndianness;      goto tmDSPExecutableLoadExit3;    }    TMIF.DSPHandle = DSPHandle;    TMIF.Endianess = ((endian == LittleEndian) ?		      constTMManEndianessLittle :		      constTMManEndianessBig);    dlStatus = TMDwnLdr_get_contents(ObjectHandle,				     "__TMMan_Version",				     &TargetVersion);    if (dlStatus != TMDwnLdr_OK) {      TMIF.PeerMajorVersion = constTMManDefaultVersionMajor;      TMIF.PeerMinorVersion = constTMManDefaultVersionMinor;    }    else {      /*       * major version = __TMMan_Version[31:16]       * minor version = __TMMan_Version[15:0]       */      TMIF.PeerMajorVersion = ((TargetVersion  & 0xffff0000) >> 16);      TMIF.PeerMinorVersion = TargetVersion & (0x0000ffff);      if ((TMIF.PeerMajorVersion != constTMManDefaultVersionMajor) ||	  (TMIF.PeerMinorVersion != constTMManDefaultVersionMinor)) {	wsprintf(szTemp,		 TEXT("Target Executable Version [%d.%d] is INCOMPATIBLE "		      "with TriMedia Driver Version [%d.%d]\n"),		 TMIF.PeerMajorVersion,		 TMIF.PeerMinorVersion,		 constTMManDefaultVersionMajor,		 constTMManDefaultVersionMinor);	switch ((MessageBox(NULL,			    szTemp,			    TEXT("TriMedia Manager : TMMPRun.exe : Continue ? "),			    MB_OKCANCEL | MB_ICONQUESTION | MB_DEFBUTTON1 | MB_APPLMODAL))) {	case IDOK:	  break;	case IDCANCEL:	default:	  Status = ((TMIF.PeerMajorVersion != constTMManDefaultVersionMajor) ?		    statusMajorVersionError :		    statusMinorVersionError);	  goto tmDSPExecutableLoadExit3;	}      }    }    /*     * call to kernel mode driver     */    if (DeviceIoControl(tmmanGetDriverHandle(),			constIOCTLtmmanDSPLoad,			(PVOID)&TMIF, sizeof(tmifDSPLoad),			(PVOID)&TMIF, sizeof(tmifDSPLoad),			&BytesReturned, NULL) != TRUE) {      Status = TMIF.Status;    }    else {      dlStatus = TMDwnLdr_get_memory_image(ObjectHandle,					   (UInt8*)tmmanPhysicalToMapped(&DSPInfo.SDRAM,									 AlignedDownloadAddress));      if (dlStatus != TMDwnLdr_OK) {	OutputDebugString(TMDwnLdr_get_last_error(dlStatus));	Status = tmmanDownloaderStatusToTMManStatus(dlStatus);      }    }  }tmDSPExecutableLoadExit3:  TMDwnLdr_unload_object(ObjectHandle);tmDSPExecutableLoadExit2:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -