#ifndef __PROTECT_H
#define __PROTECT_H 

#ifdef __cplusplus
extern "C" {
#endif

/////constant///////////
#include "hc32_ll.h"
/////////////////////////
#define GRID_VOLRMS_MAX_THRESHOLD     220.0f*1.2f
#define GRID_VOLRMS_MIN_THRESHOLD     220.0f*0.8f
#define GRID_VOLINSTANT_MAX_THRESHOLD 311.0f*1.2f
#define FAULT_FILTER_TIMES            3
#define GRID_CURINSTANT_MAX_THRESHOLD 4.0f
#define PVCUR_MAX_THRESHOLD           40.0f
#define PVVOL_MAX_THRESHOLD           60.0f
#define PVVOL_MIN_THRESHOLD           28.0f
////////////////////////

struct MICROINV_PRO_BITS {
  uint16_t Grid_OVP_SW:1;
  uint16_t Grid_OCP_SW:1;
	uint16_t Grid_RMS_OVP_SW:1;
  uint16_t Grid_RMS_UVP_SW:1;
	
  uint16_t PVVOL_OVP_SW:1;
	uint16_t PVVOL_UVP_SW:1;
	uint16_t PLL_ERROR: 1;
	uint16_t PVCur_OCP_SW: 1;
	
	uint16_t FB_OCP1_HW:1;
  uint16_t FB_OCP2_HW:1;
	uint16_t IACL_OCP_HW:1;
	uint16_t IACR_OCP_HW:1;

	uint16_t VBUS_OVP_HW:1;
	uint16_t reserved: 3;
};

union MICROINV_Pro {
    uint16_t  all;
    struct  MICROINV_PRO_BITS  bit;
};

/////////////////////////variable
extern union MICROINV_Pro MicroInv_Fault_Flag;
extern uint8_t System_Fault_CLR_cmd;
/////////////////////////////////////////////////
extern void MicroInv_Protect(void);
/////////////////////////////////////////////////

#ifdef __cplusplus
}
#endif

#endif /* __MAIN_H */
