/** * @brief Resets the MPU6000 FIFO from an ISR * @param woken[in,out] If non-NULL, will be set to true if woken was false and a higher priority * task has is now eligible to run, else unchanged * @return 0 if operation was successful * @return -1 if unable to claim SPI bus * @return -2 if write to the device failed */ static int32_t PIOS_MPU6000_ResetFifoISR(bool *woken) { int32_t result = 0; /* Register writes must be at < 1MHz SPI clock. * Speed can only be changed when SPI bus semaphore is held, but * device chip select must not be enabled, so we use the direct * SPI bus claim call here */ if (PIOS_SPI_ClaimBusISR(dev->spi_id, woken) != 0) { return -1; } /* Reduce SPI clock speed. */ PIOS_SPI_SetClockSpeed(dev->spi_id, PIOS_SPI_PRESCALER_256); /* Enable chip select */ PIOS_SPI_RC_PinSet(dev->spi_id, dev->slave_num, 0); /* Reset FIFO. */ if (PIOS_SPI_TransferByte(dev->spi_id, 0x7f & PIOS_MPU6000_USER_CTRL_REG) != 0) { result = -2; } else if (PIOS_SPI_TransferByte(dev->spi_id, (dev->cfg->User_ctl | PIOS_MPU6000_USERCTL_FIFO_RST)) != 0) { result = -2; } /* Disable chip select. */ PIOS_SPI_RC_PinSet(dev->spi_id, dev->slave_num, 1); /* Increase SPI clock speed. */ PIOS_SPI_SetClockSpeed(dev->spi_id, PIOS_SPI_PRESCALER_16); /* Release the SPI bus semaphore. */ PIOS_SPI_ReleaseBusISR(dev->spi_id, woken); return result; }
/** * @brief Release the SPI bus for the accel communications and end the transaction * @return 0 if successful * @param woken[in,out] If non-NULL, will be set to true if woken was false and a higher priority * task has is now eligible to run, else unchanged */ static int32_t PIOS_MPU6000_ReleaseBusISR(bool *woken) { if (PIOS_MPU6000_Validate(dev) != 0) { return -1; } PIOS_SPI_RC_PinSet(dev->spi_id, dev->slave_num, 1); return PIOS_SPI_ReleaseBusISR(dev->spi_id, woken); }
/** * @brief Release the SPI bus for the accel communications and end the transaction * \param[in] pointer which receives if a task has been woken * @return 0 if successful */ int32_t PIOS_BMA180_ReleaseBusISR(bool *woken) { if(PIOS_BMA180_Validate(dev) != 0) return -1; PIOS_SPI_RC_PinSet(dev->spi_id,dev->slave_num,1); return PIOS_SPI_ReleaseBusISR(dev->spi_id, woken); }
/** * @brief Release the SPI bus for the accel communications and end the transaction * \param[in] pointer which receives if a task has been woken * @return 0 if successful, -1 for invalid device */ static int32_t PIOS_L3GD20_ReleaseBusIsr(bool *woken) { if (PIOS_L3GD20_Validate(pios_l3gd20_dev) != 0) return -1; PIOS_SPI_RC_PinSet(pios_l3gd20_dev->spi_id, pios_l3gd20_dev->slave_num, 1); return PIOS_SPI_ReleaseBusISR(pios_l3gd20_dev->spi_id, woken); }