/*==================================================================================================
*   Project              : RTD AUTOSAR 4.4
*   Platform             : CORTEXM
*   Peripheral           : LPUART
*   Dependencies         : none
*
*   Autosar Version      : 4.4.0
*   Autosar Revision     : ASR_REL_4_4_REV_0000
*   Autosar Conf.Variant :
*   SW Version           : 0.9.0
*   Build Version        : S32K3_RTD_0_9_0__ASR_REL_4_4_REV_0000_20210326
*
*   (c) Copyright 2020 - 2021 NXP Semiconductors
*   All Rights Reserved.
*
*   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.
==================================================================================================*/

#ifndef LPUART_LIN_IP_TYPESS_H
#define LPUART_LIN_IP_TYPESS_H

/**
*   @file   Lpuart_Lin_Ip_Types.h
*
*   @defgroup lpuart_lin_ip Lpuart Lin IPL
*   @addtogroup  lpuart_lin_ip Lpuart Lin IPL
*   @{
*/

#ifdef __cplusplus
extern "C"{
#endif

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

#include "StandardTypes.h"

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

#define LPUART_LIN_IP_TYPES_VENDOR_ID                    43
#define LPUART_LIN_IP_TYPES_AR_RELEASE_MAJOR_VERSION     4
#define LPUART_LIN_IP_TYPES_AR_RELEASE_MINOR_VERSION     4
#define LPUART_LIN_IP_TYPES_AR_RELEASE_REVISION_VERSION  0
#define LPUART_LIN_IP_TYPES_SW_MAJOR_VERSION             0
#define LPUART_LIN_IP_TYPES_SW_MINOR_VERSION             9
#define LPUART_LIN_IP_TYPES_SW_PATCH_VERSION             0

/*==================================================================================================
*                                       FILE VERSION CHECKS
==================================================================================================*/
#ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
    /* Check if current file and StandardTypes.h header file are of the same Autosar version */
    #if ((LPUART_LIN_IP_TYPES_AR_RELEASE_MAJOR_VERSION != STD_AR_RELEASE_MAJOR_VERSION) || \
         (LPUART_LIN_IP_TYPES_AR_RELEASE_MINOR_VERSION != STD_AR_RELEASE_MINOR_VERSION))
        #error "AutoSar Version Numbers of Lpuart_Lin_Ip_Types.h and StandardTypes.h are different"
    #endif
#endif

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

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

/**
 * @brief Macro that specifies usage of a SLAVE note
 * 
 * @details This macro is used in user configuration structure to set the node type as SLAVE.
 * 
 */
#define LPUART_LIN_IP_SLAVE  (0U)

/**
 * @brief Macro that specifies usage of a SLAVE note
 * 
 * @details This macro is used in user configuration structure to set the node type as MASTER.
 *
 */
#define LPUART_LIN_IP_MASTER (1U)

/**
 * @brief Macro LPUART break char length 10 bit times
 *
 * @details LPUART break char length 10 bit times (if M = 0, SBNS = 0)
 * or 11 (if M = 1, SBNS = 0 or M = 0, SBNS = 1) or 12 (if M = 1,
 * SBNS = 1 or M10 = 1, SNBS = 0) or 13 (if M10 = 1, SNBS = 1)
 */
#define LPUART_LIN_IP_BREAK_CHAR_10_BIT_MINIMUM_U8  ((uint8)0x0U)

/**
 * @brief Macro LPUART break char length 10 bit times
 *
 * @details LPUART break char length 13 bit times (if M = 0, SBNS = 0
 * or M10 = 0, SBNS = 1) or 14 (if M = 1, SBNS = 0 or M = 1,
 * SBNS = 1) or 15 (if M10 = 1, SBNS = 1 or M10 = 1, SNBS = 0)
 */
#define LPUART_LIN_IP_BREAK_CHAR_13_BIT_MINIMUM_U8  ((uint8)0x1U)

/*==================================================================================================
*                                              ENUMS
==================================================================================================*/
/**
 * @brief Enum containing the events related to a ID
 * 
 * @details This enum defines types for an enumerating event related to an Identifier.
 * 
 * @implements Lpuart_Lin_Ip_EventIdType_enumeration
 *
 *
 */
typedef enum {
    LPUART_LIN_IP_NO_EVENT                = 0x00U,    /**< @brief No event */
    LPUART_LIN_IP_WAKEUP_SIGNAL           = 0x01U,    /**< @brief Wakeup signal detected */
    LPUART_LIN_IP_BAUDRATE_ADJUSTED       = 0x02U,    /**< @brief Baudrate adjusted */
    LPUART_LIN_IP_RECV_BREAK_FIELD_OK     = 0x03U,    /**< @brief Break field received */
    LPUART_LIN_IP_SYNC_OK                 = 0x04U,    /**< @brief Sync byte received ok */
    LPUART_LIN_IP_SYNC_ERROR              = 0x05U,    /**< @brief Sync byte received with errors */
    LPUART_LIN_IP_PID_OK                  = 0x06U,    /**< @brief PID byte received ok */
    LPUART_LIN_IP_PID_ERROR               = 0x07U,    /**< @brief PID byte received with errors */
    LPUART_LIN_IP_FRAME_ERROR             = 0x08U,    /**< @brief Frame transfer has errors */
    LPUART_LIN_IP_READBACK_ERROR          = 0x09U,    /**< @brief Readback error */
    LPUART_LIN_IP_CHECKSUM_ERROR_EVENT    = 0x0AU,    /**< @brief Checksum error */
    LPUART_LIN_IP_TX_COMPLETED            = 0x0BU,    /**< @brief Tx completed */
    LPUART_LIN_IP_RX_COMPLETED            = 0x0CU,    /**< @brief Rx completed */
    LPUART_LIN_IP_RX_OVERRUN_ERROR        = 0x0DU,    /**< @brief Rx overrun error */
    LPUART_LIN_IP_TIMEOUT_ERROR           = 0x0EU     /**< @brief Timeout error */
} Lpuart_Lin_Ip_EventIdType;

/**
 * @brief Define type for an enumerating LIN Node state.
 * @implements Lpuart_Lin_Ip_NodeStateType_enumeration
 *
 *
 */
typedef enum {
    LPUART_LIN_IP_NODE_STATE_UNINIT                 = 0x00U,    /**< @brief Uninitialized state */
    LPUART_LIN_IP_NODE_STATE_SLEEP_MODE             = 0x01U,    /**< @brief Sleep mode state */
    LPUART_LIN_IP_NODE_STATE_IDLE                   = 0x02U,    /**< @brief Idle state */
    LPUART_LIN_IP_NODE_STATE_SEND_BREAK_FIELD       = 0x03U,    /**< @brief Send break field state */
    LPUART_LIN_IP_NODE_STATE_RECV_SYNC              = 0x04U,    /**< @brief Receive the synchronization byte state */
    LPUART_LIN_IP_NODE_STATE_SEND_PID               = 0x05U,    /**< @brief Send PID state */
    LPUART_LIN_IP_NODE_STATE_RECV_PID               = 0x06U,    /**< @brief Receive PID state */
    LPUART_LIN_IP_NODE_STATE_RECV_DATA              = 0x07U,    /**< @brief Receive data state */
    LPUART_LIN_IP_NODE_STATE_RECV_DATA_COMPLETED    = 0x08U,    /**< @brief Receive data completed state */
    LPUART_LIN_IP_NODE_STATE_SEND_DATA              = 0x09U,    /**< @brief Send data state */
    LPUART_LIN_IP_NODE_STATE_SEND_DATA_COMPLETED    = 0x0AU     /**< @brief Send data completed state */
} Lpuart_Lin_Ip_NodeStateType;

/** 
 * @brief LPUART status type 
 * 
 */
typedef enum
{
    LPUART_LIN_IP_STATUS_SUCCESS = 0x00,
    LPUART_LIN_IP_STATUS_ERROR,
    LPUART_LIN_IP_STATUS_BUSY,
    LPUART_LIN_IP_STATUS_TIMEOUT
} Lpuart_Lin_Ip_StatusType;
/*==================================================================================================
*                                  STRUCTURES AND OTHER TYPEDEFS
==================================================================================================*/
/**
 * @brief Callback function to get time interval in nanoseconds
 * Implements : Lpuart_Lin_Ip_GetTimerGetTimeIntervalType_Class
 */

typedef uint32 (*Lpuart_Lin_Ip_GetTimerGetTimeIntervalType) (uint32 instance, uint32 *nanoSeconds);

/**
 * @brief LIN Driver callback function type
 * @implements Lpuart_Lin_Ip_CallbackType_pointer
 */
typedef void (*Lpuart_Lin_Ip_CallbackType)(uint32 instance, void *plinState);

/**
 * @internal
 * @brief Runtime state of the LIN driver.
 *
 * 
 * 
 */
typedef struct {
    const uint8 * txBuff;                                         /**< @brief The buffer of data being sent. */
    uint8 * rxBuff;                                         /**< @brief The buffer of received data. */
    uint8 cntByte;                                          /**< @brief To count number of bytes already transmitted or received. */
    volatile uint8 txSize;                                  /**< @brief The remaining number of bytes to be transmitted. */
    volatile uint8 rxSize;                                  /**< @brief The remaining number of bytes to be received. */
    uint8 checkSum;                                         /**< @brief Checksum byte. */
    volatile boolean isTxBusy;                              /**< @brief True if the LIN interface is transmitting frame data. */
    volatile boolean isRxBusy;                              /**< @brief True if the LIN interface is receiving frame data. */
    volatile boolean isBusBusy;                             /**< @brief True if there are data, frame headers being transferred on bus */
    uint8 currentId;                                        /**< @brief Current ID */
    uint8 currentPid;                                       /**< @brief Current PID */
    volatile Lpuart_Lin_Ip_EventIdType currentEventId;      /**< @brief Current ID Event */
    volatile Lpuart_Lin_Ip_NodeStateType currentNodeState;  /**< @brief Current Node state */
    volatile uint32 timeoutCounter;                         /**< @brief Value of the timeout counter */
    volatile boolean timeoutCounterFlag;                    /**< @brief Timeout counter flag */
    volatile boolean baudrateEvalEnable;                    /**< @brief Baudrate Evaluation Process Enable */
    volatile uint8 fallingEdgeInterruptCount;               /**< @brief Falling Edge count of a sync byte */
    uint32 linSourceClockFreq;                              /**< @brief Frequency of the source clock for LIN */
    uint8 *classicPID;                                      /**< @brief List of PIDs use classic checksum */ 
    uint8 numOfClassicPID;                                  /**< @brief Number of PIDs use classic checksum */
} 
Lpuart_Lin_Ip_StateStructType;

/**
 * @brief User configuration structure of the LIN driver.
 * @implements Lpuart_Lin_Ip_UserConfigType_structure
 * 
 * 
 */
typedef struct {
    uint32 u32BaudRateDivisor;
    uint32 u32OverSamplingRatio;                            /**< @brief baudrate of LIN Hardware Interface to configure */
    boolean nodeFunction;                                   /**< @brief Node function as Master or Slave */
    uint8 u8BreakLength;                                    /**< @brief Length of break character will be transmitted */
    uint8 u8BreakLengthDetect;                              /**< @brief Length of break character can be detected */
    boolean autobaudEnable;                                 /**< @brief Enable Autobaud feature */
    Lpuart_Lin_Ip_GetTimerGetTimeIntervalType timerGetTimeIntervalCallback;    /**< @brief Callback function to get time interval in nanoseconds */
    uint8 *classicPID;                                      /**< @brief List of PIDs use classic checksum */ 
    uint8 numOfClassicPID;                                  /**< @brief Number of PIDs use classic checksum */
    uint8 u8WakeupByte;                                     /**< @brief Assign wakeup signal to satisfy LIN Specifications specifies that*/
    Lpuart_Lin_Ip_CallbackType Callback;                    /**< @brief Callback function to invoke after receiving a byte or transmitting a byte. */
    Lpuart_Lin_Ip_StateStructType *pStateStruct;
    uint32 u32HeaderTimeoutValue;                           /**< @brief Received header timeout converted to micro second. */
    uint32 u32ResponseTimeoutValue;                         /**< @brief Received reponse timeout converted to micro second. */
    uint32 u32ChannelClock;                                 /**< @brief Channel clock */
} Lpuart_Lin_Ip_UserConfigType;

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

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


#ifdef __cplusplus
}
#endif

/** @} */

#endif /* LPUART_LIN_IP_TYPESS_H  */
