mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-06 03:50:13 +02:00
Modify library with BE specific tweaks
This commit is contained in:
parent
297c56b289
commit
43fdb4a2f3
7 changed files with 64 additions and 104 deletions
|
@ -5,7 +5,8 @@
|
|||
//
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include <ACAN2517FD.h>
|
||||
#include "ACAN2517FD.h"
|
||||
#include "../../system_settings.h" //Contains task priority //Modded by Battery-Emulator
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
@ -173,6 +174,29 @@ static uint16_t u16FromBufferAtIndex (uint8_t ioBuffer [], const uint8_t inIndex
|
|||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
static inline void turnOffInterrupts () {
|
||||
#ifndef DISABLEMCP2517FDCOMPAT
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
taskDISABLE_INTERRUPTS () ;
|
||||
#else
|
||||
noInterrupts () ;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
static inline void turnOnInterrupts() {
|
||||
#ifndef DISABLEMCP2517FDCOMPAT
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
taskENABLE_INTERRUPTS () ;
|
||||
#else
|
||||
interrupts () ;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
ACAN2517FD::ACAN2517FD (const uint8_t inCS, // CS input of MCP2517FD
|
||||
SPIClass & inSPI, // Hardware SPI object
|
||||
|
@ -502,7 +526,7 @@ uint32_t ACAN2517FD::begin (const ACAN2517FDSettings & inSettings,
|
|||
}
|
||||
}
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
xTaskCreate (myESP32Task, "ACAN2517Handler", 1024, this, 16, &mESP32TaskHandle) ;
|
||||
xTaskCreate (myESP32Task, "ACAN2517Handler", 1024, this, TASK_ACAN2517FD_PRIORITY, &mESP32TaskHandle) ; //Modded by Battery-Emulator
|
||||
#endif
|
||||
if (mINT != 255) { // 255 means interrupt is not used
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
|
@ -527,11 +551,7 @@ uint32_t ACAN2517FD::begin (const ACAN2517FDSettings & inSettings,
|
|||
|
||||
bool ACAN2517FD::end (void) {
|
||||
mSPI.beginTransaction (mSPISettings) ;
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
taskDISABLE_INTERRUPTS () ;
|
||||
#else
|
||||
noInterrupts () ;
|
||||
#endif
|
||||
turnOffInterrupts () ;
|
||||
//--- Detach interrupt pin
|
||||
if (mINT != 255) { // 255 means interrupt is not used
|
||||
const int8_t itPin = digitalPinToInterrupt (mINT) ;
|
||||
|
@ -566,11 +586,7 @@ bool ACAN2517FD::end (void) {
|
|||
mDriverReceiveBuffer.initWithSize (0) ;
|
||||
mDriverTransmitBuffer.initWithSize (0) ;
|
||||
//---
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
taskENABLE_INTERRUPTS () ;
|
||||
#else
|
||||
interrupts () ;
|
||||
#endif
|
||||
turnOnInterrupts () ;
|
||||
mSPI.endTransaction () ;
|
||||
//---
|
||||
return ok ;
|
||||
|
@ -600,11 +616,7 @@ bool ACAN2517FD::tryToSend (const CANFDMessage & inMessage) {
|
|||
ok = sendViaTXQ (inMessage) ;
|
||||
}
|
||||
}
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
taskENABLE_INTERRUPTS () ;
|
||||
#else
|
||||
interrupts () ;
|
||||
#endif
|
||||
turnOnInterrupts () ;
|
||||
mSPI.endTransaction () ;
|
||||
}
|
||||
return ok ;
|
||||
|
@ -771,17 +783,9 @@ bool ACAN2517FD::sendViaTXQ (const CANFDMessage & inMessage) {
|
|||
|
||||
bool ACAN2517FD::available (void) {
|
||||
mSPI.beginTransaction (mSPISettings) ;
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
taskDISABLE_INTERRUPTS () ;
|
||||
#else
|
||||
noInterrupts () ;
|
||||
#endif
|
||||
turnOffInterrupts () ;
|
||||
const bool hasReceivedMessage = mDriverReceiveBuffer.count () > 0 ;
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
taskENABLE_INTERRUPTS () ;
|
||||
#else
|
||||
interrupts () ;
|
||||
#endif
|
||||
turnOnInterrupts () ;
|
||||
mSPI.endTransaction () ;
|
||||
return hasReceivedMessage ;
|
||||
}
|
||||
|
@ -808,11 +812,7 @@ bool ACAN2517FD::receive (CANFDMessage & outMessage) {
|
|||
data8 |= (1 << 1) ; // Receive FIFO Interrupt Enable
|
||||
writeRegister8Assume_SPI_transaction (INT_REGISTER + 2, data8) ;
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
taskENABLE_INTERRUPTS () ;
|
||||
#else
|
||||
interrupts () ;
|
||||
#endif
|
||||
turnOnInterrupts () ;
|
||||
mSPI.endTransaction () ;
|
||||
}
|
||||
return hasReceivedMessage ;
|
||||
|
@ -929,9 +929,7 @@ void ACAN2517FD::isr_poll_core (void) {
|
|||
writeRegister8Assume_SPI_transaction (FIFOSTA_REGISTER (RECEIVE_FIFO_INDEX), ~ (1 << 3)) ;
|
||||
}
|
||||
}
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
taskENABLE_INTERRUPTS () ;
|
||||
#endif
|
||||
turnOnInterrupts () ;
|
||||
mSPI.endTransaction () ;
|
||||
}
|
||||
|
||||
|
@ -1102,17 +1100,9 @@ uint8_t ACAN2517FD::readRegister8Assume_SPI_transaction (const uint16_t inRegist
|
|||
|
||||
void ACAN2517FD::writeRegister8 (const uint16_t inRegisterAddress, const uint8_t inValue) {
|
||||
mSPI.beginTransaction (mSPISettings) ;
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
taskDISABLE_INTERRUPTS () ;
|
||||
#else
|
||||
noInterrupts () ;
|
||||
#endif
|
||||
turnOffInterrupts () ;
|
||||
writeRegister8Assume_SPI_transaction (inRegisterAddress, inValue) ;
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
taskENABLE_INTERRUPTS () ;
|
||||
#else
|
||||
interrupts () ;
|
||||
#endif
|
||||
turnOnInterrupts () ;
|
||||
mSPI.endTransaction () ;
|
||||
}
|
||||
|
||||
|
@ -1120,17 +1110,9 @@ void ACAN2517FD::writeRegister8 (const uint16_t inRegisterAddress, const uint8_t
|
|||
|
||||
uint8_t ACAN2517FD::readRegister8 (const uint16_t inRegisterAddress) {
|
||||
mSPI.beginTransaction (mSPISettings) ;
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
taskDISABLE_INTERRUPTS () ;
|
||||
#else
|
||||
noInterrupts () ;
|
||||
#endif
|
||||
turnOffInterrupts () ;
|
||||
const uint8_t result = readRegister8Assume_SPI_transaction (inRegisterAddress) ;
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
taskENABLE_INTERRUPTS () ;
|
||||
#else
|
||||
interrupts () ;
|
||||
#endif
|
||||
turnOnInterrupts () ;
|
||||
mSPI.endTransaction () ;
|
||||
return result ;
|
||||
}
|
||||
|
@ -1139,17 +1121,9 @@ uint8_t ACAN2517FD::readRegister8 (const uint16_t inRegisterAddress) {
|
|||
|
||||
uint16_t ACAN2517FD::readRegister16 (const uint16_t inRegisterAddress) {
|
||||
mSPI.beginTransaction (mSPISettings) ;
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
taskDISABLE_INTERRUPTS () ;
|
||||
#else
|
||||
noInterrupts () ;
|
||||
#endif
|
||||
turnOffInterrupts () ;
|
||||
const uint16_t result = readRegister16Assume_SPI_transaction (inRegisterAddress) ;
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
taskENABLE_INTERRUPTS () ;
|
||||
#else
|
||||
interrupts () ;
|
||||
#endif
|
||||
turnOnInterrupts () ;
|
||||
mSPI.endTransaction () ;
|
||||
return result ;
|
||||
}
|
||||
|
@ -1158,17 +1132,9 @@ uint16_t ACAN2517FD::readRegister16 (const uint16_t inRegisterAddress) {
|
|||
|
||||
void ACAN2517FD::writeRegister32 (const uint16_t inRegisterAddress, const uint32_t inValue) {
|
||||
mSPI.beginTransaction (mSPISettings) ;
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
taskDISABLE_INTERRUPTS () ;
|
||||
#else
|
||||
noInterrupts () ;
|
||||
#endif
|
||||
turnOffInterrupts () ;
|
||||
writeRegister32Assume_SPI_transaction (inRegisterAddress, inValue) ;
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
taskENABLE_INTERRUPTS () ;
|
||||
#else
|
||||
interrupts () ;
|
||||
#endif
|
||||
turnOnInterrupts () ;
|
||||
mSPI.endTransaction () ;
|
||||
}
|
||||
|
||||
|
@ -1176,17 +1142,9 @@ void ACAN2517FD::writeRegister32 (const uint16_t inRegisterAddress, const uint32
|
|||
|
||||
uint32_t ACAN2517FD::readRegister32 (const uint16_t inRegisterAddress) {
|
||||
mSPI.beginTransaction (mSPISettings) ;
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
taskDISABLE_INTERRUPTS () ;
|
||||
#else
|
||||
noInterrupts () ;
|
||||
#endif
|
||||
turnOffInterrupts () ;
|
||||
const uint32_t result = readRegister32Assume_SPI_transaction (inRegisterAddress) ;
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
taskENABLE_INTERRUPTS () ;
|
||||
#else
|
||||
interrupts () ;
|
||||
#endif
|
||||
turnOnInterrupts () ;
|
||||
mSPI.endTransaction () ;
|
||||
return result ;
|
||||
}
|
||||
|
@ -1238,19 +1196,11 @@ void ACAN2517FD::setOperationMode (const ACAN2517FDSettings::OperationMode inOpe
|
|||
|
||||
void ACAN2517FD::reset2517FD (void) {
|
||||
mSPI.beginTransaction (mSPISettings) ; // Check RESET is performed with 800 kHz clock
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
taskDISABLE_INTERRUPTS () ;
|
||||
#else
|
||||
noInterrupts () ;
|
||||
#endif
|
||||
turnOffInterrupts () ;
|
||||
assertCS () ;
|
||||
mSPI.transfer16 (0x00) ; // Reset instruction: 0x0000
|
||||
deassertCS () ;
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
taskENABLE_INTERRUPTS () ;
|
||||
#else
|
||||
interrupts () ;
|
||||
#endif
|
||||
turnOnInterrupts () ;
|
||||
mSPI.endTransaction () ;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,12 +8,22 @@
|
|||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include <ACAN2517FDSettings.h>
|
||||
#include <ACAN2517FD_ACANFDBuffer.h>
|
||||
#include <ACAN2517FD_CANMessage.h>
|
||||
#include <ACAN2517FDFilters.h>
|
||||
#include "ACAN2517FDSettings.h"
|
||||
#include "ACAN2517FD_ACANFDBuffer.h"
|
||||
#include "ACAN2517FD_CANMessage.h"
|
||||
#include "ACAN2517FDFilters.h"
|
||||
#include <SPI.h>
|
||||
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
// Settings
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Enable this if you want to disable the MCP2517FD compatability mode. This can slightly increase performance when
|
||||
// running on the MCP2518FD but you risk hitting issues mentioned in the MCP2517FD errata-sheet when using this option
|
||||
// on the MCP2517FD.
|
||||
//
|
||||
#define DISABLEMCP2517FDCOMPAT
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// ACAN2517FD class
|
||||
//------------------------------------------------------------------------------
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include <ACAN2517FD_CANFDMessage.h>
|
||||
#include "ACAN2517FD_CANFDMessage.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// ACAN2517FDFilters class
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
//
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include <ACAN2517FDSettings.h>
|
||||
#include "ACAN2517FDSettings.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include <ACAN2517FD_DataBitRateFactor.h>
|
||||
#include "ACAN2517FD_DataBitRateFactor.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// ACAN2517FDSettings class
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include <ACAN2517FD_CANFDMessage.h>
|
||||
#include "ACAN2517FD_CANFDMessage.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#include <ACAN2517FD_CANMessage.h>
|
||||
#include "ACAN2517FD_CANMessage.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// CANFDMessage class
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue