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

📄 ms.c

📁 常见卡(SD,NAND,XD,MS,ATA,CF)完整DRIVER
💻 C
📖 第 1 页 / 共 5 页
字号:
		return swRetValue;
	}

	if ((bIntValue & CMDNK) || ((bIntValue & BREQ) && (bIntValue & ERR)))
	{
		//Set Parameter Register
		MP_DEBUG1("-E- Error termination (bIntValue: %d)", bIntValue);
		SetProParaReg(bProFlashCMD[PRO_STOP], 0, 0, 0x00, 0x00);
		if ((swRetValue = WriteTpcBs(TPC_EX_SET_CMD, (BYTE *) (&sProParamReg), 7)))
		{
			MP_DEBUG1("-E- TPC_EX_SET_CMD FAIL (swRetValue: %d)", swRetValue);
			return swRetValue;
		}
		return FAIL;
	}
	else if (((bIntValue & CED) && (bIntValue & ERR) && (bIntValue & CMDNK)))
	{
		MP_DEBUG1("-E- Write disabled status (bIntValue: %d)", bIntValue);
		return FAIL;
	}

	for (i = 0; i < dwSectorCount; i++)
	{
		SetDataDma(dwBufferAddress);
		if ((swRetValue = WriteTpcBsPage()))
		{
			MP_DEBUG1("-E- ReadTpcBsPage FAIL (swRetValue: %d)", swRetValue);
			return swRetValue;
		}
		if ((swRetValue = WaitINT()))
		{
			MP_DEBUG1("-E- GetINT FAIL (swRetValue: %d)", swRetValue);
			return swRetValue;
		}
		if ((swRetValue = GetIntValue(&bIntValue)))
		{
			MP_DEBUG1("-E- GetINT FAIL (swRetValue: %d)", swRetValue);
			return swRetValue;
		}

		if ((bIntValue & CMDNK) || ((bIntValue & BREQ) && (bIntValue & ERR)))
		{
			//Set Parameter Register
			MP_DEBUG1("-E- Error termination (bIntValue: %d)", bIntValue);
			SetProParaReg(bProFlashCMD[PRO_STOP], 0, 0, 0x00, 0x00);
			if ((swRetValue = WriteTpcBs(TPC_EX_SET_CMD, (BYTE *) (&sProParamReg), 7)))
			{
				MP_DEBUG1("-E- TPC_EX_SET_CMD FAIL (swRetValue: %d)", swRetValue);
				return swRetValue;
			}
			return FAIL;
		}
		else if (((bIntValue & CED) && (bIntValue & ERR) && (bIntValue & CMDNK)))
		{
			MP_DEBUG1("-E- pro CED && ERR && CMDNK fail! (bIntValue: %d)", bIntValue);
			return FAIL;
		}
		dwBufferAddress += MCARD_SECTOR_SIZE;
	}
	return PASS;
}

static SWORD ProLogicalRead(DWORD dwLogAddr, DWORD dwSectorCount, DWORD dwBufferAddress)
{
	register MCARD *sMcard;
	register DWORD i;
	register SWORD swRetValue;
	BYTE bIntValue;

	sMcard = (MCARD *) (MCARD_BASE);
	sMcard->McMsT1 = PRO_TIMEOUT1;

	//Set Parameter Register
	SetProParaReg(bProFlashCMD[PRO_READ_DATA], dwSectorCount, dwLogAddr, 0x00, 0x00);

	if ((swRetValue = WriteTpcBs(TPC_EX_SET_CMD, (BYTE *) (&sProParamReg), 7)))
	{
		MP_DEBUG1("-E- TPC_EX_SET_CMD FAIL (swRetValue: %d)", swRetValue);
		return swRetValue;
	}
	if ((swRetValue = WaitTime1INT()))
	{
		MP_DEBUG1("-E- WaitTime1INT FAIL (swRetValue: %d)", swRetValue);
		return swRetValue;
	}

	if ((swRetValue = GetIntValue(&bIntValue)))
	{
		MP_DEBUG1("-E- GetINT FAIL (swRetValue: %d)", swRetValue);
		return swRetValue;
	}

	if ((bIntValue & CMDNK) || ((bIntValue & BREQ) && (bIntValue & ERR)))
	{
		MP_DEBUG1("-E- Error termination (bIntValue: %d)", bIntValue);
		//Set Parameter Register
		SetProParaReg(bProFlashCMD[PRO_STOP], 0, 0, 0x00, 0x00);
		if ((swRetValue = WriteTpcBs(TPC_EX_SET_CMD, (BYTE *) (&sProParamReg), 7)))
		{
			MP_DEBUG1("-E- TPC_EX_SET_CMD FAIL (swRetValue: %d)", swRetValue);
			return swRetValue;
		}
		return FAIL;
	}

	for (i = 0; i < dwSectorCount; i++)
	{
		SetDataDma(dwBufferAddress);
		if ((swRetValue = ReadTpcBsPage()))
		{
			MP_DEBUG1("-E- ReadTpcBsPage FAIL (swRetValue: %d)", swRetValue);
			return swRetValue;
		}
		if ((swRetValue = WaitINT()))
		{
			MP_DEBUG1("-E- GetINT FAIL (swRetValue: %d)", swRetValue);
			return swRetValue;
		}
		if ((swRetValue = GetIntValue(&bIntValue)))
		{
			MP_DEBUG1("-E- GetINT FAIL (swRetValue: %d)", swRetValue);
			return swRetValue;
		}

		if ((bIntValue & CMDNK) || ((bIntValue & BREQ) && (bIntValue & ERR)))
		{
			//Set Parameter Register
			SetProParaReg(bProFlashCMD[PRO_STOP], 0, 0, 0x00, 0x00);
			if ((swRetValue = WriteTpcBs(TPC_EX_SET_CMD, (BYTE *) (&sProParamReg), 7)))
			{
				MP_DEBUG1("-E- TPC_EX_SET_CMD FAIL (swRetValue: %d)", swRetValue);
				return swRetValue;
			}
			return FAIL;
		}
		dwBufferAddress += MCARD_SECTOR_SIZE;
	}
	return PASS;
}

static SWORD ProReadAttribute(DWORD dwBufferAddress)
{
	register MCARD *sMcard;
	SWORD swRetValue;
	BYTE bIntValue;

	sMcard = (MCARD *) (MCARD_BASE);
	sMcard->McMsT1 = PRO_TIMEOUT1;

	//Set Parameter Register 
	SetProParaReg(bProFlashCMD[PRO_READ_ATRB], 0x01, 0x00, 0x00, 0x00);

	if ((swRetValue = WriteTpcBs(TPC_EX_SET_CMD, (BYTE *) (&sProParamReg), 7)))
	{
		MP_DEBUG1("-E- TPC_EX_SET_CMD FAIL (swRetValue: %d)", swRetValue);
		return swRetValue;
	}

	if ((swRetValue = WaitTime1INT()))
	{
		MP_DEBUG1("-E- WaitTime1INT FAIL (swRetValue: %d)", swRetValue);
		return swRetValue;
	}

	if ((swRetValue = GetIntValue(&bIntValue)))
	{
		MP_DEBUG1("-E- GetINT FAIL (swRetValue: %d)", swRetValue);
		return swRetValue;
	}

	if ((bIntValue & CMDNK) || ((bIntValue & BREQ) && (bIntValue & ERR)))
	{
		//Set Parameter Register
		MP_DEBUG1("-E- Error termination (bIntValue: %d)", bIntValue);
		SetProParaReg(bProFlashCMD[PRO_STOP], 0, 0, 0x00, 0x00);
		if ((swRetValue = WriteTpcBs(TPC_EX_SET_CMD, (BYTE *) (&sProParamReg), 7)))
		{
			MP_DEBUG1("-E- TPC_EX_SET_CMD FAIL (swRetValue: %d)", swRetValue);
			return swRetValue;
		}
		return FAIL;
	}

	SetDataDma(dwBufferAddress);

	if ((swRetValue = ReadTpcBsPage()))
	{
		MP_DEBUG1("-E- ReadTpcBsPage FAIL (swRetValue: %d)", swRetValue);
		return swRetValue;
	}

	if ((swRetValue = WaitTime1INT()))
	{
		MP_DEBUG1("-E- WaitTime1INT FAIL (swRetValue: %d)", swRetValue);
		return swRetValue;
	}

	if ((swRetValue = GetIntValue(&bIntValue)))
	{
		MP_DEBUG1("-E- GetINT FAIL (swRetValue: %d)", swRetValue);
		return swRetValue;
	}
	return PASS;
}

#else

static SWORD ProLogicalWrite(DWORD dwLogAddr, DWORD dwSectorCount, DWORD dwBufferAddress)
{
	register MCARD *sMcard;
	DWORD i;
	SWORD swRetValue;
	BYTE bIntValue;
	DWORD dwMcMsStatusTemp;

	sMcard = (MCARD *) (MCARD_BASE);
	sMcard->McMsT1 = PRO_TIMEOUT1;
	//Set Parameter Register
	SetProParaReg(bProFlashCMD[PRO_WRITE_DATA], dwSectorCount, dwLogAddr, 0x00, 0x00);
	if ((swRetValue = WriteTpcBs(TPC_EX_SET_CMD, (BYTE *) (&sProParamReg), 7)))
	{
		MP_DEBUG1("-E- TPC_EX_SET_CMD FAIL (swRetValue: %d)", swRetValue);
		return swRetValue;
	}

	if ((swRetValue = Wait_For_INT_Pulse(&dwMcMsStatusTemp)))
	{	
		MP_DEBUG1("-E- Wait_For_INT_Pulse FAIL (swRetValue: %d)", swRetValue);
		return swRetValue;
	}
	if ((swRetValue = Wait_INT_Signal_BREQ(&dwMcMsStatusTemp)))
	{
		MP_DEBUG1("-E- Wait_INT_Signal_BREQ FAIL (swRetValue: %d)", swRetValue);
		return swRetValue;
	}	
	if(dwMcMsStatusTemp & (STATUS_ERR || STATUS_CMDNK))
	{
		if ((swRetValue = GetIntValue(&bIntValue)))
		{
			MP_DEBUG1("-E- GetINT FAIL (swRetValue: %d)", swRetValue);
			return swRetValue;
		}

		if ((bIntValue & CMDNK) || ((bIntValue & BREQ) && (bIntValue & ERR)))
		{
			//Set Parameter Register
			MP_DEBUG1("-E- Error termination (bIntValue: %d)", bIntValue);
			SetProParaReg(bProFlashCMD[PRO_STOP], 0, 0, 0x00, 0x00);
			if ((swRetValue = WriteTpcBs(TPC_EX_SET_CMD, (BYTE *) (&sProParamReg), 7)))
			{
				MP_DEBUG1("-E- TPC_EX_SET_CMD FAIL (swRetValue: %d)", swRetValue);
				return swRetValue;
			}
			return FAIL;
		}
		else if (((bIntValue & CED) && (bIntValue & ERR) && (bIntValue & CMDNK)))
		{
			MP_DEBUG1("-E- Write disabled status (bIntValue: %d)", bIntValue);
			return FAIL;
		}
	}
	for (i = 0; i < dwSectorCount; i++)
	{
		SetDataDma(dwBufferAddress);
		if ((swRetValue = WriteTpcBsPage()))
		{
			MP_DEBUG1("-E- WriteTpcBsPage FAIL (swRetValue: %d)", swRetValue);
			return swRetValue;
		}
		if ((swRetValue = Wait_INT_Signal(&dwMcMsStatusTemp)))
		{
			MP_DEBUG1("-E- Wait_INT_Signal FAIL (swRetValue: %d)", swRetValue);
			return swRetValue;
		}
		if(i !=(dwSectorCount-1))
		{
			if ((swRetValue = Wait_INT_Signal_BREQ(&dwMcMsStatusTemp)))
			{
					MP_DEBUG1("-E- Wait_INT_Signal_BREQ FAIL (swRetValue: %d)", swRetValue);
					return swRetValue;
			}
		}
		else
		{
			if ((swRetValue = Wait_INT_Signal_CED(&dwMcMsStatusTemp)))
			{
					MP_DEBUG1("-E- Wait_INT_Signal_CED FAIL (swRetValue: %d)", swRetValue);
					return swRetValue;
			}
		}
if(dwMcMsStatusTemp & (STATUS_ERR || STATUS_CMDNK))
{
		if ((swRetValue = GetIntValue(&bIntValue)))
		{
			MP_DEBUG1("-E- GetINT FAIL (swRetValue: %d)", swRetValue);
			return swRetValue;
		}
		if ((bIntValue & CMDNK) || ((bIntValue & BREQ) && (bIntValue & ERR)))
		{
			//Set Parameter Register
			MP_DEBUG1("-E- Error termination (bIntValue: %d)", bIntValue);
			SetProParaReg(bProFlashCMD[PRO_STOP], 0, 0, 0x00, 0x00);
			if ((swRetValue = WriteTpcBs(TPC_EX_SET_CMD, (BYTE *) (&sProParamReg), 7)))
			{
				MP_DEBUG1("-E- TPC_EX_SET_CMD FAIL (swRetValue: %d)", swRetValue);
				return swRetValue;
			}
			return FAIL;
		}
		else if (((bIntValue & CED) && (bIntValue & ERR) && (bIntValue & CMDNK)))
		{
			MP_DEBUG1("-E- Write disabled status (bIntValue: %d)", bIntValue);
			return FAIL;
		}
}		
		
		dwBufferAddress += MCARD_SECTOR_SIZE;
	}
	return PASS;
}

static SWORD ProLogicalRead(DWORD dwLogAddr, DWORD dwSectorCount, DWORD dwBufferAddress)
{
	register MCARD *sMcard;
	register DWORD i;
	register SWORD swRetValue;
	BYTE bIntValue;
	DWORD dwMcMsStatusTemp;

	sMcard = (MCARD *) (MCARD_BASE);
	sMcard->McMsT1 = PRO_TIMEOUT1;

	//Set Parameter Register
	SetProParaReg(bProFlashCMD[PRO_READ_DATA], dwSectorCount, dwLogAddr, 0x00, 0x00);

	if ((swRetValue = WriteTpcBs(TPC_EX_SET_CMD, (BYTE *) (&sProParamReg), 7)))
	{
		MP_DEBUG1("-E- TPC_EX_SET_CMD FAIL (swRetValue: %d)", swRetValue);
		return swRetValue;
	}
	if ((swRetValue = Wait_For_INT_Pulse(&dwMcMsStatusTemp)))
	{
		MP_DEBUG1("-E- Wait_For_INT_Pulse FAIL (swRetValue: %d)", swRetValue);
		return swRetValue;
	}
	if ((swRetValue = Wait_INT_Signal_BREQ(&dwMcMsStatusTemp)))
	{
		MP_DEBUG1("-E- Wait_INT_Signal_BREQ FAIL (swRetValue: %d)", swRetValue);
		return swRetValue;
	}
	if(dwMcMsStatusTemp & (STATUS_ERR ||STATUS_CMDNK))
	{
		if ((swRetValue = GetIntValue(&bIntValue)))
		{
			MP_DEBUG1("-E- GetINT FAIL (swRetValue: %d)", swRetValue);
			return swRetValue;
		}
		if ((bIntValue & CMDNK) || ((bIntValue & BREQ) && (bIntValue & ERR)))
		{
			MP_DEBUG1("-E- Error termination (bIntValue: %d)", bIntValue);
			//Set Parameter Register
			SetProParaReg(bProFlashCMD[PRO_STOP], 0, 0, 0x00, 0x00);
			if ((swRetValue = WriteTpcBs(TPC_EX_SET_CMD, (BYTE *) (&sProParamReg), 7)))
			{
				MP_DEBUG1("-E- TPC_EX_SET_CMD FAIL (swRetValue: %d)", swRetValue);
				return swRetValue;
			}
			return FAIL;
		}
	}
	for (i = 0; i < dwSectorCount; i++)
	{
		SetDataDma(dwBufferAddress);
		if ((swRetValue = ReadTpcBsPage()))
		{
			MP_DEBUG1("-E- ReadTpcBsPage FAIL (swRetValue: %d)", swRetValue);
			return swRetValue;
		}
		if ((swRetValue = Wait_INT_Signal(&dwMcMsStatusTemp)))
		{
			MP_DEBUG1("-E- Wait_INT_Signal FAIL (swRetValue: %d)", swRetValue);
			return swRetValue;
		}
		if(i !=(dwSectorCount-1))
		{
			if ((swRetValue = Wait_INT_Signal_BREQ(&dwMcMsStatusTemp)))
			{
					MP_DEBUG1("-E- Wait_INT_Signal_BREQ FAIL (swRetValue: %d)", swRetValue);
					return swRetValue;
			}
		}
		else
		{
			if ((swRetValue = Wait_INT_Signal_CED(&dwMcMsStatusTemp)))
			{
					MP_DEBUG1("-E- Wait_INT_Signal_CED FAIL (swRetValue: %d)", swRetValue);
			return swRetValue;
		}

		}
		if(dwMcMsStatusTemp & (STATUS_ERR ||STATUS_CMDNK))
		{
			if ((swRetValue = GetIntValue(&bIntValue)))
			{	
				MP_DEBUG1("-E- GetINT FAIL (swRetValue: %d)", swRetValue);
				return swRetValue;
			}

			if ((bIntValue & CMDNK) || ((bIntValue & BREQ) && (bIntValue & ERR)))
			{
				//Set Parameter Register
				SetProParaReg(bProFlashCMD[PRO_STOP], 0, 0, 0x00, 0x00);
				if ((swRetValue = WriteTpcBs(TPC_EX_SET_CMD, (BYTE *) (&sProParamReg), 7)))
				{
					MP_DEBUG1("-E- TPC_EX_SET_CMD FAIL (swRetValue: %d)", swRetValue);
					return swRetValue;
				}
				return FAIL;
			}
		}		
		dwBufferAddress += MCARD_SECTOR_SIZE;
	}
	return PASS;
}

static SWORD ProReadAttribute(DWORD dwBufferAddress)
{
	register MCARD *sMcard;
	SWORD swRetValue;
	BYTE bIntValue;
	DWORD dwMcMsStatusTemp;
	sMcard = (MCARD *) (MCARD_BASE);
	sMcard->McMsT1 = PRO_TIMEOUT1;

	//Set Parameter Register 
	SetProParaReg(bProFlashCMD[PRO_READ_ATRB], 0x01, 0x00, 0x00, 0x00);

	if ((swRetValue = WriteTpcBs(TPC_EX_SET_CMD, (BYTE *) (&sProParamReg), 7)))
	{
		MP_DEBUG1("-E- TPC_EX_SET_CMD FAIL (swRetValue: %d)", swRetValue);
		return swRetValue;
	}

	if ((swRetValue = Wait_For_INT_Pulse(&dwMcMsStatusTemp)))
	{
		MP_DEBUG1("-E- WaitTime1INT FAIL (swRetValue: %d)", swRetValue);
		return swRetValue;
	}

	
	if(dwMcMsStatusTemp & (STATUS_ERR ||STATUS_CMDNK))
	{
		if ((swRetValue = GetIntValue(&bIntValue)))
		{
			MP_DEBUG1("-E- GetINT FAIL (swRetValue: %d)", swRetValue);
			return swRetValue;
		}
	
		if ((bIntValue & CMDNK) || ((bIntValue & BREQ) && (bIntValue & ERR)))
		{
			//Set Parameter Register
			MP_DEBUG1("-E- Error termination (bIntValue: %d)", bIntValue);
			SetProParaReg(bProFlashCMD[PRO_STOP], 0, 0, 0x00, 0x00);
			if ((swRetValue = WriteTpcBs(TPC_EX_SET_CMD, (BYTE *) (&sProParamReg), 7)))
			{
				MP_DEBUG1("-E- TPC_EX_SET_CMD FAIL (swRetValue: %d)", swRetValue);
				return swRetValue;
			}
			return FAIL;
		}

⌨️ 快捷键说明

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