#ifndef DEBUG_DEF
#define DEBUG_DEF

#include "../common.h"

// compiler switch, comment out when not using debug module
#define DEBUG

//=========================== defines =========================================

//==== messages
#define MSG_IDN "\n\nANALOG DEVICES, WirelessHART Host Application\n"

// hart_xor.c
#define HART_PARITY_ERR()                debug_errors.hart_xor_parity++
#define HART_CHCKSUM_ERR()               debug_errors.hart_xor_checkSum++
#define HART_OVERRUN_ERR()               debug_errors.hart_xor_overrun++
#define HART_RX_TIMEOUT_ERR()            debug_errors.hart_xor_rxTimeout++
#define HART_FSM_ERR()                   debug_errors.hart_xor_invalidState++

// hart_serial.c
#define HART_INVALID_TX_DELIMITER_ERR()  debug_errors.hart_serial_invalidTxDelimiter++
#define HART_INVALID_RX_DELIMITER_ERR()  debug_errors.hart_serial_invalidRxDelimiter++
#define HART_ADDR_MISMATCH_ERR()         debug_errors.hart_serial_addressMismatch++
#define HART_SERIAL_ERROR()              debug_errors.hart_serial_communicationError++

// hart_modem.c
#define HART_BUFFER_ERR()                debug_errors.hart_modem_buffer++
#define HART_PAYLOAD_ERR()               debug_errors.hart_modem_payload++ 

// hart_lib.c
#define HART_LIB_DATA_ERR()              debug_errors.hart_lib_invalidData++

// api.c
#define MOTE_RC_ERR()                    debug_errors.api_invalidMoteRC++
#define MOTE_INVALID_EVENT_ERR()         debug_errors.api_invalidEvent++
#define MOTE_INVALID_NOTIF_ERR()         debug_errors.api_invalidNotification++
#define MOTE_INVALID_SERVICE_ERR()       debug_errors.api_invalidService++
#define MOTE_SEND_ERR()                  debug_errors.api_sendFailed++ 

// fsm.c
#define FSM_INVALID_STATE_ERR()          debug_errors.fsm_invalidState++
#define FSM_HART_PAYLOAD_ERR()           debug_errors.fsm_hartPayload++
#define FSM_EVENT_PUT_TO_QUEUE()         debug_errors.fsm_eventPutToQueue++

// time.c
#define TIME_RTC1_IRQ_ERR()              debug_errors.time_invalidIrq++

// adi_ltc3335.c
#define LTC3335_I2C_ERR()                debug_errors.ltc3335_i2c++

//=========================== typedef =========================================

typedef struct
{
		// hart_xor.c
    uint8_t hart_xor_parity;
    uint8_t hart_xor_checkSum;
	  uint8_t hart_xor_rxTimeout;
		uint8_t hart_xor_overrun;
		uint8_t hart_xor_invalidState;
	
		// hart_serial.c
		uint8_t hart_serial_invalidTxDelimiter;
		uint8_t hart_serial_invalidRxDelimiter;
		uint8_t hart_serial_addressMismatch;
		uint8_t hart_serial_communicationError;
	
		// hart_modem.c
		uint8_t hart_modem_buffer;
		uint8_t hart_modem_payload;
	
		// hart_lib.c
		uint8_t hart_lib_invalidData;
		
		// api.c
		uint8_t api_invalidMoteRC;
		uint8_t api_invalidEvent;
		uint8_t api_invalidNotification;
		uint8_t api_invalidService;
		uint8_t api_sendFailed;
	
		// fsm.c
		uint8_t fsm_invalidState;
		uint8_t fsm_hartPayload;
		uint8_t fsm_eventPutToQueue;
		
		// time.c
		uint8_t time_invalidIrq;
		
		// adi_ltc3335.c
		uint8_t ltc3335_i2c;
} debug_errors_t;


//=========================== variables =======================================

extern debug_errors_t debug_errors;

//=========================== prototypes ======================================

int16_t DEBUG_MSG(const char* format, ...);
int16_t ERR_MSG(const char* format, ...);

#endif
