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

📄 eventlog.cpp

📁 基于Nuleus操作系统和s3c4510的编写的EFC。已经包含了该EFC的设计说明。这是个实际产品的代码
💻 CPP
字号:
///////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2003, Ulink Telecom Equipment Co., Ltd. All rights reserved.
//
// File:
//
//    EventLog.cpp
//
// Abstract:
//
//    implementation of the CEventLog class.
//
// History:
//
//    V1.0	2003-05-07	Alex Duan	Original version.
//	  V1.1  2007-06-27  Bozhong Xu  Add saving action in Add() function.
///////////////////////////////////////////////////////////////////////////////

#ifdef __EFC_MASTER // Added by xbz
#include "EventLog.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CEventLog::CEventLog()
{
	ASSERT((RECORD_SIZE & 0x01) == 0);
	ROMCON rcRom;
	rcRom.dwReg = ROMCON0;
	DWORD dwAddr = rcRom.bits.base;
	dwAddr <<= 16;
	m_cFlash.SetType(AM29LV160D, dwAddr);

	VERIFY(m_cFlash.Lookup(SECTOR_EVENT_MIN, m_fsSector[0]));
	VERIFY(m_cFlash.Lookup(SECTOR_EVENT_MAX, m_fsSector[1]));

	m_nPosition = 0;
	dwAddr = m_fsSector[0].dwSize + m_fsSector[1].dwSize; // max offset address
	while (VPbyte(m_fsSector[0].dwAddr + m_nPosition) != 0xFF &&
		m_nPosition < dwAddr)
	{
		m_nPosition += RECORD_SIZE;
	}

	m_nKey = 0;
}

CEventLog::~CEventLog()
{
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		event	The EVENT structure that contains the data of event to be added.
// Remarks:
//		Add an event.
void CEventLog::Add(const EVENT& event)
{
	m_mapEvents.SetAt(m_nKey++, event);
	
	// Save the lastest event to flash (Added by Bozhong xu in 2007-06-27)
	Save();
}

// Clear the event table
// NOTE: this function can only be call in task routine only
void CEventLog::Clear()
{
	VERIFY(m_cFlash.EraseSector(SECTOR_EVENT_MIN));
	VERIFY(m_cFlash.EraseSector(SECTOR_EVENT_MAX));
	m_nPosition = 0;
	m_nKey = 0;
	m_mapEvents.RemoveAll();
}

// Get current count of events
UINT CEventLog::GetCount() const
{
	UINT nCount = m_nPosition / RECORD_SIZE;
	if (m_nPosition < m_fsSector[0].dwSize &&  // sector_event_min
		VPbyte(m_fsSector[1].dwAddr + m_fsSector[1].dwSize - RECORD_SIZE) != 0xFF)
	{
		nCount += m_fsSector[1].dwSize / RECORD_SIZE;
	}
	return nCount;
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		uType	Type of the event
//		pBuf	Pointer of parameter buffer
//		nCount	Buffer size, in bytes
// Remarks:
//		Add an event
void CEventLog::Add(BYTE uType, const void* pBuf, UINT nCount)
{
	EVENT event;
	event.uType = uType;
	memcpy(event.uParam, pBuf, nCount);
	GetSystemTime(&event.stTime);
	/////////////////////////////////////////////////////////////////////////////
	// Temporary code, need modifying the message format to delete following code.
	BYTE* pstTime = (BYTE*) &event.stTime;
	BYTE uTmp;
	for (int i = 0; i < 3; i++)
	{
		uTmp = pstTime[i];
		pstTime[i] = pstTime[6 - i];
		pstTime[6 - i] = uTmp;
	}
	uTmp = pstTime[6];
	pstTime[6] = pstTime[5];
	pstTime[5] = uTmp;
	/////////////////////////////////////////////////////////////////////////////
	Add(event);
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		nIndex	Zero-based index of the event(0: means newest, 1: newer...)
// Return Value:
//		Pointer of the specified event. if event does not exist, return NULL
// Remarks:
//		Retrieve an event
const EVENT* CEventLog::GetEvent(UINT nIndex)
{
	if (nIndex >= GetCount())
		return NULL;
	DWORD dwAddr = (nIndex + 1) * RECORD_SIZE;
	if (dwAddr <= m_nPosition)
	{
		dwAddr = m_nPosition - dwAddr;
	}
	else
	{
		dwAddr = m_nPosition - dwAddr +	m_fsSector[0].dwSize + m_fsSector[1].dwSize;
	}
	dwAddr += m_fsSector[0].dwAddr;
	return (const EVENT *)dwAddr;
}

// save events which is stored in memory temporarily to flash
//   NOTE: this function can only be call in task routine only
void CEventLog::Save()
{
	if (m_mapEvents.IsEmpty())
		return;

	EVENT event;
	for (int i = 0; i < m_mapEvents.GetCount(); i++)
	{
		if (!m_mapEvents.Lookup(i, event))
			continue;

		if (m_nPosition >= m_fsSector[0].dwSize + m_fsSector[1].dwSize)
			m_nPosition = 0;
		
		// Erase sector if it is not blank before using.		
		if (m_nPosition == 0)
		{
			// sector min
			if (!m_cFlash.IsBlankSector(SECTOR_EVENT_MIN))
			{
				VERIFY(m_cFlash.EraseSector(SECTOR_EVENT_MIN));
			}
		}
		else if (m_nPosition == m_fsSector[0].dwSize)
		{
			// sector max
			if (!m_cFlash.IsBlankSector(SECTOR_EVENT_MAX))
			{
				VERIFY(m_cFlash.EraseSector(SECTOR_EVENT_MAX));
			}
		}
		
		VERIFY(m_cFlash.Write(m_fsSector[0].dwAddr + m_nPosition, &event, 
			sizeof(EVENT)));
		m_nPosition += RECORD_SIZE;
	}
	m_mapEvents.RemoveAll();
	m_nKey = 0;
}

#endif

⌨️ 快捷键说明

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