diff options
author | Lorenz Meier <lm@inf.ethz.ch> | 2013-09-16 13:30:49 +0200 |
---|---|---|
committer | Lorenz Meier <lm@inf.ethz.ch> | 2013-09-16 13:30:49 +0200 |
commit | 6c2640768d21e0c1898bfd8a2cd0b763a9e348c7 (patch) | |
tree | 7e0f3914beffade909b564f37cf115e01a411cee /src/drivers/device/spi.cpp | |
parent | 9e7077fdf9c62ae08c9915e752353671839b5e0b (diff) | |
parent | 489e7b2f1e8639059587c730525397e9424d4044 (diff) | |
download | px4-firmware-6c2640768d21e0c1898bfd8a2cd0b763a9e348c7.tar.gz px4-firmware-6c2640768d21e0c1898bfd8a2cd0b763a9e348c7.tar.bz2 px4-firmware-6c2640768d21e0c1898bfd8a2cd0b763a9e348c7.zip |
Merge branch 'master' of github.com:PX4/Firmware into fixedwing_l1
Diffstat (limited to 'src/drivers/device/spi.cpp')
-rw-r--r-- | src/drivers/device/spi.cpp | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/src/drivers/device/spi.cpp b/src/drivers/device/spi.cpp index 8fffd60cb..fa6b78d64 100644 --- a/src/drivers/device/spi.cpp +++ b/src/drivers/device/spi.cpp @@ -67,6 +67,7 @@ SPI::SPI(const char *name, CDev(name, devname, irq), // public // protected + locking_mode(LOCK_PREEMPTION), // private _bus(bus), _device(device), @@ -132,13 +133,25 @@ SPI::probe() int SPI::transfer(uint8_t *send, uint8_t *recv, unsigned len) { + irqstate_t state; if ((send == nullptr) && (recv == nullptr)) return -EINVAL; - /* do common setup */ - if (!up_interrupt_context()) - SPI_LOCK(_dev, true); + /* lock the bus as required */ + if (!up_interrupt_context()) { + switch (locking_mode) { + default: + case LOCK_PREEMPTION: + state = irqsave(); + break; + case LOCK_THREADS: + SPI_LOCK(_dev, true); + break; + case LOCK_NONE: + break; + } + } SPI_SETFREQUENCY(_dev, _frequency); SPI_SETMODE(_dev, _mode); @@ -151,8 +164,19 @@ SPI::transfer(uint8_t *send, uint8_t *recv, unsigned len) /* and clean up */ SPI_SELECT(_dev, _device, false); - if (!up_interrupt_context()) - SPI_LOCK(_dev, false); + if (!up_interrupt_context()) { + switch (locking_mode) { + default: + case LOCK_PREEMPTION: + irqrestore(state); + break; + case LOCK_THREADS: + SPI_LOCK(_dev, false); + break; + case LOCK_NONE: + break; + } + } return OK; } |