#ifndef HART_XOR_H
#define HART_XOR_H

#include "hart_settings.h"
#include "../common.h"

//=========================== define ==========================================

//==== Communication status codes, HCF_SPEC-099,Table 10 
#define HART_ERR_COM                    0x80
#define HART_ERR_PARITY                 0x40
#define HART_ERR_OVERRUN                0x20
#define HART_ERR_FRAMING                0x10
#define HART_ERR_CHCKSUM                0x08
#define HART_ERR_COMMUNICATION          0x04
#define HART_ERR_BUFF_OVF               0x02
#define HART_ERR_NONE                   0x00

#define HART_XOR_XORINIT                0x00
#define HART_XOR_XORGOOD                0x00 

#define HART_PREAMBLE_BYTE              0xFF
#define HART_PREAMBLE_LENGTH            HART_MIN_TX_PREAMBLES 

#define DELIM_ADDR_POLLING              0x00
#define DELIM_ADDR_UNIQUE               0x80

#define UNIQUE_ADDR_LEN                 5
#define POLLING_ADDR_LEN                1
#define DELIM_ADDR_MSK                  0x80
#define DELIM_EXPBYTES_MSK              0x60
#define DELIM_EXPBYTES_0                0x00
#define DELIM_ADDR_OFFS                 7
#define DELIM_EXPBYTES_OFFS             5
#define ADDR_MASTER_OFFS                7
#define ADDR_MASTER_MSK                 0x80
#define ADDR_BURST_OFFS                 6

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

typedef void (*hart_xor_rxFrame_cbt)(uint8_t* rxAddr, bool pollingAddr, uint8_t rxCmd, uint8_t* rxData, uint8_t rxDataLen, uint8_t rxError);

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

void hart_xor_init(hart_xor_rxFrame_cbt rxFrame_cb, uint8_t* inputBuf, uint8_t inputBufLen);

// interrupt routine
void hart_xor_rxByte(uint8_t rxbyte, uint8_t err);

// output
void hart_xor_outputOpen(void);
void hart_xor_outputWrite(uint8_t b);
void hart_xor_outputClose(void);

// input
void hart_xor_inputOpen(void);
void hart_xor_inputWrite(uint8_t byte, uint8_t err);
void hart_xor_inputClose(void);
#endif
