realtek-doc/sources/rtk-xgs1210/include/rtk/time.h
Markus Stockhausen 18a30ac6d1 add XGS1210 sdk
2025-04-27 15:53:52 -04:00

705 lines
19 KiB
C

/*
* Copyright (C) 2009-2016 Realtek Semiconductor Corp.
* All Rights Reserved.
*
* This program is the proprietary software of Realtek Semiconductor
* Corporation and/or its licensors, and only be used, duplicated,
* modified or distributed under the authorized license from Realtek.
*
* ANY USE OF THE SOFTWARE OTHER THAN AS AUTHORIZED UNDER
* THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.
*
* $Revision: 95405 $
* $Date: 2019-02-21 21:46:25 +0800 (Thu, 21 Feb 2019) $
*
* Purpose : Definition of TIME API
*
* Feature : The file includes the following modules and sub-modules
* (1) IEEE 1588
*
*/
#ifndef __RTK_TIME_H__
#define __RTK_TIME_H__
/*
* Include Files
*/
#include <common/rt_type.h>
#include <rtk/port.h>
/*
* Symbol Definition
*/
/* TIME transmission callback function prototype */
typedef int32 (rtk_time_ptpTime_cb_f)(
uint32 unit,
rtk_port_t port,
rtk_time_ptpIdentifier_t identifier,
rtk_time_timeStamp_t time);
/*
* Data Declaration
*/
/*
* Macro Declaration
*/
/*
* Function Declaration
*/
/* Module Name : TIME */
/* Function Name:
* rtk_time_init
* Description:
* Initialize Time module of the specified device.
* Input:
* unit - unit id
* Output:
* None
* Return:
* RT_ERR_OK
* RT_ERR_FAILED
* RT_ERR_UNIT_ID - invalid unit id
* Applicable:
* 8380, 8390, 9310
* Note:
* Must initialize Time module before calling any Time APIs.
* Changes:
* None
*/
extern int32
rtk_time_init(uint32 unit);
/* Function Name:
* rtk_time_portPtpEnable_get
* Description:
* Get PTP status of the specified port.
* Input:
* unit - unit id
* port - port id
* Output:
* pEnable - status
* Return:
* RT_ERR_OK
* RT_ERR_FAILED
* RT_ERR_UNIT_ID - invalid unit id
* RT_ERR_NOT_INIT - The module is not initial
* RT_ERR_PORT - invalid port id
* RT_ERR_NULL_POINTER - input parameter may be null pointer
* Applicable:
* 8380, 8390, 9310
* Note:
* None
* Changes:
* None
*/
extern int32
rtk_time_portPtpEnable_get(uint32 unit, rtk_port_t port, rtk_enable_t *pEnable);
/* Function Name:
* rtk_time_portPtpEnable_set
* Description:
* Set PTP status of the specified port.
* Input:
* unit - unit id
* port - port id
* enable - status
* Output:
* None
* Return:
* RT_ERR_OK
* RT_ERR_FAILED
* RT_ERR_UNIT_ID - invalid unit id
* RT_ERR_NOT_INIT - The module is not initial
* RT_ERR_PORT - invalid port id
* RT_ERR_INPUT - invalid input parameter
* Applicable:
* 8380, 8390, 9310
* Note:
* None
* Changes:
* None
*/
extern int32
rtk_time_portPtpEnable_set(uint32 unit, rtk_port_t port, rtk_enable_t enable);
/* Function Name:
* rtk_time_portPtpRxTimestamp_get
* Description:
* Get PTP Rx timstamp according to the PTP identifier on the dedicated port from the specified device.
* Input:
* unit - unit id
* port - port id
* identifier - indentifier of PTP packet
* Output:
* pTimeStamp - pointer buffer of TIME timestamp
* Return:
* RT_ERR_OK
* RT_ERR_FAILED
* RT_ERR_UNIT_ID - invalid unit id
* RT_ERR_NOT_INIT - The module is not initial
* RT_ERR_PORT_ID - invalid port id
* RT_ERR_INPUT - invalid input parameter
* RT_ERR_NULL_POINTER - input parameter may be null pointer
* Applicable:
* 8380, 8390, 9310
* Note:
* None
* Changes:
* None
*/
extern int32
rtk_time_portPtpRxTimestamp_get(
uint32 unit,
rtk_port_t port,
rtk_time_ptpIdentifier_t identifier,
rtk_time_timeStamp_t *pTimeStamp);
/* Function Name:
* rtk_time_portPtpTxTimestamp_get
* Description:
* Get PTP Tx timstamp according to the PTP identifier on the dedicated port from the specified device.
* Input:
* unit - unit id
* port - port id
* identifier - indentifier of PTP packet
* Output:
* pTimeStamp - pointer buffer of TIME timestamp
* Return:
* RT_ERR_OK
* RT_ERR_FAILED
* RT_ERR_UNIT_ID - invalid unit id
* RT_ERR_NOT_INIT - The module is not initial
* RT_ERR_PORT_ID - invalid port id
* RT_ERR_INPUT - invalid input parameter
* RT_ERR_NULL_POINTER - input parameter may be null pointer
* Applicable:
* 8390, 9310
* Note:
* None
* Changes:
* None
*/
extern int32
rtk_time_portPtpTxTimestamp_get(
uint32 unit,
rtk_port_t port,
rtk_time_ptpIdentifier_t identifier,
rtk_time_timeStamp_t *pTimeStamp);
/* Function Name:
* rtk_time_portPtpTxTimestampCallback_register
* Description:
* Register PTP transmission callback function of the PTP identifier on the dedicated port to the specified device.
* Input:
* unit - unit id
* port - port id
* identifier - indentifier of PTP packet
* fCb - callback function
* Output:
* None
* Return:
* RT_ERR_OK
* RT_ERR_FAILED
* RT_ERR_UNIT_ID - invalid unit id
* RT_ERR_NOT_INIT - The module is not initial
* RT_ERR_PORT_ID - invalid port id
* RT_ERR_INPUT - invalid input parameter
* RT_ERR_NULL_POINTER - input parameter may be null pointer
* Applicable:
* 8380, 8390
* Note:
* None
* Changes:
* None
*/
extern int32
rtk_time_portPtpTxTimestampCallback_register(
uint32 unit,
rtk_port_t port,
rtk_time_ptpIdentifier_t identifier,
rtk_time_ptpTime_cb_f *fCb);
/* Function Name:
* rtk_time_portRefTime_get
* Description:
* Get the reference time of the specified port.
* Input:
* unit - unit id
* port - port id, it should be base port of PHY
* Output:
* pTimeStamp - pointer buffer of the reference time
* Return:
* RT_ERR_OK
* RT_ERR_FAILED
* RT_ERR_UNIT_ID - invalid unit id
* RT_ERR_NOT_INIT - The module is not initial
* RT_ERR_NULL_POINTER - input parameter may be null pointer
* Applicable:
* 8380, 8390, 9310
* Note:
* None
* Changes:
* [3.2.0]
* Change name from rtk_time_refTime_get.
* Add port parameter.
*/
extern int32
rtk_time_portRefTime_get(uint32 unit, rtk_port_t port, rtk_time_timeStamp_t *pTimeStamp);
/* Function Name:
* rtk_time_portRefTime_set
* Description:
* Set the reference time of the specified portmask.
* Input:
* unit - unit id
* portmask - portmask, it should be base ports of PHYs
* timeStamp - reference timestamp value
* Output:
* None
* Return:
* RT_ERR_OK
* RT_ERR_FAILED
* RT_ERR_UNIT_ID - invalid unit id
* RT_ERR_NOT_INIT - The module is not initial
* RT_ERR_INPUT - invalid input parameter
* Applicable:
* 8380, 8390, 9310
* Note:
* None
* Changes:
* [3.2.0]
* Change name from rtk_time_refTime_set.
* Add portmask parameter.
*/
extern int32
rtk_time_portRefTime_set(uint32 unit, rtk_portmask_t portmask, rtk_time_timeStamp_t timeStamp);
/* Function Name:
* rtk_time_portRefTimeAdjust_set
* Description:
* Adjust the reference time of portmask.
* Input:
* unit - unit id
* portmask - portmask, it should be base ports of PHYs
* sign - significant
* timeStamp - reference timestamp value
* Output:
* None
* Return:
* RT_ERR_OK
* RT_ERR_FAILED
* RT_ERR_UNIT_ID - invalid unit id
* RT_ERR_NOT_INIT - The module is not initial
* RT_ERR_INPUT - invalid input parameter
* Applicable:
* 8380, 8390, 9310
* Note:
* sign=0 for positive adjustment, sign=1 for negative adjustment.
* Changes:
* [3.2.0]
* Change name from rtk_time_refTimeAdjust_set.
* Add portmask parameter.
*/
extern int32
rtk_time_portRefTimeAdjust_set(uint32 unit, rtk_portmask_t portmask, uint32 sign, rtk_time_timeStamp_t timeStamp);
/* Function Name:
* rtk_time_portRefTimeEnable_get
* Description:
* Get the enable state of reference time of the specified port.
* Input:
* unit - unit id
* port - port id, it should be base port of PHY
* Output:
* pEnable - status
* Return:
* RT_ERR_OK
* RT_ERR_FAILED
* RT_ERR_UNIT_ID - invalid unit id
* RT_ERR_NOT_INIT - The module is not initial
* RT_ERR_NULL_POINTER - input parameter may be null pointer
* Applicable:
* 8380, 8390, 9310
* Note:
* None
* Changes:
* [3.2.0]
* Change name from rtk_time_refTimeEnable_get.
* Add port parameter.
*/
extern int32
rtk_time_portRefTimeEnable_get(uint32 unit, rtk_port_t port, rtk_enable_t *pEnable);
/* Function Name:
* rtk_time_portRefTimeEnable_set
* Description:
* Set the enable state of reference time of the specified portmask.
* Input:
* unit - unit id
* portmask - portmask, it should be base ports of PHYs
* enable - status
* Output:
* None
* Return:
* RT_ERR_OK
* RT_ERR_FAILED
* RT_ERR_UNIT_ID - invalid unit id
* RT_ERR_NOT_INIT - The module is not initial
* RT_ERR_INPUT - invalid input parameter
* Applicable:
* 8380, 8390, 9310
* Note:
* None
* Changes:
* [3.2.0]
* Change name from rtk_time_refTimeEnable_set.
* Add portmask parameter.
*/
extern int32
rtk_time_portRefTimeEnable_set(uint32 unit, rtk_portmask_t portmask, rtk_enable_t enable);
/* Function Name:
* rtk_time_portRefTimeFreq_get
* Description:
* Get the frequency of PTP reference time of the specified port.
* Input:
* unit - unit id
* port - port id, it should be base port of PHY
* Output:
* pFreq - pointer to reference time frequency
* Return:
* RT_ERR_OK
* RT_ERR_FAILED
* RT_ERR_UNIT_ID - invalid unit id
* RT_ERR_NOT_INIT - The module is not initial
* RT_ERR_NULL_POINTER - input parameter may be null pointer
* Applicable:
* 9310
* Note:
* The frequency configuration decides the reference time tick frequency.
* The default value is 0x80000000.
* If it is configured to 0x40000000, the tick frequency would be half of default.
* If it is configured to 0xC0000000, the tick frequency would be one and half times of default.
* Changes:
* [SDK_3.0.0]
* New added function.
* [3.2.0]
* Change name from rtk_time_refTimeFreq_get.
* Add port parameter.
*/
extern int32
rtk_time_portRefTimeFreq_get(uint32 unit, rtk_port_t port, uint32 *pFreq);
/* Function Name:
* rtk_time_portRefTimeFreq_set
* Description:
* Set the frequency of PTP reference time of the specified portmask.
* Input:
* unit - unit id
* portmask - portmask, it should be base ports of PHYs
* freq - reference time frequency
* Output:
* None
* Return:
* RT_ERR_OK
* RT_ERR_FAILED
* RT_ERR_UNIT_ID - invalid unit id
* RT_ERR_NOT_INIT - The module is not initial
* RT_ERR_INPUT - invalid input parameter
* Applicable:
* 9310
* Note:
* The frequency configuration decides the reference time tick frequency.
* The default value is 0x80000000.
* If it is configured to 0x40000000, the tick frequence would be half of default.
* If it is configured to 0xC0000000, the tick frequence would be one and half times of default.
* Changes:
* [SDK_3.0.0]
* New added function.
* [3.2.0]
* Change name from rtk_time_refTimeFreq_set.
* Add portmask parameter.
*/
extern int32
rtk_time_portRefTimeFreq_set(uint32 unit, rtk_portmask_t portmask, uint32 freq);
/* Function Name:
* rtk_time_correctionFieldTransparentValue_get
* Description:
* Get the transparent value of correction field for transparent clock.
* Input:
* unit - unit id
* oriCf - original correction field value
* rxTimeStamp - RX time stamp of the packet
* Output:
* pTransCf - pointer to transparent correction field value
* Return:
* RT_ERR_OK
* RT_ERR_FAILED
* RT_ERR_UNIT_ID - invalid unit id
* RT_ERR_NOT_INIT - The module is not initial
* RT_ERR_INPUT - invalid input parameter
* Applicable:
* 8380, 8390, 9310
* Note:
* This API calculate the value of transparent correction field by original correction field - rxTimeStamp.
* Software should replace the correction field in packet with the transparent correction field and send the packet.
* Hardware would replace the correction field by the result of TX TimeStamp - RX TimeStamp + original correction field.
* Changes:
* [SDK_3.0.0]
* New added function.
*/
extern int32
rtk_time_correctionFieldTransparentValue_get(uint32 unit, int64 oriCf, rtk_time_timeStamp_t rxTimeStamp, int64 *pTransCf);
/* Function Name:
* rtk_time_portPtpMacAddr_get
* Description:
* Get the PTP MAC address of specific port.
* Input:
* unit - unit id
* port - port ID
* Output:
* pMac - pointer to MAC adress
* Return:
* RT_ERR_OK
* RT_ERR_FAILED
* RT_ERR_UNIT_ID - invalid unit id
* RT_ERR_NOT_INIT - The module is not initial
* RT_ERR_NULL_POINTER - input parameter may be null pointer
* Applicable:
* 8380, 8390, 9310
* Note:
* None
* Changes:
* [SDK_3.6.0]
* New added function.
*/
extern int32
rtk_time_portPtpMacAddr_get(uint32 unit, rtk_port_t port, rtk_mac_t *pMac);
/* Function Name:
* rtk_time_portPtpMacAddr_set
* Description:
* Set the PTP MAC address of the specified port.
* Input:
* unit - unit id
* port - port ID
* pMac - pointer to MAC adress
* Output:
* None
* Return:
* RT_ERR_OK
* RT_ERR_FAILED
* RT_ERR_UNIT_ID - invalid unit id
* RT_ERR_NOT_INIT - The module is not initial
* RT_ERR_INPUT - invalid input parameter
* Applicable:
* 8380, 8390, 9310
* Note:
* None
* Changes:
* [SDK_3.6.0]
* New added function.
*/
extern int32
rtk_time_portPtpMacAddr_set(uint32 unit, rtk_port_t port, rtk_mac_t *pMac);
/* Function Name:
* rtk_time_portPtpMacAddrRange_get
* Description:
* Get the PTP MAC address of specific port.
* Input:
* unit - unit id
* port - port ID
* Output:
* pMacRange - pointer to MAC adress range
* Return:
* RT_ERR_OK
* RT_ERR_FAILED
* RT_ERR_UNIT_ID - invalid unit id
* RT_ERR_NOT_INIT - The module is not initial
* RT_ERR_NULL_POINTER - input parameter may be null pointer
* Applicable:
* 8380, 8390, 9310
* Note:
* None
* Changes:
* [SDK_3.6.0]
* New added function.
*/
extern int32
rtk_time_portPtpMacAddrRange_get(uint32 unit, rtk_port_t port, uint32 *pRange);
/* Function Name:
* rtk_time_portPtpMacAddrRange_set
* Description:
* Set the PTP MAC address range of the specified port.
* Input:
* unit - unit id
* port - port ID
* range - pointer to MAC adress range
* Output:
* None
* Return:
* RT_ERR_OK
* RT_ERR_FAILED
* RT_ERR_UNIT_ID - invalid unit id
* RT_ERR_NOT_INIT - The module is not initial
* RT_ERR_INPUT - invalid input parameter
* Applicable:
* 8380, 8390, 9310
* Note:
* None
* Changes:
* [SDK_3.6.0]
* New added function.
*/
extern int32
rtk_time_portPtpMacAddrRange_set(uint32 unit, rtk_port_t port, uint32 range);
/* Function Name:
* rtk_time_portPtpVlanTpid_get
* Description:
* Get the VLAN TPID of specific port.
* Input:
* unit - unit id
* port - port ID
* type - outer or inner VLAN
* idx - TPID entry index
* Output:
* pTpid - pointer to TPID
* Return:
* RT_ERR_OK
* RT_ERR_FAILED
* RT_ERR_UNIT_ID - invalid unit id
* RT_ERR_NOT_INIT - The module is not initial
* RT_ERR_NULL_POINTER - input parameter may be null pointer
* Applicable:
* 8390, 8380, 9310
* Note:
* None
* Changes:
* [SDK_3.6.0]
* New added function.
*/
extern int32
rtk_time_portPtpVlanTpid_get(uint32 unit, rtk_port_t port, rtk_vlanType_t type, uint32 idx, uint32 *pTpid);
/* Function Name:
* rtk_time_portPtpVlanTpid_set
* Description:
* Set the VLAN TPID of specific port.
* Input:
* unit - unit id
* port - port ID
* type - outer or inner VLAN
* idx - TPID entry index
* tpid - VLAN TPID
* Output:
* None
* Return:
* RT_ERR_OK
* RT_ERR_FAILED
* RT_ERR_UNIT_ID - invalid unit id
* RT_ERR_NOT_INIT - The module is not initial
* RT_ERR_INPUT - invalid input parameter
* Applicable:
* 8380, 8390, 9310
* Note:
* None
* Changes:
* [SDK_3.6.0]
* New added function.
*/
extern int32
rtk_time_portPtpVlanTpid_set(uint32 unit, rtk_port_t port, rtk_vlanType_t type, uint32 idx, uint32 tpid);
/* Function Name:
* rtk_time_portPtpOper_get
* Description:
* Get the PTP time operation configuration of specific port.
* Input:
* unit - unit id
* port - port ID
* Output:
* pOperCfg - pointer to PTP time operation configuraton
* Return:
* RT_ERR_OK
* RT_ERR_FAILED
* RT_ERR_UNIT_ID - invalid unit id
* RT_ERR_NOT_INIT - The module is not initial
* RT_ERR_NULL_POINTER - input parameter may be null pointer
* Applicable:
* 8390, 8380, 9310
* Note:
* None
* Changes:
* [SDK_3.6.0]
* New added function.
*/
extern int32
rtk_time_portPtpOper_get(uint32 unit, rtk_port_t port, rtk_time_operCfg_t *pOperCfg);
/* Function Name:
* rtk_time_portPtpOper_set
* Description:
* Set the PTP time operation configuration of specific port.
* Input:
* unit - unit id
* port - port ID
* pOperCfg - pointer to PTP time operation configuraton
* Output:
* None
* Return:
* RT_ERR_OK
* RT_ERR_FAILED
* RT_ERR_UNIT_ID - invalid unit id
* RT_ERR_NOT_INIT - The module is not initial
* RT_ERR_NULL_POINTER - input parameter may be null pointer
* Applicable:
* 8390, 8380, 9310
* Note:
* None
* Changes:
* [SDK_3.6.0]
* New added function.
*/
extern int32
rtk_time_portPtpOper_set(uint32 unit, rtk_port_t port, rtk_time_operCfg_t *pOperCfg);
/* Function Name:
* rtk_time_portPtpLatchTime_get
* Description:
* Get the PTP latched time of specific port.
* Input:
* unit - unit id
* port - port ID
* Output:
* pOperCfg - pointer to PTP time operation configuraton
* Return:
* RT_ERR_OK
* RT_ERR_FAILED
* RT_ERR_UNIT_ID - invalid unit id
* RT_ERR_NOT_INIT - The module is not initial
* RT_ERR_NULL_POINTER - input parameter may be null pointer
* Applicable:
* 8390, 8380, 9310
* Note:
* None
* Changes:
* [SDK_3.6.0]
* New added function.
*/
extern int32
rtk_time_portPtpLatchTime_get(uint32 unit, rtk_port_t port, rtk_time_timeStamp_t *pLatchTime);
#endif /* __RTK_TIME_H__ */