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

📄 board.cpp

📁 基于Nuleus操作系统和s3c4510的编写的EFC。已经包含了该EFC的设计说明。这是个实际产品的代码
💻 CPP
字号:
///////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2003, Ulink Telecom Equipment Co., Ltd. All rights reserved.
//
// File:
//
//    Board.cpp
//
// Abstract:
//
//    implementation of the CBoard class. CBoard class is an enwrapping of the 
//	  hardware board.
//
// History:
//
//    V1.0	2003-03-18	Alex Duan	Original version.
//    V1.1	2003-11-06	Alex Duan	Replace EBoardType enum with macros
//    V1.2	2003-11-12	Alex Duan	Replace >>/<< with OnSaveData/OnLoadData
//
///////////////////////////////////////////////////////////////////////////////

#include "Board.h"
#include "APPCORE.H"
#include "LiuInterface.h"
#include "AsyInterface.h"
#include "SynInterface.h"
#include "LanInterface.h"
#include "OptInterface.h"

///////////////////////////////////////////////////////////////////////////////
// CBoard

IMPLEMENT_DYNAMIC(CBoard, CRTObject)

CBoard::CBoard()
{
	m_nSynMode = 0;
	m_wIndex = 0;
	m_wType = BOARD_TYPE_MCU;
	SetSectionString("Boards(0)"); // default section string
}

CBoard::~CBoard()
{
	// free memory
	DWORD key;
	CInterface* pciInterface = NULL;
	POSITION pos = m_mapInterfaces.GetStartPosition();
	while (pos != NULL)
	{
		m_mapInterfaces.GetNextAssoc(pos, key, pciInterface);
		if (pciInterface != NULL)
		{
			delete pciInterface;
			pciInterface = NULL;
		}
	}
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		wInterfaceType	Interface type defined in the file interface.h
//		wInterfaceIndex	Zero-based index of the specified interface in the board
// Return Value:
//		Zero if installed succesfully, otherwise nonzero.
//		error code: -1	Interface exists, -2 failed to install interface
// Remarks:
//		Install an interface to the board.
int CBoard::Install(WORD wInterfaceType, WORD wInterfaceIndex)
{
	int nRetVal = -1;
	CInterface* pci = NULL;
	CString strSection;
	DWORD key = MAKELONG(wInterfaceIndex, wInterfaceType);

	if (!m_mapInterfaces.Lookup(key, pci))
	{// Install new interface
		pci = OnCreateInterface(wInterfaceType); // create interface
		if (pci != NULL)
		{// create successfully.
			pci->SetIndex(wInterfaceIndex); // set index
			strSection.Format("Interfaces(%d,%d)",
				GetIndex(), m_mapInterfaces.GetCount());
			pci->SetSectionString(strSection);
			pci->OnLoadData();
			VERIFY(pci->OnInitInterface()); // initialize interface
			m_mapInterfaces.SetAt(key, pci);
			nRetVal = 0;
		}
		else
		{// failed to create
			nRetVal = -2;
		}
	}
	return nRetVal;
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		wInterfaceType	Interface type
//		wInterfaceIndex	Zero-based index of the specified interface in the board
// Remarks:
//		Uninstall an interface from the board.
void CBoard::Uninstall(WORD wInterfaceType, WORD wInterfaceIndex)
{
	DWORD key = MAKELONG(wInterfaceIndex, wInterfaceType);
	CInterface* pciInterface = NULL;
	m_mapInterfaces.Lookup(key, pciInterface);
	if (pciInterface)
		delete pciInterface; // free memory
	m_mapInterfaces.RemoveKey(key);
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		wInterfaceType	Interface type
//		wInterfaceIndex	Zero-based index of the specified interface in the board
// Return Value:
//		A pointer to the CInterface object if interface exists, else NULL.
// Remarks:
//		Get interface information by type and index
CInterface* CBoard::GetInterface(WORD wInterfaceType, WORD wInterfaceIndex) const
{
	CInterface* pciRetVal = NULL;
	DWORD key = MAKELONG(wInterfaceIndex, wInterfaceType);
	if (!m_mapInterfaces.Lookup(key, pciRetVal))
		pciRetVal = NULL;
	return pciRetVal;
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		viInfo	[in][out]Contains the version information
// Return Value:
//		TRUE if such version type exists, else FALSE
// Remarks:
//		Get the version of the specified type.
BOOL CBoard::GetVersionInfo(VERSIONINFO& viInfo) const
{
	return m_mapVersions.Lookup(viInfo.eType, viInfo);
}

///////////////////////////////////////////////////////////////////////////////
// Return Value:
//		The value of every two bits shows the status of one interface
//		BITn-BITn-1 : 00 - ok, 01 - not in use, 11 - self test error
// Remarks:
//		Get configuration of the user interface
// NOTE: temporary code, must be modified
WORD CBoard::GetConfig() const
{
	WORD wRetVal = 0xFFFF;
	DWORD key;
	CInterface* pciInterface = NULL;

	POSITION pos = m_mapInterfaces.GetStartPosition();
	while (pos != NULL)
	{
		m_mapInterfaces.GetNextAssoc(pos, key, pciInterface);
		ASSERT(pciInterface);
		if (pciInterface->GetType() == INTERFACE_TYPE_LIU)
		{
			SetBitVal(wRetVal, pciInterface->GetIndex() * 2, 0);
			SetBitVal(wRetVal, pciInterface->GetIndex() * 2 + 1, 0);
		}
		else
		{
			SetBitVal(wRetVal, pciInterface->GetIndex() * 2 + 8, 0);
			SetBitVal(wRetVal, pciInterface->GetIndex() * 2 + 9, 0);
		}
	}
	return wRetVal;
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		wInterfaceType	Type of the interface
// Return Value:
//		Interface count
// Remarks:
//		Gets the count of the specified interface type.
UINT CBoard::GetInterfaceCount(WORD wInterfaceType) const
{
	UINT nRetVal = 0;
	DWORD key;
	CInterface* pciInterface = NULL;

	POSITION pos = m_mapInterfaces.GetStartPosition();
	while (pos != NULL)
	{
		m_mapInterfaces.GetNextAssoc(pos, key, pciInterface);
		ASSERT(pciInterface);
		ASSERT(HIWORD(key) == pciInterface->GetType());
		if (HIWORD(key) == wInterfaceType)
			nRetVal++;
	}
	return nRetVal;
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		nMode	Synchronization mode (clock mode)
//				For LIU (0:Internal mode, 0x00FF:External mode, other:line rec)
//				For SD2010 (Low byte: mode, high byte: other parameter)
// Remarks:
//		Set system synchronization mode (clock mode)
void CBoard::SetSynMode(WORD nMode)
{
	m_nSynMode = nMode;
//	GetApp()->SetModifiedFlag();
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		bReadFromHardware	TRUE: read clock mode from hardware, else read the
//							variable setted last time.
// Return Value:
//		The system or board's sync mode(clock mode)
// Remarks:
//		Get synchronization mode from hardware
WORD CBoard::GetSynMode(BOOL bReadFromHardware) const
{
	UNUSED(bReadFromHardware);
	return m_nSynMode;
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		WType	Type of the board
// Remarks:
//		Set the type of the board.
void CBoard::SetType(WORD wType)
{
	m_wType = wType;
//	GetApp()->SetModifiedFlag();
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		wIndex	Zero-based index of the board in the device.
// Remarks:
//		Set index of the board.
void CBoard::SetIndex(WORD wIndex)
{ 
	m_wIndex = wIndex;
//	GetApp()->SetModifiedFlag();
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		dwBaseAddr	32-bits absolute base address of the board.
// Remarks:
//		Set base address of the board
void CBoard::SetBaseAddr(DWORD dwBaseAddr)
{
	m_dwBaseAddr = dwBaseAddr;
//	GetApp()->SetModifiedFlag();
}

// Framework call this to initialize the board.
BOOL CBoard::OnInitBoard()
{
	return TRUE;
}

// create a new interface
CInterface* CBoard::OnCreateInterface(WORD wInterfaceType)
{
	CInterface *pci = NULL;
	switch (wInterfaceType)
	{
	case INTERFACE_TYPE_LIU:
		pci = new CLiuInterface();
		break;
	case INTERFACE_TYPE_SYN:
		pci = new CSynInterface();
		break;
	case INTERFACE_TYPE_ASY:
		pci = new CAsyInterface();
		break;
	case INTERFACE_TYPE_OPT:
		pci = new COptInterface();
		break;
	case INTERFACE_TYPE_LAN:
		pci = new CLanInterface();
		break;
	default:
		break;
	}
	return pci;
}

// load parameters
void CBoard::OnLoadData()
{
	LOAD_INT(m_wType);
	LOAD_INT(m_wIndex);
	LOAD_INT(m_dwBaseAddr);
	LOAD_INT(m_nSynMode);
	LOAD_STRING(m_strSerialNumber);

	// load interfaces
	WORD wType, wIndex;
	CString strSection;
	for (int i = 0; ;i++) 
	{
		strSection.Format("Interfaces(%d,%d)", GetIndex(), i);
		wType  = GetApp()->GetProfileInt(strSection, "Type", -1);
		wIndex = GetApp()->GetProfileInt(strSection, "m_wIndex", -1);
		if (wType == (WORD)-1 || wIndex == (WORD)-1)
			break;
		VERIFY(Install(wType, wIndex) != -2);
	}
}

// save parameters
void CBoard::OnSaveData()
{
	SAVE_INT(m_wType);
	SAVE_INT(m_wIndex);
	SAVE_INT(m_dwBaseAddr);
	SAVE_INT(m_nSynMode);
	SAVE_STRING(m_strSerialNumber);

	// Save Interfaces
	DWORD key;
	CInterface *pciInterface = NULL;
	POSITION pos = m_mapInterfaces.GetStartPosition();
	while (pos != NULL) 
	{
		m_mapInterfaces.GetNextAssoc(pos, key, pciInterface);
		ASSERT(pciInterface);
		pciInterface->OnSaveData();
	}
}

⌨️ 快捷键说明

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