/****************************************************************************
* 文件名: hrtimer.h
* 内容简述: HRTIMER 驱动代码	
* 文件历史:
* 版本号	日期	作者	说明
*
*/

#ifndef __HRTIMER_H
#define __HRTIMER_H 	

/* Includes ------------------------------------------------------------------*/
#include "main.h"
//#include "hc32_ll_def.h"
//#include "hc32f3xx.h"
//#include "hc32f3xx_conf.h"
#include "hc32_ll_gpio.h"
#include "Hrtim_debug.h"

//#define HRPWM_SSTAIDLR   (*((volatile unsigned long *)(0x4003C000 + 0x03A0)))
//#define HRPWM_SSTARUNR1  (*((volatile unsigned long *)(0x4003C000 + 0x03A4)))//(uint32_t *)(0x4003C000 + 0x03A4);
//#define HRPWM_SSTARUNR2  (*((volatile unsigned long *)(0x4003C000 + 0x03A8)))//(uint32_t *)(0x4003C000 + 0x03A8);
//#define HRPWM_SSTADIDLR  (*((volatile unsigned long *)(0x4003C000 + 0x03AC)))//(uint32_t *)(0x4003C000 + 0x03AC);

#define DEBUG_MODE_NOR             0
#define DEBUG_MODE_HWSYC_SCMPB     1
#define DEBUG_MODE_HWSYC_CMPA      2
#define DEBUG_MODE_HWSYC_CMPB      3
#define DEBUG_MODE_HW_RUN          4
#define DEBUG_MODE_OUTPUT_SWAP     5
#define DEBUG_MODE_OUTPUT_HALF     6
#define DEBUG_MODE_HWUPDATE        7   //HW update
#define DEBUG_MODE_HW_CLAER        8   //HW clear
#define DEBUG_MODE_SELECT         (DEBUG_MODE_NOR)


#define HRPWM_UNIT_1                      (CM_HRPWM1)
#define HRPWM_UNIT_2                      (CM_HRPWM2)
#define HRPWM_UNIT_3                      (CM_HRPWM3)
#define HRPWM_UNIT_4                      (CM_HRPWM4)
#define HRPWM_UNIT_5                      (CM_HRPWM5)
#define HRPWM_UNIT_6                      (CM_HRPWM6)





#define CMP_A_VALUE                     (0x2000UL)
#define CMP_B_VALUE                     (0x4000UL + 64UL)
//#define DEADTIME_VALUE                  (256) 
#define  PHSCMP2_VALUE                  ((PERIOD_VALUE>>2)+64)
#define  ADC_START_VALUE                ((PERIOD_VALUE>>1)-1500)
#define  PWM_0_8uS                        (2048)
#define  PWM_0_4uS                        (1024)

#define HRPWM_1A_PIN                    (GPIO_HRPWM1_PWMA)
#define HRPWM_1B_PIN                    (GPIO_HRPWM1_PWMB)
#define HRPWM_2A_PIN                    (GPIO_HRPWM2_PWMA)
#define HRPWM_2B_PIN                    (GPIO_HRPWM2_PWMB)
#define HRPWM_3A_PIN                    (GPIO_HRPWM3_PWMA)
#define HRPWM_3B_PIN                    (GPIO_HRPWM3_PWMB)
#define HRPWM_4A_PIN                    (GPIO_HRPWM4_PWMA)
#define HRPWM_4B_PIN                    (GPIO_HRPWM4_PWMB)
#define HRPWM_5A_PIN                    (GPIO_HRPWM5_PWMA)
#define HRPWM_5B_PIN                    (GPIO_HRPWM5_PWMB)
#define HRPWM_6A_PIN                    (GPIO_HRPWM6_PWMA)
#define HRPWM_6B_PIN                    (GPIO_HRPWM6_PWMB)


typedef struct
{
	int32_t Prd;                   //period
	int32_t PhaseShift_P1;         //phase shift    P1
	int32_t PhaseSRShift_P1;       //phase vs sr    P1
	int32_t SR_Up_P1;              //SR_Up_Value    P1
	int32_t SR_Down_P1;            //SR_Down_Value  P1
	uint32_t DeadTime_P1;          //DeadTime       P1
	
	int32_t PhaseShift_P2;         //phase shift    P2
	int32_t PhaseSRShift_P2;       //phase vs sr    P2
	int32_t SR_Up_P2;              //SR_Up_Value    P2
	int32_t SR_Down_P2;            //SR_Down_Value  P2	
	uint32_t DeadTime_P2;          //DeadTime       P2
	
}LL_Ctrl;


typedef enum
{
	HRPWM_REPMODE_DISABLE = 0,       //disable
	HRPWM_REPMODE_SAWTOOTH_PRD = 1,  //sawtooh only prd
	HRPWM_REPMODE_TRIANGLE_ZERO = 2, //triangle zero
	HRPWM_REPMODE_TRIANGLE_PRD = 3,  //triangle prd
	HRPWM_REPMODE_TRIANGLE_ZERO_PRD = 4,//triangle zero and prd
	HRPWM_REPMODE_SCMPA = 5,            //scmpb  
	HRPWM_REPMODE_SCMPB = 6,            //scmpa
	HRPWM_REPMODE_TOTAL		
}Repetive_mode_select;


extern LL_Ctrl  LL_Ctrl_Real;

extern void GPIO_LLC_HB_outputs_Config(void);
extern void HRTIM_Config(void);
extern void trim(void);
extern void HRPWM_UpdatePRD(LL_Ctrl  *LL_Ctrl_RealTemp);
extern void IDLE_WorkMode(uint16_t workmode);
extern void SwapConfi(uint8_t linkIndex,uint8_t state);
extern void HalfModeConfi(uint8_t linkIndex);
extern void HWSynchConfi(uint32_t modeselt);
extern void HWSynchUpdateConfi(uint32_t modeselt);
extern void HWSynchClearConfi(uint32_t modeselt);
extern void SCMA_B_Confi(uint8_t linkIndex,uint8_t scma_b_select,uint8_t mode);
extern void HRTIM_OutputReverseConf(uint16_t modeselect);
#endif





























