From e53c5fbf6c8928e416490fa668089541883d40f4 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 28 Sep 2018 09:10:43 +0000 Subject: [PATCH] Improvements to SIO driver. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@12301 110e8d01-0319-4d1e-a829-52ad28d1bb01 --- os/hal/include/hal_sio.h | 76 +++++++++++++++++++++++++++++++--- os/hal/templates/hal_sio_lld.c | 47 --------------------- os/hal/templates/hal_sio_lld.h | 62 ++++++++++++++++++++++----- 3 files changed, 121 insertions(+), 64 deletions(-) diff --git a/os/hal/include/hal_sio.h b/os/hal/include/hal_sio.h index 6aedba68a..6999574eb 100644 --- a/os/hal/include/hal_sio.h +++ b/os/hal/include/hal_sio.h @@ -62,6 +62,16 @@ /* Driver data structures and types. */ /*===========================================================================*/ +/** + * @brief Type of structure representing a SIO driver. + */ +typedef struct hal_sio_driver SIODriver; + +/** + * @brief Type of structure representing a SIO configuration. + */ +typedef struct hal_sio_config SIOConfig; + /** * @brief Driver state machine possible states. */ @@ -71,12 +81,67 @@ typedef enum { SIO_READY = 2 /**< Ready. */ } siostate_t; +/** + * @brief Type of a function writing a frame received by SIO. + */ +typedef msg_t (*sioput_t)(void *p, uint8_t b); + +/** + * @brief Type of a function reading a frame to be transmitted by SIO. + */ +typedef msg_t (*sioget_t)(void *p); + #include "hal_sio_lld.h" /*===========================================================================*/ /* Driver macros. */ /*===========================================================================*/ +/** + * @brief Determines the state of the RX FIFO. + * + * @param[in] siop pointer to the @p SIODriver object + * @return The RX FIFO state. + * @retval false if RX FIFO is not empty + * @retval true if RX FIFO is empty + * + * @xclass + */ +#define sioRXIsEmptyX(siop) sio_lld_rx_is_empty(siop) + +/** + * @brief Determines the state of the TX FIFO. + * + * @param[in] siop pointer to the @p SIODriver object + * @return The TX FIFO state. + * @retval false if TX FIFO is not full + * @retval true if TX FIFO is full + * + * @xclass + */ +#define sioTXIsFullX(siop) sio_lld_tx_is_full(siop) + +/** + * @brief Returns one frame from the RX FIFO. + * @note If the FIFO is empty then the returned value is unpredictable. + * + * @param[in] siop pointer to the @p SIODriver object + * @return The frame from RX FIFO. + * + * @xclass + */ +#define sioRXGetX(siop) sio_lld_rx_get(siop) + +/** + * @brief Pushes one frame into the TX FIFO. + * @note If the FIFO is full then the behavior is unpredictable. + * + * @param[in] siop pointer to the @p SIODriver object + * + * @xclass + */ +#define sioTXPutX(siop, data) sio_lld_tx_put(siop, data) + /** * @brief Reads data from the RX FIFO. * @details This function is non-blocking, data is read if present and the @@ -86,8 +151,8 @@ typedef enum { * * @param[in] siop pointer to the @p SIODriver object * @param[in] buffer buffer for the received data - * @param[in] size maximum number of bytes to read - * @return The number of received bytes. + * @param[in] size maximum number of frames to read + * @return The number of received frames. * * @xclass */ @@ -101,9 +166,9 @@ typedef enum { * be called from the @p txnf_cb callback handler. * * @param[in] siop pointer to the @p SIODriver object - * @param[out] buffer buffer containing the data to be transmitted - * @param[in] size maximum number of bytes to read - * @return The number of transmitted bytes. + * @param[out] buffer buffer containing the data to be transmitted + * @param[in] size maximum number of frames to read + * @return The number of transmitted frames. * * @xclass */ @@ -136,7 +201,6 @@ extern "C" { void sioObjectInit(SIODriver *siop); void sioStart(SIODriver *siop, const SIOConfig *config); void sioStop(SIODriver *siop); - msg_t sioControl(SIODriver *siop, unsigned int operation, void *arg); #ifdef __cplusplus } #endif diff --git a/os/hal/templates/hal_sio_lld.c b/os/hal/templates/hal_sio_lld.c index ea425709c..96b229106 100644 --- a/os/hal/templates/hal_sio_lld.c +++ b/os/hal/templates/hal_sio_lld.c @@ -112,53 +112,6 @@ void sio_lld_stop(SIODriver *siop) { } } - -/** - * @brief Reads data from the RX FIFO. - * @details This function is non-blocking, data is read if present and the - * effective amount is returned. - * @note This function can be called from any context but it is meant to - * be called from the @p rxne_cb callback handler. - * - * @param[in] siop pointer to the @p SIODriver object - * @param[in] buffer buffer for the received data - * @param[in] size maximum number of bytes to read - * @return The number of received bytes. - * - * @notapi - */ -size_t sio_lld_read(SIODriver *siop, uint8_t *buffer, size_t size) { - - (void)siop; - (void)buffer; - (void)size; - - return (size_t)0; -} - -/** - * @brief Writes data into the TX FIFO. - * @details This function is non-blocking, data is written if there is space - * in the FIFO and the effective amount is returned. - * @note This function can be called from any context but it is meant to - * be called from the @p rxne_cb callback handler. - * - * @param[in] siop pointer to the @p SIODriver object - * @param[out] buffer buffer containing the data to be transmitted - * @param[in] size maximum number of bytes to read - * @return The number of transmitted bytes. - * - * @notapi - */ -size_t sio_lld_write(SIODriver *siop, const uint8_t *buffer, size_t size) { - - (void)siop; - (void)buffer; - (void)size; - - return (size_t)0; -} - /** * @brief Control operation on a serial port. * diff --git a/os/hal/templates/hal_sio_lld.h b/os/hal/templates/hal_sio_lld.h index 45aa3f2e8..c78de4da9 100644 --- a/os/hal/templates/hal_sio_lld.h +++ b/os/hal/templates/hal_sio_lld.h @@ -62,11 +62,6 @@ */ typedef uint32_t sioflags_t; -/** - * @brief Type of structure representing an SIO driver. - */ -typedef struct SIODriver SIODriver; - /** * @brief Generic SIO notification callback type. * @@ -88,7 +83,7 @@ typedef void (*sioecb_t)(SIODriver *siop, sioflags_t e); * @note Implementations may extend this structure to contain more, * architecture dependent, fields. */ -typedef struct { +struct hal_sio_config { /** * @brief Receive buffer filled callback. */ @@ -106,14 +101,14 @@ typedef struct { */ sioecb_t rxevt_cb; /* End of the mandatory fields.*/ -} SIOConfig; +}; /** - * @brief Structure representing an SIO driver. + * @brief Structure representing a SIO driver. * @note Implementations may extend this structure to contain more, * architecture dependent, fields. */ -struct SIODriver { +struct hal_sio_driver { /** * @brief Driver state. */ @@ -132,6 +127,51 @@ struct SIODriver { /* Driver macros. */ /*===========================================================================*/ +/** + * @brief Determines the state of the RX FIFO. + * + * @param[in] siop pointer to the @p SIODriver object + * @return The RX FIFO state. + * @retval false if RX FIFO is not empty + * @retval true if RX FIFO is empty + * + * @notapi + */ +#define sio_lld_rx_is_empty(siop) true + +/** + * @brief Determines the state of the TX FIFO. + * + * @param[in] siop pointer to the @p SIODriver object + * @return The TX FIFO state. + * @retval false if TX FIFO is not full + * @retval true if TX FIFO is full + * + * @notapi + */ +#define sio_lld_tx_is_full(siop) true + +/** + * @brief Returns one frame from the RX FIFO. + * @note If the FIFO is empty then the returned value is unpredictable. + * + * @param[in] siop pointer to the @p SIODriver object + * @return The frame from RX FIFO. + * + * @notapi + */ +#define sio_lld_rx_get(siop) + +/** + * @brief Pushes one frame into the TX FIFO. + * @note If the FIFO is full then the behavior is unpredictable. + * + * @param[in] siop pointer to the @p SIODriver object + * + * @notapi + */ +#define sio_lld_tx_put(siop, data) + /*===========================================================================*/ /* External declarations. */ /*===========================================================================*/ @@ -146,8 +186,8 @@ extern "C" { void sio_lld_init(void); void sio_lld_start(SIODriver *siop); void sio_lld_stop(SIODriver *siop); - size_t sio_lld_read(SIODriver *siop, uint8_t *buffer, size_t size); - size_t sio_lld_write(SIODriver *siop, const uint8_t *buffer, size_t size); + size_t sio_lld_read(SIODriver *siop, void *buffer, size_t size); + size_t sio_lld_write(SIODriver *siop, const void *buffer, size_t size); msg_t sio_lld_control(SIODriver *siop, unsigned int operation, void *arg); #ifdef __cplusplus }