- Timestamp:
- Mar 28, 2016, 2:09:46 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
rtos_arduino/trunk/arduino_lib/libraries/RTC/src/RTCInt.cpp
r136 r175 2 2 RTC library for Arduino M0/M0PRO. 3 3 Copyright (c) 2015 Arduino SRL. All right reserved. 4 5 4 This library is free software; you can redistribute it and/or 6 5 modify it under the terms of the GNU Lesser General Public 7 6 License as published by the Free Software Foundation; either 8 7 version 2.1 of the License, or (at your option) any later version. 9 10 8 This library is distributed in the hope that it will be useful, 11 9 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 11 Lesser General Public License for more details. 14 15 12 You should have received a copy of the GNU Lesser General Public 16 13 License along with this library; if not, write to the Free Software … … 28 25 *Return Parameter: None 29 26 *******************************************************************************************/ 30 void RTCInt::begin(bool timeRep )27 void RTCInt::begin(bool timeRep, int oscillatorType) 31 28 { 32 29 … … 37 34 while (GCLK->STATUS.bit.SYNCBUSY); 38 35 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 40 45 while (GCLK->STATUS.reg & GCLK_STATUS_SYNCBUSY); 41 46 … … 73 78 RTCenable(); 74 79 80 } 81 82 void RTCInt::begin(bool timeRep){ 83 begin(timeRep, LOW_POWER); 75 84 } 76 85 … … 132 141 133 142 /********************************************************************************************************************** 134 *Description: Function for getting time (hours, minutes and seconds). This function fills a structure called local_time143 *Description: Function for getting time (hours, minutes and seconds). This function fills a structure called time 135 144 accessible in the class RTCInt. 136 145 *Input Parameters: None … … 141 150 unsigned int hour=0, h=0; 142 151 143 local_time.hour = getHour();152 time.hour = getHour(); 144 153 if(time_Mode == TIME_H12) 145 154 { 146 155 h=RTC->MODE2.CLOCK.bit.HOUR; 147 156 while (RTCSync()); 148 local_time.Tmode = h & 0x10;157 time.Tmode = h & 0x10; 149 158 } 150 local_time.minute = getMinute();151 local_time.second = getSecond();159 time.minute = getMinute(); 160 time.second = getSecond(); 152 161 } 153 162 … … 219 228 220 229 /********************************************************************************************************************** 221 *Description: Function for getting date (day, month and year). This function fills a structure called local_date230 *Description: Function for getting date (day, month and year). This function fills a structure called date 222 231 accessible in the class RTCInt. 223 232 *Input Parameters: None … … 226 235 void RTCInt::getDate(void) 227 236 { 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(); 231 240 } 232 241 … … 315 324 /********************************************************************************************************************** 316 325 *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. 318 327 *Input Parameters: None 319 328 *Return Parameter: None … … 321 330 void RTCInt::setTime(void) 322 331 { 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); 326 335 } 327 336 … … 397 406 /********************************************************************************************************************** 398 407 *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. 400 409 *Input Parameters: None 401 410 *Return Parameter: None … … 403 412 void RTCInt::setDate(void) 404 413 { 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); 408 417 } 409 418 … … 461 470 /********************************************************************************************************************** 462 471 *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, values464 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. 465 474 *Input Parameters: None 466 475 *Return Parameter: None … … 474 483 break; 475 484 case SEC : 476 RTC->MODE2.Mode2Alarm->ALARM.bit.SECOND= local_time.second;485 RTC->MODE2.Mode2Alarm->ALARM.bit.SECOND= time.second; 477 486 while (RTCSync()); 478 487 break; 479 488 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; 483 492 while (RTCSync()); 484 493 break; 485 494 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; 491 500 while (RTCSync()); 492 501 break; 493 502 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; 501 510 while (RTCSync()); 502 511 break; 503 512 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; 513 522 while (RTCSync()); 514 523 break; 515 524 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; 527 536 while (RTCSync()); 528 537 break;
Note:
See TracChangeset
for help on using the changeset viewer.