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

📄 stoe.c

📁 台湾亚信电子ASIX11015以太网驱动.AX系列单片机带TCP/IP协议栈,和适合网络应用.希望和大家一起探讨
💻 C
📖 第 1 页 / 共 2 页
字号:
 * Returns:
 * Note:
 * ----------------------------------------------------------------------------
 */
void stoe_InterruptDisable(void)
{
	U8_T XDATA	temp;

	temp = 0;
	stoe_WriteReg(STOE_INT_MASK_REG, &temp, 1);

} /* End of stoe_InterruptDisable */

/*
 * ----------------------------------------------------------------------------
 * Function Name: STOE_SetInterruptFlag
 * Purpose:
 * Params:
 * Returns:
 * Note:
 * ----------------------------------------------------------------------------
 */
void STOE_SetInterruptFlag(void)
{
	U8_T XDATA	int_status;

	/* disable stoe interrupt*/
	stoe_InterruptDisable();

	/* read stoe interrupt status */
	stoe_ReadReg(STOE_INT_STATUS_REG, &int_status, 1);

	stoe_InterruptStatus = (int_status & STOE_DEFAULT_INT_MASK);

} /* End of STOE_SetInterruptFlag */

/*
 * ----------------------------------------------------------------------------
 * Function Name: STOE_GetInterruptFlag
 * Purpose:
 * Params:
 * Returns:
 * Note:
 * ----------------------------------------------------------------------------
 */
U8_T STOE_GetInterruptFlag(void)
{
	return stoe_InterruptStatus;

} /* End of STOE_SetInterruptFlag */

/*
 * ----------------------------------------------------------------------------
 * Function Name: STOE_ProcessInterrupt
 * Purpose: When STOE interrupt is trigged, programmer can call this function
 *			to process interrupt event. 
 * Params:
 * Returns:
 * Note:
 * ----------------------------------------------------------------------------
 */
void STOE_ProcessInterrupt(void)
{
	U8_T XDATA	temp;

	while (stoe_InterruptStatus)
	{
		if (stoe_InterruptStatus & RCV_PACKET)
		{
			while (PBDP->RFP < PAGES_OF_RCV)
				stoe_RcvHandle();
		}
		if (stoe_InterruptStatus & RCV_BUF_RING_FULL)
		{
//			printf ("\rRX Packet Buffer Ring is Full.\n\r");
			temp = RESUME_PKT_RCV;
			stoe_WriteReg(STOE_L4_CMD_REG, &temp, 1);
		}

		/* read stoe interrupt status */
		stoe_ReadReg(STOE_INT_STATUS_REG, &stoe_InterruptStatus, 1);
		stoe_InterruptStatus &= STOE_DEFAULT_INT_MASK;
	}

	/* ensable stoe interrupt */
	stoe_InterruptEnable();
}
#else
/*
 * ----------------------------------------------------------------------------
 * Function Name: STOE_ProcessInterrupt
 * Purpose: programmer can call this function by polling type to find that
 *			interrupt event had happened.
 * Params:
 * Returns:
 * Note:
 * ----------------------------------------------------------------------------
 */
void STOE_ProcessInterrupt(void)
{
	static U8_T XDATA	int_status;
	U8_T XDATA			temp;

	while (1)
	{
		/* read stoe interrupt status */
		stoe_ReadReg(STOE_INT_STATUS_REG, &int_status, 1);
		int_status &= STOE_DEFAULT_INT_MASK;

		if (!int_status)
			break;

		if (int_status & RCV_PACKET)
		{
			while (PBDP->RFP < PAGES_OF_RCV)
				stoe_RcvHandle();
		}
		if (int_status & RCV_BUF_RING_FULL)
		{
//			printf ("\rRX Packet Buffer Ring is Full.\n\r");
			temp = RESUME_PKT_RCV;
			stoe_WriteReg(STOE_L4_CMD_REG, &temp, 1);
		}
	}
}

#endif

/*
 * ----------------------------------------------------------------------------
 * Function Name: stoe_StartOperate
 * Purpose: start L2/L3/L4 engine
 * Params:
 * Returns:
 * Note:
 * ----------------------------------------------------------------------------
 */
void stoe_StartOperate(void)
{
	U8_T XDATA	temp;

	stoe_ReadReg(STOE_L2_CTL_REG, &temp, 1);

	temp |= (RX_START_OPERA | TX_START_OPERA);
	stoe_WriteReg(STOE_L2_CTL_REG, &temp, 1);

} /* End of stoe_StartOperate */

#if 0
/*
 * ----------------------------------------------------------------------------
 * Function Name: stoe_StopOperate
 * Purpose: stop L2/L3/L4 engine
 * Params:
 * Returns:
 * Note:
 * ----------------------------------------------------------------------------
 */
void stoe_StopOperate(void)
{
	U8_T XDATA	temp;

	stoe_ReadReg(STOE_L2_CTL_REG, &temp, 1);

	Temp &= ~(RX_START_OPERA | TX_START_OPERA);
	stoe_WriteReg(STOE_L2_CTL_REG, &temp, 1);

} /* End of stoe_StopOperate */
#endif

/*
* -----------------------------------------------------------------------------
 * Function Name: stoe_RcvHandle
 * Purpose: 
 * Params: 
 * Returns:
 * Note:
 * ----------------------------------------------------------------------------
 */
void stoe_RcvHandle(void)
{
	static STOE_FRAME_HEADER XDATA*	pframe;
	U16_T	length;
	U8_T	pages;

	pframe = ((PBDP->RHPR) << 8);
	length = (pframe->Length & 0xfff);

	PBDP->STOE_RxInform.Protocol = pframe->Protocol;
	PBDP->STOE_RxInform.TotalLen = length;
	PBDP->STOE_RxInform.PBuf = &pframe->Packet; 

	if (length && STOE_RcvCallback)
		STOE_RcvCallback(&pframe->Packet, length, pframe->Protocol);

	if (PBDP->RHPR > pframe->NPR)
		pages = (PBDP->TSPP - PBDP->RHPR) + (pframe->NPR - PBDP->RSPP);
	else
		pages = pframe->NPR - PBDP->RHPR;

	PBDP->RHPR = pframe->NPR;

	EA = 0;
	PBDP->RFP += pages;
	EA = 1;

} /* End of stoe_RcvHandle */

/*
* -----------------------------------------------------------------------------
 * Function Name: stoe_XmitHandle
 * Purpose: Set send packet bit to tell hardware transmit one packet to ethernet.
 * Params: 
 * Returns:	
 * Note:
 * ----------------------------------------------------------------------------
 */
void stoe_XmitHandle(void)
{
	U8_T XDATA temp;

	stoe_ReadReg(STOE_L4_CMD_REG, &temp, 1);
	while (temp & XMIT_PACKET)
		stoe_ReadReg(STOE_L4_CMD_REG, &temp, 1);

	temp = XMIT_PACKET;
	stoe_WriteReg(STOE_L4_CMD_REG, &temp, 1);

} /* stoe_XmitHandle */

/*
* -----------------------------------------------------------------------------
 * Function Name: STOE_Send
 * Purpose:	Call this function to set add STOE header.
 * Params:	pbuf : buffer address, must between TSPP and TEPP.
 *			length : packet length.
 *			protocol : if the packet is ip packet, set the ip layer protocol,
 *						if not a ip packet, set value to 0xff.
 * Returns:
 * Note:
 * ----------------------------------------------------------------------------
 */
void STOE_Send(U8_T XDATA* pbuf, U16_T length, U8_T protocol)
{
	STOE_FRAME_HEADER XDATA*	pframe =
									(STOE_FRAME_HEADER XDATA*)pbuf;
	U8_T	occupypages = PBDP->STOE_TxInform.Pages;

	pframe->Length = length;
	pframe->Protocol = protocol;

	EA = 0;
	PBDP->TFP -= occupypages;
	EA = 1;

	PBDP->TTPR += occupypages;
	if (PBDP->TTPR > PBDP->TEPP)
		PBDP->TTPR = PBDP->TSPP + PBDP->TTPR - PBDP->TEPP - 1;

	pframe->NPR = PBDP->TTPR;

	stoe_XmitHandle();

} /* End of STOE_Send() */


/*
* -----------------------------------------------------------------------------
 * Function Name: STOE_AssignSendBuf
 * Purpose: Assign a buffer that adress is between TSPP and TEPP, so STOE engine
 *				cans transmit the packet to MAC SRAM.
 * Params: length : Buffer size that the packet occupied.
 * Returns: Assigned transmit buffer address
 * Note:
 * ----------------------------------------------------------------------------
 */
U8_T XDATA* STOE_AssignSendBuf(U16_T length)
{
	U8_T XDATA*	pframe;
	U8_T		occupypages;

	occupypages = ((length + PAGE_SIZE - 1)/PAGE_SIZE);

	if (PBDP->TFP < occupypages)
		return (U8_T XDATA*)0;

	pframe = ((PBDP->TTPR) << 8);
	PBDP->STOE_TxInform.Pages = occupypages;

	return pframe;

} /* End of STOE_AssignSendBuf */

#if (!BOOTLDR_ISR)
/*
* -----------------------------------------------------------------------------
 * Function Name: STOE_CopyCode2TPBR
 * Purpose: 
 * Params: 
 * Returns:
 * Note:
 * ----------------------------------------------------------------------------
 */
U8_T XDATA* STOE_CopyCode2TPBR(U8_T XDATA* pdest, U8_T* psour, U16_T length)
{
	U16_T	space, leftlen;

	/* destination address is not in range of TPBR. */
	if ((pdest > PBDP->XmtEndAddr) || (pdest < PBDP->XmtStartAddr))
		return 0;

	space = (U16_T)PBDP->XmtEndAddr - (U16_T)pdest + 1;
	if (space > length)
	{
		while (length--)
			*pdest++ = *psour++;
	}
	else
	{
		leftlen = length - space;

		while (space--)
			*pdest++ = *psour++;

		pdest = PBDP->XmtStartAddr;

		while (leftlen--)
			*pdest++ = *psour++;
	}

	return pdest;

} /* End of STOE_CopyCode2TPBR */
#endif

/* End of stoe.c */

⌨️ 快捷键说明

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