Incomplete work on SIO implementation.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@13811 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
This commit is contained in:
Giovanni Di Sirio 2020-08-27 19:33:50 +00:00
parent 5fec2a17fc
commit c21bbe0fa0
6 changed files with 423 additions and 10 deletions

View File

@ -282,11 +282,11 @@
/*
* SERIAL driver system settings.
*/
#define STM32_SERIAL_USE_USART1 FALSE
#define STM32_SERIAL_USE_USART2 FALSE
#define STM32_SERIAL_USE_USART3 FALSE
#define STM32_SERIAL_USE_UART4 FALSE
#define STM32_SERIAL_USE_UART5 FALSE
#define STM32_SERIAL_USE_USART1 TRUE
#define STM32_SERIAL_USE_USART2 TRUE
#define STM32_SERIAL_USE_USART3 TRUE
#define STM32_SERIAL_USE_UART4 TRUE
#define STM32_SERIAL_USE_UART5 TRUE
#define STM32_SERIAL_USE_LPUART1 TRUE
/*

View File

@ -51,7 +51,9 @@
* @name SIO configuration options
* @{
*/
#if !defined(HAL_SIO_USE_SYNCHRONIZATION) || defined(__DOXYGEN__)
#define HAL_SIO_USE_SYNCHRONIZATION TRUE
#endif
/** @} */
/*===========================================================================*/
@ -62,6 +64,11 @@
/* Driver data structures and types. */
/*===========================================================================*/
/**
* @brief SIO driver condition flags type.
*/
typedef uint_fast8_t sioflags_t;
/**
* @brief Type of structure representing a SIO driver.
*/
@ -72,17 +79,105 @@ typedef struct hal_sio_driver SIODriver;
*/
typedef struct hal_sio_config SIOConfig;
/**
* @brief Type of structure representing a SIO operation.
*/
typedef struct hal_sio_operation SIOOperation;
/**
* @brief Generic SIO notification callback type.
*
* @param[in] siop pointer to the @p SIODriver object
*/
typedef void (*siocb_t)(SIODriver *siop);
/**
* @brief Driver state machine possible states.
*/
typedef enum {
SIO_UNINIT = 0, /**< Not initialized. */
SIO_STOP = 1, /**< Stopped. */
SIO_READY = 2 /**< Ready. */
SIO_READY = 2, /**< Ready. */
SIO_ACTIVE = 3 /**< Operation ongoing. */
} siostate_t;
#include "hal_sio_lld.h"
/**
* @brief Driver configuration structure.
* @note Implementations may extend this structure to contain more,
* architecture dependent, fields.
*/
struct hal_sio_config {
/* End of the mandatory fields.*/
sio_lld_config_fields;
};
/**
* @brief Structure representing a SIO driver.
* @note Implementations may extend this structure to contain more,
* architecture dependent, fields.
*/
struct hal_sio_driver {
/**
* @brief Driver state.
*/
siostate_t state;
/**
* @brief Current configuration data.
*/
const SIOConfig *config;
/**
* @brief Current configuration data.
*/
const SIOOperation *operation;
#if (HAL_SIO_USE_SYNCHRONIZATION == TRUE) || defined(__DOXYGEN__)
/**
* @brief Synchronization point for RX.
*/
thread_reference_t sync_rx;
/**
* @brief Synchronization point for TX.
*/
thread_reference_t sync_tx;
/**
* @brief Synchronization point for TX-end.
*/
thread_reference_t sync_txend;
#endif /* HAL_SIO_USE_SYNCHRONIZATION == TRUE */
#if defined(SIO_DRIVER_EXT_FIELDS)
SIO_DRIVER_EXT_FIELDS
#endif
/* End of the mandatory fields.*/
sio_lld_driver_fields;
};
/**
* @brief Structure representing a SIO operation.
*/
struct hal_sio_operation {
/**
* @brief Receive buffer filled callback.
* @note Can be @p NULL.
*/
siocb_t rxne_cb;
/**
* @brief End of transmission buffer callback.
* @note Can be @p NULL.
*/
siocb_t txnf_cb;
/**
* @brief Physical end of transmission callback.
* @note Can be @p NULL.
*/
siocb_t txend_cb;
/**
* @brief Receive event callback.
* @note Can be @p NULL.
*/
siocb_t rxevt_cb;
};
/*===========================================================================*/
/* Driver macros. */
/*===========================================================================*/
@ -195,8 +290,13 @@ extern "C" {
#endif
void sioInit(void);
void sioObjectInit(SIODriver *siop);
void sioStart(SIODriver *siop, const SIOConfig *config);
bool sioStart(SIODriver *siop, const SIOConfig *config);
void sioStop(SIODriver *siop);
void sioStartOperation(SIODriver *siop, const SIOOperation *operation);
void sioStopOperation(SIODriver *siop);
msg_t sioSynchronizeRX(SIODriver *siop);
msg_t sioSynchronizeTX(SIODriver *siop);
msg_t sioSynchronizeTXEnd(SIODriver *siop);
#ifdef __cplusplus
}
#endif

View File

@ -2,11 +2,15 @@ ifeq ($(USE_SMART_BUILD),yes)
ifneq ($(findstring HAL_USE_SERIAL TRUE,$(HALCONF)),)
PLATFORMSRC += $(CHIBIOS)/os/hal/ports/STM32/LLD/USARTv2/hal_serial_lld.c
endif
ifneq ($(findstring HAL_USE_SIO TRUE,$(HALCONF)),)
PLATFORMSRC += $(CHIBIOS)/os/hal/ports/STM32/LLD/USARTv2/hal_sio_lld.c
endif
ifneq ($(findstring HAL_USE_UART TRUE,$(HALCONF)),)
PLATFORMSRC += $(CHIBIOS)/os/hal/ports/STM32/LLD/USARTv2/hal_uart_lld.c
endif
else
PLATFORMSRC += $(CHIBIOS)/os/hal/ports/STM32/LLD/USARTv2/hal_serial_lld.c
PLATFORMSRC += $(CHIBIOS)/os/hal/ports/STM32/LLD/USARTv2/hal_sio_lld.c
PLATFORMSRC += $(CHIBIOS)/os/hal/ports/STM32/LLD/USARTv2/hal_uart_lld.c
endif

View File

@ -0,0 +1,144 @@
/*
ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* @file hal_sio_lld.c
* @brief PLATFORM SIO subsystem low level driver source.
*
* @addtogroup SIO
* @{
*/
#include "hal.h"
#if (HAL_USE_SIO == TRUE) || defined(__DOXYGEN__)
/*===========================================================================*/
/* Driver local definitions. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver exported variables. */
/*===========================================================================*/
/**
* @brief SIO1 driver identifier.
*/
#if (PLATFORM_SIO_USE_SIO1 == TRUE) || defined(__DOXYGEN__)
SIODriver SIOD1;
#endif
/*===========================================================================*/
/* Driver local variables and types. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver local functions. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver interrupt handlers. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver exported functions. */
/*===========================================================================*/
/**
* @brief Low level SIO driver initialization.
*
* @notapi
*/
void sio_lld_init(void) {
#if PLATFORM_SIO_USE_SIO1 == TRUE
/* Driver initialization.*/
sioObjectInit(&SIOD1);
#endif
}
/**
* @brief Configures and activates the SIO peripheral.
*
* @param[in] siop pointer to the @p SIODriver object
* @return The operation status.
* @retval false if the driver has been correctly started.
* @retval true if an error occurred.
*
* @notapi
*/
bool sio_lld_start(SIODriver *siop) {
if (siop->state == SIO_STOP) {
/* Enables the peripheral.*/
#if PLATFORM_SIO_USE_SIO1 == TRUE
if (&SIOD1 == siop) {
}
#endif
}
/* Configures the peripheral.*/
return false;
}
/**
* @brief Deactivates the SIO peripheral.
*
* @param[in] siop pointer to the @p SIODriver object
*
* @notapi
*/
void sio_lld_stop(SIODriver *siop) {
if (siop->state == SIO_READY) {
/* Resets the peripheral.*/
/* Disables the peripheral.*/
#if PLATFORM_SIO_USE_SIO1 == TRUE
if (&SIOD1 == siop) {
}
#endif
}
}
/**
* @brief Control operation on a serial port.
*
* @param[in] siop pointer to the @p SIODriver object
* @param[in] operation control operation code
* @param[in,out] arg operation argument
*
* @return The control operation status.
* @retval MSG_OK in case of success.
* @retval MSG_TIMEOUT in case of operation timeout.
* @retval MSG_RESET in case of operation reset.
*
* @notapi
*/
msg_t sio_lld_control(SIODriver *siop, unsigned int operation, void *arg) {
(void)siop;
(void)operation;
(void)arg;
return MSG_OK;
}
#endif /* HAL_USE_SIO == TRUE */
/** @} */

View File

@ -0,0 +1,157 @@
/*
ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* @file hal_sio_lld.h
* @brief PLATFORM SIO subsystem low level driver header.
*
* @addtogroup SIO
* @{
*/
#ifndef HAL_SIO_LLD_H
#define HAL_SIO_LLD_H
#if (HAL_USE_SIO == TRUE) || defined(__DOXYGEN__)
/*===========================================================================*/
/* Driver constants. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver pre-compile time settings. */
/*===========================================================================*/
/**
* @name PLATFORM configuration options
* @{
*/
/**
* @brief SIO driver enable switch.
* @details If set to @p TRUE the support for SIO1 is included.
* @note The default is @p FALSE.
*/
#if !defined(PLATFORM_SIO_USE_SIO1) || defined(__DOXYGEN__)
#define PLATFORM_SIO_USE_SIO1 FALSE
#endif
/** @} */
/*===========================================================================*/
/* Derived constants and error checks. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver data structures and types. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver macros. */
/*===========================================================================*/
/**
* @brief Low level fields of the SIO driver structure.
*/
#define sio_lld_driver_fields \
/* Pointer to the USARTx registers block.*/ \
USART_TypeDef *usart
/**
* @brief Low level fields of the SIO configuration structure.
*/
#define sio_lld_config_fields \
/* Desired baud rate.*/ \
uint32_t baud; \
/* USART PRESC register initialization data.*/ \
uint32_t presc; \
/* USART CR1 register initialization data.*/ \
uint32_t cr1; \
/* USART CR1 register initialization data.*/ \
uint32_t cr2; \
/* USART CR1 register initialization data.*/ \
uint32_t cr3
/**
* @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
* @param[in] data frame to be written
*
* @notapi
*/
#define sio_lld_tx_put(siop, data)
/*===========================================================================*/
/* External declarations. */
/*===========================================================================*/
#if (PLATFORM_SIO_USE_SIO1 == TRUE) && !defined(__DOXYGEN__)
extern SIODriver SIOD1;
#endif
#ifdef __cplusplus
extern "C" {
#endif
void sio_lld_init(void);
bool sio_lld_start(SIODriver *siop);
void sio_lld_stop(SIODriver *siop);
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
}
#endif
#endif /* HAL_USE_SIO == TRUE */
#endif /* HAL_SIO_LLD_H */
/** @} */

View File

@ -81,21 +81,29 @@ void sioObjectInit(SIODriver *siop) {
*
* @param[in] siop pointer to the @p SIODriver object
* @param[in] config pointer to the @p SIOConfig object
* @return The operation status.
* @retval false if the driver has been correctly started.
* @retval true if an error occurred.
*
* @api
*/
void sioStart(SIODriver *siop, const SIOConfig *config) {
bool sioStart(SIODriver *siop, const SIOConfig *config) {
bool result;
osalDbgCheck((siop != NULL) && (config != NULL));
osalSysLock();
osalDbgAssert((siop->state == SIO_STOP) || (siop->state == SIO_READY),
"invalid state");
siop->config = config;
sio_lld_start(siop);
result = sio_lld_start(siop);
siop->state = SIO_READY;
osalSysUnlock();
return result;
}
/**