From a79d650d0df238b7286379ca5e11566eda3a2cfe Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Wed, 25 Apr 2018 10:32:28 +0200 Subject: bsp/mcf5206elite: Move nvram.c to bsps This patch is a part of the BSP source reorganization. Update #3285. --- bsps/m68k/mcf5206elite/nvram/nvram.c | 173 +++++++++++++++++++++++ c/src/lib/libbsp/m68k/mcf5206elite/Makefile.am | 2 +- c/src/lib/libbsp/m68k/mcf5206elite/nvram/nvram.c | 173 ----------------------- 3 files changed, 174 insertions(+), 174 deletions(-) create mode 100644 bsps/m68k/mcf5206elite/nvram/nvram.c delete mode 100644 c/src/lib/libbsp/m68k/mcf5206elite/nvram/nvram.c diff --git a/bsps/m68k/mcf5206elite/nvram/nvram.c b/bsps/m68k/mcf5206elite/nvram/nvram.c new file mode 100644 index 0000000000..d140272523 --- /dev/null +++ b/bsps/m68k/mcf5206elite/nvram/nvram.c @@ -0,0 +1,173 @@ +/* + * 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 + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * + * http://www.rtems.org/license/LICENSE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +/* 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; + uint32_t 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; + uint32_t 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 { + uint8_t 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; +} diff --git a/c/src/lib/libbsp/m68k/mcf5206elite/Makefile.am b/c/src/lib/libbsp/m68k/mcf5206elite/Makefile.am index b05c381e88..4148b28366 100644 --- a/c/src/lib/libbsp/m68k/mcf5206elite/Makefile.am +++ b/c/src/lib/libbsp/m68k/mcf5206elite/Makefile.am @@ -42,7 +42,7 @@ librtemsbsp_a_SOURCES += ../../../../../../bsps/m68k/mcf5206elite/rtc/ds1307.c librtemsbsp_a_SOURCES += ../../../../../../bsps/m68k/mcf5206elite/rtc/todcfg.c librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/dev/rtc/rtc-support.c # nvram -librtemsbsp_a_SOURCES += nvram/nvram.c +librtemsbsp_a_SOURCES += ../../../../../../bsps/m68k/mcf5206elite/nvram/nvram.c librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/cache/nocache.c librtemsbsp_a_SOURCES += ../../../../../../bsps/m68k/shared/m68kidle.c diff --git a/c/src/lib/libbsp/m68k/mcf5206elite/nvram/nvram.c b/c/src/lib/libbsp/m68k/mcf5206elite/nvram/nvram.c deleted file mode 100644 index d140272523..0000000000 --- a/c/src/lib/libbsp/m68k/mcf5206elite/nvram/nvram.c +++ /dev/null @@ -1,173 +0,0 @@ -/* - * 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 - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * - * http://www.rtems.org/license/LICENSE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -/* 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; - uint32_t 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; - uint32_t 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 { - uint8_t 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; -} -- cgit v1.2.3