/*******************************************************
 * InterLeaveLL_SR_Product.h
 *
 *  Created on: 2023Äê4ÔÂ28ÈÕ
 *      Author: yangch
 *******************************************************/

#ifndef SOURCE_INTERLEAVELL_SR_PRODUCT_H_
#define SOURCE_INTERLEAVELL_SR_PRODUCT_H_

#define ILLLC_sr_enable                             1
#define ILLLC_FB_DB_HS_US                           ((float32_t)(0.25f))
#define ILLLC_FB_DB_LS_US                           ((float32_t)(0.25f))
#define ILLLC_PWMSYSCLOCK_FREQ_HZ                   ((float32_t)(120000000.0))





//CTRL interrupt
#define TMR0_FUNC_CMPB_Vaule                        (599) //frequency / 2 / 100K -1


//Fault define
#define Fault_HW_OVP                          ((uint32_t)(0x1L))
#define Fault_SW_OVP                          ((uint32_t)(0x2L))
#define Fault_CMPSS_OVP                       ((uint32_t)(0x4L))
#define Fault_RSV_OVP                         ((uint32_t)(0x8L)) //TBD

#define Fault_HW_UVP                          ((uint32_t)(0x10L))
#define Fault_SW_UVP                          ((uint32_t)(0x20L))
#define Fault_CMPSS_UVP                       ((uint32_t)(0x40L)) //TBD
#define Fault_RSV_UVP                         ((uint32_t)(0x80L)) //TBD

#define Fault_HW_OCP                          ((uint32_t)(0x100L))
#define Fault_SW_OCP                          ((uint32_t)(0x200L))
#define Fault_CMPSS_OCP                       ((uint32_t)(0x400L))
#define Fault_RSV_OCP                         ((uint32_t)(0x800L)) //TBD

#define Fault_PRICURR1_HW_OCP                 ((uint32_t)(0x1000L))
#define Fault_PRICURR1_SW_OCP                 ((uint32_t)(0x2000L))
#define Fault_PRICURR1_CMPSS_OCP              ((uint32_t)(0x4000L))
#define Fault_PRICURR1_RSV_OCP                ((uint32_t)(0x8000L)) //TBD

#define Fault_PRICURR2_HW_OCP                 ((uint32_t)(0x10000L))
#define Fault_PRICURR2_SW_OCP                 ((uint32_t)(0x20000L))
#define Fault_PRICURR2_CMPSS_OCP              ((uint32_t)(0x40000L))
#define Fault_PRICURR2_RSV_OCP                ((uint32_t)(0x80000L)) //TBD

#define Fault_VIN_SW_OVP                      ((uint32_t)(0x100000L))
#define Fault_VIN_SW_UVP                      ((uint32_t)(0x200000L))
#define Fault_TEMP1_OTP                       ((uint32_t)(0x400000L))
#define Fault_TEMP2_OTP                       ((uint32_t)(0x800000L)) //TBD

#define Fault_MASK                            ((uint32_t)(0x00FFFFFFL)) //TBD

//protect and restore value
#define VOUT_OVP_VALUE                        ((int32_t)(60.0f*2048))
#define VOUT_UVP_VALUE                        ((int32_t)(40.0f*2048))
#define IOUT_OCP_VALUE                        ((int32_t)(85.0f*2048))

#define VIN_OVP_VALUE                         ((int32_t)(440.0f*2048))
#define VIN_OVP_RECOVER_VALUE                 ((int32_t)(420.0f*2048))
#define VIN_UVP_VALUE                         ((int32_t)(320.0f*2048))
#define VIN_UVP_RECOVER_VALUE                 ((int32_t)(340.0f*2048))

#define TEMP1_OTP_VALUE                       ((int16_t)(2137))//TODO
#define TEMP1_OTP_RECOVER_VALUE               ((int16_t)(1913))//TODO
#define TEMP2_OTP_VALUE                       ((int16_t)(2137))//TODO
#define TEMP2_OTP_RECOVER_VALUE               ((int16_t)(1913))//TODO

//Fan control
#define FAN_STOP_VALUE                        ((int16_t)(25))//TODO 
#define FAN_SPEED1_VALUE                      ((int16_t)(35))//TODO 
#define FAN_SPEED2_VALUE                      ((int16_t)(45))//TODO 
#define FAN_SPEED3_VALUE                      ((int16_t)(50))//TODO 
#define FAN_SPEED4_VALUE                      ((int16_t)(55))//TODO 

//protect times
#define VOUT_OVP_TIMES                        (20)
#define VOUT_UVP_TIMES                        (20)
#define IOUT_OCP_TIMES                        (20)
#define VIN_OVP_TIMES                         (20)
#define VIN_OVP_RECOVER_TIMES                 (20)
#define VIN_UVP_TIMES                         (20)
#define VIN_UVP_RECOVER_TIMES                 (20)
#define TEMP1_OTP_TIMES                       (100)
#define TEMP1_OTP_RECOVER_TIMES               (100)
#define TEMP2_OTP_TIMES                       (100)
#define TEMP2_OTP_RECOVER_TIMES               (100)


#define VOUT_1V_ADC                           (64)
#define IOUT_1A_ADC                           (31)

#define  CONSTVoutScaleQ11                    ((int32_t)(31))   //0.017725
#define  CONSTIoutScaleQ11                    ((int32_t)(47))  //
#define  CONSTIoutOffsetQ11                   ((int32_t)(0))    //
#define  CONSTVinScaleQ11                     ((int32_t)(244))  //
#define  CONSTPriCurr1ScaleQ11                ((int32_t)(13))   //TODO
#define  CONSTPriCurr2ScaleQ11                ((int32_t)(13))   //TODO
/************controller configuration**************************************/
//
//#define VoutLPFCoff_A_Q16                       ((int32_t)(58982))//((int32_t)(41177))//((int32_t)(20588)) //5KHZ
//#define VoutLPFCoff_B_Q16                       ((int32_t)(6553))//((int32_t)(24358))//((int32_t)(44947)) //

//#define IoutLPFCoff_A_Q16                       ((int32_t)(41177))//((int32_t)(20588))//((int32_t)(20588)) //5KHZ
//#define IoutLPFCoff_B_Q16                       ((int32_t)(24358))//((int32_t)(44947))//((int32_t)(44947)) //

//#define VinLPFCoff_A_Q16                        ((int32_t)(5147))//((int32_t)(20588)) //5KHZ
//#define VinLPFCoff_B_Q16                        ((int32_t)(60388))//((int32_t)(44947)) //

//#define PriCurrLPFCoff_A_Q16                    ((int32_t)(5147)) //5KHZ
//#define PriCurrLPFCoff_B_Q16                    ((int32_t)(60388)) //

//#define PriCurrCtrlCoff_A_Q16                   ((int32_t)(2)) //IQ16(0.001)
//#define CTRL_KP_GAIN_Q16                        ((int32_t)(1658))//IQ16(0.0253)
//#define CTRL_KP_OFFSENT_Q16                     ((int32_t)(-2795635))//IQ16(-42.158)

//#define VOLTAGE_MAX_ERROR                       ((int32_t)(320))   //5V
//#define VOLTAGE_MIN_ERROR                       ((int32_t)(-320))  //-5V

//#define CURRENT_MAX_ERROR                       ((int32_t)(205))   //10A
//#define CURRENT_MIN_ERROR                       ((int32_t)(-205))  //-10A

//#define BURST_ENABLE_VALUE                      ((int32_t)(200))
//#define SR_CURR_ENABLE_VALUE                    ((int32_t)(814))  //18.75A@30%
//#define SR_CURR_DISABLE_VALUE                   ((int32_t)(678))  //15.625A@25%

//#define VLOOP_CTRL_MAX                          (96000)             //80KHZ
//#define VLOOP_CTRL_MIN                          (21942)//(25600)             //300KHZ
//#define ILOOP_CTRL_MAX                          (96000)             //80KHZ
//#define ILOOP_CTRL_MIN                          (21942)//(25600)             //300KHZ
//#define FRE_CTRL_MAX                            (96000)             //80KHZ
//#define BURST_CTRL_VALUE                        (25600)//(30720)             //250KHZ    
//#define RESANANT_FRE                            ((int32_t)(56888))   //135KHZ
//#define SR_TIME_LEFT_RESANT                     ((int32_t)(25367))   //resanant time - 400ns
//#define SR_TIME_RIGHT_RESANT                    ((int32_t)(2308))    //300ns


//#define UINTx_DT_UP_MIN                         (2307L) //(1923L)     //250ns
//#define UINTx_DT_DOWN_MIN                       (2307L)//(1923L)     //250ns
//#define UINTx_DT_UP_MAX                         (2307L)//(1923L)     //500ns
//#define UINTx_DT_DOWN_MAX                       (2307L)//(1923L)     //500ns



//#define PriCurrCtrlMAX                          ((int32_t)(26214))    //0.25
//#define PriCurrCtrlMIN                          ((int32_t)(-26214))   //-0.25
//#define DelatPhaseMAX                           ((int32_t)(11538))    //1.5us

//#define CURRENT_SET_MAX_Q0                      ((int32_t)(2802))  //((int32_t)(3080))     //
//#define CURRENT_SET_MIN_Q0                      ((int32_t)(559))


////output voltage limit current
#define CURR_LIMIT_K_Q11                        ((int32_t)(0.515503876f * 2048))
#define CURR_LIMIT_B_Q0                         ((int32_t)(640))

//HW FAULT flag
#define USER_XBAR_INPUT_FLG_INPUT1          (0x0001)
#define USER_XBAR_INPUT_FLG_INPUT2          (0x0002)
#define USER_XBAR_INPUT_FLG_INPUT3          (0x0004)
#define USER_XBAR_INPUT_FLG_INPUT4          (0x0008)
#define USER_XBAR_INPUT_FLG_INPUT5          (0x0010)

#define USER_XBAR_INPUT_FLG_CMPSS1_CTRIPH   (0x0002)
#define USER_XBAR_INPUT_FLG_CMPSS2_CTRIPH   (0x0004)
#define USER_XBAR_INPUT_FLG_CMPSS3_CTRIPH   (0x0010)
#define USER_XBAR_INPUT_FLG_CMPSS4_CTRIPH   (0x0040)


//POWER ON TIME
#define POWERON_CHECK_ENABLE_TIME_100MS    (100)
#define POWERON_CHECK_DISABLE_TIME_20MS    (20)
#define POWERON_DELAY_TIME_50MS            (50)
#define POWERON_ENABLE_VOLT                ((int32_t)(120 * 2048))
#define POWERON_DISABLE_VOLT               ((int32_t)(100 * 2048))


#endif /* SOURCE_INTERLEAVELL_SR_PRODUCT_H_ */
