[59e92f62] | 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 libdrv
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
| 33 | */
|
---|
| 34 |
|
---|
| 35 | #include <async.h>
|
---|
| 36 | #include <errno.h>
|
---|
| 37 | #include <time.h>
|
---|
[9be30cdf] | 38 | #include <macros.h>
|
---|
[6e04581] | 39 | #include <device/clock_dev.h>
|
---|
[59e92f62] | 40 |
|
---|
| 41 | #include <ops/clock_dev.h>
|
---|
| 42 | #include <ddf/driver.h>
|
---|
| 43 |
|
---|
| 44 | static void remote_clock_time_get(ddf_fun_t *, void *, ipc_callid_t,
|
---|
| 45 | ipc_call_t *);
|
---|
| 46 | static void remote_clock_time_set(ddf_fun_t *, void *, ipc_callid_t,
|
---|
| 47 | ipc_call_t *);
|
---|
| 48 |
|
---|
| 49 | /** Remote clock interface operations */
|
---|
[9be30cdf] | 50 | static const remote_iface_func_ptr_t remote_clock_dev_iface_ops[] = {
|
---|
[6e04581] | 51 | [CLOCK_DEV_TIME_GET] = remote_clock_time_get,
|
---|
| 52 | [CLOCK_DEV_TIME_SET] = remote_clock_time_set,
|
---|
[59e92f62] | 53 | };
|
---|
| 54 |
|
---|
| 55 | /** Remote clock interface structure
|
---|
| 56 | *
|
---|
| 57 | * Interface for processing requests from remote clients
|
---|
| 58 | * addressed by the clock interface.
|
---|
| 59 | */
|
---|
[7f80313] | 60 | const remote_iface_t remote_clock_dev_iface = {
|
---|
[9be30cdf] | 61 | .method_count = ARRAY_SIZE(remote_clock_dev_iface_ops),
|
---|
[59e92f62] | 62 | .methods = remote_clock_dev_iface_ops,
|
---|
| 63 | };
|
---|
| 64 |
|
---|
| 65 | /** Process the time_get() request from the remote client
|
---|
| 66 | *
|
---|
| 67 | * @param fun The function from which the time is read
|
---|
| 68 | * @param ops The local ops structure
|
---|
| 69 | */
|
---|
| 70 | static void
|
---|
| 71 | remote_clock_time_get(ddf_fun_t *fun, void *ops, ipc_callid_t callid,
|
---|
| 72 | ipc_call_t *call)
|
---|
| 73 | {
|
---|
| 74 | clock_dev_ops_t *clock_dev_ops = (clock_dev_ops_t *) ops;
|
---|
| 75 | ipc_callid_t cid;
|
---|
| 76 | struct tm t;
|
---|
[b7fd2a0] | 77 | errno_t rc;
|
---|
[59e92f62] | 78 | size_t len;
|
---|
| 79 |
|
---|
| 80 | if (!async_data_read_receive(&cid, &len)) {
|
---|
| 81 | /* TODO: Handle protocol error */
|
---|
| 82 | async_answer_0(callid, EINVAL);
|
---|
| 83 | return;
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | if (!clock_dev_ops->time_get) {
|
---|
| 87 | /* The driver does not provide the time_get() functionality */
|
---|
[9ab2714] | 88 | async_answer_0(cid, ENOTSUP);
|
---|
[59e92f62] | 89 | async_answer_0(callid, ENOTSUP);
|
---|
| 90 | return;
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | rc = (*clock_dev_ops->time_get)(fun, &t);
|
---|
| 94 |
|
---|
| 95 | if (rc != EOK) {
|
---|
| 96 | /* Some error occurred */
|
---|
[9ab2714] | 97 | async_answer_0(cid, rc);
|
---|
[59e92f62] | 98 | async_answer_0(callid, rc);
|
---|
[bfc5577a] | 99 | return;
|
---|
[59e92f62] | 100 | }
|
---|
| 101 |
|
---|
| 102 | /* The operation was successful */
|
---|
| 103 | async_data_read_finalize(cid, &t, sizeof(struct tm));
|
---|
[bfc5577a] | 104 | async_answer_0(callid, rc);
|
---|
[59e92f62] | 105 | }
|
---|
| 106 |
|
---|
[917797f] | 107 | /** Process the time_set() request from the remote client
|
---|
[aeb49e9] | 108 | *
|
---|
| 109 | * @param fun The function to which the data are written
|
---|
| 110 | * @param ops The local ops structure
|
---|
| 111 | */
|
---|
| 112 | static void remote_clock_time_set(ddf_fun_t *fun, void *ops,
|
---|
| 113 | ipc_callid_t callid, ipc_call_t *call)
|
---|
| 114 | {
|
---|
| 115 | clock_dev_ops_t *clock_dev_ops = (clock_dev_ops_t *) ops;
|
---|
[b7fd2a0] | 116 | errno_t rc;
|
---|
[aeb49e9] | 117 | struct tm t;
|
---|
| 118 | ipc_callid_t cid;
|
---|
| 119 | size_t len;
|
---|
| 120 |
|
---|
| 121 | if (!async_data_write_receive(&cid, &len)) {
|
---|
| 122 | /* TODO: Handle protocol error */
|
---|
| 123 | async_answer_0(callid, EINVAL);
|
---|
| 124 | return;
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | if (!clock_dev_ops->time_set) {
|
---|
| 128 | /* The driver does not support the time_set() functionality */
|
---|
[3ccba14] | 129 | async_answer_0(cid, ENOTSUP);
|
---|
[aeb49e9] | 130 | async_answer_0(callid, ENOTSUP);
|
---|
| 131 | return;
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 | async_data_write_finalize(cid, &t, sizeof(struct tm));
|
---|
| 135 |
|
---|
| 136 | rc = (*clock_dev_ops->time_set)(fun, &t);
|
---|
| 137 |
|
---|
[bfc5577a] | 138 | async_answer_0(callid, rc);
|
---|
[aeb49e9] | 139 | }
|
---|
[59e92f62] | 140 |
|
---|
| 141 | /**
|
---|
| 142 | * @}
|
---|
| 143 | */
|
---|
| 144 |
|
---|