summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/m68k/mcf5206elite/nvram/nvram.c
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2001-10-26 19:30:11 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2001-10-26 19:30:11 +0000
commite56c35463b227b85d6a741e30a826d7ba2a71db7 (patch)
tree568f587e83eed0359e1f111dc91f826c6b10eb48 /c/src/lib/libbsp/m68k/mcf5206elite/nvram/nvram.c
parent2001-10-26 Joel Sherrill <joel@OARcorp.com> (diff)
downloadrtems-e56c35463b227b85d6a741e30a826d7ba2a71db7.tar.bz2
2001-10-26 Victor V. Vengerov <vvv@oktet.ru>
* New BSP for MCF5206eLITE evaluation board BSP. * ChangeLog, README, bsp_specs, configure.ac, console/console.c, console/.cvsignore, i2c/i2c.c, i2c/i2cdrv.c, i2c/.cvsignore, include/bsp.h, include/bspopts.h.in, include/coverhd.h, include/ds1307.h, include/i2c.h, include/i2cdrv.h, include/nvram.h, include/.cvsignore, nvram/nvram.c, nvram/.cvsignore, start/start.S, start/.cvsignore, startup/bspclean.c, startup/bspstart.c, startup/gdbinit, startup/init5206e.c, startup/linkcmds, startup/linkcmds.flash, startup/.cvsignore, times, tod/ds1307.c, tod/todcfg.c, tod/.cvsignore, tools/.cvsignore, tools/configure.ac, tools/runtest, tools/changes, wrapup/.cvsignore, .cvsignore: New files.
Diffstat (limited to 'c/src/lib/libbsp/m68k/mcf5206elite/nvram/nvram.c')
-rw-r--r--c/src/lib/libbsp/m68k/mcf5206elite/nvram/nvram.c177
1 files changed, 177 insertions, 0 deletions
diff --git a/c/src/lib/libbsp/m68k/mcf5206elite/nvram/nvram.c b/c/src/lib/libbsp/m68k/mcf5206elite/nvram/nvram.c
new file mode 100644
index 0000000000..ea084a728d
--- /dev/null
+++ b/c/src/lib/libbsp/m68k/mcf5206elite/nvram/nvram.c
@@ -0,0 +1,177 @@
+/*
+ * DS1307-based Non-Volatile memory device driver
+ *
+ * DS1307 chip is a I2C Real-Time Clock. It contains 56 bytes of
+ * non-volatile RAM storage. This driver provide file-like interface to
+ * this memory.
+ *
+ * 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.OARcorp.com/rtems/license.html.
+ *
+ * @(#) $Id$
+ */
+
+#include <rtems.h>
+#include <rtems/libio.h>
+#include <errno.h>
+#include <bsp.h>
+#include <nvram.h>
+#include <i2c.h>
+#include <ds1307.h>
+
+
+/* nvram_driver_initialize --
+ * Non-volatile memory device driver initialization.
+ */
+rtems_device_driver
+nvram_driver_initialize(rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg)
+{
+ rtems_status_code sc;
+ i2c_message_status status;
+ i2c_bus_number bus = DS1307_I2C_BUS_NUMBER;
+ i2c_address addr = DS1307_I2C_ADDRESS;
+ int try = 0;
+ do {
+ status = i2c_wrbyte(bus, addr, 0);
+ if (status == I2C_NO_DEVICE)
+ break;
+ try++;
+ } while ((try < 15) && (status != I2C_SUCCESSFUL));
+
+ if (status == I2C_SUCCESSFUL)
+ {
+ sc = rtems_io_register_name("/dev/nvram", major, 0);
+ if (sc != RTEMS_SUCCESSFUL)
+ {
+ errno = EIO;
+ return RTEMS_UNSATISFIED;
+ }
+ else
+ return RTEMS_SUCCESSFUL;
+ }
+ else
+ {
+ errno = ENODEV;
+ return RTEMS_UNSATISFIED;
+ }
+}
+
+/* nvram_driver_open --
+ * Non-volatile memory device driver open primitive.
+ */
+rtems_device_driver
+nvram_driver_open(rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg)
+{
+ return RTEMS_SUCCESSFUL;
+}
+
+/* nvram_driver_close --
+ * Non-volatile memory device driver close primitive.
+ */
+rtems_device_driver
+nvram_driver_close(rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg)
+{
+ return RTEMS_SUCCESSFUL;
+}
+
+/* nvram_driver_read --
+ * Non-volatile memory device driver read primitive.
+ */
+rtems_device_driver
+nvram_driver_read(rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg)
+{
+ rtems_libio_rw_args_t *args = arg;
+ unsigned32 count;
+ i2c_bus_number bus = DS1307_I2C_BUS_NUMBER;
+ i2c_address addr = DS1307_I2C_ADDRESS;
+ i2c_message_status status;
+ if (args->offset >= DS1307_NVRAM_SIZE)
+ {
+ count = 0;
+ }
+ else if (args->offset + args->count >= DS1307_NVRAM_SIZE)
+ {
+ count = DS1307_NVRAM_SIZE - args->offset;
+ }
+ else
+ {
+ count = args->count;
+ }
+ if (count > 0)
+ {
+ int try = 0;
+ do {
+ status = i2c_wbrd(bus, addr, DS1307_NVRAM_START + args->offset,
+ args->buffer, count);
+ try++;
+ } while ((try < 15) && (status != I2C_SUCCESSFUL));
+ if (status != I2C_SUCCESSFUL)
+ {
+ errno = EIO;
+ return RTEMS_UNSATISFIED;
+ }
+ }
+ args->bytes_moved = count;
+ return RTEMS_SUCCESSFUL;
+}
+
+/* nvram_driver_write --
+ * Non-volatile memory device driver write primitive.
+ */
+rtems_device_driver
+nvram_driver_write(rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg)
+{
+ rtems_libio_rw_args_t *args = arg;
+ unsigned32 count;
+ i2c_bus_number bus = DS1307_I2C_BUS_NUMBER;
+ i2c_address addr = DS1307_I2C_ADDRESS;
+ i2c_message_status status;
+
+ if (args->offset >= DS1307_NVRAM_SIZE)
+ {
+ count = 0;
+ }
+ else if (args->offset + args->count >= DS1307_NVRAM_SIZE)
+ {
+ count = DS1307_NVRAM_SIZE - args->offset;
+ }
+ else
+ {
+ count = args->count;
+ }
+ if (count > 0)
+ {
+ int try = 0;
+ do {
+ rtems_unsigned8 buf[DS1307_NVRAM_SIZE + 1];
+ buf[0] = DS1307_NVRAM_START + args->offset;
+ memcpy(buf+1, args->buffer, count);
+ status = i2c_write(bus, addr, buf, count+1);
+ try++;
+ } while ((try < 15) && (status != I2C_SUCCESSFUL));
+ if (status != I2C_SUCCESSFUL)
+ {
+ errno = EIO;
+ return RTEMS_UNSATISFIED;
+ }
+ }
+ args->bytes_moved = count;
+ return RTEMS_SUCCESSFUL;
+}
+
+ \ No newline at end of file