/*
 * DS3231_RealTime.h
 *
 *  Created on: Jan 27, 2017
 *      Author: User
 */

#ifndef SOURCES_DS3231_REALTIME_H_
#define SOURCES_DS3231_REALTIME_H_

#include "Cpu.h"
#include "Events.h"
#include "clockMan1.h"
#include "pin_init.h"
#include "osa1.h"
#include "i2cCom1.h"

#define DS3231_ADRRESS_SECOND	0x00
#define DS3231_ADRRESS_MINUTES	0x01
#define DS3231_ADRRESS_HOURS	0x02
#define DS3231_ADRRESS_DATE		0x04
#define DS3231_ADRRESS_MONTH	0x05
#define DS3231_ADRRESS_YEAR		0x06
#define DS3231_ADDRESS_CONTROL	0x0E
#define DS3231_ADDRESS_STATUS	0x0F
#define DS3231_ADRRESS_TEMP_MSB	0x11
#define DS3231_ADRRESS_TEMP_LSB	0x12

#define	DS3231_MASK_SECOUNDS_1	0x0F
#define	DS3231_MASK_SECOUNDS_10	0x70
#define	DS3231_MASK_MINUTES_1	0x0F
#define	DS3231_MASK_MINUTES_10	0x70
#define	DS3231_MASK_HOUR_1		0x0F
#define	DS3231_MASK_HOUR_10_20	0x30
#define	DS3231_MASK_DATE_1		0x0F
#define	DS3231_MASK_DATE_10		0x30
#define	DS3231_MASK_MONTH_1		0x0F
#define	DS3231_MASK_MONTH_10	0x10
#define	DS3231_MASK_YEAR_1		0x0F
#define	DS3231_MASK_YEAR_10		0xFF

#define DS3231_SIZE_OF_ALL_DATA	0x07
#define DS3231_SIZE_OF_TIME		0x03
#define DS3231_SIZE_OF_DATE		0x03

#define	I2C_TIMEOUT				100
#define DS3231_I2C_ADDRESS		0x68

typedef struct
{
	i2c_device_t i2c_device;
	i2c_status_t i2c_status;
	uint32_t IIC_instance;
}DS3231_IIC;

typedef struct
{
	uint8_t	seconds;
	uint8_t	minutes;
	uint8_t hours;
	uint8_t	date;
	uint8_t	month;
	uint8_t	year;

	DS3231_IIC	i2cConfig;

	uint8_t buffer[DS3231_SIZE_OF_ALL_DATA];

}DS3231_realTime;

void DS3231_GetDefaultConfig(DS3231_realTime* config);

i2c_status_t DS3231_ReadAll(DS3231_realTime* config);
i2c_status_t DS3231_WriteAll(DS3231_realTime* config);
i2c_status_t DS3231_WriteTime(DS3231_realTime* config);
i2c_status_t DS3231_WriteDate(DS3231_realTime* config);


#endif /* SOURCES_DS3231_REALTIME_H_ */
