From 523f6f4bb2735b2a48f137a95344df9476e65a16 Mon Sep 17 00:00:00 2001 From: Felix Kopp Date: Sun, 29 Nov 2020 20:38:16 +0100 Subject: [PATCH] serial: forgot to commit some shit --- include/arch/at91sam3x8e/serial.h | 38 +++++++++++++++++++++++++++++++ include/arch/serial.h | 8 +++++++ include/ardix/serial.h | 2 +- 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/include/arch/at91sam3x8e/serial.h b/include/arch/at91sam3x8e/serial.h index 325be71..e253258 100644 --- a/include/arch/at91sam3x8e/serial.h +++ b/include/arch/at91sam3x8e/serial.h @@ -4,6 +4,44 @@ #pragma once #include +#include +#include + +#include + +#ifndef CONFIG_ARCH_SERIAL_BUFSZ +#define CONFIG_ARCH_SERIAL_BUFSZ 32 +#endif /* CONFIG_ARCH_SERIAL_BUFSZ */ + +/** Architecture-specific extension of `struct serial_interface` */ +struct arch_serial_interface { + struct serial_interface interface; + + /* + * two hardware buffers; one is for being written to while the other one can be read from + * by the hardware w/out interfering with each other. `arch_serial_hwbuf_rotate()` is + * responsible for writing this to the respective hardware register and swapping them out. + * The platform's buffer length registers only allow 16-byte numbers, so we can save some + * memory by not using `size_t` + */ + uint16_t current_len; /* buffer length registers are only 16 bytes */ + uint8_t tx1[CONFIG_ARCH_SERIAL_BUFSZ]; + uint8_t tx2[CONFIG_ARCH_SERIAL_BUFSZ]; + /** hardware has finished sending the current buffer and ready for a swap */ + bool hw_txrdy; + /** which hardware buffer is currently being written to (use `ARCH_SERIAL_BUF*`) */ + bool current_txbuf; +}; +#define ARCH_SERIAL_BUF1 false +#define ARCH_SERIAL_BUF2 true + +/** + * Cast a `struct serial_interface` out to a `struct arch_serial_interface`. + * + * @param ptr: The `struct serial_interface *` to cast out from. + * @returns The containing `struct arch_serial_interface *`. + */ +#define to_arch_serial_interface(ptr) container_of(ptr, struct arch_serial_interface, interface) /* * Copyright (c) 2020 Felix Kopp diff --git a/include/arch/serial.h b/include/arch/serial.h index 91b1ccd..1ac0d4a 100644 --- a/include/arch/serial.h +++ b/include/arch/serial.h @@ -17,6 +17,14 @@ void arch_serial_exit(struct serial_interface *interface); */ void arch_serial_notify(struct serial_interface *interface); +/** + * Copy the current TX ring buffer content to a new hardware buffer. + * + * @param interface: The serial interface to rotate the hardware buffer of. + * @returns 0 on success, or a negative number on failure. + */ +int arch_serial_txbuf_rotate(struct serial_interface *interface); + #ifdef ARCH_AT91SAM3X8E #include #else diff --git a/include/ardix/serial.h b/include/ardix/serial.h index 896e0be..1ad184e 100644 --- a/include/ardix/serial.h +++ b/include/ardix/serial.h @@ -9,7 +9,7 @@ #ifndef SERIAL_BUFSZ /** size of a serial I/O buffer in bytes */ -#define SERIAL_BUFSZ 64 +#define SERIAL_BUFSZ 256 #endif struct serial_interface {