//*************************************************************************************************
// @Module              Communication
// @Filename            COMM.H
// @Controller          XC16x Series
//
//
// @Description   This file contains references for Communication Protocol
//*************************************************************************************************

#ifndef _COMM_H_
#define _COMM_H_

//*************************************************************************************************
// @Includes
//*************************************************************************************************

//*************************************************************************************************
// @Global Variables Declaration
//*************************************************************************************************

//*************************************************************************************************
// @Prototypes Of Functions
//*************************************************************************************************

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

#define SER_VERSION 0x00A1	

#if DAVECG_BLOCK_COMMUTATION
#if DAVECG_BTS
#define TRACE_LOAD 256
#endif
#elif DAVECG_FOC
#define TRACE_LOAD 512
#else
#define TRACE_LOAD 200
#endif


#if DAVECG_VOLTAGE_CTRL
#define SCODE_CS 0x0
#elif DAVECG_CURRENT_CTRL
#define SCODE_CS 0x1
#elif DAVECG_SPEED_CTRL
#define SCODE_CS 0x2
#elif DAVECG_SPEED_ENC_CTRL
#define SCODE_CS 0x3
#elif DAVECG_SPEED_CURRENT_CTRL
#define SCODE_CS 0x4
#elif DAVECG_SPEED_CURRENT_ENC_CTRL
#define SCODE_CS 0x5
#endif

#if DAVECG_BTS
#define SCODE_PB 0x0
#elif DAVECG_TLE
#define SCODE_PB 0x1
#else
#define SCODE_PB 0x0
#endif

#if DAVECG_HALL
#define SCODE_CT 0x0
#endif
#if DAVECG_BEMF
#if START_RAMP == 0
#define SCODE_CT 0x1
#elif   START_RAMP == 1
#define SCODE_CT 0x9
#endif
#endif

#if DAVECG_BLOCK_COMMUTATION
#define SCODE_CA 0x0
#endif
#if DAVECG_FOC
    #define SCODE_CT 0x0
    #if (SINUS_POSITION_CTRL == 1)
    #define SCODE_CS 0x8
    #elif (SINUS_SPEED_CTRL == 1)
    #define SCODE_CS 0x6
    #elif (SINUS_SPEED_FW_CTRL == 1)
    #define SCODE_CS 0x7
#endif
#define SCODE_CA 0x1
#endif

#if DAVECG_KEIL
#define SCODE_COMPILER 0x0
#elif DAVECG_TASKING
#define SCODE_COMPILER 0x1
#endif

#define STECKERCODE (SCODE_CS | (SCODE_PB << 4) | (SCODE_CT << 8) | (SCODE_CA << 12) | (SCODE_COMPILER << 14))

#define ADDRESS_LENGTH  31                                 // Number of variables accessible by Control Panel.

#define SIO_INIT() sio_init();

#if DAVECG_BLOCK_COMMUTATION
#define TRACE() trace();
#endif

#define COMM_FUNC_DECL()\
    extern void sio_init(void);\
    extern void iiup(void);\
    extern void trace(void);

#define COMM_VAR_DECL()

//*************************************************************************************************
// @Defines
//*************************************************************************************************

//*************************************************************************************************
// @Typedefs
//*************************************************************************************************

#endif
