Changeset 74017ce in mainline
- Timestamp:
- 2017-11-22T17:36:54Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7a6065c
- Parents:
- c4c6025
- git-author:
- Jiri Svoboda <jiri@…> (2017-11-22 15:53:34)
- git-committer:
- Jiri Svoboda <jiri@…> (2017-11-22 17:36:54)
- Files:
-
- 5 deleted
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
.gitignore
rc4c6025 r74017ce 248 248 uspace/dist/logo.tga 249 249 uspace/dist/srv/cdfs 250 uspace/dist/srv/chardev-test 250 251 uspace/dist/srv/clipboard 251 252 uspace/dist/srv/compositor … … 420 421 uspace/srv/ns/ns 421 422 uspace/srv/taskmon/taskmon 423 uspace/srv/test/chardev-test/chardev-test 422 424 uspace/srv/vfs/vfs 423 425 uspace/srv/volsrv/volsrv -
uspace/app/sportdmp/sportdmp.c
rc4c6025 r74017ce 27 27 */ 28 28 29 #include <char_dev_iface.h>30 29 #include <errno.h> 30 #include <io/chardev.h> 31 31 #include <io/serial.h> 32 32 #include <loc.h> 33 33 #include <stdio.h> 34 #include <stdlib.h> 34 35 35 36 #define BUF_SIZE 1 … … 44 45 sysarg_t baud = 9600; 45 46 service_id_t svc_id; 47 chardev_t *chardev; 46 48 serial_t *serial; 49 size_t nread; 47 50 48 51 int arg = 1; … … 119 122 } 120 123 124 rc = chardev_open(sess, &chardev); 125 if (rc != EOK) { 126 fprintf(stderr, "Failed opening character device\n"); 127 return 2; 128 } 129 121 130 rc = serial_open(sess, &serial); 122 131 if (rc != EOK) { … … 138 147 139 148 while (true) { 140 ssize_t read = char_dev_read(sess, buf, BUF_SIZE); 141 if (read < 0) { 142 fprintf(stderr, "Failed reading from serial device\n"); 149 rc = chardev_read(chardev, buf, BUF_SIZE, &nread); 150 for (size_t i = 0; i < nread; i++) { 151 printf("%02hhx ", buf[i]); 152 } 153 if (rc != EOK) { 154 fprintf(stderr, "\nFailed reading from serial device\n"); 143 155 break; 144 }145 ssize_t i;146 for (i = 0; i < read; i++) {147 printf("%02hhx ", buf[i]);148 156 } 149 157 fflush(stdout); … … 152 160 free(buf); 153 161 serial_close(serial); 162 chardev_close(chardev); 154 163 async_hangup(sess); 155 164 return 0; -
uspace/app/tester/Makefile
rc4c6025 r74017ce 68 68 mm/mapping1.c \ 69 69 mm/pager1.c \ 70 hw/misc/virtchar1.c \71 70 hw/serial/serial1.c \ 72 71 chardev/chardev1.c -
uspace/app/tester/hw/serial/serial1.c
rc4c6025 r74017ce 35 35 */ 36 36 37 #include < inttypes.h>37 #include <async.h> 38 38 #include <errno.h> 39 #include <io/chardev.h> 40 #include <io/serial.h> 41 #include <ipc/services.h> 42 #include <loc.h> 39 43 #include <stdlib.h> 40 44 #include <stdio.h> 41 45 #include <stddef.h> 42 #include < async.h>46 #include <str.h> 43 47 #include <thread.h> 44 #include <ipc/services.h>45 #include <loc.h>46 #include <char_dev_iface.h>47 #include <str.h>48 #include <io/serial.h>49 48 #include "../../tester.h" 50 49 … … 57 56 size_t cnt; 58 57 serial_t *serial; 58 chardev_t *chardev; 59 int rc; 60 size_t nread; 61 size_t nwritten; 59 62 60 63 if (test_argc < 1) … … 83 86 return "Failed connecting to serial device"; 84 87 88 res = chardev_open(sess, &chardev); 89 if (res != EOK) { 90 async_hangup(sess); 91 return "Failed opening serial port"; 92 } 93 85 94 res = serial_open(sess, &serial); 86 if (res != EOK) 95 if (res != EOK) { 96 chardev_close(chardev); 97 async_hangup(sess); 87 98 return "Failed opening serial port"; 99 } 88 100 89 101 char *buf = (char *) malloc(cnt + 1); 90 102 if (buf == NULL) { 103 chardev_close(chardev); 91 104 serial_close(serial); 92 105 async_hangup(sess); … … 103 116 if (res != EOK) { 104 117 free(buf); 118 chardev_close(chardev); 105 119 serial_close(serial); 106 120 async_hangup(sess); … … 111 125 if (EOK != res) { 112 126 free(buf); 127 chardev_close(chardev); 113 128 serial_close(serial); 114 129 async_hangup(sess); … … 121 136 size_t total = 0; 122 137 while (total < cnt) { 123 ssize_t read = char_dev_read(sess, buf, cnt - total);124 125 if (r ead < 0) {138 139 rc = chardev_read(chardev, buf, cnt - total, &nread); 140 if (rc != EOK) { 126 141 (void) serial_set_comm_props(serial, old_baud, 127 142 old_par, old_word_size, old_stop); 128 143 129 144 free(buf); 145 chardev_close(chardev); 130 146 serial_close(serial); 131 147 async_hangup(sess); … … 133 149 } 134 150 135 if ( (size_t)read > cnt - total) {151 if (nread > cnt - total) { 136 152 (void) serial_set_comm_props(serial, old_baud, 137 153 old_par, old_word_size, old_stop); 138 154 139 155 free(buf); 156 chardev_close(chardev); 140 157 serial_close(serial); 141 158 async_hangup(sess); … … 143 160 } 144 161 145 TPRINTF("Read %zd bytes\n", read);146 147 if ( read == 0)162 TPRINTF("Read %zd bytes\n", nread); 163 164 if (nread == 0) 148 165 thread_usleep(DEFAULT_SLEEP); 149 166 else { 150 buf[ read] = 0;167 buf[nread] = 0; 151 168 152 169 /* … … 154 171 * direction of data transfer. 155 172 */ 156 ssize_t written = char_dev_write(sess, buf, read); 157 158 if (written < 0) { 173 rc = chardev_write(chardev, buf, nread, &nwritten); 174 if (rc != EOK) { 159 175 (void) serial_set_comm_props(serial, old_baud, 160 176 old_par, old_word_size, old_stop); 161 177 162 178 free(buf); 179 chardev_close(chardev); 163 180 serial_close(serial); 164 181 async_hangup(sess); … … 166 183 } 167 184 168 if ( written !=read) {185 if (nwritten != nread) { 169 186 (void) serial_set_comm_props(serial, old_baud, 170 187 old_par, old_word_size, old_stop); 171 188 172 189 free(buf); 190 chardev_close(chardev); 173 191 serial_close(serial); 174 192 async_hangup(sess); … … 176 194 } 177 195 178 TPRINTF("Written %zd bytes\n", written);179 } 180 181 total += read;196 TPRINTF("Written %zd bytes\n", nwritten); 197 } 198 199 total += nread; 182 200 } 183 201 … … 185 203 186 204 size_t eot_size = str_size(EOT); 187 ssize_t written = char_dev_write(sess, (void *) EOT, eot_size);205 rc = chardev_write(chardev, (void *) EOT, eot_size, &nwritten); 188 206 189 207 (void) serial_set_comm_props(serial, old_baud, old_par, old_word_size, … … 191 209 192 210 free(buf); 211 chardev_close(chardev); 193 212 serial_close(serial); 194 213 async_hangup(sess); 195 214 196 if ( written < 0)215 if (rc != EOK) 197 216 return "Failed to write EOT banner to serial device"; 198 217 199 if ( (size_t)written != eot_size)218 if (nwritten != eot_size) 200 219 return "Written less data than the size of the EOT banner " 201 220 "to serial device"; -
uspace/app/tester/tester.c
rc4c6025 r74017ce 76 76 #include "mm/pager1.def" 77 77 #include "hw/serial/serial1.def" 78 #include "hw/misc/virtchar1.def"79 78 #include "chardev/chardev1.def" 80 79 {NULL, NULL, NULL, false} -
uspace/app/tester/tester.h
rc4c6025 r74017ce 108 108 extern const char *test_pager1(void); 109 109 extern const char *test_serial1(void); 110 extern const char *test_virtchar1(void);111 110 extern const char *test_devman1(void); 112 111 extern const char *test_devman2(void); -
uspace/drv/char/ns8250/ns8250.c
rc4c6025 r74017ce 1 1 /* 2 2 * Copyright (c) 2010 Lenka Trochtova 3 * Copyright (c) 201 1Jiri Svoboda3 * Copyright (c) 2017 Jiri Svoboda 4 4 * All rights reserved. 5 5 * … … 53 53 #include <ddf/interrupt.h> 54 54 #include <ddf/log.h> 55 #include < ops/char_dev.h>55 #include <io/chardev_srv.h> 56 56 57 57 #include <device/hw_res.h> … … 153 153 /** DDF function node */ 154 154 ddf_fun_t *fun; 155 /** Character device service */ 156 chardev_srvs_t cds; 155 157 /** Parent session */ 156 158 async_sess_t *parent_sess; … … 189 191 } 190 192 193 /** Obtain soft-state structure from chardev srv */ 194 static ns8250_t *srv_ns8250(chardev_srv_t *srv) 195 { 196 return (ns8250_t *)srv->srvs->sarg; 197 } 198 199 191 200 /** Find out if there is some incoming data available on the serial port. 192 201 * … … 234 243 /** Read data from the serial port device. 235 244 * 236 * @param fun The serial port function245 * @param srv Server-side connection data 237 246 * @param buf The output buffer for read data. 238 247 * @param count The number of bytes to be read. 239 * 240 * @return The number of bytes actually read on success, negative 241 * error number otherwise. 242 */ 243 static int ns8250_read(ddf_fun_t *fun, char *buf, size_t count) 244 { 245 ns8250_t *ns = fun_ns8250(fun); 246 int ret = 0; 247 248 if (count == 0) return 0; 248 * @param nread Place to store number of bytes actually read 249 * 250 * @return EOK on success or non-zero error code 251 */ 252 static int ns8250_read(chardev_srv_t *srv, void *buf, size_t count, size_t *nread) 253 { 254 ns8250_t *ns = srv_ns8250(srv); 255 char *bp = (char *) buf; 256 size_t pos = 0; 257 258 if (count == 0) { 259 *nread = 0; 260 return EOK; 261 } 249 262 250 263 fibril_mutex_lock(&ns->mutex); 251 264 while (buf_is_empty(&ns->input_buffer)) 252 265 fibril_condvar_wait(&ns->input_buffer_available, &ns->mutex); 253 while (!buf_is_empty(&ns->input_buffer) && (size_t)ret< count) {254 b uf[ret] = (char)buf_pop_front(&ns->input_buffer);255 ret++;266 while (!buf_is_empty(&ns->input_buffer) && pos < count) { 267 bp[pos] = (char)buf_pop_front(&ns->input_buffer); 268 pos++; 256 269 } 257 270 fibril_mutex_unlock(&ns->mutex); 258 271 259 return ret; 272 *nread = pos; 273 return EOK; 260 274 } 261 275 … … 274 288 /** Write data to the serial port. 275 289 * 276 * @param fun The serial port function290 * @param srv Server-side connection data 277 291 * @param buf The data to be written 278 292 * @param count The number of bytes to be written 279 * @return Zero on success 280 */ 281 static int ns8250_write(ddf_fun_t *fun, char *buf, size_t count) 282 { 283 ns8250_t *ns = fun_ns8250(fun); 293 * @param nwritten Place to store number of bytes successfully written 294 * @return EOK on success or non-zero error code 295 */ 296 static int ns8250_write(chardev_srv_t *srv, const void *buf, size_t count, 297 size_t *nwritten) 298 { 299 ns8250_t *ns = srv_ns8250(srv); 284 300 size_t idx; 301 uint8_t *bp = (uint8_t *) buf; 285 302 286 303 for (idx = 0; idx < count; idx++) 287 ns8250_putchar(ns, (uint8_t) buf[idx]); 288 289 return count; 290 } 291 292 static ddf_dev_ops_t ns8250_dev_ops; 304 ns8250_putchar(ns, bp[idx]); 305 306 *nwritten = count; 307 return EOK; 308 } 309 310 static int ns8250_open(chardev_srvs_t *, chardev_srv_t *); 311 static int ns8250_close(chardev_srv_t *); 312 static void ns8250_default_handler(chardev_srv_t *, ipc_callid_t, ipc_call_t *); 293 313 294 314 /** The character interface's callbacks. */ 295 static char_dev_ops_t ns8250_char_dev_ops = { 296 .read = &ns8250_read, 297 .write = &ns8250_write 315 static chardev_ops_t ns8250_chardev_ops = { 316 .open = ns8250_open, 317 .close = ns8250_close, 318 .read = ns8250_read, 319 .write = ns8250_write, 320 .def_handler = ns8250_default_handler 298 321 }; 322 323 static void ns8250_char_conn(ipc_callid_t, ipc_call_t *, void *); 299 324 300 325 static int ns8250_dev_add(ddf_dev_t *dev); … … 872 897 } 873 898 874 /* Set device operations. */ 875 ddf_fun_set_ops(fun, &ns8250_dev_ops); 899 ddf_fun_set_conn_handler(fun, ns8250_char_conn); 900 901 chardev_srvs_init(&ns->cds); 902 ns->cds.ops = &ns8250_chardev_ops; 903 ns->cds.sarg = ns; 904 876 905 rc = ddf_fun_bind(fun); 877 906 if (rc != EOK) { … … 930 959 * device. 931 960 * 932 * @param dev The device. 933 */ 934 static int ns8250_open(ddf_fun_t *fun) 935 { 936 ns8250_t *ns = fun_ns8250(fun); 961 * @param srvs Service structure 962 * @param srv Server-side connection structure 963 */ 964 static int ns8250_open(chardev_srvs_t *srvs, chardev_srv_t *srv) 965 { 966 ns8250_t *ns = srv_ns8250(srv); 937 967 int res; 938 968 … … 954 984 * the device. 955 985 * 956 * @param dev The device.957 */ 958 static void ns8250_close(ddf_fun_t *fun)959 { 960 ns8250_t *data = fun_ns8250(fun);986 * @param srv Server-side connection structure 987 */ 988 static int ns8250_close(chardev_srv_t *srv) 989 { 990 ns8250_t *data = srv_ns8250(srv); 961 991 962 992 fibril_mutex_lock(&data->mutex); … … 968 998 969 999 fibril_mutex_unlock(&data->mutex); 1000 1001 return EOK; 970 1002 } 971 1003 … … 1034 1066 * Configure the parameters of the serial communication. 1035 1067 */ 1036 static void ns8250_default_handler( ddf_fun_t *fun, ipc_callid_t callid,1068 static void ns8250_default_handler(chardev_srv_t *srv, ipc_callid_t callid, 1037 1069 ipc_call_t *call) 1038 1070 { 1071 ns8250_t *ns8250 = srv_ns8250(srv); 1039 1072 sysarg_t method = IPC_GET_IMETHOD(*call); 1040 1073 int ret; … … 1043 1076 switch (method) { 1044 1077 case SERIAL_GET_COM_PROPS: 1045 ns8250_get_props( ddf_fun_get_dev(fun), &baud_rate, &parity, &word_length,1078 ns8250_get_props(ns8250->dev, &baud_rate, &parity, &word_length, 1046 1079 &stop_bits); 1047 1080 async_answer_4(callid, EOK, baud_rate, parity, word_length, … … 1054 1087 word_length = IPC_GET_ARG3(*call); 1055 1088 stop_bits = IPC_GET_ARG4(*call); 1056 ret = ns8250_set_props( ddf_fun_get_dev(fun), baud_rate, parity, word_length,1089 ret = ns8250_set_props(ns8250->dev, baud_rate, parity, word_length, 1057 1090 stop_bits); 1058 1091 async_answer_0(callid, ret); … … 1064 1097 } 1065 1098 1099 void ns8250_char_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg) 1100 { 1101 ns8250_t *ns8250 = fun_ns8250((ddf_fun_t *)arg); 1102 1103 chardev_conn(iid, icall, &ns8250->cds); 1104 } 1105 1066 1106 /** Initialize the serial port driver. 1067 1107 * … … 1072 1112 { 1073 1113 ddf_log_init(NAME); 1074 1075 ns8250_dev_ops.open = &ns8250_open;1076 ns8250_dev_ops.close = &ns8250_close;1077 1078 ns8250_dev_ops.interfaces[CHAR_DEV_IFACE] = &ns8250_char_dev_ops;1079 ns8250_dev_ops.default_handler = &ns8250_default_handler;1080 1114 } 1081 1115 -
uspace/drv/root/virt/devices.def
rc4c6025 r74017ce 26 26 }, 27 27 { 28 .name = "null",29 .match_id = "virtual&test1"30 },31 {32 28 .name = "test3", 33 29 .match_id = "virtual&test3" -
uspace/drv/test/test1/Makefile
rc4c6025 r74017ce 32 32 33 33 SOURCES = \ 34 char.c \35 34 test1.c 36 35 -
uspace/drv/test/test1/test1.c
rc4c6025 r74017ce 177 177 ddf_fun_add_to_category(fun_a, "virtual"); 178 178 179 if (str_cmp(dev_name, "null") == 0) { 180 ddf_fun_set_ops(fun_a, &char_device_ops); 181 ddf_fun_add_to_category(fun_a, "virt-null"); 182 } else if (str_cmp(dev_name, "test1") == 0) { 179 if (str_cmp(dev_name, "test1") == 0) { 183 180 (void) register_fun_verbose(dev, 184 181 "cloning myself ;-)", "clone", -
uspace/drv/test/test1/test1.h
rc4c6025 r74017ce 36 36 #define NAME "test1" 37 37 38 extern ddf_dev_ops_t char_device_ops;39 40 38 #endif -
uspace/lib/c/generic/io/chardev_srv.c
rc4c6025 r74017ce 169 169 break; 170 170 default: 171 async_answer_0(callid, EINVAL); 171 if (srv->srvs->ops->def_handler != NULL) 172 srv->srvs->ops->def_handler(srv, callid, &call); 173 else 174 async_answer_0(callid, ENOTSUP); 172 175 } 173 176 } -
uspace/lib/c/include/io/chardev_srv.h
rc4c6025 r74017ce 61 61 int (*read)(chardev_srv_t *, void *, size_t, size_t *); 62 62 int (*write)(chardev_srv_t *, const void *, size_t, size_t *); 63 void (*def_handler)(chardev_srv_t *, ipc_callid_t, ipc_call_t *); 63 64 }; 64 65 -
uspace/lib/c/include/ipc/chardev.h
rc4c6025 r74017ce 41 41 typedef enum { 42 42 CHARDEV_READ = IPC_FIRST_USER_METHOD, 43 CHARDEV_WRITE 43 CHARDEV_WRITE, 44 44 } chardev_request_t; 45 46 enum { 47 CHARDEV_LIMIT = CHARDEV_WRITE + 1 48 }; 45 49 46 50 #endif -
uspace/lib/c/include/ipc/serial_ctl.h
rc4c6025 r74017ce 30 30 #define LIBC_IPC_SERIAL_CTL_H_ 31 31 32 #include <ipc/ dev_iface.h>32 #include <ipc/chardev.h> 33 33 34 34 /** IPC methods for getting/setting serial communication properties … … 41 41 */ 42 42 typedef enum { 43 SERIAL_GET_COM_PROPS = DEV_FIRST_CUSTOM_METHOD,43 SERIAL_GET_COM_PROPS = CHARDEV_LIMIT, 44 44 SERIAL_SET_COM_PROPS 45 45 } serial_ctl_t; -
uspace/lib/drv/Makefile
rc4c6025 r74017ce 43 43 generic/remote_hw_res.c \ 44 44 generic/remote_pio_window.c \ 45 generic/remote_char_dev.c \46 45 generic/remote_nic.c \ 47 46 generic/remote_ieee80211.c \ -
uspace/lib/drv/generic/dev_iface.c
rc4c6025 r74017ce 42 42 #include "remote_hw_res.h" 43 43 #include "remote_pio_window.h" 44 #include "remote_char_dev.h"45 44 #include "remote_clock_dev.h" 46 45 #include "remote_led_dev.h" … … 62 61 [HW_RES_DEV_IFACE] = &remote_hw_res_iface, 63 62 [PIO_WINDOW_DEV_IFACE] = &remote_pio_window_iface, 64 [CHAR_DEV_IFACE] = &remote_char_dev_iface,65 63 [NIC_DEV_IFACE] = &remote_nic_iface, 66 64 [IEEE80211_DEV_IFACE] = &remote_ieee80211_iface, -
uspace/srv/hid/input/input.c
rc4c6025 r74017ce 37 37 */ 38 38 39 #include <adt/fifo.h> 39 40 #include <adt/list.h> 40 #include <stdbool.h> 41 #include <async.h> 42 #include <config.h> 43 #include <errno.h> 44 #include <fibril.h> 41 45 #include <fibril_synch.h> 46 #include <io/chardev.h> 47 #include <io/console.h> 48 #include <io/keycode.h> 42 49 #include <ipc/services.h> 43 50 #include <ipc/input.h> 44 #include <config.h> 51 #include <loc.h> 52 #include <ns.h> 53 #include <stdbool.h> 45 54 #include <stdio.h> 46 55 #include <stdlib.h> 47 #include <ns.h>48 #include <async.h>49 #include <errno.h>50 #include <adt/fifo.h>51 #include <io/console.h>52 #include <io/keycode.h>53 #include <loc.h>54 56 #include <str_error.h> 55 #include <char_dev_iface.h> 56 #include <fibril.h> 57 #include "layout.h" 57 58 #include "input.h" 58 59 #include "kbd.h" 59 60 #include "kbd_port.h" 60 61 #include "kbd_ctl.h" 62 #include "layout.h" 61 63 #include "mouse.h" 62 64 #include "mouse_proto.h" 63 65 #include "serial.h" 64 #include "input.h"65 66 66 67 #define NUM_LAYOUTS 4 … … 536 537 while (true) { 537 538 uint8_t data; 538 539 char_dev_read(sdev->sess, &data, sizeof(data)); 539 size_t nread; 540 541 chardev_read(sdev->chardev, &data, sizeof(data), &nread); 542 /* XXX Handle error */ 540 543 kbd_push_data(sdev->kdev, data); 541 544 } … … 552 555 { 553 556 bool match = false; 557 int rc; 554 558 555 559 serial_dev_t *sdev = serial_dev_new(); … … 559 563 sdev->kdev->svc_id = service_id; 560 564 561 intrc = loc_service_get_name(service_id, &sdev->kdev->svc_name);565 rc = loc_service_get_name(service_id, &sdev->kdev->svc_name); 562 566 if (rc != EOK) 563 567 goto fail; … … 582 586 sdev->sess = loc_service_connect(service_id, INTERFACE_DDF, 583 587 IPC_FLAG_BLOCKING); 588 589 rc = chardev_open(sdev->sess, &sdev->chardev); 590 if (rc != EOK) { 591 async_hangup(sdev->sess); 592 sdev->sess = NULL; 593 list_remove(&sdev->link); 594 goto fail; 595 } 584 596 585 597 fid_t fid = fibril_create(serial_consumer, sdev); -
uspace/srv/hid/input/serial.h
rc4c6025 r74017ce 39 39 40 40 #include <async.h> 41 #include <io/chardev.h> 41 42 #include "kbd.h" 42 43 … … 45 46 link_t link; 46 47 async_sess_t *sess; 48 chardev_t *chardev; 47 49 } serial_dev_t; 48 50 -
uspace/srv/hid/isdv4_tablet/isdv4.c
rc4c6025 r74017ce 27 27 */ 28 28 29 #include <char_dev_iface.h>30 29 #include <errno.h> 30 #include <io/chardev.h> 31 #include <mem.h> 31 32 #include <stdbool.h> 32 33 #include <stdint.h> 33 34 #include <stdlib.h> 34 #include <mem.h>35 35 #include <thread.h> 36 36 … … 298 298 bool reading = true; 299 299 while (reading) { 300 ssize_t read = char_dev_read(state->sess, state->buf + state->buf_end, 301 state->buf_size - state->buf_end); 302 if (read < 0) 300 size_t nread; 301 int rc; 302 303 rc = chardev_read(state->chardev, state->buf + state->buf_end, 304 state->buf_size - state->buf_end, &nread); 305 if (rc != EOK && nread == 0) 303 306 return EIO; 304 state->buf_end += read;307 state->buf_end += nread; 305 308 306 309 size_t i = 0; … … 357 360 return EOK; 358 361 } 359 static bool write_command(async_sess_t *sess, uint8_t command) 360 { 361 return char_dev_write(sess, &command, 1) == 1; 362 363 static bool write_command(chardev_t *chardev, uint8_t command) 364 { 365 int rc; 366 size_t nwr; 367 368 rc = chardev_write(chardev, &command, 1, &nwr); 369 return rc == EOK; 362 370 } 363 371 … … 365 373 isdv4_event_fn event_fn) 366 374 { 375 chardev_t *chardev; 376 int rc; 377 378 rc = chardev_open(sess, &chardev); 379 if (rc != EOK) 380 return rc; 381 367 382 memset(state, 0, sizeof(isdv4_state_t)); 383 368 384 state->sess = sess; 385 state->chardev = chardev; 386 369 387 state->buf = malloc(BUF_SIZE); 370 if (state->buf == NULL) 388 if (state->buf == NULL) { 389 chardev_close(chardev); 371 390 return ENOMEM; 391 } 392 372 393 state->buf_size = BUF_SIZE; 373 394 state->emit_event_fn = event_fn; … … 377 398 int isdv4_init_tablet(isdv4_state_t *state) 378 399 { 379 if (!write_command(state-> sess, CMD_STOP))400 if (!write_command(state->chardev, CMD_STOP)) 380 401 return EIO; 381 402 … … 383 404 384 405 // FIXME: Read all possible garbage before sending commands 385 if (!write_command(state-> sess, CMD_QUERY_STYLUS))406 if (!write_command(state->chardev, CMD_QUERY_STYLUS)) 386 407 return EIO; 387 408 … … 390 411 return rc; 391 412 392 if (!write_command(state-> sess, CMD_QUERY_TOUCH))413 if (!write_command(state->chardev, CMD_QUERY_TOUCH)) 393 414 return EIO; 394 415 … … 397 418 return rc; 398 419 399 if (!write_command(state-> sess, CMD_START))420 if (!write_command(state->chardev, CMD_START)) 400 421 return EIO; 401 422 -
uspace/srv/hid/isdv4_tablet/isdv4.h
rc4c6025 r74017ce 31 31 32 32 #include <async.h> 33 #include <io/chardev.h> 33 34 34 35 typedef struct isdv4_event isdv4_event_t; … … 58 59 bool finger1_pressed; /* Reported as touch button 1 */ 59 60 60 /* Session tothe serial device */61 /** Session with the serial device */ 61 62 async_sess_t *sess; 63 /** Character device */ 64 chardev_t *chardev; 62 65 63 66 /* Receive buffer state */ … … 66 69 size_t buf_end; 67 70 68 /* Callbacks */71 /** Callbacks */ 69 72 isdv4_event_fn emit_event_fn; 70 73 } isdv4_state_t; -
uspace/srv/hid/output/port/chardev.c
rc4c6025 r74017ce 30 30 */ 31 31 32 #include <async.h> 33 #include <config.h> 34 #include <errno.h> 35 #include <fibril_synch.h> 36 #include <io/chardev.h> 37 #include <loc.h> 32 38 #include <stddef.h> 33 39 #include <stdint.h> 34 #include <char_dev_iface.h>35 40 #include <stdio.h> 36 41 #include <stdlib.h> 37 #include <async.h>38 #include <fibril_synch.h>39 #include <loc.h>40 #include <errno.h>41 42 #include <str.h> 42 #include <config.h>43 43 #include "../ctl/serial.h" 44 44 #include "../output.h" … … 48 48 49 49 static async_sess_t *sess; 50 static chardev_t *chardev; 50 51 static service_id_t serial_cat_id; 51 52 … … 57 58 { 58 59 uint8_t byte = (uint8_t) ch; 59 char_dev_write(sess, &byte, 1); 60 size_t nwr; 61 chardev_write(chardev, &byte, 1, &nwr); 62 /* XXX Handle error */ 60 63 } 61 64 62 65 static void chardev_control_puts(const char *str) 63 66 { 64 char_dev_write(sess, (void *) str, str_size(str)); 67 size_t nwr; 68 chardev_write(chardev, (void *) str, str_size(str), &nwr); 69 /* XXX Handle error */ 65 70 } 66 71 … … 126 131 return; 127 132 } 133 134 rc = chardev_open(sess, &chardev); 135 if (rc != EOK) { 136 fibril_mutex_unlock(&discovery_lock); 137 printf("%s: Failed opening character device\n", NAME); 138 return; 139 } 140 128 141 serial_init(chardev_putchar, chardev_control_puts); 129 142 -
uspace/srv/net/slip/slip.c
rc4c6025 r74017ce 40 40 #include <inet/addr.h> 41 41 #include <inet/iplink_srv.h> 42 #include < char_dev_iface.h>42 #include <io/chardev.h> 43 43 #include <io/log.h> 44 44 #include <errno.h> … … 96 96 } 97 97 98 static void write_flush( async_sess_t *sess)98 static void write_flush(chardev_t *chardev) 99 99 { 100 100 size_t written = 0; 101 101 102 102 while (slip_send_pending > 0) { 103 ssize_t size; 104 105 size = char_dev_write(sess, &slip_send_buf[written], 106 slip_send_pending); 107 if (size < 0) { 103 int rc; 104 size_t nwr; 105 106 rc = chardev_write(chardev, &slip_send_buf[written], 107 slip_send_pending, &nwr); 108 if (rc != EOK) { 108 109 log_msg(LOG_DEFAULT, LVL_ERROR, 109 "char_dev_write() returned %d", 110 (int) size); 110 "chardev_write() returned %d", rc); 111 111 slip_send_pending = 0; 112 112 break; 113 113 } 114 written += size;115 slip_send_pending -= size;116 } 117 } 118 119 static void write_buffered( async_sess_t *sess, uint8_t ch)114 written += nwr; 115 slip_send_pending -= nwr; 116 } 117 } 118 119 static void write_buffered(chardev_t *chardev, uint8_t ch) 120 120 { 121 121 if (slip_send_pending == sizeof(slip_send_buf)) 122 write_flush( sess);122 write_flush(chardev); 123 123 slip_send_buf[slip_send_pending++] = ch; 124 124 } … … 128 128 log_msg(LOG_DEFAULT, LVL_DEBUG, "slip_send()"); 129 129 130 async_sess_t *sess = (async_sess_t *) srv->arg;130 chardev_t *chardev = (chardev_t *) srv->arg; 131 131 uint8_t *data = sdu->data; 132 132 … … 136 136 * measure for dealing with previous possible noise on the line. 137 137 */ 138 write_buffered( sess, SLIP_END);138 write_buffered(chardev, SLIP_END); 139 139 140 140 for (size_t i = 0; i < sdu->size; i++) { 141 141 switch (data[i]) { 142 142 case SLIP_END: 143 write_buffered( sess, SLIP_ESC);144 write_buffered( sess, SLIP_ESC_END);143 write_buffered(chardev, SLIP_ESC); 144 write_buffered(chardev, SLIP_ESC_END); 145 145 break; 146 146 case SLIP_ESC: 147 write_buffered( sess, SLIP_ESC);148 write_buffered( sess, SLIP_ESC_ESC);147 write_buffered(chardev, SLIP_ESC); 148 write_buffered(chardev, SLIP_ESC_ESC); 149 149 break; 150 150 default: 151 write_buffered( sess, data[i]);151 write_buffered(chardev, data[i]); 152 152 break; 153 153 } 154 154 } 155 155 156 write_buffered( sess, SLIP_END);157 write_flush( sess);156 write_buffered(chardev, SLIP_END); 157 write_flush(chardev); 158 158 159 159 return EOK; … … 203 203 } 204 204 205 static uint8_t read_buffered( async_sess_t *sess)205 static uint8_t read_buffered(chardev_t *chardev) 206 206 { 207 207 while (slip_recv_pending == 0) { 208 ssize_t size; 209 210 size = char_dev_read(sess, slip_recv_buf, 211 sizeof(slip_recv_buf)); 212 if (size < 0) { 208 int rc; 209 size_t nread; 210 211 rc = chardev_read(chardev, slip_recv_buf, 212 sizeof(slip_recv_buf), &nread); 213 if (rc != EOK) { 213 214 log_msg(LOG_DEFAULT, LVL_ERROR, 214 "char_dev_read() returned %d", (int) size); 215 "char_dev_read() returned %d", rc); 216 } 217 218 if (nread == 0) 215 219 return SLIP_END; 216 } 217 slip_recv_pending = size;220 221 slip_recv_pending = nread; 218 222 slip_recv_read = 0; 219 223 } … … 224 228 static int slip_recv_fibril(void *arg) 225 229 { 226 async_sess_t *sess = (async_sess_t *) arg;230 chardev_t *chardev = (chardev_t *) arg; 227 231 static uint8_t recv_final[SLIP_MTU]; 228 232 iplink_recv_sdu_t sdu; … … 234 238 while (true) { 235 239 for (sdu.size = 0; sdu.size < sizeof(recv_final); /**/) { 236 ch = read_buffered( sess);240 ch = read_buffered(chardev); 237 241 switch (ch) { 238 242 case SLIP_END: … … 246 250 247 251 case SLIP_ESC: 248 ch = read_buffered( sess);252 ch = read_buffered(chardev); 249 253 if (ch == SLIP_ESC_END) { 250 254 recv_final[sdu.size++] = SLIP_END; 251 255 break; 252 } else if (ch == 256 } else if (ch == SLIP_ESC_ESC) { 253 257 recv_final[sdu.size++] = SLIP_ESC; 254 258 break; … … 295 299 async_sess_t *sess_in = NULL; 296 300 async_sess_t *sess_out = NULL; 301 chardev_t *chardev_in = NULL; 302 chardev_t *chardev_out = NULL; 297 303 fid_t fid; 298 304 int rc; … … 336 342 return ENOENT; 337 343 } 338 slip_iplink.arg = sess_out; 344 345 rc = chardev_open(sess_out, &chardev_out); 346 if (rc != EOK) { 347 log_msg(LOG_DEFAULT, LVL_ERROR, 348 "Failed opening character device."); 349 return ENOENT; 350 } 351 352 slip_iplink.arg = chardev_out; 339 353 340 354 sess_in = loc_service_connect(svcid, INTERFACE_DDF, 0); … … 347 361 } 348 362 363 rc = chardev_open(sess_in, &chardev_in); 364 if (rc != EOK) { 365 log_msg(LOG_DEFAULT, LVL_ERROR, 366 "Failed opening character device."); 367 return ENOENT; 368 } 369 349 370 rc = loc_service_register(linkstr, &linksid); 350 371 if (rc != EOK) { … … 363 384 } 364 385 365 fid = fibril_create(slip_recv_fibril, sess_in);386 fid = fibril_create(slip_recv_fibril, chardev_in); 366 387 if (!fid) { 367 388 log_msg(LOG_DEFAULT, LVL_ERROR, … … 375 396 376 397 fail: 398 chardev_close(chardev_out); 377 399 if (sess_out) 378 400 async_hangup(sess_out); 401 chardev_close(chardev_in); 379 402 if (sess_in) 380 403 async_hangup(sess_in);
Note:
See TracChangeset
for help on using the changeset viewer.