mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-03 16:58:54 +08:00
Just the changes required to avoid SPI bus conflicts for MS5611
This commit is contained in:
@@ -103,6 +103,14 @@ private:
|
||||
* @param reg The register to read.
|
||||
*/
|
||||
uint16_t _reg16(unsigned reg);
|
||||
|
||||
/**
|
||||
* Wrapper around transfer() that prevents interrupt-context transfers
|
||||
* from pre-empting us. The sensor may (does) share a bus with sensors
|
||||
* that are polled from interrupt context (or we may be pre-empted)
|
||||
* so we need to guarantee that transfers complete without interruption.
|
||||
*/
|
||||
int _transfer(uint8_t *send, uint8_t *recv, unsigned len);
|
||||
};
|
||||
|
||||
device::Device *
|
||||
@@ -161,7 +169,7 @@ MS5611_SPI::read(unsigned offset, void *data, unsigned count)
|
||||
|
||||
/* read the most recent measurement */
|
||||
buf[0] = 0 | DIR_WRITE;
|
||||
int ret = transfer(&buf[0], &buf[0], sizeof(buf));
|
||||
int ret = _transfer(&buf[0], &buf[0], sizeof(buf));
|
||||
|
||||
if (ret == OK) {
|
||||
/* fetch the raw value */
|
||||
@@ -206,7 +214,7 @@ MS5611_SPI::_reset()
|
||||
{
|
||||
uint8_t cmd = ADDR_RESET_CMD | DIR_WRITE;
|
||||
|
||||
return transfer(&cmd, nullptr, 1);
|
||||
return _transfer(&cmd, nullptr, 1);
|
||||
}
|
||||
|
||||
int
|
||||
@@ -214,7 +222,7 @@ MS5611_SPI::_measure(unsigned addr)
|
||||
{
|
||||
uint8_t cmd = addr | DIR_WRITE;
|
||||
|
||||
return transfer(&cmd, nullptr, 1);
|
||||
return _transfer(&cmd, nullptr, 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -244,9 +252,21 @@ MS5611_SPI::_reg16(unsigned reg)
|
||||
|
||||
cmd[0] = reg | DIR_READ;
|
||||
|
||||
transfer(cmd, cmd, sizeof(cmd));
|
||||
_transfer(cmd, cmd, sizeof(cmd));
|
||||
|
||||
return (uint16_t)(cmd[1] << 8) | cmd[2];
|
||||
}
|
||||
|
||||
int
|
||||
MS5611_SPI::_transfer(uint8_t *send, uint8_t *recv, unsigned len)
|
||||
{
|
||||
irqstate_t flags = irqsave();
|
||||
|
||||
int ret = transfer(send, recv, len);
|
||||
|
||||
irqrestore(flags);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* PX4_SPIDEV_BARO */
|
||||
|
||||
Reference in New Issue
Block a user