📄 ixtimesyncacc.c
字号:
} /* end of if ((IX_TIMESYNCACC_1588PTP_PORT_ANYMODE == ptpPortMode) || (TRUE == txsFlag)) */ /* Fill-in the PTP message type */ switch (ptpPortMode) { case IX_TIMESYNCACC_1588PTP_PORT_MASTER: { ptpMsgData->ptpMsgType = IX_TIMESYNCACC_1588PTP_MSGTYPE_SYNC; break; } /* end of case IX_TIMESYNCACC_1588PTP_PORT_MASTER */ case IX_TIMESYNCACC_1588PTP_PORT_SLAVE: { ptpMsgData->ptpMsgType = IX_TIMESYNCACC_1588PTP_MSGTYPE_DELAYREQ; break; } /* end of case IX_TIMESYNCACC_1588PTP_PORT_SLAVE */ case IX_TIMESYNCACC_1588PTP_PORT_ANYMODE: { ptpMsgData->ptpMsgType = IX_TIMESYNCACC_1588PTP_MSGTYPE_UNKNOWN; break; } /* end of case IX_TIMESYNCACC_1588PTP_PORT_ANYMODE */ default: { /* This part of the code should never be reached */#ifndef NDEBUG ixOsalLog (IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDERR, "ixTimeSyncAccPTPTxPoll(): Invalid Port Mode\n", 0,0,0,0,0,0);#endif /* end of #ifndef NDEBUG */ return IX_TIMESYNCACC_FAILED; } /* end of case default */ } /* end of switch (ptpPortMode) */ /* Increment transmit timestamp counter */ ixTsStats.txMsgs++; /* Allow next timestamp to be captured */ ixTimeSyncAccControlPTPPortTxsFlagClear(ptpPort); return IX_TIMESYNCACC_SUCCESS;} /* end of ixTimeSyncAccPTPTxPoll() function *//* Set the System Time in the IEEE 1588 hardware assist block */PUBLIC IxTimeSyncAccStatusixTimeSyncAccSystemTimeSet(IxTimeSyncAccTimeValue systemTime){ /* Local variables */ UINT32 oldFsv = 0; /* Initialised before? */ IXP400_TIMESYNCACC_INIT_CHECK(); /* * Secure Mutex so that Change in Frequency Scaling Value * else where affect the System Time */ IXP400_TIMESYNCACC_MUTEX_LOCK(ixTsSysTimeMutex); /* Retrieve old Frequency Scaling Value */ ixTimeSyncAccAddendFsvGet(&oldFsv); /* * Set the Frequency Scaling Value to zero (0) so that * System Time doesn't get increment while it is being * written into low and high registers */ ixTimeSyncAccAddendFsvSet(0); /* Update System Time with user specified values */ ixTimeSyncAccSystemTimeSnapshotSet(systemTime.timeValueLowWord, systemTime.timeValueHighWord); /* * Let the hardware assist to re-evaluate the target time reached * condition based on the new system time */ ixTimeSyncAccEventTtmFlagClear(); /* * Restore old Frequency Scaling Value so that System Time * can be incremented */ ixTimeSyncAccAddendFsvSet(oldFsv); /* Unlock the mutex obtained at the beginning */ IXP400_TIMESYNCACC_MUTEX_UNLOCK(ixTsSysTimeMutex); return IX_TIMESYNCACC_SUCCESS;} /* end of ixTimeSyncAccSystemTimeSet() function *//* Get the System Time from the IEEE 1588 hardware assist block */PUBLIC IxTimeSyncAccStatusixTimeSyncAccSystemTimeGet(IxTimeSyncAccTimeValue *systemTime){ /* Verify the parameter */ if ((IxTimeSyncAccTimeValue *)NULL == systemTime) { return IX_TIMESYNCACC_INVALIDPARAM; } /* end of if ((IxTimeSyncAccTimeValue *)NULL == systemTime) */ /* Initialised before? */ IXP400_TIMESYNCACC_INIT_CHECK(); /* Fetch System Time */ ixTimeSyncAccSystemTimeSnapshotGet(&systemTime->timeValueLowWord, &systemTime->timeValueHighWord); return IX_TIMESYNCACC_SUCCESS;} /* end of ixTimeSyncAccSystemTimeGet() function *//* * Set the Tick Rate (Frequency Scaling Value) in the IEEE 1588 * hardware assist block */PUBLIC IxTimeSyncAccStatusixTimeSyncAccTickRateSet(UINT32 tickRate){ /* Initialised before? */ IXP400_TIMESYNCACC_INIT_CHECK(); /* * Secure Mutex to avoid update of Frequency Scaling Value * and the System Time, happening at the same time */ IXP400_TIMESYNCACC_MUTEX_LOCK(ixTsSysTimeMutex); /* Update the Frequency Scaling Value */ ixTimeSyncAccAddendFsvSet(tickRate); /* Release the mutex obtained at the beginning */ IXP400_TIMESYNCACC_MUTEX_UNLOCK(ixTsSysTimeMutex); return IX_TIMESYNCACC_SUCCESS;} /* end of ixTimeSyncAccTickRateSet() function *//* * Get the Tick Rate (Frequency Scaling Value) from the IEEE 1588 * hardware assist block */PUBLIC IxTimeSyncAccStatusixTimeSyncAccTickRateGet(UINT32 *tickRate){ /* Verify the parameter */ if ((UINT32 *)NULL == tickRate) { return IX_TIMESYNCACC_INVALIDPARAM; } /* end of if ((UINT32 *)NULL == tickRate) */ /* Initialised before? */ IXP400_TIMESYNCACC_INIT_CHECK(); /* Retrieve Current Frequency Scaling Value */ ixTimeSyncAccAddendFsvGet(tickRate); return IX_TIMESYNCACC_SUCCESS;} /* end of ixTimeSyncAccTickRateGet() function *//* * Enable the interrupt to verify the condition where the System Time * greater or equal to the Target Time in the IEEE 1588 hardware assist * block. */PUBLIC IxTimeSyncAccStatusixTimeSyncAccTargetTimeInterruptEnable( IxTimeSyncAccTargetTimeCallback targetTimeCallback){ /* Verify the parameter */ if ((IxTimeSyncAccTargetTimeCallback)NULL == targetTimeCallback) { return IX_TIMESYNCACC_INVALIDPARAM; } /* end of if ((IxTimeSyncAccTargetTimeCallback)NULL == targetTimeCallback) */ /* Initialised before? */ IXP400_TIMESYNCACC_INIT_CHECK(); /* Register the Callback */ ixTsTargetTimeCallback = targetTimeCallback; /* Set target time interrupt mask */ ixTimeSyncAccControlTtmInterruptMaskSet(); return IX_TIMESYNCACC_SUCCESS;} /* end of ixTimeSyncAccTargetTimeInterruptEnable() function *//* * Disable the interrupt to verify the condition that the System Time * greater or equal to the Target Time in the IEEE 1588 hardware assist * block. */PUBLIC IxTimeSyncAccStatusixTimeSyncAccTargetTimeInterruptDisable(void){ /* Initialised before? */ IXP400_TIMESYNCACC_INIT_CHECK(); /* Clear target time interrupt mask */ ixTimeSyncAccControlTtmInterruptMaskClear(); /* Unregister the Callback */ ixTsTargetTimeCallback = (IxTimeSyncAccTargetTimeCallback) NULL; return IX_TIMESYNCACC_SUCCESS;} /* end of ixTimeSyncAccTargetTimeInterruptDisable() function *//* * Poll to verify the condition where the System Time greater or equal * to the Target Time in the IEEE 1588 hardware assist block. */PUBLIC IxTimeSyncAccStatusixTimeSyncAccTargetTimePoll( BOOL *ttmPollFlag, IxTimeSyncAccTimeValue *targetTime){ /* Verify the parameters */ if (((BOOL *)NULL == ttmPollFlag) || ((IxTimeSyncAccTimeValue *)NULL == targetTime)) { return IX_TIMESYNCACC_INVALIDPARAM; } /* end of if (((BOOL *)NULL == ttmPollFlag) || ((IxTimeSyncAccTimeValue)NULL == targetTime)) */ /* Is interrupt mode of processing is enabled? */ if ((IxTimeSyncAccTargetTimeCallback) NULL != ixTsTargetTimeCallback) { return IX_TIMESYNCACC_INTERRUPTMODEINUSE; } /* if ((IxTimeSyncAccTargetTimeCallback) NULL != ixTsTargetTimeCallback) */ /* Initialised before? */ IXP400_TIMESYNCACC_INIT_CHECK(); /* Is the System Time reached or exceeded Target Time? */ *ttmPollFlag = ixTimeSyncAccEventTtmFlagGet(); if (FALSE == ttmPollFlag) { /* Target Time not to be returned yet */ targetTime->timeValueLowWord = 0; targetTime->timeValueHighWord = 0; return IX_TIMESYNCACC_SUCCESS; } /* if (FALSE == ttmPollFlag) */ /* Fetch Target Time */ ixTimeSyncAccTargetTimeSnapshotGet(&targetTime->timeValueLowWord, &targetTime->timeValueHighWord); /* Clear the target time reached condition (ttipend bit) */ ixTimeSyncAccEventTtmFlagClear(); return IX_TIMESYNCACC_SUCCESS;} /* end of ixTimeSyncAccTargetTimePoll() function *//* Set the Target Time in the IEEE 1588 hardware assist block */PUBLIC IxTimeSyncAccStatusixTimeSyncAccTargetTimeSet(IxTimeSyncAccTimeValue targetTime){ /* Local variables */ BOOL oldTtmMask = FALSE; /* Initialised before? */ IXP400_TIMESYNCACC_INIT_CHECK(); /* Retrieve existing target time interrupt mask value */ oldTtmMask = ixTimeSyncAccControlTtmInterruptMaskGet(); /* Clear the target time interrupt mask value to prevent false * interrupts from being asserted due to the increments of the * values in the System Time low and high registers (i.e., the * target time reached or exceeded interrupt does not get * generated */ ixTimeSyncAccControlTtmInterruptMaskClear(); /* Update Target Time with user specified values */ ixTimeSyncAccTargetTimeSnapshotSet(targetTime.timeValueLowWord, targetTime.timeValueHighWord); /* * Let the hardware assist to re-evaluate the target time reached * condition based on the new target time */ ixTimeSyncAccEventTtmFlagClear(); /* Restore the preserved target time interrupt mask value */ if (TRUE == oldTtmMask) { ixTimeSyncAccControlTtmInterruptMaskSet(); } /* end of if (TRUE == oldTtmMask) */ return IX_TIMESYNCACC_SUCCESS;} /* end of ixTimeSyncAccTargetTimeSet() function *//* Get the Target Time in the IEEE 1588 hardware assist block */PUBLIC IxTimeSyncAccStatusixTimeSyncAccTargetTimeGet(IxTimeSyncAccTimeValue *targetTime){ /* Verify the parameter */ if ((IxTimeSyncAccTimeValue *)NULL == targetTime) { return IX_TIMESYNCACC_INVALIDPARAM; } /* end of if ((IxTimeSyncAccTimeValue *)NULL == systemTime) */ /* Initialised before? */ IXP400_TIMESYNCACC_INIT_CHECK(); /* Fetch Target Time */ ixTimeSyncAccTargetTimeSnapshotGet(&targetTime->timeValueLowWord, &targetTime->timeValueHighWord); return IX_TIMESYNCACC_SUCCESS;} /* end of ixTimeSyncAccTargetTimeGet() function *//* * Enable the interrupt notification for the given mode of Auxiliary Time * Stamp in the IEEE 1588 hardware assist block */ PUBLIC IxTimeSyncAccStatusixTimeSyncAccAuxTimeInterruptEnable( IxTimeSyncAccAuxMode auxMode, IxTimeSyncAccAuxTimeCallback auxTimeCallback){ /* Verify the parameters */ if ((IX_TIMESYNCACC_AUXMODE_INVALID <= auxMode) || ((IxTimeSyncAccAuxTimeCallback)NULL == auxTimeCallback)) { return IX_TIMESYNCACC_INVALIDPARAM; } /* if ((IX_TIMESYNCACC_AUXMODE_INVALID <= auxMode) || ((IxTimeSyncAccAuxTimeCallback)NULL == auxTimeCallback)) */ /* Initialised before? */ IXP400_TIMESYNCACC_INIT_CHECK(); /* Register the Callback and SET the amm/asm bits on */ if (IX_TIMESYNCACC_AUXMODE_MASTER == auxMode) { ixTsAuxMasterTimeCallback = auxTimeCallback; ixTimeSyncAccControlAmmsInterruptMaskSet(); } /* else of if (IX_TIMESYNCACC_AUXMODE_MASTER == auxMode) */ else { ixTsAuxSlaveTimeCallback = auxTimeCallback; ixTimeSyncAccControlAsmsInterruptMaskSet(); } /* end of if (IX_TIMESYNCACC_AUXMODE_MASTER == auxMode) */ return IX_TIMESYNCACC_SUCCESS;} /* end of ixTimeSyncAccAuxTimeInterruptEnable() function */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -