forked from len0rd/rockbox
Move the RTC read throttling to a smarter place
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8912 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
63c0d1dd9c
commit
6668b65ef2
2 changed files with 21 additions and 23 deletions
|
|
@ -20,6 +20,7 @@
|
||||||
#include <stdio.h> /* get NULL */
|
#include <stdio.h> /* get NULL */
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "kernel.h"
|
||||||
#include "rtc.h"
|
#include "rtc.h"
|
||||||
#include "timefuncs.h"
|
#include "timefuncs.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
@ -42,25 +43,29 @@ bool valid_time(const struct tm *tm)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int last_tick = 0;
|
||||||
|
|
||||||
struct tm *get_time(void)
|
struct tm *get_time(void)
|
||||||
{
|
{
|
||||||
#ifndef SIMULATOR
|
#ifndef SIMULATOR
|
||||||
#ifdef CONFIG_RTC
|
#ifdef CONFIG_RTC
|
||||||
char rtcbuf[7];
|
|
||||||
|
|
||||||
rtc_read_datetime(rtcbuf);
|
/* Don't read the RTC more than 4 times per second */
|
||||||
|
if (last_tick + HZ/4 < current_tick) {
|
||||||
|
char rtcbuf[7];
|
||||||
|
rtc_read_datetime(rtcbuf);
|
||||||
|
|
||||||
tm.tm_sec = ((rtcbuf[0] & 0x70) >> 4) * 10 + (rtcbuf[0] & 0x0f);
|
tm.tm_sec = ((rtcbuf[0] & 0x70) >> 4) * 10 + (rtcbuf[0] & 0x0f);
|
||||||
tm.tm_min = ((rtcbuf[1] & 0x70) >> 4) * 10 + (rtcbuf[1] & 0x0f);
|
tm.tm_min = ((rtcbuf[1] & 0x70) >> 4) * 10 + (rtcbuf[1] & 0x0f);
|
||||||
tm.tm_hour = ((rtcbuf[2] & 0x30) >> 4) * 10 + (rtcbuf[2] & 0x0f);
|
tm.tm_hour = ((rtcbuf[2] & 0x30) >> 4) * 10 + (rtcbuf[2] & 0x0f);
|
||||||
tm.tm_wday = rtcbuf[3] & 0x07;
|
tm.tm_wday = rtcbuf[3] & 0x07;
|
||||||
tm.tm_mday = ((rtcbuf[4] & 0x30) >> 4) * 10 + (rtcbuf[4] & 0x0f);
|
tm.tm_mday = ((rtcbuf[4] & 0x30) >> 4) * 10 + (rtcbuf[4] & 0x0f);
|
||||||
tm.tm_mon = ((rtcbuf[5] & 0x10) >> 4) * 10 + (rtcbuf[5] & 0x0f) - 1;
|
tm.tm_mon = ((rtcbuf[5] & 0x10) >> 4) * 10 + (rtcbuf[5] & 0x0f) - 1;
|
||||||
tm.tm_year = ((rtcbuf[6] & 0xf0) >> 4) * 10 + (rtcbuf[6] & 0x0f) + 100;
|
tm.tm_year = ((rtcbuf[6] & 0xf0) >> 4) * 10 + (rtcbuf[6] & 0x0f) + 100;
|
||||||
|
|
||||||
tm.tm_yday = 0; /* Not implemented for now */
|
tm.tm_yday = 0; /* Not implemented for now */
|
||||||
tm.tm_isdst = -1; /* Not implemented for now */
|
tm.tm_isdst = -1; /* Not implemented for now */
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
tm.tm_sec = 0;
|
tm.tm_sec = 0;
|
||||||
tm.tm_min = 0;
|
tm.tm_min = 0;
|
||||||
|
|
|
||||||
|
|
@ -61,24 +61,17 @@ int rtc_write_datetime(unsigned char* buf)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
#elif CONFIG_RTC == RTC_PCF50606
|
#elif CONFIG_RTC == RTC_PCF50606
|
||||||
static int last_tick;
|
|
||||||
static char rtc_buf[7];
|
|
||||||
void rtc_init(void)
|
void rtc_init(void)
|
||||||
{
|
{
|
||||||
last_tick = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int rtc_read_datetime(unsigned char* buf) {
|
int rtc_read_datetime(unsigned char* buf) {
|
||||||
int rc;
|
int rc;
|
||||||
if (last_tick + HZ/2 < current_tick) {
|
int oldlevel = set_irq_level(HIGHEST_IRQ_LEVEL);
|
||||||
int oldlevel = set_irq_level(HIGHEST_IRQ_LEVEL);
|
|
||||||
last_tick = current_tick;
|
rc = pcf50606_read_multiple(0x0a, buf, 7);
|
||||||
rc = pcf50606_read_multiple(0x0a, rtc_buf, 7);
|
|
||||||
set_irq_level(oldlevel);
|
set_irq_level(oldlevel);
|
||||||
} else {
|
|
||||||
rc = 7;
|
|
||||||
}
|
|
||||||
memcpy(buf, rtc_buf, 7);
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue