Merge pull request #556 from tekka007/RF24IRQ
Reorganize RX message buffering checks
This commit is contained in:
+9
-6
@@ -430,16 +430,18 @@
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def MY_RF24_IRQ_PIN
|
||||
* @brief Disable RF24 interrupt pin usage by default. Override in sketch if needed.
|
||||
*/
|
||||
//#define MY_RF24_IRQ_PIN
|
||||
* @def MY_RX_MESSAGE_BUFFER_FEATURE
|
||||
* @brief This enabled the receiving buffer feature.
|
||||
*
|
||||
* This feature is currently not supported for RFM69 and RS485, for RF24 MY_RF24_IRQ_PIN has to be defined.
|
||||
*/
|
||||
//#define MY_RX_MESSAGE_BUFFER_FEATURE
|
||||
|
||||
/**
|
||||
* @def MY_RX_MESSAGE_BUFFER_SIZE
|
||||
* @brief Declare the amount of incoming messages that can be buffered. Requires MY_RADIO_NRF24 and MY_RF24_IRQ_PIN. Override in sketch if needed.
|
||||
* @brief Declare the amount of incoming messages that can be buffered.
|
||||
*/
|
||||
#ifdef MY_RF24_IRQ_PIN
|
||||
#ifdef MY_RX_MESSAGE_BUFFER_FEATURE
|
||||
#ifndef MY_RX_MESSAGE_BUFFER_SIZE
|
||||
#define MY_RX_MESSAGE_BUFFER_SIZE (20)
|
||||
#endif
|
||||
@@ -711,6 +713,7 @@
|
||||
#define MY_DEBUG_VERBOSE_RF24
|
||||
#define MY_TRANSPORT_SANITY_CHECK
|
||||
#define MY_RF24_IRQ_PIN
|
||||
#define MY_RX_MESSAGE_BUFFER_FEATURE
|
||||
#define MY_RX_MESSAGE_BUFFER_SIZE
|
||||
#define MY_NODE_LOCK_FEATURE
|
||||
#endif
|
||||
|
||||
-17
@@ -255,23 +255,6 @@
|
||||
#error Only one forward link driver can be activated
|
||||
#endif
|
||||
#if defined(MY_RADIO_NRF24)
|
||||
#ifdef MY_RF24_IRQ_PIN
|
||||
// SoftSPI does not support usingInterrupt()
|
||||
#ifdef MY_SOFTSPI
|
||||
#error RF24 IRQ usage cannot be used with Soft SPI
|
||||
#endif
|
||||
// ESP8266 does not support usingInterrupt()
|
||||
#ifdef ESP8266
|
||||
#error RF24 IRQ usage cannot be used with ESP8266
|
||||
#endif
|
||||
#ifndef SPI_HAS_TRANSACTION
|
||||
#error RF24 IRQ usage requires transactional SPI support
|
||||
#endif
|
||||
#else
|
||||
#ifdef MY_RX_MESSAGE_BUFFER_SIZE
|
||||
#error Receive message buffering requires RF24 IRQ usage
|
||||
#endif
|
||||
#endif
|
||||
#if defined(MY_RF24_ENABLE_ENCRYPTION)
|
||||
#include "drivers/AES/AES.cpp"
|
||||
#endif
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
* - MCO:<b>REG</b> from @ref _registerNode()
|
||||
* - MCO:<b>SND</b> from @ref send()
|
||||
* - MCO:<b>PIM</b> from @ref _processInternalMessages()
|
||||
* - MCO:<b>NLK</b> from @ref nodeLock()
|
||||
* - MCO:<b>NLK</b> from nodeLock()
|
||||
*
|
||||
* MySensorsCore debug log messages:
|
||||
*
|
||||
|
||||
@@ -147,6 +147,18 @@
|
||||
#else
|
||||
#define TRANSMISSION_FAILURES 5 //!< search for a new parent node after this many transmission failures, lower threshold for non-repeating nodes
|
||||
#endif
|
||||
|
||||
#if defined(MY_RX_MESSAGE_BUFFER_FEATURE)
|
||||
#if defined(MY_RADIO_RFM69)
|
||||
#error Receive message buffering not supported for RFM69!
|
||||
#endif
|
||||
#if defined(MY_RS485)
|
||||
#error Receive message buffering not supported for RS485!
|
||||
#endif
|
||||
#elif !defined(MY_RX_MESSAGE_BUFFER_FEATURE) && defined(MY_RX_MESSAGE_BUFFER_SIZE)
|
||||
#error Receive message buffering requires message buffering feature enabled!
|
||||
#endif
|
||||
|
||||
#define TIMEOUT_FAILURE_STATE 10000 //!< duration failure state
|
||||
#define STATE_TIMEOUT 2000 //!< general state timeout
|
||||
#define STATE_RETRIES 3 //!< retries before switching to FAILURE
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#include "drivers/AES/AES.h"
|
||||
#endif
|
||||
|
||||
#ifdef MY_RF24_IRQ_PIN
|
||||
#if defined(MY_RX_MESSAGE_BUFFER_FEATURE)
|
||||
typedef struct _transportQueuedMessage
|
||||
{
|
||||
uint8_t m_len; // Length of the data
|
||||
@@ -76,7 +76,7 @@ bool transportInit() {
|
||||
memset(_psk, 0, 16);
|
||||
#endif
|
||||
|
||||
#ifdef MY_RF24_IRQ_PIN
|
||||
#if defined(MY_RX_MESSAGE_BUFFER_FEATURE)
|
||||
RF24_registerReceiveCallback( transportRxCallback );
|
||||
#endif
|
||||
return RF24_initialize();
|
||||
@@ -109,7 +109,7 @@ bool transportSend(uint8_t recipient, const void* data, uint8_t len) {
|
||||
}
|
||||
|
||||
bool transportAvailable() {
|
||||
#ifdef MY_RF24_IRQ_PIN
|
||||
#if defined(MY_RX_MESSAGE_BUFFER_FEATURE)
|
||||
(void)RF24_isDataAvailable; // Prevent 'defined but not used' warning
|
||||
return !transportRxQueue.empty();
|
||||
#else
|
||||
@@ -123,10 +123,9 @@ bool transportSanityCheck() {
|
||||
|
||||
uint8_t transportReceive(void* data) {
|
||||
uint8_t len = 0;
|
||||
#ifdef MY_RF24_IRQ_PIN
|
||||
#if defined(MY_RX_MESSAGE_BUFFER_FEATURE)
|
||||
transportQueuedMessage* msg = transportRxQueue.getBack();
|
||||
if (msg)
|
||||
{
|
||||
if (msg) {
|
||||
len = msg->m_len;
|
||||
(void)memcpy(data, msg->m_data, len);
|
||||
(void)transportRxQueue.popBack();
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
LOCAL uint8_t MY_RF24_BASE_ADDR[MY_RF24_ADDR_WIDTH] = { MY_RF24_BASE_RADIO_ID };
|
||||
LOCAL uint8_t MY_RF24_NODE_ADDRESS = AUTO;
|
||||
|
||||
#ifdef MY_RF24_IRQ_PIN
|
||||
#if defined(MY_RX_MESSAGE_BUFFER_FEATURE)
|
||||
LOCAL RF24_receiveCallbackType RF24_receiveCallback = NULL;
|
||||
#endif
|
||||
|
||||
@@ -261,7 +261,7 @@ LOCAL bool RF24_sanityCheck(void) {
|
||||
return status;
|
||||
}
|
||||
|
||||
#ifdef MY_RF24_IRQ_PIN
|
||||
#if defined(MY_RX_MESSAGE_BUFFER_FEATURE)
|
||||
LOCAL void RF24_irqHandler( void )
|
||||
{
|
||||
if (RF24_receiveCallback)
|
||||
@@ -307,14 +307,14 @@ LOCAL bool RF24_initialize(void) {
|
||||
// Initialize pins
|
||||
pinMode(MY_RF24_CE_PIN,OUTPUT);
|
||||
pinMode(MY_RF24_CS_PIN,OUTPUT);
|
||||
#ifdef MY_RF24_IRQ_PIN
|
||||
#if defined(MY_RX_MESSAGE_BUFFER_FEATURE)
|
||||
pinMode(MY_RF24_IRQ_PIN,INPUT);
|
||||
#endif
|
||||
// Initialize SPI
|
||||
_SPI.begin();
|
||||
RF24_ce(LOW);
|
||||
RF24_csn(HIGH);
|
||||
#ifdef MY_RF24_IRQ_PIN
|
||||
#if defined(MY_RX_MESSAGE_BUFFER_FEATURE)
|
||||
// assure SPI can be used from interrupt context
|
||||
// Note: ESP8266 & SoftSPI currently do not support interrupt usage for SPI,
|
||||
// therefore it is unsafe to use MY_RF24_IRQ_PIN with ESP8266/SoftSPI!
|
||||
|
||||
+25
-5
@@ -36,9 +36,6 @@
|
||||
#if defined (ARDUINO) && !defined (__arm__) && !defined (_SPI)
|
||||
#if defined(MY_SOFTSPI)
|
||||
SoftSPI<MY_SOFT_SPI_MISO_PIN, MY_SOFT_SPI_MOSI_PIN, MY_SOFT_SPI_SCK_PIN, MY_RF24_SPI_DATA_MODE> _SPI;
|
||||
#elif defined(ARDUINO_ARCH_SAMD)
|
||||
#include <SPI.h>
|
||||
#define _SPI SPI1
|
||||
#else
|
||||
#include <SPI.h>
|
||||
#define _SPI SPI
|
||||
@@ -61,8 +58,31 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// verify RF24 IRQ defs
|
||||
#if defined(MY_RX_MESSAGE_BUFFER_FEATURE)
|
||||
#if !defined(MY_RF24_IRQ_PIN)
|
||||
#error Message buffering feature requires MY_RF24_IRQ_PIN to be defined!
|
||||
#endif
|
||||
// SoftSPI does not support usingInterrupt()
|
||||
#ifdef MY_SOFTSPI
|
||||
#error RF24 IRQ usage cannot be used with Soft SPI
|
||||
#endif
|
||||
// ESP8266 does not support usingInterrupt()
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
#error RF24 IRQ usage cannot be used with ESP8266
|
||||
#endif
|
||||
#ifndef SPI_HAS_TRANSACTION
|
||||
#error RF24 IRQ usage requires transactional SPI support
|
||||
#endif
|
||||
#else
|
||||
#ifdef MY_RX_MESSAGE_BUFFER_SIZE
|
||||
#error Receive message buffering requires RF24 IRQ usage
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
// RF24 settings
|
||||
#ifdef MY_RF24_IRQ_PIN
|
||||
#if defined(MY_RX_MESSAGE_BUFFER_FEATURE)
|
||||
#define MY_RF24_CONFIGURATION (uint8_t) ((RF24_CRC_16 << 2) | (1 << MASK_TX_DS) | (1 << MASK_MAX_RT))
|
||||
#else
|
||||
#define MY_RF24_CONFIGURATION (uint8_t) (RF24_CRC_16 << 2)
|
||||
@@ -253,7 +273,7 @@ LOCAL void RF24_setPipeLSB(uint8_t pipe, uint8_t LSB);
|
||||
LOCAL void RF24_setStatus(uint8_t status);
|
||||
LOCAL void RF24_enableFeatures(void);
|
||||
|
||||
#ifdef MY_RF24_IRQ_PIN
|
||||
#if defined(MY_RX_MESSAGE_BUFFER_FEATURE)
|
||||
typedef void (*RF24_receiveCallbackType)(void);
|
||||
/**
|
||||
* Register a callback, which will be called (from interrupt context) for every message received.
|
||||
|
||||
@@ -74,6 +74,7 @@ MY_RF24_SPI_MAX_SPEED LITERAL1
|
||||
MY_RF24_CE_PIN LITERAL1
|
||||
MY_RF24_CS_PIN LITERAL1
|
||||
MY_RF24_IRQ_PIN LITERAL1
|
||||
MY_RX_MESSAGE_BUFFER_FEATURE LITERAL1
|
||||
MY_RF24_PA_LEVEL LITERAL1
|
||||
MY_RF24_CHANNEL LITERAL1
|
||||
MY_RF24_DATARATE LITERAL1
|
||||
|
||||
Reference in New Issue
Block a user