Changeset c657bd7 in mainline
- Timestamp:
- 2017-11-20T10:06:59Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 19ea61d
- Parents:
- 5d50c419
- git-author:
- Jiri Svoboda <jiri@…> (2017-11-19 22:05:26)
- git-committer:
- Jiri Svoboda <jiri@…> (2017-11-20 10:06:59)
- Location:
- uspace
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/char/i8042/buffer.h
r5d50c419 rc657bd7 113 113 * 114 114 * @param buffer Cyclic buffer to read from. 115 * @param rb Place to store byte read 116 * @param wait @c True to wait until byte is available 115 117 * 116 * @return Byte read.118 * @return EOK on success, EAGAIN if @c wait is false and no data is available 117 119 * 118 120 */ 119 static inline uint8_t buffer_read(buffer_t *buffer)121 static inline int buffer_read(buffer_t *buffer, uint8_t *rb, bool wait) 120 122 { 121 123 fibril_mutex_lock(&buffer->guard); 122 124 123 125 /* Buffer is empty. */ 124 while ( buffer->write_head == buffer->read_head)126 while (wait && buffer->write_head == buffer->read_head) 125 127 fibril_condvar_wait(&buffer->change, &buffer->guard); 128 129 if (buffer->write_head == buffer->read_head) { 130 fibril_mutex_unlock(&buffer->guard); 131 return EAGAIN; 132 } 126 133 127 134 /* Next position. */ … … 144 151 145 152 fibril_mutex_unlock(&buffer->guard); 146 return data; 153 *rb = data; 154 return EOK; 147 155 } 148 156 -
uspace/drv/char/i8042/i8042.c
r5d50c419 rc657bd7 374 374 i8042_t *i8042 = port->ctl; 375 375 uint8_t *destp = (uint8_t *)dest; 376 int rc; 377 size_t i; 376 378 377 379 buffer_t *buffer = (port == i8042->aux) ? 378 380 &i8042->aux_buffer : &i8042->kbd_buffer; 379 381 380 for (size_t i = 0; i < size; ++i) 381 *destp++ = buffer_read(buffer); 382 383 return size; 382 for (i = 0; i < size; ++i) { 383 rc = buffer_read(buffer, destp, i == 0); 384 if (rc != EOK) 385 break; 386 ++destp; 387 } 388 389 return i; 384 390 } 385 391 -
uspace/drv/char/pl050/pl050.c
r5d50c419 rc657bd7 246 246 left = size; 247 247 while (left > 0) { 248 while ( pl050->buf_rp == pl050->buf_wp)248 while (left == size && pl050->buf_rp == pl050->buf_wp) 249 249 fibril_condvar_wait(&pl050->buf_cv, &pl050->buf_lock); 250 if (pl050->buf_rp == pl050->buf_wp) 251 break; 250 252 *bp++ = pl050->buffer[pl050->buf_rp]; 251 253 --left; … … 255 257 fibril_mutex_unlock(&pl050->buf_lock); 256 258 257 return size ;259 return size - left; 258 260 } 259 261 -
uspace/drv/hid/ps2mouse/ps2mouse.c
r5d50c419 rc657bd7 212 212 } 213 213 214 /** Read fixed-size mouse packet. 215 * 216 * Continue reading until entire packet is received. 217 * 218 * @param mouse Mouse device 219 * @param pbuf Buffer for storing packet 220 * @param psize Packet size 221 * 222 * @return EOK on success or non-zero error code 223 */ 224 static int ps2_mouse_read_packet(ps2_mouse_t *mouse, void *pbuf, size_t psize) 225 { 226 int rc; 227 size_t pos; 228 size_t nread; 229 230 pos = 0; 231 while (pos < psize) { 232 rc = chardev_read(mouse->chardev, pbuf + pos, psize - pos, 233 &nread); 234 if (rc != EOK) { 235 ddf_msg(LVL_WARN, "Error reading packet."); 236 return rc; 237 } 238 239 pos += nread; 240 } 241 242 return EOK; 243 } 244 214 245 /** Get data and parse ps2 protocol packets. 215 246 * @param arg Pointer to ps2_mouse_t structure. … … 219 250 { 220 251 ps2_mouse_t *mouse = (ps2_mouse_t *) arg; 221 size_t nread;222 252 int rc; 223 253 … … 225 255 while (1) { 226 256 uint8_t packet[PS2_BUFSIZE] = {}; 227 rc = chardev_read(mouse->chardev, packet, PS2_BUFSIZE, &nread); 228 if (rc != EOK || nread != PS2_BUFSIZE) { 229 ddf_msg(LVL_WARN, "Incorrect packet size: %zd.", nread); 257 rc = ps2_mouse_read_packet(mouse, packet, PS2_BUFSIZE); 258 if (rc != EOK) 230 259 continue; 231 }232 260 233 261 ddf_msg(LVL_DEBUG2, "Got packet: %hhx:%hhx:%hhx.", … … 274 302 { 275 303 ps2_mouse_t *mouse = (ps2_mouse_t *) arg; 276 size_t nread;277 304 int rc; 278 305 … … 280 307 while (1) { 281 308 uint8_t packet[INTELLIMOUSE_BUFSIZE] = {}; 282 rc = chardev_read(mouse->chardev, packet, INTELLIMOUSE_BUFSIZE, 283 &nread); 284 if (rc != EOK || nread != INTELLIMOUSE_BUFSIZE) { 285 ddf_msg(LVL_WARN, "Incorrect packet size: %zd.", nread); 309 rc = ps2_mouse_read_packet(mouse, packet, INTELLIMOUSE_BUFSIZE); 310 if (rc != EOK) 286 311 continue; 287 } 312 288 313 ddf_msg(LVL_DEBUG2, "Got packet: %hhx:%hhx:%hhx:%hhx.", 289 314 packet[0], packet[1], packet[2], packet[3]); -
uspace/drv/hid/xtkbd/xtkbd.c
r5d50c419 rc657bd7 353 353 354 354 size_t nwr; 355 int rc = chardev_write(kbd->chardev, cmds, sizeof(cmds), &nwr); 356 if (nwr != sizeof(cmds)) 357 rc = EIO; 358 355 int rc = chardev_write(kbd->chardev, &cmds[0], 1, &nwr); 356 if (rc != EOK) { 357 async_answer_0(icallid, rc); 358 break; 359 } 360 361 rc = chardev_write(kbd->chardev, &cmds[1], 1, &nwr); 359 362 async_answer_0(icallid, rc); 360 363 break; -
uspace/lib/c/generic/io/chardev.c
r5d50c419 rc657bd7 77 77 } 78 78 79 int chardev_read(chardev_t *chardev, void *data, size_t size, size_t *nread) 79 /** Read from character device. 80 * 81 * Read as much data as is available from character device up to @a size 82 * bytes into @a buf. On success EOK is returned and at least one byte 83 * is read (if no byte is available the function blocks). The number 84 * of bytes read is stored in @a *nread. 85 * 86 * On error a non-zero error code is returned and @a *nread is filled with 87 * the number of bytes that were successfully transferred. 88 * 89 * @param chardev Character device 90 * @param buf Destination buffer 91 * @param size Maximum number of bytes to read 92 * @param nread Place to store actual number of bytes read 93 * 94 * @return EOK on success or non-zero error code 95 */ 96 int chardev_read(chardev_t *chardev, void *buf, size_t size, size_t *nread) 80 97 { 81 98 if (size > 4 * sizeof(sysarg_t)) … … 88 105 async_exchange_end(exch); 89 106 if (ret > 0 && (size_t)ret <= size) 90 memcpy( data, message, size);107 memcpy(buf, message, size); 91 108 92 109 if (ret < 0) { … … 99 116 } 100 117 118 /** Write to character device. 119 * 120 * Write @a size bytes from @a data to character device. On success EOK 121 * is returned, all bytes were written and @a *nwritten is set to @a size. 122 * 123 * On error a non-zero error code is returned and @a *nwritten is filled with 124 * the number of bytes that were successfully transferred. 125 * 126 * @param chardev Character device 127 * @param buf Destination buffer 128 * @param size Maximum number of bytes to read 129 * @param nwritten Place to store actual number of bytes written 130 * 131 * @return EOK on success or non-zero error code 132 */ 101 133 int chardev_write(chardev_t *chardev, const void *data, size_t size, 102 134 size_t *nwritten)
Note:
See TracChangeset
for help on using the changeset viewer.