The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/dev/dec/mcclock.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /* $NetBSD: mcclock.c,v 1.11 1998/04/19 07:50:25 jonathan Exp $ */
    2 
    3 #include <sys/cdefs.h>
    4 __FBSDID("$FreeBSD: releng/5.3/sys/dev/dec/mcclock.c 119418 2003-08-24 17:55:58Z obrien $");
    5 
    6 /*
    7  * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
    8  * All rights reserved.
    9  *
   10  * Author: Chris G. Demetriou
   11  *
   12  * Permission to use, copy, modify and distribute this software and
   13  * its documentation is hereby granted, provided that both the copyright
   14  * notice and this permission notice appear in all copies of the
   15  * software, derivative works or modified versions, and any portions
   16  * thereof, and that both notices appear in supporting documentation.
   17  *
   18  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
   19  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
   20  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
   21  *
   22  * Carnegie Mellon requests users of this software to return to
   23  *
   24  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
   25  *  School of Computer Science
   26  *  Carnegie Mellon University
   27  *  Pittsburgh PA 15213-3890
   28  *
   29  * any improvements or extensions that they make and grant Carnegie the
   30  * rights to redistribute these changes.
   31  */
   32 
   33 #include <sys/param.h>
   34 #include <sys/kernel.h>
   35 #include <sys/systm.h>
   36 #include <sys/bus.h>
   37 
   38 #include <machine/clockvar.h>
   39 #include <dev/dec/mcclockvar.h>
   40 #include <dev/dec/mc146818reg.h>
   41 
   42 /*
   43  * XXX rate is machine-dependent.
   44  */
   45 #ifdef __alpha__
   46 #define MC_DEFAULTRATE MC_RATE_1024_Hz
   47 #endif
   48 #ifdef __pmax__
   49 #define MC_DEFAULTRATE MC_RATE_256_Hz
   50 #endif
   51 
   52 void
   53 mcclock_attach(device_t dev)
   54 {
   55         /* Turn interrupts off, just in case. */
   56         MCCLOCK_WRITE(dev, MC_REGB, MC_REGB_BINARY | MC_REGB_24HR);
   57 
   58         clockattach(dev);
   59 }
   60 
   61 void
   62 mcclock_init(device_t dev)
   63 {
   64         MCCLOCK_WRITE(dev, MC_REGA, MC_BASE_32_KHz | MC_DEFAULTRATE);
   65         MCCLOCK_WRITE(dev, MC_REGB,
   66             MC_REGB_PIE | MC_REGB_SQWE | MC_REGB_BINARY | MC_REGB_24HR);
   67 }
   68 
   69 /*
   70  * Get the time of day, based on the clock's value and/or the base value.
   71  */
   72 void
   73 mcclock_get(device_t dev, time_t base, struct clocktime *ct)
   74 {
   75         mc_todregs regs;
   76         int s;
   77 
   78         s = splclock();
   79         MC146818_GETTOD(dev, &regs)
   80         splx(s);
   81 
   82         ct->sec = regs[MC_SEC];
   83         ct->min = regs[MC_MIN];
   84         ct->hour = regs[MC_HOUR];
   85         ct->dow = regs[MC_DOW];
   86         ct->day = regs[MC_DOM];
   87         ct->mon = regs[MC_MONTH];
   88         ct->year = regs[MC_YEAR];
   89 }
   90 
   91 /*
   92  * Reset the TODR based on the time value.
   93  */
   94 void
   95 mcclock_set(device_t dev, struct clocktime *ct)
   96 {
   97         mc_todregs regs;
   98         int s;
   99 
  100         s = splclock();
  101         MC146818_GETTOD(dev, &regs);
  102         splx(s);
  103 
  104         regs[MC_SEC] = ct->sec;
  105         regs[MC_MIN] = ct->min;
  106         regs[MC_HOUR] = ct->hour;
  107         regs[MC_DOW] = ct->dow;
  108         regs[MC_DOM] = ct->day;
  109         regs[MC_MONTH] = ct->mon;
  110         regs[MC_YEAR] = ct->year;
  111 
  112         s = splclock();
  113         MC146818_PUTTOD(dev, &regs);
  114         splx(s);
  115 }
  116 
  117 int
  118 mcclock_getsecs(device_t dev, int *secp)
  119 {
  120         int timeout = 100000000;
  121         int sec;
  122         int s;
  123 
  124         s = splclock();
  125         for (;;) {
  126                 if (!(MCCLOCK_READ(dev, MC_REGA) & MC_REGA_UIP)) {
  127                         sec = MCCLOCK_READ(dev, MC_SEC);
  128                         break;
  129                 }
  130                 if (--timeout == 0)
  131                         goto fail;
  132         }
  133 
  134         splx(s);
  135         *secp = sec;
  136         return 0;
  137 
  138  fail:
  139         splx(s);
  140         return ETIMEDOUT;
  141 }

Cache object: b1ffa85d04dba0e5925f1ffa274726b1


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.