summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/powerpc/gen5200/tod
diff options
context:
space:
mode:
authorRalf Corsepius <ralf.corsepius@rtems.org>2005-12-31 05:09:26 +0000
committerRalf Corsepius <ralf.corsepius@rtems.org>2005-12-31 05:09:26 +0000
commitca680bc5890abe0d6bfe7eb4a40a0229f1b6bd36 (patch)
tree805a5ddce1250235d6133376ddabb5543eb2cf82 /c/src/lib/libbsp/powerpc/gen5200/tod
parentAdd BuildRoot. (diff)
downloadrtems-ca680bc5890abe0d6bfe7eb4a40a0229f1b6bd36.tar.bz2
New (CVS import Thomas Doerfler <Thomas.Doerfler@embedded-brains.de>'s
submission).
Diffstat (limited to 'c/src/lib/libbsp/powerpc/gen5200/tod')
-rw-r--r--c/src/lib/libbsp/powerpc/gen5200/tod/pcf8563.c247
-rw-r--r--c/src/lib/libbsp/powerpc/gen5200/tod/pcf8563.h118
-rw-r--r--c/src/lib/libbsp/powerpc/gen5200/tod/todcfg.c123
3 files changed, 488 insertions, 0 deletions
diff --git a/c/src/lib/libbsp/powerpc/gen5200/tod/pcf8563.c b/c/src/lib/libbsp/powerpc/gen5200/tod/pcf8563.c
new file mode 100644
index 0000000000..932e0004a3
--- /dev/null
+++ b/c/src/lib/libbsp/powerpc/gen5200/tod/pcf8563.c
@@ -0,0 +1,247 @@
+/*===============================================================*\
+| Project: RTEMS generic MPC5200 BSP |
++-----------------------------------------------------------------+
+| File: $File$
++-----------------------------------------------------------------+
+| Partially based on the code references which are named below. |
+| Adaptions, modifications, enhancements and any recent parts of |
+| the code are: |
+| Copyright (c) 2005 |
+| Embedded Brains GmbH |
+| Obere Lagerstr. 30 |
+| D-82178 Puchheim |
+| Germany |
+| rtems@embedded-brains.de |
++-----------------------------------------------------------------+
+| The license and distribution terms for this file may be |
+| found in the file LICENSE in this distribution or at |
+| |
+| http://www.rtems.com/license/LICENSE. |
+| |
++-----------------------------------------------------------------+
+| this file contains the tod driver for a Philips pcf8563 I2C RTC |
++-----------------------------------------------------------------+
+| date history ID |
+| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
+| 01.12.05 creation doe |
+|*****************************************************************|
+|*CVS information: |
+|*(the following information is created automatically, |
+|*do not edit here) |
+|*****************************************************************|
+|* $Log$
+|* Revision 1.3 2005/12/06 14:11:12 thomas
+|* added EB file headers
+|*
+ *
+|*****************************************************************|
+\*===============================================================*/
+/*
+ * This file interfaces with the real-time clock found in a
+ * Philips PCF8563 serial real-time clock chip.
+ * This RTC have I2C bus interface. BSP have to provide I2C bus primitives
+ * to make this driver working. getRegister and setRegister primitives is
+ * not used here to avoid multiple transactions over I2C bus (each transaction
+ * require significant time and error when date/time information red may
+ * occurs). ulControlPort contains I2C bus number; ulDataPort contains
+ * RTC I2C device address.
+ *
+ * Based on a ds1307 driver from:
+ *
+ * Copyright (C) 2000 OKTET Ltd., St.-Petersburg, Russia
+ * Author: Victor V. Vengerov <vvv@oktet.ru>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ *
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * @(#) ds1307.c,v 1.5 2004/04/21 10:42:52 ralf Exp
+ */
+
+#include <rtems.h>
+#include <libchip/rtc.h>
+#include <string.h>
+#include "../tod/pcf8563.h"
+#include "../include/i2c.h"
+
+/* Convert from/to Binary-Coded Decimal representation */
+#define From_BCD( _x ) ((((_x) >> 4) * 10) + ((_x) & 0x0F))
+#define To_BCD( _x ) ((((_x) / 10) << 4) + ((_x) % 10))
+
+/* pcf8563_initialize --
+ * Initialize PCF8563 real-time clock chip. If RTC is halted, this
+ * function resume counting.
+ *
+ * PARAMETERS:
+ * minor -- minor RTC device number
+ */
+void
+pcf8563_initialize(int minor)
+{
+ i2c_message_status status;
+ int try;
+ uint8_t ctrl1;
+ i2c_bus_number bus;
+ i2c_address addr;
+
+ bus = RTC_Table[minor].ulCtrlPort1;
+ addr = RTC_Table[minor].ulDataPort;
+
+ /* Read SECONDS register */
+ try = 0;
+ do {
+ status = i2c_wbrd(bus, addr, PCF8563_CONTROL1_ADR,
+ &ctrl1, sizeof(ctrl1));
+ try++;
+ } while ((status != I2C_SUCCESSFUL) && (try < 15));
+
+ /* If clock is halted, reset and start the clock */
+ if ((ctrl1 & PCF8563_CONTROL1_STOP) != 0)
+ {
+ uint8_t start[8];
+ memset(start, 0, sizeof(start));
+ start[0] = PCF8563_CONTROL1_ADR;
+ try = 0;
+ do {
+ status = i2c_write(bus, addr, start, 2);
+ } while ((status != I2C_SUCCESSFUL) && (try < 15));
+ }
+}
+
+/* pcf8563_get_time --
+ * read current time from PCF8563 real-time clock chip and convert it
+ * to the rtems_time_of_day structure.
+ *
+ * PARAMETERS:
+ * minor -- minor RTC device number
+ * time -- place to put return value (date and time)
+ *
+ * RETURNS:
+ * 0, if time obtained successfully
+ * -1, if error occured
+ */
+int
+pcf8563_get_time(int minor, rtems_time_of_day *time)
+{
+ i2c_bus_number bus;
+ i2c_address addr;
+ uint8_t info[10];
+ uint32_t v1, v2;
+ i2c_message_status status;
+ int try;
+
+ if (time == NULL)
+ return -1;
+
+ bus = RTC_Table[minor].ulCtrlPort1;
+ addr = RTC_Table[minor].ulDataPort;
+
+ memset(time, 0, sizeof(rtems_time_of_day));
+ try = 0;
+ do {
+ status = i2c_wbrd(bus, addr, PCF8563_SECOND_ADR, info, sizeof(info));
+ try++;
+ } while ((status != I2C_SUCCESSFUL) && (try < 10));
+
+ if (status != I2C_SUCCESSFUL)
+ {
+ return -1;
+ }
+
+ v1 = info[PCF8563_YEAR_ADR-PCF8563_SECOND_ADR];
+ v2 = From_BCD(v1);
+ if ((info[PCF8563_MONTH_ADR-PCF8563_SECOND_ADR]
+ & PCF8563_MONTH_CENTURY) == 0) {
+ time->year = 1900 + v2;
+ }
+ else {
+ time->year = 2000 + v2;
+ }
+
+ v1 = info[PCF8563_MONTH_ADR-PCF8563_SECOND_ADR] & PCF8563_MONTH_MASK;
+ time->month = From_BCD(v1);
+
+ v1 = info[PCF8563_DAY_ADR-PCF8563_SECOND_ADR] & PCF8563_DAY_MASK;
+ time->day = From_BCD(v1);
+
+ v1 = info[PCF8563_HOUR_ADR-PCF8563_SECOND_ADR] & PCF8563_HOUR_ADR;
+ time->hour = From_BCD(v1);
+
+ v1 = info[PCF8563_MINUTE_ADR-PCF8563_SECOND_ADR] & PCF8563_MINUTE_MASK;
+ time->minute = From_BCD(v1);
+
+ v1 = info[PCF8563_SECOND_ADR-PCF8563_SECOND_ADR] & PCF8563_SECOND_MASK;
+ time->second = From_BCD(v1);
+
+ return 0;
+}
+
+/* pcf8563_set_time --
+ * set time to the PCF8563 real-time clock chip
+ *
+ * PARAMETERS:
+ * minor -- minor RTC device number
+ * time -- new date and time to be written to PCF8563
+ *
+ * RETURNS:
+ * 0, if time obtained successfully
+ * -1, if error occured
+ */
+int
+pcf8563_set_time(int minor, rtems_time_of_day *time)
+{
+ i2c_bus_number bus;
+ i2c_address addr;
+ uint8_t info[8];
+ i2c_message_status status;
+ int try;
+
+ if (time == NULL)
+ return -1;
+
+ bus = RTC_Table[minor].ulCtrlPort1;
+ addr = RTC_Table[minor].ulDataPort;
+
+ if ((time->year >= 2100) ||
+ (time->year < 1900)) {
+ rtems_fatal_error_occurred(RTEMS_INVALID_NUMBER);
+ }
+ info[0] = PCF8563_SECOND_ADR;
+ info[1 + PCF8563_YEAR_ADR -PCF8563_SECOND_ADR] = To_BCD(time->year % 100);
+ info[1 + PCF8563_MONTH_ADR -PCF8563_SECOND_ADR] = To_BCD(time->month);
+ info[1 + PCF8563_DAY_ADR -PCF8563_SECOND_ADR] = To_BCD(time->day);
+ info[1 + PCF8563_HOUR_ADR -PCF8563_SECOND_ADR] = To_BCD(time->hour);
+ info[1 + PCF8563_MINUTE_ADR-PCF8563_SECOND_ADR] = To_BCD(time->minute);
+ info[1 + PCF8563_SECOND_ADR-PCF8563_SECOND_ADR] = To_BCD(time->second);
+ /* Do not set day of week */
+ info[1 + PCF8563_DAY_OF_WEEK_ADR-PCF8563_SECOND_ADR] = 1;
+
+ /*
+ * add century info
+ */
+ if (time->year >= 2000) {
+ info[1 + PCF8563_MONTH_ADR -PCF8563_SECOND_ADR] |= PCF8563_MONTH_CENTURY;
+ }
+ /*
+ * send to device
+ */
+ try = 0;
+ do {
+ status = i2c_write(bus, addr, info, 8);
+ try++;
+ } while ((status != I2C_SUCCESSFUL) && (try < 10));
+
+ if (status != I2C_SUCCESSFUL)
+ return -1;
+ else
+ return 0;
+}
+
+/* Driver function table */
+
+rtc_fns pcf8563_fns = {
+ pcf8563_initialize,
+ pcf8563_get_time,
+ pcf8563_set_time
+};
diff --git a/c/src/lib/libbsp/powerpc/gen5200/tod/pcf8563.h b/c/src/lib/libbsp/powerpc/gen5200/tod/pcf8563.h
new file mode 100644
index 0000000000..916a723010
--- /dev/null
+++ b/c/src/lib/libbsp/powerpc/gen5200/tod/pcf8563.h
@@ -0,0 +1,118 @@
+/*===============================================================*\
+| Project: RTEMS generic MPC5200 BSP |
++-----------------------------------------------------------------+
+| File: $File$
++-----------------------------------------------------------------+
+| Partially based on the code references which are named below. |
+| Adaptions, modifications, enhancements and any recent parts of |
+| the code are: |
+| Copyright (c) 2005 |
+| Embedded Brains GmbH |
+| Obere Lagerstr. 30 |
+| D-82178 Puchheim |
+| Germany |
+| rtems@embedded-brains.de |
++-----------------------------------------------------------------+
+| The license and distribution terms for this file may be |
+| found in the file LICENSE in this distribution or at |
+| |
+| http://www.rtems.com/license/LICENSE. |
+| |
++-----------------------------------------------------------------+
+| this file contains declarations for the pcf8563 RTC driver |
++-----------------------------------------------------------------+
+| date history ID |
+| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
+| 01.12.05 creation doe |
+|*****************************************************************|
+|*CVS information: |
+|*(the following information is created automatically, |
+|*do not edit here) |
+|*****************************************************************|
+|* $Log$
+|* Revision 1.2 2005/12/06 14:11:12 thomas
+|* added EB file headers
+|*
+ *
+|*****************************************************************|
+\*===============================================================*/
+/*
+ * This file contains the definitions for Dallas Semiconductor
+ * DS1307/DS1308 serial real-time clock/NVRAM.
+ *
+ * Copyright (C) 2000 OKTET Ltd., St.-Petersburg, Russia
+ * Author: Victor V. Vengerov <vvv@oktet.ru>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ *
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * @(#) ds1307.h,v 1.2 2003/09/04 18:51:56 joel Exp
+ */
+
+#ifndef __RTC_PCF8563__
+#define __RTC_PCF8563__
+
+#define PCF8563_I2C_ADDRESS (0xA2) /* I2C bus address assigned to PCF8563 */
+
+#define PCF8563_CONTROL1_ADR (0x00)
+#define PCF8563_CONTROL1_TEST1 (0x80) /* EXT_CLK test mode */
+#define PCF8563_CONTROL1_STOP (0x20) /* stop RTC source clock, clear divider*/
+#define PCF8563_CONTROL1_TESTC (0x08) /* enable power-on reset override */
+ /***********/
+#define PCF8563_CONTROL2_ADR (0x01)
+#define PCF8563_CONTROL2_TITP (0x10) /* 0: int output is level */
+#define PCF8563_CONTROL2_AF (0x08) /* alarm flag */
+#define PCF8563_CONTROL2_TF (0x04) /* timer flag */
+#define PCF8563_CONTROL2_AIE (0x02) /* alarm interrupt enable */
+#define PCF8563_CONTROL2_TIE (0x01) /* timer interrupt enable */
+ /***********/
+
+#define PCF8563_SECOND_ADR (0x02)
+#define PCF8563_SECOND_VL (0x80) /* clock integrity no longer guaranteed */
+#define PCF8563_SECOND_MASK (0x7f)
+ /***********/
+
+#define PCF8563_MINUTE_ADR (0x03)
+#define PCF8563_MINUTE_MASK (0x7f)
+ /***********/
+
+#define PCF8563_HOUR_ADR (0x04)
+#define PCF8563_HOUR_MASK (0x3f)
+ /***********/
+
+#define PCF8563_DAY_ADR (0x05)
+#define PCF8563_DAY_MASK (0x3f)
+
+#define PCF8563_DAY_OF_WEEK_ADR (0x06)
+#define PCF8563_DAY_OF_WEEK_MASK (0x07)
+
+#define PCF8563_MONTH_ADR (0x07)
+#define PCF8563_MONTH_MASK (0x1f)
+#define PCF8563_MONTH_CENTURY (0x80)
+ /***********/
+
+#define PCF8563_YEAR_ADR (0x08)
+#define PCF8563_YEAR_MASK (0xff)
+
+#define PCF8563_MINUTE_ALARM_ADR (0x09)
+#define PCF8563_HOUR_ALARM_ADR (0x0A)
+#define PCF8563_DAY_ALARM_ADR (0x0B)
+#define PCF8563_DAY_OF_WEEK_ALARM_ADR (0x0C)
+#define PCF8563_XXX_ALARM_AE (0x80)
+ /***********/
+
+#define PCF8563_CLKOUTCTL_ADR (0x0D)
+#define PCF8563_CLKOUTCTL_FE (0x80) /* */
+#define PCF8563_CLKOUTCTL_FD (0x03) /* */
+ /***********/
+
+#define PCF8563_TIMERCTL_ADR (0x0E)
+#define PCF8563_TIMERCTL_FE (0x80) /* */
+#define PCF8563_TIMERCTL_FD (0x03) /* */
+ /***********/
+
+#define PCF8563_TIMER_ADR (0x0F)
+
+#endif /* __RTC_PCF8563__ */
diff --git a/c/src/lib/libbsp/powerpc/gen5200/tod/todcfg.c b/c/src/lib/libbsp/powerpc/gen5200/tod/todcfg.c
new file mode 100644
index 0000000000..381c91b70b
--- /dev/null
+++ b/c/src/lib/libbsp/powerpc/gen5200/tod/todcfg.c
@@ -0,0 +1,123 @@
+/*===============================================================*\
+| Project: RTEMS generic MPC5200 BSP |
++-----------------------------------------------------------------+
+| File: $File$
++-----------------------------------------------------------------+
+| Partially based on the code references which are named below. |
+| Adaptions, modifications, enhancements and any recent parts of |
+| the code are: |
+| Copyright (c) 2005 |
+| Embedded Brains GmbH |
+| Obere Lagerstr. 30 |
+| D-82178 Puchheim |
+| Germany |
+| rtems@embedded-brains.de |
++-----------------------------------------------------------------+
+| The license and distribution terms for this file may be |
+| found in the file LICENSE in this distribution or at |
+| |
+| http://www.rtems.com/license/LICENSE. |
+| |
++-----------------------------------------------------------------+
+| this file configures the pcf8563 RTC for a PM520 board |
++-----------------------------------------------------------------+
+| date history ID |
+| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
+| 01.12.05 creation doe |
+|*****************************************************************|
+|*CVS information: |
+|*(the following information is created automatically, |
+|*do not edit here) |
+|*****************************************************************|
+|* $Log$
+|* Revision 1.4 2005/12/06 14:11:12 thomas
+|* added EB file headers
+|*
+ *
+|*****************************************************************|
+\*===============================================================*/
+/*
+ * This file contains the RTC driver table for Motorola MCF5206eLITE
+ * ColdFire evaluation board.
+ *
+ * Copyright (C) 2000 OKTET Ltd., St.-Petersburg, Russia
+ * Author: Victor V. Vengerov <vvv@oktet.ru>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ *
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * @(#) todcfg.c,v 1.4 2005/01/22 04:12:39 ralf Exp
+ */
+
+#include "../include/bsp.h"
+#include "../include/i2c.h"
+#include <libchip/rtc.h>
+#include "../tod/pcf8563.h"
+
+/* Forward function declaration */
+boolean mpc5200_pcf8563_probe(int minor);
+
+extern rtc_fns pcf8563_fns;
+
+/* The following table configures the RTC drivers used in this BSP */
+rtc_tbl RTC_Table[] = {
+ {
+ "/dev/rtc", /* sDeviceName */
+ RTC_CUSTOM, /* deviceType */
+ &pcf8563_fns, /* pDeviceFns */
+ mpc5200_pcf8563_probe, /* deviceProbe */
+ NULL, /* pDeviceParams */
+ 0x01, /* ulCtrlPort1, for PCF8563-I2C bus number */
+ PCF8563_I2C_ADDRESS, /* ulDataPort, for PCF8563-I2C device addr */
+ NULL, /* getRegister - not applicable to PCF8563 */
+ NULL /* setRegister - not applicable to PCF8563 */
+ }
+};
+
+/* Some information used by the RTC driver */
+
+#define NUM_RTCS (sizeof(RTC_Table)/sizeof(rtc_tbl))
+
+size_t RTC_Count = NUM_RTCS;
+
+rtems_device_minor_number RTC_Minor;
+
+/* mpc5200_pcf8563_probe --
+ * RTC presence probe function. Return TRUE, if device is present.
+ * Device presence checked by probe access to RTC device over I2C bus.
+ *
+ * PARAMETERS:
+ * minor - minor RTC device number
+ *
+ * RETURNS:
+ * TRUE, if RTC device is present
+ */
+boolean
+mpc5200_pcf8563_probe(int minor)
+{
+ int try = 0;
+ i2c_message_status status;
+ rtc_tbl *rtc;
+ i2c_bus_number bus;
+ i2c_address addr;
+
+ if (minor >= NUM_RTCS)
+ return FALSE;
+
+ rtc = RTC_Table + minor;
+
+ bus = rtc->ulCtrlPort1;
+ addr = rtc->ulDataPort;
+ do {
+ status = i2c_wrbyte(bus, addr, 0);
+ if (status == I2C_NO_DEVICE)
+ return FALSE;
+ try++;
+ } while ((try < 15) && (status != I2C_SUCCESSFUL));
+ if (status == I2C_SUCCESSFUL)
+ return TRUE;
+ else
+ return FALSE;
+}