+/**
+ * Get the XON/XOFF configuration from a port configuration.
+ *
+ * The user should allocate a variable of type enum sp_xonxoff and
+ * pass a pointer to this to receive the result.
+ *
+ * @param[in] config Pointer to a configuration structure. Must not be NULL.
+ * @param[out] xon_xoff_ptr Pointer to a variable to store the result. Must not be NULL.
+ *
+ * @return SP_OK upon success, a negative error code otherwise.
+ *
+ * @since 0.1.0
+ */
+enum sp_return sp_get_config_xon_xoff(const struct sp_port_config *config, enum sp_xonxoff *xon_xoff_ptr);
+
+/**
+ * Set the XON/XOFF configuration in a port configuration.
+ *
+ * @param[in] config Pointer to a configuration structure. Must not be NULL.
+ * @param[in] xon_xoff XON/XOFF mode, or -1 to retain the current setting.
+ *
+ * @return SP_OK upon success, a negative error code otherwise.
+ *
+ * @since 0.1.0
+ */
+enum sp_return sp_set_config_xon_xoff(struct sp_port_config *config, enum sp_xonxoff xon_xoff);
+
+/**
+ * Set the flow control type in a port configuration.
+ *
+ * This function is a wrapper that sets the RTS, CTS, DTR, DSR and
+ * XON/XOFF settings as necessary for the specified flow control
+ * type. For more fine-grained control of these settings, use their
+ * individual configuration functions.
+ *
+ * @param[in] config Pointer to a configuration structure. Must not be NULL.
+ * @param[in] flowcontrol Flow control setting to use.
+ *
+ * @return SP_OK upon success, a negative error code otherwise.
+ *
+ * @since 0.1.0
+ */
+enum sp_return sp_set_config_flowcontrol(struct sp_port_config *config, enum sp_flowcontrol flowcontrol);
+
+/**
+ * Set the flow control type for the specified serial port.
+ *
+ * This function is a wrapper that sets the RTS, CTS, DTR, DSR and
+ * XON/XOFF settings as necessary for the specified flow control
+ * type. For more fine-grained control of these settings, use their
+ * individual configuration functions.
+ *
+ * @param[in] port Pointer to a port structure. Must not be NULL.
+ * @param[in] flowcontrol Flow control setting to use.
+ *
+ * @return SP_OK upon success, a negative error code otherwise.
+ *
+ * @since 0.1.0
+ */
+enum sp_return sp_set_flowcontrol(struct sp_port *port, enum sp_flowcontrol flowcontrol);
+
+/**
+ * @}
+ *
+ * @defgroup Data Data handling
+ *
+ * Reading, writing, and flushing data.
+ *
+ * @{
+ */
+
+/**
+ * Read bytes from the specified serial port, blocking until complete.
+ *
+ * @warning If your program runs on Unix, defines its own signal handlers, and
+ * needs to abort blocking reads when these are called, then you
+ * should not use this function. It repeats system calls that return
+ * with EINTR. To be able to abort a read from a signal handler, you
+ * should implement your own blocking read using sp_nonblocking_read()
+ * together with a blocking method that makes sense for your program.
+ * E.g. you can obtain the file descriptor for an open port using
+ * sp_get_port_handle() and use this to call select() or pselect(),
+ * with appropriate arrangements to return if a signal is received.
+ *
+ * @param[in] port Pointer to a port structure. Must not be NULL.
+ * @param[out] buf Buffer in which to store the bytes read. Must not be NULL.
+ * @param[in] count Requested number of bytes to read.
+ * @param[in] timeout_ms Timeout in milliseconds, or zero to wait indefinitely.
+ *
+ * @return The number of bytes read on success, or a negative error code. If
+ * the number of bytes returned is less than that requested, the
+ * timeout was reached before the requested number of bytes was
+ * available. If timeout is zero, the function will always return
+ * either the requested number of bytes or a negative error code.
+ *
+ * @since 0.1.0
+ */
+enum sp_return sp_blocking_read(struct sp_port *port, void *buf, size_t count, unsigned int timeout_ms);
+
+/**
+ * Read bytes from the specified serial port, returning as soon as any data is
+ * available.
+ *
+ * @warning If your program runs on Unix, defines its own signal handlers, and
+ * needs to abort blocking reads when these are called, then you
+ * should not use this function. It repeats system calls that return
+ * with EINTR. To be able to abort a read from a signal handler, you
+ * should implement your own blocking read using sp_nonblocking_read()
+ * together with a blocking method that makes sense for your program.
+ * E.g. you can obtain the file descriptor for an open port using
+ * sp_get_port_handle() and use this to call select() or pselect(),
+ * with appropriate arrangements to return if a signal is received.
+ *
+ * @param[in] port Pointer to a port structure. Must not be NULL.
+ * @param[out] buf Buffer in which to store the bytes read. Must not be NULL.
+ * @param[in] count Maximum number of bytes to read. Must not be zero.
+ * @param[in] timeout_ms Timeout in milliseconds, or zero to wait indefinitely.
+ *
+ * @return The number of bytes read on success, or a negative error code. If
+ * the result is zero, the timeout was reached before any bytes were
+ * available. If timeout_ms is zero, the function will always return
+ * either at least one byte, or a negative error code.
+ *
+ * @since 0.1.1
+ */
+enum sp_return sp_blocking_read_next(struct sp_port *port, void *buf, size_t count, unsigned int timeout_ms);
+
+/**
+ * Read bytes from the specified serial port, without blocking.
+ *
+ * @param[in] port Pointer to a port structure. Must not be NULL.
+ * @param[out] buf Buffer in which to store the bytes read. Must not be NULL.
+ * @param[in] count Maximum number of bytes to read.
+ *
+ * @return The number of bytes read on success, or a negative error code. The
+ * number of bytes returned may be any number from zero to the maximum
+ * that was requested.
+ *
+ * @since 0.1.0
+ */
+enum sp_return sp_nonblocking_read(struct sp_port *port, void *buf, size_t count);
+
+/**
+ * Write bytes to the specified serial port, blocking until complete.
+ *
+ * Note that this function only ensures that the accepted bytes have been
+ * written to the OS; they may be held in driver or hardware buffers and not
+ * yet physically transmitted. To check whether all written bytes have actually
+ * been transmitted, use the sp_output_waiting() function. To wait until all
+ * written bytes have actually been transmitted, use the sp_drain() function.
+ *
+ * @warning If your program runs on Unix, defines its own signal handlers, and
+ * needs to abort blocking writes when these are called, then you
+ * should not use this function. It repeats system calls that return
+ * with EINTR. To be able to abort a write from a signal handler, you
+ * should implement your own blocking write using sp_nonblocking_write()
+ * together with a blocking method that makes sense for your program.
+ * E.g. you can obtain the file descriptor for an open port using
+ * sp_get_port_handle() and use this to call select() or pselect(),
+ * with appropriate arrangements to return if a signal is received.
+ *
+ * @param[in] port Pointer to a port structure. Must not be NULL.
+ * @param[in] buf Buffer containing the bytes to write. Must not be NULL.
+ * @param[in] count Requested number of bytes to write.
+ * @param[in] timeout_ms Timeout in milliseconds, or zero to wait indefinitely.
+ *
+ * @return The number of bytes written on success, or a negative error code.
+ * If the number of bytes returned is less than that requested, the
+ * timeout was reached before the requested number of bytes was
+ * written. If timeout is zero, the function will always return
+ * either the requested number of bytes or a negative error code. In
+ * the event of an error there is no way to determine how many bytes
+ * were sent before the error occurred.
+ *
+ * @since 0.1.0
+ */
+enum sp_return sp_blocking_write(struct sp_port *port, const void *buf, size_t count, unsigned int timeout_ms);
+
+/**
+ * Write bytes to the specified serial port, without blocking.
+ *
+ * Note that this function only ensures that the accepted bytes have been
+ * written to the OS; they may be held in driver or hardware buffers and not
+ * yet physically transmitted. To check whether all written bytes have actually
+ * been transmitted, use the sp_output_waiting() function. To wait until all
+ * written bytes have actually been transmitted, use the sp_drain() function.
+ *
+ * @param[in] port Pointer to a port structure. Must not be NULL.
+ * @param[in] buf Buffer containing the bytes to write. Must not be NULL.
+ * @param[in] count Maximum number of bytes to write.
+ *
+ * @return The number of bytes written on success, or a negative error code.
+ * The number of bytes returned may be any number from zero to the
+ * maximum that was requested.
+ *
+ * @since 0.1.0
+ */
+enum sp_return sp_nonblocking_write(struct sp_port *port, const void *buf, size_t count);
+
+/**
+ * Gets the number of bytes waiting in the input buffer.
+ *
+ * @param[in] port Pointer to a port structure. Must not be NULL.
+ *
+ * @return Number of bytes waiting on success, a negative error code otherwise.
+ *
+ * @since 0.1.0
+ */
+enum sp_return sp_input_waiting(struct sp_port *port);
+
+/**
+ * Gets the number of bytes waiting in the output buffer.
+ *
+ * @param[in] port Pointer to a port structure. Must not be NULL.
+ *
+ * @return Number of bytes waiting on success, a negative error code otherwise.
+ *
+ * @since 0.1.0
+ */
+enum sp_return sp_output_waiting(struct sp_port *port);
+
+/**
+ * Flush serial port buffers. Data in the selected buffer(s) is discarded.
+ *
+ * @param[in] port Pointer to a port structure. Must not be NULL.
+ * @param[in] buffers Which buffer(s) to flush.
+ *
+ * @return SP_OK upon success, a negative error code otherwise.
+ *
+ * @since 0.1.0
+ */
+enum sp_return sp_flush(struct sp_port *port, enum sp_buffer buffers);
+
+/**
+ * Wait for buffered data to be transmitted.
+ *
+ * @warning If your program runs on Unix, defines its own signal handlers, and
+ * needs to abort draining the output buffer when when these are
+ * called, then you should not use this function. It repeats system
+ * calls that return with EINTR. To be able to abort a drain from a
+ * signal handler, you would need to implement your own blocking
+ * drain by polling the result of sp_output_waiting().
+ *
+ * @param[in] port Pointer to a port structure. Must not be NULL.
+ *
+ * @return SP_OK upon success, a negative error code otherwise.
+ *
+ * @since 0.1.0
+ */
+enum sp_return sp_drain(struct sp_port *port);
+
+/**
+ * @}
+ *
+ * @defgroup Waiting Waiting
+ *
+ * Waiting for events and timeout handling.
+ *
+ * @{
+ */
+
+/**
+ * Allocate storage for a set of events.
+ *
+ * The user should allocate a variable of type struct sp_event_set *,
+ * then pass a pointer to this variable to receive the result.
+ *
+ * The result should be freed after use by calling sp_free_event_set().
+ *
+ * @param[out] result_ptr If any error is returned, the variable pointed to by
+ * result_ptr will be set to NULL. Otherwise, it will
+ * be set to point to the event set. Must not be NULL.
+ *
+ * @return SP_OK upon success, a negative error code otherwise.
+ *
+ * @since 0.1.0
+ */
+enum sp_return sp_new_event_set(struct sp_event_set **result_ptr);
+
+/**
+ * Add events to a struct sp_event_set for a given port.
+ *
+ * The port must first be opened by calling sp_open() using the same port
+ * structure.
+ *
+ * After the port is closed or the port structure freed, the results may
+ * no longer be valid.
+ *
+ * @param[in,out] event_set Event set to update. Must not be NULL.
+ * @param[in] port Pointer to a port structure. Must not be NULL.
+ * @param[in] mask Bitmask of events to be waited for.
+ *
+ * @return SP_OK upon success, a negative error code otherwise.
+ *
+ * @since 0.1.0
+ */
+enum sp_return sp_add_port_events(struct sp_event_set *event_set,
+ const struct sp_port *port, enum sp_event mask);
+
+/**
+ * Wait for any of a set of events to occur.
+ *
+ * @param[in] event_set Event set to wait on. Must not be NULL.
+ * @param[in] timeout_ms Timeout in milliseconds, or zero to wait indefinitely.
+ *
+ * @return SP_OK upon success, a negative error code otherwise.
+ *
+ * @since 0.1.0
+ */
+enum sp_return sp_wait(struct sp_event_set *event_set, unsigned int timeout_ms);
+
+/**
+ * Free a structure allocated by sp_new_event_set().
+ *
+ * @param[in] event_set Event set to free. Must not be NULL.
+ *
+ * @since 0.1.0
+ */
+void sp_free_event_set(struct sp_event_set *event_set);
+