return len;
}
+/* Return the number of seconds of the curent day */
+uint32_t rtc_pcf85363_daytime_to_seconds(struct rtc_time* time)
+{
+ uint32_t seconds = ((time->sec & 0x0F) + ((time->sec & 0xF0) >> 4) * 10);
+ seconds += ((time->min & 0x0F) + ((time->min & 0xF0) >> 4) * 10) * 60;
+ seconds += ((time->hour & 0x0F) + ((time->hour & 0xF0) >> 4) * 10) * 3600;
+ return seconds;
+}
+
+/* Update the hours, minutes and seconds fields of the given time according to the number
+ * of seconds given in second argument.
+ * LPC1224 uses a Cortex M0, which has no modulo or division instruction, so this solution
+ * limits the calls to the ROM division routines to 5.
+ */
+void rtc_pcf85363_seconds_to_daytime(struct rtc_time* time, uint32_t seconds)
+{
+ uint32_t sec_tmp, min_tmp, hour_tmp;
+ hour_tmp = seconds / 3600;
+ seconds -= 3600 * hour_tmp;
+ min_tmp = seconds / 60;
+ sec_tmp = seconds - 60 * min_tmp;
+
+ time->hour = (hour_tmp / 10) << 4;
+ time->hour += (hour_tmp - (time->hour >> 4) * 10);
+
+ time->min = (min_tmp / 10) << 4;
+ time->min += (min_tmp - (time->min >> 4) * 10);
+
+ time->sec = (sec_tmp / 10) << 4;
+ time->sec += (sec_tmp - (time->sec >> 4) * 10);
+}
+
/* Compare two times
* Return 0 if they are equal, 1 if t1 > t2, and -1 if t1 < t2
*/
};
-/* Time Read
- * When performing a time read operation, all time registers have to be read at once as
- * a copy of the internal values is made by the device to a temporary buffer at the
- * beginning of the read for data coherency.
- */
+/* Time Read from RTC */
int rtc_pcf85363_time_read(struct rtc_pcf85363a_config* conf, struct rtc_time* time);
-/* Time Write
- * A time write operation has to be done in one go for all time registers for time data
- * coherency.
- * Also, when performing a time write, the STOP bit must be set and the prescalers should
- * be cleared.
- */
+/* Time Write to RTC */
int rtc_pcf85363_time_write(struct rtc_pcf85363a_config* conf, struct rtc_time* time);
-/* Get one of the timestamps
- */
+/* Get one of the timestamps */
int rtc_pcf85363_get_timestamp(struct rtc_pcf85363a_config* conf,
struct rtc_timestamp* tstmp, uint8_t timestamp_num);
/* Erase timestamps */
/* Print the time to a usable string, in a unix format which "date" could understand. */
int rtc_pcf85363_time_to_str(struct rtc_time* time, char* str, int size);
+/* Return the number of seconds of the curent day */
+uint32_t rtc_pcf85363_daytime_to_seconds(struct rtc_time* time);
+
+/* Update the hours, minutes and seconds fields of the given time according to the number
+ * of seconds given in second argument. */
+void rtc_pcf85363_seconds_to_daytime(struct rtc_time* time, uint32_t seconds);
+
/* Compare two times
* Return 0 if they are equal, 1 if t1 > t2, and -1 if t1 < t2
*/