MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / xs_serial_write

Function xs_serial_write

modules/io/serial/pico/serial.c:318–349  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

316}
317
318void 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
351void xs_serial_purge(xsMachine *the)
352{

Callers

nothing calls this directly

Calls 3

fifo_lengthFunction · 0.85
fifo_putFunction · 0.85
uart_irqFunction · 0.85

Tested by

no test coverage detected