//*****************************************************************************
//! msp_wm430fr4_golbal.h
//
//! Function Declarations.
//
//! \author Texas Instruments
//! \author A0222632
//
//! \version Release 1
//
//*****************************************************************************

#ifndef MSP_WM430FR4_GLOBAL_H_
#define MSP_WM430FR4_GLOBAL_H_

#include <msp430.h>
#include <stdint.h>
#include <stdbool.h>
//#include <User_Config.h>

#ifdef Comm_Sub1GHz
#include <msp_wm430fr4_cc1120.h>
#include <msp_wm430fr4_rtc.h>
#endif

// Fram record address
#define FRAM_RECORD_ADDRESS 0xFF00	 // Refresh every 1 second
#define FRAM_RECORD_CHECK 0xFF40	 // First record check address
#define FRAM_RECORD_BASE 0xFA00	     // Monthly record in stand-alone address

// LED port definition
#define LED1_PORT_OUT	P1OUT  //  P1OUT |= BIT0;    // Turn LED1 On
#define LED2_PORT_OUT	P4OUT  //  P1OUT |= BIT0;    // Turn LED1 On
//#define LED_PORT_DIR	P2DIR  // P4OUT |= BIT0;    // Turn LED2 On
//#define LED_PORT_SEL	P2SEL0
#define LED_BIT			BIT0
#define LED1_ON()		(LED1_PORT_OUT |= LED_BIT)
#define LED1_OFF()		(LED1_PORT_OUT &=~ LED_BIT)
#define LED1_TOGGLE()    (LED1_PORT_OUT ^= LED_BIT)

#define LED2_ON()		(LED2_PORT_OUT |= LED_BIT)
#define LED2_OFF()		(LED2_PORT_OUT &=~ LED_BIT)
#define LED2_TOGGLE()   (LED2_PORT_OUT ^= LED_BIT)

// RTC format structure
typedef struct
{
	uint8_t  ui8Year;
	uint8_t  ui8Month;
	uint8_t  ui8Day;
	uint8_t  ui8Hour;
	uint8_t  ui8Minute;
	uint8_t  ui8Second;
} tWMRTC;

tWMRTC tRTCData;

extern uint32_t ui32Sum;
extern uint16_t ui16Freq;
extern uint8_t ui8RX_finished;

extern bool bOpen_Valve_Flag;
extern bool bClose_Valve_Flag;

extern void WM_Initialize(void);
extern void Measure_standby();
extern void FRAMWrite_Long(uint32_t *pFRAM_write_ptr, uint32_t ui32Data);
extern void FRAMWrite_Char(uint8_t *pFRAM_write_ptr, uint8_t ui8Data);

#endif /* MSP_WM430FR4_GLOBAL_H_ */
