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

📄 ixtimesyncacccodelet.c

📁 有关ARM开发板上的IXP400网络驱动程序的源码以。
💻 C
📖 第 1 页 / 共 4 页
字号:
} /* end of ixTimeSyncAccCodeletPTPMsgTransmit function *//** * @ingroup IxTimeSyncAccCodelet * * @fn ixTimeSyncAccCodeletPTPMsgTransmitStop () * * @brief Stop PTP message transmission and destroy semaphore that is used in the  *	  transmission.   * * @return void */PRIVATE void ixTimeSyncAccCodeletPTPMsgTransmitStop (){	/* set PTP message transmission halt flag */	ixTimeSyncAccCodeletTxHalt = TRUE;	/* wait for a while to let unfinished PTP message transmission to complete */	ixOsalSleep (IX_TIMESYNCACC_CODELET_PTP_MSG_XMIT_INTERVAL);	if (NULL != ixTimeSyncAccCodeletSemId)	{		if (IX_SUCCESS != ixOsalSemaphoreDestroy (&ixTimeSyncAccCodeletSemId))		{			ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDERR, "ixTimeSyncAccCodeletPTPMsgTransmitStop: failed to destroy semaphore\n",				0, 0, 0, 0, 0, 0);		}		ixTimeSyncAccCodeletSemId = NULL;	}} /* end of ixTimeSyncAccCodeletPTPMsgTransmitStop function *//** * @ingroup IxTimeSyncAccCodelet * * @fn ixTimeSyncAccCodeletPTPMsgShow ( 	BOOL receive,	IxTimeSyncAcc1588PTPPort channel,	IxTimeSyncAccPtpMsgData *ptpMsgData) * * @brief Display PTP message type and relevant information  * * @param  * receive BOOL [in] - direction of detected message. *	- FALSE : PTP message is transmitted. *	- TRUE  : PTP message is received. * * channel IxTimeSyncAcc1588PTPPort [in] - channel number  * * ptpMsgData IxTimeSyncAccPtpMsgData* [in] - pointer to  *		IxTimeSyncAccPtpMsgData buffer. * * @return void */PRIVATE void ixTimeSyncAccCodeletPTPMsgShow (	BOOL receive,	IxTimeSyncAcc1588PTPPort tsChannel,	IxTimeSyncAccPtpMsgData *ptpMsgData			){	/* get the operation mode at a given channel */	IxTimeSyncAcc1588PTPPortMode tsChannelMode = ixTimeSyncAccCodeletConfigPtr->tsChannelMode[tsChannel];	/* PTP message is detected */	ixOsalLog (IX_OSAL_LOG_LVL_USER, IX_OSAL_LOG_DEV_STDOUT, "ixTimeSyncAccCodeletPTPMsgShow: %s channel (%s) %s %s Msg @ system time %08x %08x\n", 		(UINT32) (ixTimeSyncAccCodeletTSChannelLabel[tsChannel]),		(UINT32) (ixTimeSyncAccCodeletTSChannelModeLabel[tsChannelMode]),		(UINT32) (receive ? "received" : "transmitted"),		(UINT32) (ixTimeSyncAccCodeletPTPMessageLabel[ptpMsgData->ptpMsgType]),		ptpMsgData->ptpTimeStamp.timeValueHighWord,		ptpMsgData->ptpTimeStamp.timeValueLowWord); 	if (TRUE == receive)	{		/* show sequence number and UuId of received message */		ixOsalLog (IX_OSAL_LOG_LVL_USER, IX_OSAL_LOG_DEV_STDOUT, "ixTimeSyncAccCodeletPTPMsgShow: \tptpSequenceNumber %08x ptpUuid %08x %08x\n", 			ptpMsgData->ptpSequenceNumber, ptpMsgData->ptpUuid.uuidValueHighHalfword,		 	ptpMsgData->ptpUuid.uuidValueLowWord, 0, 0, 0);	}} /* end of ixTimeSyncAccCodeletPTPMsgShow function *//** * @ingroup IxTimeSyncAccCodelet * * @fn ixTimeSyncAccCodeletPTPMsgCheck (void) * * @brief  Check if any PTP message is received or transmitted at  * 	   any channel. * * @param  void  * * @return  IX_STATUS *          @li IX_SUCCESS - no error detected during check  *          @li IX_FAIL    - error detected during check  */PUBLIC IX_STATUS ixTimeSyncAccCodeletPTPMsgCheck (void){	IxTimeSyncAccPtpMsgData ptpMsgData;	IxTimeSyncAccStatus tsStatus;	IxTimeSyncAcc1588PTPPort channel;	for (channel = IX_TIMESYNCACC_NPE_A_1588PTP_PORT; 	     channel < IX_TIMESYNCACC_CODELET_MAX_TS_CHANNELS; 	     channel++)	{		/* initialize ptpMsgData buffer */		memset ((void *)&ptpMsgData, 0xff, sizeof (IxTimeSyncAccPtpMsgData));		/* check if any PTP message is received */		tsStatus = ixTimeSyncAccPTPRxPoll (channel, &ptpMsgData);			/* PTP message is detected */		if (IX_TIMESYNCACC_SUCCESS == tsStatus)		{			ixTimeSyncAccCodeletPTPMsgShow (TRUE, channel, &ptpMsgData);		}		else if  (IX_TIMESYNCACC_NOTIMESTAMP == tsStatus)		{			ixOsalLog (IX_OSAL_LOG_LVL_USER, IX_OSAL_LOG_DEV_STDOUT, "ixTimeSyncAccCodeletPTPMsgCheck: no new PTP message is received at %s channel\n",				(UINT32) (ixTimeSyncAccCodeletTSChannelLabel[channel]), 				0, 0, 0, 0, 0);		}		/* error is detected */		else 		{			ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDERR, "ixTimeSyncAccCodeletPTPMsgCheck: failed to determine if PTP message is received at channel %d, error code %d\n",				channel, tsStatus, 0, 0, 0, 0);			return IX_FAIL; 		}				/* initialize ptpMsgData buffer */		memset ((void *)&ptpMsgData, 0xff, sizeof (IxTimeSyncAccPtpMsgData));		/* check if any PTP message is transmitted */		tsStatus = ixTimeSyncAccPTPTxPoll (channel, &ptpMsgData);			/* PTP message is detected */		if (IX_TIMESYNCACC_SUCCESS == tsStatus)		{			ixTimeSyncAccCodeletPTPMsgShow (FALSE, channel, &ptpMsgData);		}		else if  (IX_TIMESYNCACC_NOTIMESTAMP == tsStatus)		{			ixOsalLog (IX_OSAL_LOG_LVL_USER, IX_OSAL_LOG_DEV_STDOUT, "ixTimeSyncAccCodeletPTPMsgCheck: no new PTP message is transmitted at %s channel\n",				(UINT32) (ixTimeSyncAccCodeletTSChannelLabel[channel]), 				0, 0, 0, 0, 0);		}		/* error is detected */		else 		{			ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDERR, "ixTimeSyncAccCodeletPTPMsgCheck: failed to determine if PTP message is transmitted at channel %d, error code %d\n",				channel, tsStatus, 0, 0, 0, 0);			return IX_FAIL; 		}	}	ixOsalLog (IX_OSAL_LOG_LVL_USER, IX_OSAL_LOG_DEV_STDOUT, "\n", 0, 0, 0, 0, 0, 0); 	return IX_SUCCESS;} /* end of ixTimeSyncAccCodeletPTPMsgCheck function */	/** * @ingroup IxTimeSyncAccCodelet * * @fn ixTimeSyncAccCodeletTargetTimeHitCallback (void) * * @brief  When target time is hit, first clear target time. Then, *         check if any PTP message is received or transmitted at *	   any channel. If termination is not requested, set next * 	   target time (approximately 1 second later). * * @param  void  * * @return void  */PRIVATE voidixTimeSyncAccCodeletTargetTimeHitCallback (void){	/* 	 * clear target time to prevent second interrupt 	 * from being generated on same event	 */	ixTimeSyncAccCodeletTargetTimeClear ();	/* check if any PTP message is detected */	if (IX_SUCCESS != ixTimeSyncAccCodeletPTPMsgCheck ())	{		ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDERR, "ixTimeSyncAccCodeletTargetTimeHitCallback: PTP message check failed, terminate timeSyncAcc codelet execution\n",			0, 0, 0, 0, 0, 0);		/* terminate time sync codelet execution */		ixTimeSyncAccCodeletQuit ();		return;	}	/* codelet execution was requested to be terminated */	if (TRUE == ixTimeSyncAccCodeletTerminate)	{		ixOsalLog (IX_OSAL_LOG_LVL_USER, IX_OSAL_LOG_DEV_STDOUT, "ixTimeSyncAccCodeletTargetTimeHitCallback: target time was cleared and disabled\n",			0, 0, 0, 0, 0, 0);		return;	}	/* set next target time */	if (IX_SUCCESS != ixTimeSyncAccCodeletTargetTimeSet ())	{		ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDERR, "ixTimeSyncAccCodeletTargetTimeHitCallback: failed to set target time, terminate timeSyncAcc codelet execution\n",			0, 0, 0, 0, 0, 0);		/* terminate time sync codelet execution */		ixTimeSyncAccCodeletQuit ();	}} /* end of ixTimeSyncAccCodeletTargetTimeHitCallback function *//** * @ingroup IxTimeSyncAccCodelet * * @fn ixTimeSyncAccCodeletTargetTimeSet (void) * * @brief  Set target time and enable target time interrupt.   * * @param  void  * * @return  IX_STATUS *          @li IX_SUCCESS - set target time successfully *          @li IX_FAIL    - fails */PRIVATE IX_STATUS ixTimeSyncAccCodeletTargetTimeSet (void){	IxTimeSyncAccTimeValue	tsSystemTime, tsTargetTime;	IxTimeSyncAccStatus tsStatus;	UINT32 interval = IX_TIMESYNCACC_CODELET_TARGET_TIME_HIT_INTERVAL;	/* get current system time */		tsStatus = ixTimeSyncAccSystemTimeGet (&tsSystemTime);	if (IX_TIMESYNCACC_SUCCESS != tsStatus)	{		ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDERR, "ixTimeSyncAccCodeletTargetTimeSet: failed to get system time, error code %d\n",			tsStatus, 0, 0, 0, 0, 0);				return IX_FAIL;	}	/* calculate new target time using the given interval */	tsTargetTime.timeValueLowWord = tsSystemTime.timeValueLowWord + interval;		tsTargetTime.timeValueHighWord = tsSystemTime.timeValueHighWord;	/* if next target time's lower 32 bit value will roll over */	if (tsTargetTime.timeValueLowWord < tsSystemTime.timeValueLowWord)	{		/* if next target time's upper 32 bit value will roll over */		if (IX_TIMESYNCACC_CODELET_ROLLOVER_VALUE == tsSystemTime.timeValueHighWord)		{			/* reset system time */			if (IX_SUCCESS != ixTimeSyncAccCodeletSystemTimeClear ())			{				ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDERR, "ixTimeSyncAccCodeletTargetTimeSet: failed to reset system time\n",					0, 0, 0, 0, 0, 0);				return IX_FAIL;			}			/* re-calculate new target time */			tsTargetTime.timeValueLowWord = interval;			tsTargetTime.timeValueHighWord = 0;		}		/* increment next target time's upper 32 bit value */		else		{			tsTargetTime.timeValueHighWord = tsSystemTime.timeValueHighWord + 1;			}	} /* end of if (tsTargetTime.timeValueLowWord < tsSystemTime.timeValueLowWord) */		/* write next target time to registers */		tsStatus = ixTimeSyncAccTargetTimeSet (tsTargetTime);	if (IX_TIMESYNCACC_SUCCESS != tsStatus)	{		ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDERR, "ixTimeSyncAccCodeletTargetTimeSet: failed to set next target time, error code %d\n",			tsStatus, 0, 0, 0, 0, 0);		return IX_FAIL;	}	/* enable target time interrupt */	tsStatus = ixTimeSyncAccTargetTimeInterruptEnable (			(IxTimeSyncAccTargetTimeCallback) ixTimeSyncAccCodeletTargetTimeHitCallback);	if (IX_TIMESYNCACC_SUCCESS != tsStatus)	{		/* clear target time */		ixTimeSyncAccCodeletTargetTimeClear ();		ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDERR, "ixTimeSyncAccCodeletTargetTimeSet: failed to enable Target Time interrupt, error code %d\n",			tsStatus, 0, 0, 0, 0, 0);		return IX_FAIL;	}		ixOsalLog (IX_OSAL_LOG_LVL_DEBUG1, IX_OSAL_LOG_DEV_STDOUT, "ixTimeSyncAccCodeletTargetTimeSet: current system time %08x%08x (hex) next target time %08x%08x (hex)\n",		tsSystemTime.timeValueHighWord,tsSystemTime.timeValueLowWord,		tsTargetTime.timeValueHighWord,tsTargetTime.timeValueLowWord, 0, 0);	return IX_SUCCESS;} /* end of ixTimeSyncAccCodeletTargetTimeSet function *//** * @ingroup IxTimeSyncAccCodelet * * @fn ixTimeSyncAccCodeletSystemTimeClear (void) * * @brief  Clear system time to zero.   * * @param  void  * * @return  IX_STATUS *          @li IX_SUCCESS - clear system time successfully *          @li IX_FAIL    - fails */PRIVATE IX_STATUS ixTimeSyncAccCodeletSystemTimeClear (void){	IxTimeSyncAccTimeValue	tsSystemTime;	IxTimeSyncAccStatus	tsStatus;		tsSystemTime.timeValueLowWord = 0; 	tsSystemTime.timeValueHighWord = 0;	tsStatus = ixTimeSyncAccSystemTimeSet (tsSystemTime);	if (IX_TIMESYNCACC_SUCCESS != tsStatus)	{		ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDERR, "ixTimeSyncAccCodeletSystemTimeClear: failed to clear system time, error code %d\n",			tsStatus, 0, 0, 0, 0, 0);		return IX_FAIL;	}	return IX_SUCCESS;} /* end of ixTimeSyncAccCodeletSystemTimeClear function *//** * @ingroup IxTimeSyncAccCodelet * * @fn ixTimeSyncAccCodeletTargetTimeClear (void) * * @brief  Clear Target Time Hit condition by setting Target Time to   *	   maximum value and disabling Target Time interrupt. * * @param  void  * * @return void  */PRIVATE void ixTimeSyncAccCodeletTargetTimeClear (void){	IxTimeSyncAccTimeValue	tsTargetTime;	IxTimeSyncAccStatus	tsStatus;		tsTargetTime.timeValueLowWord = 0xFFFFFFFF;	tsTargetTime.timeValueHighWord = 0xFFFFFFFF;	tsStatus = ixTimeSyncAccTargetTimeSet (tsTargetTime);	if (IX_TIMESYNCACC_SUCCESS != tsStatus)	{		ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDERR, "ixTimeSyncAccCodeletTargetTimeClear: failed to clear Target Time, error code %d\n",			tsStatus, 0, 0, 0, 0, 0);	}	/* disable Target Time interrupt */		tsStatus = ixTimeSyncAccTargetTimeInterruptDisable ();	if (IX_TIMESYNCACC_SUCCESS != tsStatus)	{		ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDERR, "ixTimeSyncAccCodeletTargetTimeClear: failed to disable Target Time interrupt, error code %d\n",			tsStatus, 0, 0, 0, 0, 0); 	}} /* end of ixTimeSyncAccCodeletTargetTimeClear () function */#endif /* end of #ifdef __ixp46X */

⌨️ 快捷键说明

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