//----------------------------------------------------------------------------- static void vectornav_gpt_end_cb(GPTDriver * gptp) { (void)gptp; switch( async_vn_msg.state ) { case VN_ASYNC_1ST_SLEEP: chSysLockFromISR(); async_vn_msg.state = VN_ASYNC_2ND_SPI_CB; memset(&async_vn_msg.buf, 0, sizeof(async_vn_msg.buf)); spiSelectI(VND1.spip); spiStartReceiveI(VND1.spip, async_vn_msg.buf_size, async_vn_msg.buf); chSysUnlockFromISR(); break; case VN_ASYNC_2ND_SLEEP: // finished, clear it all memset(&async_vn_msg, 0, sizeof(async_vn_msg)); break; case VN_ASYNC_INACTIVE: case VN_ASYNC_1ST_SPI_CB: case VN_ASYNC_2ND_SPI_CB: default: // @TODO: assert? break; } }
/** * @brief Receives data from the SPI bus. * @details This asynchronous function starts a receive operation. * @pre A slave must have been selected using @p spiSelect() or * @p spiSelectI(). * @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 * * @api */ void spiStartReceive(SPIDriver *spip, size_t n, void *rxbuf) { osalDbgCheck((spip != NULL) && (n > 0U) && (rxbuf != NULL)); osalSysLock(); osalDbgAssert(spip->state == SPI_READY, "not ready"); spiStartReceiveI(spip, n, rxbuf); osalSysUnlock(); }
/** * @brief Receives data from the SPI bus. * @details This asynchronous function starts a receive operation. * @pre A slave must have been selected using @p spiSelect() or * @p spiSelectI(). * @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 * * @api */ void spiStartReceive(SPIDriver *spip, size_t n, void *rxbuf) { chDbgCheck((spip != NULL) && (n > 0) && (rxbuf != NULL), "spiStartReceive"); chSysLock(); chDbgAssert(spip->state == SPI_READY, "spiStartReceive(), #1", "not ready"); spiStartReceiveI(spip, n, rxbuf); chSysUnlock(); }
/** * @brief Receives data from the SPI bus. * @details This synchronous function performs a receive operation. * @pre In order to use this function the option @p SPI_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] spip pointer to the @p SPIDriver object * @param[in] n number of words to receive * @param[out] rxbuf the pointer to the receive buffer * * @api */ void spiReceive(SPIDriver *spip, size_t n, void *rxbuf) { osalDbgCheck((spip != NULL) && (n > 0U) && (rxbuf != NULL)); osalSysLock(); osalDbgAssert(spip->state == SPI_READY, "not ready"); osalDbgAssert(spip->config->end_cb == NULL, "has callback"); spiStartReceiveI(spip, n, rxbuf); (void) osalThreadSuspendS(&spip->thread); osalSysUnlock(); }
/** * @brief Receives data from the SPI bus. * @details This synchronous function performs a receive operation. * @pre In order to use this function the option @p SPI_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] spip pointer to the @p SPIDriver object * @param[in] n number of words to receive * @param[out] rxbuf the pointer to the receive buffer * * @api */ void spiReceive(SPIDriver *spip, size_t n, void *rxbuf) { osalDbgCheck((spip != NULL) && (n > 0U) && (rxbuf != NULL)); #if SPI_SUPPORTS_CIRCULAR osalDbgCheck((spip->config->circular == false) || ((n & 1U) == 0U)); #endif osalSysLock(); osalDbgAssert(spip->state == SPI_READY, "not ready"); spiStartReceiveI(spip, n, rxbuf); (void) osalThreadSuspendS(&spip->thread); osalSysUnlock(); }
/** * @brief Receives data from the SPI bus. * @details This synchronous function performs a receive operation. * @pre In order to use this function the option @p SPI_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] spip pointer to the @p SPIDriver object * @param[in] n number of words to receive * @param[out] rxbuf the pointer to the receive buffer * * @api */ void spiReceive(SPIDriver *spip, size_t n, void *rxbuf) { chDbgCheck((spip != NULL) && (n > 0) && (rxbuf != NULL), "spiReceive"); chSysLock(); chDbgAssert(spip->state == SPI_READY, "spiReceive(), #1", "not ready"); chDbgAssert(spip->config->end_cb == NULL, "spiReceive(), #2", "has callback"); spiStartReceiveI(spip, n, rxbuf); _spi_wait_s(spip); chSysUnlock(); }