From ac1f65e8f8a10bd41d8c46b8427d676bd3385551 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 24 Jul 2010 09:03:11 +0000 Subject: [PATCH] UART driver model, no implementations yet. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2087 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/hal.dox | 85 ++++++++++ os/hal/include/uart.h | 126 +++++++++++++++ os/hal/src/hal.c | 3 + os/hal/src/uart.c | 299 ++++++++++++++++++++++++++++++++++++ os/hal/templates/halconf.h | 11 ++ os/hal/templates/uart_lld.c | 130 ++++++++++++++++ os/hal/templates/uart_lld.h | 116 ++++++++++++++ readme.txt | 2 + todo.txt | 12 +- 9 files changed, 778 insertions(+), 6 deletions(-) create mode 100644 os/hal/include/uart.h create mode 100644 os/hal/src/uart.c create mode 100644 os/hal/templates/uart_lld.c create mode 100644 os/hal/templates/uart_lld.h diff --git a/os/hal/hal.dox b/os/hal/hal.dox index 733e71758..2d8a54dc9 100644 --- a/os/hal/hal.dox +++ b/os/hal/hal.dox @@ -406,3 +406,88 @@ */ +/** + * @defgroup UART UART Driver + * @brief Generic UART Driver. + * @details This module implements a generic UART driver. The driver implements + * a state machine internally: + * @dot + digraph example { + rankdir="LR"; + node [shape=circle, fontname=Helvetica, fontsize=8, fixedsize="true", width="0.8", height="0.8"]; + edge [fontname=Helvetica, fontsize=8]; + + subgraph cluster_RECEIVER { + rx_idle [label="RX_IDLE", style="bold"]; + rx_active [label="RX_ACTIVE"]; + rx_complete [label="RX_COMPLETE"]; + rx_fatal [label="Fatal Error", style="bold"]; + + rx_idle -> rx_idle [label="\nuartStopReceive()\n>uc_rxchar<\n>uc_rxerr<"]; + rx_idle -> rx_active [label="\nuartStartReceive()"]; + + rx_active -> rx_complete [label="\nbuffer filled\n>uc_rxend<"]; + rx_active -> rx_idle [label="\nuartStopReceive()"]; + rx_active -> rx_active [label="\nreceive error\n>uc_rxerr<"]; + rx_active -> rx_fatal [label="\nuartStartReceive()"]; + rx_complete -> rx_active [label="\nuartStartReceiveI()\nthen\ncallback return"]; + rx_complete -> rx_idle [label="\ncallback return"]; + + color = blue; + label = "Receiver state machine (within driver state UART_READY)"; + } + + subgraph cluster_TRANSMITTER { + tx_idle [label="TX_IDLE", style="bold"]; + tx_active [label="TX_ACTIVE"]; + tx_complete [label="TX_COMPLETE"]; + tx_fatal [label="Fatal Error", style="bold"]; + + tx_idle -> tx_active [label="\nuartStartSend()"]; + tx_idle -> tx_idle [label="\nuartStopSend()\n>uc_txend2<"]; + tx_active -> tx_complete [label="\nbuffer transmitted\n>uc_txend1<"]; + tx_active -> tx_idle [label="\nuartStopSend()"]; + tx_active -> tx_fatal [label="\nuartStartSend()"]; + tx_complete -> tx_active [label="\nuartStartSendI()\nthen\ncallback return"]; + tx_complete -> tx_idle [label="\ncallback return"]; + + color = blue; + label = "Transmitter state machine (within driver state UART_READY)"; + } + + subgraph cluster_DRIVER { + uninit [label="UART_UNINIT", style="bold"]; + stop [label="UART_STOP\nLow Power"]; + ready [label="UART_READY\nClock Enabled"]; + + uninit -> stop [label="\nuartInit()"]; + stop -> ready [label="\nuartStart()"]; + ready -> ready [label="\nuartStart()"]; + ready -> stop [label="\nuartStop()"]; + stop -> stop [label="\nuartStop()"]; + + color = blue; + label = "Driver state machine"; + } + } + * @enddot + * The UART driver is meant for those application where unbuffered access to + * the physical device is required. The driver is totally asynchronous and + * invokes callbacks on relevant driver state transitions. If your application + * requires a buffered driver then the @ref SERIAL should be used instead.
+ * This driver model is best used where communication events are meant to + * drive an higher level state machine, as example: + * - RS485 drivers. + * - Multipoint network drivers. + * - Protocol decoders. + * . + * + * @ingroup IO + */ + +/** + * @defgroup UART_LLD UART Low Level Driver + * @brief @ref UART low level driver template. + * + * @ingroup UART + */ diff --git a/os/hal/include/uart.h b/os/hal/include/uart.h new file mode 100644 index 000000000..72273b2a7 --- /dev/null +++ b/os/hal/include/uart.h @@ -0,0 +1,126 @@ +/* + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file uart.h + * @brief UART Driver macros and structures. + * + * @addtogroup UART + * @{ + */ + +#ifndef _UART_H_ +#define _UART_H_ + +#if CH_HAL_USE_UART || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Driver constants. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver pre-compile time settings. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Derived constants and error checks. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver data structures and types. */ +/*===========================================================================*/ + +/** + * @brief Generic UART notification callback type. + */ +typedef void (*uartcb_t)(void); + +/** + * @brief Character received UART notification callback type. + * + * @param[in] c received character + */ +typedef void (*uartccb_t)(uint16_t c); + +/** + * @brief Receive error UART notification callback type. + * + * @param[in] e receive error mask + */ +typedef void (*uartecb_t)(uint16_t e); + +/** + * @brief Driver state machine possible states. + */ +typedef enum { + UART_UNINIT = 0, /**< @brief Not initialized. */ + UART_STOP = 1, /**< @brief Stopped. */ + UART_READY = 2 /**< @brief Ready. */ +} uartstate_t; + +/** + * @brief Transmitter state machine states. + */ +typedef enum { + UART_TX_IDLE = 0, /**< @brief Not transmitting. */ + UART_TX_ACTIVE = 1, /**< @brief Transmitting. */ + UART_TX_COMPLETE = 2 /**< @brief Buffer complete. */ +} uarttxstate_t; + +/** + * @brief Receiver state machine states. + */ +typedef enum { + UART_RX_IDLE = 0, /**< @brief Not receiving. */ + UART_RX_ACTIVE = 1, /**< @brief Receiving. */ + UART_TX_ERROR = 2, /**< @brief Receive error. */ + UART_TX_COMPLETE = 3 /**< @brief Buffer complete. */ +} uartrxstate_t; + +#include "uart_lld.h" + +/*===========================================================================*/ +/* Driver macros. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* External declarations. */ +/*===========================================================================*/ + +#ifdef __cplusplus +extern "C" { +#endif + void uartInit(void); + void uartObjectInit(UARTDriver *uartp); + void uartStart(UARTDriver *uartp, const UARTConfig *config); + void uartStop(UARTDriver *uartp); + void uartStartSend(UARTDriver *uartp, size_t n, const void *txbuf); + void uartStartSendI(UARTDriver *uartp, size_t n, const void *txbuf); + void uartStopSend(UARTDriver *uartp); + void uartStartReceive(UARTDriver *uartp, size_t n, void *rxbuf); + void uartStopReceive(UARTDriver *uartp); +#ifdef __cplusplus +} +#endif + +#endif /* CH_HAL_USE_UART */ + +#endif /* _UART_H_ */ + +/** @} */ diff --git a/os/hal/src/hal.c b/os/hal/src/hal.c index d7e963f74..d2b2fc528 100644 --- a/os/hal/src/hal.c +++ b/os/hal/src/hal.c @@ -75,6 +75,9 @@ void halInit(void) { #if CH_HAL_USE_MMC_SPI mmcInit(); #endif +#if CH_HAL_USE_UART + uartInit(); +#endif } /** @} */ diff --git a/os/hal/src/uart.c b/os/hal/src/uart.c new file mode 100644 index 000000000..281d6ad78 --- /dev/null +++ b/os/hal/src/uart.c @@ -0,0 +1,299 @@ +/* + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file uart.c + * @brief UART Driver code. + * + * @addtogroup UART + * @{ + */ + +#include "ch.h" +#include "hal.h" + +#if CH_HAL_USE_UART || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + +/** + * @brief UART Driver initialization. + */ +void uartInit(void) { + + uart_lld_init(); +} + +/** + * @brief Initializes the standard part of a @p UARTDriver structure. + * + * @param[in] uartp pointer to the @p UARTDriver object + */ +void uartObjectInit(UARTDriver *uartp) { + + uartp->ud_state = UART_STOP; + uartp->ud_txstate = UART_TX_IDLE; + uartp->ud_rxstate = UART_RX_IDLE; + uartp->ud_config = NULL; +} + +/** + * @brief Configures and activates the UART peripheral. + * + * @param[in] uartp pointer to the @p UARTDriver object + * @param[in] config pointer to the @p UARTConfig object + */ +void uartStart(UARTDriver *uartp, const UARTConfig *config) { + + chDbgCheck((uartp != NULL) && (config != NULL), "uartStart"); + + chSysLock(); + chDbgAssert((uartp->ud_state == UART_STOP) || + (uartp->ud_state == UART_READY), + "uartStart(), #1", + "invalid state"); + + uartp->ud_config = config; + uart_lld_start(uartp); + uartp->ud_state = UART_READY; + chSysUnlock(); +} + +/** + * @brief Deactivates the UART peripheral. + * + * @param[in] uartp pointer to the @p UARTDriver object + */ +void uartStop(UARTDriver *uartp) { + + chDbgCheck(uartp != NULL, "uartStop"); + + chSysLock(); + chDbgAssert((uartp->ud_state == UART_STOP) || + (uartp->ud_state == UART_READY), + "uartStop(), #1", + "invalid state"); + + uart_lld_stop(uartp); + uartp->ud_state = UART_STOP; + uartp->ud_txstate = UART_TX_IDLE; + uartp->ud_rxstate = UART_RX_IDLE; + chSysUnlock(); +} + +/** + * @brief Starts a transmission on the UART peripheral. + * @note The buffers are organized as uint8_t arrays for data sizes below + * or equal to 8 bits else it is organized as uint16_t arrays. + * + * @param[in] uartp pointer to the @p UARTDriver object + * @param[in] n number of data frames to send + * @param[in] txbuf the pointer to the transmit buffer + */ +void uartStartSend(UARTDriver *uartp, size_t n, const void *txbuf) { + + chDbgCheck((uartp != NULL) && (n > 0) && (txbuf != NULL), + "uartStartSend"); + + chSysLock(); + chDbgAssert((uartp->ud_state == UART_READY) && + (uartp->ud_txstate == UART_TX_IDLE), + "uartStartSend(), #1", + "not active"); + + uart_lld_start_send(uartp, n, txbuf); + uartp->ud_txstate = UART_TX_ACTIVE; + chSysUnlock(); +} + +/** + * @brief Starts a transmission on the UART peripheral. + * @note The buffers are organized as uint8_t arrays for data sizes below + * or equal to 8 bits else it is organized as uint16_t arrays. + * @note This function has to be invoked from a lock zone. + * + * @param[in] uartp pointer to the @p UARTDriver object + * @param[in] n number of data frames to send + * @param[in] txbuf the pointer to the transmit buffer + */ +void uartStartSendI(UARTDriver *uartp, size_t n, const void *txbuf) { + + chDbgCheck((uartp != NULL) && (n > 0) && (txbuf != NULL), + "uartStartSendI"); + + chDbgAssert((uartp->ud_state == UART_READY) && + (uartp->ud_txstate != UART_TX_ACTIVE), + "uartStartSendI(), #1", + "not active"); + uart_lld_start_send(uartp, n, txbuf); + uartp->ud_txstate = UART_TX_ACTIVE; +} + +/** + * @brief Stops any ongoing transmission. + * @note Stopping a transmission also suppresses the transmission callbacks. + * + * @param[in] uartp pointer to the @p UARTDriver object + */ +void uartStopSend(UARTDriver *uartp) { + + chDbgCheck(uartp != NULL, "uartStopSend"); + + chSysLock() + chDbgAssert(uartp->ud_state == UART_READY, + "uartStopSend(), #1", + "not active"); + + if (uartp->ud_txstate == UART_TX_ACTIVE) { + uart_lld_stop_send(uartp); + uartp->ud_txstate = UART_TX_IDLE; + } + chSysUnlock(); +} + +/** + * @brief Stops any ongoing transmission. + * @note Stopping a transmission also suppresses the transmission callbacks. + * @note This function has to be invoked from a lock zone. + * + * @param[in] uartp pointer to the @p UARTDriver object + */ +void uartStopSendI(UARTDriver *uartp) { + + chDbgCheck(uartp != NULL, "uartStopSendI"); + + chDbgAssert(uartp->ud_state == UART_READY, + "uartStopSendI(), #1", + "not active"); + + if (uartp->ud_txstate == UART_TX_ACTIVE) { + uart_lld_stop_send(uartp); + uartp->ud_txstate = UART_TX_IDLE; + } +} + +/** + * @brief Starts a receive operation on the UART peripheral. + * @note The buffers are organized as uint8_t arrays for data sizes below + * or equal to 8 bits else it is organized as uint16_t arrays. + * + * @param[in] uartp pointer to the @p UARTDriver object + * @param[in] n number of data frames to send + * @param[in] rxbuf the pointer to the receive buffer + */ +void uartStartReceive(UARTDriver *uartp, size_t n, void *rxbuf) { + + chDbgCheck((uartp != NULL) && (n > 0) && (rxbuf != NULL), + "uartStartReceive"); + + chSysLock(); + chDbgAssert((uartp->ud_state == UART_READY) && + (uartp->ud_rxstate == UART_RX_IDLE), + "uartStartReceive(), #1", + "not active"); + + uart_lld_start_receive(uartp, n, txbuf); + uartp->ud_rxstate = UART_RX_ACTIVE; + chSysUnlock(); +} + +/** + * @brief Starts a receive operation on the UART peripheral. + * @note The buffers are organized as uint8_t arrays for data sizes below + * or equal to 8 bits else it is organized as uint16_t arrays. + * @note This function has to be invoked from a lock zone. + * + * @param[in] uartp pointer to the @p UARTDriver object + * @param[in] n number of data frames to send + * @param[in] rxbuf the pointer to the receive buffer + */ +void uartStartReceiveI(UARTDriver *uartp, size_t n, void *rxbuf) { + + chDbgCheck((uartp != NULL) && (n > 0) && (rxbuf != NULL), + "uartStartReceiveI"); + + chDbgAssert((uartp->ud_state == UART_READY) && + (uartp->ud_rxstate == UART_RX_IDLE), + "uartStartReceiveI(), #1", + "not active"); + + uart_lld_start_receive(uartp, n, txbuf); + uartp->ud_rxstate = UART_RX_ACTIVE; +} + +/** + * @brief Stops any ongoing receive operation. + * @note Stopping a receive operation also suppresses the receive callbacks. + * + * @param[in] uartp pointer to the @p UARTDriver object + */ +void uartStopReceive(UARTDriver *uartp) { + + chDbgCheck(uartp != NULL, "uartStopReceive"); + + chSysLock() + chDbgAssert(uartp->ud_state == UART_READY, + "uartStopReceive(), #1", + "not active"); + + if (uartp->ud_rxstate == UART_RX_ACTIVE) { + uart_lld_stop_receive(uartp); + uartp->ud_rxstate = UART_RX_IDLE; + } + chSysUnlock(); +} + +/** + * @brief Stops any ongoing receive operation. + * @note Stopping a receive operation also suppresses the receive callbacks. + * @note This function has to be invoked from a lock zone. + * + * @param[in] uartp pointer to the @p UARTDriver object + */ +void uartStopReceiveI(UARTDriver *uartp) { + + chDbgCheck(uartp != NULL, "uartStopReceiveI"); + + chDbgAssert(uartp->ud_state == UART_READY, + "uartStopReceiveI(), #1", + "not active"); + + if (uartp->ud_rxstate == UART_RX_ACTIVE) { + uart_lld_stop_receive(uartp); + uartp->ud_rxstate = UART_RX_IDLE; + } +} + +#endif /* CH_HAL_USE_UART */ + +/** @} */ diff --git a/os/hal/templates/halconf.h b/os/hal/templates/halconf.h index f58ca677b..719a3cf2f 100644 --- a/os/hal/templates/halconf.h +++ b/os/hal/templates/halconf.h @@ -154,6 +154,17 @@ /*#define MMC_POLLING_INTERVAL 10*/ /*#define MMC_POLLING_DELAY 10*/ +/*===========================================================================*/ +/* UART driver related settings. */ +/*===========================================================================*/ + +/** + * @brief Enables the UART subsystem. + */ +#if !defined(CH_HAL_USE_UART) || defined(__DOXYGEN__) +#define CH_HAL_USE_UART TRUE +#endif + #endif /* _HALCONF_H_ */ /** @} */ diff --git a/os/hal/templates/uart_lld.c b/os/hal/templates/uart_lld.c new file mode 100644 index 000000000..46c04fe8c --- /dev/null +++ b/os/hal/templates/uart_lld.c @@ -0,0 +1,130 @@ +/* + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file templates/uart_lld.c + * @brief UART Driver subsystem low level driver source template. + * + * @addtogroup UART_LLD + * @{ + */ + +#include "ch.h" +#include "hal.h" + +#if CH_HAL_USE_UART || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver interrupt handlers. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + +/** + * @brief Low level UART driver initialization. + */ +void uart_lld_init(void) { + +} + +/** + * @brief Configures and activates the UART peripheral. + * + * @param[in] uartp pointer to the @p UARTDriver object + */ +void uart_lld_start(UARTDriver *uartp) { + + if (uartp->uart_state == UART_STOP) { + /* Clock activation.*/ + } + /* Configuration.*/ +} + +/** + * @brief Deactivates the UART peripheral. + * + * @param[in] uartp pointer to the @p UARTDriver object + */ +void uart_lld_stop(UARTDriver *uartp) { + +} + +/** + * @brief Starts a transmission on the UART peripheral. + * @note The buffers are organized as uint8_t arrays for data sizes below + * or equal to 8 bits else it is organized as uint16_t arrays. + * + * @param[in] uartp pointer to the @p UARTDriver object + * @param[in] n number of data frames to send + * @param[in] txbuf the pointer to the transmit buffer + */ +void uart_lld_start_send(UARTDriver *uartp, size_t n, const void *txbuf) { + +} + +/** + * @brief Stops any ongoing transmission. + * @note Stopping a transmission also suppresses the transmission callbacks. + * + * @param[in] uartp pointer to the @p UARTDriver object + */ +void uart_lld_stop_send(UARTDriver *uartp) { + +} + +/** + * @brief Starts a receive operation on the UART peripheral. + * @note The buffers are organized as uint8_t arrays for data sizes below + * or equal to 8 bits else it is organized as uint16_t arrays. + * + * @param[in] uartp pointer to the @p UARTDriver object + * @param[in] n number of data frames to send + * @param[in] rxbuf the pointer to the receive buffer + */ +void uart_lld_start_receive(UARTDriver *uartp, size_t n, void *rxbuf) { + +} + +/** + * @brief Stops any ongoing receive operation. + * @note Stopping a receive operation also suppresses the receive callbacks. + * + * @param[in] uartp pointer to the @p UARTDriver object + */ +void uart_lld_stop_receive(UARTDriver *uartp) { + +} + +#endif /* CH_HAL_USE_UART */ + +/** @} */ diff --git a/os/hal/templates/uart_lld.h b/os/hal/templates/uart_lld.h new file mode 100644 index 000000000..adc824bd0 --- /dev/null +++ b/os/hal/templates/uart_lld.h @@ -0,0 +1,116 @@ +/* + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file templates/uart_lld.h + * @brief UART Driver subsystem low level driver header template. + * + * @addtogroup UART_LLD + * @{ + */ + +#ifndef _UART_LLD_H_ +#define _UART_LLD_H_ + +#if CH_HAL_USE_UART || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Driver constants. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver pre-compile time settings. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Derived constants and error checks. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver data structures and types. */ +/*===========================================================================*/ + +/** + * @brief Driver configuration structure. + * @note It could be empty on some architectures. + */ +typedef struct { + /** @brief End of transmission buffer callback.*/ + uartcb_t uc_txend1; + /** @brief Physical end of transmission callback.*/ + uartcb_t uc_txend2; + /** @brief Receive buffer filled callback.*/ + uartcb_t uc_rxend; + /** @brief Character received while out if the @p UART_RECEIVE state.*/ + uartcb_t uc_rxchar; + /** @brief Receive error callback.*/ + uartcb_t uc_rxerr; + /* End of the mandatory fields.*/ +} UARTConfig; + +/** + * @brief Structure representing an UART driver. + */ +typedef struct { + /** + * @brief Driver state. + */ + uartstate_t ud_state; + /** + * @brief Transmitter state. + */ + uarttxstate_t ud_txstate; + /** + * @brief Receiver state. + */ + uartrxstate_t ud_rxstate; + /** + * @brief Current configuration data. + */ + const UARTConfig *ud_config; + /* End of the mandatory fields.*/ +} UARTDriver; + +/*===========================================================================*/ +/* Driver macros. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* External declarations. */ +/*===========================================================================*/ + +#ifdef __cplusplus +extern "C" { +#endif + void uart_lld_init(void); + void uart_lld_start(UARTDriver *uartp); + void uart_lld_stop(UARTDriver *uartp); + void uart_lld_start_send(UARTDriver *uartp, size_t n, const void *txbuf); + void uart_lld_stop_send(UARTDriver *uartp); + void uart_lld_start_receive(UARTDriver *uartp, size_t n, void *rxbuf); + void uart_lld_stop_receive(UARTDriver *uartp); +#ifdef __cplusplus +} +#endif + +#endif /* CH_HAL_USE_UART */ + +#endif /* _UART_LLD_H_ */ + +/** @} */ diff --git a/readme.txt b/readme.txt index ac5039db5..375a8d826 100644 --- a/readme.txt +++ b/readme.txt @@ -76,6 +76,8 @@ 3025549)(backported to 2.0.2). - FIX: Added option to enforce the stack alignment to 32 or 64 bits in the Cortex-Mx port (bug 3025133)(backported to 2.0.2). +- NEW: New UART device driver model, this device driver allows unbuffered, + callback driven access to UART-type devices. - NEW: Added friendly interrupt vectors names to the STM32 HAL (change request 3023944). - NEW: Added support for SPI3 in the STM32 HAL. diff --git a/todo.txt b/todo.txt index 7d9b26b31..767e705cb 100644 --- a/todo.txt +++ b/todo.txt @@ -6,6 +6,12 @@ X = In progress, some work done. Within 2.1.x (hopefully) * Binary Semaphores on top of Counting Semaphores. +X Direct unbuffered UART driver (evaluate rebuilding the current serial driver + as a generic driver on top of the low level UART driver). + Requirements: low level, callbacks, DMA capable, state machines buildable + on top, support data words greater than 8 bits, callback for + "last byte transmitted (RS485)", simple implementation, + verifiable. X Resist doing more changes and optimizations in the kernel, fixes only. - Merge the Coldfire branch in mainline. - Merge the H8S branch in mainline. @@ -13,12 +19,6 @@ X Resist doing more changes and optimizations in the kernel, fixes only. - Add a *very simple* ADC API for simgle one shot sampling (implement it as an injected conversion on the STM32). - MAC driver for STM32F105/STM32F107 (hardware missing). -- Direct unbuffered UART driver (evaluate rebuilding the current serial driver - as a generic driver on top of the low level UART driver). - Requirements: low level, callbacks, DMA capable, state machines buildable - on top, support data words greater than 8 bits, callback for - "last byte transmitted (RS485)", simple implementation, - verifiable. - Device drivers for STM8 (SPI, ADC, PWM, bring it on par with STM32). - Support for more compilers (ARMCMx only initially). - Support for not just Makefiles (Ride7, Crossworks, Eclipse CDT etc).