/*
 * uart2usb.h
 *
 *  Created on: Jan 21, 2017
 *      Author: User
 */

#ifndef SOURCES_UART2USB_H_
#define SOURCES_UART2USB_H_

#include "uartCom1.h"
#include "Cpu.h"
#include "Events.h"
#include "clockMan1.h"
#include "pin_init.h"
#include "osa1.h"
#include "i2cCom1.h"
#include "tpmTmr1.h"
#include "DbgCs1.h"
#include "gpio1.h"
#include "TLC3335.h"
#include "DS3231_RealTime.h"
#include "SaveData.h"


#define UART_TIMEOUT			75
#define UART_FRAME_LENGTH		5

#define UART_INDEX_LENGTH		1
#define UART_INDEX_ID			0

#define UART_ACK_LENGTH			1
#define UART_ACK_ID				0
#define UART_ACK				0x55u
#define UART_NACK				0xAAu

#define UART_IRQVAL_LENGTH		4

#define UART_ACCU_CHARGE_ID		1
#define UART_SETVOLTSOURCE_ID	1
#define UART_SETVOLTVALUE_ID	1
#define UART_SETPRESCALER_ID	1

#define	UART_PWM_FREQ_LBYTE_ID	4
#define	UART_PWM_FREQ_MBYTE_ID	3
#define	UART_PWM_FREQ_HBYTE_ID	2
#define UART_PWM_DUTY_ID		1

#define UART_HOURS_ID			1
#define UART_MINUTES_ID			2
#define UART_SECONDS_ID			3

#define UART_YEAR_ID			1
#define UART_MONTH_ID			2
#define UART_DATE_ID			3

#define UART_TIMECYKLE_DATA_ID	1

#define UART_NOTE_LENGTH_BUFF	2000u
#define UART_NOTE_LENGTH_IDX	1
#define UART_NOTE_MSB_BUFF		3
#define UART_NOTE_LSB_BUFF		4



extern volatile uint32_t irqOldCount, irqCount;
extern bool RloadEnable;

typedef enum
{
	noAction,
	irqCountRead,
	ltc3335SelectVoltageSource,
	ltc3335SetOutVoltage,
	ltc3335SetPrescaler,
	ltc3335SetAccumCharge,
	ltc3335GetAccumCharge,
	ltc3335GetAlarms,
	ltc3335ClearInterrupt,
	ltc3335SetCounterTest,
	ltc3335StopCounterTest,
	temperatureRead,
	dateRead,
	dateWrite,
	pwmStart,
	pwmStop,
	readTime,
	readDate,
	writeTime,
	writeDate,
	saveDataEnable,
	saveDataDisable,
	saveMeasuremenNote,
	ltc3335TurnOn,
	rLoadOnOff,

} uart_message_index;

uart_status_t UART_SendFrame(uint8_t* buff);
uart_status_t UART_ReadFrame(uint8_t* buff);

uart_status_t UART_SendIrq(uint8_t* buff);

uart_status_t SelectVoltageSource(LTC3335_Config *drvConfig, uint8_t *buff);
uart_status_t UART_SetOutVoltage(LTC3335_Config *drvConfig, const uint8_t *buff);
uart_status_t UART_SetPrescaler(LTC3335_Config *drvConfig, uint8_t *buff);

uart_status_t UART_ReadAccumCharge(LTC3335_Config *drvConfig, uint8_t * buff);
uart_status_t UART_WriteAccumCharge(LTC3335_Config *drvConfig, const uint8_t *buff);

uart_status_t UART_GetAlarms(LTC3335_Config *drvConfig, uint8_t *buff);
uart_status_t UART_ClearInterrupt(LTC3335_Config *drvConfig);

uart_status_t UART_SetCounterTest(LTC3335_Config *drvConfig);
uart_status_t UART_StopCounterTest(LTC3335_Config *drvConfig);

uart_status_t UART_StartPWM(tpm_pwm_param_t *pwmConfig, uint8_t *buff);
uart_status_t UART_StopPWM(tpm_pwm_param_t *pwmConfig);

uart_status_t UART_GetAlarms(LTC3335_Config *drvConfig, uint8_t *buff);

uart_status_t UART_ReadTime(DS3231_realTime* config, uint8_t *buff);
uart_status_t UART_ReadDate(DS3231_realTime* config, uint8_t *buff);

uart_status_t UART_EnableSaveData(save_data_t *config, uint8_t *buff);
uart_status_t UART_DisableSaveData(save_data_t *config);

uart_status_t UART_SaveMeasurementNote(uint8_t *buff);
uart_status_t UART_Ltc3335TurnOn(LTC3335_Config *drvConfig, save_data_t *config, uint8_t *buff);

void UART_Routine(LTC3335_Config *drvConfig, DS3231_realTime *timeConfig ,save_data_t *saveDataConfig);



#endif /* SOURCES_UART2USB_H_ */
