source: mainline/uspace/drv/time/rtc.c@ 0b8a3e7

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 0b8a3e7 was 0b8a3e7, checked in by Maurizio Lombardi <m.lombardi85@…>, 14 years ago

RTC: Add some comments on top of rtc_time_get() and rtc_time_set() functions

  • Property mode set to 100644
File size: 3.7 KB
Line 
1/*
2 * Copyright (c) 2012 Maurizio Lombardi
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/**
30 * @defgroup CMOS RTC driver.
31 * @brief HelenOS RTC driver.
32 * @{
33 */
34
35/** @file
36 */
37
38#include <errno.h>
39#include <ddi.h>
40#include <stdio.h>
41#include <ddf/driver.h>
42#include <ddf/log.h>
43#include <ops/clock.h>
44#include <fibril_synch.h>
45
46#define NAME "RTC"
47
48static int
49rtc_time_get(ddf_fun_t *fun, time_t *t);
50
51static int
52rtc_time_set(ddf_fun_t *fun, time_t t);
53
54static int
55rtc_dev_add(ddf_dev_t *dev);
56
57
58static ddf_dev_ops_t rtc_dev_ops;
59
60/** The RTC device driver's standard operations */
61static driver_ops_t rtc_ops = {
62 .dev_add = rtc_dev_add,
63 .dev_remove = NULL,
64};
65
66/** The RTC device driver structure */
67static driver_t rtc_driver = {
68 .name = NAME,
69 .driver_ops = &rtc_ops,
70};
71
72/** Clock interface */
73static clock_dev_ops_t rtc_clock_dev_ops = {
74 .time_get = rtc_time_get,
75 .time_set = rtc_time_set,
76};
77
78typedef struct rtc {
79 /** DDF device node */
80 ddf_dev_t *dev;
81 /** DDF function node */
82 ddf_fun_t *fun;
83 /** The fibril mutex for synchronizing the access to the device */
84 fibril_mutex_t mutex;
85} rtc_t;
86
87
88/** Initialize the RTC driver */
89static void
90rtc_init(void)
91{
92 ddf_log_init(NAME, LVL_ERROR);
93
94 rtc_dev_ops.open = NULL;
95 rtc_dev_ops.close = NULL;
96
97 rtc_dev_ops.interfaces[CLOCK_DEV_IFACE] = &rtc_clock_dev_ops;
98 rtc_dev_ops.default_handler = NULL;
99}
100
101/** Read the current time from the CMOS
102 *
103 * @param fun The RTC function
104 * @param t Pointer to the time variable
105 *
106 * @return EOK on success or a negative error code
107 */
108static int
109rtc_time_get(ddf_fun_t *fun, time_t *t)
110{
111 return EOK;
112}
113
114/** Set the time in the RTC
115 *
116 * @param fun The RTC function
117 * @param t The time value to set
118 *
119 * @return EOK or a negative error code
120 */
121static int
122rtc_time_set(ddf_fun_t *fun, time_t t)
123{
124 return EOK;
125}
126
127/** The dev_add callback of the rtc driver
128 *
129 * @param dev The RTC device
130 *
131 * @return EOK on success or a negative error code
132 */
133static int
134rtc_dev_add(ddf_dev_t *dev)
135{
136 rtc_t *rtc;
137
138 ddf_msg(LVL_DEBUG, "rtc_dev_add %s (handle = %d)",
139 dev->name, (int) dev->handle);
140
141 rtc = ddf_dev_data_alloc(dev, sizeof(rtc_t));
142 if (!rtc)
143 return ENOMEM;
144
145 rtc->dev = dev;
146 fibril_mutex_initialize(&rtc->mutex);
147
148 return EOK;
149}
150
151int
152main(int argc, char **argv)
153{
154 printf(NAME ": HelenOS RTC driver\n");
155 rtc_init();
156 return ddf_driver_main(&rtc_driver);
157}
158
159/**
160 * @}
161 */
Note: See TracBrowser for help on using the repository browser.