mirror of https://github.com/rusefi/ChibiOS.git
SIO improvements, it is almost final.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@13829 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
This commit is contained in:
parent
281f23ea19
commit
5f9d6389e7
|
@ -59,19 +59,21 @@
|
|||
* @name SIO configuration options
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @brief Default bit rate.
|
||||
* @details Configuration parameter, this is the baud rate selected for the
|
||||
* default configuration.
|
||||
*/
|
||||
#if !defined(SIO_DEFAULT_BITRATE) || defined(__DOXYGEN__)
|
||||
#define SIO_DEFAULT_BITRATE 38400
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Support for thread synchronization API.
|
||||
*/
|
||||
#if !defined(HAL_SIO_USE_SYNCHRONIZATION) || defined(__DOXYGEN__)
|
||||
#define HAL_SIO_USE_SYNCHRONIZATION TRUE
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Support for callbacks.
|
||||
*/
|
||||
#if !defined(HAL_SIO_USE_CALLBACKS) || defined(__DOXYGEN__)
|
||||
#define HAL_SIO_USE_CALLBACKS TRUE
|
||||
#endif
|
||||
/** @} */
|
||||
|
||||
/*===========================================================================*/
|
||||
|
|
|
@ -123,6 +123,19 @@ SIODriver LPSIOD1;
|
|||
/* Driver local variables and types. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Driver default configuration.
|
||||
* @note In this implementation it is: 38400-8-N-1, RX and TX FIFO
|
||||
* thresholds set to 50%.
|
||||
*/
|
||||
static const SIOConfig default_config = {
|
||||
.baud = SIO_DEFAULT_BITRATE,
|
||||
.presc = USART_PRESC1,
|
||||
.cr1 = USART_CR1_DATA8 | USART_CR1_OVER16,
|
||||
.cr2 = USART_CR2_STOP1_BITS,
|
||||
.cr3 = USART_CR3_TXFTCFG_1H | USART_CR3_RXFTCFG_1H
|
||||
};
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local functions. */
|
||||
/*===========================================================================*/
|
||||
|
@ -299,6 +312,12 @@ void sio_lld_init(void) {
|
|||
*/
|
||||
bool sio_lld_start(SIODriver *siop) {
|
||||
|
||||
/* Using the default configuration if the application passed a
|
||||
NULL pointer.*/
|
||||
if (siop->config == NULL) {
|
||||
siop->config = &default_config;
|
||||
}
|
||||
|
||||
if (siop->state == SIO_STOP) {
|
||||
|
||||
/* Enables the peripheral.*/
|
||||
|
|
|
@ -38,6 +38,14 @@
|
|||
/* Driver local variables and types. */
|
||||
/*===========================================================================*/
|
||||
|
||||
static const SIOOperation default_operation = {
|
||||
.rx_cb = NULL,
|
||||
.rx_idle_cb = NULL,
|
||||
.tx_cb = NULL,
|
||||
.tx_end_cb = NULL,
|
||||
.rx_evt_cb = NULL
|
||||
};
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver local functions. */
|
||||
/*===========================================================================*/
|
||||
|
@ -108,7 +116,7 @@ static msg_t __put(void *ip, uint8_t b) {
|
|||
|
||||
msg = sioSynchronizeTX(siop, TIME_INFINITE);
|
||||
if (msg != MSG_OK) {
|
||||
return MSG_RESET;
|
||||
return msg;
|
||||
}
|
||||
|
||||
sioPutX(siop, b);
|
||||
|
@ -121,7 +129,7 @@ static msg_t __get(void *ip) {
|
|||
|
||||
msg = sioSynchronizeRX(siop, TIME_INFINITE);
|
||||
if (msg != MSG_OK) {
|
||||
return MSG_RESET;
|
||||
return msg;
|
||||
}
|
||||
|
||||
return sioGetX(siop);
|
||||
|
@ -231,7 +239,8 @@ void sioObjectInit(SIODriver *siop) {
|
|||
* @brief Configures and activates the SIO peripheral.
|
||||
*
|
||||
* @param[in] siop pointer to the @p SIODriver object
|
||||
* @param[in] config pointer to the @p SIOConfig object
|
||||
* @param[in] config pointer to the @p SIOConfig object, can be @p NULL
|
||||
* if the default configuration is desired
|
||||
* @return The operation status.
|
||||
* @retval false if the driver has been correctly started.
|
||||
* @retval true if an error occurred.
|
||||
|
@ -241,7 +250,7 @@ void sioObjectInit(SIODriver *siop) {
|
|||
bool sioStart(SIODriver *siop, const SIOConfig *config) {
|
||||
bool result;
|
||||
|
||||
osalDbgCheck((siop != NULL) && (config != NULL));
|
||||
osalDbgCheck(siop != NULL);
|
||||
|
||||
osalSysLock();
|
||||
|
||||
|
@ -284,20 +293,28 @@ void sioStop(SIODriver *siop) {
|
|||
* @brief Starts a SIO operation.
|
||||
*
|
||||
* @param[in] siop pointer to an @p SIODriver structure
|
||||
* @param[in] operation pointer to an @p SIOOperation structure
|
||||
* @param[in] operation pointer to an @p SIOOperation structure, can
|
||||
* be @p NULL if callbacks are not required
|
||||
* encoding the operation to be performed
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
void sioStartOperation(SIODriver *siop, const SIOOperation *operation) {
|
||||
|
||||
osalDbgCheck((siop != NULL) && (operation != NULL));
|
||||
osalDbgCheck(siop != NULL);
|
||||
|
||||
osalSysLock();
|
||||
|
||||
osalDbgAssert(siop->state == SIO_READY, "invalid state");
|
||||
|
||||
siop->operation = operation;
|
||||
/* The application can pass NULL if it is not interested in callbacks,
|
||||
attaching a default operation structure.*/
|
||||
if (operation != NULL) {
|
||||
siop->operation = operation;
|
||||
}
|
||||
else {
|
||||
siop->operation = &default_operation;
|
||||
}
|
||||
siop->state = SIO_ACTIVE;
|
||||
|
||||
sio_lld_start_operation(siop);
|
||||
|
|
Loading…
Reference in New Issue