/*
 * 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 _EIM_DRV_H_
#define _EIM_DRV_H_

/*! \brief Contains public interface to various functions related
 *         to the driver of EIM
 */

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

#include <stdint.h>
#include <stdbool.h>

/*! \addtogroup eim_drv
 *  @{
 */

#ifdef __cplusplus
extern "C" {
#endif

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

/*******************************************************************************
 * the typedefs
 ******************************************************************************/

/* Forward declaration of related register */
struct _EimRegType_;

/*! \brief The definition of EIM driver class
 */
typedef struct _EimDrvType_
{
    struct _EimRegType_ *reg; /*!< pointer to EIM register */
} EimDrvType;

/*! \brief struct of EIM Sram channel control
 */
typedef struct _EimDrv_ErrInSramType_
{
    uint8_t  data_h; /*!< Access Sram Error in data high   */
    uint32_t data_m; /*!< Access Sram Error in data middle */
    uint32_t data_l; /*!< Access Sram Error in data low    */
} EimDrv_SramType;

/*! \brief struct of EIM Config
 */
typedef struct _EimDrv_ChnCfgType_
{
    bool            globalEnable; /*!< Eim global enable status      */
    bool            chnNumStatus; /*!< Eim channel num enable status */
    EimDrv_SramType accSramCfg;   /*!< Access Sram Error in config   */
} EimDrv_ChnCfgType;

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

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

/*! \brief Initializes the EIM driver module
 *
 * This function initializes EIM driver by setting the register
 * instances to it.
 *
 * \param[in] obj : pointer to EIM driver instance
 * \param[in] eimReg : pointer to EIM register instance
 */
extern void EimDrv_Init(EimDrvType *obj, struct _EimRegType_ *eimReg);

/*! \brief Get EIM Default config paramter
 *
 * This function get EIM config paramter.
 *
 * \param[in] userConfig : pointer to default parameter
 */
extern void EimDrv_GetDefaultConfig(EimDrv_ChnCfgType *userConfig);

/*! \brief Get EIM Global Channel Enable Status
 *
 * This function get global Channel enable status.
 *
 * \param[in] obj : pointer to EIM driver instance
 */
extern bool EimDrv_GetChnGlobalEnable(EimDrvType *obj);

/*! \brief Set EIM Global Channel Enable Status
 *
 * This function set global Channel enable status.
 *
 * \param[in] obj : pointer to EIM driver instance
 * \param[in] enable :
 *             - true  : enable global channel
 *             - false : disable global channel
 *
 */
extern void EimDrv_EnableGlobalChn(EimDrvType *obj, bool enable);

/*! \brief Get EIM Channel Number Enable Status
 *
 * This function get global Channel number enable status.
 *
 * \param[in] obj : pointer to EIM driver instance
 */
extern bool EimDrv_GetChnNumEnable(EimDrvType *obj);

/*! \brief Set EIM Channel Number Enable Status
 *
 * This function set global Channel number enable status.
 *
 * \param[in] obj : pointer to EIM driver instance
 * \param[in] chnNum : select the channel set status
 * \param[in] enable :
 *             - true  : enable selected channel
 *             - false : disable selected channel
 */
extern void EimDrv_EnableChannel(EimDrvType *obj, bool enable);

/*! \brief Get Access Sram EIM Config
 *
 * This function get access sram EIM config parameter
 *
 * \param[in] obj : pointer to EIM driver instance
 * \param[in] sramType : pointer to get access sram paramter chk/data/addr
 */
extern void EimDrv_GetSramErrInStatus(EimDrvType *obj, EimDrv_SramType *sramType);

/*! \brief Set Access Sram EIM Config
 *
 * This function set access sram EIM config parameter
 *
 * \param[in] obj : pointer to EIM driver instance
 * \param[in] sramType : pointer to set access sram paramter chk/data/addr
 */
extern void EimDrv_SetSramErrInStatus(EimDrvType *obj, EimDrv_SramType *sramType);

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

/*! @}*/

#endif /* _EIM_DRV_H_ */
