Commit e69b1f86 authored by TMRh20's avatar TMRh20

RPi Interrupts w/SPIDEV Bugfix: Enable mutex lock

It seems mutex locking is still required when using SPIDEV. Errors only
become apparent with very heavy radio traffic (HARDWARE FAIL: RADIO NOT
RESPONDING )
parent 3e15a1ad
......@@ -10,6 +10,9 @@
#include "spi.h"
#include <pthread.h>
static pthread_mutex_t spiMutex;
SPI::SPI() {
}
......@@ -110,6 +113,7 @@ void SPI::init()
uint8_t SPI::transfer(uint8_t tx_)
{
pthread_mutex_lock (&spiMutex);
int ret;
uint8_t tx[1] = {tx_};
uint8_t rx[1];
......@@ -143,10 +147,12 @@ uint8_t SPI::transfer(uint8_t tx_)
ret = ioctl(this->fd, SPI_IOC_MESSAGE(1), &tr);
if (ret < 1)
{
pthread_mutex_unlock (&spiMutex);
perror("can't send spi message");
abort();
}
pthread_mutex_unlock (&spiMutex);
return rx[0];
}
......@@ -154,6 +160,7 @@ uint8_t SPI::transfer(uint8_t tx_)
void SPI::transfernb(char* tbuf, char* rbuf, uint32_t len)
{
pthread_mutex_lock (&spiMutex);
int ret;
this->init();
struct spi_ioc_transfer tr = {
......@@ -184,10 +191,11 @@ void SPI::transfernb(char* tbuf, char* rbuf, uint32_t len)
ret = ioctl(this->fd, SPI_IOC_MESSAGE(1), &tr);
if (ret < 1)
{
pthread_mutex_unlock (&spiMutex);
perror("can't send spi message");
abort();
}
pthread_mutex_unlock (&spiMutex);
//return rx[0];
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment