Improvements to SIO driver.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@12301 110e8d01-0319-4d1e-a829-52ad28d1bb01
This commit is contained in:
gdisirio 2018-09-28 09:10:43 +00:00
parent 4b23f3b361
commit e53c5fbf6c
3 changed files with 121 additions and 64 deletions

View File

@ -62,6 +62,16 @@
/* Driver data structures and types. */ /* 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. * @brief Driver state machine possible states.
*/ */
@ -71,12 +81,67 @@ typedef enum {
SIO_READY = 2 /**< Ready. */ SIO_READY = 2 /**< Ready. */
} siostate_t; } 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" #include "hal_sio_lld.h"
/*===========================================================================*/ /*===========================================================================*/
/* Driver macros. */ /* 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. * @brief Reads data from the RX FIFO.
* @details This function is non-blocking, data is read if present and the * @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] siop pointer to the @p SIODriver object
* @param[in] buffer buffer for the received data * @param[in] buffer buffer for the received data
* @param[in] size maximum number of bytes to read * @param[in] size maximum number of frames to read
* @return The number of received bytes. * @return The number of received frames.
* *
* @xclass * @xclass
*/ */
@ -101,9 +166,9 @@ typedef enum {
* be called from the @p txnf_cb callback handler. * be called from the @p txnf_cb callback handler.
* *
* @param[in] siop pointer to the @p SIODriver object * @param[in] siop pointer to the @p SIODriver object
* @param[out] buffer buffer containing the data to be transmitted * @param[out] buffer buffer containing the data to be transmitted
* @param[in] size maximum number of bytes to read * @param[in] size maximum number of frames to read
* @return The number of transmitted bytes. * @return The number of transmitted frames.
* *
* @xclass * @xclass
*/ */
@ -136,7 +201,6 @@ extern "C" {
void sioObjectInit(SIODriver *siop); void sioObjectInit(SIODriver *siop);
void sioStart(SIODriver *siop, const SIOConfig *config); void sioStart(SIODriver *siop, const SIOConfig *config);
void sioStop(SIODriver *siop); void sioStop(SIODriver *siop);
msg_t sioControl(SIODriver *siop, unsigned int operation, void *arg);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -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. * @brief Control operation on a serial port.
* *

View File

@ -62,11 +62,6 @@
*/ */
typedef uint32_t sioflags_t; typedef uint32_t sioflags_t;
/**
* @brief Type of structure representing an SIO driver.
*/
typedef struct SIODriver SIODriver;
/** /**
* @brief Generic SIO notification callback type. * @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, * @note Implementations may extend this structure to contain more,
* architecture dependent, fields. * architecture dependent, fields.
*/ */
typedef struct { struct hal_sio_config {
/** /**
* @brief Receive buffer filled callback. * @brief Receive buffer filled callback.
*/ */
@ -106,14 +101,14 @@ typedef struct {
*/ */
sioecb_t rxevt_cb; sioecb_t rxevt_cb;
/* End of the mandatory fields.*/ /* 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, * @note Implementations may extend this structure to contain more,
* architecture dependent, fields. * architecture dependent, fields.
*/ */
struct SIODriver { struct hal_sio_driver {
/** /**
* @brief Driver state. * @brief Driver state.
*/ */
@ -132,6 +127,51 @@ struct SIODriver {
/* Driver macros. */ /* 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. */ /* External declarations. */
/*===========================================================================*/ /*===========================================================================*/
@ -146,8 +186,8 @@ extern "C" {
void sio_lld_init(void); void sio_lld_init(void);
void sio_lld_start(SIODriver *siop); void sio_lld_start(SIODriver *siop);
void sio_lld_stop(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_read(SIODriver *siop, void *buffer, size_t size);
size_t sio_lld_write(SIODriver *siop, const uint8_t *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); msg_t sio_lld_control(SIODriver *siop, unsigned int operation, void *arg);
#ifdef __cplusplus #ifdef __cplusplus
} }