/* =========================================================================
 *  This code (or certain portions of it) is released for use under license
 *  from Imagination Technologies Limited.
 *  Copyright (c) 2019 Imagination Technologies Limited
 *  Copyright 2020-2022 NXP
 *
 *  NXP Confidential. This software is owned or controlled by NXP and may only
 *  be used strictly in accordance with the applicable license terms. By
 *  expressly accepting such terms or by downloading, installing, activating
 *  and/or otherwise using the software, you are agreeing that you have read,
 *  and that you agree to comply with and are bound by, such license terms. If
 *  you do not agree to be bound by the applicable license terms, then you may
 *  not retain, install, activate or otherwise use the software.
 *  <<< PFE Restricted Software >>>
 *
 * ========================================================================= */

#ifndef PUBLIC_PFE_HIF_PTP_H_
#define PUBLIC_PFE_HIF_PTP_H_

/*==================================================================================================
*                                     FILE VERSION CHECK
==================================================================================================*/
#ifdef PFE_SRC_VERSION_CHECK
    #if (PFE_SRC_VERSION_CHECK != 43100440)
        #error "This header file was included from incompatible source file (different SW version)"
    #endif
#else
    #define PFE_SRC_VERSION_CHECK 43100440
#endif

#include "linked_list.h"

typedef struct
{
	oal_mutex_t lock;
	LLIST_t entries;
	oal_thread_t *worker;
	oal_mbox_t *mbox;
	uint8_t count;
	bool_t reported;
} pfe_hif_ptp_ts_db_t;

#ifdef PFE_CFG_TARGET_OS_AUTOSAR
#define ETH_43_PFE_START_SEC_CODE
#include "Eth_43_PFE_MemMap.h"
#endif /* PFE_CFG_TARGET_OS_AUTOSAR */

errno_t pfe_hif_ptp_ts_db_init(pfe_hif_ptp_ts_db_t *db);
void pfe_hif_ptp_ts_db_fini(pfe_hif_ptp_ts_db_t *db);
errno_t pfe_hif_ptp_ts_db_push_msg(pfe_hif_ptp_ts_db_t *db, bool_t rx,
		uint16_t refnum, uint8_t type, uint16_t port, uint16_t seq_id);
errno_t pfe_hif_ptp_ts_db_push_ts(pfe_hif_ptp_ts_db_t *db,
		uint16_t refnum, uint32_t ts_sec, uint32_t ts_nsec);
errno_t pfe_hif_ptp_ts_db_pop(pfe_hif_ptp_ts_db_t *db,
		uint8_t type, uint16_t port, uint16_t seq_id,
		uint32_t *ts_sec, uint32_t *ts_nsec, bool_t rx);

#ifdef PFE_CFG_TARGET_OS_AUTOSAR
void pfe_hif_ptp_ts_db_tick_iteration(void *arg);
#endif

#ifdef PFE_CFG_TARGET_OS_AUTOSAR
#define ETH_43_PFE_STOP_SEC_CODE
#include "Eth_43_PFE_MemMap.h"
#endif /* PFE_CFG_TARGET_OS_AUTOSAR */

#endif /* PUBLIC_PFE_HIF_PTP_H_ */
