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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 25a179e was 25a179e, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 8 years ago

IPC return values are always errno constants. Adjust types to reflect that.

In principle, IPC server is not allowed to return non-errno values via
the "main" return value, because kernel interprets it (e.g. EHANGUP).
It's still possible to return arbitrary additional return values alongside EOK,
which are not interpreted in normal communication.

  • Property mode set to 100644
File size: 2.8 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 int rc;
63 if (ret != EOK) {
64 async_forget(req);
65 return ret;
66 }
67
68 async_wait_for(req, &rc);
69 return (int)rc;
70}
71
72/** Set the current time
73 *
74 * @param sess Session of the device
75 * @param t The current time that will be written to the device
76 *
77 * @return EOK on success or a negative error code
78 */
79int
80clock_dev_time_set(async_sess_t *sess, struct tm *t)
81{
82 aid_t req;
83 int ret;
84
85 async_exch_t *exch = async_exchange_begin(sess);
86
87 req = async_send_1(exch, DEV_IFACE_ID(CLOCK_DEV_IFACE),
88 CLOCK_DEV_TIME_SET, NULL);
89 ret = async_data_write_start(exch, t, sizeof(*t));
90
91 async_exchange_end(exch);
92
93 int rc;
94 if (ret != EOK) {
95 async_forget(req);
96 return ret;
97 }
98
99 async_wait_for(req, &rc);
100 return (int)rc;
101}
102
103/** @}
104 */
105
Note: See TracBrowser for help on using the repository browser.