Skip to content

Commit ac34f29

Browse files
authored
Merge pull request #2297 from neilt6/spi-mutex-fix
[HAL] Modified SPI to use shared mutex
2 parents 9cb049f + e80b166 commit ac34f29

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

hal/api/SPI.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include "PlatformMutex.h"
2424
#include "spi_api.h"
25+
#include "SingletonPtr.h"
2526

2627
#if DEVICE_SPI_ASYNCH
2728
#include "CThunk.h"
@@ -247,7 +248,7 @@ class SPI {
247248

248249
void aquire(void);
249250
static SPI *_owner;
250-
PlatformMutex _mutex;
251+
static SingletonPtr<PlatformMutex> _mutex;
251252
int _bits;
252253
int _mode;
253254
int _hz;

hal/common/SPI.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ void SPI::frequency(int hz) {
5757
}
5858

5959
SPI* SPI::_owner = NULL;
60+
SingletonPtr<PlatformMutex> SPI::_mutex;
6061

6162
// ignore the fact there are multiple physical spis, and always update if it wasnt us last
6263
void SPI::aquire() {
@@ -78,11 +79,11 @@ int SPI::write(int value) {
7879
}
7980

8081
void SPI::lock() {
81-
_mutex.lock();
82+
_mutex->lock();
8283
}
8384

8485
void SPI::unlock() {
85-
_mutex.unlock();
86+
_mutex->unlock();
8687
}
8788

8889
#if DEVICE_SPI_ASYNCH

0 commit comments

Comments
 (0)