summaryrefslogtreecommitdiff
path: root/firmware/drivers/rtc.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/drivers/rtc.c')
-rw-r--r--firmware/drivers/rtc.c50
1 files changed, 44 insertions, 6 deletions
diff --git a/firmware/drivers/rtc.c b/firmware/drivers/rtc.c
index 0e6d68eb1a..6458092348 100644
--- a/firmware/drivers/rtc.c
+++ b/firmware/drivers/rtc.c
@@ -23,24 +23,62 @@
23#include "kernel.h" 23#include "kernel.h"
24#include "system.h" 24#include "system.h"
25#include "pcf50606.h" 25#include "pcf50606.h"
26#include "pcf50605.h"
26#include <stdbool.h> 27#include <stdbool.h>
27 28
28#define RTC_ADR 0xd0 29#define RTC_ADR 0xd0
29#define RTC_DEV_WRITE (RTC_ADR | 0x00) 30#define RTC_DEV_WRITE (RTC_ADR | 0x00)
30#define RTC_DEV_READ (RTC_ADR | 0x01) 31#define RTC_DEV_READ (RTC_ADR | 0x01)
31 32
32#if CONFIG_RTC == RTC_PCF50606 33#if CONFIG_RTC == RTC_PCF50605
33void rtc_init(void) 34void rtc_init(void)
34{ 35{
35} 36}
36int rtc_read_datetime(unsigned char* buf) { 37int rtc_read_datetime(unsigned char* buf)
38{
37 int rc; 39 int rc;
38 int oldlevel = set_irq_level(HIGHEST_IRQ_LEVEL); 40 int old_irq_level = set_irq_level(HIGHEST_IRQ_LEVEL);
39
40 rc = pcf50606_read_multiple(0x0a, buf, 7);
41 41
42 set_irq_level(oldlevel); 42 rc = pcf50605_read_multiple(0x0a, buf, 7);
43
44 set_irq_level(old_irq_level);
45
46 return rc;
47}
48
49
50int rtc_write_datetime(unsigned char* buf)
51{
52 int i;
53 int old_irq_level = set_irq_level(HIGHEST_IRQ_LEVEL);
54
55 for (i=0;i<7;i++) {
56 pcf50605_write(0x0a+i, buf[i]);
57 }
58
59 set_irq_level(old_irq_level);
60
61 return 1;
62}
63#elif CONFIG_RTC == RTC_PCF50606
64static int last_tick;
65static char rtc_buf[7];
66void rtc_init(void)
67{
68 last_tick = 0;
69}
43 70
71int rtc_read_datetime(unsigned char* buf) {
72 int rc;
73 if (last_tick + HZ/2 < current_tick) {
74 int oldlevel = set_irq_level(HIGHEST_IRQ_LEVEL);
75 last_tick = current_tick;
76 rc = pcf50606_read_multiple(0x0a, rtc_buf, 7);
77 set_irq_level(oldlevel);
78 } else {
79 rc = 7;
80 }
81 memcpy(buf, rtc_buf, 7);
44 return rc; 82 return rc;
45} 83}
46 84