summaryrefslogtreecommitdiffstats
path: root/cpukit
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2009-05-27 14:23:23 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2009-05-27 14:23:23 +0000
commit22ed4172f7998db711f72f973fa75a469ed817e4 (patch)
tree61d390aaa96c5a92a2ffdac02325973c939e1e0e /cpukit
parent2009-05-27 Sebastian Huber <sebastian.huber@embedded-brains.de> (diff)
downloadrtems-22ed4172f7998db711f72f973fa75a469ed817e4.tar.bz2
2009-05-27 Sebastian Huber <sebastian.huber@embedded-brains.de>
* libcsupport/include/rtc.h: New RTC driver interface. * libmisc/Makefile.am, libmisc/shell/shellconfig.h: Added RTC command. * libmisc/shell/main_rtc.c: New file.
Diffstat (limited to 'cpukit')
-rw-r--r--cpukit/ChangeLog6
-rw-r--r--cpukit/libcsupport/include/rtc.h87
-rw-r--r--cpukit/libmisc/Makefile.am2
-rw-r--r--cpukit/libmisc/shell/main_rtc.c169
-rw-r--r--cpukit/libmisc/shell/shellconfig.h9
5 files changed, 266 insertions, 7 deletions
diff --git a/cpukit/ChangeLog b/cpukit/ChangeLog
index 5c1824093a..33e3121f52 100644
--- a/cpukit/ChangeLog
+++ b/cpukit/ChangeLog
@@ -1,3 +1,9 @@
+2009-05-27 Sebastian Huber <sebastian.huber@embedded-brains.de>
+
+ * libcsupport/include/rtc.h: New RTC driver interface.
+ * libmisc/Makefile.am, libmisc/shell/shellconfig.h: Added RTC command.
+ * libmisc/shell/main_rtc.c: New file.
+
2009-05-21 Joel Sherrill <joel.sherrill@OARcorp.com>
PR 1413/cpukit
diff --git a/cpukit/libcsupport/include/rtc.h b/cpukit/libcsupport/include/rtc.h
index 1339e32c8c..68258c5362 100644
--- a/cpukit/libcsupport/include/rtc.h
+++ b/cpukit/libcsupport/include/rtc.h
@@ -1,9 +1,7 @@
/**
- * @file rtems/rtc.h
+ * @file
*
- * This file describes the Real-Time Clock driver for all boards.
- * This driver provides support for the standard RTEMS routines
- * that set the tod based on an RTC.
+ * Real-time clock driver interface.
*/
/*
@@ -20,22 +18,99 @@
#ifndef _RTEMS_RTC_H
#define _RTEMS_RTC_H
+#include <rtems.h>
+
#ifdef __cplusplus
extern "C" {
#endif
+/**
+ * @defgroup rtems_rtc Real-Time Clock Driver Interface
+ *
+ * This driver interface provides support to read and set the real-time clock
+ * and to initialize the time of day for the system.
+ *
+ * @{
+ */
+
+/**
+ * Device file name path.
+ */
+#define RTC_DEVICE_NAME "/dev/rtc"
+
+/**
+ * Device driver table entry.
+ */
#define RTC_DRIVER_TABLE_ENTRY \
- { rtc_initialize, NULL, NULL, NULL, NULL, NULL }
+ { rtc_initialize, rtc_open, rtc_close, \
+ rtc_read, rtc_write, rtc_control }
+/**
+ * Initializes the real-time clock device and sets the time of day for the
+ * system.
+ *
+ * If the real-time clock provides an invalid time of day value the system time
+ * of day must remain untouched.
+ */
rtems_device_driver rtc_initialize(
rtems_device_major_number,
rtems_device_minor_number,
void *
);
+/**
+ * Opens the real-time clock device.
+ */
+rtems_device_driver rtc_open(
+ rtems_device_major_number,
+ rtems_device_minor_number,
+ void *
+);
+
+/**
+ * Closes the real-time clock device.
+ */
+rtems_device_driver rtc_close(
+ rtems_device_major_number,
+ rtems_device_minor_number,
+ void *
+);
+
+/**
+ * Reads the real-time clock value.
+ *
+ * The value will be returned in a @ref rtems_time_of_day structure.
+ */
+rtems_device_driver rtc_read(
+ rtems_device_major_number,
+ rtems_device_minor_number,
+ void *
+);
+
+/**
+ * Sets the real-time clock value.
+ *
+ * The value will be set from a @ref rtems_time_of_day structure.
+ */
+rtems_device_driver rtc_write(
+ rtems_device_major_number,
+ rtems_device_minor_number,
+ void *
+);
+
+/**
+ * Controls the real-time clock.
+ */
+rtems_device_driver rtc_control(
+ rtems_device_major_number,
+ rtems_device_minor_number,
+ void *
+);
+
+/** @} */
+
#ifdef __cplusplus
}
#endif
#endif
-/* end of include file */
diff --git a/cpukit/libmisc/Makefile.am b/cpukit/libmisc/Makefile.am
index d2f97378f4..dd1bbd6d74 100644
--- a/cpukit/libmisc/Makefile.am
+++ b/cpukit/libmisc/Makefile.am
@@ -86,7 +86,7 @@ libshell_a_SOURCES = shell/cat_file.c shell/cmds.c shell/internal.h \
shell/verrx.c shell/vwarn.c shell/vwarnx.c shell/warn.c shell/warnx.c \
shell/fts.c shell/print_heapinfo.c shell/main_wkspaceinfo.c \
shell/shell_script.c shell/login_prompt.c shell/login_check.c \
- shell/fdisk.c
+ shell/fdisk.c shell/main_rtc.c
if LIBNETWORKING
libshell_a_SOURCES += shell/main_mount_ftp.c shell/main_mount_tftp.c \
shell/main_ifconfig.c shell/main_route.c shell/main_netstats.c \
diff --git a/cpukit/libmisc/shell/main_rtc.c b/cpukit/libmisc/shell/main_rtc.c
new file mode 100644
index 0000000000..56a622dccc
--- /dev/null
+++ b/cpukit/libmisc/shell/main_rtc.c
@@ -0,0 +1,169 @@
+/**
+ * @file
+ *
+ * Real time clock shell command.
+ */
+
+/*
+ * Copyright (c) 2009
+ * 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.
+ */
+
+#include <stdio.h>
+#include <inttypes.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include <rtems.h>
+#include <rtems/rtc.h>
+#include <rtems/error.h>
+#include <rtems/shell.h>
+
+#define RTEMS_RTC_SHELL_ERROR( fmt, ...) \
+ do { \
+ printf( "error: " fmt "\n", ##__VA_ARGS__); \
+ return -1; \
+ } while (0)
+
+#define RTEMS_RTC_SHELL_ERROR_SC( sc, fmt, ...) \
+ if ((sc) != RTEMS_SUCCESSFUL) { \
+ printf( "error: " fmt ": %s\n", ##__VA_ARGS__, rtems_status_text( sc)); \
+ return -1; \
+ }
+
+static const char rtems_rtc_shell_usage [] =
+ "real time clock read and set\n"
+ "\n"
+ "rtc\n"
+ "\tprints the current time of day\n"
+ "\n"
+ "rtc YYYY-MM-DD [HH:MM:SS [TICKS]]\n"
+ "\tsets the time of day and real time clock";
+
+static int rtems_rtc_shell_main( int argc, char **argv)
+{
+ rtems_status_code sc = RTEMS_SUCCESSFUL;
+ rtems_time_of_day tod = {
+ .year = 1988,
+ .month = 1,
+ .day = 1,
+ .hour = 0,
+ .minute = 0,
+ .second = 0,
+ .ticks = 0
+ };
+
+ if (argc == 1) {
+ sc = rtems_clock_get_tod( &tod);
+ RTEMS_RTC_SHELL_ERROR_SC( sc, "get time of day");
+
+ printf(
+ "%04" PRIu32 "-%02" PRIu32 "-%02" PRIu32
+ " %02" PRIu32 ":%02" PRIu32 ":%02" PRIu32
+ " %02" PRIu32 "\n",
+ tod.year,
+ tod.month,
+ tod.day,
+ tod.hour,
+ tod.minute,
+ tod.second,
+ tod.ticks
+ );
+ } else if (argc > 1 && argc < 5) {
+ int rv = 0;
+ int fd = 0;
+ ssize_t n = 0;
+ uint32_t v [3];
+
+ if (argc > 1) {
+ rv = sscanf(
+ argv [1],
+ "%04" PRIu32 "-%02" PRIu32 "-%02" PRIu32,
+ v,
+ v + 1,
+ v + 2
+ );
+
+ if (rv == 3) {
+ tod.year = v [0];
+ tod.month = v [1];
+ tod.day = v [2];
+ } else {
+ RTEMS_RTC_SHELL_ERROR( "unexpected YYYY-MM-DD input: %s", argv [1]);
+ }
+ }
+
+ if (argc > 2) {
+ rv = sscanf(
+ argv [2],
+ "%04" PRIu32 ":%02" PRIu32 ":%02" PRIu32,
+ v,
+ v + 1,
+ v + 2
+ );
+
+ if (rv == 3) {
+ tod.hour = v [0];
+ tod.minute = v [1];
+ tod.second = v [2];
+ } else {
+ RTEMS_RTC_SHELL_ERROR( "unexpected HH:MM:SS input: %s", argv [2]);
+ }
+ }
+
+ if (argc > 3) {
+ rv = sscanf( argv [3], "%" PRIu32, v);
+
+ if (rv == 1) {
+ tod.ticks = v [0];
+ } else {
+ RTEMS_RTC_SHELL_ERROR( "unexpected TICKS input: %s", argv [3]);
+ }
+ }
+
+ sc = rtems_clock_set( &tod);
+ RTEMS_RTC_SHELL_ERROR_SC( sc, "set time of day");
+
+ fd = open( RTC_DEVICE_NAME, O_WRONLY);
+ if (fd < 0) {
+ perror( "error: open " RTC_DEVICE_NAME);
+ return -1;
+ }
+
+ n = write( fd, &tod, sizeof( tod));
+ if (n != (ssize_t) sizeof( tod)) {
+ perror( "error: write to " RTC_DEVICE_NAME);
+ close( fd);
+ return -1;
+ }
+
+ rv = close( fd);
+ if (rv != 0) {
+ perror( "error: close " RTC_DEVICE_NAME);
+ return -1;
+ }
+ } else {
+ puts( rtems_rtc_shell_usage);
+ return -1;
+ }
+
+ return 0;
+}
+
+struct rtems_shell_cmd_tt rtems_shell_RTC_Command = {
+ .name = "rtc",
+ .usage = rtems_rtc_shell_usage,
+ .topic = "misc",
+ .command = rtems_rtc_shell_main,
+ .alias = NULL,
+ .next = NULL
+};
diff --git a/cpukit/libmisc/shell/shellconfig.h b/cpukit/libmisc/shell/shellconfig.h
index f3bc16ddc4..d7179b5629 100644
--- a/cpukit/libmisc/shell/shellconfig.h
+++ b/cpukit/libmisc/shell/shellconfig.h
@@ -55,6 +55,8 @@ extern rtems_shell_cmd_t rtems_shell_UNMOUNT_Command;
extern rtems_shell_cmd_t rtems_shell_BLKSYNC_Command;
extern rtems_shell_cmd_t rtems_shell_FDISK_Command;
+extern rtems_shell_cmd_t rtems_shell_RTC_Command;
+
extern rtems_shell_cmd_t rtems_shell_HALT_Command;
extern rtems_shell_cmd_t rtems_shell_CPUUSE_Command;
extern rtems_shell_cmd_t rtems_shell_STACKUSE_Command;
@@ -368,6 +370,13 @@ extern rtems_shell_filesystems_t *rtems_shell_Mount_filesystems[];
#endif
#endif
+ /* Miscanellous shell commands */
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) \
+ && !defined(CONFIGURE_SHELL_NO_COMMAND_RTC)) \
+ || defined(CONFIGURE_SHELL_COMMAND_RTC)
+ &rtems_shell_RTC_Command,
+ #endif
+
/*
* User defined shell commands
*/