/**
*   @file           Eth_GeneralTypes.h
*   @version 1.0.0
*
*   @brief   AUTOSAR Base driver type definitions header file
*   @details Definitions of types for the Ethernet driver
*            This file contains sample code only. It is not part of the production code deliverables
*   @addtogroup BASE_COMPONENT
*   @{
*/
/*==================================================================================================
*   Project              : AUTOSAR 4.3 MCAL
*   Platform             : PA
*   Peripheral           : MPC5777C
*   Dependencies         : none
*
*   Autosar Version      : 4.3.1
*   Autosar Revision     : ASR_REL_4_3_REV_0001
*   Autosar Conf.Variant :
*   SW Version           : 1.0.0
*   Build Version        : MPC5777C_MCAL_1_0_0_RTM_ASR_REL_4_3_REV_0001_20190315
*
*   (c) Copyright 2006-2016 Freescale Semiconductor, Inc. 
*       Copyright 2017-2019 NXP
*   All Rights Reserved.
==================================================================================================*/
/*==================================================================================================
==================================================================================================*/

#ifndef ETH_GENERALTYPES_H
#define ETH_GENERALTYPES_H

#ifdef __cplusplus
extern "C"{
#endif

/**
* @page misra_violations MISRA-C:2012 violations
*
*/

/*==================================================================================================
*                                        INCLUDE FILES
* 1) system and project includes
* 2) needed interfaces from external units
* 3) internal and external interfaces from this unit
==================================================================================================*/

#include "ComStack_Types.h" /* Mandatory include - see the SWS */

/*==================================================================================================
*                              SOURCE FILE VERSION INFORMATION
==================================================================================================*/


/*==================================================================================================
*                                     FILE VERSION CHECKS
==================================================================================================*/

/*==================================================================================================
*                                          CONSTANTS
==================================================================================================*/

/*==================================================================================================
*                                      DEFINES AND MACROS
==================================================================================================*/

/*==================================================================================================
*                                             ENUMS
==================================================================================================*/
/**
* @brief          The Ethernet driver state.
* @details        A variable of this type holds the state of the Ethernet driver
*                 module. The driver is at the ETH_STATE_UNINIT at the beginning
*                 until the Eth_Init() function is called. The state remains
*                 equal to the ETH_STATE_INIT until the Eth_ControllerInit()
*                 function is called. Then the state is ETH_STATE_ACTIVE.
* @implements     Eth_StateType_enumeration
*/
typedef enum
{
    ETH_STATE_UNINIT = 0, /**< The driver has not been initialized yet */
    ETH_STATE_INIT        /**< The driver has not been configured and
                               the controller was configured */
} Eth_StateType;

/**
* @brief          The Ethernet controller mode.
* @details        This type is used to store the information whether the
*                 Ethernet controller is stopped or running.
* @implements     Eth_ModeType_enumeration
*/
typedef enum
{
    ETH_MODE_DOWN = 0,    /**< Controller is shut down */
    ETH_MODE_ACTIVE       /**< Controller is active */
}  Eth_ModeType;

/**
* @brief          The Ethernet reception status
* @details        This status is returned by the @c Eth_Receive() function to indicate
*                 whether any frame has been received and if yes, whether there is any
*                 frame still waiting in the queue (for another @c Eth_Receive() call).
* @implements     Eth_RxStatusType_enumeration
*/
typedef enum
{
    ETH_RECEIVED = 0,   /**< A frame has been received and there are no more frames in the queue */
    ETH_NOT_RECEIVED,   /**< No frames received */
    ETH_RECEIVED_MORE_DATA_AVAILABLE /**< A frame received and at least another one in the queue detected */
} Eth_RxStatusType;

/**
* @brief          Action type for PHY address filtering
* @details        The Enumeration type describes the action to be taken
*                 for the MAC address given in *PhysAddrPtr
* @implements     Eth_FilterActionType_enumeration
*/
typedef enum
{
    ETH_ADD_TO_FILTER = 0,    /**< Add address to the filter */
    ETH_REMOVE_FROM_FILTER    /**< Remove address */
} Eth_FilterActionType;

/**
* @brief          The Ethernet quality of timestamp type
* @details        Depending on the HW, quality information regarding the evaluated time stamp 
*                 might be supported. If not supported, the value shall be always Valid. For 
*                 Uncertain and Invalid values, the upper layer shall discard the time stamp.
* @implements     Eth_TimeStampQualType_enumeration
*/
typedef enum
{
    ETH_VALID = 0,         /**< Success */
    ETH_INVALID,       /**< General failure */
    ETH_UNCERTAIN     /**< Ethernet hardware access failure */
}  Eth_TimeStampQualType;


/*==================================================================================================
*                                STRUCTURES AND OTHER TYPEDEFS
==================================================================================================*/
/**
* @brief         Frame type.
* @details       This type is used to pass the value of type or length field in the
*                Ethernet frame header. It is 16 bits long unsigned integer.
*                - Values less than or equal to 1500 represent the length.
*                - Values grater than 1500 represent the type (i.e. 0x800 = IP).
* @implements     Eth_FrameType_type
*/
typedef uint16 Eth_FrameType;

/**
* @brief         Type used to pass transmit or receive data to or from the driver.
* @details       This type was defined as 8 bit wide unsigned integer because
*                this definition is available on all CPU types.
* @implements     Eth_DataType_type
*/
typedef uint8 Eth_DataType;

/**
* @brief         Type used to identify the ethernet buffer. 
* @details       This type was defined for index of buffer used in transmitted and received data.
* @implements     Eth_BufIdxType_type
*/
typedef uint32 Eth_BufIdxType;

/**
* @brief         Type used to express the timestamp value. 
* @details       Variables of this type are used for expressing time stamps including relative time 
*                and absolute calendar time. The absolute time starts acc. to "[5], Annex C/C1" 
*                specification at 1970-01-01.
*                0 to 281474976710655s
*                == 3257812230d
*                [0xFFFF FFFF FFFF]
*                0 to 999999999ns
*                [0x3B9A C9FF]
*                invalid value in nanoseconds: [0x3B9A CA00] to [0x3FFF FFFF]
*                Bit 30 and 31 reserved, default: 0
* @implements    Eth_TimeStampType_type
*/
typedef struct
{
    VAR(uint32, ETH_VAR) nanoseconds;   /**< @brief Nanoseconds part of the time */
    VAR(uint32, ETH_VAR) seconds;       /**< @brief 32 bit LSB of the 48 bits Seconds part of the time */
    VAR(uint16, ETH_VAR) secondsHi;     /**< @brief 16 bit MSB of the 48 bits Seconds part of the time */
} Eth_TimeStampType;

/**
* @brief         Type used to express the diff between timestamp values. 
* @details       Variables of this type are used to express time differences in a usual way. The 
*                described "TimeInterval" type referenced in ", chapter 6.3.3.3" will not be used 
*                and hereby slightly simplified.
* @implements    Eth_TimeIntDiffType_structure
*/
typedef struct
{
    VAR(Eth_TimeStampType, ETH_VAR) diff;   /**< @brief diff time difference */
    VAR(boolean, ETH_VAR) sign;       /**< @brief Positive (True) Or negative (False) time */
} Eth_TimeIntDiffType;

/**
* @brief         Type used to express frequency ratio. 
* @details       Variables of this type are used to express frequency ratios. 
* @implements    Eth_RateRatioType_structure
*/
typedef struct
{
    VAR(Eth_TimeIntDiffType, ETH_VAR) IngressTimeStampDelta;   /**< @brief   IngressTimeStampSync2 -IngressTimeStampSync1 */
    VAR(Eth_TimeIntDiffType, ETH_VAR) OriginTimeStampDelta;       /**< @brief OriginTimeStampSync2[FUP2]-OriginTimeStampSync1[FUP1] */
} Eth_RateRatioType;

/**
* @brief         Type used to statistic counter for diagnostics. 
* @details       Variables of this type are used to statistic counter for diagnostics. 
* @implements    Eth_CounterType_structure
*/
typedef struct{
    uint32 DropPktBufOverrun;
    uint32 DropPktCrc;
    uint32 UndersizePkt;
    uint32 OversizePkt;
    uint32 AlgnmtErr;
    uint32 SqeTestErr;
    uint32 DiscInbdPkt;
    uint32 ErrInbdPkt;
    uint32 DiscOtbdPkt;
    uint32 ErrOtbdPkt;
    uint32 SnglCollPkt;
    uint32 MultCollPkt;
    uint32 DfrdPkt;
    uint32 LatCollPkt;
    uint32 HwDepCtr0;
    uint32 HwDepCtr1;
    uint32 HwDepCtr2;
    uint32 HwDepCtr3;
}Eth_CounterType;

/**
* @brief         Type used to statistic counter for diagnostics. 
* @details       Variables of this type are used to statistic counter for diagnostics. 
* @implements    Eth_RxStatsType_structure
*/
typedef struct
{
   uint32 RxStatsDropEvents;
   uint32 RxStatsOctets;
   uint32 RxStatsPkts;
   uint32 RxStatsBroadcastPkts;
   uint32 RxStatsMulticastPkts;
   uint32 RxStatsCrcAlignErrors;
   uint32 RxStatsUndersizePkts;
   uint32 RxStatsOversizePkts;
   uint32 RxStatsFragments;
   uint32 RxStatsJabbers;
   uint32 RxStatsCollisions;
   uint32 RxStatsPkts64Octets;
   uint32 RxStatsPkts65to127Octets;
   uint32 RxStatsPkts128to255Octets;
   uint32 RxStatsPkts256to511Octets;
   uint32 RxStatsPkts512to1023Octets;
   uint32 RxStatsPkts1024to1518Octets;
   uint32 RxUnicastFrames;
}Eth_RxStatsType;

/**
* @brief         Type used to statistic counter for diagnostics. 
* @details       Variables of this type are used to statistic counter for diagnostics. 
* @implements    Eth_TxStatsType_structure
*/
typedef struct
{
    uint32 TxNumberOfOctets;
    uint32 TxNUcastPkts;
    uint32 TxUniCastPkts;
}Eth_TxStatsType;

/**
* @brief         Type used to statistic counter for diagnostics. 
* @details       Variables of this type are used to statistic counter for diagnostics. 
* @implements    Eth_TxErrorCounterValuesType_structure
*/
typedef struct
{
    uint32 TxDroppedNoErrorPkts;
    uint32 TxDroppedErrorPkts;
    uint32 TxDeferredTrans;
    uint32 TxSingleCollision;
    uint32 TxMultipleCollision;
    uint32 TxLateCollision;
    uint32 TxExcessiveCollison;
}Eth_TxErrorCounterValuesType;

/**
* @brief         Type used for VLAN management in EthSwt. 
* @details       Variables of this type are used to store information related to VLAN. 
* @implements    Eth_MacVlanType_structure
*/
typedef struct
{
    uint8 MacAddr[6];
    uint16 VlanId;
    uint8 SwitchPort;
    uint16 HashValue;
}Eth_MacVlanType;

/*==================================================================================================
*                                GLOBAL VARIABLE DECLARATIONS
==================================================================================================*/

/*==================================================================================================
*                                    FUNCTION PROTOTYPES
==================================================================================================*/

#ifdef __cplusplus
}
#endif

#endif /* ETH_GENERALTYPES_H */
/** @} */
