Main Page | Directories | File List | Globals

rtc.c

Go to the documentation of this file.
00001 /*
00002  * kernel_drivers/adi_chips/rtc.c
00003  *
00004  * Copyright (c) 2003-2004 Lukasz Dembinski <dembol@nasa.com.pl>
00005  * All Rights Reserved
00006  * 
00007  * Date:        2004/01
00008  * Author:      Lukasz Dembinski
00009  * Info:        rtc.c core file
00010  * Contact:     mailto: <dembol@nasa.com.pl>
00011  *
00012  */
00013 
00014 #include <agnix/agnix.h>
00015 #include <agnix/adi/adi.h>
00016 #include <agnix/ioport.h>
00017 #include <agnix/memory.h>
00018 #include <agnix/timer.h>
00019 
00020 int rtc_timer_gettimeofday_lock(struct timeval_s *tv)
00021 {
00022     int i;
00023 
00024     for(i = 0; i < 1000000; i++)
00025         if (IS_RTC_UIP) break;
00026 
00027     for(i = 0; i < 1000000; i++)
00028         if (!IS_RTC_UIP) break;
00029 
00030     tv->tv_sec  = BCD_TO_BIN(RTC_READ(RTC_REG_SECONDS))
00031                 + BCD_TO_BIN(RTC_READ(RTC_REG_MINUTES)) * 60
00032                 + BCD_TO_BIN(RTC_READ(RTC_REG_HOURS)) * 60 * 60;
00033                 
00034     tv->tv_usec = 0;
00035 
00036     return 0;
00037 }
00038 
00039 int rtc_gettime(struct chip_s *chip, struct timeval_s *tv)
00040 {
00041     int ret;
00042 
00043     CHIP_LOCK;
00044 
00045     ret = rtc_timer_gettimeofday_lock(tv);
00046 
00047     CHIP_UNLOCK;
00048     
00049     return ret;
00050 }
00051 
00052 int rtc_settime(struct chip_s *chip, struct timeval_s *tv)
00053 {
00054     return 0;
00055 }
00056 
00057 struct chip_rtc_ops_s   rtc_int_ops = 
00058 {
00059     rtc_gettime,
00060     rtc_settime
00061 };
00062 
00063 int rtc_chip_init(struct chip_s *chip)
00064 {
00065     CHIP_LOCK;
00066     CHIP_UNLOCK;
00067 
00068     return 0;
00069 }
00070 
00071 int rtc_chip_release(struct chip_s *chip)
00072 {
00073     CHIP_LOCK;
00074     CHIP_UNLOCK;
00075 
00076     return 0;
00077 }
00078 
00079 struct chip_ops_s       rtc_chip_ops = {
00080     .init               = rtc_chip_init,
00081     .release            = rtc_chip_release
00082 };
00083 
00084 struct chip_s           rtc_chip = {
00085     .chip_name          = "rtc",
00086     .chip_class         = CHIP_CLASS_RTC,
00087     .chip_vendor        = 0x8086,
00088     .chip_priority      = 90,
00089     .chip_ops           = &rtc_chip_ops,
00090     .chip_pm_ops        = NULL,
00091     .internal_ops       = (void *)&rtc_int_ops,
00092     .internal_parm      = (void *)0
00093 };
00094 
00095 int __init rtc_init(void)
00096 {
00097     adi_register_chip(&rtc_chip);
00098 
00099     return 0;    
00100 }
Dokumentacje wygenerowano programem Doxygen 1.4.2 dla projektu Agnix