Skip to content
Permalink
Browse files

Fixes in SPIDEV driver for NanoPi NEO2 / NEO Plus2 based on Allwinner…

…’s H5 CPU
  • Loading branch information...
sashok1337 committed Jan 12, 2018
1 parent d14ff47 commit a1c5514e7721bbdfea188a1b735a37f5964df559
Showing with 45 additions and 19 deletions.
  1. +2 −2 RF24.cpp
  2. +33 −10 utility/SPIDEV/compatibility.c
  3. +3 −2 utility/SPIDEV/compatibility.h
  4. +5 −3 utility/SPIDEV/spi.cpp
  5. +2 −2 utility/SPIDEV/spi.h
@@ -814,12 +814,12 @@ bool RF24::write( const void* buf, uint8_t len, const bool multicast )

//Wait until complete or failed
#if defined (FAILURE_HANDLING) || defined (RF24_LINUX)
uint32_t timer = millis();
unsigned long timer = millis();
#endif

while( ! ( get_status() & ( _BV(TX_DS) | _BV(MAX_RT) ))) {
#if defined (FAILURE_HANDLING) || defined (RF24_LINUX)
if(millis() - timer > 95){
if((millis() - timer) > 95){
errNotify();
#if defined (FAILURE_HANDLING)
return 0;
@@ -10,20 +10,43 @@ static struct timeval start, end;
* This function is added in order to simulate arduino delay() function
* @param milisec
*/
void __msleep(int milisec)
void __msleep(unsigned int howLong)
{
struct timespec req = {0};
req.tv_sec = 0;
req.tv_nsec = milisec * 1000000L;
nanosleep(&req, (struct timespec *)NULL);
struct timespec sleeper, dummy;

sleeper.tv_sec = (time_t) (howLong / 1000);
sleeper.tv_nsec = (long) (howLong % 1000) * 1000000;

nanosleep(&sleeper, &dummy);
}

void __usleep(int milisec)
void delayMicrosecondsHard(unsigned int howLong) {
struct timeval tNow, tLong, tEnd;

gettimeofday(&tNow, NULL);
tLong.tv_sec = howLong / 1000000;
tLong.tv_usec = howLong % 1000000;
timeradd(&tNow, &tLong, &tEnd);

while (timercmp(&tNow, &tEnd, <))
gettimeofday(&tNow, NULL);
}

void __usleep(unsigned int howLong)
{
struct timespec req = {0};
req.tv_sec = 0;
req.tv_nsec = milisec * 1000L;
nanosleep(&req, (struct timespec *)NULL);
struct timespec sleeper;
unsigned int uSecs = howLong % 1000000;
unsigned int wSecs = howLong / 1000000;

if (howLong == 0)
return;
else if (howLong < 100)
delayMicrosecondsHard(howLong);
else {
sleeper.tv_sec = wSecs;
sleeper.tv_nsec = (long) (uSecs * 1000L);
nanosleep(&sleeper, NULL);
}
}

/**
@@ -16,8 +16,9 @@ extern "C" {
#include <time.h>
#include <sys/time.h>

void __msleep(int milisec);
void __usleep(int milisec);
void __msleep(unsigned int howLong);
void delayMicrosecondsHard(unsigned int howLong);
void __usleep(unsigned int howLong);
void __start_timer();
long __millis();

@@ -30,9 +30,11 @@ void SPI::begin(int busNo){
*
* a bit messy but simple
* */
char device[] = "/dev/spidev0.0";
device[11] += (busNo / 10) % 10;
device[13] += busNo % 10;
char device[] = "/dev/spidev0.0";

/* We have only one variant on H5 core */
//device[11] += (busNo / 10) % 10;
//device[13] += busNo % 10;

if (this->fd < 0) // check whether spi is already open
{
@@ -26,8 +26,8 @@
#include <inttypes.h>

#ifndef RF24_SPIDEV_SPEED
/* 8MHz as default */
#define RF24_SPIDEV_SPEED 8000000
/* 8MHz is default, but after 6MHz my H5 jumps to 12MHz (tested by logic analyzer) and works with errors */
#define RF24_SPIDEV_SPEED 6000000
#endif

class SPI {

0 comments on commit a1c5514

Please sign in to comment.
You can’t perform that action at this time.