wes3 closed pull request #793: lora: make the lora driver not dependent on lora 
node
URL: https://github.com/apache/mynewt-core/pull/793
 
 
   

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/apps/loraping/pkg.yml b/apps/loraping/pkg.yml
index 59924639b..972cafa2a 100644
--- a/apps/loraping/pkg.yml
+++ b/apps/loraping/pkg.yml
@@ -31,7 +31,6 @@ pkg.deps:
     - "@apache-mynewt-core/mgmt/imgmgr"
     - "@apache-mynewt-core/mgmt/newtmgr"
     - "@apache-mynewt-core/mgmt/newtmgr/transport/nmgr_shell"
-    - "@apache-mynewt-core/net/lora/node"
     - "@apache-mynewt-core/sys/config"
     - "@apache-mynewt-core/sys/console/full"
     - "@apache-mynewt-core/sys/id"
diff --git a/apps/loraping/src/main.c b/apps/loraping/src/main.c
index 2f845e457..24dc0e5b4 100644
--- a/apps/loraping/src/main.c
+++ b/apps/loraping/src/main.c
@@ -34,7 +34,7 @@ Description: Ping-Pong implementation.  Adapted to run in the 
MyNewt OS.
 #include "hal/hal_spi.h"
 #include "bsp/bsp.h"
 #include "os/os.h"
-#include "node/radio.h"
+#include "radio/radio.h"
 #include "loraping.h"
 
 #define USE_BAND_915
@@ -140,7 +140,7 @@ loraping_tx(struct os_event *ev)
 
             /* A master already exists.  Become a slave. */
             loraping_is_master = 0;
-        } else { 
+        } else {
             /* Valid reception but neither a PING nor a PONG message. */
             loraping_stats.rx_other++;
             /* Set device as master and start again. */
@@ -225,6 +225,8 @@ main(void)
 
     sysinit();
 
+    hal_timer_config(4, 1000000);
+
     /* Radio initialization. */
     radio_events.TxDone = on_tx_done;
     radio_events.RxDone = on_rx_done;
diff --git a/apps/loraping/syscfg.yml b/apps/loraping/syscfg.yml
new file mode 100644
index 000000000..60d294f48
--- /dev/null
+++ b/apps/loraping/syscfg.yml
@@ -0,0 +1,34 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+syscfg.defs:
+    LORA_NODE:
+        description: >
+            Used by package management system to include mfrg firmware.
+        value: 1
+
+    LORA_MAC_TIMER_NUM:
+        description: Timer number used for lora mac and radio
+        value: -1
+
+syscfg.vals:
+    STATS_CLI: 1
+    STATS_NAMES: 1
+    SHELL_TASK: 1
+    SHELL_MAX_COMPAT_COMMANDS: 32
diff --git a/hw/drivers/lora/sx1276/include/radio/radio.h 
b/hw/drivers/lora/sx1276/include/radio/radio.h
index 6f23183be..ccc0ffc98 100644
--- a/hw/drivers/lora/sx1276/include/radio/radio.h
+++ b/hw/drivers/lora/sx1276/include/radio/radio.h
@@ -6,28 +6,332 @@
 (______/|_____)_|_|_| \__)_____)\____)_| |_|
     (C)2013 Semtech
 
-Description: Generic SX1276 driver implementation
+Description: Generic radio driver definition
 
 License: Revised BSD License, see LICENSE.TXT file include in the project
 
 Maintainer: Miguel Luis and Gregory Cristian
 */
-#ifndef H_RADIO_RADIO_
-#define H_RADIO_RADIO_
+#ifndef __RADIO_H__
+#define __RADIO_H__
+
+#include <inttypes.h>
+#include <stdbool.h>
+
+/*!
+ * Radio driver supported modems
+ */
+typedef enum
+{
+    MODEM_FSK = 0,
+    MODEM_LORA,
+}RadioModems_t;
 
 /*!
- * Radio wakeup time from SLEEP mode
+ * Radio driver internal state machine states definition
  */
-#define RADIO_OSC_STARTUP                           1 // [ms]
+typedef enum
+{
+    RF_IDLE = 0,
+    RF_RX_RUNNING,
+    RF_TX_RUNNING,
+    RF_CAD,
+}RadioState_t;
+
+/*!
+ * \brief Radio driver callback functions
+ */
+typedef struct
+{
+    /*!
+     * \brief  Tx Done callback prototype.
+     */
+    void    ( *TxDone )( void );
+    /*!
+     * \brief  Tx Timeout callback prototype.
+     */
+    void    ( *TxTimeout )( void );
+    /*!
+     * \brief Rx Done callback prototype.
+     *
+     * \param [IN] payload Received buffer pointer
+     * \param [IN] size    Received buffer size
+     * \param [IN] rssi    RSSI value computed while receiving the frame [dBm]
+     * \param [IN] snr     Raw SNR value given by the radio hardware
+     *                     FSK : N/A ( set to 0 )
+     *                     LoRa: SNR value in dB
+     */
+    void    ( *RxDone )( uint8_t *payload, uint16_t size, int16_t rssi, int8_t 
snr );
+    /*!
+     * \brief  Rx Timeout callback prototype.
+     */
+    void    ( *RxTimeout )( void );
+    /*!
+     * \brief Rx Error callback prototype.
+     */
+    void    ( *RxError )( void );
+    /*!
+     * \brief  FHSS Change Channel callback prototype.
+     *
+     * \param [IN] currentChannel   Index number of the current channel
+     */
+    void ( *FhssChangeChannel )( uint8_t currentChannel );
+
+    /*!
+     * \brief CAD Done callback prototype.
+     *
+     * \param [IN] channelDetected    Channel Activity detected during the CAD
+     */
+    void ( *CadDone ) ( bool channelActivityDetected );
+}RadioEvents_t;
 
 /*!
- * Radio PLL lock and Mode Ready delay which can vary with the temperature
+ * \brief Radio driver definition
  */
-#define RADIO_SLEEP_TO_RX                           2 // [ms]
+struct Radio_s
+{
+    /*!
+     * \brief Initializes the radio
+     *
+     * \param [IN] events Structure containing the driver callback functions
+     */
+    void    ( *Init )( RadioEvents_t *events );
+    /*!
+     * Return current radio status
+     *
+     * \param status Radio status.[RF_IDLE, RF_RX_RUNNING, RF_TX_RUNNING]
+     */
+    RadioState_t ( *GetStatus )( void );
+    /*!
+     * \brief Configures the radio with the given modem
+     *
+     * \param [IN] modem Modem to be used [0: FSK, 1: LoRa] 
+     */
+    void    ( *SetModem )( RadioModems_t modem );
+    /*!
+     * \brief Sets the channel frequency
+     *
+     * \param [IN] freq         Channel RF frequency
+     */
+    void    ( *SetChannel )( uint32_t freq );
+    /*!
+     * \brief Sets the channels configuration
+     *
+     * \param [IN] modem      Radio modem to be used [0: FSK, 1: LoRa]
+     * \param [IN] freq       Channel RF frequency
+     * \param [IN] rssiThresh RSSI threshold
+     *
+     * \retval isFree         [true: Channel is free, false: Channel is not 
free]
+     */
+    bool    ( *IsChannelFree )( RadioModems_t modem, uint32_t freq, int16_t 
rssiThresh );
+    /*!
+     * \brief Generates a 32 bits random value based on the RSSI readings
+     *
+     * \remark This function sets the radio in LoRa modem mode and disables 
+     *         all interrupts.
+     *         After calling this function either Radio.SetRxConfig or
+     *         Radio.SetTxConfig functions must be called.
+     *
+     * \retval randomValue    32 bits random value
+     */
+    uint32_t ( *Random )( void );
+    /*!
+     * \brief Sets the reception parameters
+     *
+     * \param [IN] modem        Radio modem to be used [0: FSK, 1: LoRa]
+     * \param [IN] bandwidth    Sets the bandwidth
+     *                          FSK : >= 2600 and <= 250000 Hz
+     *                          LoRa: [0: 125 kHz, 1: 250 kHz,
+     *                                 2: 500 kHz, 3: Reserved] 
+     * \param [IN] datarate     Sets the Datarate
+     *                          FSK : 600..300000 bits/s
+     *                          LoRa: [6: 64, 7: 128, 8: 256, 9: 512,
+     *                                10: 1024, 11: 2048, 12: 4096  chips]
+     * \param [IN] coderate     Sets the coding rate (LoRa only)
+     *                          FSK : N/A ( set to 0 )
+     *                          LoRa: [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8] 
+     * \param [IN] bandwidthAfc Sets the AFC Bandwidth (FSK only) 
+     *                          FSK : >= 2600 and <= 250000 Hz
+     *                          LoRa: N/A ( set to 0 ) 
+     * \param [IN] preambleLen  Sets the Preamble length
+     *                          FSK : Number of bytes 
+     *                          LoRa: Length in symbols (the hardware adds 4 
more symbols)
+     * \param [IN] symbTimeout  Sets the RxSingle timeout value (LoRa only) 
+     *                          FSK : N/A ( set to 0 ) 
+     *                          LoRa: timeout in symbols
+     * \param [IN] fixLen       Fixed length packets [0: variable, 1: fixed]
+     * \param [IN] payloadLen   Sets payload length when fixed length is used
+     * \param [IN] crcOn        Enables/Disables the CRC [0: OFF, 1: ON]
+     * \param [IN] FreqHopOn    Enables disables the intra-packet frequency 
hopping
+     *                          FSK : N/A ( set to 0 )
+     *                          LoRa: [0: OFF, 1: ON]
+     * \param [IN] HopPeriod    Number of symbols between each hop
+     *                          FSK : N/A ( set to 0 )
+     *                          LoRa: Number of symbols
+     * \param [IN] iqInverted   Inverts IQ signals (LoRa only)
+     *                          FSK : N/A ( set to 0 )
+     *                          LoRa: [0: not inverted, 1: inverted]
+     * \param [IN] rxContinuous Sets the reception in continuous mode
+     *                          [false: single mode, true: continuous mode]
+     */
+    void    ( *SetRxConfig )( RadioModems_t modem, uint32_t bandwidth,
+                              uint32_t datarate, uint8_t coderate,
+                              uint32_t bandwidthAfc, uint16_t preambleLen,
+                              uint16_t symbTimeout, bool fixLen,
+                              uint8_t payloadLen,
+                              bool crcOn, bool FreqHopOn, uint8_t HopPeriod,
+                              bool iqInverted, bool rxContinuous );
+    /*!
+     * \brief Sets the transmission parameters
+     *
+     * \param [IN] modem        Radio modem to be used [0: FSK, 1: LoRa] 
+     * \param [IN] power        Sets the output power [dBm]
+     * \param [IN] fdev         Sets the frequency deviation (FSK only)
+     *                          FSK : [Hz]
+     *                          LoRa: 0
+     * \param [IN] bandwidth    Sets the bandwidth (LoRa only)
+     *                          FSK : 0
+     *                          LoRa: [0: 125 kHz, 1: 250 kHz,
+     *                                 2: 500 kHz, 3: Reserved] 
+     * \param [IN] datarate     Sets the Datarate
+     *                          FSK : 600..300000 bits/s
+     *                          LoRa: [6: 64, 7: 128, 8: 256, 9: 512,
+     *                                10: 1024, 11: 2048, 12: 4096  chips]
+     * \param [IN] coderate     Sets the coding rate (LoRa only)
+     *                          FSK : N/A ( set to 0 )
+     *                          LoRa: [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8] 
+     * \param [IN] preambleLen  Sets the preamble length
+     *                          FSK : Number of bytes 
+     *                          LoRa: Length in symbols (the hardware adds 4 
more symbols)
+     * \param [IN] fixLen       Fixed length packets [0: variable, 1: fixed]
+     * \param [IN] crcOn        Enables disables the CRC [0: OFF, 1: ON]
+     * \param [IN] FreqHopOn    Enables disables the intra-packet frequency 
hopping
+     *                          FSK : N/A ( set to 0 )
+     *                          LoRa: [0: OFF, 1: ON]
+     * \param [IN] HopPeriod    Number of symbols between each hop
+     *                          FSK : N/A ( set to 0 )
+     *                          LoRa: Number of symbols
+     * \param [IN] iqInverted   Inverts IQ signals (LoRa only)
+     *                          FSK : N/A ( set to 0 )
+     *                          LoRa: [0: not inverted, 1: inverted]
+     * \param [IN] timeout      Transmission timeout [ms]
+     */
+    void    ( *SetTxConfig )( RadioModems_t modem, int8_t power, uint32_t 
fdev, 
+                              uint32_t bandwidth, uint32_t datarate,
+                              uint8_t coderate, uint16_t preambleLen,
+                              bool fixLen, bool crcOn, bool FreqHopOn,
+                              uint8_t HopPeriod, bool iqInverted, uint32_t 
timeout );
+    /*!
+     * \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    ( *CheckRfFrequency )( uint32_t frequency );
+    /*!
+     * \brief Computes the packet time on air in ms for the given payload
+     *
+     * \Remark Can only be called once SetRxConfig or SetTxConfig have been 
called
+     *
+     * \param [IN] modem      Radio modem to be used [0: FSK, 1: LoRa]
+     * \param [IN] pktLen     Packet payload length
+     *
+     * \retval airTime        Computed airTime (ms) for the given packet 
payload length
+     */
+    uint32_t  ( *TimeOnAir )( RadioModems_t modem, uint8_t pktLen );
+    /*!
+     * \brief Sends the buffer of size. Prepares the packet to be sent and sets
+     *        the radio in transmission
+     *
+     * \param [IN]: buffer     Buffer pointer
+     * \param [IN]: size       Buffer size
+     */
+    void    ( *Send )( uint8_t *buffer, uint8_t size );
+    /*!
+     * \brief Sets the radio in sleep mode
+     */
+    void    ( *Sleep )( void );
+    /*!
+     * \brief Sets the radio in standby mode
+     */
+    void    ( *Standby )( void );
+    /*!
+     * \brief Sets the radio in reception mode for the given time
+     * \param [IN] timeout Reception timeout [ms]
+     *                     [0: continuous, others timeout]
+     */
+    void    ( *Rx )( uint32_t timeout );
+    /*!
+     * \brief Start a Channel Activity Detection
+     */
+    void    ( *StartCad )( void );
+    /*!
+     * \brief Sets the radio in continuous wave transmission mode
+     *
+     * \param [IN]: freq       Channel RF frequency
+     * \param [IN]: power      Sets the output power [dBm]
+     * \param [IN]: time       Transmission mode timeout [s]
+     */
+    void    ( *SetTxContinuousWave )( uint32_t freq, int8_t power, uint16_t 
time );
+    /*!
+     * \brief Reads the current RSSI value
+     *
+     * \retval rssiValue Current RSSI value in [dBm]
+     */
+    int16_t ( *Rssi )( RadioModems_t modem );
+    /*!
+     * \brief Writes the radio register at the specified address
+     *
+     * \param [IN]: addr Register address
+     * \param [IN]: data New register value
+     */
+    void    ( *Write )( uint8_t addr, uint8_t data );
+    /*!
+     * \brief Reads the radio register at the specified address
+     *
+     * \param [IN]: addr Register address
+     * \retval data Register value
+     */
+    uint8_t ( *Read )( uint8_t addr );
+    /*!
+     * \brief Writes multiple radio registers starting at address
+     *
+     * \param [IN] addr   First Radio register address
+     * \param [IN] buffer Buffer containing the new register's values
+     * \param [IN] size   Number of registers to be written
+     */
+    void    ( *WriteBuffer )( uint8_t addr, uint8_t *buffer, uint8_t size );
+    /*!
+     * \brief Reads multiple radio registers starting at address
+     *
+     * \param [IN] addr First Radio register address
+     * \param [OUT] buffer Buffer where to copy the registers data
+     * \param [IN] size Number of registers to be read
+     */
+    void    ( *ReadBuffer )( uint8_t addr, uint8_t *buffer, uint8_t size );
+    /*!
+     * \brief Sets the maximum payload length.
+     *
+     * \param [IN] modem      Radio modem to be used [0: FSK, 1: LoRa]
+     * \param [IN] max        Maximum payload length in bytes
+     */
+    void    ( *SetMaxPayloadLength )( RadioModems_t modem, uint8_t max );
+    /*!
+     * \brief Sets the network to public or private. Updates the sync byte.
+     *
+     * \remark Applies to LoRa modem only
+     *
+     * \param [IN] enable if true, it enables a public network
+     */
+    void    ( *SetPublicNetwork )( bool enable );
+};
 
 /*!
- * Radio complete Wake-up Time with margin for temperature compensation
+ * \brief Radio driver
+ *
+ * \remark This variable is defined and initialized in the specific radio
+ *         board implementation
  */
-#define RADIO_WAKEUP_TIME                           ( RADIO_OSC_STARTUP + 
RADIO_SLEEP_TO_RX )
+extern const struct Radio_s Radio;
 
-#endif /* H_RADIO_RADIO */
+#endif // __RADIO_H__
diff --git a/hw/drivers/lora/sx1276/pkg.yml b/hw/drivers/lora/sx1276/pkg.yml
index 8f8d69e8b..2b483910b 100644
--- a/hw/drivers/lora/sx1276/pkg.yml
+++ b/hw/drivers/lora/sx1276/pkg.yml
@@ -6,7 +6,7 @@
 # to you under the Apache License, Version 2.0 (the
 # "License"); you may not use this file except in compliance
 # with the License.  You may obtain a copy of the License at
-# 
+#
 #  http://www.apache.org/licenses/LICENSE-2.0
 #
 # Unless required by applicable law or agreed to in writing,
@@ -26,7 +26,6 @@ pkg.keywords:
 
 pkg.deps:
     - "@apache-mynewt-core/kernel/os"
-    - "@apache-mynewt-core/net/lora/node"
 
 pkg.apis:
     - lora_node_driver
diff --git a/hw/drivers/lora/sx1276/src/sx1276-board.c 
b/hw/drivers/lora/sx1276/src/sx1276-board.c
index e91c86c1f..ffcdfa697 100644
--- a/hw/drivers/lora/sx1276/src/sx1276-board.c
+++ b/hw/drivers/lora/sx1276/src/sx1276-board.c
@@ -15,7 +15,7 @@ Maintainer: Miguel Luis and Gregory Cristian
 #include <assert.h>
 #include "hal/hal_spi.h"
 #include "bsp/bsp.h"
-#include "node/radio.h"
+#include "radio/radio.h"
 #include "sx1276.h"
 #include "sx1276-board.h"
 
diff --git a/hw/drivers/lora/sx1276/src/sx1276.c 
b/hw/drivers/lora/sx1276/src/sx1276.c
index 5200d24aa..e307370b8 100644
--- a/hw/drivers/lora/sx1276/src/sx1276.c
+++ b/hw/drivers/lora/sx1276/src/sx1276.c
@@ -22,11 +22,9 @@ Maintainer: Miguel Luis, Gregory Cristian and Wael Guibene
 #include "hal/hal_timer.h"
 #include "bsp/bsp.h"
 #include "os/os.h"
-#include "node/lora.h"
-#include "node/radio.h"
+#include "radio/radio.h"
 #include "sx1276.h"
 #include "sx1276-board.h"
-#include "node/lora_priv.h"
 
 #if MYNEWT_VAL(LORA_MAC_TIMER_NUM) == -1
 #error "Must define a Lora MAC timer number"
@@ -227,11 +225,33 @@ struct hal_timer RxTimeoutSyncWord;
 
 static uint32_t rx_timeout_sync_delay = -1;
 
+double
+ceil(double d)
+{
+    int64_t i;
+
+    i = d;
+    if (d == i) {
+        return i;
+    }
+    return i + 1;
+}
+
+double
+floor(double d)
+{
+    return (int64_t)d;
+}
+
+double
+round(double d)
+{
+    return (int64_t)(d + 0.5);
+}
+
 static void
 SX1276RxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr )
 {
-    STATS_INC(lora_stats, rx_success);
-
     if( ( RadioEvents != NULL ) && ( RadioEvents->RxDone != NULL ) )
     {
         RadioEvents->RxDone( payload, size, rssi, snr );
@@ -241,8 +261,6 @@ SX1276RxDone( uint8_t *payload, uint16_t size, int16_t 
rssi, int8_t snr )
 static void
 SX1276RxError( void )
 {
-    STATS_INC(lora_stats, rx_error);
-
     if( ( RadioEvents != NULL ) && ( RadioEvents->RxError != NULL ) )
     {
         RadioEvents->RxError( );
@@ -252,8 +270,6 @@ SX1276RxError( void )
 static void
 SX1276RxTimeout( void )
 {
-    STATS_INC(lora_stats, rx_timeout);
-
     if( ( RadioEvents != NULL ) && ( RadioEvents->RxTimeout != NULL ) )
     {
         RadioEvents->RxTimeout( );
@@ -263,8 +279,6 @@ SX1276RxTimeout( void )
 static void
 SX1276TxDone( void )
 {
-    STATS_INC(lora_stats, tx_success);
-
     if( ( RadioEvents != NULL ) && ( RadioEvents->TxDone != NULL ) )
     {
         RadioEvents->TxDone( );
@@ -274,8 +288,6 @@ SX1276TxDone( void )
 static void
 SX1276TxTimeout( void )
 {
-    STATS_INC(lora_stats, tx_timeout);
-
     if( ( RadioEvents != NULL ) && ( RadioEvents->TxTimeout != NULL ) )
     {
         RadioEvents->TxTimeout( );
@@ -1440,7 +1452,6 @@ void SX1276OnTimeoutIrq(void *unused)
                 hal_timer_stop(&RxTimeoutSyncWord);
             }
         }
-        lora_node_log(LORA_NODE_LOG_RADIO_TIMEOUT_IRQ, 0, 0, 0);
         SX1276RxTimeout( );
         break;
     case RF_TX_RUNNING:
@@ -1677,7 +1688,6 @@ void SX1276OnDio1Irq(void *unused)
             case MODEM_LORA:
                 // Sync time out
                 hal_timer_stop(&RxTimeoutTimer);
-                lora_node_log(LORA_NODE_LOG_RX_SYNC_TIMEOUT, 0, 0, 0);
                 SX1276Write( REG_LR_IRQFLAGS, RFLR_IRQFLAGS_RXTIMEOUT );
                 SX1276.Settings.State = RF_IDLE;
                 SX1276RxTimeout( );
diff --git a/hw/drivers/lora/sx1276/src/sx1276.h 
b/hw/drivers/lora/sx1276/src/sx1276.h
index f8be732a1..899da8edf 100644
--- a/hw/drivers/lora/sx1276/src/sx1276.h
+++ b/hw/drivers/lora/sx1276/src/sx1276.h
@@ -16,7 +16,7 @@ Maintainer: Miguel Luis and Gregory Cristian
 #define __SX1276_H__
 #include <stdint.h>
 #include <stdbool.h>
-#include "node/radio.h"
+#include "radio/radio.h"
 #include "sx1276Regs-Fsk.h"
 #include "sx1276Regs-LoRa.h"
 
@@ -30,6 +30,21 @@ Maintainer: Miguel Luis and Gregory Cristian
  */
 #define LORA_MAC_PUBLIC_SYNCWORD                    0x34
 
+/*!
+ * Radio wakeup time from SLEEP mode
+ */
+#define RADIO_OSC_STARTUP                           1 // [ms]
+
+/*!
+ * Radio PLL lock and Mode Ready delay which can vary with the temperature
+ */
+#define RADIO_SLEEP_TO_RX                           2 // [ms]
+
+/*!
+ * Radio complete Wake-up Time with margin for temperature compensation
+ */
+#define RADIO_WAKEUP_TIME                           ( RADIO_OSC_STARTUP + 
RADIO_SLEEP_TO_RX )
+
 /*!
  * Radio FSK modem parameters
  */
diff --git a/net/lora/node/include/node/radio.h 
b/net/lora/node/include/node/radio.h
deleted file mode 100644
index 6923ec981..000000000
--- a/net/lora/node/include/node/radio.h
+++ /dev/null
@@ -1,337 +0,0 @@
-/*
- / _____)             _              | |
-( (____  _____ ____ _| |_ _____  ____| |__
- \____ \| ___ |    (_   _) ___ |/ ___)  _ \
- _____) ) ____| | | || |_| ____( (___| | | |
-(______/|_____)_|_|_| \__)_____)\____)_| |_|
-    (C)2013 Semtech
-
-Description: Generic radio driver definition
-
-License: Revised BSD License, see LICENSE.TXT file include in the project
-
-Maintainer: Miguel Luis and Gregory Cristian
-*/
-#ifndef __RADIO_H__
-#define __RADIO_H__
-
-#include <inttypes.h>
-#include <stdbool.h>
-
-/*!
- * Radio driver supported modems
- */
-typedef enum
-{
-    MODEM_FSK = 0,
-    MODEM_LORA,
-}RadioModems_t;
-
-/*!
- * Radio driver internal state machine states definition
- */
-typedef enum
-{
-    RF_IDLE = 0,
-    RF_RX_RUNNING,
-    RF_TX_RUNNING,
-    RF_CAD,
-}RadioState_t;
-
-/*!
- * \brief Radio driver callback functions
- */
-typedef struct
-{
-    /*!
-     * \brief  Tx Done callback prototype.
-     */
-    void    ( *TxDone )( void );
-    /*!
-     * \brief  Tx Timeout callback prototype.
-     */
-    void    ( *TxTimeout )( void );
-    /*!
-     * \brief Rx Done callback prototype.
-     *
-     * \param [IN] payload Received buffer pointer
-     * \param [IN] size    Received buffer size
-     * \param [IN] rssi    RSSI value computed while receiving the frame [dBm]
-     * \param [IN] snr     Raw SNR value given by the radio hardware
-     *                     FSK : N/A ( set to 0 )
-     *                     LoRa: SNR value in dB
-     */
-    void    ( *RxDone )( uint8_t *payload, uint16_t size, int16_t rssi, int8_t 
snr );
-    /*!
-     * \brief  Rx Timeout callback prototype.
-     */
-    void    ( *RxTimeout )( void );
-    /*!
-     * \brief Rx Error callback prototype.
-     */
-    void    ( *RxError )( void );
-    /*!
-     * \brief  FHSS Change Channel callback prototype.
-     *
-     * \param [IN] currentChannel   Index number of the current channel
-     */
-    void ( *FhssChangeChannel )( uint8_t currentChannel );
-
-    /*!
-     * \brief CAD Done callback prototype.
-     *
-     * \param [IN] channelDetected    Channel Activity detected during the CAD
-     */
-    void ( *CadDone ) ( bool channelActivityDetected );
-}RadioEvents_t;
-
-/*!
- * \brief Radio driver definition
- */
-struct Radio_s
-{
-    /*!
-     * \brief Initializes the radio
-     *
-     * \param [IN] events Structure containing the driver callback functions
-     */
-    void    ( *Init )( RadioEvents_t *events );
-    /*!
-     * Return current radio status
-     *
-     * \param status Radio status.[RF_IDLE, RF_RX_RUNNING, RF_TX_RUNNING]
-     */
-    RadioState_t ( *GetStatus )( void );
-    /*!
-     * \brief Configures the radio with the given modem
-     *
-     * \param [IN] modem Modem to be used [0: FSK, 1: LoRa] 
-     */
-    void    ( *SetModem )( RadioModems_t modem );
-    /*!
-     * \brief Sets the channel frequency
-     *
-     * \param [IN] freq         Channel RF frequency
-     */
-    void    ( *SetChannel )( uint32_t freq );
-    /*!
-     * \brief Sets the channels configuration
-     *
-     * \param [IN] modem      Radio modem to be used [0: FSK, 1: LoRa]
-     * \param [IN] freq       Channel RF frequency
-     * \param [IN] rssiThresh RSSI threshold
-     *
-     * \retval isFree         [true: Channel is free, false: Channel is not 
free]
-     */
-    bool    ( *IsChannelFree )( RadioModems_t modem, uint32_t freq, int16_t 
rssiThresh );
-    /*!
-     * \brief Generates a 32 bits random value based on the RSSI readings
-     *
-     * \remark This function sets the radio in LoRa modem mode and disables 
-     *         all interrupts.
-     *         After calling this function either Radio.SetRxConfig or
-     *         Radio.SetTxConfig functions must be called.
-     *
-     * \retval randomValue    32 bits random value
-     */
-    uint32_t ( *Random )( void );
-    /*!
-     * \brief Sets the reception parameters
-     *
-     * \param [IN] modem        Radio modem to be used [0: FSK, 1: LoRa]
-     * \param [IN] bandwidth    Sets the bandwidth
-     *                          FSK : >= 2600 and <= 250000 Hz
-     *                          LoRa: [0: 125 kHz, 1: 250 kHz,
-     *                                 2: 500 kHz, 3: Reserved] 
-     * \param [IN] datarate     Sets the Datarate
-     *                          FSK : 600..300000 bits/s
-     *                          LoRa: [6: 64, 7: 128, 8: 256, 9: 512,
-     *                                10: 1024, 11: 2048, 12: 4096  chips]
-     * \param [IN] coderate     Sets the coding rate (LoRa only)
-     *                          FSK : N/A ( set to 0 )
-     *                          LoRa: [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8] 
-     * \param [IN] bandwidthAfc Sets the AFC Bandwidth (FSK only) 
-     *                          FSK : >= 2600 and <= 250000 Hz
-     *                          LoRa: N/A ( set to 0 ) 
-     * \param [IN] preambleLen  Sets the Preamble length
-     *                          FSK : Number of bytes 
-     *                          LoRa: Length in symbols (the hardware adds 4 
more symbols)
-     * \param [IN] symbTimeout  Sets the RxSingle timeout value (LoRa only) 
-     *                          FSK : N/A ( set to 0 ) 
-     *                          LoRa: timeout in symbols
-     * \param [IN] fixLen       Fixed length packets [0: variable, 1: fixed]
-     * \param [IN] payloadLen   Sets payload length when fixed length is used
-     * \param [IN] crcOn        Enables/Disables the CRC [0: OFF, 1: ON]
-     * \param [IN] FreqHopOn    Enables disables the intra-packet frequency 
hopping
-     *                          FSK : N/A ( set to 0 )
-     *                          LoRa: [0: OFF, 1: ON]
-     * \param [IN] HopPeriod    Number of symbols between each hop
-     *                          FSK : N/A ( set to 0 )
-     *                          LoRa: Number of symbols
-     * \param [IN] iqInverted   Inverts IQ signals (LoRa only)
-     *                          FSK : N/A ( set to 0 )
-     *                          LoRa: [0: not inverted, 1: inverted]
-     * \param [IN] rxContinuous Sets the reception in continuous mode
-     *                          [false: single mode, true: continuous mode]
-     */
-    void    ( *SetRxConfig )( RadioModems_t modem, uint32_t bandwidth,
-                              uint32_t datarate, uint8_t coderate,
-                              uint32_t bandwidthAfc, uint16_t preambleLen,
-                              uint16_t symbTimeout, bool fixLen,
-                              uint8_t payloadLen,
-                              bool crcOn, bool FreqHopOn, uint8_t HopPeriod,
-                              bool iqInverted, bool rxContinuous );
-    /*!
-     * \brief Sets the transmission parameters
-     *
-     * \param [IN] modem        Radio modem to be used [0: FSK, 1: LoRa] 
-     * \param [IN] power        Sets the output power [dBm]
-     * \param [IN] fdev         Sets the frequency deviation (FSK only)
-     *                          FSK : [Hz]
-     *                          LoRa: 0
-     * \param [IN] bandwidth    Sets the bandwidth (LoRa only)
-     *                          FSK : 0
-     *                          LoRa: [0: 125 kHz, 1: 250 kHz,
-     *                                 2: 500 kHz, 3: Reserved] 
-     * \param [IN] datarate     Sets the Datarate
-     *                          FSK : 600..300000 bits/s
-     *                          LoRa: [6: 64, 7: 128, 8: 256, 9: 512,
-     *                                10: 1024, 11: 2048, 12: 4096  chips]
-     * \param [IN] coderate     Sets the coding rate (LoRa only)
-     *                          FSK : N/A ( set to 0 )
-     *                          LoRa: [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8] 
-     * \param [IN] preambleLen  Sets the preamble length
-     *                          FSK : Number of bytes 
-     *                          LoRa: Length in symbols (the hardware adds 4 
more symbols)
-     * \param [IN] fixLen       Fixed length packets [0: variable, 1: fixed]
-     * \param [IN] crcOn        Enables disables the CRC [0: OFF, 1: ON]
-     * \param [IN] FreqHopOn    Enables disables the intra-packet frequency 
hopping
-     *                          FSK : N/A ( set to 0 )
-     *                          LoRa: [0: OFF, 1: ON]
-     * \param [IN] HopPeriod    Number of symbols between each hop
-     *                          FSK : N/A ( set to 0 )
-     *                          LoRa: Number of symbols
-     * \param [IN] iqInverted   Inverts IQ signals (LoRa only)
-     *                          FSK : N/A ( set to 0 )
-     *                          LoRa: [0: not inverted, 1: inverted]
-     * \param [IN] timeout      Transmission timeout [ms]
-     */
-    void    ( *SetTxConfig )( RadioModems_t modem, int8_t power, uint32_t 
fdev, 
-                              uint32_t bandwidth, uint32_t datarate,
-                              uint8_t coderate, uint16_t preambleLen,
-                              bool fixLen, bool crcOn, bool FreqHopOn,
-                              uint8_t HopPeriod, bool iqInverted, uint32_t 
timeout );
-    /*!
-     * \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    ( *CheckRfFrequency )( uint32_t frequency );
-    /*!
-     * \brief Computes the packet time on air in ms for the given payload
-     *
-     * \Remark Can only be called once SetRxConfig or SetTxConfig have been 
called
-     *
-     * \param [IN] modem      Radio modem to be used [0: FSK, 1: LoRa]
-     * \param [IN] pktLen     Packet payload length
-     *
-     * \retval airTime        Computed airTime (ms) for the given packet 
payload length
-     */
-    uint32_t  ( *TimeOnAir )( RadioModems_t modem, uint8_t pktLen );
-    /*!
-     * \brief Sends the buffer of size. Prepares the packet to be sent and sets
-     *        the radio in transmission
-     *
-     * \param [IN]: buffer     Buffer pointer
-     * \param [IN]: size       Buffer size
-     */
-    void    ( *Send )( uint8_t *buffer, uint8_t size );
-    /*!
-     * \brief Sets the radio in sleep mode
-     */
-    void    ( *Sleep )( void );
-    /*!
-     * \brief Sets the radio in standby mode
-     */
-    void    ( *Standby )( void );
-    /*!
-     * \brief Sets the radio in reception mode for the given time
-     * \param [IN] timeout Reception timeout [ms]
-     *                     [0: continuous, others timeout]
-     */
-    void    ( *Rx )( uint32_t timeout );
-    /*!
-     * \brief Start a Channel Activity Detection
-     */
-    void    ( *StartCad )( void );
-    /*!
-     * \brief Sets the radio in continuous wave transmission mode
-     *
-     * \param [IN]: freq       Channel RF frequency
-     * \param [IN]: power      Sets the output power [dBm]
-     * \param [IN]: time       Transmission mode timeout [s]
-     */
-    void    ( *SetTxContinuousWave )( uint32_t freq, int8_t power, uint16_t 
time );
-    /*!
-     * \brief Reads the current RSSI value
-     *
-     * \retval rssiValue Current RSSI value in [dBm]
-     */
-    int16_t ( *Rssi )( RadioModems_t modem );
-    /*!
-     * \brief Writes the radio register at the specified address
-     *
-     * \param [IN]: addr Register address
-     * \param [IN]: data New register value
-     */
-    void    ( *Write )( uint8_t addr, uint8_t data );
-    /*!
-     * \brief Reads the radio register at the specified address
-     *
-     * \param [IN]: addr Register address
-     * \retval data Register value
-     */
-    uint8_t ( *Read )( uint8_t addr );
-    /*!
-     * \brief Writes multiple radio registers starting at address
-     *
-     * \param [IN] addr   First Radio register address
-     * \param [IN] buffer Buffer containing the new register's values
-     * \param [IN] size   Number of registers to be written
-     */
-    void    ( *WriteBuffer )( uint8_t addr, uint8_t *buffer, uint8_t size );
-    /*!
-     * \brief Reads multiple radio registers starting at address
-     *
-     * \param [IN] addr First Radio register address
-     * \param [OUT] buffer Buffer where to copy the registers data
-     * \param [IN] size Number of registers to be read
-     */
-    void    ( *ReadBuffer )( uint8_t addr, uint8_t *buffer, uint8_t size );
-    /*!
-     * \brief Sets the maximum payload length.
-     *
-     * \param [IN] modem      Radio modem to be used [0: FSK, 1: LoRa]
-     * \param [IN] max        Maximum payload length in bytes
-     */
-    void    ( *SetMaxPayloadLength )( RadioModems_t modem, uint8_t max );
-    /*!
-     * \brief Sets the network to public or private. Updates the sync byte.
-     *
-     * \remark Applies to LoRa modem only
-     *
-     * \param [IN] enable if true, it enables a public network
-     */
-    void    ( *SetPublicNetwork )( bool enable );
-};
-
-/*!
- * \brief Radio driver
- *
- * \remark This variable is defined and initialized in the specific radio
- *         board implementation
- */
-extern const struct Radio_s Radio;
-
-#endif // __RADIO_H__
diff --git a/net/lora/node/src/lora_node.c b/net/lora/node/src/lora_node.c
index 55742f497..0b3fadcb8 100644
--- a/net/lora/node/src/lora_node.c
+++ b/net/lora/node/src/lora_node.c
@@ -41,15 +41,6 @@ STATS_NAME_START(lora_mac_stats)
     STATS_NAME(lora_mac_stats, rx_mcps)
 STATS_NAME_END(lora_mac_stats)
 
-STATS_SECT_DECL(lora_stats) lora_stats;
-STATS_NAME_START(lora_stats)
-    STATS_NAME(lora_stats, rx_error)
-    STATS_NAME(lora_stats, rx_success)
-    STATS_NAME(lora_stats, rx_timeout)
-    STATS_NAME(lora_stats, tx_success)
-    STATS_NAME(lora_stats, tx_timeout)
-STATS_NAME_END(lora_stats)
-
 /* Device EUI */
 uint8_t g_lora_dev_eui[LORA_EUI_LEN];
 
@@ -580,12 +571,6 @@ lora_node_init(void)
     LoRaMacCallback_t lora_cb;
 #endif
 
-    rc = stats_init_and_reg(
-        STATS_HDR(lora_stats),
-        STATS_SIZE_INIT_PARMS(lora_stats, STATS_SIZE_32),
-        STATS_NAME_INIT_PARMS(lora_stats), "lora");
-    SYSINIT_PANIC_ASSERT(rc == 0);
-
     rc = stats_init_and_reg(
         STATS_HDR(lora_mac_stats),
         STATS_SIZE_INIT_PARMS(lora_mac_stats, STATS_SIZE_32),
diff --git a/net/lora/node/src/mac/LoRaMac.c b/net/lora/node/src/mac/LoRaMac.c
index 69431ad4b..cbff9d1da 100644
--- a/net/lora/node/src/mac/LoRaMac.c
+++ b/net/lora/node/src/mac/LoRaMac.c
@@ -20,7 +20,6 @@ License: Revised BSD License, see LICENSE.TXT file include in 
the project
 
 #include <string.h>
 #include <assert.h>
-#include "node/radio.h"
 #include "node/lora.h"
 #include "radio/radio.h"
 #include "node/utilities.h"
@@ -37,6 +36,14 @@ License: Revised BSD License, see LICENSE.TXT file include 
in the project
 #define LORA_MAC_TIMER_NUM    MYNEWT_VAL(LORA_MAC_TIMER_NUM)
 #endif
 
+/*
+ * XXX: TODO. This is radio dependent! Need to put this in driver. For
+ * now, just use SX1276 time
+ */
+#ifndef RADIO_WAKEUP_TIME
+#define RADIO_WAKEUP_TIME       (3)
+#endif
+
 /* The lora mac timer counts in 1 usec increments */
 #define LORA_MAC_TIMER_FREQ     1000000
 
diff --git a/net/lora/node/src/utilities.c b/net/lora/node/src/utilities.c
index 59ecee1da..308d66d3b 100644
--- a/net/lora/node/src/utilities.c
+++ b/net/lora/node/src/utilities.c
@@ -30,30 +30,6 @@ randr(int32_t min, int32_t max)
     return rand() % (max - min + 1) + min;
 }
 
-double
-ceil(double d)
-{
-    int64_t i;
-
-    i = d;
-    if (d == i) {
-        return i;
-    }
-    return i + 1;
-}
-
-double
-floor(double d)
-{
-    return (int64_t)d;
-}
-
-double
-round(double d)
-{
-    return (int64_t)(d + 0.5);
-}
-
 uint32_t
 TimerGetElapsedTime(uint32_t savedTime)
 {


 

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to