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