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

📄 utils.cpp

📁 The Lite Evaluation/Demonstration Kit is intended to illustrate use of the AN3042. The AN3042 is c
💻 CPP
字号:
//////////////////////////////////////////////////////////////////////
//
// File: utils.cpp 
//
// $Archive: /ComemL/Host/ComemLif/utils.cpp $
//
// Purpose:
//
// $Author: Tpm $
//
// $History: utils.cpp $
//  
//  *****************  Version 12  *****************
//  User: Tpm          Date: 11/11/98   Time: 2:28p
//  Updated in $/ComemL/Host/ComemLif
//  Used cast (unsigned short) to remove compile warning.
//  
//  *****************  Version 11  *****************
//  User: Tpm          Date: 11/06/98   Time: 4:58p
//  Updated in $/ComemL/Host/ComemLif
//  Creat seperate directory for ComemLite IF Library.
//  
//  *****************  Version 9  *****************
//  User: Tpm          Date: 8/27/98    Time: 10:30a
//  Updated in $/Comem/Mapper
//  Aug Plug-Fest version.
//  
//  *****************  Version 8  *****************
//  User: Tpm          Date: 8/27/98    Time: 9:12a
//  Updated in $/ComemL/Host/ComemLif
//  use ComelL.vxd.
//  
//  *****************  Version 7  *****************
//  User: Tpm          Date: 1/09/98    Time: 5:33p
//  Updated in $/Comem/Mapper
//  Change Target to Local Processor
//  
//  *****************  Version 6  *****************
//  User: Stevek       Date: 10/28/97   Time: 9:57a
//  Updated in $/Comem/comem_if
//  More seperation for seperate library file.
//  Removed embeddedSystems stuff.
//  
//  *****************  Version 5  *****************
//  User: Stevek       Date: 10/27/97   Time: 1:16p
//  Updated in $/Comem/Mapper
//  Moved interface functions into the comem_if.lib file.
//  
//  *****************  Version 4  *****************
//  User: Stevek       Date: 10/22/97   Time: 12:27p
//  Updated in $/Comem/Mapper
//  Added header blocks to all files at once!
//  
// Copyright (c) 1997 Anchor Chips, Inc.  May not be reproduced without
// permission.  See the license agreement for more details.
//
//////////////////////////////////////////////////////////////////////
// Inputs:
//		time (long) -- non zero value = number of ticks until timeout (set timer)
//							zero = poll timer
//		Timer -- timer number to use (0-9)
//			FOREGROUND_TIMER (0) -- used for any task sitting still while waiting for an event
//
// Outputs:
//		0 -- Timer has not expired
//		1 -- Timer has expired
//
// Example:
//		timeout2(ONE_SECOND, 1)
//		while (!timeout2(0L, 1))	// wait for timeout
//			;
// OR
//   for (timeout2(ONE_SECOND, 1); !timeout2(0L, 1);)
//       ;
#include <afxwin.h>
//#include <windows.h>
#include <sys\timeb.h>
#include <stdio.h>
#include "comemDevice.h"
int timeout(unsigned long time, unsigned timer)
{
	#define DIVISOR	18L
	static struct timeb oldtimebuff[10];
	struct timeb timebuff;

	/* get the time B4 we let them have control, so we get at least one*/
	/* good one before a timeout occurs */
	ftime(&timebuff);

	if (time)
		{
		/* save current time */
		memmove(&(oldtimebuff[timer]), &timebuff, sizeof(struct timeb));

		if ((oldtimebuff[timer].millitm += (unsigned short)((time % DIVISOR) * 1000L/DIVISOR)) >= 1000)
			{
			oldtimebuff[timer].millitm -= 1000;
			time += DIVISOR;
			}

		oldtimebuff[timer].time += time / DIVISOR;
		return(0);
		}

	if (timebuff.time > oldtimebuff[timer].time)
		return(1);
	
	if (timebuff.time == oldtimebuff[timer].time)
		if (timebuff.millitm > oldtimebuff[timer].millitm)
			return(1);

	return(0);
}



void reportErrorCode(DWORD status, char * whereAmI)
{
	char buf[0x1000];

	switch(status)
		{
      case  ERROR_INVALID_REGION:
         strcpy(buf, "Invalid region detected");
         break;
         
      case  ERROR_INVALID_ADDIN_ADDR:
         strcpy(buf, "Invalid Local processor address detected");
         break;
         
      case  ERROR_OVERLAID_REGION:
         strcpy(buf, "Region was totally obscured by another");
         break;
         
      case  ERROR_BAD_PAGE_TABLE:
         strcpy(buf, "Bad page table detected");
         break;
         
      case  ERROR_MEMORY_ALLOC:
         strcpy(buf, "Memory allocation error");
         break;
         
      case  ERROR_ALLOC_EXISTS:
         strcpy(buf, "Memory alread allocated.  Must deallocate before allocating.");
         break;
         
      case  ERROR_NO_DRIVER:
         strcpy(buf, "Driver is not resident");
         break;
         
      case  ERROR_INVALID_COMEM_ID:
         strcpy(buf, "Invalid comem ID");
         break;
         
      case  ERROR_DEVICE_NOT_FOUND:
         strcpy(buf, "Device not found");
         break;
         
      case  ERROR_UNKNOWN:
         strcpy(buf, "Unknown error code detected");
         break;
         
      default:
         strcpy(buf, "An error was reported that is not in our table");
         break;
         
		}
      
   if (whereAmI)
     {
      strcat(buf, " while ");
      strcat(buf, whereAmI);
     }
   else  
      strcat(buf, ".");
            
	AfxMessageBox(buf, MB_OK | MB_ICONEXCLAMATION);
}
void report_error(const char *fmt, ...)
{
	char buf[0x1000];
	va_list va;
	va_start( va, fmt );
	vsprintf( buf, fmt, va );
	va_end( va );
	AfxMessageBox(buf, MB_OK | MB_ICONEXCLAMATION);
}


// Assign data only
// Return 0 if no data scanned
int my_sscanf(LPCSTR cBuffer, DWORD *data)
{
	char *ptr;
   char buffer[0x100];
	int value;

   strcpy(buffer, cBuffer);

	if (ptr = strchr(_strlwr(buffer), 'k'))
	{
		*ptr = 0;
		if (sscanf(buffer, "%d", &value))
		{
			*data = value * ONE_K;
			return 1;
		}
		*ptr = 'K';		// failed, but let's put it back
	}

	if (ptr = strchr(_strlwr(buffer), 'm'))
	{
		*ptr = 0;
		if (sscanf(buffer, "%d", &value))
		{
			*data = value * ONE_MEG;
			return 1;
		}
		*ptr = 'M';		// failed, but let's put it back
	}

	if (ptr = strpbrk(buffer, "xX"))
	{
		if (sscanf(ptr+1, "%x", &value))
			{
				*data = value;
				return 1;
			}
	}
	else if (sscanf(buffer, "%x", &value))
	{
		*data = value;
		return 1;
	}
	return 0;
}




⌨️ 快捷键说明

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