aditihilbert closed pull request #1298: Lora spi fix
URL: https://github.com/apache/mynewt-core/pull/1298
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/hw/drivers/lora/sx1272/include/radio/radio.h 
b/hw/drivers/lora/sx1272/include/radio/radio.h
index 2ede131836..b8ffe6fb65 100644
--- a/hw/drivers/lora/sx1272/include/radio/radio.h
+++ b/hw/drivers/lora/sx1272/include/radio/radio.h
@@ -339,31 +339,13 @@ struct Radio_s
      * \retval time Radio plus board wakeup time in ms.
      */
     uint32_t  ( *GetWakeupTime )( void );
+
     /*!
-     * \brief Process radio irq
-     */
-    void ( *IrqProcess )( void );
-    /*
-     * The next functions are available only on SX126x radios.
-     */
-    /*!
-     * \brief Sets the radio in reception mode with Max LNA gain for the given 
time
-     *
-     * \remark Available on SX126x radios only.
-     *
-     * \param [IN] timeout Reception timeout [ms]
-     *                     [0: continuous, others timeout]
-     */
-    void    ( *RxBoosted )( uint32_t timeout );
-    /*!
-     * \brief Sets the Rx duty cycle management parameters
-     *
-     * \remark Available on SX126x radios only.
+     * \brief Disables receive irq, puts chip in standby and clears any pending
+     * rx interrupts
      *
-     * \param [in]  rxTime        Structure describing reception timeout value
-     * \param [in]  sleepTime     Structure describing sleep timeout value
      */
-    void ( *SetRxDutyCycle ) ( uint32_t rxTime, uint32_t sleepTime );
+    void  ( *RxDisable )( void );
 };
 
 /*!
diff --git a/hw/drivers/lora/sx1272/src/sx1272-board.c 
b/hw/drivers/lora/sx1272/src/sx1272-board.c
index 9e587663b2..460735e96d 100644
--- a/hw/drivers/lora/sx1272/src/sx1272-board.c
+++ b/hw/drivers/lora/sx1272/src/sx1272-board.c
@@ -63,7 +63,8 @@ const struct Radio_s Radio =
     SX1272ReadBuffer,
     SX1272SetMaxPayloadLength,
     SX1272SetPublicNetwork,
-    SX1272GetWakeupTime
+    SX1272GetWakeupTime,
+    SX1272RxDisable
 };
 
 void
@@ -349,3 +350,20 @@ SX1272GetBoardTcxoWakeupTime(void)
     return 0;
 }
 
+void
+SX1272RxIoIrqDisable(void)
+{
+    hal_gpio_irq_disable(SX1272_DIO0);
+    hal_gpio_irq_disable(SX1272_DIO1);
+    hal_gpio_irq_disable(SX1272_DIO2);
+    hal_gpio_irq_disable(SX1272_DIO3);
+}
+
+void
+SX1272RxIoIrqEnable(void)
+{
+    hal_gpio_irq_enable(SX1272_DIO0);
+    hal_gpio_irq_enable(SX1272_DIO1);
+    hal_gpio_irq_enable(SX1272_DIO2);
+    hal_gpio_irq_enable(SX1272_DIO3);
+}
diff --git a/hw/drivers/lora/sx1272/src/sx1272-board.h 
b/hw/drivers/lora/sx1272/src/sx1272-board.h
index b20d86f34b..e8e9b112d3 100644
--- a/hw/drivers/lora/sx1272/src/sx1272-board.h
+++ b/hw/drivers/lora/sx1272/src/sx1272-board.h
@@ -151,6 +151,17 @@ bool SX1272CheckRfFrequency(uint32_t frequency);
  */
 uint32_t SX1272GetBoardTcxoWakeupTime( void );
 
+/*!
+ * \brief Disables all receive related IO Irqs
+ */
+void SX1272RxIoIrqDisable( void );
+
+/*!
+ * \brief Enables all receive related IO Irqs
+ */
+void SX1272RxIoIrqEnable( void );
+
+
 /*!
  * Radio hardware and global parameters
  */
diff --git a/hw/drivers/lora/sx1272/src/sx1272.c 
b/hw/drivers/lora/sx1272/src/sx1272.c
index cd6d0cb6d8..253d5dbef9 100644
--- a/hw/drivers/lora/sx1272/src/sx1272.c
+++ b/hw/drivers/lora/sx1272/src/sx1272.c
@@ -1564,3 +1564,31 @@ SX1272OnDio5Irq(void *unused)
         break;
     }
 }
+
+void
+SX1272RxDisable(void)
+{
+    if (SX1272.Settings.Modem == MODEM_LORA) {
+        /* Disable GPIO interrupts */
+        SX1272RxIoIrqDisable();
+
+        /* Disable RX interrupts */
+        SX1272Write(REG_LR_IRQFLAGSMASK, RFLR_IRQFLAGS_RXTIMEOUT_MASK       |
+                                         RFLR_IRQFLAGS_RXDONE_MASK          |
+                                         RFLR_IRQFLAGS_PAYLOADCRCERROR_MASK |
+                                         RFLR_IRQFLAGS_CADDONE_MASK         |
+                                         RFLR_IRQFLAGS_CADDETECTED_MASK);
+
+        /* Put radio into standby */
+        SX1272SetStby();
+
+        /* Clear any pending interrupts */
+        SX1272Write(REG_LR_IRQFLAGS, RFLR_IRQFLAGS_RXTIMEOUT            |
+                                     RFLR_IRQFLAGS_RXDONE               |
+                                     RFLR_IRQFLAGS_PAYLOADCRCERROR_MASK |
+                                     RFLR_IRQFLAGS_CADDONE_MASK         |
+                                     RFLR_IRQFLAGS_CADDETECTED_MASK);
+        /* Enable GPIO interrupts */
+        SX1272RxIoIrqEnable();
+    }
+}
diff --git a/hw/drivers/lora/sx1272/src/sx1272.h 
b/hw/drivers/lora/sx1272/src/sx1272.h
index af4fd5df5d..37d9e082e8 100644
--- a/hw/drivers/lora/sx1272/src/sx1272.h
+++ b/hw/drivers/lora/sx1272/src/sx1272.h
@@ -398,4 +398,6 @@ void SX1272SetPublicNetwork(bool enable);
  */
 uint32_t SX1272GetWakeupTime(void);
 
+void SX1272RxDisable(void);
+
 #endif // __SX1272_H__
diff --git a/hw/drivers/lora/sx1276/include/radio/radio.h 
b/hw/drivers/lora/sx1276/include/radio/radio.h
index 2ede131836..b8ffe6fb65 100644
--- a/hw/drivers/lora/sx1276/include/radio/radio.h
+++ b/hw/drivers/lora/sx1276/include/radio/radio.h
@@ -339,31 +339,13 @@ struct Radio_s
      * \retval time Radio plus board wakeup time in ms.
      */
     uint32_t  ( *GetWakeupTime )( void );
+
     /*!
-     * \brief Process radio irq
-     */
-    void ( *IrqProcess )( void );
-    /*
-     * The next functions are available only on SX126x radios.
-     */
-    /*!
-     * \brief Sets the radio in reception mode with Max LNA gain for the given 
time
-     *
-     * \remark Available on SX126x radios only.
-     *
-     * \param [IN] timeout Reception timeout [ms]
-     *                     [0: continuous, others timeout]
-     */
-    void    ( *RxBoosted )( uint32_t timeout );
-    /*!
-     * \brief Sets the Rx duty cycle management parameters
-     *
-     * \remark Available on SX126x radios only.
+     * \brief Disables receive irq, puts chip in standby and clears any pending
+     * rx interrupts
      *
-     * \param [in]  rxTime        Structure describing reception timeout value
-     * \param [in]  sleepTime     Structure describing sleep timeout value
      */
-    void ( *SetRxDutyCycle ) ( uint32_t rxTime, uint32_t sleepTime );
+    void  ( *RxDisable )( void );
 };
 
 /*!
diff --git a/hw/drivers/lora/sx1276/src/sx1276-board.c 
b/hw/drivers/lora/sx1276/src/sx1276-board.c
index 7430c69e80..5e28d17a6e 100644
--- a/hw/drivers/lora/sx1276/src/sx1276-board.c
+++ b/hw/drivers/lora/sx1276/src/sx1276-board.c
@@ -55,7 +55,8 @@ const struct Radio_s Radio =
     .ReadBuffer = SX1276ReadBuffer,
     .SetMaxPayloadLength = SX1276SetMaxPayloadLength,
     .SetPublicNetwork = SX1276SetPublicNetwork,
-    .GetWakeupTime = SX1276GetWakeupTime
+    .GetWakeupTime = SX1276GetWakeupTime,
+    .RxDisable = SX1276RxDisable
 };
 
 void
@@ -231,3 +232,20 @@ SX1276GetBoardTcxoWakeupTime(void)
     return 0;
 }
 
+void
+SX1276RxIoIrqDisable(void)
+{
+    hal_gpio_irq_disable(SX1276_DIO0);
+    hal_gpio_irq_disable(SX1276_DIO1);
+    hal_gpio_irq_disable(SX1276_DIO2);
+    hal_gpio_irq_disable(SX1276_DIO3);
+}
+
+void
+SX1276RxIoIrqEnable(void)
+{
+    hal_gpio_irq_enable(SX1276_DIO0);
+    hal_gpio_irq_enable(SX1276_DIO1);
+    hal_gpio_irq_enable(SX1276_DIO2);
+    hal_gpio_irq_enable(SX1276_DIO3);
+}
diff --git a/hw/drivers/lora/sx1276/src/sx1276-board.h 
b/hw/drivers/lora/sx1276/src/sx1276-board.h
index 173f1d9447..73edf9c63f 100644
--- a/hw/drivers/lora/sx1276/src/sx1276-board.h
+++ b/hw/drivers/lora/sx1276/src/sx1276-board.h
@@ -1,131 +1,141 @@
-/*
- / _____)             _              | |
-( (____  _____ ____ _| |_ _____  ____| |__
- \____ \| ___ |    (_   _) ___ |/ ___)  _ \
- _____) ) ____| | | || |_| ____( (___| | | |
-(______/|_____)_|_|_| \__)_____)\____)_| |_|
-    (C)2013 Semtech
-
-Description: SX1276 driver specific target board functions implementation
-
-License: Revised BSD License, see LICENSE.TXT file include in the project
-
-Maintainer: Miguel Luis and Gregory Cristian
-*/
-#ifndef __SX1276_ARCH_H__
-#define __SX1276_ARCH_H__
-
-#include "hal/hal_gpio.h"
-
-#define RADIO_SPI_IDX               MYNEWT_VAL(SX1276_SPI_IDX)
-
-#if RADIO_SPI_IDX == 0
-#define RADIO_NSS                   MYNEWT_VAL(SX1276_SPI_CS_PIN)
-#else
-#error Invalid SX1276_SPI_IDX value
-#endif
-
-/*!
- * \brief Radio hardware registers initialization definition
- *
- * \remark Can be automatically generated by the SX1276 GUI (not yet 
implemented)
- */
-#define RADIO_INIT_REGISTERS_VALUE                \
-{                                                 \
-    { MODEM_FSK , REG_LNA                , 0x23 },\
-    { MODEM_FSK , REG_RXCONFIG           , 0x1E },\
-    { MODEM_FSK , REG_RSSICONFIG         , 0xD2 },\
-    { MODEM_FSK , REG_AFCFEI             , 0x01 },\
-    { MODEM_FSK , REG_PREAMBLEDETECT     , 0xAA },\
-    { MODEM_FSK , REG_OSC                , 0x07 },\
-    { MODEM_FSK , REG_SYNCCONFIG         , 0x12 },\
-    { MODEM_FSK , REG_SYNCVALUE1         , 0xC1 },\
-    { MODEM_FSK , REG_SYNCVALUE2         , 0x94 },\
-    { MODEM_FSK , REG_SYNCVALUE3         , 0xC1 },\
-    { MODEM_FSK , REG_PACKETCONFIG1      , 0xD8 },\
-    { MODEM_FSK , REG_FIFOTHRESH         , 0x8F },\
-    { MODEM_FSK , REG_IMAGECAL           , 0x02 },\
-    { MODEM_FSK , REG_DIOMAPPING1        , 0x00 },\
-    { MODEM_FSK , REG_DIOMAPPING2        , 0x30 },\
-    { MODEM_LORA, REG_LR_PAYLOADMAXLENGTH, 0x40 },\
-}                                                 \
-
-#define RF_MID_BAND_THRESH                          525000000
-
-/*!
- * \brief Initializes the radio I/Os pins interface
- */
-void SX1276IoInit(void);
-
-void SX1276IoIrqInit(DioIrqHandler **irqHandlers);
-
-/*!
- * \brief De-initializes the radio I/Os pins interface.
- *
- * \remark Useful when going in MCU low power modes
- */
-void SX1276IoDeInit(void);
-
-/*!
- * \brief Sets the radio output power.
- *
- * \param [IN] power Sets the RF output power
- */
-void SX1276SetRfTxPower(int8_t power);
-
-/*!
- * \brief Gets the board PA selection configuration
- *
- * \param [IN] channel Channel frequency in Hz
- * \retval PaSelect RegPaConfig PaSelect value
- */
-uint8_t SX1276GetPaSelect(uint32_t channel);
-
-#if MYNEWT_VAL(SX1276_HAS_ANT_SW)
-/*!
- * \brief Set the RF Switch I/Os pins in Low Power mode
- *
- * \param [IN] status enable or disable
- */
-void SX1276SetAntSwLowPower(bool status);
-
-/*!
- * \brief Initializes the RF Switch I/Os pins interface
- */
-void SX1276AntSwInit(void);
-
-/*!
- * \brief De-initializes the RF Switch I/Os pins interface
- *
- * \remark Needed to decrease the power consumption in MCU low power modes
- */
-void SX1276AntSwDeInit(void);
-
-/*!
- * \brief Controls the antenna switch if necessary.
- *
- * \remark see errata note
- *
- * \param [IN] opMode Current radio operating mode
- */
-void SX1276SetAntSw(uint8_t opMode);
-#endif
-
-/*!
- * \brief Checks if the given RF frequency is supported by the hardware
- *
- * \param [IN] frequency RF frequency to be checked
- * \retval isSupported [true: supported, false: unsupported]
- */
-bool SX1276CheckRfFrequency(uint32_t frequency);
-
-void SX1276SetPublicNetwork(bool enable);
-
-uint32_t SX1276GetBoardTcxoWakeupTime(void);
-
-/*!
- * Radio hardware and global parameters
- */
-extern SX1276_t SX1276;
-
-#endif // __SX1276_ARCH_H__
+/*
+ / _____)             _              | |
+( (____  _____ ____ _| |_ _____  ____| |__
+ \____ \| ___ |    (_   _) ___ |/ ___)  _ \
+ _____) ) ____| | | || |_| ____( (___| | | |
+(______/|_____)_|_|_| \__)_____)\____)_| |_|
+    (C)2013 Semtech
+
+Description: SX1276 driver specific target board functions implementation
+
+License: Revised BSD License, see LICENSE.TXT file include in the project
+
+Maintainer: Miguel Luis and Gregory Cristian
+*/
+#ifndef __SX1276_ARCH_H__
+#define __SX1276_ARCH_H__
+
+#include "hal/hal_gpio.h"
+
+#define RADIO_SPI_IDX               MYNEWT_VAL(SX1276_SPI_IDX)
+
+#if RADIO_SPI_IDX == 0
+#define RADIO_NSS                   MYNEWT_VAL(SX1276_SPI_CS_PIN)
+#else
+#error Invalid SX1276_SPI_IDX value
+#endif
+
+/*!
+ * \brief Radio hardware registers initialization definition
+ *
+ * \remark Can be automatically generated by the SX1276 GUI (not yet 
implemented)
+ */
+#define RADIO_INIT_REGISTERS_VALUE                \
+{                                                 \
+    { MODEM_FSK , REG_LNA                , 0x23 },\
+    { MODEM_FSK , REG_RXCONFIG           , 0x1E },\
+    { MODEM_FSK , REG_RSSICONFIG         , 0xD2 },\
+    { MODEM_FSK , REG_AFCFEI             , 0x01 },\
+    { MODEM_FSK , REG_PREAMBLEDETECT     , 0xAA },\
+    { MODEM_FSK , REG_OSC                , 0x07 },\
+    { MODEM_FSK , REG_SYNCCONFIG         , 0x12 },\
+    { MODEM_FSK , REG_SYNCVALUE1         , 0xC1 },\
+    { MODEM_FSK , REG_SYNCVALUE2         , 0x94 },\
+    { MODEM_FSK , REG_SYNCVALUE3         , 0xC1 },\
+    { MODEM_FSK , REG_PACKETCONFIG1      , 0xD8 },\
+    { MODEM_FSK , REG_FIFOTHRESH         , 0x8F },\
+    { MODEM_FSK , REG_IMAGECAL           , 0x02 },\
+    { MODEM_FSK , REG_DIOMAPPING1        , 0x00 },\
+    { MODEM_FSK , REG_DIOMAPPING2        , 0x30 },\
+    { MODEM_LORA, REG_LR_PAYLOADMAXLENGTH, 0x40 },\
+}                                                 \
+
+#define RF_MID_BAND_THRESH                          525000000
+
+/*!
+ * \brief Initializes the radio I/Os pins interface
+ */
+void SX1276IoInit(void);
+
+void SX1276IoIrqInit(DioIrqHandler **irqHandlers);
+
+/*!
+ * \brief De-initializes the radio I/Os pins interface.
+ *
+ * \remark Useful when going in MCU low power modes
+ */
+void SX1276IoDeInit(void);
+
+/*!
+ * \brief Sets the radio output power.
+ *
+ * \param [IN] power Sets the RF output power
+ */
+void SX1276SetRfTxPower(int8_t power);
+
+/*!
+ * \brief Gets the board PA selection configuration
+ *
+ * \param [IN] channel Channel frequency in Hz
+ * \retval PaSelect RegPaConfig PaSelect value
+ */
+uint8_t SX1276GetPaSelect(uint32_t channel);
+
+#if MYNEWT_VAL(SX1276_HAS_ANT_SW)
+/*!
+ * \brief Set the RF Switch I/Os pins in Low Power mode
+ *
+ * \param [IN] status enable or disable
+ */
+void SX1276SetAntSwLowPower(bool status);
+
+/*!
+ * \brief Initializes the RF Switch I/Os pins interface
+ */
+void SX1276AntSwInit(void);
+
+/*!
+ * \brief De-initializes the RF Switch I/Os pins interface
+ *
+ * \remark Needed to decrease the power consumption in MCU low power modes
+ */
+void SX1276AntSwDeInit(void);
+
+/*!
+ * \brief Controls the antenna switch if necessary.
+ *
+ * \remark see errata note
+ *
+ * \param [IN] opMode Current radio operating mode
+ */
+void SX1276SetAntSw(uint8_t opMode);
+#endif
+
+/*!
+ * \brief Checks if the given RF frequency is supported by the hardware
+ *
+ * \param [IN] frequency RF frequency to be checked
+ * \retval isSupported [true: supported, false: unsupported]
+ */
+bool SX1276CheckRfFrequency(uint32_t frequency);
+
+void SX1276SetPublicNetwork(bool enable);
+
+uint32_t SX1276GetBoardTcxoWakeupTime(void);
+
+/*!
+ * \brief Disables all receive related IO Irqs
+ */
+void SX1276RxIoIrqDisable( void );
+
+/*!
+ * \brief Enables all receive related IO Irqs
+ */
+void SX1276RxIoIrqEnable( void );
+
+/*!
+ * Radio hardware and global parameters
+ */
+extern SX1276_t SX1276;
+
+#endif // __SX1276_ARCH_H__
diff --git a/hw/drivers/lora/sx1276/src/sx1276.c 
b/hw/drivers/lora/sx1276/src/sx1276.c
index d728ce13f9..892ef7e774 100644
--- a/hw/drivers/lora/sx1276/src/sx1276.c
+++ b/hw/drivers/lora/sx1276/src/sx1276.c
@@ -1712,3 +1712,31 @@ SX1276OnDio5Irq(void *unused)
         break;
     }
 }
+
+void
+SX1276RxDisable(void)
+{
+    if (SX1276.Settings.Modem == MODEM_LORA) {
+        /* Disable GPIO interrupts */
+        SX1276RxIoIrqDisable();
+
+        /* Disable RX interrupts */
+        SX1276Write(REG_LR_IRQFLAGSMASK, RFLR_IRQFLAGS_RXTIMEOUT_MASK       |
+                                         RFLR_IRQFLAGS_RXDONE_MASK          |
+                                         RFLR_IRQFLAGS_PAYLOADCRCERROR_MASK |
+                                         RFLR_IRQFLAGS_CADDONE_MASK         |
+                                         RFLR_IRQFLAGS_CADDETECTED_MASK);
+
+        /* Put radio into standby */
+        SX1276SetStby();
+
+        /* Clear any pending interrupts */
+        SX1276Write(REG_LR_IRQFLAGS, RFLR_IRQFLAGS_RXTIMEOUT            |
+                                     RFLR_IRQFLAGS_RXDONE               |
+                                     RFLR_IRQFLAGS_PAYLOADCRCERROR_MASK |
+                                     RFLR_IRQFLAGS_CADDONE_MASK         |
+                                     RFLR_IRQFLAGS_CADDETECTED_MASK);
+        /* Enable GPIO interrupts */
+        SX1276RxIoIrqEnable();
+    }
+}
diff --git a/hw/drivers/lora/sx1276/src/sx1276.h 
b/hw/drivers/lora/sx1276/src/sx1276.h
index bfbb082a6d..ae54a62347 100644
--- a/hw/drivers/lora/sx1276/src/sx1276.h
+++ b/hw/drivers/lora/sx1276/src/sx1276.h
@@ -394,4 +394,6 @@ void SX1276SetPublicNetwork(bool enable);
  */
 uint32_t SX1276GetWakeupTime(void);
 
+void SX1276RxDisable(void);
+
 #endif // __SX1276_H__
diff --git a/net/lora/node/src/mac/LoRaMac.c b/net/lora/node/src/mac/LoRaMac.c
index 7c74ff1e11..b254eb0ffa 100644
--- a/net/lora/node/src/mac/LoRaMac.c
+++ b/net/lora/node/src/mac/LoRaMac.c
@@ -230,6 +230,21 @@ struct os_event g_lora_mac_tx_delay_timeout_event;
 static void lora_mac_rx_on_window2(void);
 static uint8_t lora_mac_extract_mac_cmds(uint8_t max_cmd_bytes, uint8_t *buf);
 
+static void
+lora_mac_rx_disable(void)
+{
+    struct os_eventq *evq;
+
+    /* Disable reception (if not receiving) */
+    Radio.RxDisable();
+
+    /* Remove all possible receive related events */
+    evq = lora_node_mac_evq_get();
+    os_eventq_remove(evq, &g_lora_mac_radio_rx_event);
+    os_eventq_remove(evq, &g_lora_mac_radio_rx_err_event);
+    os_eventq_remove(evq, &g_lora_mac_radio_rx_timeout_event);
+}
+
 /**
  * lora mac rtx timer stop
  *
@@ -2003,6 +2018,9 @@ ScheduleTx(void)
             RxWindow2Config.WindowOffset;
     }
 
+    /* Make sure receive is disabled before attempting to transmit */
+    lora_mac_rx_disable();
+
     // Try to send now
     return SendFrameOnChannel(g_lora_mac_data.cur_chan);
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to