vt100/src/serial.h

1/* One direction of an asynchronous serial line: 8 data bits, no parity, 1 stop bit, so a2 * character takes 10 bit times. A byte put on the line arrives when its last bit has. */3#pragma once4#include <stdbool.h>5#include <stdint.h>67#define SERIAL_BUF 3276889typedef struct {10  uint8_t buf[SERIAL_BUF];11  unsigned head, tail; /* head: next to arrive, tail: next free */12  double char_ms;      /* 0 = infinitely fast */13  double busy_until;   /* when the character now on the wire has arrived */14  bool paused;         /* flow control (XOFF): the sender stops after the current character */15} serial_line;1617void serial_init(serial_line *l, int baud);18bool serial_put(serial_line *l, uint8_t b, double now_ms);19/* next byte that has arrived by now_ms, or -1 */20int serial_get(serial_line *l, double now_ms);21bool serial_empty(const serial_line *l);22/* XOFF / XON */23void serial_set_paused(serial_line *l, bool paused, double now_ms);