Skip to content

Commit e80b166

Browse files
committed
[HAL] Modified SPI to use shared mutex
Modified the SPI class to use a shared mutex for all instances. This is consistent with I2C and others.
1 parent 36468c9 commit e80b166

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
@@ -21,6 +21,7 @@
2121
#if DEVICE_SPI
2222

2323
#include "spi_api.h"
24+
#include "SingletonPtr.h"
2425

2526
#if DEVICE_SPI_ASYNCH
2627
#include "CThunk.h"
@@ -246,7 +247,7 @@ class SPI {
246247

247248
void aquire(void);
248249
static SPI *_owner;
249-
PlatformMutex _mutex;
250+
static SingletonPtr<PlatformMutex> _mutex;
250251
int _bits;
251252
int _mode;
252253
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)