summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMoshe Piekarski <dev.rockbox@melachim.net>2021-05-05 12:52:19 -0400
committerSolomon Peachy <pizza@shaftnet.org>2021-05-12 10:52:03 +0000
commitb895fb66437655888386db82aa6434b0f5bfc0d6 (patch)
tree5a59015999db8a94740940a76b50a4dea0f2e556
parent3f26fcf34001197ed267fa1ad549095aae49c88e (diff)
downloadrockbox-b895fb66437655888386db82aa6434b0f5bfc0d6.tar.gz
rockbox-b895fb66437655888386db82aa6434b0f5bfc0d6.tar.bz2
rockbox-b895fb66437655888386db82aa6434b0f5bfc0d6.zip
Add tm->yday to RTC ports missing it
Change-Id: I86882262bafb8d06f925aabb87ebd1b5dcb0cd53
-rw-r--r--firmware/common/timefuncs.c16
-rw-r--r--firmware/drivers/rtc/rtc_d2.c2
-rw-r--r--firmware/drivers/rtc/rtc_ds1339_ds3231.c2
-rw-r--r--firmware/drivers/rtc/rtc_e8564.c2
-rw-r--r--firmware/drivers/rtc/rtc_mr100.c2
-rw-r--r--firmware/drivers/rtc/rtc_pcf50605.c2
-rw-r--r--firmware/drivers/rtc/rtc_pcf50606.c3
-rw-r--r--firmware/drivers/rtc/rtc_rx5x348ab.c2
-rw-r--r--firmware/drivers/rtc/rtc_s35380a.c2
-rw-r--r--firmware/drivers/rtc/rtc_s35390a.c2
-rw-r--r--firmware/drivers/rtc/rtc_s3c2440.c2
-rw-r--r--firmware/include/timefuncs.h1
-rw-r--r--firmware/target/arm/s5l8700/ipodnano2g/rtc-nano2g.c2
-rw-r--r--firmware/target/arm/s5l8702/ipod6g/rtc-6g.c2
14 files changed, 30 insertions, 12 deletions
diff --git a/firmware/common/timefuncs.c b/firmware/common/timefuncs.c
index 50addad27a..108431753a 100644
--- a/firmware/common/timefuncs.c
+++ b/firmware/common/timefuncs.c
@@ -135,5 +135,21 @@ void set_day_of_week(struct tm *tm)
if(m == 0 || m == 1) y--;
tm->tm_wday = (d + mo[m] + y + y/4 - y/100 + y/400) % 7;
}
+
+void set_day_of_year(struct tm *tm)
+{
+ int y=tm->tm_year+1900;
+ int d=tm->tm_mday;
+ int m=tm->tm_mon;
+ d+=m*30;
+ if( ( (m>1) && !(y%4) ) && ( (y%100) || !(y%400) ) )
+ d++;
+ if(m>6)
+ {
+ d+=4;
+ m-=7;
+ }
+ tm->tm_yday = d + ((m+1) /2);
+}
#endif /* CONFIG_RTC */
diff --git a/firmware/drivers/rtc/rtc_d2.c b/firmware/drivers/rtc/rtc_d2.c
index 1d202410e2..726564a255 100644
--- a/firmware/drivers/rtc/rtc_d2.c
+++ b/firmware/drivers/rtc/rtc_d2.c
@@ -53,9 +53,9 @@ int rtc_read_datetime(struct tm *tm)
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);
+ set_day_of_year(tm);
return rc;
}
diff --git a/firmware/drivers/rtc/rtc_ds1339_ds3231.c b/firmware/drivers/rtc/rtc_ds1339_ds3231.c
index 8f2a531e5f..b77e059595 100644
--- a/firmware/drivers/rtc/rtc_ds1339_ds3231.c
+++ b/firmware/drivers/rtc/rtc_ds1339_ds3231.c
@@ -126,9 +126,9 @@ int rtc_read_datetime(struct tm *tm)
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);
+ set_day_of_year(tm);
return rc;
}
diff --git a/firmware/drivers/rtc/rtc_e8564.c b/firmware/drivers/rtc/rtc_e8564.c
index 4bb61410db..775ff86728 100644
--- a/firmware/drivers/rtc/rtc_e8564.c
+++ b/firmware/drivers/rtc/rtc_e8564.c
@@ -86,9 +86,9 @@ int rtc_read_datetime(struct tm *tm)
tm->tm_mday = BCD2DEC(buf[3] & 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);
+ set_day_of_year(tm);
return read;
}
diff --git a/firmware/drivers/rtc/rtc_mr100.c b/firmware/drivers/rtc/rtc_mr100.c
index 6e1b0b5f40..2f44137e38 100644
--- a/firmware/drivers/rtc/rtc_mr100.c
+++ b/firmware/drivers/rtc/rtc_mr100.c
@@ -144,9 +144,9 @@ int rtc_read_datetime(struct tm *tm)
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);
+ set_day_of_year(tm);
return rc;
}
diff --git a/firmware/drivers/rtc/rtc_pcf50605.c b/firmware/drivers/rtc/rtc_pcf50605.c
index daa35fb13f..42ea15ff2e 100644
--- a/firmware/drivers/rtc/rtc_pcf50605.c
+++ b/firmware/drivers/rtc/rtc_pcf50605.c
@@ -52,9 +52,9 @@ int rtc_read_datetime(struct tm *tm)
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);
+ set_day_of_year(tm);
return rc;
}
diff --git a/firmware/drivers/rtc/rtc_pcf50606.c b/firmware/drivers/rtc/rtc_pcf50606.c
index 540ebfff06..16ae5a3e9c 100644
--- a/firmware/drivers/rtc/rtc_pcf50606.c
+++ b/firmware/drivers/rtc/rtc_pcf50606.c
@@ -56,7 +56,7 @@ int rtc_read_datetime(struct tm *tm)
tm->tm_hour = buf[2];
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
@@ -68,6 +68,7 @@ int rtc_read_datetime(struct tm *tm)
#endif /* IRIVER_H300_SERIES */
set_day_of_week(tm);
+ set_day_of_year(tm);
return rc;
}
diff --git a/firmware/drivers/rtc/rtc_rx5x348ab.c b/firmware/drivers/rtc/rtc_rx5x348ab.c
index 6d7b78b281..d95186e8be 100644
--- a/firmware/drivers/rtc/rtc_rx5x348ab.c
+++ b/firmware/drivers/rtc/rtc_rx5x348ab.c
@@ -52,9 +52,9 @@ int rtc_read_datetime(struct tm *tm)
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);
+ set_day_of_year(tm);
return 1;
}
diff --git a/firmware/drivers/rtc/rtc_s35380a.c b/firmware/drivers/rtc/rtc_s35380a.c
index f32c431990..6deaed6354 100644
--- a/firmware/drivers/rtc/rtc_s35380a.c
+++ b/firmware/drivers/rtc/rtc_s35380a.c
@@ -192,9 +192,9 @@ int rtc_read_datetime(struct tm *tm)
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);
+ set_day_of_year(tm);
return ret;
}
diff --git a/firmware/drivers/rtc/rtc_s35390a.c b/firmware/drivers/rtc/rtc_s35390a.c
index b82029a114..6e69073254 100644
--- a/firmware/drivers/rtc/rtc_s35390a.c
+++ b/firmware/drivers/rtc/rtc_s35390a.c
@@ -79,9 +79,9 @@ int rtc_read_datetime(struct tm *tm)
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);
+ set_day_of_year(tm);
return ret;
}
diff --git a/firmware/drivers/rtc/rtc_s3c2440.c b/firmware/drivers/rtc/rtc_s3c2440.c
index 6cd34f0e23..71f99ac6f4 100644
--- a/firmware/drivers/rtc/rtc_s3c2440.c
+++ b/firmware/drivers/rtc/rtc_s3c2440.c
@@ -39,9 +39,9 @@ int rtc_read_datetime(struct tm *tm)
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);
+ set_day_of_year(tm);
return 1;
}
diff --git a/firmware/include/timefuncs.h b/firmware/include/timefuncs.h
index 4c5f0fbb42..c72508e862 100644
--- a/firmware/include/timefuncs.h
+++ b/firmware/include/timefuncs.h
@@ -31,6 +31,7 @@ int set_time(const struct tm *tm);
#if CONFIG_RTC
bool valid_time(const struct tm *tm);
void set_day_of_week(struct tm *tm);
+void set_day_of_year(struct tm *tm);
#endif
#endif /* _TIMEFUNCS_H_ */
diff --git a/firmware/target/arm/s5l8700/ipodnano2g/rtc-nano2g.c b/firmware/target/arm/s5l8700/ipodnano2g/rtc-nano2g.c
index 6f6b58ca35..a14bffb81c 100644
--- a/firmware/target/arm/s5l8700/ipodnano2g/rtc-nano2g.c
+++ b/firmware/target/arm/s5l8700/ipodnano2g/rtc-nano2g.c
@@ -45,9 +45,9 @@ int rtc_read_datetime(struct tm *tm)
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);
+ set_day_of_year(tm);
return 0;
}
diff --git a/firmware/target/arm/s5l8702/ipod6g/rtc-6g.c b/firmware/target/arm/s5l8702/ipod6g/rtc-6g.c
index 384cded758..bf1b18035a 100644
--- a/firmware/target/arm/s5l8702/ipod6g/rtc-6g.c
+++ b/firmware/target/arm/s5l8702/ipod6g/rtc-6g.c
@@ -45,9 +45,9 @@ int rtc_read_datetime(struct tm *tm)
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);
+ set_day_of_year(tm);
return 0;
}