aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/src
diff options
context:
space:
mode:
authorGiovanni Di Sirio <gdisirio@gmail.com>2016-05-11 15:54:52 +0000
committerGiovanni Di Sirio <gdisirio@gmail.com>2016-05-11 15:54:52 +0000
commitd9c4509e94b5c66c190396711a8217c8a67335bb (patch)
treea09d7a5cd6b063785ea1354bd1c808ccaa30de94 /os/hal/src
parentb24cd5b34f11aa3e7dbbec3f6fd0a390fb93233d (diff)
downloadChibiOS-d9c4509e94b5c66c190396711a8217c8a67335bb.tar.gz
ChibiOS-d9c4509e94b5c66c190396711a8217c8a67335bb.tar.bz2
ChibiOS-d9c4509e94b5c66c190396711a8217c8a67335bb.zip
QSPI driver model, not complete.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@9468 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/hal/src')
-rw-r--r--os/hal/src/hal_qspi.c263
1 files changed, 263 insertions, 0 deletions
diff --git a/os/hal/src/hal_qspi.c b/os/hal/src/hal_qspi.c
new file mode 100644
index 000000000..e57694925
--- /dev/null
+++ b/os/hal/src/hal_qspi.c
@@ -0,0 +1,263 @@
+/*
+ ChibiOS - Copyright (C) 2006..2016 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_qspi.c
+ * @brief QSPI Driver code.
+ *
+ * @addtogroup QSPI
+ * @{
+ */
+
+#include "hal.h"
+
+#if (HAL_USE_QSPI == TRUE) || defined(__DOXYGEN__)
+
+/*===========================================================================*/
+/* Driver local definitions. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver exported variables. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver local variables and types. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver local functions. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver exported functions. */
+/*===========================================================================*/
+
+/**
+ * @brief QSPI Driver initialization.
+ * @note This function is implicitly invoked by @p halInit(), there is
+ * no need to explicitly initialize the driver.
+ *
+ * @init
+ */
+void qspiInit(void) {
+
+ qspi_lld_init();
+}
+
+/**
+ * @brief Initializes the standard part of a @p QSPIDriver structure.
+ *
+ * @param[out] qspip pointer to the @p QSPIDriver object
+ *
+ * @init
+ */
+void qspiObjectInit(QSPIDriver *qspip) {
+
+ qspip->state = QSPI_STOP;
+ qspip->config = NULL;
+#if QSPI_USE_WAIT == TRUE
+ qspip->thread = NULL;
+#endif
+#if QSPI_USE_MUTUAL_EXCLUSION == TRUE
+ osalMutexObjectInit(&qspip->mutex);
+#endif
+#if defined(QSPI_DRIVER_EXT_INIT_HOOK)
+ QSPI_DRIVER_EXT_INIT_HOOK(qspip);
+#endif
+}
+
+/**
+ * @brief Configures and activates the QSPI peripheral.
+ *
+ * @param[in] qspip pointer to the @p QSPIDriver object
+ * @param[in] config pointer to the @p QSPIConfig object
+ *
+ * @api
+ */
+void qspiStart(QSPIDriver *qspip, const QSPIConfig *config) {
+
+ osalDbgCheck((qspip != NULL) && (config != NULL));
+
+ osalSysLock();
+ osalDbgAssert((qspip->state == QSPI_STOP) || (qspip->state == QSPI_READY),
+ "invalid state");
+ qspip->config = config;
+ qspi_lld_start(qspip);
+ qspip->state = QSPI_READY;
+ osalSysUnlock();
+}
+
+/**
+ * @brief Deactivates the QSPI peripheral.
+ * @note Deactivating the peripheral also enforces a release of the slave
+ * select line.
+ *
+ * @param[in] qspip pointer to the @p QSPIDriver object
+ *
+ * @api
+ */
+void qspiStop(QSPIDriver *qspip) {
+
+ osalDbgCheck(qspip != NULL);
+
+ osalSysLock();
+ osalDbgAssert((qspip->state == QSPI_STOP) || (qspip->state == QSPI_READY),
+ "invalid state");
+ qspi_lld_stop(qspip);
+ qspip->state = QSPI_STOP;
+ osalSysUnlock();
+}
+
+/**
+ * @brief Sends data over the QSPI bus.
+ * @details This asynchronous function starts a transmit operation.
+ * @post At the end of the operation the configured callback is invoked.
+ *
+ * @param[in] qspip pointer to the @p QSPIDriver object
+ * @param[in] n number of words to send
+ * @param[in] txbuf the pointer to the transmit buffer
+ *
+ * @api
+ */
+void qspiStartSend(QSPIDriver *qspip, size_t n, const void *txbuf) {
+
+ osalDbgCheck((qspip != NULL) && (n > 0U) && (txbuf != NULL));
+
+ osalSysLock();
+ osalDbgAssert(qspip->state == QSPI_READY, "not ready");
+ qspiStartSendI(qspip, n, txbuf);
+ osalSysUnlock();
+}
+
+/**
+ * @brief Receives data from the QSPI bus.
+ * @details This asynchronous function starts a receive operation.
+ * @post At the end of the operation the configured callback is invoked.
+ *
+ * @param[in] qspip pointer to the @p QSPIDriver object
+ * @param[in] n number of words to receive
+ * @param[out] rxbuf the pointer to the receive buffer
+ *
+ * @api
+ */
+void qspiStartReceive(QSPIDriver *qspip, size_t n, void *rxbuf) {
+
+ osalDbgCheck((qspip != NULL) && (n > 0U) && (rxbuf != NULL));
+
+ osalSysLock();
+ osalDbgAssert(qspip->state == QSPI_READY, "not ready");
+ qspiStartReceiveI(qspip, n, rxbuf);
+ osalSysUnlock();
+}
+
+#if (QSPI_USE_WAIT == TRUE) || defined(__DOXYGEN__)
+/**
+ * @brief Sends data over the QSPI bus.
+ * @details This synchronous function performs a transmit operation.
+ * @pre In order to use this function the option @p QSPI_USE_WAIT must be
+ * enabled.
+ * @pre In order to use this function the driver must have been configured
+ * without callbacks (@p end_cb = @p NULL).
+ * @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] qspip pointer to the @p QSPIDriver object
+ * @param[in] n number of words to send
+ * @param[in] txbuf the pointer to the transmit buffer
+ *
+ * @api
+ */
+void qspiSend(QSPIDriver *qspip, size_t n, const void *txbuf) {
+
+ osalDbgCheck((qspip != NULL) && (n > 0U) && (txbuf != NULL));
+
+ osalSysLock();
+ osalDbgAssert(qspip->state == QSPI_READY, "not ready");
+ osalDbgAssert(qspip->config->end_cb == NULL, "has callback");
+ qspiStartSendI(qspip, n, txbuf);
+ (void) osalThreadSuspendS(&qspip->thread);
+ osalSysUnlock();
+}
+
+/**
+ * @brief Receives data from the QSPI bus.
+ * @details This synchronous function performs a receive operation.
+ * @pre In order to use this function the option @p QSPI_USE_WAIT must be
+ * enabled.
+ * @pre In order to use this function the driver must have been configured
+ * without callbacks (@p end_cb = @p NULL).
+ * @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] qspip pointer to the @p QSPIDriver object
+ * @param[in] n number of words to receive
+ * @param[out] rxbuf the pointer to the receive buffer
+ *
+ * @api
+ */
+void qspiReceive(QSPIDriver *qspip, size_t n, void *rxbuf) {
+
+ osalDbgCheck((qspip != NULL) && (n > 0U) && (rxbuf != NULL));
+
+ osalSysLock();
+ osalDbgAssert(qspip->state == QSPI_READY, "not ready");
+ osalDbgAssert(qspip->config->end_cb == NULL, "has callback");
+ qspiStartReceiveI(qspip, n, rxbuf);
+ (void) osalThreadSuspendS(&qspip->thread);
+ osalSysUnlock();
+}
+#endif /* QSPI_USE_WAIT == TRUE */
+
+#if (QSPI_USE_MUTUAL_EXCLUSION == TRUE) || defined(__DOXYGEN__)
+/**
+ * @brief Gains exclusive access to the QSPI bus.
+ * @details This function tries to gain ownership to the QSPI bus, if the bus
+ * is already being used then the invoking thread is queued.
+ * @pre In order to use this function the option @p QSPI_USE_MUTUAL_EXCLUSION
+ * must be enabled.
+ *
+ * @param[in] qspip pointer to the @p QSPIDriver object
+ *
+ * @api
+ */
+void qspiAcquireBus(QSPIDriver *qspip) {
+
+ osalDbgCheck(qspip != NULL);
+
+ osalMutexLock(&qspip->mutex);
+}
+
+/**
+ * @brief Releases exclusive access to the QSPI bus.
+ * @pre In order to use this function the option @p QSPI_USE_MUTUAL_EXCLUSION
+ * must be enabled.
+ *
+ * @param[in] qspip pointer to the @p QSPIDriver object
+ *
+ * @api
+ */
+void qspiReleaseBus(QSPIDriver *qspip) {
+
+ osalDbgCheck(qspip != NULL);
+
+ osalMutexUnlock(&qspip->mutex);
+}
+#endif /* QSPI_USE_MUTUAL_EXCLUSION == TRUE */
+
+#endif /* HAL_USE_QSPI == TRUE */
+
+/** @} */