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

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

rtc: add support to the clock_dev_time_set() operation

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