| 316 | } |
| 317 | |
| 318 | void xs_serial_write(xsMachine *the) |
| 319 | { |
| 320 | Serial serial = xsmcGetHostDataValidate(xsThis, (void *)&xsSerialHooks); |
| 321 | int count = FIFO_SIZE - fifo_length(&serial->tx_fifo); |
| 322 | |
| 323 | if (kIOFormatNumber == serial->format) { |
| 324 | uint8_t byte; |
| 325 | |
| 326 | if (0 == count) |
| 327 | xsUnknownError("output full"); |
| 328 | |
| 329 | byte = (uint8_t)xsmcToInteger(xsArg(0)); |
| 330 | if (0 != fifo_put(&serial->tx_fifo, byte)) |
| 331 | xsUnknownError("tx full"); |
| 332 | } |
| 333 | else { |
| 334 | uint8_t *buffer; |
| 335 | xsUnsignedValue requested; |
| 336 | |
| 337 | xsmcGetBufferReadable(xsArg(0), (void**)&buffer, &requested); |
| 338 | if (requested > count) |
| 339 | xsUnknownError("output full"); |
| 340 | |
| 341 | while (requested--) { |
| 342 | if (0 != fifo_put(&serial->tx_fifo, *buffer++)) |
| 343 | xsUnknownError("tx full2"); |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | serial->txInterruptEnabled = (NULL != serial->onWritable); |
| 348 | uart_irq(); |
| 349 | } |
| 350 | |
| 351 | void xs_serial_purge(xsMachine *the) |
| 352 | { |
nothing calls this directly
no test coverage detected