Ignore:
Timestamp:
Mar 28, 2016, 2:09:46 PM (8 years ago)
Author:
ertl-honda
Message:

ライブラリを Arduino IDE 1.7.9 にupdate

File:
1 edited

Legend:

Unmodified
Added
Removed
  • rtos_arduino/trunk/arduino_lib/libraries/RTC/src/RTCInt.cpp

    r136 r175  
    22  RTC library for Arduino M0/M0PRO.
    33  Copyright (c) 2015 Arduino SRL. All right reserved.
    4 
    54  This library is free software; you can redistribute it and/or
    65  modify it under the terms of the GNU Lesser General Public
    76  License as published by the Free Software Foundation; either
    87  version 2.1 of the License, or (at your option) any later version.
    9 
    108  This library is distributed in the hope that it will be useful,
    119  but WITHOUT ANY WARRANTY; without even the implied warranty of
    1210  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    1311  Lesser General Public License for more details.
    14 
    1512  You should have received a copy of the GNU Lesser General Public
    1613  License along with this library; if not, write to the Free Software
     
    2825*Return Parameter: None
    2926*******************************************************************************************/
    30 void RTCInt::begin(bool timeRep)
     27void RTCInt::begin(bool timeRep, int oscillatorType)
    3128{
    3229 
     
    3734  while (GCLK->STATUS.bit.SYNCBUSY);
    3835 
    39   GCLK->GENCTRL.reg = (GCLK_GENCTRL_GENEN | GCLK_GENCTRL_SRC_OSCULP32K | GCLK_GENCTRL_ID(4) | GCLK_GENCTRL_DIVSEL );
     36  //Set the oscillator to use - M0 only
     37  if(oscillatorType==HIGH_PRECISION)
     38  //External oscillator
     39  GCLK->GENCTRL.reg = (GCLK_GENCTRL_GENEN | GCLK_GENCTRL_SRC_XOSC32K | GCLK_GENCTRL_ID(4) | GCLK_GENCTRL_DIVSEL );
     40 
     41  else
     42  //Internal low power oscillator (default configuration)
     43  GCLK->GENCTRL.reg = (GCLK_GENCTRL_GENEN |  GCLK_GENCTRL_SRC_OSCULP32K | GCLK_GENCTRL_ID(4) | GCLK_GENCTRL_DIVSEL );
     44 
    4045  while (GCLK->STATUS.reg & GCLK_STATUS_SYNCBUSY);
    4146 
     
    7378  RTCenable();
    7479 
     80}
     81
     82void RTCInt::begin(bool timeRep){
     83    begin(timeRep, LOW_POWER);
    7584}
    7685
     
    132141
    133142/**********************************************************************************************************************
    134 *Description: Function for getting time (hours, minutes and seconds). This function fills a structure called local_time
     143*Description: Function for getting time (hours, minutes and seconds). This function fills a structure called time
    135144                          accessible in the class RTCInt.       
    136145*Input Parameters: None
     
    141150        unsigned int hour=0, h=0;
    142151       
    143         local_time.hour = getHour();
     152        time.hour = getHour();
    144153        if(time_Mode == TIME_H12)
    145154        {
    146155                h=RTC->MODE2.CLOCK.bit.HOUR;
    147156                while (RTCSync());
    148                 local_time.Tmode = h & 0x10;
     157                time.Tmode = h & 0x10;
    149158        }       
    150         local_time.minute = getMinute();
    151         local_time.second = getSecond();
     159        time.minute = getMinute();
     160        time.second = getSecond();
    152161}
    153162
     
    219228
    220229/**********************************************************************************************************************
    221 *Description: Function for getting date (day, month and year). This function fills a structure called local_date
     230*Description: Function for getting date (day, month and year). This function fills a structure called date
    222231                          accessible in the class RTCInt.       
    223232*Input Parameters: None
     
    226235void RTCInt::getDate(void)
    227236{
    228         local_date.day = getDay();
    229         local_date.month = getMonth();
    230         local_date.year = getYear();
     237        date.day = getDay();
     238        date.month = getMonth();
     239        date.year = getYear();
    231240}
    232241
     
    315324/**********************************************************************************************************************
    316325*Description: Function for setting time (hour, minute and second). This function sets time retrieving values from a
    317                           local structure called local_time accessible in the class RTCInt.     
     326                          local structure called time accessible in the class RTCInt.   
    318327*Input Parameters: None
    319328*Return Parameter: None
     
    321330void RTCInt::setTime(void)
    322331{
    323         setHour(local_time.hour,local_time.Tmode);
    324     setMinute(local_time.minute);
    325     setSecond(local_time.second); 
     332        setHour(time.hour,time.Tmode);
     333    setMinute(time.minute);
     334    setSecond(time.second); 
    326335}
    327336
     
    397406/**********************************************************************************************************************
    398407*Description: Function for setting date (day, month and year). This function retrieves values from a local structure
    399                           called local_date accessible in the class RTCInt.     
     408                          called date accessible in the class RTCInt.   
    400409*Input Parameters: None
    401410*Return Parameter: None
     
    403412void RTCInt::setDate(void)
    404413{
    405         setDay(local_date.day);
    406         setMonth(local_date.month); 
    407     setYear(local_date.year);
     414        setDay(date.day);
     415        setMonth(date.month); 
     416    setYear(date.year);
    408417}
    409418
     
    461470 /**********************************************************************************************************************
    462471*Description: Function for setting alarm. This function retrieves values from two local structures
    463                           called local_date and local_time accessible in the class RTCInt. According to match alarm type, values
    464                           can be obtained from local_time, local_date or both structures.       
     472                          called date and time accessible in the class RTCInt. According to match alarm type, values
     473                          can be obtained from time, date or both structures.   
    465474*Input Parameters: None
    466475*Return Parameter: None
     
    474483      break;
    475484   case SEC :
    476           RTC->MODE2.Mode2Alarm->ALARM.bit.SECOND= local_time.second;
     485          RTC->MODE2.Mode2Alarm->ALARM.bit.SECOND= time.second;
    477486          while (RTCSync());
    478487          break;       
    479488   case MMSS :
    480       RTC->MODE2.Mode2Alarm->ALARM.bit.MINUTE= local_time.minute;
    481           while (RTCSync());
    482           RTC->MODE2.Mode2Alarm->ALARM.bit.SECOND= local_time.second;
     489      RTC->MODE2.Mode2Alarm->ALARM.bit.MINUTE= time.minute;
     490          while (RTCSync());
     491          RTC->MODE2.Mode2Alarm->ALARM.bit.SECOND= time.second;
    483492          while (RTCSync());
    484493          break;
    485494   case HHMMSS :
    486       RTC->MODE2.Mode2Alarm->ALARM.bit.HOUR= local_time.hour;
    487           while (RTCSync());
    488           RTC->MODE2.Mode2Alarm->ALARM.bit.MINUTE= local_time.minute;
    489           while (RTCSync());
    490           RTC->MODE2.Mode2Alarm->ALARM.bit.SECOND= local_time.second;
     495      RTC->MODE2.Mode2Alarm->ALARM.bit.HOUR= time.hour;
     496          while (RTCSync());
     497          RTC->MODE2.Mode2Alarm->ALARM.bit.MINUTE= time.minute;
     498          while (RTCSync());
     499          RTC->MODE2.Mode2Alarm->ALARM.bit.SECOND= time.second;
    491500          while (RTCSync());
    492501      break;
    493502   case DDHHMMSS :
    494       RTC->MODE2.Mode2Alarm->ALARM.bit.DAY= local_date.day;
    495           while (RTCSync());
    496           RTC->MODE2.Mode2Alarm->ALARM.bit.HOUR= local_time.hour;
    497           while (RTCSync());
    498           RTC->MODE2.Mode2Alarm->ALARM.bit.MINUTE= local_time.minute;
    499           while (RTCSync());
    500           RTC->MODE2.Mode2Alarm->ALARM.bit.SECOND= local_time.second;
     503      RTC->MODE2.Mode2Alarm->ALARM.bit.DAY= date.day;
     504          while (RTCSync());
     505          RTC->MODE2.Mode2Alarm->ALARM.bit.HOUR= time.hour;
     506          while (RTCSync());
     507          RTC->MODE2.Mode2Alarm->ALARM.bit.MINUTE= time.minute;
     508          while (RTCSync());
     509          RTC->MODE2.Mode2Alarm->ALARM.bit.SECOND= time.second;
    501510          while (RTCSync());
    502511      break;
    503512   case MMDDHHMMSS :
    504       RTC->MODE2.Mode2Alarm->ALARM.bit.MONTH= local_date.month;
    505           while (RTCSync());
    506           RTC->MODE2.Mode2Alarm->ALARM.bit.DAY= local_date.day;
    507           while (RTCSync());
    508           RTC->MODE2.Mode2Alarm->ALARM.bit.HOUR= local_time.hour;
    509           while (RTCSync());
    510           RTC->MODE2.Mode2Alarm->ALARM.bit.MINUTE= local_time.minute;
    511           while (RTCSync());
    512           RTC->MODE2.Mode2Alarm->ALARM.bit.SECOND= local_time.second;
     513      RTC->MODE2.Mode2Alarm->ALARM.bit.MONTH= date.month;
     514          while (RTCSync());
     515          RTC->MODE2.Mode2Alarm->ALARM.bit.DAY= date.day;
     516          while (RTCSync());
     517          RTC->MODE2.Mode2Alarm->ALARM.bit.HOUR= time.hour;
     518          while (RTCSync());
     519          RTC->MODE2.Mode2Alarm->ALARM.bit.MINUTE= time.minute;
     520          while (RTCSync());
     521          RTC->MODE2.Mode2Alarm->ALARM.bit.SECOND= time.second;
    513522          while (RTCSync());
    514523      break;
    515524   case YYMMDDHHMMSS :
    516       RTC->MODE2.Mode2Alarm->ALARM.bit.YEAR= local_date.year;
    517           while (RTCSync());
    518           RTC->MODE2.Mode2Alarm->ALARM.bit.MONTH= local_date.month;
    519           while (RTCSync());
    520           RTC->MODE2.Mode2Alarm->ALARM.bit.DAY= local_date.day;
    521           while (RTCSync());
    522           RTC->MODE2.Mode2Alarm->ALARM.bit.HOUR= local_time.hour;
    523           while (RTCSync());
    524           RTC->MODE2.Mode2Alarm->ALARM.bit.MINUTE= local_time.minute;
    525           while (RTCSync());
    526           RTC->MODE2.Mode2Alarm->ALARM.bit.SECOND= local_time.second;
     525      RTC->MODE2.Mode2Alarm->ALARM.bit.YEAR= date.year;
     526          while (RTCSync());
     527          RTC->MODE2.Mode2Alarm->ALARM.bit.MONTH= date.month;
     528          while (RTCSync());
     529          RTC->MODE2.Mode2Alarm->ALARM.bit.DAY= date.day;
     530          while (RTCSync());
     531          RTC->MODE2.Mode2Alarm->ALARM.bit.HOUR= time.hour;
     532          while (RTCSync());
     533          RTC->MODE2.Mode2Alarm->ALARM.bit.MINUTE= time.minute;
     534          while (RTCSync());
     535          RTC->MODE2.Mode2Alarm->ALARM.bit.SECOND= time.second;
    527536          while (RTCSync());
    528537      break;     
Note: See TracChangeset for help on using the changeset viewer.