This repository has been archived on 2022-01-28. You can view files and clone it, but cannot push or open issues or pull requests.
Marlin-Artillery-M600/Marlin/frameworks/CMSIS/LPC1768/lib/chanfs/rtc176x.c
Chris Pepper a5cf3a190c bugfix-2.0.x critical fix (#7401)
* Fix mistake in gitignore file and add in missing core files.

The missing leading slash on "lib" meant all folders names lib in the directory tree are ignored, rather than just the top level PlatformIO lib folder

* Add LiquidCrystal Library and associated headers modified to compile.
2017-08-31 18:23:44 -05:00

92 lines
2 KiB
C

/*------------------------------------------------------------------------/
/ LPC176x RTC control module
/-------------------------------------------------------------------------/
/
/ Copyright (C) 2011, ChaN, all right reserved.
/
/ * This software is a free software and there is NO WARRANTY.
/ * No restriction on use. You can use, modify and redistribute it for
/ personal, non-profit or commercial products UNDER YOUR RESPONSIBILITY.
/ * Redistributions of source code must retain the above copyright notice.
/
/-------------------------------------------------------------------------*/
#include "rtc176x.h"
int rtc_initialize (void)
{
/* Enable PCLK to the RTC */
__set_PCONP(PCRTC, 1);
/* Start RTC with external XTAL */
RTC_CCR = 0x11;
return 1;
}
int rtc_gettime (RTC *rtc) /* 1:RTC valid, 0:RTC volatiled */
{
DWORD d, t;
do {
t = RTC_CTIME0;
d = RTC_CTIME1;
} while (t != RTC_CTIME0 || d != RTC_CTIME1);
if (RTC_AUX & _BV(4)) { /* If power fail has been detected, return default time. */
rtc->sec = 0; rtc->min = 0; rtc->hour = 0;
rtc->wday = 0; rtc->mday = 1; rtc->month = 1; rtc->year = 2014;
return 0;
}
rtc->sec = t & 63;
rtc->min = (t >> 8) & 63;
rtc->hour = (t >> 16) & 31;
rtc->wday = (t >> 24) & 7;
rtc->mday = d & 31;
rtc->month = (d >> 8) & 15;
rtc->year = (d >> 16) & 4095;
return 1;
}
int rtc_settime (const RTC *rtc)
{
RTC_CCR = 0x12; /* Stop RTC */
/* Update RTC registers */
RTC_SEC = rtc->sec;
RTC_MIN = rtc->min;
RTC_HOUR = rtc->hour;
RTC_DOW = rtc->wday;
RTC_DOM = rtc->mday;
RTC_MONTH = rtc->month;
RTC_YEAR = rtc->year;
RTC_AUX = _BV(4); /* Clear power fail flag */
RTC_CCR = 0x11; /* Restart RTC, Disable calibration feature */
return 1;
}
DWORD get_fattime (void) {
RTC rtc;
/* Get local time */
rtc_gettime(&rtc);
/* Pack date and time into a DWORD variable */
return ((DWORD)(rtc.year - 1980) << 25)
| ((DWORD)rtc.month << 21)
| ((DWORD)rtc.mday << 16)
| ((DWORD)rtc.hour << 11)
| ((DWORD)rtc.min << 5)
| ((DWORD)rtc.sec >> 1);
}