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

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

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

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

/*! \addtogroup fhu_drv
 *  @{
 */

#ifdef __cplusplus
extern "C" {
#endif

/*******************************************************************************
 * the defines
 ******************************************************************************/
#define FHUDRV_USER_KEY_UNLOCK             (0x97D356BA)

/*******************************************************************************
 * the typedefs
 ******************************************************************************/
typedef enum
{
    FHUDRV_CHNID_AD_LVD         = 0x0U, /*!< fault channel low voltage detection     */
    FHUDRV_CHNID_AD_LVW         = 0x1U, /*!< fault channel low voltage warning       */ 
    FHUDRV_CHNID_AD_FLDO_RDY    = 0x2U, /*!< fault channel Flash LDO ready           */
    FHUDRV_CHNID_AD_FLDO_LVD    = 0x3U, /*!< fault channel Flash LDO Low voltage     */
    FHUDRV_CHNID_AD_OTP         = 0x4U, /*!< fault channel Flash LDO over tempreture */
    FHUDRV_CHNID_SRAM_SEC       = 0x5U, /*!< fault channel sram single bit error     */
    FHUDRV_CHNID_SRAM_DED       = 0x6U, /*!< fault channel sram multi bits error     */
    FHUDRV_CHNID_FLS_SEC        = 0x7U, /*!< fault channel falsh single bit error    */
    FHUDRV_CHNID_FLS_DED        = 0x8U, /*!< fault channel falsh multi bits error    */
    FHUDRV_CHNID_NUM            = 0x9U
}FhuDrv_ChnIdType;

typedef struct _FhuDrv_ConfigType_
{
    uint16_t chnEn; /*!< fault channel enable config     */
    uint16_t irqEn; /*!< fault channel interrupt config  */
    uint16_t rstEn; /*!< fault channel reset config      */
    uint16_t nmiEn; /*!< fault channel NMI config        */
}FhuDrv_ConfigType;

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

/*! \brief The definition of FHU driver class
 */
typedef struct _FhuDrvType_
{
    struct _FhuRegType_ *reg; /*!< pointer to FHU register */
} FhuDrvType;

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

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

/*! \brief Initializes the FHU driver module
 *
 * This function initializes FHU driver by setting the register
 * instances to it.
 *
 * \param[in] obj : pointer to FHU driver instance
 * \param[in] fhuReg : pointer to FHU register instance
 */
extern void FhuDrv_Init(FhuDrvType *obj, struct _FhuRegType_ *fhuReg);

/*! \brief Get FHU Module default config
 *
 * This function Get FHU default config from registers.
 *
 * \param[in] *cfg : pointer to get FHU register default value
 */
extern void FhuDrv_GetDefaultConfig(FhuDrv_ConfigType *cfg);

/*! \brief Get FHU user lock status
 *
 * This function get FHU user lock status
 *
 * \param[in] obj : pointer to FHU driver instance
 */
extern bool FhuDrv_GetUserLockSts(FhuDrvType *obj);

/*! \brief Set FHU initial config
 *
 * This function FHU initial user config
 *
 * \param[in] obj : pointer to FHU driver instance
 * \param[in] *cfg : pointer to set FHU register default value
 */
extern void FhuDrv_Config(FhuDrvType *obj, const FhuDrv_ConfigType *cfg);

/*! \brief Get FHU channel status
 *
 * This function Get FHU channel status
 *
 * \param[in] obj : pointer to FHU driver instance
 */
extern uint16_t FhuDrv_GetChnSts(FhuDrvType *obj);

/*! \brief clear FHU channel error status
 *
 * This function clear FHU channel error in status
 *
 * \param[in] obj : pointer to FHU driver instance
 * \param[in] clrValue : corresponding bit set 1 to clear
 *                       corresponding bit set 0 to reserve
 */
extern void FhuDrv_ClearChnSts(FhuDrvType *obj, uint16_t clrValue);

/*! \brief get FHU analog channel error status
 *
 * This function get FHU analog channel error in status
 * for real time.
 *
 * \param[in] obj : pointer to FHU driver instance
 */
extern uint8_t FhuDrv_AnalogRealTimeChnSts(FhuDrvType *obj);

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

/*! @}*/

#endif /* _FHU_DRV_H_ */

