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

RTC configuration. More...

#include "cleon_conf.h"
#include "app_define.h"
#include "sys_define.h"
#include "hal_define.h"
#include "fs_define.h"
Include dependency graph for hal_rtc.c:

Go to the source code of this file.

Macros

#define GPS_TEST_ON_INITIALIZATION   _ENABLE_
 

Functions

void HAL_RTC_Init ()
 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 *ptruniTempRTCTime)
 Get total seconds converted from RTC time.
 
__interrupt void RTC_VECTOR_ISR (void)
 
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)
 

Variables

cleon_header_u uniCLEONHeader
 
cleon_gps_data_u uniCLEONGPSData
 
cleon_sensor_data_u uniCLEONSensorData
 
bool bFLAG_CLEONSampleIntervalConuter
 
bool bFLAG_ISLoggingRequested
 
bool bFLAG_IsTimeSynced = _CLEAR_
 
bool bFLAG_RTCTimeTickOfSecond = _CLEAR_
 
bool bFLAG_ISResetOccuredBySVSHPOR = _CLEAR_
 
volatile unsigned int SysRstIv
 
unsigned long ulSampleCount
 
unsigned long ulSampleGap
 
unsigned long ulChunkCount
 
unsigned long ulChunkGap
 
rtc_time_u uniRTCTime = {0}
 
milliseoncd_time_tick_u uniMillisecondTimeTick = {0}
 
seoncd_time_tick_u uniSecondTimeTick = {0}
 
unsigned char ucRTCNumberOfSecondCounter = 0
 
time_measurement_s stTimeMeasurement [NUMBER_OF_TIME_MEASUREMENT_TEST] = {0}
 

Detailed Description

RTC configuration.

Definition in file hal_rtc.c.

Macro Definition Documentation

#define GPS_TEST_ON_INITIALIZATION   _ENABLE_

Definition at line 13 of file hal_rtc.c.

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:

__interrupt void RTC_VECTOR_ISR ( void  )

Definition at line 238 of file hal_rtc.c.

{
switch(__even_in_range(RTCIV,16))
{
case RTC_NONE: // No interrupts
break;
case RTC_RTCRDYIFG: // RTCRDYIFG
// Reset millisecond to zero
// Increase second time tick
// Set flag if condition is met
if(ulSampleCount != 1){
// Check if defined time interval for logging has elapsed
// If defined time interval for logging has elapsed, exit low-power-mode
__low_power_mode_off_on_exit();
}else{
}
}
}
}
break;
case RTC_RTCTEVIFG: // RTCEVIFG
break;
case RTC_RTCAIFG: // RTCAIFG
break;
case RTC_RT0PSIFG: // RT0PSIFG
break;
case RTC_RT1PSIFG: // RT1PSIFG
break;
case 12: break; // Reserved
case 14: break; // Reserved
case 16: break; // Reserved
default: break;
}
}

Variable Documentation

bool bFLAG_CLEONSampleIntervalConuter

Definition at line 33 of file app_log.c.

bool bFLAG_ISLoggingRequested

Definition at line 31 of file app_log.c.

bool bFLAG_ISResetOccuredBySVSHPOR = _CLEAR_

Definition at line 25 of file hal_rtc.c.

bool bFLAG_IsTimeSynced = _CLEAR_

Definition at line 23 of file hal_rtc.c.

bool bFLAG_RTCTimeTickOfSecond = _CLEAR_

Definition at line 24 of file hal_rtc.c.

Definition at line 47 of file hal_rtc.c.

volatile unsigned int SysRstIv

Definition at line 14 of file hal_pmm.c.

unsigned char ucRTCNumberOfSecondCounter = 0

Definition at line 44 of file hal_rtc.c.

unsigned long ulChunkCount

Definition at line 44 of file app_log.c.

unsigned long ulChunkGap

Definition at line 45 of file app_log.c.

unsigned long ulSampleCount

Definition at line 42 of file app_log.c.

unsigned long ulSampleGap

Definition at line 43 of file app_log.c.

cleon_gps_data_u uniCLEONGPSData

Definition at line 14 of file sys_init.c.

cleon_header_u uniCLEONHeader

Definition at line 13 of file sys_init.c.

cleon_sensor_data_u uniCLEONSensorData

Definition at line 15 of file sys_init.c.

milliseoncd_time_tick_u uniMillisecondTimeTick = {0}

Definition at line 40 of file hal_rtc.c.

rtc_time_u uniRTCTime = {0}

Definition at line 37 of file hal_rtc.c.

seoncd_time_tick_u uniSecondTimeTick = {0}

Definition at line 41 of file hal_rtc.c.