Changeset 5d50c419 in mainline
- Timestamp:
- 2017-11-19T21:14:19Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c657bd7
- Parents:
- 75fcf9b
- Location:
- uspace
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/hid/atkbd/atkbd.c
r75fcf9b r5d50c419 203 203 { 204 204 at_kbd_t *kbd = arg; 205 size_t nwr; 206 int rc; 205 207 206 208 while (true) { 207 209 uint8_t code = 0; 208 ssize_t size = chardev_read(kbd->chardev, &code, 1);209 if ( size != 1)210 rc = chardev_read(kbd->chardev, &code, 1, &nwr); 211 if (rc != EOK) 210 212 return EIO; 211 213 … … 217 219 map_size = sizeof(scanmap_e0) / sizeof(unsigned int); 218 220 219 size = chardev_read(kbd->chardev, &code, 1);220 if ( size != 1)221 rc = chardev_read(kbd->chardev, &code, 1, &nwr); 222 if (rc != EOK) 221 223 return EIO; 222 224 } else if (code == KBD_SCANCODE_SET_EXTENDED_SPECIAL) { 223 size = chardev_read(kbd->chardev, &code, 1);224 if ( size != 1)225 rc = chardev_read(kbd->chardev, &code, 1, &nwr); 226 if (rc != EOK) 225 227 return EIO; 226 228 if (code != 0x14) 227 229 continue; 228 230 229 size = chardev_read(kbd->chardev, &code, 1);230 if ( size != 1)231 rc = chardev_read(kbd->chardev, &code, 1, &nwr); 232 if (rc != EOK) 231 233 return EIO; 232 234 if (code != 0x77) 233 235 continue; 234 236 235 size = chardev_read(kbd->chardev, &code, 1);236 if ( size != 1)237 rc = chardev_read(kbd->chardev, &code, 1, &nwr); 238 if (rc != EOK) 237 239 return EIO; 238 240 if (code != 0xe1) 239 241 continue; 240 242 241 size = chardev_read(kbd->chardev, &code, 1);242 if ( size != 1)243 rc = chardev_read(kbd->chardev, &code, 1, &nwr); 244 if (rc != EOK) 243 245 return EIO; 244 246 if (code != 0xf0) 245 247 continue; 246 248 247 size = chardev_read(kbd->chardev, &code, 1);248 if ( size != 1)249 rc = chardev_read(kbd->chardev, &code, 1, &nwr); 250 if (rc != EOK) 249 251 return EIO; 250 252 if (code != 0x14) 251 253 continue; 252 254 253 size = chardev_read(kbd->chardev, &code, 1);254 if ( size != 1)255 rc = chardev_read(kbd->chardev, &code, 1, &nwr); 256 if (rc != EOK) 255 257 return EIO; 256 258 if (code != 0xf0) 257 259 continue; 258 260 259 size = chardev_read(kbd->chardev, &code, 1);260 if ( size != 1)261 rc = chardev_read(kbd->chardev, &code, 1, &nwr); 262 if (rc != EOK) 261 263 return EIO; 262 264 if (code == 0x77) … … 272 274 if (code == KBD_SCANCODE_KEY_RELEASE) { 273 275 type = KEY_RELEASE; 274 size = chardev_read(kbd->chardev, &code, 1);275 if ( size != 1)276 rc = chardev_read(kbd->chardev, &code, 1, &nwr); 277 if (rc != EOK) 276 278 return EIO; 277 279 } else { -
uspace/drv/hid/ps2mouse/ps2mouse.c
r75fcf9b r5d50c419 75 75 uint8_t value = (value_); \ 76 76 uint8_t data = 0; \ 77 const ssize_t size = chardev_read((mouse)->chardev, &data, 1); \ 78 if (size != 1) { \ 79 ddf_msg(LVL_ERROR, "Failed reading byte: %zd)", size);\ 80 return size < 0 ? size : EIO; \ 77 size_t nread; \ 78 const int rc = chardev_read((mouse)->chardev, &data, 1, &nread); \ 79 if (rc != EOK) { \ 80 ddf_msg(LVL_ERROR, "Failed reading byte: %d", rc);\ 81 return rc; \ 81 82 } \ 82 83 if (data != value) { \ … … 91 92 uint8_t value = (value_); \ 92 93 uint8_t data = (value); \ 93 const ssize_t size = chardev_write((mouse)->chardev, &data, 1); \ 94 if (size < 0 ) { \ 95 ddf_msg(LVL_ERROR, "Failed writing byte: %hhx", value); \ 96 return size; \ 94 size_t nwr; \ 95 const int rc = chardev_write((mouse)->chardev, &data, 1, &nwr); \ 96 if (rc != EOK) { \ 97 ddf_msg(LVL_ERROR, "Failed writing byte: %d", rc); \ 98 return rc; \ 97 99 } \ 98 100 } while (0) … … 172 174 /* Enable mouse data reporting. */ 173 175 uint8_t report = PS2_MOUSE_ENABLE_DATA_REPORT; 174 ssize_t size = chardev_write(mouse->chardev, &report, 1); 175 if (size != 1) { 176 size_t nwr; 177 rc = chardev_write(mouse->chardev, &report, 1, &nwr); 178 if (rc != EOK) { 176 179 ddf_msg(LVL_ERROR, "Failed to enable data reporting."); 177 180 rc = EIO; … … 179 182 } 180 183 181 size = chardev_read(mouse->chardev, &report, 1); 182 if (size != 1 || report != PS2_MOUSE_ACK) { 184 size_t nread; 185 rc = chardev_read(mouse->chardev, &report, 1, &nread); 186 if (rc != EOK || report != PS2_MOUSE_ACK) { 183 187 ddf_msg(LVL_ERROR, "Failed to confirm data reporting: %hhx.", 184 188 report); … … 215 219 { 216 220 ps2_mouse_t *mouse = (ps2_mouse_t *) arg; 221 size_t nread; 222 int rc; 217 223 218 224 bool buttons[PS2_BUTTON_COUNT] = {}; 219 225 while (1) { 220 226 uint8_t packet[PS2_BUFSIZE] = {}; 221 const ssize_t size = 222 chardev_read(mouse->chardev, packet, PS2_BUFSIZE); 223 224 if (size != PS2_BUFSIZE) { 225 ddf_msg(LVL_WARN, "Incorrect packet size: %zd.", size); 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); 226 230 continue; 227 231 } 232 228 233 ddf_msg(LVL_DEBUG2, "Got packet: %hhx:%hhx:%hhx.", 229 234 packet[0], packet[1], packet[2]); … … 269 274 { 270 275 ps2_mouse_t *mouse = (ps2_mouse_t *) arg; 276 size_t nread; 277 int rc; 271 278 272 279 bool buttons[INTELLIMOUSE_BUTTON_COUNT] = {}; 273 280 while (1) { 274 281 uint8_t packet[INTELLIMOUSE_BUFSIZE] = {}; 275 const ssize_t size = chardev_read( 276 mouse->chardev, packet, INTELLIMOUSE_BUFSIZE); 277 278 if (size != INTELLIMOUSE_BUFSIZE) { 279 ddf_msg(LVL_WARN, "Incorrect packet size: %zd.", size); 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); 280 286 continue; 281 287 } -
uspace/drv/hid/xtkbd/xtkbd.c
r75fcf9b r5d50c419 208 208 { 209 209 xt_kbd_t *kbd = arg; 210 size_t nread; 211 int rc; 210 212 211 213 while (true) { … … 214 216 215 217 uint8_t code = 0; 216 ssize_t size = chardev_read(kbd->chardev, &code, 1);217 if ( size != 1)218 rc = chardev_read(kbd->chardev, &code, 1, &nread); 219 if (rc != EOK) 218 220 return EIO; 219 221 … … 227 229 map_size = sizeof(scanmap_e0) / sizeof(unsigned int); 228 230 229 size = chardev_read(kbd->chardev, &code, 1);230 if ( size != 1)231 rc = chardev_read(kbd->chardev, &code, 1, &nread); 232 if (rc != EOK) 231 233 return EIO; 232 234 … … 234 236 235 237 if (code == 0x2a) { /* Print Screen */ 236 size = chardev_read(kbd->chardev, &code, 1);237 if ( size != 1)238 rc = chardev_read(kbd->chardev, &code, 1, &nread); 239 if (rc != EOK) 238 240 return EIO; 239 241 … … 241 243 continue; 242 244 243 size = chardev_read(kbd->chardev, &code, 1);244 if ( size != 1)245 rc = chardev_read(kbd->chardev, &code, 1, &nread); 246 if (rc != EOK) 245 247 return EIO; 246 248 … … 252 254 253 255 if (code == 0x46) { /* Break */ 254 size = chardev_read(kbd->chardev, &code, 1);255 if ( size != 1)256 rc = chardev_read(kbd->chardev, &code, 1, &nread); 257 if (rc != EOK) 256 258 return EIO; 257 259 … … 259 261 continue; 260 262 261 size = chardev_read(kbd->chardev, &code, 1);262 if ( size != 1)263 rc = chardev_read(kbd->chardev, &code, 1, &nread); 264 if (rc != EOK) 263 265 return EIO; 264 266 … … 272 274 /* Extended special set */ 273 275 if (code == KBD_SCANCODE_SET_EXTENDED_SPECIAL) { 274 size = chardev_read(kbd->chardev, &code, 1);275 if ( size != 1)276 rc = chardev_read(kbd->chardev, &code, 1, &nread); 277 if (rc != EOK) 276 278 return EIO; 277 279 … … 279 281 continue; 280 282 281 size = chardev_read(kbd->chardev, &code, 1);282 if ( size != 1)283 rc = chardev_read(kbd->chardev, &code, 1, &nread); 284 if (rc != EOK) 283 285 return EIO; 284 286 … … 286 288 continue; 287 289 288 size = chardev_read(kbd->chardev, &code, 1);289 if ( size != 1)290 rc = chardev_read(kbd->chardev, &code, 1, &nread); 291 if (rc != EOK) 290 292 return EIO; 291 293 … … 293 295 continue; 294 296 295 size = chardev_read(kbd->chardev, &code, 1);296 if ( size != 1)297 rc = chardev_read(kbd->chardev, &code, 1, &nread); 298 if (rc != EOK) 297 299 return EIO; 298 300 … … 300 302 continue; 301 303 302 size = chardev_read(kbd->chardev, &code, 1);303 if ( size != 1)304 rc = chardev_read(kbd->chardev, &code, 1, &nread); 305 if (rc != EOK) 304 306 return EIO; 305 307 … … 350 352 uint8_t cmds[] = { KBD_CMD_SET_LEDS, status }; 351 353 352 ssize_t size = chardev_write(kbd->chardev, cmds, sizeof(cmds)); 353 354 async_answer_0(icallid, size < 0 ? size : EOK); 354 size_t nwr; 355 int rc = chardev_write(kbd->chardev, cmds, sizeof(cmds), &nwr); 356 if (nwr != sizeof(cmds)) 357 rc = EIO; 358 359 async_answer_0(icallid, rc); 355 360 break; 356 361 } -
uspace/lib/c/generic/io/chardev.c
r75fcf9b r5d50c419 40 40 #include <io/chardev.h> 41 41 #include <ipc/chardev.h> 42 #include <stddef.h> 42 43 #include <stdlib.h> 43 44 … … 76 77 } 77 78 78 ssize_t chardev_read(chardev_t *chardev, void *data, size_t size)79 int chardev_read(chardev_t *chardev, void *data, size_t size, size_t *nread) 79 80 { 80 81 if (size > 4 * sizeof(sysarg_t)) … … 88 89 if (ret > 0 && (size_t)ret <= size) 89 90 memcpy(data, message, size); 90 return ret; 91 92 if (ret < 0) { 93 *nread = 0; 94 return ret; 95 } 96 97 *nread = ret; 98 return EOK; 91 99 } 92 100 93 ssize_t chardev_write(chardev_t *chardev, const void *data, size_t size) 101 int chardev_write(chardev_t *chardev, const void *data, size_t size, 102 size_t *nwritten) 94 103 { 95 104 int ret; … … 104 113 message[0], message[1], message[2]); 105 114 async_exchange_end(exch); 106 return ret; 115 116 if (ret < 0) { 117 *nwritten = 0; 118 return ret; 119 } 120 121 *nwritten = ret; 122 return EOK; 107 123 } 108 124 -
uspace/lib/c/include/io/chardev.h
r75fcf9b r5d50c419 35 35 36 36 #include <async.h> 37 #include < types/common.h>37 #include <stddef.h> 38 38 39 39 typedef struct { … … 43 43 extern int chardev_open(async_sess_t *, chardev_t **); 44 44 extern void chardev_close(chardev_t *); 45 extern ssize_t chardev_read(chardev_t *, void *, size_t);46 extern ssize_t chardev_write(chardev_t *, const void *, size_t);45 extern int chardev_read(chardev_t *, void *, size_t, size_t *); 46 extern int chardev_write(chardev_t *, const void *, size_t, size_t *); 47 47 48 48 #endif
Note:
See TracChangeset
for help on using the changeset viewer.