Move intrinsic RTC implmentation differences to driver files

Some drivers set tm_wday just fine and do not need it coerced to
be correct. Others set tm_yday, so don't overwrite what the driver
sets; just zero it inside if it can't fill the field. Move calls
to set_day_of_week() to the sorts of drivers that presumably
required the hammer (FS#11814) in get_time() where the weekday
isn't locked to the date.

Change-Id: Idd0ded6bfc9d9f48fcc1a6074068164c42fcf24a
This commit is contained in:
Michael Sevakis 2017-01-25 19:32:15 -05:00
parent 783c77531c
commit 58b849c451
15 changed files with 54 additions and 22 deletions

View file

@ -71,9 +71,6 @@ struct tm *get_time(void)
/* Once per second, 1/10th of a second off */
timeout = HZ * (current_tick / HZ + 1) + HZ / 5;
rtc_read_datetime(&tm);
set_day_of_week(&tm);
tm.tm_yday = 0; /* Not implemented for now */
tm.tm_isdst = -1; /* Not implemented for now */
}
#else /* No RTC */

View file

@ -23,6 +23,7 @@
#include "pcf50606.h"
#include "pcf50635.h"
#include "pmu-target.h"
#include "timefuncs.h"
void rtc_init(void)
{
@ -49,10 +50,12 @@ int rtc_read_datetime(struct tm *tm)
tm->tm_sec = buf[0];
tm->tm_min = buf[1];
tm->tm_hour = buf[2];
tm->tm_wday = buf[3];
tm->tm_mday = buf[4];
tm->tm_mon = buf[5] - 1;
tm->tm_year = buf[6] + 100;
tm->tm_yday = 0; /* Not implemented for now */
set_day_of_week(tm);
return rc;
}

View file

@ -21,6 +21,7 @@
#include "rtc.h"
#include "logf.h"
#include "sw_i2c.h"
#include "timefuncs.h"
#define RTC_ADDR 0xD0
@ -122,10 +123,12 @@ int rtc_read_datetime(struct tm *tm)
tm->tm_sec = BCD2DEC(buf[0] & 0x7f);
tm->tm_min = BCD2DEC(buf[1] & 0x7f);
tm->tm_hour = BCD2DEC(buf[2] & 0x3f);
tm->tm_wday = BCD2DEC(buf[3] & 0x7) - 1; /* timefuncs wants 0..6 for wday */
tm->tm_mday = BCD2DEC(buf[4] & 0x3f);
tm->tm_mon = BCD2DEC(buf[5] & 0x1f) - 1;
tm->tm_year = BCD2DEC(buf[6]) + 100;
tm->tm_yday = 0; /* Not implemented for now */
set_day_of_week(tm);
return rc;
}

View file

@ -25,7 +25,7 @@
#include "kernel.h"
#include "system.h"
#include "i2c-pp.h"
#include <stdbool.h>
#include "timefuncs.h"
/*RTC_E8564's slave address is 0x51*/
#define RTC_ADDR 0x51
@ -83,9 +83,11 @@ int rtc_read_datetime(struct tm *tm)
tm->tm_min = BCD2DEC(buf[1] & 0x7f);
tm->tm_hour = BCD2DEC(buf[2] & 0x3f);
tm->tm_mday = BCD2DEC(buf[3] & 0x3f);
tm->tm_wday = BCD2DEC(buf[4] & 0x7);
tm->tm_mon = BCD2DEC(buf[5] & 0x1f) - 1;
tm->tm_year = BCD2DEC(buf[6]) + 100;
tm->tm_yday = 0; /* Not implemented for now */
set_day_of_week(tm);
return read;
}

View file

@ -23,7 +23,7 @@
#include "rtc.h"
#include "kernel.h"
#include "system.h"
#include <stdbool.h>
#include "timefuncs.h"
#define RTC_ADR 0xd0
#define RTC_DEV_WRITE (RTC_ADR | 0x00)
@ -257,14 +257,12 @@ int rtc_read_datetime(struct tm *tm)
tm->tm_sec = BCD2DEC(buf[0] & 0x7f);
tm->tm_min = BCD2DEC(buf[1] & 0x7f);
tm->tm_hour = BCD2DEC(buf[2] & 0x3f);
tm->tm_wday = BCD2DEC(buf[3] & 0x7);
tm->tm_mday = BCD2DEC(buf[4] & 0x3f);
tm->tm_mon = BCD2DEC(buf[5] & 0x1f) - 1;
tm->tm_year = BCD2DEC(buf[6]) + 100;
tm->tm_yday = 0; /* Not implemented for now */
/* Adjust weekday */
if (tm->tm_wday == 7)
tm->tm_wday = 0;
set_day_of_week(tm);
return rc;
}

View file

@ -22,6 +22,7 @@
#include "logf.h"
#include "sw_i2c.h"
#include "i2c-pp.h"
#include "timefuncs.h"
/* The RTC chip is unknown, the information about it was gathered by
* reverse engineering the bootloader.
@ -140,10 +141,12 @@ int rtc_read_datetime(struct tm *tm)
tm->tm_sec = buf[6];
tm->tm_min = buf[5];
tm->tm_hour = buf[4];
tm->tm_wday = buf[3];
tm->tm_mday = buf[2];
tm->tm_mon = buf[1] - 1;
tm->tm_year = buf[0] + 100;
tm->tm_yday = 0; /* Not implemented for now */
set_day_of_week(tm);
return rc;
}

View file

@ -24,7 +24,7 @@
#include "kernel.h"
#include "system.h"
#include "pcf50605.h"
#include <stdbool.h>
#include "timefuncs.h"
/* Values which each disable one alarm time register */
static const char alarm_disable[] = {
@ -49,10 +49,12 @@ int rtc_read_datetime(struct tm *tm)
tm->tm_sec = buf[0];
tm->tm_min = buf[1];
tm->tm_hour = buf[2];
tm->tm_wday = buf[3];
tm->tm_mday = buf[4];
tm->tm_mon = buf[5] - 1;
tm->tm_year = buf[6] + 100;
tm->tm_yday = 0; /* Not implemented for now */
set_day_of_week(tm);
return rc;
}

View file

@ -24,6 +24,7 @@
#include "kernel.h"
#include "system.h"
#include "pcf50606.h"
#include "timefuncs.h"
void rtc_init(void)
{
@ -47,9 +48,9 @@ int rtc_read_datetime(struct tm *tm)
tm->tm_sec = buf[0];
tm->tm_min = buf[1];
tm->tm_hour = buf[2];
tm->tm_wday = buf[3];
tm->tm_mday = buf[4];
tm->tm_mon = buf[5] - 1;
tm->tm_yday = 0; /* Not implemented for now */
#ifdef IRIVER_H300_SERIES
/* Special kludge to coexist with the iriver firmware. The iriver firmware
stores the date as 1965+nn, and allows a range of 1980..2064. We use
@ -60,6 +61,8 @@ int rtc_read_datetime(struct tm *tm)
tm->tm_year = buf[6] + 100;
#endif /* IRIVER_H300_SERIES */
set_day_of_week(tm);
return rc;
}

View file

@ -22,6 +22,7 @@
#include "config.h"
#include "spi.h"
#include "rtc.h"
#include "timefuncs.h"
/* Choose one of: */
#define ADDR_READ 0x04
@ -48,10 +49,12 @@ int rtc_read_datetime(struct tm *tm)
tm->tm_sec = buf[0];
tm->tm_min = buf[1];
tm->tm_hour = buf[2];
tm->tm_wday = buf[3];
tm->tm_mday = buf[4];
tm->tm_mon = buf[5] - 1;
tm->tm_year = buf[6] + 100;
tm->tm_yday = 0; /* Not implemented for now */
set_day_of_week(tm);
return 1;
}

View file

@ -23,6 +23,7 @@
#include "config.h"
#include "rtc.h"
#include "i2c-coldfire.h"
#include "timefuncs.h"
/* Driver for the Seiko S35380A real-time clock chip with i2c interface
@ -188,10 +189,12 @@ int rtc_read_datetime(struct tm *tm)
tm->tm_sec = buf[TIME_SECOND];
tm->tm_min = buf[TIME_MINUTE];
tm->tm_hour = buf[TIME_HOUR];
tm->tm_wday = buf[TIME_WEEKDAY];
tm->tm_mday = buf[TIME_DAY];
tm->tm_mon = buf[TIME_MONTH] - 1;
tm->tm_year = buf[TIME_YEAR] + 100;
tm->tm_yday = 0; /* Not implemented for now */
set_day_of_week(tm);
return ret;
}

View file

@ -22,6 +22,7 @@
#include "config.h"
#include "rtc.h"
#include "i2c-s5l8700.h"
#include "timefuncs.h"
/* Driver for the Seiko S35390A real-time clock chip with i2c interface
@ -75,10 +76,12 @@ int rtc_read_datetime(struct tm *tm)
tm->tm_sec = buf[6];
tm->tm_min = buf[5];
tm->tm_hour = buf[4];
tm->tm_wday = buf[3];
tm->tm_mday = buf[2];
tm->tm_mon = buf[1] - 1;
tm->tm_year = buf[0] + 100;
tm->tm_yday = 0; /* Not implemented for now */
set_day_of_week(tm);
return ret;
}

View file

@ -23,6 +23,7 @@
#include "rtc.h"
#include "kernel.h"
#include "system.h"
#include "timefuncs.h"
void rtc_init(void)
{
@ -35,10 +36,12 @@ int rtc_read_datetime(struct tm *tm)
tm->tm_sec = BCD2DEC(BCDSEC);
tm->tm_min = BCD2DEC(BCDMIN);
tm->tm_hour = BCD2DEC(BCDHOUR);
tm->tm_wday = BCD2DEC(BCDDAY) - 1; /* timefuncs wants 0..6 for wday */
tm->tm_mday = BCD2DEC(BCDDATE);
tm->tm_mon = BCD2DEC(BCDMON) - 1;
tm->tm_year = BCD2DEC(BCDYEAR) + 100;
tm->tm_yday = 0; /* Not implemented for now */
set_day_of_week(tm);
return 1;
}

View file

@ -108,6 +108,9 @@ struct tm *gmtime_r(const time_t *timep, struct tm *tm)
/* Second */
tm->tm_sec = seconds;
tm->tm_yday = 0; /* Not implemented for now */
tm->tm_isdst = -1; /* Not implemented for now */
return tm;
}

View file

@ -23,6 +23,7 @@
#include "kernel.h"
#include "system.h"
#include "pmu-target.h"
#include "timefuncs.h"
void rtc_init(void)
{
@ -41,10 +42,12 @@ int rtc_read_datetime(struct tm *tm)
tm->tm_sec = buf[0];
tm->tm_min = buf[1];
tm->tm_hour = buf[2];
tm->tm_wday = buf[3];
tm->tm_mday = buf[4];
tm->tm_mon = buf[5] - 1;
tm->tm_year = buf[6] + 100;
tm->tm_yday = 0; /* Not implemented for now */
set_day_of_week(tm);
return 0;
}

View file

@ -23,6 +23,7 @@
#include "kernel.h"
#include "system.h"
#include "pmu-target.h"
#include "timefuncs.h"
void rtc_init(void)
{
@ -41,10 +42,12 @@ int rtc_read_datetime(struct tm *tm)
tm->tm_sec = buf[0];
tm->tm_min = buf[1];
tm->tm_hour = buf[2];
tm->tm_wday = buf[3];
tm->tm_mday = buf[4];
tm->tm_mon = buf[5] - 1;
tm->tm_year = buf[6] + 100;
tm->tm_yday = 0; /* Not implemented for now */
set_day_of_week(tm);
return 0;
}