Changes in uspace/drv/char/ns8250/ns8250.c [74017ce:d51838f] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/char/ns8250/ns8250.c
r74017ce rd51838f 1 1 /* 2 2 * Copyright (c) 2010 Lenka Trochtova 3 * Copyright (c) 201 7Jiri Svoboda3 * Copyright (c) 2011 Jiri Svoboda 4 4 * All rights reserved. 5 5 * … … 53 53 #include <ddf/interrupt.h> 54 54 #include <ddf/log.h> 55 #include < io/chardev_srv.h>55 #include <ops/char_dev.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;157 155 /** Parent session */ 158 156 async_sess_t *parent_sess; … … 191 189 } 192 190 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 200 191 /** Find out if there is some incoming data available on the serial port. 201 192 * … … 243 234 /** Read data from the serial port device. 244 235 * 245 * @param srv Server-side connection data236 * @param fun The serial port function 246 237 * @param buf The output buffer for read data. 247 238 * @param count The number of bytes to be read. 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 } 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; 262 249 263 250 fibril_mutex_lock(&ns->mutex); 264 251 while (buf_is_empty(&ns->input_buffer)) 265 252 fibril_condvar_wait(&ns->input_buffer_available, &ns->mutex); 266 while (!buf_is_empty(&ns->input_buffer) && pos< count) {267 b p[pos] = (char)buf_pop_front(&ns->input_buffer);268 pos++;253 while (!buf_is_empty(&ns->input_buffer) && (size_t)ret < count) { 254 buf[ret] = (char)buf_pop_front(&ns->input_buffer); 255 ret++; 269 256 } 270 257 fibril_mutex_unlock(&ns->mutex); 271 258 272 *nread = pos; 273 return EOK; 259 return ret; 274 260 } 275 261 … … 288 274 /** Write data to the serial port. 289 275 * 290 * @param srv Server-side connection data276 * @param fun The serial port function 291 277 * @param buf The data to be written 292 278 * @param count The number of bytes to be written 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); 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); 300 284 size_t idx; 301 uint8_t *bp = (uint8_t *) buf;302 285 303 286 for (idx = 0; idx < count; idx++) 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 *); 287 ns8250_putchar(ns, (uint8_t) buf[idx]); 288 289 return count; 290 } 291 292 static ddf_dev_ops_t ns8250_dev_ops; 313 293 314 294 /** The character interface's callbacks. */ 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 295 static char_dev_ops_t ns8250_char_dev_ops = { 296 .read = &ns8250_read, 297 .write = &ns8250_write 321 298 }; 322 323 static void ns8250_char_conn(ipc_callid_t, ipc_call_t *, void *);324 299 325 300 static int ns8250_dev_add(ddf_dev_t *dev); … … 897 872 } 898 873 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 874 /* Set device operations. */ 875 ddf_fun_set_ops(fun, &ns8250_dev_ops); 905 876 rc = ddf_fun_bind(fun); 906 877 if (rc != EOK) { … … 959 930 * device. 960 931 * 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); 932 * @param dev The device. 933 */ 934 static int ns8250_open(ddf_fun_t *fun) 935 { 936 ns8250_t *ns = fun_ns8250(fun); 967 937 int res; 968 938 … … 984 954 * the device. 985 955 * 986 * @param srv Server-side connection structure987 */ 988 static int ns8250_close(chardev_srv_t *srv)989 { 990 ns8250_t *data = srv_ns8250(srv);956 * @param dev The device. 957 */ 958 static void ns8250_close(ddf_fun_t *fun) 959 { 960 ns8250_t *data = fun_ns8250(fun); 991 961 992 962 fibril_mutex_lock(&data->mutex); … … 998 968 999 969 fibril_mutex_unlock(&data->mutex); 1000 1001 return EOK;1002 970 } 1003 971 … … 1066 1034 * Configure the parameters of the serial communication. 1067 1035 */ 1068 static void ns8250_default_handler( chardev_srv_t *srv, ipc_callid_t callid,1036 static void ns8250_default_handler(ddf_fun_t *fun, ipc_callid_t callid, 1069 1037 ipc_call_t *call) 1070 1038 { 1071 ns8250_t *ns8250 = srv_ns8250(srv);1072 1039 sysarg_t method = IPC_GET_IMETHOD(*call); 1073 1040 int ret; … … 1076 1043 switch (method) { 1077 1044 case SERIAL_GET_COM_PROPS: 1078 ns8250_get_props( ns8250->dev, &baud_rate, &parity, &word_length,1045 ns8250_get_props(ddf_fun_get_dev(fun), &baud_rate, &parity, &word_length, 1079 1046 &stop_bits); 1080 1047 async_answer_4(callid, EOK, baud_rate, parity, word_length, … … 1087 1054 word_length = IPC_GET_ARG3(*call); 1088 1055 stop_bits = IPC_GET_ARG4(*call); 1089 ret = ns8250_set_props( ns8250->dev, baud_rate, parity, word_length,1056 ret = ns8250_set_props(ddf_fun_get_dev(fun), baud_rate, parity, word_length, 1090 1057 stop_bits); 1091 1058 async_answer_0(callid, ret); … … 1097 1064 } 1098 1065 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 1106 1066 /** Initialize the serial port driver. 1107 1067 * … … 1112 1072 { 1113 1073 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; 1114 1080 } 1115 1081
Note:
See TracChangeset
for help on using the changeset viewer.