aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal
diff options
context:
space:
mode:
authorGiovanni Di Sirio <gdisirio@gmail.com>2018-09-30 17:01:52 +0000
committerGiovanni Di Sirio <gdisirio@gmail.com>2018-09-30 17:01:52 +0000
commit85d62cbdf68219a526aa4ee68c325adda8b8d67e (patch)
tree0d2293850986a464910ea05a7786acdd4d9a9d51 /os/hal
parente100ea5b29ad86a12ef87aaf5c854dec17becfd4 (diff)
downloadChibiOS-85d62cbdf68219a526aa4ee68c325adda8b8d67e.tar.gz
ChibiOS-85d62cbdf68219a526aa4ee68c325adda8b8d67e.tar.bz2
ChibiOS-85d62cbdf68219a526aa4ee68c325adda8b8d67e.zip
Added WSPI-related code, updated halconf.h files.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@12311 110e8d01-0319-4d1e-a829-52ad28d1bb01
Diffstat (limited to 'os/hal')
-rwxr-xr-xos/hal/dox/wspi.dox26
-rw-r--r--os/hal/include/hal_wspi.h20
-rw-r--r--os/hal/templates/hal_wspi_lld.c208
-rw-r--r--os/hal/templates/hal_wspi_lld.h145
-rw-r--r--os/hal/templates/halconf.h27
-rw-r--r--os/hal/templates/platform.mk6
6 files changed, 430 insertions, 2 deletions
diff --git a/os/hal/dox/wspi.dox b/os/hal/dox/wspi.dox
new file mode 100755
index 000000000..5cf29d9bc
--- /dev/null
+++ b/os/hal/dox/wspi.dox
@@ -0,0 +1,26 @@
+/*
+ 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.
+*/
+
+/**
+ * @defgroup WSPI WSPI Driver
+ * @brief Generic WSPI Driver
+ * @details This module defines an abstract interface for an wide SPI
+ * communication interface (Quad SPI, Octal SPI and similar).
+ * @pre In order to use the WSPI driver the @p HAL_USE_WSPI option
+ * must be enabled in @p halconf.h.
+ *
+ * @ingroup HAL_NORMAL_DRIVERS
+ */
diff --git a/os/hal/include/hal_wspi.h b/os/hal/include/hal_wspi.h
index 3d7a9a1aa..8ba4be5ff 100644
--- a/os/hal/include/hal_wspi.h
+++ b/os/hal/include/hal_wspi.h
@@ -37,7 +37,7 @@
* supported. The LLD can also define additional modes or reorder
* the bit masks in a more convenient way for the underlying
* implementation. It is important however to maintain the same
- * same for the same functionality.
+ * name for the same functionality.
* @{
*/
#define WSPI_CFG_INSTRUCTION_MODE_MASK (7LU << 0LU)
@@ -143,6 +143,24 @@ typedef enum {
} wspistate_t;
/**
+ * @brief Type of a structure representing an WSPI driver.
+ */
+typedef struct hal_wspi_driver WSPIDriver;
+
+/**
+ * @brief Type of a structure representing an WSPI driver configuration.
+ */
+typedef struct hal_wspi_config WSPIConfig;
+
+/**
+ * @brief Type of a WSPI notification callback.
+ *
+ * @param[in] wspip pointer to the @p WSPIDriver object triggering the
+ * callback
+ */
+typedef void (*wspicallback_t)(WSPIDriver *wspip);
+
+/**
* @brief Type of a WSPI command descriptor.
*/
typedef struct {
diff --git a/os/hal/templates/hal_wspi_lld.c b/os/hal/templates/hal_wspi_lld.c
new file mode 100644
index 000000000..233caa67a
--- /dev/null
+++ b/os/hal/templates/hal_wspi_lld.c
@@ -0,0 +1,208 @@
+/*
+ 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_wspi_lld.c
+ * @brief PLATFORM WSPI subsystem low level driver source.
+ *
+ * @addtogroup WSPI
+ * @{
+ */
+
+#include "hal.h"
+
+#if (HAL_USE_WSPI == TRUE) || defined(__DOXYGEN__)
+
+/*===========================================================================*/
+/* Driver local definitions. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver exported variables. */
+/*===========================================================================*/
+
+/** @brief WSPID1 driver identifier.*/
+#if (PLATFORM_WSPI_USE_WSPI1 == TRUE) || defined(__DOXYGEN__)
+WSPIDriver WSPID1;
+#endif
+
+/*===========================================================================*/
+/* Driver local variables and types. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver local functions. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver interrupt handlers. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver exported functions. */
+/*===========================================================================*/
+
+/**
+ * @brief Low level WSPI driver initialization.
+ *
+ * @notapi
+ */
+void wspi_lld_init(void) {
+
+#if PLATFORM_WSPI_USE_WSPI1
+ wspiObjectInit(&WSPID1);
+#endif
+}
+
+/**
+ * @brief Configures and activates the WSPI peripheral.
+ *
+ * @param[in] wspip pointer to the @p WSPIDriver object
+ *
+ * @notapi
+ */
+void wspi_lld_start(WSPIDriver *wspip) {
+
+ /* If in stopped state then full initialization.*/
+ if (wspip->state == WSPI_STOP) {
+#if PLATFORM_WSPI_USE_WSPI1
+ if (&WSPID1 == wspip) {
+ }
+#endif
+
+ /* Common initializations.*/
+ }
+
+ /* WSPI setup and enable.*/
+}
+
+/**
+ * @brief Deactivates the WSPI peripheral.
+ *
+ * @param[in] wspip pointer to the @p WSPIDriver object
+ *
+ * @notapi
+ */
+void wspi_lld_stop(WSPIDriver *wspip) {
+
+ /* If in ready state then disables WSPI.*/
+ if (wspip->state == WSPI_READY) {
+
+ /* WSPI disable.*/
+
+ /* Stopping involved clocks.*/
+#if PLATFORM_WSPI_USE_WSPI1
+ if (&WSPID1 == wspip) {
+ }
+#endif
+ }
+}
+
+/**
+ * @brief Sends a command without data phase.
+ * @post At the end of the operation the configured callback is invoked.
+ *
+ * @param[in] wspip pointer to the @p WSPIDriver object
+ * @param[in] cmdp pointer to the command descriptor
+ *
+ * @notapi
+ */
+void wspi_lld_command(WSPIDriver *wspip, const wspi_command_t *cmdp) {
+
+ (void)wspip;
+ (void)cmdp;
+}
+
+/**
+ * @brief Sends a command with data over the WSPI bus.
+ * @post At the end of the operation the configured callback is invoked.
+ *
+ * @param[in] wspip pointer to the @p WSPIDriver object
+ * @param[in] cmdp pointer to the command descriptor
+ * @param[in] n number of bytes to send
+ * @param[in] txbuf the pointer to the transmit buffer
+ *
+ * @notapi
+ */
+void wspi_lld_send(WSPIDriver *wspip, const wspi_command_t *cmdp,
+ size_t n, const uint8_t *txbuf) {
+
+ (void)wspip;
+ (void)cmdp;
+ (void)n;
+ (void)txbuf;
+}
+
+/**
+ * @brief Sends a command then receives data over the WSPI bus.
+ * @post At the end of the operation the configured callback is invoked.
+ *
+ * @param[in] wspip pointer to the @p WSPIDriver object
+ * @param[in] cmdp pointer to the command descriptor
+ * @param[in] n number of bytes to send
+ * @param[out] rxbuf the pointer to the receive buffer
+ *
+ * @notapi
+ */
+void wspi_lld_receive(WSPIDriver *wspip, const wspi_command_t *cmdp,
+ size_t n, uint8_t *rxbuf) {
+
+ (void)wspip;
+ (void)cmdp;
+ (void)n;
+ (void)rxbuf;
+}
+
+#if (WSPI_SUPPORTS_MEMMAP == TRUE) || defined(__DOXYGEN__)
+/**
+ * @brief Maps in memory space a WSPI flash device.
+ * @pre The memory flash device must be initialized appropriately
+ * before mapping it in memory space.
+ *
+ * @param[in] wspip pointer to the @p WSPIDriver object
+ * @param[in] cmdp pointer to the command descriptor
+ * @param[out] addrp pointer to the memory start address of the mapped
+ * flash or @p NULL
+ *
+ * @notapi
+ */
+void wspi_lld_map_flash(WSPIDriver *wspip,
+ const wspi_command_t *cmdp,
+ uint8_t **addrp) {
+
+ (void)wspip;
+ (void)cmdp;
+ (void)addrp;
+}
+
+/**
+ * @brief Unmaps from memory space a WSPI flash device.
+ * @post The memory flash device must be re-initialized for normal
+ * commands exchange.
+ *
+ * @param[in] wspip pointer to the @p WSPIDriver object
+ *
+ * @notapi
+ */
+void wspi_lld_unmap_flash(WSPIDriver *wspip) {
+
+ (void)wspip;
+}
+#endif /* WSPI_SUPPORTS_MEMMAP == TRUE */
+
+#endif /* HAL_USE_WSPI */
+
+/** @} */
diff --git a/os/hal/templates/hal_wspi_lld.h b/os/hal/templates/hal_wspi_lld.h
new file mode 100644
index 000000000..9b3a1550d
--- /dev/null
+++ b/os/hal/templates/hal_wspi_lld.h
@@ -0,0 +1,145 @@
+/*
+ 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_wspi_lld.h
+ * @brief PLATFORM WSPI subsystem low level driver header.
+ *
+ * @addtogroup WSPI
+ * @{
+ */
+
+#ifndef HAL_WSPI_LLD_H
+#define HAL_WSPI_LLD_H
+
+#if (HAL_USE_WSPI == TRUE) || defined(__DOXYGEN__)
+
+/*===========================================================================*/
+/* Driver constants. */
+/*===========================================================================*/
+
+/**
+ * @name WSPI capabilities
+ * @{
+ */
+#define WSPI_SUPPORTS_MEMMAP TRUE
+/** @} */
+
+/*===========================================================================*/
+/* Driver pre-compile time settings. */
+/*===========================================================================*/
+
+/**
+ * @name Configuration options
+ * @{
+ */
+/**
+ * @brief WSPID1 driver enable switch.
+ * @details If set to @p TRUE the support for WSPID1 is included.
+ * @note The default is @p FALSE.
+ */
+#if !defined(PLATFORM_WSPI_USE_WSPI1) || defined(__DOXYGEN__)
+#define PLATFORM_WSPI_USE_WSPI1 FALSE
+#endif
+/** @} */
+
+/*===========================================================================*/
+/* Derived constants and error checks. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver data structures and types. */
+/*===========================================================================*/
+
+/**
+ * @brief Driver configuration structure.
+ */
+struct hal_wspi_config {
+ /**
+ * @brief Operation complete callback or @p NULL.
+ */
+ wspicallback_t end_cb;
+ /* End of the mandatory fields.*/
+};
+
+/**
+ * @brief Structure representing an WSPI driver.
+ */
+struct hal_wspi_driver {
+ /**
+ * @brief Driver state.
+ */
+ wspistate_t state;
+ /**
+ * @brief Current configuration data.
+ */
+ const WSPIConfig *config;
+#if (WSPI_USE_WAIT == TRUE) || defined(__DOXYGEN__)
+ /**
+ * @brief Waiting thread.
+ */
+ thread_reference_t thread;
+#endif /* WSPI_USE_WAIT */
+#if (WSPI_USE_MUTUAL_EXCLUSION == TRUE) || defined(__DOXYGEN__)
+ /**
+ * @brief Mutex protecting the peripheral.
+ */
+ mutex_t mutex;
+#endif /* WSPI_USE_MUTUAL_EXCLUSION */
+#if defined(WSPI_DRIVER_EXT_FIELDS)
+ WSPI_DRIVER_EXT_FIELDS
+#endif
+ /* End of the mandatory fields.*/
+};
+
+/*===========================================================================*/
+/* Driver macros. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#if (PLATFORM_WSPI_USE_WSPI1 == TRUE) && !defined(__DOXYGEN__)
+extern WSPIDriver WSPID1;
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ void wspi_lld_init(void);
+ void wspi_lld_start(WSPIDriver *wspip);
+ void wspi_lld_stop(WSPIDriver *wspip);
+ void wspi_lld_command(WSPIDriver *wspip, const wspi_command_t *cmdp);
+ void wspi_lld_send(WSPIDriver *wspip, const wspi_command_t *cmdp,
+ size_t n, const uint8_t *txbuf);
+ void wspi_lld_receive(WSPIDriver *wspip, const wspi_command_t *cmdp,
+ size_t n, uint8_t *rxbuf);
+#if WSPI_SUPPORTS_MEMMAP == TRUE
+ void wspi_lld_map_flash(WSPIDriver *wspip,
+ const wspi_command_t *cmdp,
+ uint8_t **addrp);
+ void wspi_lld_unmap_flash(WSPIDriver *wspip);
+#endif
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* HAL_USE_WSPI */
+
+#endif /* HAL_WSPI_LLD_H */
+
+/** @} */
diff --git a/os/hal/templates/halconf.h b/os/hal/templates/halconf.h
index d78e812a7..15d9d3ebe 100644
--- a/os/hal/templates/halconf.h
+++ b/os/hal/templates/halconf.h
@@ -201,6 +201,13 @@
#define HAL_USE_WDG TRUE
#endif
+/**
+ * @brief Enables the WSPI subsystem.
+ */
+#if !defined(HAL_USE_WSPI) || defined(__DOXYGEN__)
+#define HAL_USE_WSPI TRUE
+#endif
+
/*===========================================================================*/
/* PAL driver related settings. */
/*===========================================================================*/
@@ -527,6 +534,26 @@
#define USB_USE_WAIT TRUE
#endif
+/*===========================================================================*/
+/* WSPI driver related settings. */
+/*===========================================================================*/
+
+/**
+ * @brief Enables synchronous APIs.
+ * @note Disabling this option saves both code and data space.
+ */
+#if !defined(WSPI_USE_WAIT) || defined(__DOXYGEN__)
+#define WSPI_USE_WAIT TRUE
+#endif
+
+/**
+ * @brief Enables the @p wspiAcquireBus() and @p wspiReleaseBus() APIs.
+ * @note Disabling this option saves both code and data space.
+ */
+#if !defined(WSPI_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
+#define WSPI_USE_MUTUAL_EXCLUSION TRUE
+#endif
+
#endif /* HALCONF_H */
/** @} */
diff --git a/os/hal/templates/platform.mk b/os/hal/templates/platform.mk
index 535e83b20..ee1d9e294 100644
--- a/os/hal/templates/platform.mk
+++ b/os/hal/templates/platform.mk
@@ -76,6 +76,9 @@ endif
ifneq ($(findstring HAL_USE_WDG TRUE,$(HALCONF)),)
PLATFORMSRC += ${CHIBIOS}/os/hal/templates/hal_wdg_lld.c
endif
+ifneq ($(findstring HAL_USE_WSPI TRUE,$(HALCONF)),)
+PLATFORMSRC += ${CHIBIOS}/os/hal/templates/hal_wspi_lld.c
+endif
else
PLATFORMSRC = ${CHIBIOS}/os/hal/templates/hal_lld.c \
${CHIBIOS}/os/hal/templates/hal_adc_lld.c \
@@ -100,7 +103,8 @@ PLATFORMSRC = ${CHIBIOS}/os/hal/templates/hal_lld.c \
${CHIBIOS}/os/hal/templates/hal_trng_lld.c \
${CHIBIOS}/os/hal/templates/hal_uart_lld.c \
${CHIBIOS}/os/hal/templates/hal_usb_lld.c \
- ${CHIBIOS}/os/hal/templates/hal_wdg_lld.c
+ ${CHIBIOS}/os/hal/templates/hal_wdg_lld.c \
+ ${CHIBIOS}/os/hal/templates/hal_wspi_lld.c
endif
# Required include directories