//*************************************************************************************************
// @Module              Current Control Bemf
// @Filename            CCB_CTRL.H
// @Controller          XC88x Series
//
//
// @Description   This file contains references for Current control through 
//                              Block Commutation   
//*************************************************************************************************
//*************************************************************************************************
// @Includes
//*************************************************************************************************


//*************************************************************************************************
// @Macros
//*************************************************************************************************


#define CTRL_VAR_DECL()\
    extern BIT gb_motor_status;\
    extern BIT gb_hs_error;\
    extern BIT gb_ctrap;\
    extern BIT gb_time_out;\
    extern BIT gb_overcurrent;\
    extern BIT gb_idle_state;\
	extern int idata g_adc_mem;\
	extern U_CHAR g_direction;\
    extern U_CHAR g_once;\
    extern int C_SDATA g_i_counter;\
    extern unsigned int idata g_current;\
    extern U_CHAR g_speed_counter;\
	extern C_UBDATA g_direction_user;\
    extern unsigned int idata g_duty_cyc;\
    extern unsigned int idata  g_speed_CC61;\
    extern U_CHAR g_circ_index;\
	extern unsigned int idata g_bemf_aux;\
	extern int C_SDATA g_counter0;\
	extern C_UBDATA g_trap_reset;\
	extern unsigned int idata  g_slope;\
	extern unsigned int idata compare_value;\
	extern unsigned int idata high_limit;\
	extern unsigned int idata low_limit;\
	extern unsigned int g_time_measure;\
	extern unsigned int idata g_state;\
	extern unsigned int idata  g_start_freq;\
	extern int idata g_current_rf;\
	extern U_CHAR task_counter;
	   

#define INLINE_FUNC_DECL()\
	extern void CONTROL_PANEL_PARAMS(void);\
	extern void INIT_CTRL_VAR(void);\
	extern void CCU6_CTRL_REG(void);\
	extern void ADC_AUX_BEMF(void);

#define CTRL_FUNC_DECL()\
    extern void motor_start(void);\
    extern void motor_stop(void);\
    extern void comm_init(void);\
    extern void init_control(void);\
	#if DAVECG_SPEED_CALCU
    extern unsigned int speed_calculation(unsigned int time_measurement, U_CHAR *speed_counter, int limit);\
	#endif
	extern void commutation(void);\
	extern unsigned int pi_controller_16bit(long *buf_ptr,reference,act);
	extern void OVER_CURRENT_CHECK(void);

//*************************************************************************************************

//*************************************************************************************************
CTRL_VAR_DECL()
CTRL_FUNC_DECL()
#if DAVECG_CONTROL_PANEL_ENABLE
COMM_FUNC_DECL()
#endif	// CONTROL_PANEL_ENABLE
INLINE_FUNC_DECL()
//*************************************************************************************************

extern  pi_con idata g_pi_array;
extern unsigned int idata g_pi_controller_out;
//*************************************************************************************************

