Changes in uspace/drv/char/ns8250/ns8250.c [d51838f:74017ce] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/char/ns8250/ns8250.c
rd51838f 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
Note:
See TracChangeset
for help on using the changeset viewer.