summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/i386/ts_386ex/clock
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>1999-04-23 16:35:11 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>1999-04-23 16:35:11 +0000
commit16a384cfb161f6a3dbcd69fc3b788b6dbc229669 (patch)
treedbbb2e908c64a7f8de5d4c99c16559158b99f1cf /c/src/lib/libbsp/i386/ts_386ex/clock
parentAdded lstat(). (diff)
downloadrtems-16a384cfb161f6a3dbcd69fc3b788b6dbc229669.tar.bz2
New BSP from Tony R. Ambardar <tonya@ece.ubc.ca> from the
University of British Columbia. The BSP is for: Yes, this is the "entry model" of a series of boards from Technologic Systems. Costs <$200 I believe. They have a WWW page at www.t-systems.com. I am letting them know about the availability of this BSP too.
Diffstat (limited to 'c/src/lib/libbsp/i386/ts_386ex/clock')
-rw-r--r--c/src/lib/libbsp/i386/ts_386ex/clock/Makefile.in70
-rw-r--r--c/src/lib/libbsp/i386/ts_386ex/clock/ckinit.c191
-rw-r--r--c/src/lib/libbsp/i386/ts_386ex/clock/rtc.c226
3 files changed, 487 insertions, 0 deletions
diff --git a/c/src/lib/libbsp/i386/ts_386ex/clock/Makefile.in b/c/src/lib/libbsp/i386/ts_386ex/clock/Makefile.in
new file mode 100644
index 0000000000..ae44755dc5
--- /dev/null
+++ b/c/src/lib/libbsp/i386/ts_386ex/clock/Makefile.in
@@ -0,0 +1,70 @@
+#
+# $Id$
+#
+
+@SET_MAKE@
+srcdir = @srcdir@
+top_srcdir = @top_srcdir@
+top_builddir = ../../../../../../..
+subdir = c/src/lib/libbsp/i386/ts_386ex/clock
+
+INSTALL = @INSTALL@
+
+RTEMS_ROOT = $(top_srcdir)/@RTEMS_TOPdir@
+PROJECT_ROOT = @PROJECT_ROOT@
+
+VPATH = @srcdir@
+
+PGM=${ARCH}/clock.rel
+
+# C source names, if any, go here -- minus the .c
+C_PIECES=ckinit rtc
+C_FILES=$(C_PIECES:%=%.c)
+C_O_FILES=$(C_PIECES:%=${ARCH}/%.o)
+
+H_FILES=
+
+# Assembly source names, if any, go here -- minus the .S
+S_PIECES=
+S_FILES=$(S_PIECES:%=%.S)
+S_O_FILES=$(S_FILES:%.S=${ARCH}/%.o)
+
+SRCS=$(C_FILES) $(CC_FILES) $(H_FILES) $(S_FILES)
+OBJS=$(C_O_FILES) $(CC_O_FILES) $(S_O_FILES)
+
+include $(RTEMS_ROOT)/make/custom/$(RTEMS_BSP).cfg
+include $(RTEMS_ROOT)/make/leaf.cfg
+
+#
+# (OPTIONAL) Add local stuff here using +=
+#
+
+DEFINES +=
+CPPFLAGS +=
+CFLAGS +=
+
+LD_PATHS +=
+LD_LIBS +=
+LDFLAGS +=
+
+#
+# Add your list of files to delete here. The config files
+# already know how to delete some stuff, so you may want
+# to just run 'make clean' first to see what gets missed.
+# 'make clobber' already includes 'make clean'
+#
+
+CLEAN_ADDITIONS +=
+CLOBBER_ADDITIONS +=
+
+${PGM}: ${SRCS} ${OBJS}
+ $(make-rel)
+
+all: ${ARCH} $(SRCS) $(PGM)
+
+# the .rel file built here will be put into libbsp.a by ../wrapup/Makefile
+install: all
+
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+ cd $(top_builddir) \
+ && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
diff --git a/c/src/lib/libbsp/i386/ts_386ex/clock/ckinit.c b/c/src/lib/libbsp/i386/ts_386ex/clock/ckinit.c
new file mode 100644
index 0000000000..80b644b5a4
--- /dev/null
+++ b/c/src/lib/libbsp/i386/ts_386ex/clock/ckinit.c
@@ -0,0 +1,191 @@
+/* Clock_initialize
+ *
+ * This routine initializes the Timer/Counter on the Intel
+ * 386ex evaluation board.
+ *
+ * The tick frequency is 1 millisecond.
+ *
+ * Input parameters: NONE
+ *
+ * Output parameters: NONE
+ *
+ * COPYRIGHT (c) 1989-1998.
+ * On-Line Applications Research Corporation (OAR).
+ * Copyright assigned to U.S. Government, 1994.
+ *
+ * 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 <bsp.h>
+#include <irq.h>
+
+#include <rtems/libio.h>
+
+#include <stdlib.h>
+
+rtems_unsigned32 Clock_isrs; /* ISRs until next tick */
+static rtems_unsigned32 Clock_initial_isr_value;
+
+volatile rtems_unsigned32 Clock_driver_ticks;
+
+void Clock_exit( void );
+
+/*
+ * These are set by clock driver during its init
+ */
+
+rtems_device_major_number rtems_clock_major = ~0;
+rtems_device_major_number rtems_clock_minor = 0;
+
+/*
+ * This is the ISR handler.
+ */
+
+void Clock_isr()
+{
+ /* enable_tracing(); */
+ Clock_driver_ticks += 1;
+ if ( Clock_isrs == 1 ) {
+ rtems_clock_tick();
+ Clock_isrs = Clock_initial_isr_value; /* BSP_Configuration.microseconds_per_tick / 1000;*/
+ }
+ else
+ Clock_isrs -= 1;
+}
+
+void ClockOff(const rtems_irq_connect_data* unused)
+{
+ outport_byte (TIMER_CONFIG, 0x80 ); /* disable the counter timer */
+}
+
+void ClockOn(const rtems_irq_connect_data* unused)
+{
+ outport_byte (TIMER_CONFIG, 0x00 ); /* enable the counter timer */
+}
+
+int ClockIsOn(const rtems_irq_connect_data* unused)
+{
+ return ((i8259s_cache & 0x1) == 0);
+}
+
+static rtems_irq_connect_data clockIrqData = {BSP_PERIODIC_TIMER,
+ Clock_isr,
+ ClockOn,
+ ClockOff,
+ ClockIsOn};
+
+
+rtems_device_driver Clock_initialize(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *pargp
+)
+{
+ unsigned timer_counter_init_value;
+ unsigned char clock_lsb, clock_msb;
+
+#ifdef BSP_DEBUG
+ printk("Initializing clock driver in Clock_initialize().\n");
+#endif
+
+#ifdef LOAD_RTC_AT_START
+ /* Initialize clock from on-board real time clock. This breaks the */
+ /* test code which assumes which assumes the application will do it. */
+ {
+ rtems_time_of_day now;
+
+ /* External Prototypes */
+ extern void init_rtc(void); /* defined in 'rtc.c' */
+ extern long rtc_read(rtems_time_of_day *); /* defined in 'rtc.c' */
+
+#ifdef BSP_DEBUG
+ printk("Loading clock from on-board real-time clock.\n");
+#endif
+
+ init_rtc();
+ if (rtc_read(&now) >= 0)
+ rtems_clock_set(&now);
+ }
+#endif
+
+ Clock_driver_ticks = 0;
+
+ Clock_isrs =
+ Clock_initial_isr_value =
+ BSP_Configuration.microseconds_per_tick / 1000; /* ticks per clock_isr */
+
+ /*
+ * configure the counter timer ( should be based on microsecs/tick )
+ * NB. The divisor(Clock_isrs) resolves the is the same number that appears in confdefs.h
+ * when setting the microseconds_per_tick value.
+ */
+ ClockOff ( &clockIrqData );
+
+ timer_counter_init_value = BSP_Configuration.microseconds_per_tick / Clock_isrs;
+ clock_lsb = (unsigned char)timer_counter_init_value;
+ clock_msb = timer_counter_init_value >> 8;
+
+ outport_byte (TIMER_MODE, TIMER_SEL0|TIMER_16BIT|TIMER_RATEGEN);
+ outport_byte (TIMER_CNTR0, clock_lsb ); /* load LSB first */
+ outport_byte (TIMER_CNTR0, clock_msb ); /* then MSB */
+
+ if (!BSP_install_rtems_irq_handler (&clockIrqData)) {
+ printk("Unable to initialize system clock\n");
+ rtems_fatal_error_occurred(1);
+ }
+
+ /*
+ * make major/minor avail to others such as shared memory driver
+ */
+
+ rtems_clock_major = major;
+ rtems_clock_minor = minor;
+
+ return RTEMS_SUCCESSFUL;
+}
+
+rtems_device_driver Clock_control(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *pargp
+)
+{
+ rtems_libio_ioctl_args_t *args = pargp;
+
+ if (args == 0)
+ goto done;
+
+ /*
+ * This is hokey, but until we get a defined interface
+ * to do this, it will just be this simple...
+ */
+
+ if (args->command == rtems_build_name('I', 'S', 'R', ' '))
+ {
+ Clock_isr();
+ }
+ else if (args->command == rtems_build_name('N', 'E', 'W', ' '))
+ {
+ if (!BSP_install_rtems_irq_handler (&clockIrqData)) {
+ printk("Error installing clock interrupt handler!\n");
+ rtems_fatal_error_occurred(1);
+ }
+#ifdef BSP_DEBUG
+ else
+ printk("Clock installed AGAIN\n");
+#endif
+ }
+
+done:
+ return RTEMS_SUCCESSFUL;
+}
+
+void Clock_exit()
+{
+ ClockOff(&clockIrqData);
+ BSP_remove_rtems_irq_handler (&clockIrqData);
+}
diff --git a/c/src/lib/libbsp/i386/ts_386ex/clock/rtc.c b/c/src/lib/libbsp/i386/ts_386ex/clock/rtc.c
new file mode 100644
index 0000000000..14a20e5f3f
--- /dev/null
+++ b/c/src/lib/libbsp/i386/ts_386ex/clock/rtc.c
@@ -0,0 +1,226 @@
+/*-------------------------------------------------------------------------+
+| rtc.c v1.1 - PC386 BSP - 1997/08/07
++--------------------------------------------------------------------------+
+| This file contains the real time clock manipulation package for the
+| PC386 board.
++--------------------------------------------------------------------------+
+| (C) Copyright 1997 -
+| - NavIST Group - Real-Time Distributed Systems and Industrial Automation
+|
+| http://pandora.ist.utl.pt
+|
+| Instituto Superior Tecnico * Lisboa * PORTUGAL
++--------------------------------------------------------------------------+
+| Disclaimer:
+|
+| This file is provided "AS IS" without warranty of any kind, either
+| expressed or implied.
++--------------------------------------------------------------------------+
+| This code is based on:
+| rtc.c,v 1.4 1995/12/19 20:07:15 joel Exp - go32 BSP
+| With the following copyright notice:
+| **************************************************************************
+| * COPYRIGHT (c) 1989-1998.
+| * On-Line Applications Research Corporation (OAR).
+| * Copyright assigned to U.S. Government, 1994.
+| *
+| * The license and distribution terms for this file may be
+| * found in found in the file LICENSE in this distribution or at
+| * http://www.OARcorp.com/rtems/license.html.
+| **************************************************************************
+|
+| $Id$
++--------------------------------------------------------------------------*/
+
+
+#include <string.h>
+
+#include <bsp.h>
+
+/*-------------------------------------------------------------------------+
+| Constants
++--------------------------------------------------------------------------*/
+#define IO_RTC 0x70 /* RTC */
+
+#define RTC_SEC 0x00 /* seconds */
+#define RTC_SECALRM 0x01 /* seconds alarm */
+#define RTC_MIN 0x02 /* minutes */
+#define RTC_MINALRM 0x03 /* minutes alarm */
+#define RTC_HRS 0x04 /* hours */
+#define RTC_HRSALRM 0x05 /* hours alarm */
+#define RTC_WDAY 0x06 /* week day */
+#define RTC_DAY 0x07 /* day of month */
+#define RTC_MONTH 0x08 /* month of year */
+#define RTC_YEAR 0x09 /* month of year */
+#define RTC_STATUSA 0x0a /* status register A */
+#define RTCSA_TUP 0x80 /* time update, don't look now */
+
+#define RTC_STATUSB 0x0b /* status register B */
+
+#define RTC_INTR 0x0c /* status register C (R) interrupt source */
+#define RTCIR_UPDATE 0x10 /* update intr */
+#define RTCIR_ALARM 0x20 /* alarm intr */
+#define RTCIR_PERIOD 0x40 /* periodic intr */
+#define RTCIR_INT 0x80 /* interrupt output signal */
+
+#define RTC_STATUSD 0x0d /* status register D (R) Lost Power */
+#define RTCSD_PWR 0x80 /* clock lost power */
+
+#define RTC_DIAG 0x0e /* status register E - bios diagnostic */
+#define RTCDG_BITS "\020\010clock_battery\007ROM_cksum\006config_unit\005memory_size\004fixed_disk\003invalid_time"
+
+#define RTC_CENTURY 0x32 /* current century - increment in Dec99 */
+
+
+/*-------------------------------------------------------------------------+
+| Auxiliary Functions
++--------------------------------------------------------------------------*/
+/*-------------------------------------------------------------------------+
+| Function: bcd
+| Description: Convert 2 digit number to its BCD representation.
+| Global Variables: None.
+| Arguments: i - Number to convert.
+| Returns: BCD representation of number.
++--------------------------------------------------------------------------*/
+static inline rtems_unsigned8
+bcd(rtems_unsigned8 i)
+{
+ return ((i / 16) * 10 + (i % 16));
+} /* bcd */
+
+#define QUICK_READ /* Quick read of the RTC: don't return number of seconds. */
+
+#ifndef QUICK_READ
+
+#define SECS_PER_DAY (24 * 60 * 60)
+#define SECS_PER_REG_YEAR (365 * SECS_PER_DAY)
+
+/*-------------------------------------------------------------------------+
+| Function: ytos
+| Description: Convert years to seconds (since 1970).
+| Global Variables: None.
+| Arguments: y - year to convert (1970 <= y <= 2100).
+| Returns: number of seconds since 1970.
++--------------------------------------------------------------------------*/
+static inline rtems_unsigned32
+ytos(rtems_unsigned16 y)
+{ /* v NUM LEAP YEARS v */
+ return ((y - 1970) * SECS_PER_REG_YEAR + (y - 1970 + 1) / 4 * SECS_PER_DAY);
+} /* ytos */
+
+
+/*-------------------------------------------------------------------------+
+| Function: mtos
+| Description: Convert months to seconds since January.
+| Global Variables: None.
+| Arguments: m - month to convert, leap - is this a month of a leap year.
+| Returns: number of seconds since January.
++--------------------------------------------------------------------------*/
+static inline rtems_unsigned32
+mtos(rtems_unsigned8 m, rtems_boolean leap)
+{
+ static rtems_unsigned16 daysMonth[] = { 0, 0, 31, 59, 90, 120, 151, 181,
+ 212, 243, 273, 304, 334, 365 };
+ /* Days since beginning of year until beginning of month. */
+
+ return ((daysMonth[m] + (leap ? 1 : 0)) * SECS_PER_DAY);
+} /* mtos */
+
+#endif /* QUICK_READ */
+
+/*-------------------------------------------------------------------------+
+| Function: rtcin
+| Description: Perform action on RTC and return its result.
+| Global Variables: None.
+| Arguments: what - what to write to RTC port (what to do).
+| Returns: result received from RTC port after action performed.
++--------------------------------------------------------------------------*/
+static inline rtems_unsigned8
+rtcin(rtems_unsigned8 what)
+{
+ rtems_unsigned8 r;
+
+ outport_byte(IO_RTC, what);
+ inport_byte (IO_RTC+1, r);
+ return r;
+} /* rtcin */
+
+
+/*-------------------------------------------------------------------------+
+| Functions
++--------------------------------------------------------------------------*/
+/*-------------------------------------------------------------------------+
+| Function: init_rtc
+| Description: Initialize real-time clock (RTC).
+| Global Variables: None.
+| Arguments: None.
+| Returns: Nothing.
++--------------------------------------------------------------------------*/
+void
+init_rtc(void)
+{
+ rtems_unsigned8 s;
+
+ /* initialize brain-dead battery powered clock */
+ outport_byte(IO_RTC, RTC_STATUSA);
+ outport_byte(IO_RTC+1, 0x26);
+ outport_byte(IO_RTC, RTC_STATUSB);
+ outport_byte(IO_RTC+1, 2);
+
+ outport_byte(IO_RTC, RTC_DIAG);
+ inport_byte (IO_RTC+1, s);
+ if (s)
+ printk("RTC BIOS diagnostic error %b\n", s);
+
+ /* FIXME: This was last line's original version. How was it supposed to work?
+ printf("RTC BIOS diagnostic error %b\n", s, RTCDG_BITS); */
+} /* init_rtc */
+
+
+/*-------------------------------------------------------------------------+
+| Function: rtc_read
+| Description: Read present time from RTC and return it.
+| Global Variables: None.
+| Arguments: tod - to return present time in 'rtems_time_of_day' format.
+| Returns: number of seconds from 1970/01/01 corresponding to 'tod'.
++--------------------------------------------------------------------------*/
+long int
+rtc_read(rtems_time_of_day *tod)
+{
+ rtems_unsigned8 sa;
+ rtems_unsigned32 sec = 0;
+
+ memset(tod, 0, sizeof *tod); /* zero tod structure */
+
+ /* do we have a realtime clock present? (otherwise we loop below) */
+ sa = rtcin(RTC_STATUSA);
+ if (sa == 0xff || sa == 0)
+ return -1;
+
+ /* ready for a read? */
+ while ((sa&RTCSA_TUP) == RTCSA_TUP)
+ sa = rtcin(RTC_STATUSA);
+
+ tod->year = bcd(rtcin(RTC_YEAR)) + 1900; /* year */
+ if (tod->year < 1970) tod->year += 100;
+ tod->month = bcd(rtcin(RTC_MONTH)); /* month */
+ tod->day = bcd(rtcin(RTC_DAY)); /* day */
+ (void) bcd(rtcin(RTC_WDAY)); /* weekday */
+ tod->hour = bcd(rtcin(RTC_HRS)); /* hour */
+ tod->minute = bcd(rtcin(RTC_MIN)); /* minutes */
+ tod->second = bcd(rtcin(RTC_SEC)); /* seconds */
+ tod->ticks = 0;
+
+#ifndef QUICK_READ /* Quick read of the RTC: don't return number of seconds. */
+ sec = ytos(tod->year);
+ sec += mtos(tod->month, (tod->year % 4) == 0);
+ sec += tod->day * SECS_PER_DAY;
+ sec += tod->hour * 60 * 60; /* hour */
+ sec += tod->minute * 60; /* minutes */
+ sec += tod->second; /* seconds */
+#endif /* QUICK_READ */
+
+ return (long int)sec;
+} /* rtc_read */
+
+