亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? flash.cpp

?? 基于Nuleus操作系統和s3c4510的編寫的EFC。已經包含了該EFC的設計說明。這是個實際產品的代碼
?? CPP
字號:
///////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2003, Ulink Telecom Equipment Co., Ltd. All rights reserved.
//
// File:
//
//    Flash.cpp
//
// Abstract:
//
//    implementation of the CFlash class.
//
// History:
//
//    V1.0	2003-02-25	Alex Duan	Original version.
//    V1.1	2003-05-07	Alex Duan	Addressing mode, boundary condition...
//    V1.2	2003-06-03	Alex Duan	Add Lookup function
//    V1.3	2003-06-09	Alex Duan	Add semaphore
//
///////////////////////////////////////////////////////////////////////////////

#include "Flash.h"
#include "APPCORE.H"

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

CFlash::CFlash()
{
	m_pSemaphore = GetApp()->FindSemaphore("FlashSemaphore");
	if (m_pSemaphore == NULL)
	{
		m_pSemaphore = GetApp()->CreateSemaphore("FlashSemaphore");
	}
	ASSERT(m_pSemaphore);
}

CFlash::~CFlash()
{
}

///////////////////////////////////////////////////////////////////////////////
// Helper functions

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		nSector		Zero-based index of the sector
//		dwAddr		Start address of the sector
//		dwSize		Size of the sector, in bytes
// Return value:
//		Address of the next sector border upon.
// Remarks:
//		Sets the parameters of the sector. Call this in the initialization.
DWORD CFlash::SetSector(UINT nSector, DWORD dwAddr, DWORD dwSize)
{
	FLASH_SECTOR fsSector;
	fsSector.dwAddr = dwAddr;
	fsSector.dwSize = dwSize;
	m_mapSectors.SetAt(nSector, fsSector);
	return dwAddr + dwSize;
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		dwAddr		Address of the data to be compared (must be even address)
//		wData		Value to be compared
//		dwTimeout	Time-out value
// Return value:
//		TRUE if pass, else FALSE
// Remarks:
//		Check the data in the flash
BOOL CFlash::CheckWord(DWORD dwAddr, WORD wData, DWORD dwTimeout) const
{
	ASSERT((dwAddr & 0x01) == 0);
	for (; dwTimeout != 0 && VPword(dwAddr) != wData; dwTimeout--);
	
	return (VPword(dwAddr) == wData);
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		dwAddr		Address of the data to be compared
//		uData		Value to be compared
//		dwTimeout	Time-out value
// Return value:
//		TRUE if pass, else FALSE
// Remarks:
//		Check the data in the flash
BOOL CFlash::CheckByte(DWORD dwAddr, BYTE uData, DWORD dwTimeout) const
{
	for (; dwTimeout != 0 && VPbyte(dwAddr) != uData; dwTimeout--);
	
	return (VPbyte(dwAddr) == uData);
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		dwAddr	The address of the word in the flash (must be even address)
//		wData	The data to be written
// Return Value:
//		TRUE if successful, otherwise FALSE
// Remarks:
//		Write one word (16bits) data to the flash chip.
BOOL CFlash::WriteWord(DWORD dwAddr, WORD wData)
{
	ASSERT((dwAddr & 0x01) == 0); // can only be even address.
	ASSERT(m_dwBaseAddr <= dwAddr && dwAddr < m_dwBaseAddr + GetFlashSize());
	
	VWORD* pwBaseAddr = (VWORD*)m_dwBaseAddr;
	*(pwBaseAddr + 0x555) = 0xAA;
	*(pwBaseAddr + 0x2AA) = 0x55;
	*(pwBaseAddr + 0x555) = 0xA0;
	VPword(dwAddr) = wData;
	return CheckWord(dwAddr, wData);
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		dwAddr	The address of the word in the flash
//		uData	The data to be written
// Return Value:
//		TRUE if successful, otherwise FALSE
// Remarks:
//		Write one byte (8bits) data to the flash chip.
BOOL CFlash::WriteByte(DWORD dwAddr, BYTE uData)
{
	ASSERT(m_dwBaseAddr <= dwAddr && dwAddr < m_dwBaseAddr + GetFlashSize());
	
	VWORD* pwBaseAddr = (VWORD*) m_dwBaseAddr;
	*(pwBaseAddr + 0x555) = 0xAA;
	*(pwBaseAddr + 0x2AA) = 0x55;
	*(pwBaseAddr + 0x555) = 0xA0;
	
#ifdef __BIG_ENDIAN // (high byte ==> low address)
	if (dwAddr & 0x01)
	{// odd address
		VPword(dwAddr - 1) = MAKEWORD(uData, VPbyte(dwAddr - 1));
	}
	else
	{
		VPword(dwAddr) = MAKEWORD(VPbyte(dwAddr + 1), uData);
	}
#else // __LITTLE_ENDIAN (high byte ==> high address)
	if (dwAddr & 0x01)
	{// odd address
		VPword(dwAddr - 1) = MAKEWORD(VPbyte(dwAddr - 1), uData);
	}
	else
	{
		VPword(dwAddr) = MAKEWORD(uData, VPbyte(dwAddr + 1));
	}
#endif
	
	return CheckByte(dwAddr, uData);
}

///////////////////////////////////////////////////////////////////////////////
// public functions

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		eFlashType	Flash type (enum value)
//		dwBaseAddr	Base address of the flash ROM
// Remarks:
//		Set the flash type.
void CFlash::SetType(EFlashType eFlashType, DWORD dwBaseAddr)
{
	ASSERT((dwBaseAddr & 0x01) == 0); // must be even address
	m_eFlashType = eFlashType;
	m_dwBaseAddr = dwBaseAddr;
	m_mapSectors.RemoveAll();

	UINT i;	// loop counter
	switch (eFlashType)
	{
	case AM29LV160D:
		// 35 sectors total.
		dwBaseAddr = SetSector(0, dwBaseAddr, 0x4000); // 16Kbyte
		dwBaseAddr = SetSector(1, dwBaseAddr, 0x2000); // 8Kbyte
		dwBaseAddr = SetSector(2, dwBaseAddr, 0x2000); // 8Kbyte
		dwBaseAddr = SetSector(3, dwBaseAddr, 0x8000); // 32Kbyte
		for (i = 0; i < 31; i++)
		{// thirty-one 64Kbyte sectors
			dwBaseAddr = SetSector(i + 4, dwBaseAddr, 0x10000); // 64Kbyte
		}
		break;
	default:
		break;
	}
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		nSector		Zero-based index of the sector
//		nRetryCount	Count of retrying if failed.
// Return value:
//		TRUE if erasing successful, otherwise FALSE
// Remarks:
//		Erase the specified sector of the flash
BOOL CFlash::EraseSector(UINT nSector, UINT nRetryCount)
{
	BOOL bRetVal = FALSE;
	FLASH_SECTOR fsSector;
	
	VERIFY(NU_Obtain_Semaphore(m_pSemaphore, NU_SUSPEND) == NU_SUCCESS);

	if (m_mapSectors.Lookup(nSector, fsSector))
	{
		VWORD* pwBaseAddr = (VWORD*)m_dwBaseAddr;
		do
		{
			*(pwBaseAddr + 0x555) = 0xAA;
			*(pwBaseAddr + 0x2AA) = 0x55;
			*(pwBaseAddr + 0x555) = 0x80;
			*(pwBaseAddr + 0x555) = 0xAA;
			*(pwBaseAddr + 0x2AA) = 0x55;
			VPword(fsSector.dwAddr) = 0x30;
			Sleep(1); // sleep to wait erasure & other task can run
			// Check result of erasure
			bRetVal = CheckWord(fsSector.dwAddr, 0xFFFF);
		} while (!bRetVal && nRetryCount--);

		// Reset command
		VPword(m_dwBaseAddr) = 0xF0;
	}

	VERIFY(NU_Release_Semaphore(m_pSemaphore) == NU_SUCCESS);

	return bRetVal;
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		lpBuf		Pointer to the user-supplied buffer that is to receive the 
//					data read from the flash chip.
//		dwSrcAddr	Absolute physical address from which to read data
//		nCount		The number of bytes to be read from the flash chip.
// Remarks:
//		Read data into a buffer from specified address of the flash chip. Use
//		this instead of reading directly is thinking of the odd source address.
void CFlash::Read(void *lpBuf, DWORD dwSrcAddr, UINT nCount) const
{
	if (nCount == 0)
		return;

	// obtain an instance of the specified semaphore.
	VERIFY(NU_Obtain_Semaphore(m_pSemaphore, NU_SUSPEND) == NU_SUCCESS);

	DWORD dwDesAddr = (DWORD)lpBuf; // des. address
	if ((dwSrcAddr & 0x01) || (dwDesAddr & 0x01))
	{// odd address --> slow read (read one byte every time)
		while (nCount > 0) 
		{
			VPbyte(dwDesAddr) = VPbyte(dwSrcAddr);
			dwSrcAddr++;
			dwDesAddr++;
			nCount--;
		}
	}
	else
	{// even address --> faster read (can use memcpy instead here?)
		while (nCount > 1) 
		{
			VPword(dwDesAddr) = VPword(dwSrcAddr);
			dwSrcAddr += 2;
			dwDesAddr += 2;
			nCount -=2;
		}
		if (nCount == 1) 
		{
			VPbyte(dwDesAddr) = VPbyte(dwSrcAddr);
		}
	}
	
	// release an instance of the specified semaphore.
	VERIFY(NU_Release_Semaphore(m_pSemaphore) == NU_SUCCESS);
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		dwDesAddr	Absolute physical destination address in the flash.
//		lpBuf		Pointer to the buffer that contains the data to be programed.
//		nCount		The number of bytes to be transferred from the buffer.
// Return value:
//		TRUE if successful, else FALSE
// Remarks:
//		Write data from a buffer to the flash.	
BOOL CFlash::Write(DWORD dwDesAddr, const void* lpBuf, UINT nCount)
{
	if (nCount == 0)
		return TRUE;

	BOOL bRetVal = TRUE; // result
	DWORD dwSrcAddr = (DWORD)lpBuf;	// source address

	// obtain an instance of the specified semaphore
	VERIFY(NU_Obtain_Semaphore(m_pSemaphore, NU_SUSPEND) == NU_SUCCESS);

	if ((dwDesAddr & 0x01) || (dwSrcAddr & 0x01))
	{// it is started from odd address, so write one byte every time. (slow)
		while (nCount > 0 && bRetVal)
		{
			bRetVal = WriteByte(dwDesAddr, VPbyte(dwSrcAddr));
			dwSrcAddr++;
			dwDesAddr++;
			nCount--;
		}
	}
	else
	{// it is started from even address, so write two bytes every timer. (faster)
		while (nCount > 1 && bRetVal)
		{
			bRetVal = WriteWord(dwDesAddr, VPword(dwSrcAddr));
			dwSrcAddr += 2;
			dwDesAddr += 2;
			nCount -= 2;
		}
		if (nCount == 1 && bRetVal)
		{
			bRetVal = WriteByte(dwDesAddr, VPbyte(dwSrcAddr));
		}
	}
	VPword(m_dwBaseAddr) = 0xF0; // Reset command

	// release an instance of the specified semaphore.
	VERIFY(NU_Release_Semaphore(m_pSemaphore) == NU_SUCCESS);
	
	return bRetVal;
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		nSector	Zero-based index of the sector. [0-34]
// Return Value:
//		TRUE if the specified sector exists and is blank, else FALSE
// Remarks:
//		Check the sector if it is blank.
BOOL CFlash::IsBlankSector(UINT nSector) const
{
	BOOL bRetVal = FALSE;
	FLASH_SECTOR fsSector;

	if (m_mapSectors.Lookup(nSector, fsSector))
	{
		bRetVal = TRUE;
		for (DWORD i = 0; i < fsSector.dwSize; i += 2)
		{
			if ((WORD)VPword(fsSector.dwAddr + i) != 0xFFFF)
			{
				bRetVal = FALSE;
				break;
			}
		}
	}
	return bRetVal;
}

// Gets the size of the flash chip, in bytes
DWORD CFlash::GetFlashSize() const
{
	DWORD dwFlashSize = 0;
	UINT nSector;	// zero-based index of the sector
	FLASH_SECTOR fsSector;

	POSITION pos = m_mapSectors.GetStartPosition();
	while (pos != NULL)
	{
		m_mapSectors.GetNextAssoc(pos, nSector, fsSector);
		dwFlashSize += fsSector.dwSize;
	}
	return dwFlashSize;
}

///////////////////////////////////////////////////////////////////////////////
// Return Value:
//		TRUE if the flash is busy, otherwise FALSE.
// Remarks:
//		Is the flash busy?
BOOL CFlash::IsBusy() const
{
	ASSERT(m_pSemaphore);
	
	char szName[8]; // semaphore name
	DWORD nCount, nTask;
	OPTION oSuspend;
	NU_TASK *pTask = NULL;
	NU_Semaphore_Information(m_pSemaphore, szName, &nCount, &oSuspend, &nTask, 
		&pTask);
	return (nCount == 0);
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		nSector	Sector number
// Return Value:
//		Base address of the sector if sector exists, otherwise -1.
// Remarks:
//		Get the base address of the specified sector.
DWORD CFlash::GetSectorAddr(UINT nSector) const
{
	FLASH_SECTOR fsSector;
	if (m_mapSectors.Lookup(nSector, fsSector))
	{
		return fsSector.dwAddr;
	}
	else
	{
		return -1;
	}
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		nSector	Sector number
// Return Value:
//		Size of the sector if sector exists, otherwise -1.
// Remarks:
//		Get the size of the specified sector.
DWORD CFlash::GetSectorSize(UINT nSector) const
{
	FLASH_SECTOR fsSector;
	if (m_mapSectors.Lookup(nSector, fsSector))
	{
		return fsSector.dwSize;
	}
	else
	{
		return -1;
	}
}

///////////////////////////////////////////////////////////////////////////////
// Parameters:
//		nSector	Sector number
// Return Value:
//		Next address of this sector if this sector exists, otherwise -1.
// Remarks:
//		Get the next address relative to this sector
DWORD CFlash::GetSectorNext(UINT nSector) const
{
	FLASH_SECTOR fsSector;
	if (m_mapSectors.Lookup(nSector, fsSector))
	{
		return fsSector.dwAddr + fsSector.dwSize;
	}
	else
	{
		return -1;
	}
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
综合色天天鬼久久鬼色| 成人黄色免费短视频| 成人av在线播放网站| 欧美一二三区在线| 日韩毛片一二三区| 国产一区二区看久久| 欧美亚洲禁片免费| 中文字幕一区二区日韩精品绯色| 蜜臀久久99精品久久久久久9| 色一情一伦一子一伦一区| 久久五月婷婷丁香社区| 蜜桃久久久久久久| 欧美日韩视频在线观看一区二区三区 | 亚洲一二三区在线观看| 成人精品免费视频| 国产片一区二区| 国产一区不卡视频| 欧美电影免费观看完整版| 午夜久久久久久电影| 91久久国产最好的精华液| 国产精品蜜臀在线观看| 国产乱人伦偷精品视频不卡 | 午夜视频一区二区| 色婷婷综合久久久久中文| 中文字幕一区二区三| 成人福利视频在线| 国产精品色哟哟| www.日韩精品| 中文字幕日本不卡| 成人在线一区二区三区| 欧美国产日本韩| 成人v精品蜜桃久久一区| 亚洲国产精品激情在线观看| 国产成人av电影在线播放| 久久久不卡网国产精品二区| 国产成人综合视频| 国产精品国产三级国产有无不卡| 国产成人亚洲精品青草天美| 亚洲国产激情av| aaa国产一区| 亚洲伦在线观看| 欧美日韩国产在线播放网站| 亚洲国产视频一区| 欧美精品第1页| 久草这里只有精品视频| 国产午夜精品一区二区三区视频 | 亚洲欧美国产高清| 91精品福利视频| 五月天国产精品| 亚洲精品一区在线观看| 国产精品88888| 亚洲色图欧美偷拍| 欧美日韩综合一区| 精品一区二区在线视频| 国产三级欧美三级日产三级99 | 国产精品成人免费精品自在线观看 | 欧美日韩成人一区二区| 老司机精品视频一区二区三区| 久久综合色之久久综合| 91丝袜呻吟高潮美腿白嫩在线观看| 亚洲精品免费一二三区| 在线播放91灌醉迷j高跟美女 | 久久综合狠狠综合久久激情 | 国产真实乱对白精彩久久| 亚洲国产精品av| 6080午夜不卡| 成年人网站91| 免费观看久久久4p| 国产日产精品1区| 欧美精品v国产精品v日韩精品 | 欧洲精品在线观看| 国产麻豆9l精品三级站| 亚洲无人区一区| 久久久综合网站| 欧美高清www午色夜在线视频| 国产精品一区三区| 午夜激情综合网| 国产精品久久久久天堂| 欧美va亚洲va国产综合| 91麻豆精品一区二区三区| 久久99精品久久久久婷婷| 亚洲蜜臀av乱码久久精品| 精品奇米国产一区二区三区| 在线亚洲免费视频| 懂色av中文字幕一区二区三区| 性感美女久久精品| 中文字幕在线播放不卡一区| 精品盗摄一区二区三区| 欧美三级电影一区| 色综合久久久久久久久久久| 国产一区二区免费在线| 青青草原综合久久大伊人精品优势 | 久久精品在线免费观看| 555夜色666亚洲国产免| 欧美午夜免费电影| 91免费国产在线| 国产成人亚洲综合a∨婷婷| 免费成人你懂的| 午夜精品一区在线观看| 樱花影视一区二区| 中文字幕一区视频| 国产精品乱码久久久久久| 精品av综合导航| 欧美mv日韩mv| 欧美成人在线直播| 日韩欧美中文字幕精品| 日韩一区国产二区欧美三区| 8x8x8国产精品| 欧美一区二区三区色| 欧美日韩激情在线| 欧美日韩一区二区三区在线| 91黄色在线观看| 欧美亚洲另类激情小说| 欧美在线一区二区| 欧美视频日韩视频| 欧美精三区欧美精三区| 欧美日韩一卡二卡三卡| 欧美日本视频在线| 欧美精品高清视频| 日韩免费成人网| 精品国产91乱码一区二区三区 | 国产风韵犹存在线视精品| 国产一区二区三区日韩| 国产乱码精品一区二区三区忘忧草| 麻豆精品久久精品色综合| 日本女优在线视频一区二区| 日本亚洲最大的色成网站www| 奇米一区二区三区| 极品少妇xxxx偷拍精品少妇| 国产精品一区二区久激情瑜伽| 国产九九视频一区二区三区| 成人午夜视频网站| 91猫先生在线| 91麻豆精品91久久久久同性| 日韩精品一区二区三区视频播放 | 欧美高清精品3d| 2023国产精品| 亚洲欧洲av一区二区三区久久| 亚洲欧美国产77777| 日韩精品亚洲专区| 国产麻豆成人精品| 91官网在线观看| 日韩视频在线永久播放| 国产三区在线成人av| 一二三四社区欧美黄| 美腿丝袜亚洲色图| 99热国产精品| 91麻豆精品91久久久久久清纯| 久久精品无码一区二区三区| 亚洲综合免费观看高清完整版| 日本欧美一区二区在线观看| 成人一二三区视频| 777久久久精品| 中文无字幕一区二区三区| 亚洲精品国产a| 国产一区二区三区黄视频 | 欧美极品另类videosde| 亚洲一区二区三区爽爽爽爽爽| 美女一区二区久久| 色哟哟在线观看一区二区三区| 日韩一区二区中文字幕| 国产精品第一页第二页第三页| 肉丝袜脚交视频一区二区| 国产91精品一区二区麻豆亚洲| 色噜噜夜夜夜综合网| 精品国产乱码久久久久久影片| 综合欧美亚洲日本| 国产一区二区调教| 欧美一区二区三区白人| 亚洲最新视频在线播放| 国产成人精品1024| 日韩免费视频一区二区| 一区二区三区成人在线视频| 国产伦精品一区二区三区视频青涩 | 日韩成人一级片| 91亚洲国产成人精品一区二区三| 精品捆绑美女sm三区| 亚洲一区二区在线观看视频 | 国产一区二区电影| 日韩欧美你懂的| 亚洲国产你懂的| 色国产综合视频| 国产精品久久久99| 国产盗摄精品一区二区三区在线 | 国产精品伦理一区二区| 国精品**一区二区三区在线蜜桃| 欧美欧美欧美欧美首页| 一区二区三区蜜桃| 91视频免费观看| 久久精品一区二区三区av| 卡一卡二国产精品 | 国产人成一区二区三区影院| 久久国产精品99久久久久久老狼| 91精品国产综合久久久久久| 亚洲综合色成人| 欧美日韩另类国产亚洲欧美一级| 亚洲永久免费视频| 91黄色激情网站| 亚洲bt欧美bt精品| 欧美日韩高清一区二区|