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

📄 efcapi.cpp

📁 基于Nuleus操作系统和s3c4510的编写的EFC。已经包含了该EFC的设计说明。这是个实际产品的代码
💻 CPP
字号:
///////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2003, Ulink Telecom Equipment Co., Ltd. All rights reserved.
//
// File:
//
//    EFCAPI.CPP
//
// Abstract:
//
//    Implementation for the commonly used global functions.
//
// History:
//
//    V1.0	2003-01-06	Alex Duan	Original version.
//
///////////////////////////////////////////////////////////////////////////////

#include "EFC.H"
#include "rtcDriver.h"
#include "APPCORE.H"

#ifdef _DEBUG
static BOOL IsValidMemoryPool(NU_MEMORY_POOL &mpPool)
{
	char	szPoolName[8];
	void	*pStartAddress = NULL;
	DWORD	dwPoolSize;
	DWORD	dwMinAlloc;
	DWORD	dwAvailable;
	OPTION	oSuspendType;
	DWORD	dwTasksSuspended;
	NU_TASK *pFirstTask = NULL;
	STATUS	status;
	status = NU_Memory_Pool_Information(&mpPool, 
										szPoolName,
										&pStartAddress, 
										&dwPoolSize,
										&dwMinAlloc,
										&dwAvailable, 
										&oSuspendType,
										&dwTasksSuspended, 
										&pFirstTask);
	return (status == NU_SUCCESS);
}
#endif // _DEBUG

// Over loading the operator new.
void* operator new(size_t sz)
{
	void *pRetVal = NULL;
	STATUS status;
	
	ASSERT(IsValidMemoryPool(System_Memory));

	status = NU_Allocate_Memory(&System_Memory, &pRetVal, sz, NU_NO_SUSPEND);
	
	ASSERT(status == NU_SUCCESS && pRetVal != NULL);
	return pRetVal;
}

// Over loading the operator delete.
void operator delete(void *p)
{
	if (p != NULL) 
	{
		NU_Deallocate_Memory(p);
	}
	else
	{
		TRACE("DELETING NULL POINTER!\n");
	}
}

// Over loading the operator new[].
void* operator new[](size_t sz)
{
	void *pRetVal = NULL;
	STATUS status;

	ASSERT(IsValidMemoryPool(System_Memory));
	
	status = NU_Allocate_Memory(&System_Memory, &pRetVal, sz, NU_NO_SUSPEND);
	
	ASSERT(status == NU_SUCCESS && pRetVal != NULL);
	return pRetVal;
}

// Over loading the operator delete[].
void operator delete[](void *p)
{
	if (p != NULL) 
	{
		NU_Deallocate_Memory(p);
	}
	else
	{
		TRACE("DELETING NULL POINTER!\n");
	}
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		pDateTime	[in]The DATETIME format value needs to be converted.
//		pSystemTime	[out]The SYSTEMTIME format result.
// Remarks:
//		Convert DATETIME value to SYSTEMTIME value.
void DateTime2SystemTime(SYSTEMTIME *pSystemTime, const DATETIME *pDateTime)
{
	ASSERT(pDateTime);
	ASSERT(pSystemTime);

	WORD wYear;
	pSystemTime->uSecond = BCD2BYTE(pDateTime->uSecond);
	pSystemTime->uMinute = BCD2BYTE(pDateTime->uMinute);
	pSystemTime->uHour	 = BCD2BYTE(pDateTime->uHour);
	pSystemTime->uDay	 = BCD2BYTE(pDateTime->uDay);
	pSystemTime->uMonth  = BCD2BYTE(pDateTime->uMonth);
	wYear = BCD2WORD(pDateTime->uYearH) * 100 + BCD2WORD(pDateTime->uYearL);
	pSystemTime->uYearH	 = HIBYTE(wYear);
	pSystemTime->uYearL  = LOBYTE(wYear);
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		pSystemTime	[in]The SYSTEMTIME format value needs to be converted.
//		pDateTime	[out]The DATETIME format result.
// Remarks:
//		Convert SYSTEM value to DATETIME value.
void SystemTime2DateTime(DATETIME *pDateTime, const SYSTEMTIME *pSystemTime)
{
	ASSERT(pSystemTime);
	ASSERT(pDateTime);

	WORD wYear;
	pDateTime->uSecond	= BYTE2BCD(pSystemTime->uSecond);
	pDateTime->uMinute	= BYTE2BCD(pSystemTime->uMinute);
	pDateTime->uHour	= BYTE2BCD(pSystemTime->uHour);
	pDateTime->uDay		= BYTE2BCD(pSystemTime->uDay);
	pDateTime->uMonth	= BYTE2BCD(pSystemTime->uMonth);
	
	wYear = MAKEWORD(pSystemTime->uYearL, pSystemTime->uYearH);
	wYear = WORD2BCD(wYear);
	pDateTime->uYearL	= LOBYTE(wYear);
	pDateTime->uYearH	= HIBYTE(wYear);
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		pSystemTime	[out] Pointer to a SYSTEMTIME struct to receive the current
//					system date and time.
// Remarks:
//		Retrieves the current system date and time.
void GetSystemTime(SYSTEMTIME *pSystemTime)
{
	ASSERT(pSystemTime);

#if defined(WIN32)
	pSystemTime->uYearH = HIBYTE(2003);
	pSystemTime->uYearL = LOBYTE(2003);
	pSystemTime->uMonth = 0x03;
	pSystemTime->uDay   = 0x07;
	pSystemTime->uHour  = 15;
	pSystemTime->uMinute= 35;
	pSystemTime->uSecond= 0;
	return;
#endif
	DATETIME dtTime;
	rtcGetDateTime(&dtTime);

	DateTime2SystemTime(pSystemTime, &dtTime);
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		pSystemTime	[in] Pointer to a SYSTEMTIME structure that contains the 
//					current system date and time. 
// Remarks:
//		Sets the current system date and time.
void SetSystemTime(const SYSTEMTIME *pSystemTime)
{
	ASSERT(pSystemTime);
	
	DATETIME dtTime;
	SystemTime2DateTime(&dtTime, pSystemTime);
	rtcSetDateTime(&dtTime);
}

// Comment by Bozhong Xu in 2006-10-12
//#if !defined(WIN32) && defined(_DEBUG)

extern "C" void _ttywrch(int ch);
int fputc(int ch, FILE *f)
{
	UNUSED(f);
	_ttywrch(ch);
	return ch;
}

//#endif // !defined(WIN32) && defined(_DEBUG)


///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		uException	exception type
//		pc			The value of the pc register before the exception occured.
// Remarks:
//		Exception handler will call this function (init.s)
void ExceptionISR(BYTE uException, DWORD pc)
{
#ifdef __EFC_MASTER // Added by xbz
	GetApp()->AddEvent(uException, &pc, sizeof(pc));
#else
	UNUSED(uException);
	UNUSED(pc);
#endif
}


// Get Build number.		
WORD GetEfcBuildNum()
{
	return MakeBuildNum((char *)__DATE__, 2006, 0);
}

// Get EFC version
WORD GetEfcVersion()// V1.30
{ 
	return 0x0130;   
} 

// Get a version based on version and builder number
DWORD FormatVersion(WORD wVersion, WORD wBuildNum)
{
	DWORD dwVersion;

	*((BYTE *)&dwVersion + 0) = *((BYTE *)&wVersion + 0);
	*((BYTE *)&dwVersion + 1) = *((BYTE *)&wVersion + 1);
	*((BYTE *)&dwVersion + 2) = *((BYTE *)&wBuildNum + 0);
	*((BYTE *)&dwVersion + 3) = *((BYTE *)&wBuildNum + 1);
	
	return dwVersion;
}

// Make a builder number based on time.
WORD MakeBuildNum(char *Data, WORD wYear, BYTE uIndex)
{
	BYTE tmp_uMonth;
	switch(Data[0]) 
	{
	case 'J':
		switch(Data[1])
		{
			case 'a':
				tmp_uMonth = 1;
				break;
			case 'u':
				if(Data[2] == 'n')
				{
					tmp_uMonth = 6;
				}
				else
				{
					tmp_uMonth = 7;
				}
				break;
			default:
				ASSERT(FALSE);
				return 0;
		}
		break;
	case 'F':
		tmp_uMonth = 2;
		break;
	case 'M':
		if(Data[2] == 'y')
		{
			tmp_uMonth = 5;
		}
		else
		{
			tmp_uMonth = 3;
		}
		break;
	case 'A':
		if(Data[1] == 'p')
		{
			tmp_uMonth = 4;
		}
		else
		{
			tmp_uMonth = 8;
		}
		break;
	case 'S':
		tmp_uMonth = 9;
		break;
	case 'O':
		tmp_uMonth = 10;
		break;
	case 'N':
		tmp_uMonth = 11;
		break;
	case 'D':
		tmp_uMonth = 12;
		break;
	default:
		return 0;
		break;
	}
	
	BYTE tmp_uData = (Data[4] - '0') * 10 + (Data[5] - '0');

	WORD tmp_wYear = (Data[7] - '0') * 1000 + (Data[8] - '0') * 100 + 
		(Data[9] - '0') * 10 + (Data[10] - '0') * 1;

	if(tmp_wYear >= wYear)
	{
		tmp_wYear = tmp_wYear - wYear;
	}
	else
	{
		return 0;
	}
	
	if(tmp_wYear < 4 && uIndex < 4)
	{
		WORD wtmp = (tmp_wYear << 11) + ((WORD)tmp_uMonth << 7)
			+ ((WORD)tmp_uData << 2) + (WORD)uIndex;
		WORD wReturn;
		wReturn = ((wtmp / 1000) << 12);
		wtmp %= 1000;
		wReturn += ((wtmp / 100) << 8);
		wtmp %= 100;
		wReturn += ((wtmp / 10) << 4);
		wtmp %= 10;
		wReturn += ((wtmp / 1) << 0);
		return wReturn;
	}
	else
	{
		return 0;
	}
}

⌨️ 快捷键说明

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