source: mainline/uspace/lib/c/generic/device/clock_dev.c@ a44b58c

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

rtc: fix CLOCK_DEV protocol

  • Property mode set to 100644
File size: 2.9 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 /** @addtogroup libc
30 * @{
31 */
32/** @file
33 */
34
35#include <ipc/dev_iface.h>
36#include <device/clock_dev.h>
37#include <errno.h>
38#include <async.h>
39#include <time.h>
40
41/** Read the current time from the device
42 *
43 * @param sess Session of the device
44 * @param t The current time that will be read from the device
45 *
46 * @return EOK on success or a negative error code
47 */
48int
49clock_dev_time_get(async_sess_t *sess, struct tm *t)
50{
51 aid_t req;
52 int ret;
53
54 async_exch_t *exch = async_exchange_begin(sess);
55
56 req = async_send_1(exch, DEV_IFACE_ID(CLOCK_DEV_IFACE),
57 CLOCK_DEV_TIME_GET, NULL);
58 ret = async_data_read_start(exch, t, sizeof(*t));
59
60 async_exchange_end(exch);
61
62 sysarg_t rc;
63 if (ret != EOK) {
64 async_wait_for(req, &rc);
65 if (rc == EOK)
66 return ret;
67 }
68
69 async_wait_for(req, &rc);
70 return (int)rc;
71}
72
73/** Set the current time
74 *
75 * @param sess Session of the device
76 * @param t The current time that will be written to the device
77 *
78 * @return EOK on success or a negative error code
79 */
80int
81clock_dev_time_set(async_sess_t *sess, struct tm *t)
82{
83 aid_t req;
84 int ret;
85
86 async_exch_t *exch = async_exchange_begin(sess);
87
88 req = async_send_1(exch, DEV_IFACE_ID(CLOCK_DEV_IFACE),
89 CLOCK_DEV_TIME_SET, NULL);
90 ret = async_data_write_start(exch, t, sizeof(*t));
91
92 async_exchange_end(exch);
93
94 sysarg_t rc;
95 if (ret != EOK) {
96 async_wait_for(req, &rc);
97 if (rc == EOK)
98 return ret;
99 }
100
101 async_wait_for(req, &rc);
102 return (int)rc;
103}
104
105/** @}
106 */
107
Note: See TracBrowser for help on using the repository browser.