CLEON  Version 1
Cloud-Offloaded GPS Receiver
hal_rtc.h File Reference

Initializing RTC. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

union  seoncd_time_tick_u
 
union  milliseoncd_time_tick_u
 
struct  rtc_time_s
 
union  rtc_time_u
 
struct  time_measurement_s
 

Macros

#define HAL_RTC_EnableRDYIE()   RTCCTL01 |= RTCRDYIE;
 
#define HAL_RTC_DisableRDYIE()   RTCCTL01 &= ~RTCRDYIE;
 
#define HAL_RTC_Reset()
 
#define HAL_RTC_StartMillisecondTimer()   TA1CCR0 = 12000;
 
#define HAL_RTC_StopMillisecondTimer()   TA1CCR0 = 0;
 
#define HAL_RTC_EnableSecondInterrupt()   RTCCTL01 |= RTCRDYIE
 
#define HAL_RTC_DisableSecondInterrupt()   RTCCTL01 &= ~RTCRDYIE
 
#define DAYS_IN_MONTHS_BEFORE_THE_FIRST_DAY_OF_JAN   (0)
 
#define DAYS_IN_MONTHS_BEFORE_THE_FIRST_DAY_OF_FEB   (31)
 
#define DAYS_IN_MONTHS_BEFORE_THE_FIRST_DAY_OF_MAR   (31 + 28)
 
#define DAYS_IN_MONTHS_BEFORE_THE_FIRST_DAY_OF_APR   (31 + 28 + 31)
 
#define DAYS_IN_MONTHS_BEFORE_THE_FIRST_DAY_OF_MAY   (31 + 28 + 31 + 30)
 
#define DAYS_IN_MONTHS_BEFORE_THE_FIRST_DAY_OF_JUN   (31 + 28 + 31 + 30 + 31)
 
#define DAYS_IN_MONTHS_BEFORE_THE_FIRST_DAY_OF_JUL   (31 + 28 + 31 + 30 + 31 + 30)
 
#define DAYS_IN_MONTHS_BEFORE_THE_FIRST_DAY_OF_AUG   (31 + 28 + 31 + 30 + 31 + 30 + 31)
 
#define DAYS_IN_MONTHS_BEFORE_THE_FIRST_DAY_OF_SEP   (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31)
 
#define DAYS_IN_MONTHS_BEFORE_THE_FIRST_DAY_OF_OCT   (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30)
 
#define DAYS_IN_MONTHS_BEFORE_THE_FIRST_DAY_OF_NOV   (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31)
 
#define DAYS_IN_MONTHS_BEFORE_THE_FIRST_DAY_OF_DEC   (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30)
 
#define TIME_MEASUREMENT   _DISABLE_
 
#define NUMBER_OF_TIME_MEASUREMENT_TEST   10
 

Functions

void HAL_RTC_Init (void)
 Initializing RTC.
 
void HAL_RTC_ReadRTCTime (void)
 Read RTC time.
 
void HAL_RTC_RestoreTimeTick (void)
 Restore time tick value out of RTC.
 
unsigned long long HAL_RTC_GetSecondConvertedFromStoredRTCTime (rtc_time_u *uniTempRTCTime)
 Get total seconds converted from RTC time.
 
unsigned int HAL_SetRTCYear (int year)
 
unsigned int HAL_SetRTCMon (int month)
 
unsigned int HAL_SetRTCDay (int day)
 
unsigned int HAL_SetRTCDow (int dow)
 
unsigned int HAL_SetRTCHour (int hour)
 
unsigned int HAL_SetRTCMin (int min)
 
unsigned int HAL_SetRTCSec (int sec)
 
unsigned int HAL_SetRTCMilisec (int millisec)
 
unsigned int HAL_GetRTCYear (void)
 
unsigned int HAL_GetRTCMon (void)
 
unsigned int HAL_GetRTCDow (void)
 
unsigned int HAL_GetRTCDay (void)
 
unsigned int HAL_GetRTCHour (void)
 
unsigned int HAL_GetRTCMin (void)
 
unsigned int HAL_GetRTCSec (void)
 
unsigned int HAL_GetRTCMilisec (void)
 

Detailed Description

Initializing RTC.

Definition in file hal_rtc.h.

Macro Definition Documentation

#define DAYS_IN_MONTHS_BEFORE_THE_FIRST_DAY_OF_APR   (31 + 28 + 31)

Definition at line 28 of file hal_rtc.h.

#define DAYS_IN_MONTHS_BEFORE_THE_FIRST_DAY_OF_AUG   (31 + 28 + 31 + 30 + 31 + 30 + 31)

Definition at line 32 of file hal_rtc.h.

#define DAYS_IN_MONTHS_BEFORE_THE_FIRST_DAY_OF_DEC   (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30)

Definition at line 36 of file hal_rtc.h.

#define DAYS_IN_MONTHS_BEFORE_THE_FIRST_DAY_OF_FEB   (31)

Definition at line 26 of file hal_rtc.h.

#define DAYS_IN_MONTHS_BEFORE_THE_FIRST_DAY_OF_JAN   (0)

Definition at line 25 of file hal_rtc.h.

#define DAYS_IN_MONTHS_BEFORE_THE_FIRST_DAY_OF_JUL   (31 + 28 + 31 + 30 + 31 + 30)

Definition at line 31 of file hal_rtc.h.

#define DAYS_IN_MONTHS_BEFORE_THE_FIRST_DAY_OF_JUN   (31 + 28 + 31 + 30 + 31)

Definition at line 30 of file hal_rtc.h.

#define DAYS_IN_MONTHS_BEFORE_THE_FIRST_DAY_OF_MAR   (31 + 28)

Definition at line 27 of file hal_rtc.h.

#define DAYS_IN_MONTHS_BEFORE_THE_FIRST_DAY_OF_MAY   (31 + 28 + 31 + 30)

Definition at line 29 of file hal_rtc.h.

#define DAYS_IN_MONTHS_BEFORE_THE_FIRST_DAY_OF_NOV   (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31)

Definition at line 35 of file hal_rtc.h.

#define DAYS_IN_MONTHS_BEFORE_THE_FIRST_DAY_OF_OCT   (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30)

Definition at line 34 of file hal_rtc.h.

#define DAYS_IN_MONTHS_BEFORE_THE_FIRST_DAY_OF_SEP   (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31)

Definition at line 33 of file hal_rtc.h.

#define HAL_RTC_DisableRDYIE ( )    RTCCTL01 &= ~RTCRDYIE;

Definition at line 11 of file hal_rtc.h.

#define HAL_RTC_DisableSecondInterrupt ( )    RTCCTL01 &= ~RTCRDYIE

Definition at line 22 of file hal_rtc.h.

#define HAL_RTC_EnableRDYIE ( )    RTCCTL01 |= RTCRDYIE;

Definition at line 10 of file hal_rtc.h.

#define HAL_RTC_EnableSecondInterrupt ( )    RTCCTL01 |= RTCRDYIE

Definition at line 21 of file hal_rtc.h.

#define HAL_RTC_Reset ( )
Value:
do{ \
RT0PS = 0; \
RT1PS = 0; \
}while(0)

Definition at line 13 of file hal_rtc.h.

#define HAL_RTC_StartMillisecondTimer ( )    TA1CCR0 = 12000;

Definition at line 18 of file hal_rtc.h.

#define HAL_RTC_StopMillisecondTimer ( )    TA1CCR0 = 0;

Definition at line 19 of file hal_rtc.h.

#define NUMBER_OF_TIME_MEASUREMENT_TEST   10

Definition at line 64 of file hal_rtc.h.

#define TIME_MEASUREMENT   _DISABLE_

Definition at line 63 of file hal_rtc.h.

Function Documentation

unsigned int HAL_GetRTCDay ( void  )

Definition at line 350 of file hal_rtc.c.

{
return RTCDAY;
}

Here is the caller graph for this function:

unsigned int HAL_GetRTCDow ( void  )

Definition at line 345 of file hal_rtc.c.

{
return RTCDOW;
}
unsigned int HAL_GetRTCHour ( void  )

Definition at line 355 of file hal_rtc.c.

{
return RTCHOUR;
}

Here is the caller graph for this function:

unsigned int HAL_GetRTCMilisec ( void  )

Definition at line 370 of file hal_rtc.c.

{
unsigned int uiTemp = 0;
uiTemp = (unsigned int)(uniMillisecondTimeTick.ullMillisecondTimeTick/10000);
if(uiTemp > 999) uiTemp = 0; // set value of ullMillisecondTick to 0, if it exceeds 999, to correct 1ms error
return uiTemp;
}

Here is the caller graph for this function:

unsigned int HAL_GetRTCMin ( void  )

Definition at line 360 of file hal_rtc.c.

{
return RTCMIN;
}

Here is the caller graph for this function:

unsigned int HAL_GetRTCMon ( void  )

Definition at line 340 of file hal_rtc.c.

{
return RTCMON;
}

Here is the caller graph for this function:

unsigned int HAL_GetRTCSec ( void  )

Definition at line 365 of file hal_rtc.c.

{
return RTCSEC;
}

Here is the caller graph for this function:

unsigned int HAL_GetRTCYear ( void  )

Definition at line 335 of file hal_rtc.c.

{
return RTCYEAR;
}

Here is the caller graph for this function:

unsigned long long HAL_RTC_GetSecondConvertedFromStoredRTCTime ( rtc_time_u ptruniTempRTCTime)

Get total seconds converted from RTC time.

Returns
llConvertedSecond - total time elapsed from year of '0', which is represented as seconds
Parameters
ptruniTempRTCTime- RTC time which has been kept in FLASH from last time synchronization

Definition at line 161 of file hal_rtc.c.

{
// Total elapsed time represented in seconds
unsigned long long ullConvertedSecond = 0;
// Variable for checking leap year
bool bIsLeapYear = _FALSE_;
// 'ucYear' is regarded as leap year if it is divisible by 4
// (See, pp. 567 of 'MSP430x5xx and MSP430x6xx Family User's Guide)
if(ptruniTempRTCTime->stRTCTime.ucYear % 4 == 0) bIsLeapYear = _TRUE_;
// Get total elapsed seconds from the first day of year 1 to the first day of RTC year
ullConvertedSecond += (ptruniTempRTCTime->stRTCTime.ucYear - 1) * 365 * 24 * 60 * 60;
// Compansate days in leap years
ullConvertedSecond += (ptruniTempRTCTime->stRTCTime.ucYear / 4);
// Get total elapsed seconds from the first day of this year to the end of previous month of RTC month
switch(ptruniTempRTCTime->stRTCTime.ucMonth){
case 1: // Jan
ullConvertedSecond += (unsigned long long)DAYS_IN_MONTHS_BEFORE_THE_FIRST_DAY_OF_JAN * 24 * 60 * 60;
break;
case 2: // Feb
ullConvertedSecond += (unsigned long long)DAYS_IN_MONTHS_BEFORE_THE_FIRST_DAY_OF_FEB * 24 * 60 * 60;
break;
case 3: // Mar
ullConvertedSecond += (unsigned long long)DAYS_IN_MONTHS_BEFORE_THE_FIRST_DAY_OF_MAR * 24 * 60 * 60;
break;
case 4: // Apr
ullConvertedSecond += (unsigned long long)DAYS_IN_MONTHS_BEFORE_THE_FIRST_DAY_OF_APR * 24 * 60 * 60;
break;
case 5: // May
ullConvertedSecond += (unsigned long long)DAYS_IN_MONTHS_BEFORE_THE_FIRST_DAY_OF_MAY * 24 * 60 * 60;
break;
case 6: // Jun
ullConvertedSecond += (unsigned long long)DAYS_IN_MONTHS_BEFORE_THE_FIRST_DAY_OF_JUN * 24 * 60 * 60;
break;
case 7: // Jul
ullConvertedSecond += (unsigned long long)DAYS_IN_MONTHS_BEFORE_THE_FIRST_DAY_OF_JUL * 24 * 60 * 60;
break;
case 8: // Aug
ullConvertedSecond += (unsigned long long)DAYS_IN_MONTHS_BEFORE_THE_FIRST_DAY_OF_AUG * 24 * 60 * 60;
break;
case 9: // Sep
ullConvertedSecond += (unsigned long long)DAYS_IN_MONTHS_BEFORE_THE_FIRST_DAY_OF_SEP * 24 * 60 * 60;
break;
case 10:// Oct
ullConvertedSecond += (unsigned long long)DAYS_IN_MONTHS_BEFORE_THE_FIRST_DAY_OF_OCT * 24 * 60 * 60;
break;
case 11:// Nov
ullConvertedSecond += (unsigned long long)DAYS_IN_MONTHS_BEFORE_THE_FIRST_DAY_OF_NOV * 24 * 60 * 60;
break;
case 12:// Dec
ullConvertedSecond += (unsigned long long)DAYS_IN_MONTHS_BEFORE_THE_FIRST_DAY_OF_DEC * 24 * 60 * 60;
break;
default:
break;
}
// If it is leap year, add one day
if((bIsLeapYear == _TRUE_)&&(ptruniTempRTCTime->stRTCTime.ucMonth != 1)){
ullConvertedSecond += (long long)24 * 60 * 60;
}
ullConvertedSecond += ((ptruniTempRTCTime->stRTCTime.ucDay)-1) * 24 * 60 * 60;
ullConvertedSecond += ((ptruniTempRTCTime->stRTCTime.ucHour)-1) * 60 * 60;
ullConvertedSecond += ((ptruniTempRTCTime->stRTCTime.ucMinute)-1) * 60;
ullConvertedSecond += ptruniTempRTCTime->stRTCTime.ucSecond;
// Total elapsed time from the first day of year 1, which is represented in seconds
return ullConvertedSecond;
}

Here is the caller graph for this function:

void HAL_RTC_Init ( void  )

Initializing RTC.

Returns
void
Parameters
void

Definition at line 57 of file hal_rtc.c.

{
// Check if reset has been occured by SVSH(POR)
if((SysRstIv == 0x0E)||(SysRstIv == 0x02)){
// Restore previous setting
RTCCTL01 |= RTCRDYIE; // enable rtc ready interrupt; 1sec
RTCCTL01 &= ~RTCHOLD; // release rtchold, begin count
// Restore time tick
}else{
RTCCTL01 |= RTCHOLD; // hold rtc for setting;
RTCCTL01 |= RTCRDYIE; // enable rtc ready interrupt; 1sec
// Example RTC setting
RTCYEAR = 1980; // Year = 1980
RTCMON = 1; // Month = 1 (Jan)
RTCDAY = 1; // Day = 1 (1st)
RTCHOUR = 0; // Hour = 0
RTCMIN = 0; // Minute = 0
RTCSEC = 0; // Seconds = 0
RTCCTL01 &= ~RTCHOLD; // release rtchold, begin count
// Indicating that system time is not synchronized
}
// Change backup system's power source from backup battery to main power
while(BAKCTL & LOCKBAK) BAKCTL &= ~(LOCKBAK);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void HAL_RTC_ReadRTCTime ( void  )

Read RTC time.

Returns
void
Parameters
void

Definition at line 96 of file hal_rtc.c.

{
// Only the value of 'Current-year - 1980' will be stored to 'ucYear' field to save memory
uniRTCTime.stRTCTime.ucYear = (unsigned char) (HAL_GetRTCYear() - 1980);
uniRTCTime.stRTCTime.ucDay = (unsigned char) HAL_GetRTCDay();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void HAL_RTC_RestoreTimeTick ( void  )

Restore time tick value out of RTC.

Returns
void
Parameters
void

Definition at line 116 of file hal_rtc.c.

{
// Temporary variables
rtc_time_u uniTempRTCTime;
seoncd_time_tick_u uniTempSecondTimeTick;
// Storing time difference
unsigned long long ullRTCTimeDifferenceConvertedToTimeTick = 0;
// Read stored time information, which was written to FLASH when time was synchronized
memcpy(&uniTempRTCTime, (unsigned char *)MSP430_INTERNAL_FLASH_BANK3_ADDRESS, sizeof(uniTempRTCTime));
memcpy(&uniTempSecondTimeTick, (unsigned char *)(MSP430_INTERNAL_FLASH_BANK3_ADDRESS + sizeof(uniTempRTCTime)), sizeof(uniTempSecondTimeTick));
// Read RTC time
// Validity check for restored time tick
// Note that 'uniRTCTime.stRTCTime.ucYear = 0' means current year of RTC is set to 1980 (See, HAL_RTC_ReadRTCTime())
// Because this source is being written in year of 2012, 'ucYear' cannot be smaller than 32 (2012 - 1980 = 32)
// If uniRTCTime.stRTCTime.ucYear is equal to zero, it means that current system RTC time has neither been synchronized nor restored correctly
}else{
// If it is confirmed that RTC has been running even for the period of main-battery-failure, then, get current time tick out of RTC time
// First, we get total seconds out of both current and stored RTC time
// After that, get the differnce in seconds and add it to the previous time tick which has been kept in FLASH from last time synchronization
ullRTCTimeDifferenceConvertedToTimeTick = HAL_RTC_GetSecondConvertedFromStoredRTCTime(&uniRTCTime) - HAL_RTC_GetSecondConvertedFromStoredRTCTime(&uniTempRTCTime);
uniSecondTimeTick.ullSecondTimeTick = uniTempSecondTimeTick.ullSecondTimeTick + (ullRTCTimeDifferenceConvertedToTimeTick * 10000000);
// Set flag
// Turn LED3 off
}
}

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned int HAL_SetRTCDay ( int  day)

Definition at line 298 of file hal_rtc.c.

{
RTCDAY = day;
return day;
}

Here is the caller graph for this function:

unsigned int HAL_SetRTCDow ( int  dow)

Definition at line 304 of file hal_rtc.c.

{
RTCDOW = dow;
return dow;
}
unsigned int HAL_SetRTCHour ( int  hour)

Definition at line 310 of file hal_rtc.c.

{
RTCHOUR = hour;
return hour;
}

Here is the caller graph for this function:

unsigned int HAL_SetRTCMilisec ( int  millisec)
unsigned int HAL_SetRTCMin ( int  min)

Definition at line 316 of file hal_rtc.c.

{
RTCMIN = min;
return min;
}

Here is the caller graph for this function:

unsigned int HAL_SetRTCMon ( int  month)

Definition at line 292 of file hal_rtc.c.

{
RTCMON = month;
return month;
}

Here is the caller graph for this function:

unsigned int HAL_SetRTCSec ( int  sec)

Definition at line 322 of file hal_rtc.c.

{
RTCSEC = sec;
return sec;
}

Here is the caller graph for this function:

unsigned int HAL_SetRTCYear ( int  year)

Definition at line 286 of file hal_rtc.c.

{
RTCYEAR = year;
return year;
}

Here is the caller graph for this function: