summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Nielsen Feltzing <linus@haxx.se>2002-06-24 13:23:01 +0000
committerLinus Nielsen Feltzing <linus@haxx.se>2002-06-24 13:23:01 +0000
commit740eb36c10dd43b2307767f6101833d960399438 (patch)
tree690b13f3369024e3ce878e85a21868edfe5d4fdb
parentc7fee9bcb26f01d7d483f3b5776eeb59838902c0 (diff)
downloadrockbox-740eb36c10dd43b2307767f6101833d960399438.zip
rockbox-740eb36c10dd43b2307767f6101833d960399438.tar.gz
rockbox-740eb36c10dd43b2307767f6101833d960399438.tar.bz2
rockbox-740eb36c10dd43b2307767f6101833d960399438.tar.xz
Added first RTC functions
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@1151 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/config-recorder.h3
-rw-r--r--firmware/drivers/rtc.c73
-rw-r--r--firmware/drivers/rtc.h27
3 files changed, 103 insertions, 0 deletions
diff --git a/firmware/config-recorder.h b/firmware/config-recorder.h
index 6231172..a5ae855 100644
--- a/firmware/config-recorder.h
+++ b/firmware/config-recorder.h
@@ -6,3 +6,6 @@
/* define this if you have the Recorder's 10-key keyboard */
#define HAVE_RECORDER_KEYPAD 1
+
+/* define this if you have a real-time clock */
+#define HAVE_RTC 1
diff --git a/firmware/drivers/rtc.c b/firmware/drivers/rtc.c
new file mode 100644
index 0000000..66b37fc
--- /dev/null
+++ b/firmware/drivers/rtc.c
@@ -0,0 +1,73 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2002 by Linus Nielsen Feltzing
+ *
+ * All files in this archive are subject to the GNU General Public License.
+ * See the file COPYING in the source tree root for full license agreement.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+#include "config.h"
+#ifdef HAVE_RTC
+#include "i2c.h"
+#include "rtc.h"
+
+#define RTC_ADR 0xd0
+#define RTC_DEV_WRITE (RTC_ADR | 0x00)
+#define RTC_DEV_READ (RTC_ADR | 0x01)
+
+int rtc_write(unsigned char address, unsigned char value)
+{
+ int ret = 0;
+ unsigned char buf[2];
+
+ i2c_begin();
+
+ buf[0] = address;
+ buf[1] = value;
+
+ /* send run command */
+ if (i2c_write(RTC_DEV_WRITE,buf,2))
+ {
+ ret = -1;
+ }
+
+ i2c_end();
+ return ret;
+}
+
+
+int rtc_read(unsigned char address)
+{
+ int value = -1;
+ unsigned char buf[1];
+
+ i2c_begin();
+
+ buf[0] = address;
+
+ /* send run command */
+ if (i2c_write(RTC_DEV_READ,buf,1) >= 0)
+ {
+ i2c_start();
+ i2c_outb(RTC_DEV_READ);
+ if (i2c_getack())
+ {
+ value = i2c_inb(1);
+ }
+ }
+
+ i2c_end();
+ return value;
+}
+
+#endif
diff --git a/firmware/drivers/rtc.h b/firmware/drivers/rtc.h
new file mode 100644
index 0000000..00b4db5
--- /dev/null
+++ b/firmware/drivers/rtc.h
@@ -0,0 +1,27 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2002 by Linus Nielsen Feltzing
+ *
+ * All files in this archive are subject to the GNU General Public License.
+ * See the file COPYING in the source tree root for full license agreement.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+#ifndef _RTC_H_
+#define _RTC_H_
+
+#ifdef HAVE_RTC
+int rtc_read(unsigned char address);
+int rtc_write(unsigned char address, unsigned char value);
+#endif
+
+#endif