/*
 * Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
 * All rights reserved.
 *
 * Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
 * exclusively with CVA's microcontroller products. This file can be freely
 * distributed within development tools that are supporting such microcontroller
 * products.
 *
 * THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED
 * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
 * CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
 * OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
 */

#ifndef _LIN_COM_H_
#define _LIN_COM_H_

/*! \brief his file exports Lin communication
 *
 */

/*******************************************************************************
 * the includes
 ******************************************************************************/

#include <stdint.h>
#include <stdbool.h>
#include "lin_type.h"
#include "lin_cfg.h"

/*! \addtogroup lin_com
 *  @{
 */

#ifdef __cplusplus
extern "C" {
#endif

/*******************************************************************************
 * the defines
 ******************************************************************************/

/*******************************************************************************
 * the typedefs
 ******************************************************************************/
typedef struct
{
    Lin_FrameDataType *pCurrentFrameData;
    uint32_t          counter;
} LinCom_FrameInfoType;

/*******************************************************************************
 * the globals
 ******************************************************************************/


/*******************************************************************************
 * the function prototypes
 ******************************************************************************/

/*! \brief Initialize the communication module
 *
 * This function execute to initialize the communication module
 *
 * \param[in] dataBufferPtr: the data buffer which be stored in upper layer
 * \param[in] frameNum: the total frame num in the upper layer be used
 * \return: void
 */
extern void LinCom_Init(Lin_FrameDataType *dataBufferPtr, uint8_t frameNum);

/*! \brief Get the link data buffer pointer according to pid index
 *
 * This function execute to initialize the communication module
 *
 * \param[in] pidIdx: frame index
 * \param[in] dataBufferPtr: the data buffer which be stored in upper layer
 * \return: void
 */
extern Lin_FrameDataType *LinCom_GetFramePointer(uint8_t pidIdx);

/*! \brief Update the tx signal
 *
 * This function execute to update the tx signal from local to lower lay frame buffer
 *
 * \param[in] pidIdx: pid index
 * \return: void
 */
extern void linCom_BusTxSignalUpdate(uint8_t pidIdx);

/*! \brief Update the rx signal
 *
 * This function execute to update the received data from lower layer frame buffer to local
 *
 * \param[in] channelIdx: which physical channel is used
 * \param[in] pidIdx: pid index
 * \return: void
 */
extern void linCom_BusRxSignalUpdate(uint8_t channelIdx, uint8_t pidIdx);

/*! \brief Process the local signal of tx or rx
 *
 * This function execute to update local tx to lower frame buffer or update rx from lower to rx local
 *
 * \param[in] channelIdx: which physical channel is used
 * \return: void
 */
extern void LinCom_MainFunction(uint8_t channelIdx);


#ifdef __cplusplus
}
#endif /* extern "C" */

/*! @}*/

#endif /* _LIN_COM_H_ */
