/** * @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 Claim the SPI bus for the accel communications and select this chip * @return 0 if successful, -1 for invalid device, -2 if unable to claim bus * @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_ClaimBusISR(bool *woken) { if (PIOS_MPU6000_Validate(dev) != 0) { return -1; } if (PIOS_SPI_ClaimBusISR(dev->spi_id, woken) != 0) { return -2; } PIOS_SPI_RC_PinSet(dev->spi_id, dev->slave_num, 0); return 0; }
/** * @brief Claim the SPI bus for the accel communications and select this chip * \param[in] pointer which receives if a task has been woken * @return 0 if successful, -1 for invalid device, -2 if unable to claim bus */ static int32_t PIOS_MPU6000_ClaimBusISR(bool *woken) { if (PIOS_MPU6000_Validate(pios_mpu6000_dev) != 0) return -1; if (PIOS_SPI_ClaimBusISR(pios_mpu6000_dev->spi_id, woken) != 0) return -2; PIOS_SPI_RC_PinSet(pios_mpu6000_dev->spi_id, pios_mpu6000_dev->slave_num, 0); return 0; }
/** * @brief Claim the SPI bus for the accel communications and select this chip * \param[in] pointer which receives if a task has been woken * @return 0 if successful, -1 for invalid device, -2 if unable to claim bus */ static int32_t PIOS_L3GD20_ClaimBusIsr(bool *woken) { if(PIOS_L3GD20_Validate(dev) != 0) return -1; if(PIOS_SPI_ClaimBusISR(dev->spi_id, woken) < 0) return -2; PIOS_SPI_RC_PinSet(dev->spi_id,dev->slave_num,0); return 0; }
/** * @brief Claim the SPI bus for the accel communications and select this chip * \param[in] pointer which receives if a task has been woken * @return 0 if successful, -1 if unable to claim bus */ int32_t PIOS_BMA180_ClaimBusISR(bool *woken) { if(PIOS_BMA180_Validate(dev) != 0) return -1; if(PIOS_SPI_ClaimBusISR(dev->spi_id, woken) != 0) { return -1; } PIOS_SPI_RC_PinSet(dev->spi_id,dev->slave_num,0); return 0; }