diff --git a/doc/build/hal/index.html b/doc/build/hal/index.html deleted file mode 100644 index bf4fe4e3f..000000000 --- a/doc/build/hal/index.html +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/os/hal/dox/hal_spi.dox b/os/hal/dox/hal_spi_v1.dox similarity index 94% rename from os/hal/dox/hal_spi.dox rename to os/hal/dox/hal_spi_v1.dox index 4307bacd9..8fa740562 100644 --- a/os/hal/dox/hal_spi.dox +++ b/os/hal/dox/hal_spi_v1.dox @@ -15,15 +15,15 @@ */ /** - * @defgroup SPI SPI Driver - * @brief Generic SPI Driver. + * @defgroup SPI_V1 SPIv1 Driver + * @brief Generic SPI Driver (legacy). * @details This module implements a generic SPI (Serial Peripheral Interface) * driver allowing bidirectional and monodirectional transfers, * complex atomic transactions are supported as well. * @pre In order to use the SPI driver the @p HAL_USE_SPI option * must be enabled in @p halconf.h. * - * @section spi_1 Driver State Machine + * @section spi_v1_1 Driver State Machine * The driver implements a state machine internally, not all the driver * functionalities can be used in any moment, any transition not explicitly * shown in the following diagram has to be considered an error and shall diff --git a/os/hal/templates/hal_spi_lld.c b/os/hal/templates/hal_spi_v1_lld.c similarity index 91% rename from os/hal/templates/hal_spi_lld.c rename to os/hal/templates/hal_spi_v1_lld.c index 557342d6e..40a835bfd 100644 --- a/os/hal/templates/hal_spi_lld.c +++ b/os/hal/templates/hal_spi_v1_lld.c @@ -15,10 +15,10 @@ */ /** - * @file hal_spi_lld.c - * @brief PLATFORM SPI subsystem low level driver source. + * @file hal_spi_v1_lld.c + * @brief PLATFORM SPI (v1) subsystem low level driver source. * - * @addtogroup SPI + * @addtogroup SPI_V1 * @{ */ @@ -80,13 +80,22 @@ void spi_lld_init(void) { void spi_lld_start(SPIDriver *spip) { if (spip->state == SPI_STOP) { + /* Enables the peripheral.*/ + if (false) { + } + #if PLATFORM_SPI_USE_SPI1 == TRUE if (&SPID1 == spip) { } #endif + + else { + osalDbgAssert(false, "invalid SPI instance"); + } } + /* Configures the peripheral.*/ } @@ -101,15 +110,24 @@ void spi_lld_start(SPIDriver *spip) { void spi_lld_stop(SPIDriver *spip) { if (spip->state == SPI_READY) { + /* Disables the peripheral.*/ + if (false) { + } + #if PLATFORM_SPI_USE_SPI1 == TRUE if (&SPID1 == spip) { } #endif + + else { + osalDbgAssert(false, "invalid SPI instance"); + } } } +#if (SPI_SELECT_MODE == SPI_SELECT_MODE_LLD) || defined(__DOXYGEN__) /** * @brief Asserts the slave select signal and prepares for transfers. * @@ -136,6 +154,7 @@ void spi_lld_unselect(SPIDriver *spip) { (void)spip; } +#endif /** * @brief Ignores data on the SPI bus. diff --git a/os/hal/templates/hal_spi_lld.h b/os/hal/templates/hal_spi_v1_lld.h similarity index 94% rename from os/hal/templates/hal_spi_lld.h rename to os/hal/templates/hal_spi_v1_lld.h index b3f180a9d..11fa41ff3 100644 --- a/os/hal/templates/hal_spi_lld.h +++ b/os/hal/templates/hal_spi_v1_lld.h @@ -15,10 +15,10 @@ */ /** - * @file hal_spi_lld.h - * @brief PLATFORM SPI subsystem low level driver header. + * @file hal_spi_v1_lld.h + * @brief PLATFORM SPI (v1) subsystem low level driver header. * - * @addtogroup SPI + * @addtogroup SPI_V1 * @{ */ diff --git a/os/hal/templates/hal_spi_v2_lld.c b/os/hal/templates/hal_spi_v2_lld.c new file mode 100644 index 000000000..ddc90b3dd --- /dev/null +++ b/os/hal/templates/hal_spi_v2_lld.c @@ -0,0 +1,291 @@ +/* + 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_spi_v2_lld.c + * @brief PLATFORM SPI (v2) subsystem low level driver source. + * + * @addtogroup SPI_V2 + * @{ + */ + +#include "hal.h" + +#if HAL_USE_SPI || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Driver local definitions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +/** + * @brief SPI1 driver identifier. + */ +#if (PLATFORM_SPI_USE_SPI1 == TRUE) || defined(__DOXYGEN__) +SPIDriver SPID1; +#endif + +/*===========================================================================*/ +/* Driver local variables and types. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver interrupt handlers. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + +/** + * @brief Low level SPI driver initialization. + * + * @notapi + */ +void spi_lld_init(void) { + +#if PLATFORM_SPI_USE_SPI1 == TRUE + /* Driver initialization.*/ + spiObjectInit(&SPID1); +#endif +} + +/** + * @brief Configures and activates the SPI peripheral. + * + * @param[in] spip pointer to the @p SPIDriver object + * @return The operation status. + * + * @notapi + */ +msg_t spi_lld_start(SPIDriver *spip) { + + if (spip->state == SPI_STOP) { + + /* Enables the peripheral.*/ + if (false) { + } + +#if PLATFORM_SPI_USE_SPI1 == TRUE + if (&SPID1 == spip) { + + } +#endif + + else { + osalDbgAssert(false, "invalid SPI instance"); + } + } + + return HAL_RET_SUCCESS; +} + +/** + * @brief Deactivates the SPI peripheral. + * + * @param[in] spip pointer to the @p SPIDriver object + * + * @notapi + */ +void spi_lld_stop(SPIDriver *spip) { + + if (spip->state == SPI_READY) { + + /* Disables the peripheral.*/ + if (false) { + } + +#if PLATFORM_SPI_USE_SPI1 == TRUE + if (&SPID1 == spip) { + + } +#endif + + else { + osalDbgAssert(false, "invalid SPI instance"); + } + } +} + +#if (SPI_SELECT_MODE == SPI_SELECT_MODE_LLD) || defined(__DOXYGEN__) +/** + * @brief Asserts the slave select signal and prepares for transfers. + * + * @param[in] spip pointer to the @p SPIDriver object + * + * @notapi + */ +void spi_lld_select(SPIDriver *spip) { + + (void)spip; +} + +/** + * @brief Deasserts the slave select signal. + * @details The previously selected peripheral is unselected. + * + * @param[in] spip pointer to the @p SPIDriver object + * + * @notapi + */ +void spi_lld_unselect(SPIDriver *spip) { + + (void)spip; +} +#endif + +/** + * @brief Ignores data on the SPI bus. + * @details This synchronous function performs the transmission of a series of + * idle words on the SPI bus and ignores the received data. + * @pre In order to use this function the option @p SPI_USE_SYNCHRONIZATION + * must be enabled. + * + * @param[in] spip pointer to the @p SPIDriver object + * @param[in] n number of words to be ignored + * @return The operation status. + * + * @notapi + */ +msg_t spi_lld_ignore(SPIDriver *spip, size_t n) { + + (void)spip; + (void)n; + + return HAL_RET_SUCCESS; +} + +/** + * @brief Exchanges data on the SPI bus. + * @details This asynchronous function starts a simultaneous transmit/receive + * operation. + * @post At the end of the operation the configured callback is invoked. + * @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] spip pointer to the @p SPIDriver object + * @param[in] n number of words to be exchanged + * @param[in] txbuf the pointer to the transmit buffer + * @param[out] rxbuf the pointer to the receive buffer + * @return The operation status. + * + * @notapi + */ +msg_t spi_lld_exchange(SPIDriver *spip, size_t n, + const void *txbuf, void *rxbuf) { + + (void)spip; + (void)n; + (void)txbuf; + (void)rxbuf; + + return HAL_RET_SUCCESS; +} + +/** + * @brief Sends data over the SPI bus. + * @details This asynchronous function starts a transmit operation. + * @post At the end of the operation the configured callback is invoked. + * @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] spip pointer to the @p SPIDriver object + * @param[in] n number of words to send + * @param[in] txbuf the pointer to the transmit buffer + * @return The operation status. + * + * @notapi + */ +msg_t spi_lld_send(SPIDriver *spip, size_t n, const void *txbuf) { + + (void)spip; + (void)n; + (void)txbuf; + + return HAL_RET_SUCCESS; +} + +/** + * @brief Receives data from the SPI bus. + * @details This asynchronous function starts a receive operation. + * @post At the end of the operation the configured callback is invoked. + * @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] spip pointer to the @p SPIDriver object + * @param[in] n number of words to receive + * @param[out] rxbuf the pointer to the receive buffer + * @return The operation status. + * + * @notapi + */ +msg_t spi_lld_receive(SPIDriver *spip, size_t n, void *rxbuf) { + + (void)spip; + (void)n; + (void)rxbuf; + + return HAL_RET_SUCCESS; +} + +/** + * @brief Aborts the ongoing SPI operation, if any. + * + * @param[in] spip pointer to the @p SPIDriver object + * @param[out] sizep pointer to the counter of frames not yet transferred + * or @p NULL + * @return The operation status. + * + * @notapi + */ +msg_t spi_lld_stop_transfer(SPIDriver *spip, size_t *sizep) { + + (void)spip; + (void)sizep; + + return HAL_RET_SUCCESS; +} + +/** + * @brief Exchanges one frame using a polled wait. + * @details This synchronous function exchanges one frame using a polled + * synchronization method. This function is useful when exchanging + * small amount of data on high speed channels, usually in this + * situation is much more efficient just wait for completion using + * polling than suspending the thread waiting for an interrupt. + * + * @param[in] spip pointer to the @p SPIDriver object + * @param[in] frame the data frame to send over the SPI bus + * @return The received data frame from the SPI bus. + */ +uint16_t spi_lld_polled_exchange(SPIDriver *spip, uint16_t frame) { + + (void)spip; + (void)frame; + + return 0; +} + +#endif /* HAL_USE_SPI */ + +/** @} */ diff --git a/os/hal/templates/hal_spi_v2_lld.h b/os/hal/templates/hal_spi_v2_lld.h new file mode 100644 index 000000000..5614d9c10 --- /dev/null +++ b/os/hal/templates/hal_spi_v2_lld.h @@ -0,0 +1,121 @@ +/* + 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_spi_v2_lld.h + * @brief PLATFORM SPI (v2) subsystem low level driver header. + * + * @addtogroup SPI_V2 + * @{ + */ + +#ifndef HAL_SPI_V2_LLD_H +#define HAL_SPI_V2_LLD_H + +#if HAL_USE_SPI || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Driver constants. */ +/*===========================================================================*/ + +/** + * @brief Circular mode support flag. + */ +#define SPI_SUPPORTS_CIRCULAR TRUE + +/** + * @brief Slave mode support flag. + */ +#define SPI_SUPPORTS_SLAVE_MODE TRUE + +/*===========================================================================*/ +/* Driver pre-compile time settings. */ +/*===========================================================================*/ + +/** + * @name PLATFORM configuration options + * @{ + */ +/** + * @brief SPI1 driver enable switch. + * @details If set to @p TRUE the support for SPI1 is included. + * @note The default is @p FALSE. + */ +#if !defined(PLATFORM_SPI_USE_SPI1) || defined(__DOXYGEN__) +#define PLATFORM_SPI_USE_SPI1 FALSE +#endif +/** @} */ + +/*===========================================================================*/ +/* Derived constants and error checks. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver data structures and types. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver macros. */ +/*===========================================================================*/ + +/** + * @brief Low level fields of the SPI driver structure. + */ +#define spi_lld_driver_fields \ + /* Dummy field, it is not needed.*/ \ + uint32_t dummy + +/** + * @brief Low level fields of the SPI configuration structure. + */ +#define spi_lld_config_fields \ + /* Dummy configuration, it is not needed.*/ \ + uint32_t dummy + +/*===========================================================================*/ +/* External declarations. */ +/*===========================================================================*/ + +#if (PLATFORM_SPI_USE_SPI1 == TRUE) && !defined(__DOXYGEN__) +extern SPIDriver SPID1; +#endif + +#ifdef __cplusplus +extern "C" { +#endif + void spi_lld_init(void); + msg_t spi_lld_start(SPIDriver *spip); + void spi_lld_stop(SPIDriver *spip); +#if (SPI_SELECT_MODE == SPI_SELECT_MODE_LLD) || defined(__DOXYGEN__) + void spi_lld_select(SPIDriver *spip); + void spi_lld_unselect(SPIDriver *spip); +#endif + msg_t spi_lld_ignore(SPIDriver *spip, size_t n); + msg_t spi_lld_exchange(SPIDriver *spip, size_t n, + const void *txbuf, void *rxbuf); + msg_t spi_lld_send(SPIDriver *spip, size_t n, const void *txbuf); + msg_t spi_lld_receive(SPIDriver *spip, size_t n, void *rxbuf); + msg_t spi_lld_stop_transfer(SPIDriver *spip, size_t *sizep); + uint16_t spi_lld_polled_exchange(SPIDriver *spip, uint16_t frame); +#ifdef __cplusplus +} +#endif + +#endif /* HAL_USE_SPI */ + +#endif /* HAL_SPI_V2_LLD_H */ + +/** @} */