[02b38730] | 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 |
|
---|
[7d68e5c7] | 29 | /** @addtogroup libc
|
---|
[02b38730] | 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 | *
|
---|
[cde999a] | 46 | * @return EOK on success or an error code
|
---|
[02b38730] | 47 | */
|
---|
| 48 | int
|
---|
| 49 | clock_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),
|
---|
[bfc5577a] | 57 | CLOCK_DEV_TIME_GET, NULL);
|
---|
[02b38730] | 58 | ret = async_data_read_start(exch, t, sizeof(*t));
|
---|
| 59 |
|
---|
| 60 | async_exchange_end(exch);
|
---|
| 61 |
|
---|
[25a179e] | 62 | int rc;
|
---|
[02b38730] | 63 | if (ret != EOK) {
|
---|
[077dad2] | 64 | async_forget(req);
|
---|
| 65 | return ret;
|
---|
[02b38730] | 66 | }
|
---|
| 67 |
|
---|
| 68 | async_wait_for(req, &rc);
|
---|
[bfc5577a] | 69 | return (int)rc;
|
---|
[02b38730] | 70 | }
|
---|
| 71 |
|
---|
[2703b824] | 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 | *
|
---|
[cde999a] | 77 | * @return EOK on success or an error code
|
---|
[2703b824] | 78 | */
|
---|
| 79 | int
|
---|
| 80 | clock_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),
|
---|
[bfc5577a] | 88 | CLOCK_DEV_TIME_SET, NULL);
|
---|
[2703b824] | 89 | ret = async_data_write_start(exch, t, sizeof(*t));
|
---|
| 90 |
|
---|
| 91 | async_exchange_end(exch);
|
---|
| 92 |
|
---|
[25a179e] | 93 | int rc;
|
---|
[2703b824] | 94 | if (ret != EOK) {
|
---|
[077dad2] | 95 | async_forget(req);
|
---|
| 96 | return ret;
|
---|
[2703b824] | 97 | }
|
---|
| 98 |
|
---|
| 99 | async_wait_for(req, &rc);
|
---|
[bfc5577a] | 100 | return (int)rc;
|
---|
[2703b824] | 101 | }
|
---|
| 102 |
|
---|
[02b38730] | 103 | /** @}
|
---|
| 104 | */
|
---|
| 105 |
|
---|