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

📄 ctc.c

📁 wince host 和 target PCI驱动程序
💻 C
📖 第 1 页 / 共 5 页
字号:
			// then the string ends. 
			//TR960223
			if ( ( iscntrl ( pszString[*pwPosition] ) )  ||
				( isspace (  pszString[*pwPosition] ) )	 )
			{
				fExit = 1;
			}	
			else
			{
				*pszToken++ = pszString[(*pwPosition)++];
				wState = GNT_ALPHA;
			}
			break;

			// wrong state : FSM screwed.
			default :
			break;
		}
	}
	*pszToken = '\0';
	return TRUE;
}

/*----------------------------------------------------------------------------
FUNC	ReadInputLine
ABOUT
	Calls the device class read function and accumulates all the characters
	read until the buffers fills up or a CR is encountered.
	Echos the characters back to the output.
----------------------------------------------------------------------------*/
BOOL	ReadInputLine (PVOID pParserObj, PSTR pszInputString)
{
	WORD	wStringIdx;
	CHAR	bChar;
	PPARSER	pParser = (PPARSER)pParserObj;

	for ( wStringIdx = 0 ; wStringIdx < (MAX_STRING - 1 ) ; )
	{
		(*pParser->ReadChar)(pParser->pDevice, &bChar, 1);
		switch ( bChar )
		{
			case '\b' :
			if ( wStringIdx > 0 )
			{
				wStringIdx--;
				(*pParser->WriteChar)(pParser->pDevice, "\b", 1);
				(*pParser->WriteChar)(pParser->pDevice, " ", 1);
				(*pParser->WriteChar)(pParser->pDevice, "\b", 1);
			}
			break;

			case '\r' :
			case '\n' :
			(*pParser->WriteChar)(pParser->pDevice, &bChar, 1);

			pszInputString[wStringIdx] = 0;
			return TRUE;

			case '\t' :
			bChar = ' ';

			//  fall 
			default :
			pszInputString[wStringIdx] = bChar;
			(*pParser->WriteChar)(pParser->pDevice, &bChar, 1);

			wStringIdx++;
			break;
		}
	
	}
	pszInputString[wStringIdx] = 0;
	// indicate that this string was not terminated by a CR.
	return FALSE;
}


/*----------------------------------------------------------------------------
FUNC	ProcessLine
ABOUT
	Parses the command line input from file or keyboard.
----------------------------------------------------------------------------*/
BOOL	ProcessLine ( PVOID pContext )
{
	CHAR	szToken[80];
	WORD	wPosition = 0;
	PPARSER	pParser = (PPARSER)pContext;
	CHAR	szTempString[80];
	DWORD	dwMemIdx;
	DWORD	dwScrIdx;
	DWORD	dwValue;
	WORD	wIdxCmd;
	DWORD	dwBytesXfered;


	for ( ; ; ) 
	{

		if ( GetNextToken ( 
			pParser->szInputString, &wPosition , szToken ) == FALSE )
		{
			// end of current input line.
			
			return TRUE;
		}

		if ( pParser->wState == CMD_WAIT )
		{ 
			if ( strlen( szToken) > 8 )
			{
				goto ProcessLine_syntax;
			}
			for ( wIdxCmd = 0 ; wIdxCmd < MaxCommands ; wIdxCmd++ )
			{
				if ( stricmp ( szToken , CmdTable[wIdxCmd].pszCmd ) == 0 )
				{
					pParser->wState = CmdTable[wIdxCmd].wCmdState;
					break;
				}

			}
			if ( wIdxCmd == MaxCommands )
			{
				goto ProcessLine_syntax;
			}
		}

		switch ( pParser->wState )
		{
			/* Debugging Comamnds */
			case DEBUGON_CMD :
			pParser->DebugOn = TRUE;
			pParser->wState = DEBUGON_OPTIONS;
			break;

			case DEBUGOFF_CMD :
			pParser->DebugOn = FALSE;
			pParser->wState = DEBUGON_OPTIONS;
			break;

			case DEBUGON_OPTIONS :
			case DEBUGOFF_OPTIONS :
			if ( szToken[0] == '.' ) /* set the options */
			{
				TMMAN_DSP_INFO	Info;
				PTMHD_DBG_SHARED pDBG;

				tmDSPGetMiscInfo ( ((PTM_HW)pParser->pTMHW)->DSPHandle, 
					&Info );
				pDBG = Info.pDBGSharedData;

				if ( pParser->DebugOn )
				{
					pDBG->OptionBits |= pParser->DebugOptions;
				}
				else
				{
					pDBG->OptionBits &= pParser->DebugOptions;
				}
				pParser->wState = CMD_WAIT;
			}
			else /* process the next debug on option */
			{
				DWORD Options;
				if ( ( Options = GetDebugBit ( szToken ) ) != 0 )
				{
					if ( pParser->DebugOn )
					{
						pParser->DebugOptions |= Options;
					}
					else
					{
						 pParser->DebugOptions &= Options;
					}
				}
				else
				{
					goto ProcessLine_syntax;
				}
			}
			break;


			case TRACEV_CMD :
			{
				TMMAN_DSP_INFO	Info;
				PTMHD_DBG_SHARED pDBG;
				DWORD PrintableLength1;

				tmDSPGetMiscInfo ( ((PTM_HW)pParser->pTMHW)->DSPHandle, 
					&Info );
				pDBG = Info.pDBGSharedData;
				PrintableLength1 = pDBG->VBufPos;
			
				pParser->WriteStr(pParser->pDevice,"\r\n");
				if ( pDBG->VWrapped ) /* wrap around has occured */
				{
					DWORD PrintableLength2 = pDBG->VBufLen - pDBG->VBufPos;
					pParser->WriteChar ( pParser->pDevice,  
						&pDBG->VBuffer[pDBG->VBufPos],
						PrintableLength2 );
				}

				pParser->WriteChar ( pParser->pDevice,  
					&pDBG->VBuffer[0], PrintableLength1 );
			}
			pParser->wState = CMD_WAIT;
			break;

			case	TRACEP_CMD :
			pParser->wState = TRACEP_FILENAME;
			break;


			case	TRACEP_FILENAME :
			{
				PBYTE pSDRAM =	(PBYTE )halGetSDRAMLin ( pParser->pTMHW );
				DWORD SDRAMLength = halGetSDRAMLen ( pParser->pTMHW );
				PTMHD_DBG_PBUFFER pDBG;
				DWORD PrintableLength1, PrintableLength2;
				DWORD BytesWritten, Idx;
				CHAR	szMagic[TMHD_DBG_MAGICSIZE];
				PBYTE pBuffer;

				if ( szToken[0] == '.' )
				{	/* no filename print to stdout */
					pParser->wState = CMD_WAIT;
					pParser->WriteStr(pParser->pDevice,"\r\n");


					strcpy ( szMagic, TMHD_DBG_BUFMAGIC );
					szMagic[0] = 'T';
					szMagic[1] = 'M';
					szMagic[2] = '-';
					szMagic[3] = 'S';
					szMagic[4] = 'o';
					szMagic[5] = 'f';
					szMagic[6] = 't';

					/* search the entire SDRAM for the magic string */
					for ( Idx = 0 ; Idx < SDRAMLength ;
						Idx += TMHD_DBG_MAGICSIZE, pSDRAM += TMHD_DBG_MAGICSIZE )
					{
						if ( strcmp ( pSDRAM, szMagic ) == 0 )
						{
							break;
						}
					}

					if ( Idx >= SDRAMLength )
					{
						pParser->WriteStr(pParser->pDevice,
							"\r\nTMMon : ERROR : No Debug Information in SDRAM");
						break;
					}


					pDBG = (PTMHD_DBG_PBUFFER )pSDRAM;
					PrintableLength1 = pDBG->PBufPos;
					PrintableLength2 = pDBG->PBufLen - pDBG->PBufPos;
					pBuffer = tmPhysToLin( pDBG->pPBuffer, &TMHW.DSPCaps.SDRAM );

					if ( pParser->fTraceIntoFile == FALSE )
					{
						if ( pDBG->PWrapped ) /* wrap around has occured */
						{
							
							pParser->WriteChar ( pParser->pDevice,  
								pBuffer + pDBG->PBufPos, PrintableLength2 );
						}

						pParser->WriteChar ( pParser->pDevice,  
							pBuffer, PrintableLength1 );
					}
					else /* open the trace file and write to it */
					{
						HANDLE hFile;
						
						PBYTE pBuffer = tmPhysToLin( pDBG->pPBuffer,
								&TMHW.DSPCaps.SDRAM ); 
						SYSTEMTIME	Time;
						DWORD	SizeOfMachineName;
						DWORD	RegType;
						HANDLE	hKey;
						CHAR	szMachineName[MAX_COMPUTERNAME_LENGTH + 1];
						CHAR	szString[80];
						SizeOfMachineName = MAX_COMPUTERNAME_LENGTH + 1;
						pParser->fTraceIntoFile = FALSE;

						if ( ( hFile  = CreateFile ( pParser->szTraceFileName , 
							GENERIC_READ | GENERIC_WRITE, 0,
							NULL,
							CREATE_ALWAYS,
							FILE_ATTRIBUTE_NORMAL,
							NULL ) ) == (HANDLE)-1 )
						{
							sprintf ( szTempString,
								"\r\nTMMon : ERROR [%x] : Creating Trace File [%s]",
								GetLastError(), pParser->szTraceFileName  );

							pParser->WriteStr(pParser->pDevice,	szTempString);
							break;
						}

						/*
						RegOpenKeyEx (
							HKEY_LOCAL_MACHINE,
							"System\\CurrentControlSet\\control\\ComputerName\\ComputerName",
							0, KEY_QUERY_VALUE, &hKey );

						
						RegType = REG_SZ;
						RegQueryValueEx ( hKey,
							"ComputerName",
							NULL,&RegType, szMachineName, &SizeOfMachineName );

						szMachineName[SizeOfMachineName+1] = 0;
						*/

						GetComputerName ( szMachineName, &SizeOfMachineName );
						SizeOfMachineName = GetLastError();

						GetLocalTime(&Time);
						sprintf ( szString,
							"TMMon:TraceFile:Machine[%s]:D[%02d.%02d.%04d]:T[%02d:%02d:%02d]:Size[%u]\n",
							szMachineName, Time.wMonth,  Time.wDay, Time.wYear,
							Time.wHour, Time.wMinute, Time.wSecond,
							( (pDBG->PWrapped == TRUE )?  pDBG->PBufLen  : pDBG->PBufPos ) );

						if ( WriteFile (  hFile,
							szString, strlen( szString ),
							&BytesWritten, NULL ) != TRUE )
						{
							pParser->WriteStr(pParser->pDevice,
								"\r\nTMMon : ERROR : Writing Trace File Header");
							CloseHandle ( hFile );
							break;
						}
	
						if ( pDBG->PWrapped ) /* wrap around has occured */
						{
							if ( WriteFile (  hFile,
								pBuffer + pDBG->PBufPos,
								PrintableLength2,
								&BytesWritten, NULL ) != TRUE )
							{
								pParser->WriteStr(pParser->pDevice,
									"\r\nTMMon : ERROR : Writing Trace File");
								CloseHandle ( hFile );
								break;
							}
						}

						if ( WriteFile (  hFile,
							pBuffer, PrintableLength1,
							&BytesWritten, NULL ) != TRUE )
						{
							pParser->WriteStr(pParser->pDevice,
								"\r\nTMMon : ERROR : Writing Trace File");
							CloseHandle ( hFile );
							break;
						}

						CloseHandle ( hFile );
					}

				}
				else /* second parameter is a filename */
				{
					if ( pParser->fTraceIntoFile == TRUE ) 
					{
						pParser->fTraceIntoFile = FALSE;
						goto ProcessLine_syntax;
					}
					/* copy the filename in to the parser data structure */
					pParser->fTraceIntoFile = TRUE;
					strcpy ( pParser->szTraceFileName,szToken );
					break;
				}

			}
			break;

			/*
				Read Memory Command 
			*/
			case RB_CMD :
			pParser->wDataSize = 1;
			pParser->wState = RX_ADDRESS;
			break;

			case RW_CMD :
			pParser->wDataSize = 2;
			pParser->wState = RX_ADDRESS;
			break;

			case RD_CMD :
			pParser->wDataSize = 4;
			pParser->wState = RX_ADDRESS;
			break;

			case RX_ADDRESS :
			pParser->wState = RX_LENGTH;
			goto ProcessLine_address;

			case RX_LENGTH :
			if ( sscanf( szToken,"%x", &pParser->dwLength ) != 1)
			{
				goto ProcessLine_syntax;
			}
			if ( !halValidateLength ( pParser->pTMHW, pParser->dwAddress,
				pParser->dwLength ) )
			{
				goto ProcessLine_range;
			}
			// TR960626 fix for BUG0002
			if ( ! pParser->fSDRAM )
			{
					pParser->wDataSize = 4;				
			}
			pParser->wState = CMD_WAIT;
			goto ProcessLine_readmem;

			/*
				Write Memory Command
			*/
			case WB_CMD :
			pParser->wDataSize = 1;
			pParser->wState = WX_ADDRESS;
			break;

			case WW_CMD :
			pParser->wDataSize = 2;
			pParser->wState = WX_ADDRESS;
			break;
			
			case WD_CMD :
			pParser->wDataSize = 4;
			pParser->wState = WX_ADDRESS;
			break;						

			case WX_ADDRESS :
			pParser->wState = WX_DATA;
			pParser->dwLength = 0;
			goto ProcessLine_address;

			/*
				Routines common to read and write 
			*/
			ProcessLine_address :
			if ( IsValidHex ( szToken, 8 ) == FALSE )
			{
				goto	ProcessLine_syntax;
			}
			if ( sscanf( szToken,"%x", &pParser->dwAddress ) != 1)
			{
				goto	ProcessLine_syntax;
			}
			if ( ! halValidateAddress ( pParser->pTMHW , pParser->dwAddress,
				&pParser->fSDRAM ) )
			{
				goto ProcessLine_range;
			}
			pParser->dwStartAddress = pParser->dwAddress;
			// TR960627 fix for BUG0002
			if ( ! pParser->fSDRAM )
				pParser->wDataSize = 4;

			break;

			ProcessLine_length :
			if ( IsValidHex ( szToken, 8 ) == FALSE )
			{
				goto	ProcessLine_syntax;
			}
			if ( sscanf( szToken,"%x", &pParser->dwLength ) != 1)
			{
				goto ProcessLine_syntax;
			}
			if ( !halValidateLength ( pParser->pTMHW, pParser->dwAddress,
				pParser->dwLength ) )
			{
				goto ProcessLine_range;
			}
			break;

			ProcessLine_readmem :
			/* 
				rogiers request to read the location that were just
				written into. Add code here.
			*/
			for ( pParser->dwLinesWritten = 0, dwMemIdx = 0 ; 
				dwMemIdx < pParser->dwLength ; )
			{
				pParser->szOutputString[0] = 0;
			
				sprintf ( szTempString, "\r\n%08x :", pParser->dwAddress );
				strcat ( pParser->szOutputString, szTempString );

⌨️ 快捷键说明

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