/**************************************************************************//**
 * @file     gatedrv_hw.h
 * @brief    GATEDRV module high-level header file.
 * @version  VXX.XX.XX
 * @date     XX-XXX-XXXX
 *
 * @note
 * Copyright (C) 2022 Spintrol Electronic Technology (Shanghai) Co., Ltd.. All rights reserved.
 *
 * @attention
 * THIS SOFTWARE JUST PROVIDES CUSTOMERS WITH CODING INFORMATION REGARDING 
 * THEIR PRODUCTS, WHICH AIMS AT SAVING TIME FOR THEM. SPINTROL SHALL NOT BE
 * LIABLE FOR THE USE OF THE SOFTWARE. SPINTROL DOES NOT GUARANTEE THE 
 * CORRECTNESS OF THIS SOFTWARE AND RESERVES THE RIGHT TO MODIFY THE SOFTWARE 
 * WITHOUT NOTIFICATION.
 *
 ******************************************************************************/

#ifndef GATEDRV_HW_H
#define GATEDRV_HW_H

#ifdef __cplusplus
extern "C" {
#endif


#include "spc1068.h"
#include "gatedrv.h"




/**
 *  @brief GATEDRV Register Address Definition
 */
typedef enum
{
  GATEDRV_REG_GLBSTS0_ADDR                  = 0x00,   /*!< Global Status Register 0 Address                   */
  GATEDRV_REG_GLBSTS1_ADDR                  = 0x01,   /*!< Global Status Register 1 Address                   */
  GATEDRV_REG_FAULTSTS0_ADDR                = 0x02,   /*!< Fault Status Register 0 Address                    */
  GATEDRV_REG_FAULTSTS1_ADDR                = 0x03,   /*!< Fault Status Register 1 Address                    */
  GATEDRV_REG_FAULTCLR0_ADDR                = 0x04,   /*!< Fault Clear Register 0 Address                     */
  GATEDRV_REG_FAULTCLR1_ADDR                = 0x05,   /*!< Fault Clear Register 1 Address                     */
  GATEDRV_REG_FFAULTSEL0_ADDR               = 0x06,   /*!< Fatal Fault Select Register 0 Address              */
  GATEDRV_REG_FFAULTSEL1_ADDR               = 0x07,   /*!< Fatal Fault Select Register 1 Address              */
  GATEDRV_REG_GFAULTSEL0_ADDR               = 0x08,   /*!< General Fault Select Register 0 Address            */
  GATEDRV_REG_GFAULTSEL1_ADDR               = 0x09,   /*!< General Fault Select Register 1 Address            */
  GATEDRV_REG_LDOGCTL_ADDR                  = 0x0A,   /*!< Gate Driver LDO Control Register Address           */
  GATEDRV_REG_BODCTL_ADDR                   = 0x0B,   /*!< BOD Control Register Address                       */
  GATEDRV_REG_BODVDDGHVTH_ADDR              = 0x0C,   /*!< BOD for VDDG Too-High Threshold Register Address   */
  GATEDRV_REG_BODVDDGLVTH_ADDR              = 0x0D,   /*!< BOD for VDDG Too-Low Threshold Register Address    */
  GATEDRV_REG_BODPVDD0HVTH_ADDR             = 0x0E,   /*!< BOD for PVDD0 Too-High Threshold Register Address  */
  GATEDRV_REG_BODPVDD0LVTH_ADDR             = 0x0F,   /*!< BOD for PVDD0 Too-Low Threshold Register Address   */

  GATEDRV_REG_BUCKCTL0_ADDR                 = 0x11,   /*!< Buck Control Register 0 Address                    */
  GATEDRV_REG_BUCKCTL1_ADDR                 = 0x12,   /*!< Buck Control Register 1 Address                    */
  GATEDRV_REG_RCOCTL_ADDR                   = 0x13,   /*!< RCO Control Register Address                       */

  GATEDRV_REG_CPCTL_ADDR                    = 0x18,   /*!< Charge-Pump Control Register Address               */

  GATEDRV_REG_PREDRVCTL0_ADDR               = 0x1C,   /*!< Pre-Driver Control Register 0 Address              */
  GATEDRV_REG_PREDRVCTL1_ADDR               = 0x1D,   /*!< Pre-Driver Control Register 1 Address              */
} GATEDRV_REG_ADDR;




/**
 *  @brief  GATEDRV Charge Pump Frequency Definition
 */
typedef enum
{
  GATEDRV_CP_FREQUENCY_1250KHZ              =  0,     /*!< GATEDRV Charge Pump Freuecncy = 1250 KHz */
  GATEDRV_CP_FREQUENCY_625KHZ               =  1,     /*!< GATEDRV Charge Pump Freuecncy = 625 KHz  */
  GATEDRV_CP_FREQUENCY_313KHZ               =  2,     /*!< GATEDRV Charge Pump Freuecncy = 313 KHz  */
  GATEDRV_CP_FREQUENCY_156KHZ               =  3,     /*!< GATEDRV Charge Pump Freuecncy = 156 KHz  */
} GATEDRV_CP_FrequecnyEnum;




/**
 *  @brief  GATEDRV VDDG Voltage Definition
 */
typedef enum
{
  GATEDRV_VDDG_VOLTAGE_9V                   =  2,     /*!< GATEDRV VDDG Voltage =  9 V  */
  GATEDRV_VDDG_VOLTAGE_10V                  =  3,     /*!< GATEDRV VDDG Voltage = 10 V  */
  GATEDRV_VDDG_VOLTAGE_12V                  =  4,     /*!< GATEDRV VDDG Voltage = 12 V  */
  GATEDRV_VDDG_VOLTAGE_15V                  =  5,     /*!< GATEDRV VDDG Voltage = 15 V  */
  GATEDRV_VDDG_VOLTAGE_18V                  =  6,     /*!< GATEDRV VDDG Voltage = 18 V  */
} GATEDRV_VDDG_VoltageEnum;




/**
 *  @brief  GATEDRV VDDG BOD Threshold Definition
 */
typedef enum
{
  GATEDRV_VDDG_BOD_THRESHOLD_1DOT6_V        =  0,     /*!< GATEDRV VDDG Voltage Threshold   1.6 V   */
  GATEDRV_VDDG_BOD_THRESHOLD_3DOT2_V        =  1,     /*!< GATEDRV VDDG Voltage Threshold   3.2 V   */
  GATEDRV_VDDG_BOD_THRESHOLD_6DOT4_V        =  2,     /*!< GATEDRV VDDG Voltage Threshold   6.4 V   */
  GATEDRV_VDDG_BOD_THRESHOLD_4DOT8_V        =  3,     /*!< GATEDRV VDDG Voltage Threshold   4.8 V   */
  GATEDRV_VDDG_BOD_THRESHOLD_8DOT0_V        =  4,     /*!< GATEDRV VDDG Voltage Threshold   8.0 V   */
  GATEDRV_VDDG_BOD_THRESHOLD_9DOT6_V        =  5,     /*!< GATEDRV VDDG Voltage Threshold   9.6 V   */
  GATEDRV_VDDG_BOD_THRESHOLD_11DOT2_V       =  6,     /*!< GATEDRV VDDG Voltage Threshold  11.2 V   */
  GATEDRV_VDDG_BOD_THRESHOLD_12DOT8_V       =  7,     /*!< GATEDRV VDDG Voltage Threshold  12.8 V   */
  GATEDRV_VDDG_BOD_THRESHOLD_14DOT4_V       =  8,     /*!< GATEDRV VDDG Voltage Threshold  14.4 V   */
  GATEDRV_VDDG_BOD_THRESHOLD_16DOT0_V       =  9,     /*!< GATEDRV VDDG Voltage Threshold  16.0 V   */
  GATEDRV_VDDG_BOD_THRESHOLD_17DOT6_V       = 10,     /*!< GATEDRV VDDG Voltage Threshold  17.6 V   */
  GATEDRV_VDDG_BOD_THRESHOLD_19DOT2_V       = 11,     /*!< GATEDRV VDDG Voltage Threshold  19.2 V   */
  GATEDRV_VDDG_BOD_THRESHOLD_20DOT8_V       = 12,     /*!< GATEDRV VDDG Voltage Threshold  20.8 V   */
  GATEDRV_VDDG_BOD_THRESHOLD_22DOT4_V       = 13,     /*!< GATEDRV VDDG Voltage Threshold  22.4 V   */
  GATEDRV_VDDG_BOD_THRESHOLD_24DOT0_V       = 14,     /*!< GATEDRV VDDG Voltage Threshold  24.0 V   */
  GATEDRV_VDDG_BOD_THRESHOLD_25DOT6_V       = 15,     /*!< GATEDRV VDDG Voltage Threshold  25.6 V   */
} GATEDRV_VDDG_BODThresholdEnum;




/**
 *  @brief  GATEDRV PVDD0 BOD Threshold Definition
 */
typedef enum
{
  GATEDRV_PVDD0_BOD_THRESHOLD_4DOT8_V       =  0,     /*!< GATEDRV PVDD0 Voltage Threshold   4.8 V  */
  GATEDRV_PVDD0_BOD_THRESHOLD_9DOT6_V       =  1,     /*!< GATEDRV PVDD0 Voltage Threshold   9.6 V  */
  GATEDRV_PVDD0_BOD_THRESHOLD_14DOT4_V      =  2,     /*!< GATEDRV PVDD0 Voltage Threshold  14.4 V  */
  GATEDRV_PVDD0_BOD_THRESHOLD_19DOT2_V      =  3,     /*!< GATEDRV PVDD0 Voltage Threshold  19.2 V  */
  GATEDRV_PVDD0_BOD_THRESHOLD_24DOT0_V      =  4,     /*!< GATEDRV PVDD0 Voltage Threshold  24.0 V  */
  GATEDRV_PVDD0_BOD_THRESHOLD_28DOT8_V      =  5,     /*!< GATEDRV PVDD0 Voltage Threshold  28.8 V  */
  GATEDRV_PVDD0_BOD_THRESHOLD_33DOT6_V      =  6,     /*!< GATEDRV PVDD0 Voltage Threshold  33.6 V  */
  GATEDRV_PVDD0_BOD_THRESHOLD_38DOT4_V      =  7,     /*!< GATEDRV PVDD0 Voltage Threshold  38.4 V  */
  GATEDRV_PVDD0_BOD_THRESHOLD_43DOT2_V      =  8,     /*!< GATEDRV PVDD0 Voltage Threshold  43.2 V  */
  GATEDRV_PVDD0_BOD_THRESHOLD_48DOT0_V      =  9,     /*!< GATEDRV PVDD0 Voltage Threshold  48.0 V  */
  GATEDRV_PVDD0_BOD_THRESHOLD_52DOT8_V      = 10,     /*!< GATEDRV PVDD0 Voltage Threshold  52.8 V  */
  GATEDRV_PVDD0_BOD_THRESHOLD_57DOT6_V      = 11,     /*!< GATEDRV PVDD0 Voltage Threshold  57.6 V  */
  GATEDRV_PVDD0_BOD_THRESHOLD_62DOT4_V      = 12,     /*!< GATEDRV PVDD0 Voltage Threshold  62.4 V  */
  GATEDRV_PVDD0_BOD_THRESHOLD_67DOT2_V      = 13,     /*!< GATEDRV PVDD0 Voltage Threshold  67.2 V  */
  GATEDRV_PVDD0_BOD_THRESHOLD_72DOT0_V      = 14,     /*!< GATEDRV PVDD0 Voltage Threshold  72.0 V  */
  GATEDRV_PVDD0_BOD_THRESHOLD_76DOT8_V      = 15,     /*!< GATEDRV PVDD0 Voltage Threshold  76.8 V  */
} GATEDRV_PVDD0_BODThresholdEnum;




/**
 *  @brief  GATEDRV Over Temperature Threshold Definition
 */
typedef enum
{
  GATEDRV_TEMPERATURE_THRESHOLD_146         =  0,     /*!< GATEDRV Temperature Threshold  146 Degree */
  GATEDRV_TEMPERATURE_THRESHOLD_138         =  1,     /*!< GATEDRV Temperature Threshold  138 Degree */
  GATEDRV_TEMPERATURE_THRESHOLD_131         =  2,     /*!< GATEDRV Temperature Threshold  131 Degree */
  GATEDRV_TEMPERATURE_THRESHOLD_122         =  3,     /*!< GATEDRV Temperature Threshold  122 Degree */
  GATEDRV_TEMPERATURE_THRESHOLD_114         =  4,     /*!< GATEDRV Temperature Threshold  114 Degree */
  GATEDRV_TEMPERATURE_THRESHOLD_107         =  5,     /*!< GATEDRV Temperature Threshold  107 Degree */
  GATEDRV_TEMPERATURE_THRESHOLD_99          =  6,     /*!< GATEDRV Temperature Threshold   99 Degree */
} GATEDRV_TemperatureThresholdEnum;




/**
 *  @brief  GATEDRV Pre-Driver Slew Rate Definition
 */
typedef enum
{
  GATEDRV_PREDRIVER_SLEW_RATE_1A            =  0,     /*!< Pre-Driver driving capability set to 1A  */
  GATEDRV_PREDRIVER_SLEW_RATE_2A            =  1,     /*!< Pre-Driver driving capability set to 2A  */
} GATEDRV_SlewRateEnum;




/**
 *  @brief  GATEDRV Fault Flag definition
 */
typedef enum
{
  GATEDRV_FAULT_FLAG_LDO_VOLTAGE_TOO_LOW     = (0x1 <<  0),      /*!< GATEDRV Fault Flag LDO Voltage too Low         */
  GATEDRV_FAULT_FLAG_LDO_VOLTAGE_TOO_HIGH    = (0x1 <<  1),      /*!< GATEDRV Fault Flag LDO Voltage too High        */
  GATEDRV_FAULT_FLAG_LOW_SIDE_FET0_OC        = (0x1 <<  2),      /*!< GATEDRV Fault Flag Low side FET0 OC            */
  GATEDRV_FAULT_FLAG_LOW_SIDE_FET1_OC        = (0x1 <<  3),      /*!< GATEDRV Fault Flag Low side FET1 OC            */
  GATEDRV_FAULT_FLAG_LOW_SIDE_FET2_OC        = (0x1 <<  4),      /*!< GATEDRV Fault Flag Low side FET2 OC            */
  GATEDRV_FAULT_FLAG_HIGH_SIDE_FET0_OC       = (0x1 <<  5),      /*!< GATEDRV Fault Flag High side FET0 OC           */
  GATEDRV_FAULT_FLAG_HIGH_SIDE_FET1_OC       = (0x1 <<  6),      /*!< GATEDRV Fault Flag High side FET1 OC           */
  GATEDRV_FAULT_FLAG_HIGH_SIDE_FET2_OC       = (0x1 <<  7),      /*!< GATEDRV Fault Flag High side FET2 OC           */
  GATEDRV_FAULT_FLAG_BUCK_OT_SHUTDOWN        = (0x1 <<  8),      /*!< GATEDRV Fault Flag BUCK OT shutdown            */
  GATEDRV_FAULT_FLAG_BUCK_OT_WARNING         = (0x1 <<  9),      /*!< GATEDRV Fault Flag BUCK OT WARNING             */
  GATEDRV_FAULT_FLAG_PREDRIVER_OT_SHUTDOWN   = (0x1 << 10),      /*!< GATEDRV Fault Flag PREDRIVER OT shutdown       */
  GATEDRV_FAULT_FLAG_PREDRIVER_OT_WARNING    = (0x1 << 11),      /*!< GATEDRV Fault Flag PREDRIVER OT WARNING        */
  GATEDRV_FAULT_FLAG_PVDD1_VOLTAGE_TOO_LOW   = (0x1 << 12),      /*!< GATEDRV Fault Flag PVDD1 Voltage too Low       */
  GATEDRV_FAULT_FLAG_PVDD1_VOLTAGE_TOO_HIGH  = (0x1 << 13),      /*!< GATEDRV Fault Flag PVDD1 Voltage too High      */
  GATEDRV_FAULT_FLAG_PVDD0_VOLTAGE_TOO_LOW   = (0x1 << 14),      /*!< GATEDRV Fault Flag PVDD0 Voltage too Low       */
  GATEDRV_FAULT_FLAG_PVDD0_VOLTAGE_TOO_HIGH  = (0x1 << 15),      /*!< GATEDRV Fault Flag PVDD0 Voltage too High      */
  GATEDRV_FAULT_FLAG_ALL                     = 0xFFFF,           /*!< GATEDRV Fault Flag All                         */
} GATEDRV_FaultFlagEnum;




/**
 *  @brief GATEDRV High Level Public Function Declaration
 */
void GATEDRV_EnableGate(void);
void GATEDRV_DisableGate(void);

ErrorStatus GATEDRV_EnableFatalFault(uint16_t u16EnableFlags, uint16_t *pu16ResultFlags);
ErrorStatus GATEDRV_DisableFatalFault(uint16_t u16DisableFlags, uint16_t *pu16ResultFlags);
ErrorStatus GATEDRV_EnableGeneralFault(uint16_t u16EnableFlags, uint16_t *pu16ResultFlags);
ErrorStatus GATEDRV_DisableGeneralFault(uint16_t u16DisableFlags, uint16_t *pu16ResultFlags);
ErrorStatus GATEDRV_GetFaultFlag(uint32_t *pu32ResultFlags);
ErrorStatus GATEDRV_ClearFaultFlag(uint16_t u16ClearFlags);

ErrorStatus GATEDRV_SetVDDG(GATEDRV_VDDG_VoltageEnum eVDDGVal);
ErrorStatus GATEDRV_SetChargePumpFrequency(GATEDRV_CP_FrequecnyEnum eCPFreqVal);

ErrorStatus GATEDRV_EnableVDDGBOD(void);
ErrorStatus GATEDRV_DisableVDDGBOD(void);

ErrorStatus GATEDRV_EnablePVDD0BOD(void);
ErrorStatus GATEDRV_DisablePVDD0BOD(void);

ErrorStatus GATEDRV_SetVDDGTooHighTriggerThreshold(GATEDRV_VDDG_BODThresholdEnum eBODTriggerVal);
ErrorStatus GATEDRV_SetVDDGTooHighReleaseThreshold(GATEDRV_VDDG_BODThresholdEnum eBODTriggerVal);
ErrorStatus GATEDRV_SetVDDGTooLowTriggerThreshold(GATEDRV_VDDG_BODThresholdEnum eBODTriggerVal);
ErrorStatus GATEDRV_SetVDDGTooLowReleaseThreshold(GATEDRV_VDDG_BODThresholdEnum eBODTriggerVal);

ErrorStatus GATEDRV_SetPVDD0TooHighTriggerThreshold(GATEDRV_PVDD0_BODThresholdEnum eBODTriggerVal);
ErrorStatus GATEDRV_SetPVDD0TooHighReleaseThreshold(GATEDRV_PVDD0_BODThresholdEnum eBODTriggerVal);
ErrorStatus GATEDRV_SetPVDD0TooLowTriggerThreshold(GATEDRV_PVDD0_BODThresholdEnum eBODTriggerVal);
ErrorStatus GATEDRV_SetPVDD0TooLowReleaseThreshold(GATEDRV_PVDD0_BODThresholdEnum eBODTriggerVal);

ErrorStatus GATEDRV_SetPreDriverOverTemperatureThreshold(GATEDRV_TemperatureThresholdEnum eTempratureVal);
ErrorStatus GATEDRV_SetBuckOverTemperatureThreshold(GATEDRV_TemperatureThresholdEnum eTempratureVal);

ErrorStatus GATEDRV_EnableBuck(void);
ErrorStatus GATEDRV_DisableBuck(void);

ErrorStatus GATEDRV_EnableBuckForcePWM(void);
ErrorStatus GATEDRV_DisableBuckForcePWM(void);

ErrorStatus GATEDRV_EnablePreDriverOutput(void);
ErrorStatus GATEDRV_DisablePreDriverOutput(void);

ErrorStatus GATEDRV_SetPreDriverSlewRate(GATEDRV_SlewRateEnum eSlewRate);




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

#endif /* GATEDRV_HW_H */


/******************* Copyright (C) 2022 Spintrol Electronic Technology (Shanghai) Co., Ltd. ***** END OF FILE ****/
