Exemple #1
0
 /**********************************************************************************************************************
*Description: Function for getting second, this value varies in the range 0 - 59 
*Input Parameters: None
*Return Parameter: unsigned int (second)
***********************************************************************************************************************/
 unsigned int RTCInt::getSecond()
{
  unsigned int s=0;
  
  s=RTC->MODE2.CLOCK.bit.SECOND;
  while (RTCSync());
 return s; 
}
Exemple #2
0
 /**********************************************************************************************************************
*Description: Function for getting minute, this value varies in the range 0 - 59 
*Input Parameters: None
*Return Parameter: unsigned int (minute)
***********************************************************************************************************************/
unsigned int RTCInt::getMinute()
{
  unsigned int m=0;
  
  m=RTC->MODE2.CLOCK.bit.MINUTE;
  while (RTCSync());
 return m; 
}
Exemple #3
0
/*******************************************************************************************
*Description: Function responsible of RTC initialization
*Input Parameters: bool timeRep this parameter can be TIME_H24 (24 hour mode) or TIME_H12 (12 hour mode)
*Return Parameter: None
*******************************************************************************************/
void RTCInt::begin(bool timeRep, int oscillatorType) 
{
  
  
  PM->APBAMASK.reg |= PM_APBAMASK_RTC; // turn on digital interface clock for RTC
  
  GCLK->CLKCTRL.reg = (uint32_t)((GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK4 | (RTC_GCLK_ID << GCLK_CLKCTRL_ID_Pos)));
  while (GCLK->STATUS.bit.SYNCBUSY);
  
  //Set the oscillator to use - M0 only
  if(oscillatorType==HIGH_PRECISION)
  //External oscillator
  GCLK->GENCTRL.reg = (GCLK_GENCTRL_GENEN | GCLK_GENCTRL_SRC_XOSC32K | GCLK_GENCTRL_ID(4) | GCLK_GENCTRL_DIVSEL );
  
  else
  //Internal low power oscillator (default configuration)
  GCLK->GENCTRL.reg = (GCLK_GENCTRL_GENEN |  GCLK_GENCTRL_SRC_OSCULP32K | GCLK_GENCTRL_ID(4) | GCLK_GENCTRL_DIVSEL );
  
  while (GCLK->STATUS.reg & GCLK_STATUS_SYNCBUSY);
  
  GCLK->GENDIV.reg = GCLK_GENDIV_ID(4); 
  GCLK->GENDIV.bit.DIV=4;
  while (GCLK->STATUS.reg & GCLK_STATUS_SYNCBUSY);
  
  

  RTCdisable();

  RTCreset();

  RTC->MODE2.CTRL.reg |= RTC_MODE2_CTRL_MODE_CLOCK; // set RTC operating mode
  RTC->MODE2.CTRL.reg |= RTC_MODE2_CTRL_PRESCALER_DIV1024; // set prescaler to 1024 for MODE2
  RTC->MODE2.CTRL.bit.MATCHCLR = 0; // disable clear on match
  
  
  if (timeRep)
  {
    RTC->MODE2.CTRL.bit.CLKREP = 0; // 24h time representation
	time_Mode = true;
  }		
  else
  {  
    RTC->MODE2.CTRL.bit.CLKREP = 1; // 12h time representation
	time_Mode = false;
  }	

  RTC->MODE2.READREQ.reg &= ~RTC_READREQ_RCONT; // disable continuously mode

  
  while (RTCSync());
	RTCresetRemove();
  RTCenable();
  
}
Exemple #4
0
unsigned char RTCInt::getMeridian(void)
{
	unsigned int h=0;
	unsigned char m=0;
	
	if(time_Mode == TIME_H12)
	{
		h=RTC->MODE2.CLOCK.bit.HOUR;
		while (RTCSync());
		m = h & 0x10;
		m >> 4;
	}
Exemple #5
0
/**********************************************************************************************************************
*Description: Function for getting time (hours, minutes and seconds). This function fills a structure called local_time
			  accessible in the class RTCInt.	
*Input Parameters: None
*Return Parameter: None
***********************************************************************************************************************/
void RTCInt::getTime(void)
{
	unsigned int hour=0, h=0;
	
	local_time.hour = getHour();
	if(time_Mode == TIME_H12)
	{
		h=RTC->MODE2.CLOCK.bit.HOUR;
		while (RTCSync());
		local_time.Tmode = h & 0x10;
	}	
	local_time.minute = getMinute();
	local_time.second = getSecond();
}
Exemple #6
0
/**********************************************************************************************************************
*Description: Function for getting hour, according to time representation mode this value can 
			  be in the range 0-24 (in case of TIME_H24) or in the range 0-12 (in case of TIME_H12)	
*Input Parameters: None
*Return Parameter: unsigned int (hour)
***********************************************************************************************************************/
 unsigned int RTCInt::getHour()
{
	unsigned int h=0;
	
	
	h=RTC->MODE2.CLOCK.bit.HOUR;
	while (RTCSync());
	
	if(time_Mode ==TIME_H12)
	{
		h = h & 0x0000000F;
	}
	
  return h;
}