You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ja...@apache.org on 2017/05/08 14:31:56 UTC
[01/40] incubator-mynewt-core git commit: MYNEWT-738: Fix parameter
array errors
Repository: incubator-mynewt-core
Updated Branches:
refs/heads/bluetooth5 4cab05214 -> 958bce0a5
MYNEWT-738: Fix parameter array errors
Fix number of completed packet events
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/af6fb7e0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/af6fb7e0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/af6fb7e0
Branch: refs/heads/bluetooth5
Commit: af6fb7e052873dee489ebe73e3b52f867ba3e255
Parents: 271ab1b
Author: William San Filippo <wi...@runtime.io>
Authored: Sun Apr 23 16:40:46 2017 -0700
Committer: William San Filippo <wi...@runtime.io>
Committed: Sun Apr 23 16:40:46 2017 -0700
----------------------------------------------------------------------
net/nimble/controller/src/ble_ll_conn_hci.c | 12 ++----------
net/nimble/host/src/ble_hs_dbg.c | 7 ++-----
net/nimble/host/src/ble_hs_hci_evt.c | 5 +++--
3 files changed, 7 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/af6fb7e0/net/nimble/controller/src/ble_ll_conn_hci.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_conn_hci.c b/net/nimble/controller/src/ble_ll_conn_hci.c
index 80e7adc..bd235e7 100644
--- a/net/nimble/controller/src/ble_ll_conn_hci.c
+++ b/net/nimble/controller/src/ble_ll_conn_hci.c
@@ -250,7 +250,6 @@ ble_ll_conn_num_comp_pkts_event_send(struct ble_ll_conn_sm *connsm)
int event_sent;
uint8_t *evbuf;
uint8_t *handle_ptr;
- uint8_t *comp_pkt_ptr;
uint8_t handles;
if (connsm == NULL) {
@@ -291,7 +290,6 @@ skip_conn:
evbuf = NULL;
handles = 0;
handle_ptr = NULL;
- comp_pkt_ptr = NULL;
event_sent = 0;
SLIST_FOREACH(connsm, &g_ble_ll_conn_active_list, act_sle) {
/*
@@ -308,15 +306,13 @@ skip_conn:
}
handles = 0;
handle_ptr = evbuf + 3;
- comp_pkt_ptr = handle_ptr + (sizeof(uint16_t) * max_handles);
}
/* Add handle and complete packets */
put_le16(handle_ptr, connsm->conn_handle);
- put_le16(comp_pkt_ptr, connsm->completed_pkts);
+ put_le16(handle_ptr + 2, connsm->completed_pkts);
connsm->completed_pkts = 0;
- handle_ptr += sizeof(uint16_t);
- comp_pkt_ptr += sizeof(uint16_t);
+ handle_ptr += (2 * sizeof(uint16_t));
++handles;
/* Send now if the buffer is full. */
@@ -337,10 +333,6 @@ skip_conn:
evbuf[0] = BLE_HCI_EVCODE_NUM_COMP_PKTS;
evbuf[1] = (handles * 2 * sizeof(uint16_t)) + 1;
evbuf[2] = handles;
- if (handles < max_handles) {
- /* Make the pkt counts contiguous with handles */
- memmove(handle_ptr, evbuf + 3 + (max_handles * 2), handles * 2);
- }
ble_ll_hci_event_send(evbuf);
event_sent = 1;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/af6fb7e0/net/nimble/host/src/ble_hs_dbg.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_dbg.c b/net/nimble/host/src/ble_hs_dbg.c
index 77c84f1..34ec884 100644
--- a/net/nimble/host/src/ble_hs_dbg.c
+++ b/net/nimble/host/src/ble_hs_dbg.c
@@ -247,7 +247,6 @@ ble_hs_dbg_num_comp_pkts_disp(uint8_t *evdata, uint8_t len)
{
uint8_t handles;
uint8_t *handle_ptr;
- uint8_t *pkt_ptr;
uint16_t handle;
uint16_t pkts;
@@ -263,12 +262,10 @@ ble_hs_dbg_num_comp_pkts_disp(uint8_t *evdata, uint8_t len)
handles);
if (handles) {
handle_ptr = evdata + 1;
- pkt_ptr = handle_ptr + (2 * handles);
while (handles) {
handle = get_le16(handle_ptr);
- handle_ptr += 2;
- pkts = get_le16(pkt_ptr);
- pkt_ptr += 2;
+ pkts = get_le16(handle_ptr + 2);
+ handle_ptr += 4;
BLE_HS_LOG(DEBUG, "handle:%u pkts:%u\n", handle, pkts);
--handles;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/af6fb7e0/net/nimble/host/src/ble_hs_hci_evt.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_hci_evt.c b/net/nimble/host/src/ble_hs_hci_evt.c
index a9655e3..d7cca0e 100644
--- a/net/nimble/host/src/ble_hs_hci_evt.c
+++ b/net/nimble/host/src/ble_hs_hci_evt.c
@@ -219,8 +219,9 @@ ble_hs_hci_evt_num_completed_pkts(uint8_t event_code, uint8_t *data, int len)
off++;
for (i = 0; i < num_handles; i++) {
- handle = get_le16(data + off + 2 * i);
- num_pkts = get_le16(data + off + 2 * num_handles + 2 * i);
+ handle = get_le16(data + off);
+ num_pkts = get_le16(data + off + 2);
+ off += (2 * sizeof(uint16_t));
/* XXX: Do something with these values. */
(void)handle;
[19/40] incubator-mynewt-core git commit: MYNEWT-741 Port of
LoRaMac-node library
Posted by ja...@apache.org.
MYNEWT-741 Port of LoRaMac-node library
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/9986f68c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/9986f68c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/9986f68c
Branch: refs/heads/bluetooth5
Commit: 9986f68cdf2f9a81bf67076d220e60bf64f56450
Parents: 8374b5a
Author: Christopher Collins <cc...@apache.org>
Authored: Mon Apr 24 19:18:10 2017 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Fri Apr 28 17:27:51 2017 -0700
----------------------------------------------------------------------
apps/loraping/pkg.yml | 47 +
apps/loraping/src/loraping.h | 27 +
apps/loraping/src/main.c | 279 ++
apps/loraping/src/rxinfo.c | 139 +
apps/lorashell/pkg.yml | 34 +
apps/lorashell/src/main.c | 453 ++
apps/lorashell/syscfg.yml | 27 +
hw/bsp/telee02/pkg.yml | 4 +
hw/drivers/lora/node/board/nrf52/LICENSE.txt | 25 +
.../lora/node/board/nrf52/include/board/board.h | 92 +
hw/drivers/lora/node/board/nrf52/pkg.yml | 34 +
.../lora/node/board/nrf52/src/lora_nrf52.c | 44 +
hw/drivers/lora/node/board/nrf52/syscfg.yml | 27 +
hw/drivers/lora/node/radio/sx1276/LICENSE.txt | 25 +
.../node/radio/sx1276/include/radio/radio.h | 33 +
hw/drivers/lora/node/radio/sx1276/pkg.yml | 35 +
.../lora/node/radio/sx1276/src/sx1276-board.c | 163 +
.../lora/node/radio/sx1276/src/sx1276-board.h | 119 +
hw/drivers/lora/node/radio/sx1276/src/sx1276.c | 1826 +++++++
hw/drivers/lora/node/radio/sx1276/src/sx1276.h | 364 ++
.../lora/node/radio/sx1276/src/sx1276Regs-Fsk.h | 1134 +++++
.../node/radio/sx1276/src/sx1276Regs-LoRa.h | 565 +++
net/lora/node/LICENSE.txt | 25 +
net/lora/node/README.md | 28 +
net/lora/node/include/node/lora.h | 34 +
.../node/include/node/mac/LoRaMac-definitions.h | 610 +++
net/lora/node/include/node/mac/LoRaMac.h | 1830 ++++++++
net/lora/node/include/node/mac/LoRaMacCrypto.h | 111 +
net/lora/node/include/node/mac/LoRaMacTest.h | 81 +
net/lora/node/include/node/radio.h | 337 ++
net/lora/node/include/node/timer.h | 38 +
net/lora/node/include/node/utilities.h | 72 +
net/lora/node/pkg.yml | 42 +
net/lora/node/src/lora_cli.c | 569 +++
net/lora/node/src/lora_node.c | 48 +
net/lora/node/src/lora_priv.h | 44 +
net/lora/node/src/mac/LoRaMac.c | 4439 ++++++++++++++++++
net/lora/node/src/mac/LoRaMacCrypto.c | 203 +
net/lora/node/src/mac/aes.h | 160 +
net/lora/node/src/mac/cmac.h | 63 +
net/lora/node/src/misc.c | 45 +
net/lora/node/src/timer.c | 15 +
net/lora/node/syscfg.yml | 39 +
43 files changed, 14329 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9986f68c/apps/loraping/pkg.yml
----------------------------------------------------------------------
diff --git a/apps/loraping/pkg.yml b/apps/loraping/pkg.yml
new file mode 100644
index 0000000..07c3060
--- /dev/null
+++ b/apps/loraping/pkg.yml
@@ -0,0 +1,47 @@
+#
+# 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.
+#
+
+pkg.name: apps/loraping
+pkg.type: app
+pkg.description: "Example application which uses a variety of mynewt features."
+pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+
+pkg.deps:
+ - "@apache-mynewt-core/boot/bootutil"
+ - "@apache-mynewt-core/boot/split"
+ - "@apache-mynewt-core/kernel/os"
+ - "@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"
+ - "@apache-mynewt-core/sys/log/full"
+ - "@apache-mynewt-core/sys/shell"
+ - "@apache-mynewt-core/sys/stats/full"
+ - "@apache-mynewt-core/test/flash_test"
+
+pkg.deps.CONFIG_NFFS:
+ - fs/nffs
+
+pkg.deps.CONFIG_FCB:
+ - fs/fcb
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9986f68c/apps/loraping/src/loraping.h
----------------------------------------------------------------------
diff --git a/apps/loraping/src/loraping.h b/apps/loraping/src/loraping.h
new file mode 100644
index 0000000..4b28e7a
--- /dev/null
+++ b/apps/loraping/src/loraping.h
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ */
+
+#ifndef H_LORAPING_
+#define H_LORAPING_
+
+void loraping_rxinfo_print(void);
+void loraping_rxinfo_timeout(void);
+void loraping_rxinfo_rxed(int8_t rssi, int8_t snr);
+
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9986f68c/apps/loraping/src/main.c
----------------------------------------------------------------------
diff --git a/apps/loraping/src/main.c b/apps/loraping/src/main.c
new file mode 100644
index 0000000..7c5ef8e
--- /dev/null
+++ b/apps/loraping/src/main.c
@@ -0,0 +1,279 @@
+/*
+Copyright (c) 2013, SEMTECH S.A.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of the Semtech corporation nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL SEMTECH S.A. BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+Description: Ping-Pong implementation. Adapted to run in the MyNewt OS.
+*/
+
+#include <string.h>
+#include "sysinit/sysinit.h"
+#include "syscfg/syscfg.h"
+#include "hal/hal_gpio.h"
+#include "hal/hal_spi.h"
+#include "bsp/bsp.h"
+#include "os/os.h"
+#include "board/board.h"
+#include "node/radio.h"
+#include "loraping.h"
+
+#define LORAPING_SPI_BAUDRATE 500
+#define USE_BAND_915
+
+#if defined(USE_BAND_433)
+
+#define RF_FREQUENCY 434000000 /* Hz */
+
+#elif defined(USE_BAND_780)
+
+#define RF_FREQUENCY 780000000 /* Hz */
+
+#elif defined(USE_BAND_868)
+
+#define RF_FREQUENCY 868000000 /* Hz */
+
+#elif defined(USE_BAND_915)
+
+#define RF_FREQUENCY 915000000 /* Hz */
+
+#else
+ #error "Please define a frequency band in the compiler options."
+#endif
+
+#define LORAPING_TX_OUTPUT_POWER 14 /* dBm */
+
+#define LORAPING_BANDWIDTH 0 /* [0: 125 kHz, */
+ /* 1: 250 kHz, */
+ /* 2: 500 kHz, */
+ /* 3: Reserved] */
+#define LORAPING_SPREADING_FACTOR 7 /* [SF7..SF12] */
+#define LORAPING_CODINGRATE 1 /* [1: 4/5, */
+ /* 2: 4/6, */
+ /* 3: 4/7, */
+ /* 4: 4/8] */
+#define LORAPING_PREAMBLE_LENGTH 8 /* Same for Tx and Rx */
+#define LORAPING_SYMBOL_TIMEOUT 5 /* Symbols */
+#define LORAPING_FIX_LENGTH_PAYLOAD_ON false
+#define LORAPING_IQ_INVERSION_ON false
+
+#define LORAPING_TX_TIMEOUT_MS 3000 /* ms */
+#define LORAPING_RX_TIMEOUT_MS 1000 /* ms */
+#define LORAPING_BUFFER_SIZE 64
+
+const uint8_t loraping_ping_msg[] = "PING";
+const uint8_t loraping_pong_msg[] = "PONG";
+
+static uint8_t loraping_buffer[LORAPING_BUFFER_SIZE];
+static int loraping_rx_size;
+static int loraping_is_master = 1;
+
+struct {
+ int rx_timeout;
+ int rx_ping;
+ int rx_pong;
+ int rx_other;
+ int rx_error;
+ int tx_timeout;
+ int tx_success;
+} loraping_stats;
+
+static void loraping_tx(struct os_event *ev);
+static void loraping_rx(struct os_event *ev);
+
+static struct os_event loraping_ev_tx = {
+ .ev_cb = loraping_tx,
+};
+static struct os_event loraping_ev_rx = {
+ .ev_cb = loraping_rx,
+};
+
+static void
+send_once(int is_ping)
+{
+ int i;
+
+ if (is_ping) {
+ memcpy(loraping_buffer, loraping_ping_msg, 4);
+ } else {
+ memcpy(loraping_buffer, loraping_pong_msg, 4);
+ }
+ for (i = 4; i < sizeof loraping_buffer; i++) {
+ loraping_buffer[i] = i - 4;
+ }
+
+ Radio.Send(loraping_buffer, sizeof loraping_buffer);
+}
+
+static void
+loraping_tx(struct os_event *ev)
+{
+ /* Print information about last rx attempt. */
+ loraping_rxinfo_print();
+
+ if (loraping_rx_size == 0) {
+ /* Timeout. */
+ } else {
+ os_time_delay(1);
+ if (memcmp(loraping_buffer, loraping_pong_msg, 4) == 0) {
+ loraping_stats.rx_ping++;
+ } else if (memcmp(loraping_buffer, loraping_ping_msg, 4) == 0) {
+ loraping_stats.rx_pong++;
+
+ /* A master already exists. Become a slave. */
+ loraping_is_master = 0;
+ } else {
+ /* Valid reception but neither a PING nor a PONG message. */
+ loraping_stats.rx_other++;
+ /* Set device as master and start again. */
+ loraping_is_master = 1;
+ }
+ }
+
+ loraping_rx_size = 0;
+ send_once(loraping_is_master);
+}
+
+static void
+loraping_rx(struct os_event *ev)
+{
+ Radio.Rx(LORAPING_RX_TIMEOUT_MS);
+}
+
+static void
+on_tx_done(void)
+{
+ loraping_stats.tx_success++;
+ Radio.Sleep();
+
+ os_eventq_put(os_eventq_dflt_get(), &loraping_ev_rx);
+}
+
+static void
+on_rx_done(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr)
+{
+ Radio.Sleep();
+
+ if (size > sizeof loraping_buffer) {
+ size = sizeof loraping_buffer;
+ }
+
+ loraping_rx_size = size;
+ memcpy(loraping_buffer, payload, size);
+
+ loraping_rxinfo_rxed(rssi, snr);
+
+ os_eventq_put(os_eventq_dflt_get(), &loraping_ev_tx);
+}
+
+static void
+on_tx_timeout(void)
+{
+ Radio.Sleep();
+
+ loraping_stats.tx_timeout++;
+
+ os_eventq_put(os_eventq_dflt_get(), &loraping_ev_rx);
+}
+
+static void
+on_rx_timeout(void)
+{
+ Radio.Sleep();
+
+ loraping_stats.rx_timeout++;
+ loraping_rxinfo_timeout();
+
+ os_eventq_put(os_eventq_dflt_get(), &loraping_ev_tx);
+}
+
+static void
+on_rx_error(void)
+{
+ loraping_stats.rx_error++;
+ Radio.Sleep();
+
+ os_eventq_put(os_eventq_dflt_get(), &loraping_ev_tx);
+}
+
+int
+main(void)
+{
+ RadioEvents_t radio_events;
+
+#ifdef ARCH_sim
+ mcu_sim_parse_args(argc, argv);
+#endif
+
+ sysinit();
+
+ /* Radio initialization. */
+ radio_events.TxDone = on_tx_done;
+ radio_events.RxDone = on_rx_done;
+ radio_events.TxTimeout = on_tx_timeout;
+ radio_events.RxTimeout = on_rx_timeout;
+ radio_events.RxError = on_rx_error;
+
+ Radio.Init(&radio_events);
+
+ Radio.SetChannel(RF_FREQUENCY);
+
+ Radio.SetTxConfig(MODEM_LORA,
+ LORAPING_TX_OUTPUT_POWER,
+ 0, /* Frequency deviation; unused with LoRa. */
+ LORAPING_BANDWIDTH,
+ LORAPING_SPREADING_FACTOR,
+ LORAPING_CODINGRATE,
+ LORAPING_PREAMBLE_LENGTH,
+ LORAPING_FIX_LENGTH_PAYLOAD_ON,
+ true, /* CRC enabled. */
+ 0, /* Frequency hopping disabled. */
+ 0, /* Hop period; N/A. */
+ LORAPING_IQ_INVERSION_ON,
+ LORAPING_TX_TIMEOUT_MS);
+
+ Radio.SetRxConfig(MODEM_LORA,
+ LORAPING_BANDWIDTH,
+ LORAPING_SPREADING_FACTOR,
+ LORAPING_CODINGRATE,
+ 0, /* AFC bandwisth; unused with LoRa. */
+ LORAPING_PREAMBLE_LENGTH,
+ LORAPING_SYMBOL_TIMEOUT,
+ LORAPING_FIX_LENGTH_PAYLOAD_ON,
+ 0, /* Fixed payload length; N/A. */
+ true, /* CRC enabled. */
+ 0, /* Frequency hopping disabled. */
+ 0, /* Hop period; N/A. */
+ LORAPING_IQ_INVERSION_ON,
+ true); /* Continuous receive mode. */
+
+ /* Immediately receive on start up. */
+ os_eventq_put(os_eventq_dflt_get(), &loraping_ev_rx);
+
+ /*
+ * As the last thing, process events from default event queue.
+ */
+ while (1) {
+ os_eventq_run(os_eventq_dflt_get());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9986f68c/apps/loraping/src/rxinfo.c
----------------------------------------------------------------------
diff --git a/apps/loraping/src/rxinfo.c b/apps/loraping/src/rxinfo.c
new file mode 100644
index 0000000..71c1de8
--- /dev/null
+++ b/apps/loraping/src/rxinfo.c
@@ -0,0 +1,139 @@
+/*
+ * 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.
+ */
+
+/**
+ * This file contains code to collect and print receive statistics to the
+ * console.
+ */
+
+#include <assert.h>
+#include <string.h>
+#include <stdint.h>
+
+#include "console/console.h"
+#include "loraping.h"
+
+#define LORAPING_NUM_RXINFOS 10
+
+struct loraping_rxinfo {
+ int8_t rssi;
+ int8_t snr;
+
+ uint8_t rxed:1;
+};
+
+static struct loraping_rxinfo loraping_rxinfos[LORAPING_NUM_RXINFOS];
+static int loraping_rxinfo_idx;
+static int loraping_rxinfo_rollover;
+
+static void
+loraping_rxinfo_avg(struct loraping_rxinfo *out_info, int *out_pkt_loss)
+{
+ long long rssi_sum;
+ long long snr_sum;
+ int num_rxed;
+ int count;
+ int i;
+
+ if (!loraping_rxinfo_rollover) {
+ count = loraping_rxinfo_idx;
+ } else {
+ count = LORAPING_NUM_RXINFOS;
+ }
+
+ assert(count > 0);
+
+ rssi_sum = 0;
+ snr_sum = 0;
+ num_rxed = 0;
+ for (i = 0; i < count; i++) {
+ if (loraping_rxinfos[i].rxed) {
+ num_rxed++;
+ rssi_sum += loraping_rxinfos[i].rssi;
+ snr_sum += loraping_rxinfos[i].snr;
+ }
+ }
+
+ memset(out_info, 0, sizeof *out_info);
+ if (num_rxed > 0) {
+ out_info->rssi = rssi_sum / num_rxed;
+ out_info->snr = snr_sum / num_rxed;
+ }
+
+ *out_pkt_loss = (count - num_rxed) * 10000 / count;
+}
+
+static void
+loraping_rxinfo_inc_idx(void)
+{
+ loraping_rxinfo_idx++;
+ if (loraping_rxinfo_idx >= LORAPING_NUM_RXINFOS) {
+ loraping_rxinfo_idx = 0;
+ loraping_rxinfo_rollover = 1;
+ }
+}
+
+void
+loraping_rxinfo_print(void)
+{
+ const struct loraping_rxinfo *last;
+ struct loraping_rxinfo avg;
+ int last_idx;
+ int pkt_loss;
+ int width;
+
+ last_idx = loraping_rxinfo_idx - 1;
+ if (last_idx < 0) {
+ last_idx += LORAPING_NUM_RXINFOS;
+ }
+ last = loraping_rxinfos + last_idx;
+
+ loraping_rxinfo_avg(&avg, &pkt_loss);
+
+ if (last->rxed) {
+ width = console_printf("[LAST] rssi=%-4d snr=%-4d",
+ last->rssi, last->snr);
+ } else {
+ width = console_printf("[LAST] TIMEOUT");
+ }
+
+ for (; width < 48; width++) {
+ console_printf(" ");
+ }
+
+ console_printf("[AVG-%d] rssi=%-4d snr=%-4d pkt_loss=%d.%02d%%\n",
+ LORAPING_NUM_RXINFOS, avg.rssi, avg.snr,
+ pkt_loss / 100, pkt_loss % 100);
+}
+
+void
+loraping_rxinfo_timeout(void)
+{
+ loraping_rxinfos[loraping_rxinfo_idx].rxed = 0;
+ loraping_rxinfo_inc_idx();
+}
+
+void
+loraping_rxinfo_rxed(int8_t rssi, int8_t snr)
+{
+ loraping_rxinfos[loraping_rxinfo_idx].rssi = rssi;
+ loraping_rxinfos[loraping_rxinfo_idx].snr = snr;
+ loraping_rxinfos[loraping_rxinfo_idx].rxed = 1;
+ loraping_rxinfo_inc_idx();
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9986f68c/apps/lorashell/pkg.yml
----------------------------------------------------------------------
diff --git a/apps/lorashell/pkg.yml b/apps/lorashell/pkg.yml
new file mode 100644
index 0000000..898f5d2
--- /dev/null
+++ b/apps/lorashell/pkg.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.
+#
+
+pkg.name: apps/lorashell
+pkg.type: app
+pkg.description: "Example application which uses a variety of mynewt features."
+pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+
+pkg.deps:
+ - "@apache-mynewt-core/kernel/os"
+ - "@apache-mynewt-core/net/lora/node"
+ - "@apache-mynewt-core/sys/console/full"
+ - "@apache-mynewt-core/sys/log/full"
+ - "@apache-mynewt-core/sys/shell"
+ - "@apache-mynewt-core/sys/stats/full"
+ - "@apache-mynewt-core/util/parse"
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9986f68c/apps/lorashell/src/main.c
----------------------------------------------------------------------
diff --git a/apps/lorashell/src/main.c b/apps/lorashell/src/main.c
new file mode 100644
index 0000000..7f12578
--- /dev/null
+++ b/apps/lorashell/src/main.c
@@ -0,0 +1,453 @@
+/*
+ * 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.
+ */
+
+/**
+ * A simple app for LoRa phy testing. A typical usage scenario is:
+ *
+ * ##### Receiver
+ * # Sit on a single channel.
+ * lora set_freq 915000000
+ *
+ * # Allow 250-byte packets.
+ * lora max_payload_len 1 250
+ *
+ * # Configure LoRa receiver (specify no arguments for usage).
+ * lora rx_cfg 1 0 7 1 0 8 5 0 0 1 0 0 0 1
+ *
+ * # Print message on each receive.
+ * lora_rx_verbose 1
+ *
+ * # Keep receiving until manual stop.
+ * lora_rx_rpt
+ *
+ * # Display information about recent receives.
+ * lora_rx_info
+ *
+ * ##### Transceiver
+ * # Sit on a single channel.
+ * lora set_freq 915000000
+ *
+ * # Allow 250-byte packets.
+ * lora max_payload_len 1 250
+ *
+ * # Configure LoRa transceiver (specify no arguments for usage).
+ * lora tx_cfg 1 14 0 0 7 1 8 0 1 0 0 0 3000
+ *
+ * # Send; size=50, count=5, interval=100ms.
+ * lora_tx_rpt 50 5 100
+ */
+
+#include <string.h>
+#include <limits.h>
+#include "sysinit/sysinit.h"
+#include "syscfg/syscfg.h"
+#include "hal/hal_gpio.h"
+#include "hal/hal_spi.h"
+#include "bsp/bsp.h"
+#include "os/os.h"
+#include "board/board.h"
+#include "node/radio.h"
+#include "console/console.h"
+#include "shell/shell.h"
+#include "parse/parse.h"
+
+struct lorashell_rx_entry {
+ uint16_t size;
+ int16_t rssi;
+ int8_t snr;
+};
+
+static struct lorashell_rx_entry
+ lorashell_rx_entries[MYNEWT_VAL(LORASHELL_NUM_RX_ENTRIES)];
+static int lorashell_rx_entry_idx;
+static int lorashell_rx_entry_cnt;
+
+static int lorashell_rx_rpt;
+static int lorashell_rx_verbose;
+static int lorashell_txes_pending;
+static uint8_t lorashell_tx_size;
+static uint32_t lorashell_tx_itvl; /* OS ticks. */
+
+static int lorashell_rx_info_cmd(int argc, char **argv);
+static int lorashell_rx_rpt_cmd(int argc, char **argv);
+static int lorashell_rx_verbose_cmd(int argc, char **argv);
+static int lorashell_tx_rpt_cmd(int argc, char **argv);
+
+static void lorashell_print_last_rx(struct os_event *ev);
+
+static struct shell_cmd lorashell_cli_cmds[] = {
+ {
+ .sc_cmd = "lora_rx_info",
+ .sc_cmd_func = lorashell_rx_info_cmd,
+ },
+ {
+ .sc_cmd = "lora_rx_rpt",
+ .sc_cmd_func = lorashell_rx_rpt_cmd,
+ },
+ {
+ .sc_cmd = "lora_rx_verbose",
+ .sc_cmd_func = lorashell_rx_verbose_cmd,
+ },
+ {
+ .sc_cmd = "lora_tx_rpt",
+ .sc_cmd_func = lorashell_tx_rpt_cmd,
+ },
+};
+#define LORASHELL_NUM_CLI_CMDS \
+ (sizeof lorashell_cli_cmds / sizeof lorashell_cli_cmds[0])
+
+static struct os_event lorashell_print_last_rx_ev = {
+ .ev_cb = lorashell_print_last_rx,
+};
+static struct os_callout lorashell_tx_timer;
+
+static void
+lorashell_rx_rpt_begin(void)
+{
+ Radio.Rx(0);
+}
+
+static void
+lorashell_tx_timer_exp(struct os_event *ev)
+{
+ static uint8_t start_byte;
+
+ uint8_t buf[UINT8_MAX];
+ uint8_t b;
+ int i;
+
+ if (lorashell_txes_pending <= 0) {
+ Radio.Sleep();
+ return;
+ }
+ lorashell_txes_pending--;
+
+ b = start_byte++;
+ for (i = 0; i < lorashell_tx_size; i++) {
+ buf[i] = b++;
+ }
+
+ Radio.Send(buf, lorashell_tx_size);
+}
+
+static const char *
+lorashell_rx_entry_str(const struct lorashell_rx_entry *entry)
+{
+ static char buf[32];
+
+ snprintf(buf, sizeof buf, "size=%-4d rssi=%-4d snr=%-4d",
+ entry->size, entry->rssi, entry->snr);
+ return buf;
+}
+
+static void
+lorashell_tx_timer_reset(void)
+{
+ int rc;
+
+ rc = os_callout_reset(&lorashell_tx_timer, lorashell_tx_itvl);
+ assert(rc == 0);
+}
+
+static void
+on_tx_done(void)
+{
+ if (lorashell_txes_pending <= 0) {
+ Radio.Sleep();
+ } else {
+ lorashell_tx_timer_reset();
+ }
+}
+
+static void
+on_rx_done(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr)
+{
+
+ struct lorashell_rx_entry *entry;
+
+ if (!lorashell_rx_rpt) {
+ Radio.Sleep();
+ } else {
+ lorashell_rx_rpt_begin();
+ }
+
+ entry = lorashell_rx_entries + lorashell_rx_entry_idx;
+ entry->size = size;
+ entry->rssi = rssi;
+ entry->snr = snr;
+
+ if (lorashell_rx_verbose) {
+ os_eventq_put(os_eventq_dflt_get(), &lorashell_print_last_rx_ev);
+ }
+
+ lorashell_rx_entry_idx++;
+ if (lorashell_rx_entry_idx >= MYNEWT_VAL(LORASHELL_NUM_RX_ENTRIES)) {
+ lorashell_rx_entry_idx = 0;
+ }
+
+ if (lorashell_rx_entry_cnt < MYNEWT_VAL(LORASHELL_NUM_RX_ENTRIES)) {
+ lorashell_rx_entry_cnt++;
+ }
+}
+
+static void
+on_tx_timeout(void)
+{
+ assert(0);
+ lorashell_tx_timer_reset();
+}
+
+static void
+on_rx_timeout(void)
+{
+ Radio.Sleep();
+}
+
+static void
+on_rx_error(void)
+{
+ Radio.Sleep();
+}
+
+static void
+lorashell_print_last_rx(struct os_event *ev)
+{
+ const struct lorashell_rx_entry *entry;
+ int idx;
+
+ idx = lorashell_rx_entry_idx - 1;
+ if (idx < 0) {
+ idx = lorashell_rx_entry_cnt - 1;
+ }
+
+ entry = lorashell_rx_entries + idx;
+ console_printf("rxed lora packet: %s\n", lorashell_rx_entry_str(entry));
+}
+
+static void
+lorashell_avg_rx_entry(struct lorashell_rx_entry *out_entry)
+{
+ long long rssi_sum;
+ long long size_sum;
+ long long snr_sum;
+ int i;
+
+ rssi_sum = 0;
+ size_sum = 0;
+ snr_sum = 0;
+ for (i = 0; i < lorashell_rx_entry_cnt; i++) {
+ rssi_sum += lorashell_rx_entries[i].rssi;
+ size_sum += lorashell_rx_entries[i].size;
+ snr_sum += lorashell_rx_entries[i].snr;
+ }
+
+ memset(out_entry, 0, sizeof *out_entry);
+ if (lorashell_rx_entry_cnt > 0) {
+ out_entry->size = size_sum / lorashell_rx_entry_cnt;
+ out_entry->rssi = rssi_sum / lorashell_rx_entry_cnt;
+ out_entry->snr = snr_sum / lorashell_rx_entry_cnt;
+ }
+}
+
+static int
+lorashell_rx_rpt_cmd(int argc, char **argv)
+{
+ if (argc > 1 && strcmp(argv[1], "stop") == 0) {
+ lorashell_rx_rpt = 0;
+ Radio.Sleep();
+ console_printf("lora rx stopped\n");
+ return 0;
+ }
+
+ lorashell_rx_rpt = 1;
+ lorashell_rx_rpt_begin();
+
+ return 0;
+}
+
+static int
+lorashell_rx_verbose_cmd(int argc, char **argv)
+{
+ int rc;
+
+ if (argc <= 1) {
+ console_printf("lora rx verbose: %d\n", lorashell_rx_verbose);
+ return 0;
+ }
+
+ lorashell_rx_verbose = parse_ull_bounds(argv[1], 0, 1, &rc);
+ if (rc != 0) {
+ console_printf("error: rc=%d\n", rc);
+ return rc;
+ }
+
+ return 0;
+}
+
+static int
+lorashell_rx_info_cmd(int argc, char **argv)
+{
+ const struct lorashell_rx_entry *entry;
+ struct lorashell_rx_entry avg;
+ int idx;
+ int i;
+
+ if (argc > 1 && argv[1][0] == 'c') {
+ lorashell_rx_entry_idx = 0;
+ lorashell_rx_entry_cnt = 0;
+ console_printf("lora rx info cleared\n");
+ return 0;
+ }
+
+ if (lorashell_rx_entry_cnt < MYNEWT_VAL(LORASHELL_NUM_RX_ENTRIES)) {
+ idx = 0;
+ } else {
+ idx = lorashell_rx_entry_idx;
+ }
+
+ console_printf("entries in log: %d\n", lorashell_rx_entry_cnt);
+
+ for (i = 0; i < lorashell_rx_entry_cnt; i++) {
+ entry = lorashell_rx_entries + idx;
+ console_printf("%4d: %s\n", i + 1, lorashell_rx_entry_str(entry));
+
+ idx++;
+ if (idx >= MYNEWT_VAL(LORASHELL_NUM_RX_ENTRIES)) {
+ idx = 0;
+ }
+ }
+
+ if (lorashell_rx_entry_cnt > 0) {
+ lorashell_avg_rx_entry(&avg);
+ console_printf(" avg: %s\n", lorashell_rx_entry_str(&avg));
+ }
+
+ return 0;
+}
+
+static int
+lorashell_tx_rpt_cmd(int argc, char **argv)
+{
+ const char *err;
+ uint32_t itvl_ms;
+ int rc;
+
+ if (argc < 1) {
+ rc = 1;
+ err = NULL;
+ goto err;
+ }
+
+ if (strcmp(argv[1], "stop") == 0) {
+ lorashell_txes_pending = 0;
+ Radio.Sleep();
+ console_printf("lora tx stopped\n");
+ return 0;
+ }
+
+ lorashell_tx_size = parse_ull_bounds(argv[1], 0, UINT8_MAX, &rc);
+ if (rc != 0) {
+ err = "invalid size";
+ goto err;
+ }
+
+ if (argc >= 2) {
+ lorashell_txes_pending = parse_ull_bounds(argv[2], 0, INT_MAX, &rc);
+ if (rc != 0) {
+ err = "invalid count";
+ goto err;
+ }
+ } else {
+ lorashell_txes_pending = 1;
+ }
+
+ if (argc >= 3) {
+ itvl_ms = parse_ull_bounds(argv[3], 0, UINT32_MAX, &rc);
+ if (rc != 0) {
+ err = "invalid interval";
+ goto err;
+ }
+ } else {
+ itvl_ms = 1000;
+ }
+
+ rc = os_time_ms_to_ticks(itvl_ms, &lorashell_tx_itvl);
+ if (rc != 0) {
+ err = "invalid interval";
+ goto err;
+ }
+
+ lorashell_tx_timer_exp(NULL);
+
+ return 0;
+
+err:
+ if (err != NULL) {
+ console_printf("error: %s\n", err);
+ }
+
+ console_printf(
+"usage:\n"
+" lora_tx_rpt <size> [count] [interval (ms)]\n"
+" lora_tx_rpt stop\n");
+
+ return rc;
+}
+
+int
+main(void)
+{
+ RadioEvents_t radio_events;
+ int rc;
+ int i;
+
+#ifdef ARCH_sim
+ mcu_sim_parse_args(argc, argv);
+#endif
+
+ sysinit();
+
+ for (i = 0; i < LORASHELL_NUM_CLI_CMDS; i++) {
+ rc = shell_cmd_register(lorashell_cli_cmds + i);
+ SYSINIT_PANIC_ASSERT_MSG(
+ rc == 0, "Failed to register lorashell CLI commands");
+ }
+
+ os_callout_init(&lorashell_tx_timer, os_eventq_dflt_get(),
+ lorashell_tx_timer_exp, NULL);
+
+ /* Radio initialization. */
+ radio_events.TxDone = on_tx_done;
+ radio_events.RxDone = on_rx_done;
+ radio_events.TxTimeout = on_tx_timeout;
+ radio_events.RxTimeout = on_rx_timeout;
+ radio_events.RxError = on_rx_error;
+
+ Radio.Init(&radio_events);
+ Radio.SetMaxPayloadLength(MODEM_LORA, 250);
+
+ console_printf("lorashell\n");
+
+ /*
+ * As the last thing, process events from default event queue.
+ */
+ while (1) {
+ os_eventq_run(os_eventq_dflt_get());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9986f68c/apps/lorashell/syscfg.yml
----------------------------------------------------------------------
diff --git a/apps/lorashell/syscfg.yml b/apps/lorashell/syscfg.yml
new file mode 100644
index 0000000..ba7ce41
--- /dev/null
+++ b/apps/lorashell/syscfg.yml
@@ -0,0 +1,27 @@
+#
+# 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:
+ LORASHELL_NUM_RX_ENTRIES:
+ description: "The size of the receive log."
+ value: 10
+
+syscfg.vals:
+ STATS_CLI: 1
+ STATS_NAMES: 1
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9986f68c/hw/bsp/telee02/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/telee02/pkg.yml b/hw/bsp/telee02/pkg.yml
index d1ceebd..0324334 100644
--- a/hw/bsp/telee02/pkg.yml
+++ b/hw/bsp/telee02/pkg.yml
@@ -89,6 +89,10 @@ pkg.deps:
pkg.deps.BLE_DEVICE:
- hw/drivers/nimble/nrf52
+pkg.deps.LORA_NODE:
+ - hw/drivers/lora/node/radio/sx1276
+ - hw/drivers/lora/node/board/nrf52
+
pkg.deps.UART_0:
- hw/drivers/uart/uart_hal
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9986f68c/hw/drivers/lora/node/board/nrf52/LICENSE.txt
----------------------------------------------------------------------
diff --git a/hw/drivers/lora/node/board/nrf52/LICENSE.txt b/hw/drivers/lora/node/board/nrf52/LICENSE.txt
new file mode 100644
index 0000000..82695a7
--- /dev/null
+++ b/hw/drivers/lora/node/board/nrf52/LICENSE.txt
@@ -0,0 +1,25 @@
+--- Revised BSD License ---
+Copyright (c) 2013, SEMTECH S.A.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of the Semtech corporation nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL SEMTECH S.A. BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9986f68c/hw/drivers/lora/node/board/nrf52/include/board/board.h
----------------------------------------------------------------------
diff --git a/hw/drivers/lora/node/board/nrf52/include/board/board.h b/hw/drivers/lora/node/board/nrf52/include/board/board.h
new file mode 100644
index 0000000..7d60c5f
--- /dev/null
+++ b/hw/drivers/lora/node/board/nrf52/include/board/board.h
@@ -0,0 +1,92 @@
+/*
+ / _____) _ | |
+( (____ _____ ____ _| |_ _____ ____| |__
+ \____ \| ___ | (_ _) ___ |/ ___) _ \
+ _____) ) ____| | | || |_| ____( (___| | | |
+(______/|_____)_|_|_| \__)_____)\____)_| |_|
+ (C)2013 Semtech
+
+Description: Target board general functions implementation
+
+License: Revised BSD License, see LICENSE.TXT file include in the project
+
+Maintainer: Miguel Luis and Gregory Cristian
+*/
+#ifndef __BOARD_H__
+#define __BOARD_H__
+
+#include <stdbool.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdint.h>
+#include "bsp/bsp.h"
+#include "node/utilities.h"
+
+/*!
+ * Board MCU pins definitions
+ */
+
+#define RADIO_RESET SX1276_NRESET
+
+#define RADIO_SPI_IDX MYNEWT_VAL(LORA_NODE_BOARD_SPI_IDX)
+
+#if RADIO_SPI_IDX == 0
+#define RADIO_NSS MYNEWT_VAL(SPI_0_MASTER_SS_PIN)
+#else
+#error Invalid LORA_NODE_BOARD_SPI_IDX value
+#endif
+
+#define RADIO_DIO_0 SX1276_DIO0
+#define RADIO_DIO_1 SX1276_DIO1
+#define RADIO_DIO_2 SX1276_DIO2
+#define RADIO_DIO_3 SX1276_DIO3
+#define RADIO_DIO_4 SX1276_DIO4
+#define RADIO_DIO_5 SX1276_DIO5
+
+#define RADIO_ANT_SWITCH_HF SX1276_ANT_HF_CTRL
+
+#define RF_RXTX SX1276_RXTX
+
+/*!
+ * Possible power sources
+ */
+enum BoardPowerSources
+{
+ USB_POWER = 0,
+ BATTERY_POWER,
+};
+
+/*!
+ * \brief Get the current battery level
+ *
+ * \retval value battery level [ 0: USB,
+ * 1: Min level,
+ * x: level
+ * 254: fully charged,
+ * 255: Error]
+ */
+uint8_t BoardGetBatteryLevel( void );
+
+/*!
+ * Returns a pseudo random seed generated using the MCU Unique ID
+ *
+ * \retval seed Generated pseudo random seed
+ */
+uint32_t BoardGetRandomSeed( void );
+
+/*!
+ * \brief Gets the board 64 bits unique ID
+ *
+ * \param [IN] id Pointer to an array that will contain the Unique ID
+ */
+void BoardGetUniqueId( uint8_t *id );
+
+/*!
+ * \brief Get the board power source
+ *
+ * \retval value power source [0: USB_POWER, 1: BATTERY_POWER]
+ */
+uint8_t GetBoardPowerSource( void );
+
+#endif // __BOARD_H__
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9986f68c/hw/drivers/lora/node/board/nrf52/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/drivers/lora/node/board/nrf52/pkg.yml b/hw/drivers/lora/node/board/nrf52/pkg.yml
new file mode 100644
index 0000000..d626845
--- /dev/null
+++ b/hw/drivers/lora/node/board/nrf52/pkg.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.
+#
+
+pkg.name: hw/drivers/lora/node/board/nrf52
+pkg.description: LoRaMac-node board driver for nRF52 systems.
+pkg.author: "Telenor Digital AS"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+ - lora
+pkg.deps:
+ - "@apache-mynewt-core/kernel/os"
+ - "@apache-mynewt-core/net/lora/node"
+
+pkg.apis:
+ - lora_node_board
+
+pkg.init:
+ lora_node_nrf52_init: 100
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9986f68c/hw/drivers/lora/node/board/nrf52/src/lora_nrf52.c
----------------------------------------------------------------------
diff --git a/hw/drivers/lora/node/board/nrf52/src/lora_nrf52.c b/hw/drivers/lora/node/board/nrf52/src/lora_nrf52.c
new file mode 100644
index 0000000..828f5bb
--- /dev/null
+++ b/hw/drivers/lora/node/board/nrf52/src/lora_nrf52.c
@@ -0,0 +1,44 @@
+/*
+ * 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.
+ */
+
+#include "sysinit/sysinit.h"
+#include "syscfg/syscfg.h"
+#include "hal/hal_gpio.h"
+#include "hal/hal_spi.h"
+#include "board/board.h"
+
+void
+lora_node_nrf52_init(void)
+{
+ struct hal_spi_settings spi_settings;
+ int rc;
+
+ hal_gpio_init_out(RADIO_NSS, 1);
+
+ spi_settings.data_order = HAL_SPI_MSB_FIRST;
+ spi_settings.data_mode = HAL_SPI_MODE0;
+ spi_settings.baudrate = MYNEWT_VAL(LORA_NODE_BOARD_SPI_BAUDRATE);
+ spi_settings.word_size = HAL_SPI_WORD_SIZE_8BIT;
+
+ rc = hal_spi_config(RADIO_SPI_IDX, &spi_settings);
+ SYSINIT_PANIC_ASSERT_MSG(rc == 0, "Failed to configure LoRa SPI");
+
+ rc = hal_spi_enable(0);
+ SYSINIT_PANIC_ASSERT_MSG(rc == 0, "Failed to enable LoRa SPI");
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9986f68c/hw/drivers/lora/node/board/nrf52/syscfg.yml
----------------------------------------------------------------------
diff --git a/hw/drivers/lora/node/board/nrf52/syscfg.yml b/hw/drivers/lora/node/board/nrf52/syscfg.yml
new file mode 100644
index 0000000..0babd74
--- /dev/null
+++ b/hw/drivers/lora/node/board/nrf52/syscfg.yml
@@ -0,0 +1,27 @@
+#
+# 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_BOARD_SPI_IDX:
+ description:
+ value: 0
+
+ LORA_NODE_BOARD_SPI_BAUDRATE:
+ description:
+ value: 500
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9986f68c/hw/drivers/lora/node/radio/sx1276/LICENSE.txt
----------------------------------------------------------------------
diff --git a/hw/drivers/lora/node/radio/sx1276/LICENSE.txt b/hw/drivers/lora/node/radio/sx1276/LICENSE.txt
new file mode 100644
index 0000000..82695a7
--- /dev/null
+++ b/hw/drivers/lora/node/radio/sx1276/LICENSE.txt
@@ -0,0 +1,25 @@
+--- Revised BSD License ---
+Copyright (c) 2013, SEMTECH S.A.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of the Semtech corporation nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL SEMTECH S.A. BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9986f68c/hw/drivers/lora/node/radio/sx1276/include/radio/radio.h
----------------------------------------------------------------------
diff --git a/hw/drivers/lora/node/radio/sx1276/include/radio/radio.h b/hw/drivers/lora/node/radio/sx1276/include/radio/radio.h
new file mode 100644
index 0000000..6f23183
--- /dev/null
+++ b/hw/drivers/lora/node/radio/sx1276/include/radio/radio.h
@@ -0,0 +1,33 @@
+/*
+ / _____) _ | |
+( (____ _____ ____ _| |_ _____ ____| |__
+ \____ \| ___ | (_ _) ___ |/ ___) _ \
+ _____) ) ____| | | || |_| ____( (___| | | |
+(______/|_____)_|_|_| \__)_____)\____)_| |_|
+ (C)2013 Semtech
+
+Description: Generic SX1276 driver implementation
+
+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_
+
+/*!
+ * 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 )
+
+#endif /* H_RADIO_RADIO */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9986f68c/hw/drivers/lora/node/radio/sx1276/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/drivers/lora/node/radio/sx1276/pkg.yml b/hw/drivers/lora/node/radio/sx1276/pkg.yml
new file mode 100644
index 0000000..5b98cef
--- /dev/null
+++ b/hw/drivers/lora/node/radio/sx1276/pkg.yml
@@ -0,0 +1,35 @@
+#
+# 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.
+#
+
+pkg.name: hw/drivers/lora/node/radio/sx1276
+pkg.description: LoRaMac-node radio driver for the SX1276 modem.
+pkg.author: "Semtech"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+ - lora
+
+pkg.deps:
+ - "@apache-mynewt-core/kernel/os"
+ - "@apache-mynewt-core/net/lora/node"
+
+pkg.apis:
+ - lora_node_radio
+
+pkg.req_apis:
+ - lora_node_board
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9986f68c/hw/drivers/lora/node/radio/sx1276/src/sx1276-board.c
----------------------------------------------------------------------
diff --git a/hw/drivers/lora/node/radio/sx1276/src/sx1276-board.c b/hw/drivers/lora/node/radio/sx1276/src/sx1276-board.c
new file mode 100644
index 0000000..7bebcc5
--- /dev/null
+++ b/hw/drivers/lora/node/radio/sx1276/src/sx1276-board.c
@@ -0,0 +1,163 @@
+/*
+ / _____) _ | |
+( (____ _____ ____ _| |_ _____ ____| |__
+ \____ \| ___ | (_ _) ___ |/ ___) _ \
+ _____) ) ____| | | || |_| ____( (___| | | |
+(______/|_____)_|_|_| \__)_____)\____)_| |_|
+ (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
+*/
+#include <assert.h>
+#include "board/board.h"
+#include "node/radio.h"
+#include "sx1276.h"
+#include "sx1276-board.h"
+
+/*!
+ * Flag used to set the RF switch control pins in low power mode when the radio is not active.
+ */
+static bool RadioIsActive = false;
+
+/*!
+ * Radio driver structure initialization
+ */
+const struct Radio_s Radio =
+{
+ .Init = SX1276Init,
+ .GetStatus = SX1276GetStatus,
+ .SetModem = SX1276SetModem,
+ .SetChannel = SX1276SetChannel,
+ .IsChannelFree = SX1276IsChannelFree,
+ .Random = SX1276Random,
+ .SetRxConfig = SX1276SetRxConfig,
+ .SetTxConfig = SX1276SetTxConfig,
+ .CheckRfFrequency = SX1276CheckRfFrequency,
+ .TimeOnAir = SX1276GetTimeOnAir,
+ .Send = SX1276Send,
+ .Sleep = SX1276SetSleep,
+ .Standby = SX1276SetStby,
+ .Rx = SX1276SetRx,
+ .StartCad = SX1276StartCad,
+ .Rssi = SX1276ReadRssi,
+ .Write = SX1276Write,
+ .Read = SX1276Read,
+ .WriteBuffer = SX1276WriteBuffer,
+ .ReadBuffer = SX1276ReadBuffer,
+ .SetMaxPayloadLength = SX1276SetMaxPayloadLength
+};
+
+void SX1276IoInit( void )
+{
+ int rc;
+
+ rc = hal_gpio_init_out(RF_RXTX, 1);
+ assert(rc == 0);
+}
+
+void SX1276IoIrqInit( DioIrqHandler **irqHandlers )
+{
+ int rc;
+
+ rc = hal_gpio_irq_init(RADIO_DIO_0, irqHandlers[0], NULL,
+ HAL_GPIO_TRIG_RISING, HAL_GPIO_PULL_NONE);
+ assert(rc == 0);
+ hal_gpio_irq_enable(RADIO_DIO_0);
+
+ rc = hal_gpio_irq_init(RADIO_DIO_1, irqHandlers[1], NULL,
+ HAL_GPIO_TRIG_RISING, HAL_GPIO_PULL_NONE);
+ assert(rc == 0);
+ hal_gpio_irq_enable(RADIO_DIO_1);
+
+ rc = hal_gpio_irq_init(RADIO_DIO_2, irqHandlers[2], NULL,
+ HAL_GPIO_TRIG_RISING, HAL_GPIO_PULL_NONE);
+ assert(rc == 0);
+ hal_gpio_irq_enable(RADIO_DIO_2);
+
+ rc = hal_gpio_irq_init(RADIO_DIO_3, irqHandlers[3], NULL,
+ HAL_GPIO_TRIG_RISING, HAL_GPIO_PULL_NONE);
+ assert(rc == 0);
+ hal_gpio_irq_enable(RADIO_DIO_3);
+
+ rc = hal_gpio_irq_init(RADIO_DIO_4, irqHandlers[4], NULL,
+ HAL_GPIO_TRIG_RISING, HAL_GPIO_PULL_NONE);
+ assert(rc == 0);
+ hal_gpio_irq_enable(RADIO_DIO_4);
+
+ rc = hal_gpio_irq_init(RADIO_DIO_5, irqHandlers[5], NULL,
+ HAL_GPIO_TRIG_RISING, HAL_GPIO_PULL_NONE);
+ assert(rc == 0);
+ hal_gpio_irq_enable(RADIO_DIO_5);
+}
+
+void SX1276IoDeInit( void )
+{
+ hal_gpio_irq_release(RADIO_DIO_0);
+ hal_gpio_irq_release(RADIO_DIO_1);
+ hal_gpio_irq_release(RADIO_DIO_2);
+ hal_gpio_irq_release(RADIO_DIO_3);
+ hal_gpio_irq_release(RADIO_DIO_4);
+ hal_gpio_irq_release(RADIO_DIO_5);
+}
+
+uint8_t SX1276GetPaSelect( uint32_t channel )
+{
+ if( channel < RF_MID_BAND_THRESH )
+ {
+ return RF_PACONFIG_PASELECT_PABOOST;
+ }
+ else
+ {
+ return RF_PACONFIG_PASELECT_RFO;
+ }
+}
+
+void SX1276SetAntSwLowPower( bool status )
+{
+ if( RadioIsActive != status )
+ {
+ RadioIsActive = status;
+
+ if( status == false )
+ {
+ SX1276AntSwInit( );
+ }
+ else
+ {
+ SX1276AntSwDeInit( );
+ }
+ }
+}
+
+void SX1276AntSwInit( void )
+{
+ // Consider turning off GPIO pins for low power. They are always on right
+ // now. GPIOTE library uses 0.5uA max when on, typical 0.1uA.
+}
+
+void SX1276AntSwDeInit( void )
+{
+ // Consider this for low power - ie turning off GPIO pins
+}
+
+void SX1276SetAntSw( uint8_t rxTx )
+{
+ if( rxTx != 0 ) // 1: TX, 0: RX
+ {
+ hal_gpio_write(SX1276_RXTX, 1);
+ }
+ else
+ {
+ hal_gpio_write(SX1276_RXTX, 0);
+ }
+}
+
+bool SX1276CheckRfFrequency( uint32_t frequency )
+{
+ // Implement check. Currently all frequencies are supported
+ return true;
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9986f68c/hw/drivers/lora/node/radio/sx1276/src/sx1276-board.h
----------------------------------------------------------------------
diff --git a/hw/drivers/lora/node/radio/sx1276/src/sx1276-board.h b/hw/drivers/lora/node/radio/sx1276/src/sx1276-board.h
new file mode 100644
index 0000000..5156e8a
--- /dev/null
+++ b/hw/drivers/lora/node/radio/sx1276/src/sx1276-board.h
@@ -0,0 +1,119 @@
+/*
+ / _____) _ | |
+( (____ _____ ____ _| |_ _____ ____| |__
+ \____ \| ___ | (_ _) ___ |/ ___) _ \
+ _____) ) ____| | | || |_| ____( (___| | | |
+(______/|_____)_|_|_| \__)_____)\____)_| |_|
+ (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"
+
+/*!
+ * \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 );
+
+/*!
+ * \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 );
+
+/*!
+ * \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 hal_pin_rxtx (int val);
+
+/*!
+ * Radio hardware and global parameters
+ */
+extern SX1276_t SX1276;
+
+#endif // __SX1276_ARCH_H__
[38/40] incubator-mynewt-core git commit: This closes pull request
#259
Posted by ja...@apache.org.
This closes pull request #259
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/debf64f4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/debf64f4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/debf64f4
Branch: refs/heads/bluetooth5
Commit: debf64f45157a0f8690d1274129229e2cc96705e
Parents: 5ae5f3d 32427b4
Author: julian <ju...@imgtec.com>
Authored: Mon May 8 10:27:30 2017 +0100
Committer: julian <ju...@imgtec.com>
Committed: Mon May 8 10:27:30 2017 +0100
----------------------------------------------------------------------
.../pic32mz2048efg100/include/mcu/mcu.h | 16 +
.../microchip/pic32mz2048efg100/src/hal_gpio.c | 485 +++++++++++++++++++
2 files changed, 501 insertions(+)
----------------------------------------------------------------------
[21/40] incubator-mynewt-core git commit: MYNEWT-741 Fix loraping app.
Posted by ja...@apache.org.
MYNEWT-741 Fix loraping app.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/f3b97d53
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/f3b97d53
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/f3b97d53
Branch: refs/heads/bluetooth5
Commit: f3b97d5350ad319e4eeac255c81c366f0219991e
Parents: 1eb96f4
Author: Christopher Collins <cc...@apache.org>
Authored: Fri Apr 28 10:54:48 2017 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Fri Apr 28 17:27:52 2017 -0700
----------------------------------------------------------------------
apps/loraping/src/main.c | 2 --
1 file changed, 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f3b97d53/apps/loraping/src/main.c
----------------------------------------------------------------------
diff --git a/apps/loraping/src/main.c b/apps/loraping/src/main.c
index 7c5ef8e..2f845e4 100644
--- a/apps/loraping/src/main.c
+++ b/apps/loraping/src/main.c
@@ -34,11 +34,9 @@ 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 "board/board.h"
#include "node/radio.h"
#include "loraping.h"
-#define LORAPING_SPI_BAUDRATE 500
#define USE_BAND_915
#if defined(USE_BAND_433)
[24/40] incubator-mynewt-core git commit: This closes #247.
Posted by ja...@apache.org.
This closes #247.
Merge remote-tracking branch 'ccollins476ad/util-parse'
* ccollins476ad/util-parse:
MYNEWT-740 Rudimentary Text parsing package.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/25ec5794
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/25ec5794
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/25ec5794
Branch: refs/heads/bluetooth5
Commit: 25ec5794f6ba81febdea47a1eab1f204c9f7018a
Parents: 369df92 46d0816
Author: Christopher Collins <cc...@apache.org>
Authored: Fri Apr 28 17:28:09 2017 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Fri Apr 28 17:28:09 2017 -0700
----------------------------------------------------------------------
util/parse/include/parse/parse.h | 47 ++++++
util/parse/pkg.yml | 32 +++++
util/parse/src/parse.c | 263 ++++++++++++++++++++++++++++++++++
3 files changed, 342 insertions(+)
----------------------------------------------------------------------
[03/40] incubator-mynewt-core git commit: This closes #245
Posted by ja...@apache.org.
This closes #245
Fix number of completed packet events in both controller and host.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/eb4f2898
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/eb4f2898
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/eb4f2898
Branch: refs/heads/bluetooth5
Commit: eb4f28984bce5812e1759049425ef5fbe42518da
Parents: 02fd7c7 af6fb7e
Author: William San Filippo <wi...@runtime.io>
Authored: Wed Apr 26 17:38:34 2017 -0700
Committer: William San Filippo <wi...@runtime.io>
Committed: Wed Apr 26 17:38:34 2017 -0700
----------------------------------------------------------------------
net/nimble/controller/src/ble_ll_conn_hci.c | 12 ++----------
net/nimble/host/src/ble_hs_dbg.c | 7 ++-----
net/nimble/host/src/ble_hs_hci_evt.c | 5 +++--
3 files changed, 7 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
[28/40] incubator-mynewt-core git commit: lorashell;
enable SHELL_TASK by default.
Posted by ja...@apache.org.
lorashell; enable SHELL_TASK by default.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/a819c9bf
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/a819c9bf
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/a819c9bf
Branch: refs/heads/bluetooth5
Commit: a819c9bfd9462d81e54ce7e6b40975a84c43e249
Parents: 4f89ca8
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue May 2 16:53:30 2017 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Tue May 2 16:53:30 2017 -0700
----------------------------------------------------------------------
apps/lorashell/syscfg.yml | 1 +
1 file changed, 1 insertion(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a819c9bf/apps/lorashell/syscfg.yml
----------------------------------------------------------------------
diff --git a/apps/lorashell/syscfg.yml b/apps/lorashell/syscfg.yml
index ba7ce41..19b0bf6 100644
--- a/apps/lorashell/syscfg.yml
+++ b/apps/lorashell/syscfg.yml
@@ -25,3 +25,4 @@ syscfg.defs:
syscfg.vals:
STATS_CLI: 1
STATS_NAMES: 1
+ SHELL_TASK: 1
[14/40] incubator-mynewt-core git commit: MYNEWT-741 Port of
LoRaMac-node library
Posted by ja...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9986f68c/net/lora/node/src/mac/LoRaMac.c
----------------------------------------------------------------------
diff --git a/net/lora/node/src/mac/LoRaMac.c b/net/lora/node/src/mac/LoRaMac.c
new file mode 100644
index 0000000..e8d4344
--- /dev/null
+++ b/net/lora/node/src/mac/LoRaMac.c
@@ -0,0 +1,4439 @@
+/*
+ / _____) _ | |
+( (____ _____ ____ _| |_ _____ ____| |__
+ \____ \| ___ | (_ _) ___ |/ ___) _ \
+ _____) ) ____| | | || |_| ____( (___| | | |
+(______/|_____)_|_|_| \__)_____)\____)_| |_|
+ (C)2013 Semtech
+ ___ _____ _ ___ _ _____ ___ ___ ___ ___
+/ __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __|
+\__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _|
+|___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___|
+embedded.connectivity.solutions===============
+
+Description: LoRa MAC layer implementation
+
+License: Revised BSD License, see LICENSE.TXT file include in the project
+
+Maintainer: Miguel Luis ( Semtech ), Gregory Cristian ( Semtech ) and Daniel Jäckle ( STACKFORCE )
+*/
+#include "node/radio.h"
+#include "board/board.h"
+#include "radio/radio.h"
+
+#include "node/mac/LoRaMacCrypto.h"
+#include "node/mac/LoRaMac.h"
+#include "node/mac/LoRaMacTest.h"
+
+#include "hal/hal_timer.h"
+#include "os/os_cputime.h"
+
+#include "lora_priv.h"
+
+/*!
+ * Maximum PHY layer payload size
+ */
+#define LORAMAC_PHY_MAXPAYLOAD 255
+
+/*!
+ * Maximum MAC commands buffer size
+ */
+#define LORA_MAC_COMMAND_MAX_LENGTH 15
+
+/*!
+ * FRMPayload overhead to be used when setting the Radio.SetMaxPayloadLength
+ * in RxWindowSetup function.
+ * Maximum PHYPayload = MaxPayloadOfDatarate/MaxPayloadOfDatarateRepeater + LORA_MAC_FRMPAYLOAD_OVERHEAD
+ */
+#define LORA_MAC_FRMPAYLOAD_OVERHEAD 13 // MHDR(1) + FHDR(7) + Port(1) + MIC(4)
+
+/*!
+ * LoRaMac duty cycle for the back-off procedure during the first hour.
+ */
+#define BACKOFF_DC_1_HOUR 100
+
+/*!
+ * LoRaMac duty cycle for the back-off procedure during the next 10 hours.
+ */
+#define BACKOFF_DC_10_HOURS 1000
+
+/*!
+ * LoRaMac duty cycle for the back-off procedure during the next 24 hours.
+ */
+#define BACKOFF_DC_24_HOURS 10000
+
+/*!
+ * Device IEEE EUI
+ */
+static uint8_t *LoRaMacDevEui;
+
+/*!
+ * Application IEEE EUI
+ */
+static uint8_t *LoRaMacAppEui;
+
+/*!
+ * AES encryption/decryption cipher application key
+ */
+static uint8_t *LoRaMacAppKey;
+
+/*!
+ * AES encryption/decryption cipher network session key
+ */
+static uint8_t LoRaMacNwkSKey[] =
+{
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+};
+
+/*!
+ * AES encryption/decryption cipher application session key
+ */
+static uint8_t LoRaMacAppSKey[] =
+{
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+};
+
+/*!
+ * Device nonce is a random value extracted by issuing a sequence of RSSI
+ * measurements
+ */
+static uint16_t LoRaMacDevNonce;
+
+/*!
+ * Network ID ( 3 bytes )
+ */
+static uint32_t LoRaMacNetID;
+
+/*!
+ * Mote Address
+ */
+static uint32_t LoRaMacDevAddr;
+
+/*!
+ * Multicast channels linked list
+ */
+static MulticastParams_t *MulticastChannels = NULL;
+
+/*!
+ * Actual device class
+ */
+static DeviceClass_t LoRaMacDeviceClass;
+
+/*!
+ * Indicates if the node is connected to a private or public network
+ */
+static bool PublicNetwork;
+
+/*!
+ * Indicates if the node supports repeaters
+ */
+static bool RepeaterSupport;
+
+/*!
+ * Buffer containing the data to be sent or received.
+ */
+static uint8_t LoRaMacBuffer[LORAMAC_PHY_MAXPAYLOAD];
+
+/*!
+ * Length of packet in LoRaMacBuffer
+ */
+static uint16_t LoRaMacBufferPktLen = 0;
+
+/*!
+ * Length of the payload in LoRaMacBuffer
+ */
+static uint8_t LoRaMacTxPayloadLen = 0;
+
+/*!
+ * Buffer containing the upper layer data.
+ */
+static uint8_t LoRaMacPayload[LORAMAC_PHY_MAXPAYLOAD];
+static uint8_t LoRaMacRxPayload[LORAMAC_PHY_MAXPAYLOAD];
+
+/*!
+ * LoRaMAC frame counter. Each time a packet is sent the counter is incremented.
+ * Only the 16 LSB bits are sent
+ */
+static uint32_t UpLinkCounter = 0;
+
+/*!
+ * LoRaMAC frame counter. Each time a packet is received the counter is incremented.
+ * Only the 16 LSB bits are received
+ */
+static uint32_t DownLinkCounter = 0;
+
+/*!
+ * IsPacketCounterFixed enables the MIC field tests by fixing the
+ * UpLinkCounter value
+ */
+static bool IsUpLinkCounterFixed = false;
+
+/*!
+ * Used for test purposes. Disables the opening of the reception windows.
+ */
+static bool IsRxWindowsEnabled = true;
+
+/*!
+ * Indicates if the MAC layer has already joined a network.
+ */
+static bool IsLoRaMacNetworkJoined = false;
+
+/*!
+ * LoRaMac ADR control status
+ */
+static bool AdrCtrlOn = false;
+
+/*!
+ * Counts the number of missed ADR acknowledgements
+ */
+static uint32_t AdrAckCounter = 0;
+
+/*!
+ * If the node has sent a FRAME_TYPE_DATA_CONFIRMED_UP this variable indicates
+ * if the nodes needs to manage the server acknowledgement.
+ */
+static bool NodeAckRequested = false;
+
+/*!
+ * If the server has sent a FRAME_TYPE_DATA_CONFIRMED_DOWN this variable indicates
+ * if the ACK bit must be set for the next transmission
+ */
+static bool SrvAckRequested = false;
+
+/*!
+ * Indicates if the MAC layer wants to send MAC commands
+ */
+static bool MacCommandsInNextTx = false;
+
+/*!
+ * Contains the current MacCommandsBuffer index
+ */
+static uint8_t MacCommandsBufferIndex = 0;
+
+/*!
+ * Contains the current MacCommandsBuffer index for MAC commands to repeat
+ */
+static uint8_t MacCommandsBufferToRepeatIndex = 0;
+
+/*!
+ * Buffer containing the MAC layer commands
+ */
+static uint8_t MacCommandsBuffer[LORA_MAC_COMMAND_MAX_LENGTH];
+
+/*!
+ * Buffer containing the MAC layer commands which must be repeated
+ */
+static uint8_t MacCommandsBufferToRepeat[LORA_MAC_COMMAND_MAX_LENGTH];
+
+#if defined( USE_BAND_433 )
+/*!
+ * Data rates table definition
+ */
+const uint8_t Datarates[] = { 12, 11, 10, 9, 8, 7, 7, 50 };
+
+/*!
+ * Maximum payload with respect to the datarate index. Cannot operate with repeater.
+ */
+const uint8_t MaxPayloadOfDatarate[] = { 51, 51, 51, 115, 242, 242, 242, 242 };
+
+/*!
+ * Maximum payload with respect to the datarate index. Can operate with repeater.
+ */
+const uint8_t MaxPayloadOfDatarateRepeater[] = { 51, 51, 51, 115, 222, 222, 222, 222 };
+
+/*!
+ * Tx output powers table definition
+ */
+const int8_t TxPowers[] = { 10, 7, 4, 1, -2, -5 };
+
+/*!
+ * LoRaMac bands
+ */
+static Band_t Bands[LORA_MAX_NB_BANDS] =
+{
+ BAND0,
+};
+
+/*!
+ * LoRaMAC channels
+ */
+static ChannelParams_t Channels[LORA_MAX_NB_CHANNELS] =
+{
+ LC1,
+ LC2,
+ LC3,
+};
+#elif defined( USE_BAND_470 )
+
+/*!
+ * Data rates table definition
+ */
+const uint8_t Datarates[] = { 12, 11, 10, 9, 8, 7 };
+
+/*!
+ * Maximum payload with respect to the datarate index. Cannot operate with repeater.
+ */
+const uint8_t MaxPayloadOfDatarate[] = { 51, 51, 51, 115, 222, 222 };
+
+/*!
+ * Maximum payload with respect to the datarate index. Can operate with repeater.
+ */
+const uint8_t MaxPayloadOfDatarateRepeater[] = { 51, 51, 51, 115, 222, 222 };
+
+/*!
+ * Tx output powers table definition
+ */
+const int8_t TxPowers[] = { 17, 16, 14, 12, 10, 7, 5, 2 };
+
+/*!
+ * LoRaMac bands
+ */
+static Band_t Bands[LORA_MAX_NB_BANDS] =
+{
+ BAND0,
+};
+
+/*!
+ * LoRaMAC channels
+ */
+static ChannelParams_t Channels[LORA_MAX_NB_CHANNELS];
+
+/*!
+ * Defines the first channel for RX window 1 for CN470 band
+ */
+#define LORAMAC_FIRST_RX1_CHANNEL ( (uint32_t) 500.3e6 )
+
+/*!
+ * Defines the last channel for RX window 1 for CN470 band
+ */
+#define LORAMAC_LAST_RX1_CHANNEL ( (uint32_t) 509.7e6 )
+
+/*!
+ * Defines the step width of the channels for RX window 1
+ */
+#define LORAMAC_STEPWIDTH_RX1_CHANNEL ( (uint32_t) 200e3 )
+
+#elif defined( USE_BAND_780 )
+/*!
+ * Data rates table definition
+ */
+const uint8_t Datarates[] = { 12, 11, 10, 9, 8, 7, 7, 50 };
+
+/*!
+ * Maximum payload with respect to the datarate index. Cannot operate with repeater.
+ */
+const uint8_t MaxPayloadOfDatarate[] = { 51, 51, 51, 115, 242, 242, 242, 242 };
+
+/*!
+ * Maximum payload with respect to the datarate index. Can operate with repeater.
+ */
+const uint8_t MaxPayloadOfDatarateRepeater[] = { 51, 51, 51, 115, 222, 222, 222, 222 };
+
+/*!
+ * Tx output powers table definition
+ */
+const int8_t TxPowers[] = { 10, 7, 4, 1, -2, -5 };
+
+/*!
+ * LoRaMac bands
+ */
+static Band_t Bands[LORA_MAX_NB_BANDS] =
+{
+ BAND0,
+};
+
+/*!
+ * LoRaMAC channels
+ */
+static ChannelParams_t Channels[LORA_MAX_NB_CHANNELS] =
+{
+ LC1,
+ LC2,
+ LC3,
+};
+#elif defined( USE_BAND_868 )
+/*!
+ * Data rates table definition
+ */
+const uint8_t Datarates[] = { 12, 11, 10, 9, 8, 7, 7, 50 };
+
+/*!
+ * Maximum payload with respect to the datarate index. Cannot operate with repeater.
+ */
+const uint8_t MaxPayloadOfDatarate[] = { 51, 51, 51, 115, 242, 242, 242, 242 };
+
+/*!
+ * Maximum payload with respect to the datarate index. Can operate with repeater.
+ */
+const uint8_t MaxPayloadOfDatarateRepeater[] = { 51, 51, 51, 115, 222, 222, 222, 222 };
+
+/*!
+ * Tx output powers table definition
+ */
+const int8_t TxPowers[] = { 20, 14, 11, 8, 5, 2 };
+
+/*!
+ * LoRaMac bands
+ */
+static Band_t Bands[LORA_MAX_NB_BANDS] =
+{
+ BAND0,
+ BAND1,
+ BAND2,
+ BAND3,
+ BAND4,
+};
+
+/*!
+ * LoRaMAC channels
+ */
+static ChannelParams_t Channels[LORA_MAX_NB_CHANNELS] =
+{
+ LC1,
+ LC2,
+ LC3,
+};
+#elif defined( USE_BAND_915 ) || defined( USE_BAND_915_HYBRID )
+/*!
+ * Data rates table definition
+ */
+const uint8_t Datarates[] = { 10, 9, 8, 7, 8, 0, 0, 0, 12, 11, 10, 9, 8, 7, 0, 0 };
+
+/*!
+ * Up/Down link data rates offset definition
+ */
+const int8_t datarateOffsets[5][4] =
+{
+ { DR_10, DR_9 , DR_8 , DR_8 }, // DR_0
+ { DR_11, DR_10, DR_9 , DR_8 }, // DR_1
+ { DR_12, DR_11, DR_10, DR_9 }, // DR_2
+ { DR_13, DR_12, DR_11, DR_10 }, // DR_3
+ { DR_13, DR_13, DR_12, DR_11 }, // DR_4
+};
+
+/*!
+ * Maximum payload with respect to the datarate index. Cannot operate with repeater.
+ */
+const uint8_t MaxPayloadOfDatarate[] = { 11, 53, 125, 242, 242, 0, 0, 0, 53, 129, 242, 242, 242, 242, 0, 0 };
+
+/*!
+ * Maximum payload with respect to the datarate index. Can operate with repeater.
+ */
+const uint8_t MaxPayloadOfDatarateRepeater[] = { 11, 53, 125, 242, 242, 0, 0, 0, 33, 109, 222, 222, 222, 222, 0, 0 };
+
+/*!
+ * Tx output powers table definition
+ */
+const int8_t TxPowers[] = { 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10 };
+
+/*!
+ * LoRaMac bands
+ */
+static Band_t Bands[LORA_MAX_NB_BANDS] =
+{
+ BAND0,
+};
+
+/*!
+ * LoRaMAC channels
+ */
+static ChannelParams_t Channels[LORA_MAX_NB_CHANNELS];
+
+/*!
+ * Contains the channels which remain to be applied.
+ */
+static uint16_t ChannelsMaskRemaining[6];
+
+/*!
+ * Defines the first channel for RX window 1 for US band
+ */
+#define LORAMAC_FIRST_RX1_CHANNEL ( (uint32_t) 923.3e6 )
+
+/*!
+ * Defines the last channel for RX window 1 for US band
+ */
+#define LORAMAC_LAST_RX1_CHANNEL ( (uint32_t) 927.5e6 )
+
+/*!
+ * Defines the step width of the channels for RX window 1
+ */
+#define LORAMAC_STEPWIDTH_RX1_CHANNEL ( (uint32_t) 600e3 )
+
+#else
+ #error "Please define a frequency band in the compiler options."
+#endif
+
+/*!
+ * LoRaMac parameters
+ */
+LoRaMacParams_t LoRaMacParams;
+
+/*!
+ * LoRaMac default parameters
+ */
+LoRaMacParams_t LoRaMacParamsDefaults;
+
+/*!
+ * Uplink messages repetitions counter
+ */
+static uint8_t ChannelsNbRepCounter = 0;
+
+/*!
+ * Maximum duty cycle
+ * \remark Possibility to shutdown the device.
+ */
+static uint8_t MaxDCycle = 0;
+
+/*!
+ * Aggregated duty cycle management
+ */
+static uint16_t AggregatedDCycle;
+static uint32_t AggregatedLastTxDoneTime;
+static uint32_t AggregatedTimeOff;
+
+/*!
+ * Enables/Disables duty cycle management (Test only)
+ */
+static bool DutyCycleOn;
+
+/*!
+ * Current channel index
+ */
+static uint8_t Channel;
+
+/*!
+ * Stores the time at LoRaMac initialization.
+ *
+ * \remark Used for the BACKOFF_DC computation.
+ */
+static uint32_t LoRaMacInitializationTime = 0;
+
+/*!
+ * LoRaMac internal states
+ */
+enum eLoRaMacState
+{
+ LORAMAC_IDLE = 0x00000000,
+ LORAMAC_TX_RUNNING = 0x00000001,
+ LORAMAC_RX = 0x00000002,
+ LORAMAC_ACK_REQ = 0x00000004,
+ LORAMAC_ACK_RETRY = 0x00000008,
+ LORAMAC_TX_DELAYED = 0x00000010,
+ LORAMAC_TX_CONFIG = 0x00000020,
+ LORAMAC_RX_ABORT = 0x00000040,
+};
+
+/*!
+ * LoRaMac internal state
+ */
+uint32_t LoRaMacState = LORAMAC_IDLE;
+
+/*!
+ * LoRaMac timer used to check the LoRaMacState (runs every second)
+ */
+static struct hal_timer MacStateCheckTimer;
+
+/*!
+ * LoRaMac upper layer event functions
+ */
+static LoRaMacPrimitives_t *LoRaMacPrimitives;
+
+/*!
+ * LoRaMac upper layer callback functions
+ */
+static LoRaMacCallback_t *LoRaMacCallbacks;
+
+/*!
+ * Radio events function pointer
+ */
+static RadioEvents_t RadioEvents;
+
+/*!
+ * LoRaMac duty cycle delayed Tx timer
+ */
+static struct hal_timer TxDelayedTimer;
+
+/*!
+ * LoRaMac reception windows timers
+ */
+static struct hal_timer RxWindowTimer1;
+static struct hal_timer RxWindowTimer2;
+
+/*!
+ * LoRaMac reception windows delay
+ * \remark normal frame: RxWindowXDelay = ReceiveDelayX - RADIO_WAKEUP_TIME
+ * join frame : RxWindowXDelay = JoinAcceptDelayX - RADIO_WAKEUP_TIME
+ */
+static uint32_t RxWindow1Delay;
+static uint32_t RxWindow2Delay;
+
+/*!
+ * Acknowledge timeout timer. Used for packet retransmissions.
+ */
+static struct hal_timer AckTimeoutTimer;
+
+/*!
+ * Number of trials to get a frame acknowledged
+ */
+static uint8_t AckTimeoutRetries = 1;
+
+/*!
+ * Number of trials to get a frame acknowledged
+ */
+static uint8_t AckTimeoutRetriesCounter = 1;
+
+/*!
+ * Indicates if the AckTimeout timer has expired or not
+ */
+static bool AckTimeoutRetry = false;
+
+/*!
+ * Last transmission time on air
+ */
+uint32_t TxTimeOnAir = 0;
+
+/*!
+ * Number of trials for the Join Request
+ */
+static uint8_t JoinRequestTrials;
+
+/*!
+ * Maximum number of trials for the Join Request
+ */
+static uint8_t MaxJoinRequestTrials;
+
+/*!
+ * Structure to hold an MCPS indication data.
+ */
+static McpsIndication_t McpsIndication;
+
+/*!
+ * Structure to hold MCPS confirm data.
+ */
+static McpsConfirm_t McpsConfirm;
+
+/*!
+ * Structure to hold MLME confirm data.
+ */
+static MlmeConfirm_t MlmeConfirm;
+
+/*!
+ * Holds the current rx window slot
+ */
+static uint8_t RxSlot = 0;
+
+/*!
+ * LoRaMac tx/rx operation state
+ */
+LoRaMacFlags_t LoRaMacFlags;
+
+/*!
+ * \brief Function to be executed on Radio Tx Done event
+ */
+static void OnRadioTxDone(void);
+
+/*!
+ * \brief This function prepares the MAC to abort the execution of function
+ * OnRadioRxDone in case of a reception error.
+ */
+static void PrepareRxDoneAbort( void );
+
+/*!
+ * \brief Function to be executed on Radio Rx Done event
+ */
+static void OnRadioRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr );
+
+/*!
+ * \brief Function executed on Radio Tx Timeout event
+ */
+static void OnRadioTxTimeout( void );
+
+/*!
+ * \brief Function executed on Radio Rx error event
+ */
+static void OnRadioRxError( void );
+
+/*!
+ * \brief Function executed on Radio Rx Timeout event
+ */
+static void OnRadioRxTimeout( void );
+
+/*!
+ * \brief Function executed on Resend Frame timer event.
+ */
+static void OnMacStateCheckTimerEvent(void *unused);
+
+/*!
+ * \brief Function executed on duty cycle delayed Tx timer event
+ */
+static void OnTxDelayedTimerEvent(void *unused);
+
+/*!
+ * \brief Function executed on first Rx window timer event
+ */
+static void OnRxWindow1TimerEvent(void *unused);
+
+/*!
+ * \brief Function executed on second Rx window timer event
+ */
+static void OnRxWindow2TimerEvent(void *unused);
+
+/*!
+ * \brief Function executed on AckTimeout timer event
+ */
+static void OnAckTimeoutTimerEvent(void *unused);
+
+/*!
+ * \brief Searches and set the next random available channel
+ *
+ * \param [OUT] Time to wait for the next transmission according to the duty
+ * cycle.
+ *
+ * \retval status Function status [1: OK, 0: Unable to find a channel on the
+ * current datarate]
+ */
+static bool SetNextChannel( uint32_t* time );
+
+/*!
+ * \brief Initializes and opens the reception window
+ *
+ * \param [IN] freq window channel frequency
+ * \param [IN] datarate window channel datarate
+ * \param [IN] bandwidth window channel bandwidth
+ * \param [IN] timeout window channel timeout
+ *
+ * \retval status Operation status [true: Success, false: Fail]
+ */
+static bool RxWindowSetup( uint32_t freq, int8_t datarate, uint32_t bandwidth, uint16_t timeout, bool rxContinuous );
+
+/*!
+ * \brief Verifies if the RX window 2 frequency is in range
+ *
+ * \param [IN] freq window channel frequency
+ *
+ * \retval status Function status [1: OK, 0: Frequency not applicable]
+ */
+static bool Rx2FreqInRange( uint32_t freq );
+
+/*!
+ * \brief Adds a new MAC command to be sent.
+ *
+ * \Remark MAC layer internal function
+ *
+ * \param [in] cmd MAC command to be added
+ * [MOTE_MAC_LINK_CHECK_REQ,
+ * MOTE_MAC_LINK_ADR_ANS,
+ * MOTE_MAC_DUTY_CYCLE_ANS,
+ * MOTE_MAC_RX2_PARAM_SET_ANS,
+ * MOTE_MAC_DEV_STATUS_ANS
+ * MOTE_MAC_NEW_CHANNEL_ANS]
+ * \param [in] p1 1st parameter ( optional depends on the command )
+ * \param [in] p2 2nd parameter ( optional depends on the command )
+ *
+ * \retval status Function status [0: OK, 1: Unknown command, 2: Buffer full]
+ */
+static LoRaMacStatus_t AddMacCommand( uint8_t cmd, uint8_t p1, uint8_t p2 );
+
+/*!
+ * \brief Parses the MAC commands which must be repeated.
+ *
+ * \Remark MAC layer internal function
+ *
+ * \param [IN] cmdBufIn Buffer which stores the MAC commands to send
+ * \param [IN] length Length of the input buffer to parse
+ * \param [OUT] cmdBufOut Buffer which stores the MAC commands which must be
+ * repeated.
+ *
+ * \retval Size of the MAC commands to repeat.
+ */
+static uint8_t ParseMacCommandsToRepeat( uint8_t* cmdBufIn, uint8_t length, uint8_t* cmdBufOut );
+
+/*!
+ * \brief Validates if the payload fits into the frame, taking the datarate
+ * into account.
+ *
+ * \details Refer to chapter 4.3.2 of the LoRaWAN specification, v1.0
+ *
+ * \param lenN Length of the application payload. The length depends on the
+ * datarate and is region specific
+ *
+ * \param datarate Current datarate
+ *
+ * \param fOptsLen Length of the fOpts field
+ *
+ * \retval [false: payload does not fit into the frame, true: payload fits into
+ * the frame]
+ */
+static bool ValidatePayloadLength( uint8_t lenN, int8_t datarate, uint8_t fOptsLen );
+
+/*!
+ * \brief Counts the number of bits in a mask.
+ *
+ * \param [IN] mask A mask from which the function counts the active bits.
+ * \param [IN] nbBits The number of bits to check.
+ *
+ * \retval Number of enabled bits in the mask.
+ */
+static uint8_t CountBits( uint16_t mask, uint8_t nbBits );
+
+#if defined( USE_BAND_915 ) || defined( USE_BAND_915_HYBRID )
+/*!
+ * \brief Counts the number of enabled 125 kHz channels in the channel mask.
+ * This function can only be applied to US915 band.
+ *
+ * \param [IN] channelsMask Pointer to the first element of the channel mask
+ *
+ * \retval Number of enabled channels in the channel mask
+ */
+static uint8_t CountNbEnabled125kHzChannels( uint16_t *channelsMask );
+
+#if defined( USE_BAND_915_HYBRID )
+/*!
+ * \brief Validates the correctness of the channel mask for US915, hybrid mode.
+ *
+ * \param [IN] mask Block definition to set.
+ * \param [OUT] channelsMask Pointer to the first element of the channel mask
+ */
+static void ReenableChannels( uint16_t mask, uint16_t* channelsMask );
+
+/*!
+ * \brief Validates the correctness of the channel mask for US915, hybrid mode.
+ *
+ * \param [IN] channelsMask Pointer to the first element of the channel mask
+ *
+ * \retval [true: channel mask correct, false: channel mask not correct]
+ */
+static bool ValidateChannelMask( uint16_t* channelsMask );
+#endif
+
+#endif
+
+/*!
+ * \brief Validates the correctness of the datarate against the enable channels.
+ *
+ * \param [IN] datarate Datarate to be check
+ * \param [IN] channelsMask Pointer to the first element of the channel mask
+ *
+ * \retval [true: datarate can be used, false: datarate can not be used]
+ */
+static bool ValidateDatarate( int8_t datarate, uint16_t* channelsMask );
+
+/*!
+ * \brief Limits the Tx power according to the number of enabled channels
+ *
+ * \param [IN] txPower txPower to limit
+ * \param [IN] maxBandTxPower Maximum band allowed TxPower
+ *
+ * \retval Returns the maximum valid tx power
+ */
+static int8_t LimitTxPower( int8_t txPower, int8_t maxBandTxPower );
+
+/*!
+ * \brief Verifies, if a value is in a given range.
+ *
+ * \param value Value to verify, if it is in range
+ *
+ * \param min Minimum possible value
+ *
+ * \param max Maximum possible value
+ *
+ * \retval Returns the maximum valid tx power
+ */
+static bool ValueInRange( int8_t value, int8_t min, int8_t max );
+
+/*!
+ * \brief Calculates the next datarate to set, when ADR is on or off
+ *
+ * \param [IN] adrEnabled Specify whether ADR is on or off
+ *
+ * \param [IN] updateChannelMask Set to true, if the channel masks shall be updated
+ *
+ * \param [OUT] datarateOut Reports the datarate which will be used next
+ *
+ * \retval Returns the state of ADR ack request
+ */
+static bool AdrNextDr( bool adrEnabled, bool updateChannelMask, int8_t* datarateOut );
+
+/*!
+ * \brief Disables channel in a specified channel mask
+ *
+ * \param [IN] id - Id of the channel
+ *
+ * \param [IN] mask - Pointer to the channel mask to edit
+ *
+ * \retval [true, if disable was successful, false if not]
+ */
+static bool DisableChannelInMask( uint8_t id, uint16_t* mask );
+
+/*!
+ * \brief Decodes MAC commands in the fOpts field and in the payload
+ */
+static void ProcessMacCommands( uint8_t *payload, uint8_t macIndex, uint8_t commandsSize, uint8_t snr );
+
+/*!
+ * \brief LoRaMAC layer generic send frame
+ *
+ * \param [IN] macHdr MAC header field
+ * \param [IN] fPort MAC payload port
+ * \param [IN] fBuffer MAC data buffer to be sent
+ * \param [IN] fBufferSize MAC data buffer size
+ * \retval status Status of the operation.
+ */
+LoRaMacStatus_t Send( LoRaMacHeader_t *macHdr, uint8_t fPort, void *fBuffer, uint16_t fBufferSize );
+
+/*!
+ * \brief LoRaMAC layer frame buffer initialization
+ *
+ * \param [IN] macHdr MAC header field
+ * \param [IN] fCtrl MAC frame control field
+ * \param [IN] fOpts MAC commands buffer
+ * \param [IN] fPort MAC payload port
+ * \param [IN] fBuffer MAC data buffer to be sent
+ * \param [IN] fBufferSize MAC data buffer size
+ * \retval status Status of the operation.
+ */
+LoRaMacStatus_t PrepareFrame( LoRaMacHeader_t *macHdr, LoRaMacFrameCtrl_t *fCtrl, uint8_t fPort, void *fBuffer, uint16_t fBufferSize );
+
+/*
+ * \brief Schedules the frame according to the duty cycle
+ *
+ * \retval Status of the operation
+ */
+static LoRaMacStatus_t ScheduleTx( void );
+
+/*
+ * \brief Sets the duty cycle for the join procedure.
+ *
+ * \retval Duty cycle
+ */
+static uint16_t JoinDutyCycle( void );
+
+/*
+ * \brief Calculates the back-off time for the band of a channel.
+ *
+ * \param [IN] channel The last Tx channel index
+ */
+static void CalculateBackOff( uint8_t channel );
+
+/*
+ * \brief Alternates the datarate of the channel for the join request.
+ *
+ * \param [IN] nbTrials Number of performed join requests.
+ * \retval Datarate to apply
+ */
+static int8_t AlternateDatarate( uint16_t nbTrials );
+
+/*!
+ * \brief LoRaMAC layer prepared frame buffer transmission with channel specification
+ *
+ * \remark PrepareFrame must be called at least once before calling this
+ * function.
+ *
+ * \param [IN] channel Channel parameters
+ * \retval status Status of the operation.
+ */
+LoRaMacStatus_t SendFrameOnChannel( ChannelParams_t channel );
+
+/*!
+ * \brief Sets the radio in continuous transmission mode
+ *
+ * \remark Uses the radio parameters set on the previous transmission.
+ *
+ * \param [IN] timeout Time in seconds while the radio is kept in continuous wave mode
+ * \retval status Status of the operation.
+ */
+LoRaMacStatus_t SetTxContinuousWave( uint16_t timeout );
+
+/*!
+ * \brief Resets MAC specific parameters to default
+ */
+static void ResetMacParameters( void );
+
+static void OnRadioTxDone(void)
+{
+ uint32_t curTime = os_cputime_get32();
+
+ if( LoRaMacDeviceClass != CLASS_C )
+ {
+ Radio.Sleep( );
+ }
+ else
+ {
+ OnRxWindow2TimerEvent(NULL);
+ }
+
+ // Setup timers
+ if( IsRxWindowsEnabled == true )
+ {
+ os_cputime_timer_relative(&RxWindowTimer1, RxWindow1Delay);
+ if( LoRaMacDeviceClass != CLASS_C )
+ {
+ os_cputime_timer_relative(&RxWindowTimer2, RxWindow2Delay);
+ }
+ if( ( LoRaMacDeviceClass == CLASS_C ) || ( NodeAckRequested == true ) )
+ {
+ os_cputime_timer_relative(
+ &AckTimeoutTimer,
+ RxWindow2Delay + ACK_TIMEOUT +
+ randr(-ACK_TIMEOUT_RND, ACK_TIMEOUT_RND));
+ }
+ }
+ else
+ {
+ McpsConfirm.Status = LORAMAC_EVENT_INFO_STATUS_OK;
+ MlmeConfirm.Status = LORAMAC_EVENT_INFO_STATUS_RX2_TIMEOUT;
+
+ if( LoRaMacFlags.Value == 0 )
+ {
+ LoRaMacFlags.Bits.McpsReq = 1;
+ }
+ LoRaMacFlags.Bits.MacDone = 1;
+ }
+
+ // Update last tx done time for the current channel
+ Bands[Channels[Channel].Band].LastTxDoneTime = curTime;
+ // Update Aggregated last tx done time
+ AggregatedLastTxDoneTime = curTime;
+ // Update Backoff
+ CalculateBackOff( Channel );
+
+ if( NodeAckRequested == false )
+ {
+ McpsConfirm.Status = LORAMAC_EVENT_INFO_STATUS_OK;
+ ChannelsNbRepCounter++;
+ }
+}
+
+static void PrepareRxDoneAbort( void )
+{
+ LoRaMacState |= LORAMAC_RX_ABORT;
+
+ if( NodeAckRequested )
+ {
+ OnAckTimeoutTimerEvent(NULL);
+ }
+
+ if( ( RxSlot == 0 ) && ( LoRaMacDeviceClass == CLASS_C ) )
+ {
+ OnRxWindow2TimerEvent(NULL);
+ }
+
+ LoRaMacFlags.Bits.McpsInd = 1;
+ LoRaMacFlags.Bits.MacDone = 1;
+
+ // Trig OnMacCheckTimerEvent call as soon as possible
+ os_cputime_timer_relative(&MacStateCheckTimer, 1);
+}
+
+static void OnRadioRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr )
+{
+ LoRaMacHeader_t macHdr;
+ LoRaMacFrameCtrl_t fCtrl;
+ bool skipIndication = false;
+
+ uint8_t pktHeaderLen = 0;
+ uint32_t address = 0;
+ uint8_t appPayloadStartIndex = 0;
+ uint8_t port = 0xFF;
+ uint8_t frameLen = 0;
+ uint32_t mic = 0;
+ uint32_t micRx = 0;
+
+ uint16_t sequenceCounter = 0;
+ uint16_t sequenceCounterPrev = 0;
+ uint16_t sequenceCounterDiff = 0;
+ uint32_t downLinkCounter = 0;
+
+ MulticastParams_t *curMulticastParams = NULL;
+ uint8_t *nwkSKey = LoRaMacNwkSKey;
+ uint8_t *appSKey = LoRaMacAppSKey;
+
+ uint8_t multicast = 0;
+
+ bool isMicOk = false;
+
+ McpsConfirm.AckReceived = false;
+ McpsIndication.Rssi = rssi;
+ McpsIndication.Snr = snr;
+ McpsIndication.RxSlot = RxSlot;
+ McpsIndication.Port = 0;
+ McpsIndication.Multicast = 0;
+ McpsIndication.FramePending = 0;
+ McpsIndication.Buffer = NULL;
+ McpsIndication.BufferSize = 0;
+ McpsIndication.RxData = false;
+ McpsIndication.AckReceived = false;
+ McpsIndication.DownLinkCounter = 0;
+ McpsIndication.McpsIndication = MCPS_UNCONFIRMED;
+
+ if( LoRaMacDeviceClass != CLASS_C )
+ {
+ Radio.Sleep( );
+ }
+ os_cputime_timer_stop(&RxWindowTimer2);
+
+ macHdr.Value = payload[pktHeaderLen++];
+
+ switch( macHdr.Bits.MType )
+ {
+ case FRAME_TYPE_JOIN_ACCEPT:
+ if( IsLoRaMacNetworkJoined == true )
+ {
+ McpsIndication.Status = LORAMAC_EVENT_INFO_STATUS_ERROR;
+ PrepareRxDoneAbort( );
+ return;
+ }
+ LoRaMacJoinDecrypt( payload + 1, size - 1, LoRaMacAppKey, LoRaMacRxPayload + 1 );
+
+ LoRaMacRxPayload[0] = macHdr.Value;
+
+ LoRaMacJoinComputeMic( LoRaMacRxPayload, size - LORAMAC_MFR_LEN, LoRaMacAppKey, &mic );
+
+ micRx |= ( uint32_t )LoRaMacRxPayload[size - LORAMAC_MFR_LEN];
+ micRx |= ( ( uint32_t )LoRaMacRxPayload[size - LORAMAC_MFR_LEN + 1] << 8 );
+ micRx |= ( ( uint32_t )LoRaMacRxPayload[size - LORAMAC_MFR_LEN + 2] << 16 );
+ micRx |= ( ( uint32_t )LoRaMacRxPayload[size - LORAMAC_MFR_LEN + 3] << 24 );
+
+ if( micRx == mic )
+ {
+ LoRaMacJoinComputeSKeys( LoRaMacAppKey, LoRaMacRxPayload + 1, LoRaMacDevNonce, LoRaMacNwkSKey, LoRaMacAppSKey );
+
+ LoRaMacNetID = ( uint32_t )LoRaMacRxPayload[4];
+ LoRaMacNetID |= ( ( uint32_t )LoRaMacRxPayload[5] << 8 );
+ LoRaMacNetID |= ( ( uint32_t )LoRaMacRxPayload[6] << 16 );
+
+ LoRaMacDevAddr = ( uint32_t )LoRaMacRxPayload[7];
+ LoRaMacDevAddr |= ( ( uint32_t )LoRaMacRxPayload[8] << 8 );
+ LoRaMacDevAddr |= ( ( uint32_t )LoRaMacRxPayload[9] << 16 );
+ LoRaMacDevAddr |= ( ( uint32_t )LoRaMacRxPayload[10] << 24 );
+
+ // DLSettings
+ LoRaMacParams.Rx1DrOffset = ( LoRaMacRxPayload[11] >> 4 ) & 0x07;
+ LoRaMacParams.Rx2Channel.Datarate = LoRaMacRxPayload[11] & 0x0F;
+
+ // RxDelay
+ LoRaMacParams.ReceiveDelay1 = ( LoRaMacRxPayload[12] & 0x0F );
+ if( LoRaMacParams.ReceiveDelay1 == 0 )
+ {
+ LoRaMacParams.ReceiveDelay1 = 1;
+ }
+ LoRaMacParams.ReceiveDelay1 *= 1e3;
+ LoRaMacParams.ReceiveDelay2 = LoRaMacParams.ReceiveDelay1 + 1e3;
+
+#if !( defined( USE_BAND_915 ) || defined( USE_BAND_915_HYBRID ) )
+ //CFList
+ if( ( size - 1 ) > 16 )
+ {
+ ChannelParams_t param;
+ param.DrRange.Value = ( DR_5 << 4 ) | DR_0;
+
+ LoRaMacState |= LORAMAC_TX_CONFIG;
+ for( uint8_t i = 3, j = 0; i < ( 5 + 3 ); i++, j += 3 )
+ {
+ param.Frequency = ( ( uint32_t )LoRaMacRxPayload[13 + j] | ( ( uint32_t )LoRaMacRxPayload[14 + j] << 8 ) | ( ( uint32_t )LoRaMacRxPayload[15 + j] << 16 ) ) * 100;
+ if( param.Frequency != 0 )
+ {
+ LoRaMacChannelAdd( i, param );
+ }
+ else
+ {
+ LoRaMacChannelRemove( i );
+ }
+ }
+ LoRaMacState &= ~LORAMAC_TX_CONFIG;
+ }
+#endif
+ MlmeConfirm.Status = LORAMAC_EVENT_INFO_STATUS_OK;
+ IsLoRaMacNetworkJoined = true;
+ LoRaMacParams.ChannelsDatarate = LoRaMacParamsDefaults.ChannelsDatarate;
+ }
+ else
+ {
+ MlmeConfirm.Status = LORAMAC_EVENT_INFO_STATUS_JOIN_FAIL;
+ }
+ break;
+ case FRAME_TYPE_DATA_CONFIRMED_DOWN:
+ case FRAME_TYPE_DATA_UNCONFIRMED_DOWN:
+ {
+ address = payload[pktHeaderLen++];
+ address |= ( (uint32_t)payload[pktHeaderLen++] << 8 );
+ address |= ( (uint32_t)payload[pktHeaderLen++] << 16 );
+ address |= ( (uint32_t)payload[pktHeaderLen++] << 24 );
+
+ if( address != LoRaMacDevAddr )
+ {
+ curMulticastParams = MulticastChannels;
+ while( curMulticastParams != NULL )
+ {
+ if( address == curMulticastParams->Address )
+ {
+ multicast = 1;
+ nwkSKey = curMulticastParams->NwkSKey;
+ appSKey = curMulticastParams->AppSKey;
+ downLinkCounter = curMulticastParams->DownLinkCounter;
+ break;
+ }
+ curMulticastParams = curMulticastParams->Next;
+ }
+ if( multicast == 0 )
+ {
+ // We are not the destination of this frame.
+ McpsIndication.Status = LORAMAC_EVENT_INFO_STATUS_ADDRESS_FAIL;
+ PrepareRxDoneAbort( );
+ return;
+ }
+ }
+ else
+ {
+ multicast = 0;
+ nwkSKey = LoRaMacNwkSKey;
+ appSKey = LoRaMacAppSKey;
+ downLinkCounter = DownLinkCounter;
+ }
+
+ fCtrl.Value = payload[pktHeaderLen++];
+
+ sequenceCounter = ( uint16_t )payload[pktHeaderLen++];
+ sequenceCounter |= ( uint16_t )payload[pktHeaderLen++] << 8;
+
+ appPayloadStartIndex = 8 + fCtrl.Bits.FOptsLen;
+
+ micRx |= ( uint32_t )payload[size - LORAMAC_MFR_LEN];
+ micRx |= ( ( uint32_t )payload[size - LORAMAC_MFR_LEN + 1] << 8 );
+ micRx |= ( ( uint32_t )payload[size - LORAMAC_MFR_LEN + 2] << 16 );
+ micRx |= ( ( uint32_t )payload[size - LORAMAC_MFR_LEN + 3] << 24 );
+
+ sequenceCounterPrev = ( uint16_t )downLinkCounter;
+ sequenceCounterDiff = ( sequenceCounter - sequenceCounterPrev );
+
+ if( sequenceCounterDiff < ( 1 << 15 ) )
+ {
+ downLinkCounter += sequenceCounterDiff;
+ LoRaMacComputeMic( payload, size - LORAMAC_MFR_LEN, nwkSKey, address, DOWN_LINK, downLinkCounter, &mic );
+ if( micRx == mic )
+ {
+ isMicOk = true;
+ }
+ }
+ else
+ {
+ // check for sequence roll-over
+ uint32_t downLinkCounterTmp = downLinkCounter + 0x10000 + ( int16_t )sequenceCounterDiff;
+ LoRaMacComputeMic( payload, size - LORAMAC_MFR_LEN, nwkSKey, address, DOWN_LINK, downLinkCounterTmp, &mic );
+ if( micRx == mic )
+ {
+ isMicOk = true;
+ downLinkCounter = downLinkCounterTmp;
+ }
+ }
+
+ // Check for a the maximum allowed counter difference
+ if( sequenceCounterDiff >= MAX_FCNT_GAP )
+ {
+ McpsIndication.Status = LORAMAC_EVENT_INFO_STATUS_DOWNLINK_TOO_MANY_FRAMES_LOSS;
+ McpsIndication.DownLinkCounter = downLinkCounter;
+ PrepareRxDoneAbort( );
+ return;
+ }
+
+ if( isMicOk == true )
+ {
+ McpsIndication.Status = LORAMAC_EVENT_INFO_STATUS_OK;
+ McpsIndication.Multicast = multicast;
+ McpsIndication.FramePending = fCtrl.Bits.FPending;
+ McpsIndication.Buffer = NULL;
+ McpsIndication.BufferSize = 0;
+ McpsIndication.DownLinkCounter = downLinkCounter;
+
+ McpsConfirm.Status = LORAMAC_EVENT_INFO_STATUS_OK;
+
+ AdrAckCounter = 0;
+ MacCommandsBufferToRepeatIndex = 0;
+
+ // Update 32 bits downlink counter
+ if( multicast == 1 )
+ {
+ McpsIndication.McpsIndication = MCPS_MULTICAST;
+
+ if( ( curMulticastParams->DownLinkCounter == downLinkCounter ) &&
+ ( curMulticastParams->DownLinkCounter != 0 ) )
+ {
+ McpsIndication.Status = LORAMAC_EVENT_INFO_STATUS_DOWNLINK_REPEATED;
+ McpsIndication.DownLinkCounter = downLinkCounter;
+ PrepareRxDoneAbort( );
+ return;
+ }
+ curMulticastParams->DownLinkCounter = downLinkCounter;
+ }
+ else
+ {
+ if( macHdr.Bits.MType == FRAME_TYPE_DATA_CONFIRMED_DOWN )
+ {
+ SrvAckRequested = true;
+ McpsIndication.McpsIndication = MCPS_CONFIRMED;
+
+ if( ( DownLinkCounter == downLinkCounter ) &&
+ ( DownLinkCounter != 0 ) )
+ {
+ // Duplicated confirmed downlink. Skip indication.
+ skipIndication = true;
+ }
+ }
+ else
+ {
+ SrvAckRequested = false;
+ McpsIndication.McpsIndication = MCPS_UNCONFIRMED;
+
+ if( ( DownLinkCounter == downLinkCounter ) &&
+ ( DownLinkCounter != 0 ) )
+ {
+ McpsIndication.Status = LORAMAC_EVENT_INFO_STATUS_DOWNLINK_REPEATED;
+ McpsIndication.DownLinkCounter = downLinkCounter;
+ PrepareRxDoneAbort( );
+ return;
+ }
+ }
+ DownLinkCounter = downLinkCounter;
+ }
+
+ if( ( ( size - 4 ) - appPayloadStartIndex ) > 0 )
+ {
+ port = payload[appPayloadStartIndex++];
+ frameLen = ( size - 4 ) - appPayloadStartIndex;
+
+ McpsIndication.Port = port;
+
+ if( port == 0 )
+ {
+ if( fCtrl.Bits.FOptsLen == 0 )
+ {
+ LoRaMacPayloadDecrypt( payload + appPayloadStartIndex,
+ frameLen,
+ nwkSKey,
+ address,
+ DOWN_LINK,
+ downLinkCounter,
+ LoRaMacRxPayload );
+
+ // Decode frame payload MAC commands
+ ProcessMacCommands( LoRaMacRxPayload, 0, frameLen, snr );
+ }
+ else
+ {
+ skipIndication = true;
+ }
+ }
+ else
+ {
+ if( fCtrl.Bits.FOptsLen > 0 )
+ {
+ // Decode Options field MAC commands. Omit the fPort.
+ ProcessMacCommands( payload, 8, appPayloadStartIndex - 1, snr );
+ }
+
+ LoRaMacPayloadDecrypt( payload + appPayloadStartIndex,
+ frameLen,
+ appSKey,
+ address,
+ DOWN_LINK,
+ downLinkCounter,
+ LoRaMacRxPayload );
+
+ if( skipIndication == false )
+ {
+ McpsIndication.Buffer = LoRaMacRxPayload;
+ McpsIndication.BufferSize = frameLen;
+ McpsIndication.RxData = true;
+ }
+ }
+ }
+ else
+ {
+ if( fCtrl.Bits.FOptsLen > 0 )
+ {
+ // Decode Options field MAC commands
+ ProcessMacCommands( payload, 8, appPayloadStartIndex, snr );
+ }
+ }
+
+ if( skipIndication == false )
+ {
+ // Check if the frame is an acknowledgement
+ if( fCtrl.Bits.Ack == 1 )
+ {
+ McpsConfirm.AckReceived = true;
+ McpsIndication.AckReceived = true;
+
+ // Stop the AckTimeout timer as no more retransmissions
+ // are needed.
+ os_cputime_timer_stop(&AckTimeoutTimer);
+ }
+ else
+ {
+ McpsConfirm.AckReceived = false;
+
+ if( AckTimeoutRetriesCounter > AckTimeoutRetries )
+ {
+ // Stop the AckTimeout timer as no more retransmissions
+ // are needed.
+ os_cputime_timer_stop(&AckTimeoutTimer);
+ }
+ }
+ LoRaMacFlags.Bits.McpsInd = 1;
+ }
+ }
+ else
+ {
+ McpsIndication.Status = LORAMAC_EVENT_INFO_STATUS_MIC_FAIL;
+
+ PrepareRxDoneAbort( );
+ return;
+ }
+ }
+ break;
+ case FRAME_TYPE_PROPRIETARY:
+ {
+ memcpy( LoRaMacRxPayload, &payload[pktHeaderLen], size );
+
+ McpsIndication.McpsIndication = MCPS_PROPRIETARY;
+ McpsIndication.Status = LORAMAC_EVENT_INFO_STATUS_OK;
+ McpsIndication.Buffer = LoRaMacRxPayload;
+ McpsIndication.BufferSize = size - pktHeaderLen;
+
+ LoRaMacFlags.Bits.McpsInd = 1;
+ break;
+ }
+ default:
+ McpsIndication.Status = LORAMAC_EVENT_INFO_STATUS_ERROR;
+ PrepareRxDoneAbort( );
+ break;
+ }
+
+ if( ( RxSlot == 0 ) && ( LoRaMacDeviceClass == CLASS_C ) )
+ {
+ OnRxWindow2TimerEvent(NULL);
+ }
+ LoRaMacFlags.Bits.MacDone = 1;
+
+ // Trig OnMacCheckTimerEvent call as soon as possible
+ os_cputime_timer_relative(&MacStateCheckTimer, 1);
+}
+
+static void OnRadioTxTimeout( void )
+{
+ if( LoRaMacDeviceClass != CLASS_C )
+ {
+ Radio.Sleep( );
+ }
+ else
+ {
+ OnRxWindow2TimerEvent(NULL);
+ }
+
+ McpsConfirm.Status = LORAMAC_EVENT_INFO_STATUS_TX_TIMEOUT;
+ MlmeConfirm.Status = LORAMAC_EVENT_INFO_STATUS_TX_TIMEOUT;
+ LoRaMacFlags.Bits.MacDone = 1;
+}
+
+static void OnRadioRxError( void )
+{
+ if( LoRaMacDeviceClass != CLASS_C )
+ {
+ Radio.Sleep( );
+ }
+ else
+ {
+ OnRxWindow2TimerEvent(NULL);
+ }
+
+ if( RxSlot == 1 )
+ {
+ if( NodeAckRequested == true )
+ {
+ McpsConfirm.Status = LORAMAC_EVENT_INFO_STATUS_RX2_ERROR;
+ }
+ MlmeConfirm.Status = LORAMAC_EVENT_INFO_STATUS_RX2_ERROR;
+ LoRaMacFlags.Bits.MacDone = 1;
+ }
+}
+
+static void OnRadioRxTimeout( void )
+{
+ if( LoRaMacDeviceClass != CLASS_C )
+ {
+ Radio.Sleep( );
+ }
+ else
+ {
+ OnRxWindow2TimerEvent(NULL);
+ }
+
+ if( RxSlot == 1 )
+ {
+ if( NodeAckRequested == true )
+ {
+ McpsConfirm.Status = LORAMAC_EVENT_INFO_STATUS_RX2_TIMEOUT;
+ }
+ MlmeConfirm.Status = LORAMAC_EVENT_INFO_STATUS_RX2_TIMEOUT;
+ LoRaMacFlags.Bits.MacDone = 1;
+ }
+}
+
+static void OnMacStateCheckTimerEvent(void *unused)
+{
+ os_cputime_timer_stop(&MacStateCheckTimer);
+ bool txTimeout = false;
+
+ if( LoRaMacFlags.Bits.MacDone == 1 )
+ {
+ if( ( LoRaMacState & LORAMAC_RX_ABORT ) == LORAMAC_RX_ABORT )
+ {
+ LoRaMacState &= ~LORAMAC_RX_ABORT;
+ LoRaMacState &= ~LORAMAC_TX_RUNNING;
+ }
+
+ if( ( LoRaMacFlags.Bits.MlmeReq == 1 ) || ( ( LoRaMacFlags.Bits.McpsReq == 1 ) ) )
+ {
+ if( ( McpsConfirm.Status == LORAMAC_EVENT_INFO_STATUS_TX_TIMEOUT ) ||
+ ( MlmeConfirm.Status == LORAMAC_EVENT_INFO_STATUS_TX_TIMEOUT ) )
+ {
+ // Stop transmit cycle due to tx timeout.
+ LoRaMacState &= ~LORAMAC_TX_RUNNING;
+ McpsConfirm.NbRetries = AckTimeoutRetriesCounter;
+ McpsConfirm.AckReceived = false;
+ McpsConfirm.TxTimeOnAir = 0;
+ txTimeout = true;
+ }
+ }
+
+ if( ( NodeAckRequested == false ) && ( txTimeout == false ) )
+ {
+ if( ( LoRaMacFlags.Bits.MlmeReq == 1 ) || ( ( LoRaMacFlags.Bits.McpsReq == 1 ) ) )
+ {
+ if( ( LoRaMacFlags.Bits.MlmeReq == 1 ) && ( MlmeConfirm.MlmeRequest == MLME_JOIN ) )
+ {// Procedure for the join request
+ MlmeConfirm.NbRetries = JoinRequestTrials;
+
+ if( MlmeConfirm.Status == LORAMAC_EVENT_INFO_STATUS_OK )
+ {// Node joined successfully
+ UpLinkCounter = 0;
+ ChannelsNbRepCounter = 0;
+ LoRaMacState &= ~LORAMAC_TX_RUNNING;
+ }
+ else
+ {
+ if( ( JoinRequestTrials >= MaxJoinRequestTrials ) )
+ {
+ LoRaMacState &= ~LORAMAC_TX_RUNNING;
+ }
+ else
+ {
+ LoRaMacFlags.Bits.MacDone = 0;
+ // Sends the same frame again
+ OnTxDelayedTimerEvent(NULL);
+ }
+ }
+ }
+ else
+ {// Procedure for all other frames
+ if( ( ChannelsNbRepCounter >= LoRaMacParams.ChannelsNbRep ) || ( LoRaMacFlags.Bits.McpsInd == 1 ) )
+ {
+ ChannelsNbRepCounter = 0;
+
+ AdrAckCounter++;
+ if( IsUpLinkCounterFixed == false )
+ {
+ UpLinkCounter++;
+ }
+
+ LoRaMacState &= ~LORAMAC_TX_RUNNING;
+ }
+ else
+ {
+ LoRaMacFlags.Bits.MacDone = 0;
+ // Sends the same frame again
+ OnTxDelayedTimerEvent(NULL);
+ }
+ }
+ }
+ }
+
+ if( LoRaMacFlags.Bits.McpsInd == 1 )
+ {// Procedure if we received a frame
+ if( ( McpsConfirm.AckReceived == true ) || ( AckTimeoutRetriesCounter > AckTimeoutRetries ) )
+ {
+ AckTimeoutRetry = false;
+ NodeAckRequested = false;
+ if( IsUpLinkCounterFixed == false )
+ {
+ UpLinkCounter++;
+ }
+ McpsConfirm.NbRetries = AckTimeoutRetriesCounter;
+
+ LoRaMacState &= ~LORAMAC_TX_RUNNING;
+ }
+ }
+
+ if( ( AckTimeoutRetry == true ) && ( ( LoRaMacState & LORAMAC_TX_DELAYED ) == 0 ) )
+ {// Retransmissions procedure for confirmed uplinks
+ AckTimeoutRetry = false;
+ if( ( AckTimeoutRetriesCounter < AckTimeoutRetries ) && ( AckTimeoutRetriesCounter <= MAX_ACK_RETRIES ) )
+ {
+ AckTimeoutRetriesCounter++;
+
+ if( ( AckTimeoutRetriesCounter % 2 ) == 1 )
+ {
+ LoRaMacParams.ChannelsDatarate = MAX( LoRaMacParams.ChannelsDatarate - 1, LORAMAC_TX_MIN_DATARATE );
+ }
+ if( ValidatePayloadLength( LoRaMacTxPayloadLen, LoRaMacParams.ChannelsDatarate, MacCommandsBufferIndex ) == true )
+ {
+ LoRaMacFlags.Bits.MacDone = 0;
+ // Sends the same frame again
+ ScheduleTx( );
+ }
+ else
+ {
+ // The DR is not applicable for the payload size
+ McpsConfirm.Status = LORAMAC_EVENT_INFO_STATUS_TX_DR_PAYLOAD_SIZE_ERROR;
+
+ LoRaMacState &= ~LORAMAC_TX_RUNNING;
+ NodeAckRequested = false;
+ McpsConfirm.AckReceived = false;
+ McpsConfirm.NbRetries = AckTimeoutRetriesCounter;
+ McpsConfirm.Datarate = LoRaMacParams.ChannelsDatarate;
+ if( IsUpLinkCounterFixed == false )
+ {
+ UpLinkCounter++;
+ }
+ }
+ }
+ else
+ {
+#if defined( USE_BAND_433 ) || defined( USE_BAND_780 ) || defined( USE_BAND_868 )
+ // Re-enable default channels LC1, LC2, LC3
+ LoRaMacParams.ChannelsMask[0] = LoRaMacParams.ChannelsMask[0] | ( LC( 1 ) + LC( 2 ) + LC( 3 ) );
+#elif defined( USE_BAND_470 )
+ // Re-enable default channels
+ memcpy( ( uint8_t* )LoRaMacParams.ChannelsMask, ( uint8_t* )LoRaMacParamsDefaults.ChannelsMask, sizeof( LoRaMacParams.ChannelsMask ) );
+#elif defined( USE_BAND_915 )
+ // Re-enable default channels
+ memcpy( ( uint8_t* )LoRaMacParams.ChannelsMask, ( uint8_t* )LoRaMacParamsDefaults.ChannelsMask, sizeof( LoRaMacParams.ChannelsMask ) );
+#elif defined( USE_BAND_915_HYBRID )
+ // Re-enable default channels
+ ReenableChannels( LoRaMacParamsDefaults.ChannelsMask[4], LoRaMacParams.ChannelsMask );
+#else
+ #error "Please define a frequency band in the compiler options."
+#endif
+ LoRaMacState &= ~LORAMAC_TX_RUNNING;
+
+ NodeAckRequested = false;
+ McpsConfirm.AckReceived = false;
+ McpsConfirm.NbRetries = AckTimeoutRetriesCounter;
+ if( IsUpLinkCounterFixed == false )
+ {
+ UpLinkCounter++;
+ }
+ }
+ }
+ }
+ // Handle reception for Class B and Class C
+ if( ( LoRaMacState & LORAMAC_RX ) == LORAMAC_RX )
+ {
+ LoRaMacState &= ~LORAMAC_RX;
+ }
+ if( LoRaMacState == LORAMAC_IDLE )
+ {
+ if( LoRaMacFlags.Bits.McpsReq == 1 )
+ {
+ LoRaMacPrimitives->MacMcpsConfirm( &McpsConfirm );
+ LoRaMacFlags.Bits.McpsReq = 0;
+ }
+
+ if( LoRaMacFlags.Bits.MlmeReq == 1 )
+ {
+ LoRaMacPrimitives->MacMlmeConfirm( &MlmeConfirm );
+ LoRaMacFlags.Bits.MlmeReq = 0;
+ }
+
+ LoRaMacFlags.Bits.MacDone = 0;
+ }
+ else
+ {
+ // Operation not finished restart timer
+ os_cputime_timer_relative(&MacStateCheckTimer,
+ MAC_STATE_CHECK_TIMEOUT);
+ }
+
+ if( LoRaMacFlags.Bits.McpsInd == 1 )
+ {
+ LoRaMacPrimitives->MacMcpsIndication( &McpsIndication );
+ LoRaMacFlags.Bits.McpsInd = 0;
+ }
+}
+
+static void OnTxDelayedTimerEvent(void *unused)
+{
+ LoRaMacHeader_t macHdr;
+ LoRaMacFrameCtrl_t fCtrl;
+
+ os_cputime_timer_stop(&TxDelayedTimer);
+ LoRaMacState &= ~LORAMAC_TX_DELAYED;
+
+ if( ( LoRaMacFlags.Bits.MlmeReq == 1 ) && ( MlmeConfirm.MlmeRequest == MLME_JOIN ) )
+ {
+ ResetMacParameters( );
+ // Add a +1, since we start to count from 0
+ LoRaMacParams.ChannelsDatarate = AlternateDatarate( JoinRequestTrials + 1 );
+
+ macHdr.Value = 0;
+ macHdr.Bits.MType = FRAME_TYPE_JOIN_REQ;
+
+ fCtrl.Value = 0;
+ fCtrl.Bits.Adr = AdrCtrlOn;
+
+ /* In case of join request retransmissions, the stack must prepare
+ * the frame again, because the network server keeps track of the random
+ * LoRaMacDevNonce values to prevent reply attacks. */
+ PrepareFrame( &macHdr, &fCtrl, 0, NULL, 0 );
+ }
+
+ ScheduleTx( );
+}
+
+static void OnRxWindow1TimerEvent(void *unused)
+{
+ uint16_t symbTimeout = 5; // DR_2, DR_1, DR_0
+ int8_t datarate = 0;
+ uint32_t bandwidth = 0; // LoRa 125 kHz
+
+ os_cputime_timer_stop(&RxWindowTimer1);
+ RxSlot = 0;
+
+ if( LoRaMacDeviceClass == CLASS_C )
+ {
+ Radio.Standby( );
+ }
+
+#if defined( USE_BAND_433 ) || defined( USE_BAND_780 ) || defined( USE_BAND_868 )
+ datarate = LoRaMacParams.ChannelsDatarate - LoRaMacParams.Rx1DrOffset;
+ if( datarate < 0 )
+ {
+ datarate = DR_0;
+ }
+
+ // For higher datarates, we increase the number of symbols generating a Rx Timeout
+ if( ( datarate == DR_3 ) || ( datarate == DR_4 ) )
+ { // DR_4, DR_3
+ symbTimeout = 8;
+ }
+ else if( datarate == DR_5 )
+ {
+ symbTimeout = 10;
+ }
+ else if( datarate == DR_6 )
+ {// LoRa 250 kHz
+ bandwidth = 1;
+ symbTimeout = 14;
+ }
+ RxWindowSetup( Channels[Channel].Frequency, datarate, bandwidth, symbTimeout, false );
+#elif defined( USE_BAND_470 )
+ datarate = LoRaMacParams.ChannelsDatarate - LoRaMacParams.Rx1DrOffset;
+ if( datarate < 0 )
+ {
+ datarate = DR_0;
+ }
+
+ // For higher datarates, we increase the number of symbols generating a Rx Timeout
+ if( ( datarate == DR_3 ) || ( datarate == DR_4 ) )
+ { // DR_4, DR_3
+ symbTimeout = 8;
+ }
+ else if( datarate == DR_5 )
+ {
+ symbTimeout = 10;
+ }
+ RxWindowSetup( LORAMAC_FIRST_RX1_CHANNEL + ( Channel % 48 ) * LORAMAC_STEPWIDTH_RX1_CHANNEL, datarate, bandwidth, symbTimeout, false );
+#elif ( defined( USE_BAND_915 ) || defined( USE_BAND_915_HYBRID ) )
+ datarate = datarateOffsets[LoRaMacParams.ChannelsDatarate][LoRaMacParams.Rx1DrOffset];
+ if( datarate < 0 )
+ {
+ datarate = DR_0;
+ }
+ // For higher datarates, we increase the number of symbols generating a Rx Timeout
+ switch( datarate )
+ {
+ case DR_0: // SF10 - BW125
+ symbTimeout = 5;
+ break;
+
+ case DR_1: // SF9 - BW125
+ case DR_2: // SF8 - BW125
+ case DR_8: // SF12 - BW500
+ case DR_9: // SF11 - BW500
+ case DR_10: // SF10 - BW500
+ symbTimeout = 8;
+ break;
+
+ case DR_3: // SF7 - BW125
+ case DR_11: // SF9 - BW500
+ symbTimeout = 10;
+ break;
+
+ case DR_4: // SF8 - BW500
+ case DR_12: // SF8 - BW500
+ symbTimeout = 14;
+ break;
+
+ case DR_13: // SF7 - BW500
+ symbTimeout = 16;
+ break;
+ default:
+ break;
+ }
+ if( datarate >= DR_4 )
+ {// LoRa 500 kHz
+ bandwidth = 2;
+ }
+ RxWindowSetup( LORAMAC_FIRST_RX1_CHANNEL + ( Channel % 8 ) * LORAMAC_STEPWIDTH_RX1_CHANNEL, datarate, bandwidth, symbTimeout, false );
+#else
+ #error "Please define a frequency band in the compiler options."
+#endif
+}
+
+static void OnRxWindow2TimerEvent(void *unused)
+{
+ uint16_t symbTimeout = 5; // DR_2, DR_1, DR_0
+ uint32_t bandwidth = 0; // LoRa 125 kHz
+ bool rxContinuousMode = false;
+
+ os_cputime_timer_stop(&RxWindowTimer2);
+
+#if defined( USE_BAND_433 ) || defined( USE_BAND_780 ) || defined( USE_BAND_868 )
+ // For higher datarates, we increase the number of symbols generating a Rx Timeout
+ if( ( LoRaMacParams.Rx2Channel.Datarate == DR_3 ) || ( LoRaMacParams.Rx2Channel.Datarate == DR_4 ) )
+ { // DR_4, DR_3
+ symbTimeout = 8;
+ }
+ else if( LoRaMacParams.Rx2Channel.Datarate == DR_5 )
+ {
+ symbTimeout = 10;
+ }
+ else if( LoRaMacParams.Rx2Channel.Datarate == DR_6 )
+ {// LoRa 250 kHz
+ bandwidth = 1;
+ symbTimeout = 14;
+ }
+#elif defined( USE_BAND_470 )
+ // For higher datarates, we increase the number of symbols generating a Rx Timeout
+ if( ( LoRaMacParams.Rx2Channel.Datarate == DR_3 ) || ( LoRaMacParams.Rx2Channel.Datarate == DR_4 ) )
+ { // DR_4, DR_3
+ symbTimeout = 8;
+ }
+ else if( LoRaMacParams.Rx2Channel.Datarate == DR_5 )
+ {
+ symbTimeout = 10;
+ }
+#elif ( defined( USE_BAND_915 ) || defined( USE_BAND_915_HYBRID ) )
+ // For higher datarates, we increase the number of symbols generating a Rx Timeout
+ switch( LoRaMacParams.Rx2Channel.Datarate )
+ {
+ case DR_0: // SF10 - BW125
+ symbTimeout = 5;
+ break;
+
+ case DR_1: // SF9 - BW125
+ case DR_2: // SF8 - BW125
+ case DR_8: // SF12 - BW500
+ case DR_9: // SF11 - BW500
+ case DR_10: // SF10 - BW500
+ symbTimeout = 8;
+ break;
+
+ case DR_3: // SF7 - BW125
+ case DR_11: // SF9 - BW500
+ symbTimeout = 10;
+ break;
+
+ case DR_4: // SF8 - BW500
+ case DR_12: // SF8 - BW500
+ symbTimeout = 14;
+ break;
+
+ case DR_13: // SF7 - BW500
+ symbTimeout = 16;
+ break;
+ default:
+ break;
+ }
+ if( LoRaMacParams.Rx2Channel.Datarate >= DR_4 )
+ {// LoRa 500 kHz
+ bandwidth = 2;
+ }
+#else
+ #error "Please define a frequency band in the compiler options."
+#endif
+ if( LoRaMacDeviceClass == CLASS_C )
+ {
+ rxContinuousMode = true;
+ }
+ if( RxWindowSetup( LoRaMacParams.Rx2Channel.Frequency, LoRaMacParams.Rx2Channel.Datarate, bandwidth, symbTimeout, rxContinuousMode ) == true )
+ {
+ RxSlot = 1;
+ }
+}
+
+static void OnAckTimeoutTimerEvent(void *unused)
+{
+ os_cputime_timer_stop(&AckTimeoutTimer);
+
+ if( NodeAckRequested == true )
+ {
+ AckTimeoutRetry = true;
+ LoRaMacState &= ~LORAMAC_ACK_REQ;
+ }
+ if( LoRaMacDeviceClass == CLASS_C )
+ {
+ LoRaMacFlags.Bits.MacDone = 1;
+ }
+}
+
+static bool SetNextChannel( uint32_t* time )
+{
+ uint8_t nbEnabledChannels = 0;
+ uint8_t delayTx = 0;
+ uint8_t enabledChannels[LORA_MAX_NB_CHANNELS];
+ uint32_t nextTxDelay = ( uint32_t )( -1 );
+
+ memset( enabledChannels, 0, LORA_MAX_NB_CHANNELS );
+
+#if defined( USE_BAND_915 ) || defined( USE_BAND_915_HYBRID )
+ if( CountNbEnabled125kHzChannels( ChannelsMaskRemaining ) == 0 )
+ { // Restore default channels
+ memcpy( ( uint8_t* ) ChannelsMaskRemaining, ( uint8_t* ) LoRaMacParams.ChannelsMask, 8 );
+ }
+ if( ( LoRaMacParams.ChannelsDatarate >= DR_4 ) && ( ( ChannelsMaskRemaining[4] & 0x00FF ) == 0 ) )
+ { // Make sure, that the channels are activated
+ ChannelsMaskRemaining[4] = LoRaMacParams.ChannelsMask[4];
+ }
+#elif defined( USE_BAND_470 )
+ if( ( CountBits( LoRaMacParams.ChannelsMask[0], 16 ) == 0 ) &&
+ ( CountBits( LoRaMacParams.ChannelsMask[1], 16 ) == 0 ) &&
+ ( CountBits( LoRaMacParams.ChannelsMask[2], 16 ) == 0 ) &&
+ ( CountBits( LoRaMacParams.ChannelsMask[3], 16 ) == 0 ) &&
+ ( CountBits( LoRaMacParams.ChannelsMask[4], 16 ) == 0 ) &&
+ ( CountBits( LoRaMacParams.ChannelsMask[5], 16 ) == 0 ) )
+ {
+ memcpy( ( uint8_t* )LoRaMacParams.ChannelsMask, ( uint8_t* )LoRaMacParamsDefaults.ChannelsMask, sizeof( LoRaMacParams.ChannelsMask ) );
+ }
+#else
+ if( CountBits( LoRaMacParams.ChannelsMask[0], 16 ) == 0 )
+ {
+ // Re-enable default channels, if no channel is enabled
+ LoRaMacParams.ChannelsMask[0] = LoRaMacParams.ChannelsMask[0] | ( LC( 1 ) + LC( 2 ) + LC( 3 ) );
+ }
+#endif
+
+ // Update Aggregated duty cycle
+ if( AggregatedTimeOff <= TimerGetElapsedTime( AggregatedLastTxDoneTime ) )
+ {
+ AggregatedTimeOff = 0;
+
+ // Update bands Time OFF
+ for( uint8_t i = 0; i < LORA_MAX_NB_BANDS; i++ )
+ {
+ if( ( IsLoRaMacNetworkJoined == false ) || ( DutyCycleOn == true ) )
+ {
+ if( Bands[i].TimeOff <= TimerGetElapsedTime( Bands[i].LastTxDoneTime ) )
+ {
+ Bands[i].TimeOff = 0;
+ }
+ if( Bands[i].TimeOff != 0 )
+ {
+ nextTxDelay = MIN( Bands[i].TimeOff - TimerGetElapsedTime( Bands[i].LastTxDoneTime ), nextTxDelay );
+ }
+ }
+ else
+ {
+ if( DutyCycleOn == false )
+ {
+ Bands[i].TimeOff = 0;
+ }
+ }
+ }
+
+ // Search how many channels are enabled
+ for( uint8_t i = 0, k = 0; i < LORA_MAX_NB_CHANNELS; i += 16, k++ )
+ {
+ for( uint8_t j = 0; j < 16; j++ )
+ {
+#if defined( USE_BAND_915 ) || defined( USE_BAND_915_HYBRID )
+ if( ( ChannelsMaskRemaining[k] & ( 1 << j ) ) != 0 )
+#else
+ if( ( LoRaMacParams.ChannelsMask[k] & ( 1 << j ) ) != 0 )
+#endif
+ {
+ if( Channels[i + j].Frequency == 0 )
+ { // Check if the channel is enabled
+ continue;
+ }
+#if defined( USE_BAND_868 ) || defined( USE_BAND_433 ) || defined( USE_BAND_780 )
+ if( IsLoRaMacNetworkJoined == false )
+ {
+ if( ( JOIN_CHANNELS & ( 1 << j ) ) == 0 )
+ {
+ continue;
+ }
+ }
+#endif
+ if( ( ( Channels[i + j].DrRange.Fields.Min <= LoRaMacParams.ChannelsDatarate ) &&
+ ( LoRaMacParams.ChannelsDatarate <= Channels[i + j].DrRange.Fields.Max ) ) == false )
+ { // Check if the current channel selection supports the given datarate
+ continue;
+ }
+ if( Bands[Channels[i + j].Band].TimeOff > 0 )
+ { // Check if the band is available for transmission
+ delayTx++;
+ continue;
+ }
+ enabledChannels[nbEnabledChannels++] = i + j;
+ }
+ }
+ }
+ }
+ else
+ {
+ delayTx++;
+ nextTxDelay = AggregatedTimeOff - TimerGetElapsedTime( AggregatedLastTxDoneTime );
+ }
+
+ if( nbEnabledChannels > 0 )
+ {
+ Channel = enabledChannels[randr( 0, nbEnabledChannels - 1 )];
+#if defined( USE_BAND_915 ) || defined( USE_BAND_915_HYBRID )
+ if( Channel < ( LORA_MAX_NB_CHANNELS - 8 ) )
+ {
+ DisableChannelInMask( Channel, ChannelsMaskRemaining );
+ }
+#endif
+ *time = 0;
+ return true;
+ }
+ else
+ {
+ if( delayTx > 0 )
+ {
+ // Delay transmission due to AggregatedTimeOff or to a band time off
+ *time = nextTxDelay;
+ return true;
+ }
+ // Datarate not supported by any channel
+ *time = 0;
+ return false;
+ }
+}
+
+static bool RxWindowSetup( uint32_t freq, int8_t datarate, uint32_t bandwidth, uint16_t timeout, bool rxContinuous )
+{
+ uint8_t downlinkDatarate = Datarates[datarate];
+ RadioModems_t modem;
+
+ if( Radio.GetStatus( ) == RF_IDLE )
+ {
+ Radio.SetChannel( freq );
+
+ // Store downlink datarate
+ McpsIndication.RxDatarate = ( uint8_t ) datarate;
+
+#if defined( USE_BAND_433 ) || defined( USE_BAND_780 ) || defined( USE_BAND_868 )
+ if( datarate == DR_7 )
+ {
+ modem = MODEM_FSK;
+ Radio.SetRxConfig( modem, 50e3, downlinkDatarate * 1e3, 0, 83.333e3, 5, 0, false, 0, true, 0, 0, false, rxContinuous );
+ }
+ else
+ {
+ modem = MODEM_LORA;
+ Radio.SetRxConfig( modem, bandwidth, downlinkDatarate, 1, 0, 8, timeout, false, 0, false, 0, 0, true, rxContinuous );
+ }
+#elif defined( USE_BAND_470 ) || defined( USE_BAND_915 ) || defined( USE_BAND_915_HYBRID )
+ modem = MODEM_LORA;
+ Radio.SetRxConfig( modem, bandwidth, downlinkDatarate, 1, 0, 8, timeout, false, 0, false, 0, 0, true, rxContinuous );
+#endif
+
+ if( RepeaterSupport == true )
+ {
+ Radio.SetMaxPayloadLength( modem, MaxPayloadOfDatarateRepeater[datarate] + LORA_MAC_FRMPAYLOAD_OVERHEAD );
+ }
+ else
+ {
+ Radio.SetMaxPayloadLength( modem, MaxPayloadOfDatarate[datarate] + LORA_MAC_FRMPAYLOAD_OVERHEAD );
+ }
+
+ if( rxContinuous == false )
+ {
+ Radio.Rx( LoRaMacParams.MaxRxWindow );
+ }
+ else
+ {
+ Radio.Rx( 0 ); // Continuous mode
+ }
+ return true;
+ }
+ return false;
+}
+
+static bool Rx2FreqInRange( uint32_t freq )
+{
+#if defined( USE_BAND_433 ) || defined( USE_BAND_780 ) || defined( USE_BAND_868 )
+ if( Radio.CheckRfFrequency( freq ) == true )
+#elif defined( USE_BAND_470 ) || defined( USE_BAND_915 ) || defined( USE_BAND_915_HYBRID )
+ if( ( Radio.CheckRfFrequency( freq ) == true ) &&
+ ( freq >= LORAMAC_FIRST_RX1_CHANNEL ) &&
+ ( freq <= LORAMAC_LAST_RX1_CHANNEL ) &&
+ ( ( ( freq - ( uint32_t ) LORAMAC_FIRST_RX1_CHANNEL ) % ( uint32_t ) LORAMAC_STEPWIDTH_RX1_CHANNEL ) == 0 ) )
+#endif
+ {
+ return true;
+ }
+ return false;
+}
+
+static bool ValidatePayloadLength( uint8_t lenN, int8_t datarate, uint8_t fOptsLen )
+{
+ uint16_t maxN = 0;
+ uint16_t payloadSize = 0;
+
+ // Get the maximum payload length
+ if( RepeaterSupport == true )
+ {
+ maxN = MaxPayloadOfDatarateRepeater[datarate];
+ }
+ else
+ {
+ maxN = MaxPayloadOfDatarate[datarate];
+ }
+
+ // Calculate the resulting payload size
+ payloadSize = ( lenN + fOptsLen );
+
+ // Validation of the application payload size
+ if( ( payloadSize <= maxN ) && ( payloadSize <= LORAMAC_PHY_MAXPAYLOAD ) )
+ {
+ return true;
+ }
+ return false;
+}
+
+static uint8_t CountBits( uint16_t mask, uint8_t nbBits )
+{
+ uint8_t nbActiveBits = 0;
+
+ for( uint8_t j = 0; j < nbBits; j++ )
+ {
+ if( ( mask & ( 1 << j ) ) == ( 1 << j ) )
+ {
+ nbActiveBits++;
+ }
+ }
+ return nbActiveBits;
+}
+
+#if defined( USE_BAND_915 ) || defined( USE_BAND_915_HYBRID )
+static uint8_t CountNbEnabled125kHzChannels( uint16_t *channelsMask )
+{
+ uint8_t nb125kHzChannels = 0;
+
+ for( uint8_t i = 0, k = 0; i < LORA_MAX_NB_CHANNELS - 8; i += 16, k++ )
+ {
+ nb125kHzChannels += CountBits( channelsMask[k], 16 );
+ }
+
+ return nb125kHzChannels;
+}
+
+#if defined( USE_BAND_915_HYBRID )
+static void ReenableChannels( uint16_t mask, uint16_t* channelsMask )
+{
+ uint16_t blockMask = mask;
+
+ for( uint8_t i = 0, j = 0; i < 4; i++, j += 2 )
+ {
+ channelsMask[i] = 0;
+ if( ( blockMask & ( 1 << j ) ) != 0 )
+ {
+ channelsMask[i] |= 0x00FF;
+ }
+ if( ( blockMask & ( 1 << ( j + 1 ) ) ) != 0 )
+ {
+ channelsMask[i] |= 0xFF00;
+ }
+ }
+ channelsMask[4] = blockMask;
+ channelsMask[5] = 0x0000;
+}
+
+static bool ValidateChannelMask( uint16_t* channelsMask )
+{
+ bool chanMaskState = false;
+ uint16_t block1 = 0;
+ uint16_t block2 = 0;
+ uint8_t index = 0;
+
+ for( uint8_t i = 0; i < 4; i++ )
+ {
+ block1 = channelsMask[i] & 0x00FF;
+ block2 = channelsMask[i] & 0xFF00;
+
+ if( ( CountBits( block1, 16 ) > 5 ) && ( chanMaskState == false ) )
+ {
+ channelsMask[i] &= block1;
+ channelsMask[4] = 1 << ( i * 2 );
+ chanMaskState = true;
+ index = i;
+ }
+ else if( ( CountBits( block2, 16 ) > 5 ) && ( chanMaskState == false ) )
+ {
+ channelsMask[i] &= block2;
+ channelsMask[4] = 1 << ( i * 2 + 1 );
+ chanMaskState = true;
+ index = i;
+ }
+ }
+
+ // Do only change the channel mask, if we have found a valid block.
+ if( chanMaskState == true )
+ {
+ for( uint8_t i = 0; i < 4; i++ )
+ {
+ if( i != index )
+ {
+ channelsMask[i] = 0;
+ }
+ }
+ }
+ return chanMaskState;
+}
+#endif
+#endif
+
+static bool ValidateDatarate( int8_t datarate, uint16_t* channelsMask )
+{
+ if( ValueInRange( datarate, LORAMAC_TX_MIN_DATARATE, LORAMAC_TX_MAX_DATARATE ) == false )
+ {
+ return false;
+ }
+ for( uint8_t i = 0, k = 0; i < LORA_MAX_NB_CHANNELS; i += 16, k++ )
+ {
+ for( uint8_t j = 0; j < 16; j++ )
+ {
+ if( ( ( channelsMask[k] & ( 1 << j ) ) != 0 ) )
+ {// Check datarate validity for enabled channels
+ if( ValueInRange( datarate, Channels[i + j].DrRange.Fields.Min, Channels[i + j].DrRange.Fields.Max ) == true )
+ {
+ // At least 1 channel has been found we can return OK.
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+}
+
+static int8_t LimitTxPower( int8_t txPower, int8_t maxBandTxPower )
+{
+ int8_t resultTxPower = txPower;
+
+ // Limit tx power to the band max
+ resultTxPower = MAX( txPower, maxBandTxPower );
+
+#if defined( USE_BAND_915 ) || defined( USE_BAND_915_HYBRID )
+ if( ( LoRaMacParams.ChannelsDatarate == DR_4 ) ||
+ ( ( LoRaMacParams.ChannelsDatarate >= DR_8 ) && ( LoRaMacParams.ChannelsDatarate <= DR_13 ) ) )
+ {// Limit tx power to max 26dBm
+ resultTxPower = MAX( txPower, TX_POWER_26_DBM );
+ }
+ else
+ {
+ if( CountNbEnabled125kHzChannels( LoRaMacParams.ChannelsMask ) < 50 )
+ {// Limit tx power to max 21dBm
+ resultTxPower = MAX( txPower, TX_POWER_20_DBM );
+ }
+ }
+#endif
+ return resultTxPower;
+}
+
+static bool ValueInRange( int8_t value, int8_t min, int8_t max )
+{
+ if( ( value >= min ) && ( value <= max ) )
+ {
+ return true;
+ }
+ return false;
+}
+
+static bool DisableChannelInMask( uint8_t id, uint16_t* mask )
+{
+ uint8_t index = 0;
+ index = id / 16;
+
+ if( ( index > 4 ) || ( id >= LORA_MAX_NB_CHANNELS ) )
+ {
+ return false;
+ }
+
+ // Deactivate channel
+ mask[index] &= ~( 1 << ( id % 16 ) );
+
+ return true;
+}
+
+static bool AdrNextDr( bool adrEnabled, bool updateChannelMask, int8_t* datarateOut )
+{
+ bool adrAckReq = false;
+ int8_t datarate = LoRaMacParams.ChannelsDatarate;
+
+ if( adrEnabled == true )
+ {
+ if( datarate == LORAMAC_TX_MIN_DATARATE )
+ {
+ AdrAckCounter = 0;
+ adrAckReq = false;
+ }
+ else
+ {
+ if( AdrAckCounter >= ADR_ACK_LIMIT )
+ {
+ adrAckReq = true;
+ LoRaMacParams.ChannelsTxPower = LORAMAC_MAX_TX_POWER;
+ }
+ else
+ {
+ adrAckReq = false;
+ }
+ if( AdrAckCounter >= ( ADR_ACK_LIMIT + ADR_ACK_DELAY ) )
+ {
+ if( ( AdrAckCounter % ADR_ACK_DELAY ) == 0 )
+ {
+#if defined( USE_BAND_433 ) || defined( USE_BAND_780 ) || defined( USE_BAND_868 )
+ if( datarate > LORAMAC_TX_MIN_DATARATE )
+ {
+ datarate--;
+ }
+ if( datarate == LORAMAC_TX_MIN_DATARATE )
+ {
+ if( updateChannelMask == true )
+ {
+ // Re-enable default channels LC1, LC2, LC3
+ LoRaMacParams.ChannelsMask[0] = LoRaMacParams.ChannelsMask[0] | ( LC( 1 ) + LC( 2 ) + LC( 3 ) );
+ }
+ }
+#elif defined( USE_BAND_470 )
+ if( datarate > LORAMAC_TX_MIN_DATARATE )
+ {
+ datarate--;
+ }
+ if( datarate == LORAMAC_TX_MIN_DATARATE )
+ {
+ if( updateChannelMask == true )
+ {
+ // Re-enable default channels
+ memcpy( ( uint8_t* )LoRaMacParams.ChannelsMask, ( uint8_t* )LoRaMacParamsDefaults.ChannelsMask, sizeof( LoRaMacParams.ChannelsMask ) );
+ }
+ }
+#elif defined( USE_BAND_915 ) || defined( USE_BAND_915_HYBRID )
+ if( ( datarate > LORAMAC_TX_MIN_DATARATE ) && ( datarate == DR_8 ) )
+ {
+ datarate = DR_4;
+ }
+ else if( datarate > LORAMAC_TX_MIN_DATARATE )
+ {
+ datarate--;
+ }
+ if( datarate == LORAMAC_TX_MIN_DATARATE )
+ {
+ if( updateChannelMask == true )
+ {
+#if defined( USE_BAND_915 )
+ // Re-enable default channels
+ memcpy( ( uint8_t* )LoRaMacParams.ChannelsMask, ( uint8_t* )LoRaMacParamsDefaults.ChannelsMask, sizeof( LoRaMacParams.ChannelsMask ) );
+#else // defined( USE_BAND_915_HYBRID )
+ // Re-enable default channels
+ ReenableChannels( LoRaMacParamsDefaults.ChannelsMask[4], LoRaMacParams.ChannelsMask );
+#endif
+ }
+ }
+#else
+#error "Please define a frequency band in the compiler options."
+#endif
+ }
+ }
+ }
+ }
+
+ *datarateOut = datarate;
+
+ return adrAckReq;
+}
+
+static LoRaMacStatus_t AddMacCommand( uint8_t cmd, uint8_t p1, uint8_t p2 )
+{
+ LoRaMacStatus_t status = LORAMAC_STATUS_BUSY;
+ // The maximum buffer length must take MAC commands to re-send into account.
+ uint8_t bufLen = LORA_MAC_COMMAND_MAX_LENGTH - MacCommandsBufferToRepeatIndex;
+
+ switch( cmd )
+ {
+ case MOTE_MAC_LINK_CHECK_REQ:
+ if( MacCommandsBufferIndex < bufLen )
+ {
+ MacCommandsBuffer[MacCommandsBufferIndex++] = cmd;
+ // No payload for this command
+ status = LORAMAC_STATUS_OK;
+ }
+ break;
+ case MOTE_MAC_LINK_ADR_ANS:
+ if( MacCommandsBufferIndex < ( bufLen - 1 ) )
+ {
+ MacCommandsBuffer[MacCommandsBufferIndex++] = cmd;
+ // Margin
+ MacCommandsBuffer[MacCommandsBufferIndex++] = p1;
+ status = LORAMAC_STATUS_OK;
+ }
+ break;
+ case MOTE_MAC_DUTY_CYCLE_ANS:
+ if( MacCommandsBufferIndex < bufLen )
+ {
+ MacCommandsBuffer[MacCommandsBufferIndex++] = cmd;
+ // No payload for this answer
+ status = LORAMAC_STATUS_OK;
+ }
+ break;
+ case MOTE_MAC_RX_PARAM_SETUP_ANS:
+ if( MacCommandsBufferIndex < ( bufLen - 1 ) )
+ {
+ MacCommandsBuffer[MacCommandsBufferIndex++] = cmd;
+ // Status: Datarate ACK, Channel ACK
+ MacCommandsBuffer[MacCommandsBufferIndex++] = p1;
+ status = LORAMAC_STATUS_OK;
+ }
+ break;
+ case MOTE_MAC_DEV_STATUS_ANS:
+ if( MacCommandsBufferIndex < ( bufLen - 2 ) )
+ {
+ MacCommandsBuffer[MacCommandsBufferIndex++] = cmd;
+ // 1st byte Battery
+ // 2nd byte Margin
+ MacCommandsBuffer[MacCommandsBufferIndex++] = p1;
+ MacCommandsBuffer[MacCommandsBufferIndex++] = p2;
+ status = LORAMAC_STATUS_OK;
+ }
+ break;
+ case MOTE_MAC_NEW_CHANNEL_ANS:
+ if( MacCommandsBufferIndex < ( bufLen - 1 ) )
+ {
+ MacCommandsBuffer[MacCommandsBufferIndex++] = cmd;
+ // Status: Datarate range OK, Channel frequency OK
+ MacCommandsBuffer[MacCommandsBufferIndex++] = p1;
+ status = LORAMAC_STATUS_OK;
+ }
+ break;
+ case MOTE_MAC_RX_TIMING_SETUP_ANS:
+ if( MacCommandsBufferIndex < bufLen )
+ {
+ MacCommandsBuffer[MacCommandsBufferIndex++] = cmd;
+ // No payload for this answer
+ status = LORAMAC_STATUS_OK;
+ }
+ break;
+ default:
+ return LORAMAC_STATUS_SERVICE_UNKNOWN;
+ }
+ if( status == LORAMAC_STATUS_OK )
+ {
+ MacCommandsInNextTx = true;
+ }
+ return status;
+}
+
+static uint8_t ParseMacCommandsToRepeat( uint8_t* cmdBufIn, uint8_t length, uint8_t* cmdBufOut )
+{
+ uint8_t i = 0;
+ uint8_t cmdCount = 0;
+
+ if( ( cmdBufIn == NULL ) || ( cmdBufOut == NULL ) )
+ {
+ return 0;
+ }
+
+ for( i = 0; i < length; i++ )
+ {
+ switch( cmdBufIn[i] )
+ {
+ // STICKY
+ case MOTE_MAC_RX_PARAM_SETUP_ANS:
+ {
+ cmdBufOut[cmdCount++] = cmdBufIn[i++];
+ cmdBufOut[cmdCount++] = cmdBufIn[i];
+ break;
+ }
+ case MOTE_MAC_RX_TIMING_SETUP_ANS:
+ {
+ cmdBufOut[cmdCount++] = cmdBufIn[i];
+ break;
+ }
+ // NON-STICKY
+ case MOTE_MAC_DEV_STATUS_ANS:
+ { // 2 bytes payload
+ i += 2;
+ break;
+ }
+ case MOTE_MAC_LINK_ADR_ANS:
+ case MOTE_MAC_NEW_CHANNEL_ANS:
+ { // 1 byte payload
+ i++;
+ break;
+ }
+ case MOTE_MAC_DUTY_CYCLE_ANS:
+ case MOTE_MAC_LINK_CHECK_REQ:
+ { // 0 byte payload
+ break;
+ }
+ default:
+ break;
+ }
+ }
+
+ return cmdCount;
+}
+
+static void ProcessMacCommands( uint8_t *payload, uint8_t macIndex, uint8_t commandsSize, uint8_t snr )
+{
+ while( macIndex < commandsSize )
+ {
+ // Decode Frame MAC commands
+ switch( payload[macIndex++] )
+ {
+ case SRV_MAC_LINK_CHECK_ANS:
+ MlmeConfirm.Status = LORAMAC_EVENT_INFO_STATUS_OK;
+ MlmeConfirm.DemodMargin = payload[macIndex++];
+ MlmeConfirm.NbGateways = payload[macIndex++];
+ break;
+ case SRV_MAC_LINK_ADR_REQ:
+ {
+ uint8_t i;
+ uint8_t status = 0x07;
+ uint16_t chMask;
+ int8_t txPower = 0;
+ int8_t datarate = 0;
+ uint8_t nbRep = 0;
+ uint8_t chMaskCntl = 0;
+ uint16_t channelsMask[6] = { 0, 0, 0, 0, 0, 0 };
+
+ // Initialize local copy of the channels mask array
+ for( i = 0; i < 6; i++ )
+ {
+ channelsMask[i] = LoRaMacParams.ChannelsMask[i];
+ }
+ datarate = payload[macIndex++];
+ txPower = datarate & 0x0F;
+ datarate = ( datarate >> 4 ) & 0x0F;
+
+ if( ( AdrCtrlOn == false ) &&
+ ( ( LoRaMacParams.ChannelsDatarate != datarate ) || ( LoRaMacParams.ChannelsTxPower != txPower ) ) )
+ { // ADR disabled don't handle ADR requests if server tries to change datarate or txpower
+ // Answer the server with fail status
+ // Power ACK = 0
+ // Data rate ACK = 0
+ // Channel mask = 0
+ AddMacCommand( MOTE_MAC_LINK_ADR_ANS, 0, 0 );
+ macIndex += 3; // Skip over the remaining bytes of the request
+ break;
+ }
+ chMask = ( uint16_t )payload[macIndex++];
+ chMask |= ( uint16_t )payload[macIndex++] << 8;
+
+ nbRep = payload[macIndex++];
+ chMaskCntl = ( nbRep >> 4 ) & 0x07;
+ nbRep &= 0x0F;
+ if( nbRep == 0 )
+ {
+ nbRep = 1;
+ }
+#if defined( USE_BAND_433 ) || defined( USE_BAND_780 ) || defined( USE_BAND_868 )
+ if( ( chMaskCntl == 0 ) && ( chMask == 0 ) )
+ {
+ status &= 0xFE; // Channel mask KO
+ }
+ else if( ( ( chMaskCntl >= 1 ) && ( chMaskCntl <= 5 )) ||
+ ( chMaskCntl >= 7 ) )
+ {
+ // RFU
+ status &= 0xFE; // Channel mask KO
+ }
+ else
+ {
+ for( i = 0; i < LORA_MAX_NB_CHANNELS; i++ )
+ {
+ if( chMaskCntl == 6 )
+ {
+ if( Channels[i].Frequency != 0 )
+ {
+ chMask |= 1 << i;
+ }
+ }
+ else
+ {
+ if( ( ( chMask & ( 1 << i ) ) != 0 ) &&
+ ( Channels[i].Frequency == 0 ) )
+ {// Trying to enable an undefined channel
+ status &= 0xFE; // Channel mask KO
+ }
+ }
+ }
+ channelsMask[0] = chMask;
+ }
+#elif defined( USE_BAND_470 )
+ if( chMaskCntl == 6 )
+ {
+ // Enable all 125 kHz channels
+ for( uint8_t i = 0, k = 0; i < LORA_MAX_NB_CHANNELS; i += 16, k++ )
+ {
+ for( uint8_t j = 0; j < 16; j++ )
+ {
+ if( Channels[i + j].Frequency != 0 )
+ {
+ channelsMask[k] |= 1 << j;
+ }
+ }
+ }
+ }
+ else if( chMaskCntl == 7 )
+ {
+ status &= 0xFE; // Channel mask KO
+ }
+ else
+ {
+ for( uint8_t i = 0; i < 16; i++ )
+ {
+ if( ( ( chMask & ( 1 << i ) ) != 0 ) &&
+ ( Channels[chMaskCntl * 16 + i].Frequency == 0 ) )
+ {// Trying to enable an undefined channel
+ status &= 0xFE; // Channel mask KO
+ }
+ }
+ channelsMask[chMaskCntl] = chMask;
+ }
+#elif defined( USE_BAND_915 ) || defined( USE_BAND_915_HYBRID )
+ if( chMaskCntl == 6 )
+ {
+ // Enable all 125 kHz channels
+ channelsMask[0] = 0xFFFF;
+ channelsMask[1] = 0xFFFF;
+ channelsMask[2] = 0xFFFF;
+ channelsMask[3] = 0xFFFF;
+ // Apply chMask to channels 64 to 71
+ channelsMask[4] = chMask;
+ }
+ else if( chMaskCntl == 7 )
+ {
+ // Disable all 125 kHz channels
+ channelsMask[0] = 0x0000;
+ channelsMask[1] = 0x0000;
+ channelsMask[2] = 0x0000;
+ channelsMask[3] = 0x0000;
+ // Apply chMask to channels 64 to 71
+ channelsMask[4] = chMask;
+ }
+ else if( chMaskCntl == 5 )
+ {
+ // RFU
+ status &= 0xFE; // Channel mask KO
+ }
+ else
+ {
+ channelsMask[chMaskCntl] = chMask;
+
+ // FCC 15.247 paragraph F mandates to hop on at least 2 125 kHz channels
+ if( ( datarate < DR_4 ) && ( CountNbEnabled125kHzChannels( channelsMask ) < 2 ) )
+ {
+ status &= 0xFE; /
<TRUNCATED>
[40/40] incubator-mynewt-core git commit: This closes #260
Posted by ja...@apache.org.
This closes #260
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/958bce0a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/958bce0a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/958bce0a
Branch: refs/heads/bluetooth5
Commit: 958bce0a53d059f5de4e79d459d6ce9ec0fdc3f0
Parents: 4cab052 10e041b
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Mon May 8 16:30:54 2017 +0200
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon May 8 16:30:54 2017 +0200
----------------------------------------------------------------------
apps/iptest/src/main.c | 4 +-
apps/loraping/pkg.yml | 47 +
apps/loraping/src/loraping.h | 27 +
apps/loraping/src/main.c | 277 ++
apps/loraping/src/rxinfo.c | 139 +
apps/lorashell/pkg.yml | 34 +
apps/lorashell/src/main.c | 514 ++
apps/lorashell/syscfg.yml | 29 +
compiler/xc32/compiler.yml | 4 +-
compiler/xc32/pkg.yml | 3 +
encoding/cborattr/src/cborattr.c | 3 +-
encoding/cborattr/test/src/test_cborattr.c | 1 +
encoding/cborattr/test/src/test_cborattr.h | 1 +
.../testcases/cborattr_decode_substring_key.c | 111 +
hw/bsp/nrf51-blenano/src/hal_bsp.c | 31 +
hw/bsp/nrf51-blenano/syscfg.yml | 26 +
hw/bsp/pic32mx470_6lp_clicker/pkg.yml | 4 +-
hw/bsp/pic32mx470_6lp_clicker/src/hal_bsp.c | 2 +-
hw/bsp/pic32mz2048_wi-fire/pkg.yml | 2 +
hw/bsp/pic32mz2048_wi-fire/src/hal_bsp.c | 2 +-
hw/bsp/pic32mz2048_wi-fire/src/os_bsp.c | 2 +-
.../src/arch/cortex_m4/startup_STM32F429x.s | 3 -
hw/bsp/telee02/pkg.yml | 3 +
hw/bsp/telee02/syscfg.yml | 1 +
hw/drivers/lora/sx1276/LICENSE.txt | 25 +
hw/drivers/lora/sx1276/include/radio/radio.h | 33 +
hw/drivers/lora/sx1276/pkg.yml | 32 +
hw/drivers/lora/sx1276/src/sx1276-board.c | 179 +
hw/drivers/lora/sx1276/src/sx1276-board.h | 127 +
hw/drivers/lora/sx1276/src/sx1276.c | 1824 +++++++
hw/drivers/lora/sx1276/src/sx1276.h | 364 ++
hw/drivers/lora/sx1276/src/sx1276Regs-Fsk.h | 1134 +++++
hw/drivers/lora/sx1276/src/sx1276Regs-LoRa.h | 565 +++
hw/drivers/lora/sx1276/syscfg.yml | 27 +
hw/drivers/lwip/stm32_eth/src/stm32_eth.c | 2 +-
hw/mcu/microchip/pic32mx470f512h/pkg.yml | 2 -
.../pic32mz2048efg100/include/mcu/mcu.h | 16 +
hw/mcu/microchip/pic32mz2048efg100/pkg.yml | 2 -
.../microchip/pic32mz2048efg100/src/hal_gpio.c | 485 ++
.../microchip/pic32mz2048efg100/src/hal_uart.c | 2 +-
.../arch/pic32/startup/cache-err-exception.S | 129 +
kernel/os/src/arch/pic32/startup/crt0.S | 623 +++
.../src/arch/pic32/startup/general-exception.S | 141 +
.../pic32/startup/simple-tlb-refill-exception.S | 135 +
.../stubs/default-bootstrap-exception-handler.c | 58 +
.../stubs/default-cache-err-exception-handler.c | 56 +
.../stubs/default-general-exception-handler.c | 54 +
.../src/arch/pic32/stubs/default-nmi-handler.S | 63 +
.../src/arch/pic32/stubs/default-on-bootstrap.c | 43 +
.../os/src/arch/pic32/stubs/default-on-reset.c | 43 +
...efault-simple-tlb-refill-exception-handler.c | 56 +
.../os/src/arch/pic32/stubs/pic32_init_cache.S | 299 ++
.../arch/pic32/stubs/pic32_init_tlb_ebi_sqi.S | 145 +
kernel/os/src/os_callout.c | 6 +-
net/lora/node/LICENSE.txt | 25 +
net/lora/node/README.md | 28 +
net/lora/node/include/node/lora.h | 34 +
.../node/include/node/mac/LoRaMac-definitions.h | 610 +++
net/lora/node/include/node/mac/LoRaMac.h | 1830 ++++++++
net/lora/node/include/node/mac/LoRaMacCrypto.h | 111 +
net/lora/node/include/node/mac/LoRaMacTest.h | 81 +
net/lora/node/include/node/radio.h | 337 ++
net/lora/node/include/node/utilities.h | 79 +
net/lora/node/pkg.yml | 41 +
net/lora/node/src/lora_cli.c | 569 +++
net/lora/node/src/lora_node.c | 48 +
net/lora/node/src/lora_priv.h | 44 +
net/lora/node/src/mac/LoRaMac.c | 4442 ++++++++++++++++++
net/lora/node/src/mac/LoRaMacCrypto.c | 203 +
net/lora/node/src/mac/aes.h | 160 +
net/lora/node/src/mac/cmac.h | 63 +
net/lora/node/src/utilities.c | 67 +
net/lora/node/syscfg.yml | 39 +
net/nimble/controller/src/ble_ll_conn_hci.c | 12 +-
net/nimble/host/src/ble_hs_dbg.c | 7 +-
net/nimble/host/src/ble_hs_hci_evt.c | 5 +-
sys/console/full/src/console.c | 6 +-
sys/console/minimal/src/console.c | 6 +-
util/parse/include/parse/parse.h | 47 +
util/parse/pkg.yml | 32 +
util/parse/src/parse.c | 263 ++
81 files changed, 17091 insertions(+), 38 deletions(-)
----------------------------------------------------------------------
[23/40] incubator-mynewt-core git commit: MYNEWT-741 lorashell - Tx
predictable payloads
Posted by ja...@apache.org.
MYNEWT-741 lorashell - Tx predictable payloads
This allows the receiver to calculate packet error rate.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/3fe2ef75
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/3fe2ef75
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/3fe2ef75
Branch: refs/heads/bluetooth5
Commit: 3fe2ef7574e1c1527e7b81082bc9c4184e38af05
Parents: 560fa92
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Apr 27 12:15:25 2017 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Fri Apr 28 17:27:52 2017 -0700
----------------------------------------------------------------------
apps/lorashell/src/main.c | 109 ++++++++++++++++++++++++++++++++---------
1 file changed, 85 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3fe2ef75/apps/lorashell/src/main.c
----------------------------------------------------------------------
diff --git a/apps/lorashell/src/main.c b/apps/lorashell/src/main.c
index 68c8635..71a3018 100644
--- a/apps/lorashell/src/main.c
+++ b/apps/lorashell/src/main.c
@@ -33,8 +33,11 @@
* # Print message on each receive.
* lora_rx_verbose 1
*
- * # Keep receiving until manual stop.
- * lora_rx_rpt
+ * # Clear receive log
+ * lora_rx_info clear
+ *
+ * # Keep receiving 50-byte packets until manual stop.
+ * lora_rx_rpt 50
*
* # Display information about recent receives.
* lora_rx_info
@@ -79,6 +82,7 @@ static int lorashell_rx_entry_idx;
static int lorashell_rx_entry_cnt;
static int lorashell_rx_rpt;
+static int lorashell_rx_size;
static int lorashell_rx_verbose;
static int lorashell_txes_pending;
static uint8_t lorashell_tx_size;
@@ -117,6 +121,41 @@ static struct os_event lorashell_print_last_rx_ev = {
};
static struct os_callout lorashell_tx_timer;
+static const uint8_t lorashell_payload[UINT8_MAX] = {
+ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
+ 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
+ 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
+ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
+ 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
+ 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
+ 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
+ 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
+ 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
+ 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
+ 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
+ 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
+ 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
+ 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
+ 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
+ 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
+ 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
+ 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
+ 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
+ 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
+ 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
+ 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
+ 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
+ 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
+ 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
+ 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
+ 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
+ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
+ 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
+};
+
static void
lorashell_rx_rpt_begin(void)
{
@@ -126,24 +165,13 @@ lorashell_rx_rpt_begin(void)
static void
lorashell_tx_timer_exp(struct os_event *ev)
{
- static uint8_t start_byte;
-
- uint8_t buf[UINT8_MAX];
- uint8_t b;
- int i;
-
if (lorashell_txes_pending <= 0) {
Radio.Sleep();
return;
}
lorashell_txes_pending--;
- b = start_byte++;
- for (i = 0; i < lorashell_tx_size; i++) {
- buf[i] = b++;
- }
-
- Radio.Send(buf, lorashell_tx_size);
+ Radio.Send((void *)lorashell_payload, lorashell_tx_size);
}
static const char *
@@ -178,13 +206,15 @@ on_tx_done(void)
static void
on_rx_done(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr)
{
-
struct lorashell_rx_entry *entry;
- if (!lorashell_rx_rpt) {
- Radio.Sleep();
- } else {
- lorashell_rx_rpt_begin();
+ if (lorashell_rx_size != 0) {
+ if (size != lorashell_rx_size ||
+ memcmp(payload, lorashell_payload, size) != 0) {
+
+ /* Packet error. */
+ goto done;
+ }
}
entry = lorashell_rx_entries + lorashell_rx_entry_idx;
@@ -204,6 +234,12 @@ on_rx_done(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr)
if (lorashell_rx_entry_cnt < MYNEWT_VAL(LORASHELL_NUM_RX_ENTRIES)) {
lorashell_rx_entry_cnt++;
}
+
+done:
+ Radio.Sleep();
+ if (lorashell_rx_rpt) {
+ lorashell_rx_rpt_begin();
+ }
}
static void
@@ -268,17 +304,42 @@ lorashell_avg_rx_entry(struct lorashell_rx_entry *out_entry)
static int
lorashell_rx_rpt_cmd(int argc, char **argv)
{
- if (argc > 1 && strcmp(argv[1], "stop") == 0) {
- lorashell_rx_rpt = 0;
- Radio.Sleep();
- console_printf("lora rx stopped\n");
- return 0;
+ const char *err;
+ int rc;
+
+ if (argc > 1) {
+ if (strcmp(argv[1], "stop") == 0) {
+ lorashell_rx_rpt = 0;
+ Radio.Sleep();
+ console_printf("lora rx stopped\n");
+ return 0;
+ }
+
+ lorashell_rx_size = parse_ull_bounds(argv[1], 0, UINT8_MAX, &rc);
+ if (rc != 0) {
+ err = "invalid size";
+ goto err;
+ }
+ } else {
+ lorashell_rx_size = 0;
}
lorashell_rx_rpt = 1;
lorashell_rx_rpt_begin();
return 0;
+
+err:
+ if (err != NULL) {
+ console_printf("error: %s\n", err);
+ }
+
+ console_printf(
+"usage:\n"
+" lora_rx_rpt [size]\n"
+" lora_rx_rpt stop\n");
+
+ return rc;
}
static int
[12/40] incubator-mynewt-core git commit: MYNEWT-741 Port of
LoRaMac-node library
Posted by ja...@apache.org.
MYNEWT-741 Port of LoRaMac-node library
Implement suggested changed from code review:
1. Replace hardcoded 0 argument to hal_spi_enable(); use syscfg setting
instead.
2. Merge hw/drivers/lora/node/{radio,board} --> hw/drivers/lora
3. Default LoRa SPI index to -1; require BSP to override this setting
with an actual value.
Regarding 2: the purpose of the "node" subdirectory was to distinguish
this code from a potential gateway implementation. This subdirectory
remains in the net/lora directory (mirroring
net/nimble/{host,controller}), but it has been removed from the driver
directory tree. Presumably, end-device vs. gateway drivers use
different hardware, and will be distinguishable by their package name.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/560fa920
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/560fa920
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/560fa920
Branch: refs/heads/bluetooth5
Commit: 560fa9206904948bff567ab980c8a94ea064d65c
Parents: 9986f68
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Apr 27 11:46:05 2017 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Fri Apr 28 17:27:51 2017 -0700
----------------------------------------------------------------------
apps/lorashell/src/main.c | 2 +-
hw/bsp/telee02/pkg.yml | 3 +-
hw/bsp/telee02/syscfg.yml | 1 +
hw/drivers/lora/node/board/nrf52/LICENSE.txt | 25 -
.../lora/node/board/nrf52/include/board/board.h | 92 -
hw/drivers/lora/node/board/nrf52/pkg.yml | 34 -
.../lora/node/board/nrf52/src/lora_nrf52.c | 44 -
hw/drivers/lora/node/board/nrf52/syscfg.yml | 27 -
hw/drivers/lora/node/radio/sx1276/LICENSE.txt | 25 -
.../node/radio/sx1276/include/radio/radio.h | 33 -
hw/drivers/lora/node/radio/sx1276/pkg.yml | 35 -
.../lora/node/radio/sx1276/src/sx1276-board.c | 163 --
.../lora/node/radio/sx1276/src/sx1276-board.h | 119 --
hw/drivers/lora/node/radio/sx1276/src/sx1276.c | 1826 ------------------
hw/drivers/lora/node/radio/sx1276/src/sx1276.h | 364 ----
.../lora/node/radio/sx1276/src/sx1276Regs-Fsk.h | 1134 -----------
.../node/radio/sx1276/src/sx1276Regs-LoRa.h | 565 ------
hw/drivers/lora/sx1276/LICENSE.txt | 25 +
hw/drivers/lora/sx1276/include/radio/radio.h | 33 +
hw/drivers/lora/sx1276/pkg.yml | 32 +
hw/drivers/lora/sx1276/src/sx1276-board.c | 179 ++
hw/drivers/lora/sx1276/src/sx1276-board.h | 127 ++
hw/drivers/lora/sx1276/src/sx1276.c | 1824 +++++++++++++++++
hw/drivers/lora/sx1276/src/sx1276.h | 364 ++++
hw/drivers/lora/sx1276/src/sx1276Regs-Fsk.h | 1134 +++++++++++
hw/drivers/lora/sx1276/src/sx1276Regs-LoRa.h | 565 ++++++
hw/drivers/lora/sx1276/syscfg.yml | 27 +
net/lora/node/pkg.yml | 3 +-
net/lora/node/src/mac/LoRaMac.c | 5 +-
29 files changed, 4318 insertions(+), 4492 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/560fa920/apps/lorashell/src/main.c
----------------------------------------------------------------------
diff --git a/apps/lorashell/src/main.c b/apps/lorashell/src/main.c
index 7f12578..68c8635 100644
--- a/apps/lorashell/src/main.c
+++ b/apps/lorashell/src/main.c
@@ -53,6 +53,7 @@
* lora_tx_rpt 50 5 100
*/
+#include <stdio.h>
#include <string.h>
#include <limits.h>
#include "sysinit/sysinit.h"
@@ -61,7 +62,6 @@
#include "hal/hal_spi.h"
#include "bsp/bsp.h"
#include "os/os.h"
-#include "board/board.h"
#include "node/radio.h"
#include "console/console.h"
#include "shell/shell.h"
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/560fa920/hw/bsp/telee02/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/telee02/pkg.yml b/hw/bsp/telee02/pkg.yml
index 0324334..654fcf4 100644
--- a/hw/bsp/telee02/pkg.yml
+++ b/hw/bsp/telee02/pkg.yml
@@ -90,8 +90,7 @@ pkg.deps.BLE_DEVICE:
- hw/drivers/nimble/nrf52
pkg.deps.LORA_NODE:
- - hw/drivers/lora/node/radio/sx1276
- - hw/drivers/lora/node/board/nrf52
+ - hw/drivers/lora/sx1276
pkg.deps.UART_0:
- hw/drivers/uart/uart_hal
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/560fa920/hw/bsp/telee02/syscfg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/telee02/syscfg.yml b/hw/bsp/telee02/syscfg.yml
index a98b4a9..956d00c 100644
--- a/hw/bsp/telee02/syscfg.yml
+++ b/hw/bsp/telee02/syscfg.yml
@@ -96,3 +96,4 @@ syscfg.vals:
NFFS_FLASH_AREA: FLASH_AREA_NFFS
COREDUMP_FLASH_AREA: FLASH_AREA_IMAGE_1
MCU_DCDC_ENABLED: 1
+ SX1276_SPI_IDX: 0
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/560fa920/hw/drivers/lora/node/board/nrf52/LICENSE.txt
----------------------------------------------------------------------
diff --git a/hw/drivers/lora/node/board/nrf52/LICENSE.txt b/hw/drivers/lora/node/board/nrf52/LICENSE.txt
deleted file mode 100644
index 82695a7..0000000
--- a/hw/drivers/lora/node/board/nrf52/LICENSE.txt
+++ /dev/null
@@ -1,25 +0,0 @@
---- Revised BSD License ---
-Copyright (c) 2013, SEMTECH S.A.
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- * Neither the name of the Semtech corporation nor the
- names of its contributors may be used to endorse or promote products
- derived from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL SEMTECH S.A. BE LIABLE FOR ANY
-DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/560fa920/hw/drivers/lora/node/board/nrf52/include/board/board.h
----------------------------------------------------------------------
diff --git a/hw/drivers/lora/node/board/nrf52/include/board/board.h b/hw/drivers/lora/node/board/nrf52/include/board/board.h
deleted file mode 100644
index 7d60c5f..0000000
--- a/hw/drivers/lora/node/board/nrf52/include/board/board.h
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- / _____) _ | |
-( (____ _____ ____ _| |_ _____ ____| |__
- \____ \| ___ | (_ _) ___ |/ ___) _ \
- _____) ) ____| | | || |_| ____( (___| | | |
-(______/|_____)_|_|_| \__)_____)\____)_| |_|
- (C)2013 Semtech
-
-Description: Target board general functions implementation
-
-License: Revised BSD License, see LICENSE.TXT file include in the project
-
-Maintainer: Miguel Luis and Gregory Cristian
-*/
-#ifndef __BOARD_H__
-#define __BOARD_H__
-
-#include <stdbool.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdint.h>
-#include "bsp/bsp.h"
-#include "node/utilities.h"
-
-/*!
- * Board MCU pins definitions
- */
-
-#define RADIO_RESET SX1276_NRESET
-
-#define RADIO_SPI_IDX MYNEWT_VAL(LORA_NODE_BOARD_SPI_IDX)
-
-#if RADIO_SPI_IDX == 0
-#define RADIO_NSS MYNEWT_VAL(SPI_0_MASTER_SS_PIN)
-#else
-#error Invalid LORA_NODE_BOARD_SPI_IDX value
-#endif
-
-#define RADIO_DIO_0 SX1276_DIO0
-#define RADIO_DIO_1 SX1276_DIO1
-#define RADIO_DIO_2 SX1276_DIO2
-#define RADIO_DIO_3 SX1276_DIO3
-#define RADIO_DIO_4 SX1276_DIO4
-#define RADIO_DIO_5 SX1276_DIO5
-
-#define RADIO_ANT_SWITCH_HF SX1276_ANT_HF_CTRL
-
-#define RF_RXTX SX1276_RXTX
-
-/*!
- * Possible power sources
- */
-enum BoardPowerSources
-{
- USB_POWER = 0,
- BATTERY_POWER,
-};
-
-/*!
- * \brief Get the current battery level
- *
- * \retval value battery level [ 0: USB,
- * 1: Min level,
- * x: level
- * 254: fully charged,
- * 255: Error]
- */
-uint8_t BoardGetBatteryLevel( void );
-
-/*!
- * Returns a pseudo random seed generated using the MCU Unique ID
- *
- * \retval seed Generated pseudo random seed
- */
-uint32_t BoardGetRandomSeed( void );
-
-/*!
- * \brief Gets the board 64 bits unique ID
- *
- * \param [IN] id Pointer to an array that will contain the Unique ID
- */
-void BoardGetUniqueId( uint8_t *id );
-
-/*!
- * \brief Get the board power source
- *
- * \retval value power source [0: USB_POWER, 1: BATTERY_POWER]
- */
-uint8_t GetBoardPowerSource( void );
-
-#endif // __BOARD_H__
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/560fa920/hw/drivers/lora/node/board/nrf52/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/drivers/lora/node/board/nrf52/pkg.yml b/hw/drivers/lora/node/board/nrf52/pkg.yml
deleted file mode 100644
index d626845..0000000
--- a/hw/drivers/lora/node/board/nrf52/pkg.yml
+++ /dev/null
@@ -1,34 +0,0 @@
-#
-# 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.
-#
-
-pkg.name: hw/drivers/lora/node/board/nrf52
-pkg.description: LoRaMac-node board driver for nRF52 systems.
-pkg.author: "Telenor Digital AS"
-pkg.homepage: "http://mynewt.apache.org/"
-pkg.keywords:
- - lora
-pkg.deps:
- - "@apache-mynewt-core/kernel/os"
- - "@apache-mynewt-core/net/lora/node"
-
-pkg.apis:
- - lora_node_board
-
-pkg.init:
- lora_node_nrf52_init: 100
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/560fa920/hw/drivers/lora/node/board/nrf52/src/lora_nrf52.c
----------------------------------------------------------------------
diff --git a/hw/drivers/lora/node/board/nrf52/src/lora_nrf52.c b/hw/drivers/lora/node/board/nrf52/src/lora_nrf52.c
deleted file mode 100644
index 828f5bb..0000000
--- a/hw/drivers/lora/node/board/nrf52/src/lora_nrf52.c
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * 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.
- */
-
-#include "sysinit/sysinit.h"
-#include "syscfg/syscfg.h"
-#include "hal/hal_gpio.h"
-#include "hal/hal_spi.h"
-#include "board/board.h"
-
-void
-lora_node_nrf52_init(void)
-{
- struct hal_spi_settings spi_settings;
- int rc;
-
- hal_gpio_init_out(RADIO_NSS, 1);
-
- spi_settings.data_order = HAL_SPI_MSB_FIRST;
- spi_settings.data_mode = HAL_SPI_MODE0;
- spi_settings.baudrate = MYNEWT_VAL(LORA_NODE_BOARD_SPI_BAUDRATE);
- spi_settings.word_size = HAL_SPI_WORD_SIZE_8BIT;
-
- rc = hal_spi_config(RADIO_SPI_IDX, &spi_settings);
- SYSINIT_PANIC_ASSERT_MSG(rc == 0, "Failed to configure LoRa SPI");
-
- rc = hal_spi_enable(0);
- SYSINIT_PANIC_ASSERT_MSG(rc == 0, "Failed to enable LoRa SPI");
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/560fa920/hw/drivers/lora/node/board/nrf52/syscfg.yml
----------------------------------------------------------------------
diff --git a/hw/drivers/lora/node/board/nrf52/syscfg.yml b/hw/drivers/lora/node/board/nrf52/syscfg.yml
deleted file mode 100644
index 0babd74..0000000
--- a/hw/drivers/lora/node/board/nrf52/syscfg.yml
+++ /dev/null
@@ -1,27 +0,0 @@
-#
-# 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_BOARD_SPI_IDX:
- description:
- value: 0
-
- LORA_NODE_BOARD_SPI_BAUDRATE:
- description:
- value: 500
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/560fa920/hw/drivers/lora/node/radio/sx1276/LICENSE.txt
----------------------------------------------------------------------
diff --git a/hw/drivers/lora/node/radio/sx1276/LICENSE.txt b/hw/drivers/lora/node/radio/sx1276/LICENSE.txt
deleted file mode 100644
index 82695a7..0000000
--- a/hw/drivers/lora/node/radio/sx1276/LICENSE.txt
+++ /dev/null
@@ -1,25 +0,0 @@
---- Revised BSD License ---
-Copyright (c) 2013, SEMTECH S.A.
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- * Neither the name of the Semtech corporation nor the
- names of its contributors may be used to endorse or promote products
- derived from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL SEMTECH S.A. BE LIABLE FOR ANY
-DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/560fa920/hw/drivers/lora/node/radio/sx1276/include/radio/radio.h
----------------------------------------------------------------------
diff --git a/hw/drivers/lora/node/radio/sx1276/include/radio/radio.h b/hw/drivers/lora/node/radio/sx1276/include/radio/radio.h
deleted file mode 100644
index 6f23183..0000000
--- a/hw/drivers/lora/node/radio/sx1276/include/radio/radio.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- / _____) _ | |
-( (____ _____ ____ _| |_ _____ ____| |__
- \____ \| ___ | (_ _) ___ |/ ___) _ \
- _____) ) ____| | | || |_| ____( (___| | | |
-(______/|_____)_|_|_| \__)_____)\____)_| |_|
- (C)2013 Semtech
-
-Description: Generic SX1276 driver implementation
-
-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_
-
-/*!
- * 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 )
-
-#endif /* H_RADIO_RADIO */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/560fa920/hw/drivers/lora/node/radio/sx1276/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/drivers/lora/node/radio/sx1276/pkg.yml b/hw/drivers/lora/node/radio/sx1276/pkg.yml
deleted file mode 100644
index 5b98cef..0000000
--- a/hw/drivers/lora/node/radio/sx1276/pkg.yml
+++ /dev/null
@@ -1,35 +0,0 @@
-#
-# 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.
-#
-
-pkg.name: hw/drivers/lora/node/radio/sx1276
-pkg.description: LoRaMac-node radio driver for the SX1276 modem.
-pkg.author: "Semtech"
-pkg.homepage: "http://mynewt.apache.org/"
-pkg.keywords:
- - lora
-
-pkg.deps:
- - "@apache-mynewt-core/kernel/os"
- - "@apache-mynewt-core/net/lora/node"
-
-pkg.apis:
- - lora_node_radio
-
-pkg.req_apis:
- - lora_node_board
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/560fa920/hw/drivers/lora/node/radio/sx1276/src/sx1276-board.c
----------------------------------------------------------------------
diff --git a/hw/drivers/lora/node/radio/sx1276/src/sx1276-board.c b/hw/drivers/lora/node/radio/sx1276/src/sx1276-board.c
deleted file mode 100644
index 7bebcc5..0000000
--- a/hw/drivers/lora/node/radio/sx1276/src/sx1276-board.c
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- / _____) _ | |
-( (____ _____ ____ _| |_ _____ ____| |__
- \____ \| ___ | (_ _) ___ |/ ___) _ \
- _____) ) ____| | | || |_| ____( (___| | | |
-(______/|_____)_|_|_| \__)_____)\____)_| |_|
- (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
-*/
-#include <assert.h>
-#include "board/board.h"
-#include "node/radio.h"
-#include "sx1276.h"
-#include "sx1276-board.h"
-
-/*!
- * Flag used to set the RF switch control pins in low power mode when the radio is not active.
- */
-static bool RadioIsActive = false;
-
-/*!
- * Radio driver structure initialization
- */
-const struct Radio_s Radio =
-{
- .Init = SX1276Init,
- .GetStatus = SX1276GetStatus,
- .SetModem = SX1276SetModem,
- .SetChannel = SX1276SetChannel,
- .IsChannelFree = SX1276IsChannelFree,
- .Random = SX1276Random,
- .SetRxConfig = SX1276SetRxConfig,
- .SetTxConfig = SX1276SetTxConfig,
- .CheckRfFrequency = SX1276CheckRfFrequency,
- .TimeOnAir = SX1276GetTimeOnAir,
- .Send = SX1276Send,
- .Sleep = SX1276SetSleep,
- .Standby = SX1276SetStby,
- .Rx = SX1276SetRx,
- .StartCad = SX1276StartCad,
- .Rssi = SX1276ReadRssi,
- .Write = SX1276Write,
- .Read = SX1276Read,
- .WriteBuffer = SX1276WriteBuffer,
- .ReadBuffer = SX1276ReadBuffer,
- .SetMaxPayloadLength = SX1276SetMaxPayloadLength
-};
-
-void SX1276IoInit( void )
-{
- int rc;
-
- rc = hal_gpio_init_out(RF_RXTX, 1);
- assert(rc == 0);
-}
-
-void SX1276IoIrqInit( DioIrqHandler **irqHandlers )
-{
- int rc;
-
- rc = hal_gpio_irq_init(RADIO_DIO_0, irqHandlers[0], NULL,
- HAL_GPIO_TRIG_RISING, HAL_GPIO_PULL_NONE);
- assert(rc == 0);
- hal_gpio_irq_enable(RADIO_DIO_0);
-
- rc = hal_gpio_irq_init(RADIO_DIO_1, irqHandlers[1], NULL,
- HAL_GPIO_TRIG_RISING, HAL_GPIO_PULL_NONE);
- assert(rc == 0);
- hal_gpio_irq_enable(RADIO_DIO_1);
-
- rc = hal_gpio_irq_init(RADIO_DIO_2, irqHandlers[2], NULL,
- HAL_GPIO_TRIG_RISING, HAL_GPIO_PULL_NONE);
- assert(rc == 0);
- hal_gpio_irq_enable(RADIO_DIO_2);
-
- rc = hal_gpio_irq_init(RADIO_DIO_3, irqHandlers[3], NULL,
- HAL_GPIO_TRIG_RISING, HAL_GPIO_PULL_NONE);
- assert(rc == 0);
- hal_gpio_irq_enable(RADIO_DIO_3);
-
- rc = hal_gpio_irq_init(RADIO_DIO_4, irqHandlers[4], NULL,
- HAL_GPIO_TRIG_RISING, HAL_GPIO_PULL_NONE);
- assert(rc == 0);
- hal_gpio_irq_enable(RADIO_DIO_4);
-
- rc = hal_gpio_irq_init(RADIO_DIO_5, irqHandlers[5], NULL,
- HAL_GPIO_TRIG_RISING, HAL_GPIO_PULL_NONE);
- assert(rc == 0);
- hal_gpio_irq_enable(RADIO_DIO_5);
-}
-
-void SX1276IoDeInit( void )
-{
- hal_gpio_irq_release(RADIO_DIO_0);
- hal_gpio_irq_release(RADIO_DIO_1);
- hal_gpio_irq_release(RADIO_DIO_2);
- hal_gpio_irq_release(RADIO_DIO_3);
- hal_gpio_irq_release(RADIO_DIO_4);
- hal_gpio_irq_release(RADIO_DIO_5);
-}
-
-uint8_t SX1276GetPaSelect( uint32_t channel )
-{
- if( channel < RF_MID_BAND_THRESH )
- {
- return RF_PACONFIG_PASELECT_PABOOST;
- }
- else
- {
- return RF_PACONFIG_PASELECT_RFO;
- }
-}
-
-void SX1276SetAntSwLowPower( bool status )
-{
- if( RadioIsActive != status )
- {
- RadioIsActive = status;
-
- if( status == false )
- {
- SX1276AntSwInit( );
- }
- else
- {
- SX1276AntSwDeInit( );
- }
- }
-}
-
-void SX1276AntSwInit( void )
-{
- // Consider turning off GPIO pins for low power. They are always on right
- // now. GPIOTE library uses 0.5uA max when on, typical 0.1uA.
-}
-
-void SX1276AntSwDeInit( void )
-{
- // Consider this for low power - ie turning off GPIO pins
-}
-
-void SX1276SetAntSw( uint8_t rxTx )
-{
- if( rxTx != 0 ) // 1: TX, 0: RX
- {
- hal_gpio_write(SX1276_RXTX, 1);
- }
- else
- {
- hal_gpio_write(SX1276_RXTX, 0);
- }
-}
-
-bool SX1276CheckRfFrequency( uint32_t frequency )
-{
- // Implement check. Currently all frequencies are supported
- return true;
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/560fa920/hw/drivers/lora/node/radio/sx1276/src/sx1276-board.h
----------------------------------------------------------------------
diff --git a/hw/drivers/lora/node/radio/sx1276/src/sx1276-board.h b/hw/drivers/lora/node/radio/sx1276/src/sx1276-board.h
deleted file mode 100644
index 5156e8a..0000000
--- a/hw/drivers/lora/node/radio/sx1276/src/sx1276-board.h
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- / _____) _ | |
-( (____ _____ ____ _| |_ _____ ____| |__
- \____ \| ___ | (_ _) ___ |/ ___) _ \
- _____) ) ____| | | || |_| ____( (___| | | |
-(______/|_____)_|_|_| \__)_____)\____)_| |_|
- (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"
-
-/*!
- * \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 );
-
-/*!
- * \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 );
-
-/*!
- * \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 hal_pin_rxtx (int val);
-
-/*!
- * Radio hardware and global parameters
- */
-extern SX1276_t SX1276;
-
-#endif // __SX1276_ARCH_H__
[36/40] incubator-mynewt-core git commit: This closes pull request
#253
Posted by ja...@apache.org.
This closes pull request #253
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/5ae5f3df
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/5ae5f3df
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/5ae5f3df
Branch: refs/heads/bluetooth5
Commit: 5ae5f3df58139e2984a3b235ea7f5e1cb41a69e4
Parents: b022ac7 54a8c92
Author: julian <ju...@imgtec.com>
Authored: Fri May 5 10:23:36 2017 +0100
Committer: julian <ju...@imgtec.com>
Committed: Fri May 5 10:23:36 2017 +0100
----------------------------------------------------------------------
compiler/xc32/compiler.yml | 4 +-
compiler/xc32/pkg.yml | 3 +
hw/bsp/pic32mx470_6lp_clicker/pkg.yml | 4 +-
hw/bsp/pic32mx470_6lp_clicker/src/hal_bsp.c | 2 +-
hw/bsp/pic32mz2048_wi-fire/pkg.yml | 2 +
hw/bsp/pic32mz2048_wi-fire/src/hal_bsp.c | 2 +-
hw/bsp/pic32mz2048_wi-fire/src/os_bsp.c | 2 +-
.../src/arch/cortex_m4/startup_STM32F429x.s | 3 -
hw/mcu/microchip/pic32mx470f512h/pkg.yml | 2 -
hw/mcu/microchip/pic32mz2048efg100/pkg.yml | 2 -
.../microchip/pic32mz2048efg100/src/hal_uart.c | 2 +-
.../arch/pic32/startup/cache-err-exception.S | 129 ++++
kernel/os/src/arch/pic32/startup/crt0.S | 623 +++++++++++++++++++
.../src/arch/pic32/startup/general-exception.S | 141 +++++
.../pic32/startup/simple-tlb-refill-exception.S | 135 ++++
.../stubs/default-bootstrap-exception-handler.c | 58 ++
.../stubs/default-cache-err-exception-handler.c | 56 ++
.../stubs/default-general-exception-handler.c | 54 ++
.../src/arch/pic32/stubs/default-nmi-handler.S | 63 ++
.../src/arch/pic32/stubs/default-on-bootstrap.c | 43 ++
.../os/src/arch/pic32/stubs/default-on-reset.c | 43 ++
...efault-simple-tlb-refill-exception-handler.c | 56 ++
.../os/src/arch/pic32/stubs/pic32_init_cache.S | 299 +++++++++
.../arch/pic32/stubs/pic32_init_tlb_ebi_sqi.S | 145 +++++
sys/console/full/src/console.c | 6 +-
sys/console/minimal/src/console.c | 6 +-
26 files changed, 1869 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
[18/40] incubator-mynewt-core git commit: MYNEWT-741 Port of
LoRaMac-node library
Posted by ja...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9986f68c/hw/drivers/lora/node/radio/sx1276/src/sx1276.c
----------------------------------------------------------------------
diff --git a/hw/drivers/lora/node/radio/sx1276/src/sx1276.c b/hw/drivers/lora/node/radio/sx1276/src/sx1276.c
new file mode 100644
index 0000000..60007e5
--- /dev/null
+++ b/hw/drivers/lora/node/radio/sx1276/src/sx1276.c
@@ -0,0 +1,1826 @@
+/*
+ / _____) _ | |
+( (____ _____ ____ _| |_ _____ ____| |__
+ \____ \| ___ | (_ _) ___ |/ ___) _ \
+ _____) ) ____| | | || |_| ____( (___| | | |
+(______/|_____)_|_|_| \__)_____)\____)_| |_|
+ (C)2013 Semtech
+
+Description: Generic SX1276 driver implementation
+
+License: Revised BSD License, see LICENSE.TXT file include in the project
+
+Maintainer: Miguel Luis, Gregory Cristian and Wael Guibene
+*/
+#include <assert.h>
+#include <math.h>
+#include <string.h>
+#include "syscfg/syscfg.h"
+#include "hal/hal_gpio.h"
+#include "hal/hal_spi.h"
+#include "os/os.h"
+#include "node/lora.h"
+#include "node/radio.h"
+#include "board/board.h"
+#include "sx1276.h"
+#include "sx1276-board.h"
+
+/*
+ * Local types definition
+ */
+
+/*!
+ * Radio registers definition
+ */
+typedef struct
+{
+ RadioModems_t Modem;
+ uint8_t Addr;
+ uint8_t Value;
+}RadioRegisters_t;
+
+/*!
+ * FSK bandwidth definition
+ */
+typedef struct
+{
+ uint32_t bandwidth;
+ uint8_t RegValue;
+}FskBandwidth_t;
+
+
+/*
+ * Private functions prototypes
+ */
+
+/*!
+ * Performs the Rx chain calibration for LF and HF bands
+ * \remark Must be called just after the reset so all registers are at their
+ * default values
+ */
+static void RxChainCalibration( void );
+
+/*!
+ * \brief Resets the SX1276
+ */
+void SX1276Reset( void );
+
+/*!
+ * \brief Sets the SX1276 in transmission mode for the given time
+ * \param [IN] timeout Transmission timeout [ms] [0: continuous, others timeout]
+ */
+void SX1276SetTx( uint32_t timeout );
+
+/*!
+ * \brief Writes the buffer contents to the SX1276 FIFO
+ *
+ * \param [IN] buffer Buffer containing data to be put on the FIFO.
+ * \param [IN] size Number of bytes to be written to the FIFO
+ */
+void SX1276WriteFifo( uint8_t *buffer, uint8_t size );
+
+/*!
+ * \brief Reads the contents of the SX1276 FIFO
+ *
+ * \param [OUT] buffer Buffer where to copy the FIFO read data.
+ * \param [IN] size Number of bytes to be read from the FIFO
+ */
+void SX1276ReadFifo( uint8_t *buffer, uint8_t size );
+
+/*!
+ * \brief Sets the SX1276 operating mode
+ *
+ * \param [IN] opMode New operating mode
+ */
+void SX1276SetOpMode( uint8_t opMode );
+
+/*
+ * SX1276 DIO IRQ callback functions prototype
+ */
+
+/*!
+ * \brief DIO 0 IRQ callback
+ */
+void SX1276OnDio0Irq(void *unused);
+
+/*!
+ * \brief DIO 1 IRQ callback
+ */
+void SX1276OnDio1Irq(void *unused);
+
+/*!
+ * \brief DIO 2 IRQ callback
+ */
+void SX1276OnDio2Irq(void *unused);
+
+/*!
+ * \brief DIO 3 IRQ callback
+ */
+void SX1276OnDio3Irq(void *unused);
+
+/*!
+ * \brief DIO 4 IRQ callback
+ */
+void SX1276OnDio4Irq(void *unused);
+
+/*!
+ * \brief DIO 5 IRQ callback
+ */
+void SX1276OnDio5Irq(void *unused);
+
+/*!
+ * \brief Tx & Rx timeout timer callback
+ */
+void SX1276OnTimeoutIrq(void *unused);
+
+/*
+ * Private global constants
+ */
+
+/*!
+ * Radio hardware registers initialization
+ *
+ * \remark RADIO_INIT_REGISTERS_VALUE is defined in sx1276-board.h file
+ */
+const RadioRegisters_t RadioRegsInit[] = RADIO_INIT_REGISTERS_VALUE;
+
+/*!
+ * Constant values need to compute the RSSI value
+ */
+#define RSSI_OFFSET_LF -164
+#define RSSI_OFFSET_HF -157
+
+/*!
+ * Precomputed FSK bandwidth registers values
+ */
+const FskBandwidth_t FskBandwidths[] =
+{
+ { 2600 , 0x17 },
+ { 3100 , 0x0F },
+ { 3900 , 0x07 },
+ { 5200 , 0x16 },
+ { 6300 , 0x0E },
+ { 7800 , 0x06 },
+ { 10400 , 0x15 },
+ { 12500 , 0x0D },
+ { 15600 , 0x05 },
+ { 20800 , 0x14 },
+ { 25000 , 0x0C },
+ { 31300 , 0x04 },
+ { 41700 , 0x13 },
+ { 50000 , 0x0B },
+ { 62500 , 0x03 },
+ { 83333 , 0x12 },
+ { 100000, 0x0A },
+ { 125000, 0x02 },
+ { 166700, 0x11 },
+ { 200000, 0x09 },
+ { 250000, 0x01 },
+ { 300000, 0x00 }, // Invalid Bandwidth
+};
+
+/*
+ * Private global variables
+ */
+
+/*!
+ * Radio callbacks variable
+ */
+static RadioEvents_t *RadioEvents;
+
+/*!
+ * Reception buffer
+ */
+static uint8_t RxTxBuffer[RX_BUFFER_SIZE];
+
+/*
+ * Public global variables
+ */
+
+/*!
+ * Radio hardware and global parameters
+ */
+SX1276_t SX1276;
+
+/*!
+ * Hardware DIO IRQ callback initialization
+ */
+DioIrqHandler *DioIrq[] = { SX1276OnDio0Irq, SX1276OnDio1Irq,
+ SX1276OnDio2Irq, SX1276OnDio3Irq,
+ SX1276OnDio4Irq, NULL };
+
+/*!
+ * Tx and Rx timers
+ */
+struct hal_timer TxTimeoutTimer;
+struct hal_timer RxTimeoutTimer;
+struct hal_timer RxTimeoutSyncWord;
+
+static uint32_t rx_timeout_sync_delay = -1;
+
+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 );
+ }
+}
+
+static void
+SX1276RxError( void )
+{
+ STATS_INC(lora_stats, rx_error);
+
+ if( ( RadioEvents != NULL ) && ( RadioEvents->RxError != NULL ) )
+ {
+ RadioEvents->RxError( );
+ }
+}
+
+static void
+SX1276RxTimeout( void )
+{
+ STATS_INC(lora_stats, rx_timeout);
+
+ if( ( RadioEvents != NULL ) && ( RadioEvents->RxTimeout != NULL ) )
+ {
+ RadioEvents->RxTimeout( );
+ }
+}
+
+static void
+SX1276TxDone( void )
+{
+ STATS_INC(lora_stats, tx_success);
+
+ if( ( RadioEvents != NULL ) && ( RadioEvents->TxDone != NULL ) )
+ {
+ RadioEvents->TxDone( );
+ }
+}
+
+static void
+SX1276TxTimeout( void )
+{
+ STATS_INC(lora_stats, tx_timeout);
+
+ if( ( RadioEvents != NULL ) && ( RadioEvents->TxTimeout != NULL ) )
+ {
+ RadioEvents->TxTimeout( );
+ }
+}
+
+/*
+ * Radio driver functions implementation
+ */
+
+void SX1276Init( RadioEvents_t *events )
+{
+ uint8_t i;
+
+ RadioEvents = events;
+
+ // Initialize driver timeout timers
+ os_cputime_timer_init(&TxTimeoutTimer, SX1276OnTimeoutIrq, NULL);
+ os_cputime_timer_init(&RxTimeoutTimer, SX1276OnTimeoutIrq, NULL);
+ os_cputime_timer_init(&RxTimeoutSyncWord, SX1276OnTimeoutIrq, NULL);
+
+ SX1276Reset( );
+
+ RxChainCalibration( );
+
+ SX1276SetOpMode( RF_OPMODE_SLEEP );
+
+ SX1276IoIrqInit( DioIrq );
+
+ for( i = 0; i < sizeof( RadioRegsInit ) / sizeof( RadioRegisters_t ); i++ )
+ {
+ SX1276SetModem( RadioRegsInit[i].Modem );
+ SX1276Write( RadioRegsInit[i].Addr, RadioRegsInit[i].Value );
+ }
+
+ SX1276SetModem( MODEM_FSK );
+
+ SX1276.Settings.State = RF_IDLE;
+}
+
+RadioState_t SX1276GetStatus( void )
+{
+ return SX1276.Settings.State;
+}
+
+void SX1276SetChannel( uint32_t freq )
+{
+ SX1276.Settings.Channel = freq;
+ freq = ( uint32_t )( ( double )freq / ( double )FREQ_STEP );
+ SX1276Write( REG_FRFMSB, ( uint8_t )( ( freq >> 16 ) & 0xFF ) );
+ SX1276Write( REG_FRFMID, ( uint8_t )( ( freq >> 8 ) & 0xFF ) );
+ SX1276Write( REG_FRFLSB, ( uint8_t )( freq & 0xFF ) );
+}
+
+bool SX1276IsChannelFree( RadioModems_t modem, uint32_t freq, int16_t rssiThresh )
+{
+ int16_t rssi = 0;
+
+ SX1276SetModem( modem );
+
+ SX1276SetChannel( freq );
+
+ SX1276SetOpMode( RF_OPMODE_RECEIVER );
+
+ os_cputime_delay_usecs(1000);
+
+ rssi = SX1276ReadRssi( modem );
+
+ SX1276SetSleep( );
+
+ if( rssi > rssiThresh )
+ {
+ return false;
+ }
+ return true;
+}
+
+uint32_t SX1276Random( void )
+{
+ uint8_t i;
+ uint32_t rnd = 0;
+
+ /*
+ * Radio setup for random number generation
+ */
+ // Set LoRa modem ON
+ SX1276SetModem( MODEM_LORA );
+
+ // Disable LoRa modem interrupts
+ SX1276Write( REG_LR_IRQFLAGSMASK, RFLR_IRQFLAGS_RXTIMEOUT |
+ RFLR_IRQFLAGS_RXDONE |
+ RFLR_IRQFLAGS_PAYLOADCRCERROR |
+ RFLR_IRQFLAGS_VALIDHEADER |
+ RFLR_IRQFLAGS_TXDONE |
+ RFLR_IRQFLAGS_CADDONE |
+ RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL |
+ RFLR_IRQFLAGS_CADDETECTED );
+
+ // Set radio in continuous reception
+ SX1276SetOpMode( RF_OPMODE_RECEIVER );
+
+ for( i = 0; i < 32; i++ )
+ {
+ os_cputime_delay_usecs(1000);
+ // Unfiltered RSSI value reading. Only takes the LSB value
+ rnd |= ( ( uint32_t )SX1276Read( REG_LR_RSSIWIDEBAND ) & 0x01 ) << i;
+ }
+
+ SX1276SetSleep( );
+
+ return rnd;
+}
+
+/*!
+ * Performs the Rx chain calibration for LF and HF bands
+ * \remark Must be called just after the reset so all registers are at their
+ * default values
+ */
+static void RxChainCalibration( void )
+{
+ uint8_t regPaConfigInitVal;
+ uint32_t initialFreq;
+
+ // Save context
+ regPaConfigInitVal = SX1276Read( REG_PACONFIG );
+ initialFreq = ( double )( ( ( uint32_t )SX1276Read( REG_FRFMSB ) << 16 ) |
+ ( ( uint32_t )SX1276Read( REG_FRFMID ) << 8 ) |
+ ( ( uint32_t )SX1276Read( REG_FRFLSB ) ) ) * ( double )FREQ_STEP;
+
+ // Cut the PA just in case, RFO output, power = -1 dBm
+ SX1276Write( REG_PACONFIG, 0x00 );
+
+ // Launch Rx chain calibration for LF band
+ SX1276Write( REG_IMAGECAL, ( SX1276Read( REG_IMAGECAL ) & RF_IMAGECAL_IMAGECAL_MASK ) | RF_IMAGECAL_IMAGECAL_START );
+ while( ( SX1276Read( REG_IMAGECAL ) & RF_IMAGECAL_IMAGECAL_RUNNING ) == RF_IMAGECAL_IMAGECAL_RUNNING )
+ {
+ }
+
+ // Sets a Frequency in HF band
+ SX1276SetChannel( 868000000 );
+
+ // Launch Rx chain calibration for HF band
+ SX1276Write( REG_IMAGECAL, ( SX1276Read( REG_IMAGECAL ) & RF_IMAGECAL_IMAGECAL_MASK ) | RF_IMAGECAL_IMAGECAL_START );
+ while( ( SX1276Read( REG_IMAGECAL ) & RF_IMAGECAL_IMAGECAL_RUNNING ) == RF_IMAGECAL_IMAGECAL_RUNNING )
+ {
+ }
+
+ // Restore context
+ SX1276Write( REG_PACONFIG, regPaConfigInitVal );
+ SX1276SetChannel( initialFreq );
+}
+
+/*!
+ * Returns the known FSK bandwidth registers value
+ *
+ * \param [IN] bandwidth Bandwidth value in Hz
+ * \retval regValue Bandwidth register value.
+ */
+static uint8_t GetFskBandwidthRegValue( uint32_t bandwidth )
+{
+ uint8_t i;
+
+ for( i = 0; i < ( sizeof( FskBandwidths ) / sizeof( FskBandwidth_t ) ) - 1; i++ )
+ {
+ if( ( bandwidth >= FskBandwidths[i].bandwidth ) && ( bandwidth < FskBandwidths[i + 1].bandwidth ) )
+ {
+ return FskBandwidths[i].RegValue;
+ }
+ }
+ // ERROR: Value not found
+ while( 1 );
+}
+
+void SX1276SetRxConfig( 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 )
+{
+ SX1276SetModem( modem );
+
+ switch( modem )
+ {
+ case MODEM_FSK:
+ {
+ SX1276.Settings.Fsk.Bandwidth = bandwidth;
+ SX1276.Settings.Fsk.Datarate = datarate;
+ SX1276.Settings.Fsk.BandwidthAfc = bandwidthAfc;
+ SX1276.Settings.Fsk.FixLen = fixLen;
+ SX1276.Settings.Fsk.PayloadLen = payloadLen;
+ SX1276.Settings.Fsk.CrcOn = crcOn;
+ SX1276.Settings.Fsk.IqInverted = iqInverted;
+ SX1276.Settings.Fsk.RxContinuous = rxContinuous;
+ SX1276.Settings.Fsk.PreambleLen = preambleLen;
+
+ datarate = ( uint16_t )( ( double )XTAL_FREQ / ( double )datarate );
+ SX1276Write( REG_BITRATEMSB, ( uint8_t )( datarate >> 8 ) );
+ SX1276Write( REG_BITRATELSB, ( uint8_t )( datarate & 0xFF ) );
+
+ SX1276Write( REG_RXBW, GetFskBandwidthRegValue( bandwidth ) );
+ SX1276Write( REG_AFCBW, GetFskBandwidthRegValue( bandwidthAfc ) );
+
+ SX1276Write( REG_PREAMBLEMSB, ( uint8_t )( ( preambleLen >> 8 ) & 0xFF ) );
+ SX1276Write( REG_PREAMBLELSB, ( uint8_t )( preambleLen & 0xFF ) );
+
+ if( fixLen == 1 )
+ {
+ SX1276Write( REG_PAYLOADLENGTH, payloadLen );
+ }
+ else
+ {
+ SX1276Write( REG_PAYLOADLENGTH, 0xFF ); // Set payload length to the maximum
+ }
+
+ SX1276Write( REG_PACKETCONFIG1,
+ ( SX1276Read( REG_PACKETCONFIG1 ) &
+ RF_PACKETCONFIG1_CRC_MASK &
+ RF_PACKETCONFIG1_PACKETFORMAT_MASK ) |
+ ( ( fixLen == 1 ) ? RF_PACKETCONFIG1_PACKETFORMAT_FIXED : RF_PACKETCONFIG1_PACKETFORMAT_VARIABLE ) |
+ ( crcOn << 4 ) );
+ }
+ break;
+ case MODEM_LORA:
+ {
+ if( bandwidth > 2 )
+ {
+ // Fatal error: When using LoRa modem only bandwidths 125, 250 and 500 kHz are supported
+ while( 1 );
+ }
+ bandwidth += 7;
+ SX1276.Settings.LoRa.Bandwidth = bandwidth;
+ SX1276.Settings.LoRa.Datarate = datarate;
+ SX1276.Settings.LoRa.Coderate = coderate;
+ SX1276.Settings.LoRa.PreambleLen = preambleLen;
+ SX1276.Settings.LoRa.FixLen = fixLen;
+ SX1276.Settings.LoRa.PayloadLen = payloadLen;
+ SX1276.Settings.LoRa.CrcOn = crcOn;
+ SX1276.Settings.LoRa.FreqHopOn = freqHopOn;
+ SX1276.Settings.LoRa.HopPeriod = hopPeriod;
+ SX1276.Settings.LoRa.IqInverted = iqInverted;
+ SX1276.Settings.LoRa.RxContinuous = rxContinuous;
+
+ if( datarate > 12 )
+ {
+ datarate = 12;
+ }
+ else if( datarate < 6 )
+ {
+ datarate = 6;
+ }
+
+ if( ( ( bandwidth == 7 ) && ( ( datarate == 11 ) || ( datarate == 12 ) ) ) ||
+ ( ( bandwidth == 8 ) && ( datarate == 12 ) ) )
+ {
+ SX1276.Settings.LoRa.LowDatarateOptimize = 0x01;
+ }
+ else
+ {
+ SX1276.Settings.LoRa.LowDatarateOptimize = 0x00;
+ }
+
+ SX1276Write( REG_LR_MODEMCONFIG1,
+ ( SX1276Read( REG_LR_MODEMCONFIG1 ) &
+ RFLR_MODEMCONFIG1_BW_MASK &
+ RFLR_MODEMCONFIG1_CODINGRATE_MASK &
+ RFLR_MODEMCONFIG1_IMPLICITHEADER_MASK ) |
+ ( bandwidth << 4 ) | ( coderate << 1 ) |
+ fixLen );
+
+ SX1276Write( REG_LR_MODEMCONFIG2,
+ ( SX1276Read( REG_LR_MODEMCONFIG2 ) &
+ RFLR_MODEMCONFIG2_SF_MASK &
+ RFLR_MODEMCONFIG2_RXPAYLOADCRC_MASK &
+ RFLR_MODEMCONFIG2_SYMBTIMEOUTMSB_MASK ) |
+ ( datarate << 4 ) | ( crcOn << 2 ) |
+ ( ( symbTimeout >> 8 ) & ~RFLR_MODEMCONFIG2_SYMBTIMEOUTMSB_MASK ) );
+
+ SX1276Write( REG_LR_MODEMCONFIG3,
+ ( SX1276Read( REG_LR_MODEMCONFIG3 ) &
+ RFLR_MODEMCONFIG3_LOWDATARATEOPTIMIZE_MASK ) |
+ ( SX1276.Settings.LoRa.LowDatarateOptimize << 3 ) );
+
+ SX1276Write( REG_LR_SYMBTIMEOUTLSB, ( uint8_t )( symbTimeout & 0xFF ) );
+
+ SX1276Write( REG_LR_PREAMBLEMSB, ( uint8_t )( ( preambleLen >> 8 ) & 0xFF ) );
+ SX1276Write( REG_LR_PREAMBLELSB, ( uint8_t )( preambleLen & 0xFF ) );
+
+ if( fixLen == 1 )
+ {
+ SX1276Write( REG_LR_PAYLOADLENGTH, payloadLen );
+ }
+
+ if( SX1276.Settings.LoRa.FreqHopOn == true )
+ {
+ SX1276Write( REG_LR_PLLHOP, ( SX1276Read( REG_LR_PLLHOP ) & RFLR_PLLHOP_FASTHOP_MASK ) | RFLR_PLLHOP_FASTHOP_ON );
+ SX1276Write( REG_LR_HOPPERIOD, SX1276.Settings.LoRa.HopPeriod );
+ }
+
+ if( ( bandwidth == 9 ) && ( SX1276.Settings.Channel > RF_MID_BAND_THRESH ) )
+ {
+ // ERRATA 2.1 - Sensitivity Optimization with a 500 kHz Bandwidth
+ SX1276Write( REG_LR_TEST36, 0x02 );
+ SX1276Write( REG_LR_TEST3A, 0x64 );
+ }
+ else if( bandwidth == 9 )
+ {
+ // ERRATA 2.1 - Sensitivity Optimization with a 500 kHz Bandwidth
+ SX1276Write( REG_LR_TEST36, 0x02 );
+ SX1276Write( REG_LR_TEST3A, 0x7F );
+ }
+ else
+ {
+ // ERRATA 2.1 - Sensitivity Optimization with a 500 kHz Bandwidth
+ SX1276Write( REG_LR_TEST36, 0x03 );
+ }
+
+ if( datarate == 6 )
+ {
+ SX1276Write( REG_LR_DETECTOPTIMIZE,
+ ( SX1276Read( REG_LR_DETECTOPTIMIZE ) &
+ RFLR_DETECTIONOPTIMIZE_MASK ) |
+ RFLR_DETECTIONOPTIMIZE_SF6 );
+ SX1276Write( REG_LR_DETECTIONTHRESHOLD,
+ RFLR_DETECTIONTHRESH_SF6 );
+ }
+ else
+ {
+ SX1276Write( REG_LR_DETECTOPTIMIZE,
+ ( SX1276Read( REG_LR_DETECTOPTIMIZE ) &
+ RFLR_DETECTIONOPTIMIZE_MASK ) |
+ RFLR_DETECTIONOPTIMIZE_SF7_TO_SF12 );
+ SX1276Write( REG_LR_DETECTIONTHRESHOLD,
+ RFLR_DETECTIONTHRESH_SF7_TO_SF12 );
+ }
+ }
+ break;
+ }
+}
+
+void SX1276SetTxConfig( 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 )
+{
+ uint8_t paConfig = 0;
+ uint8_t paDac = 0;
+
+ SX1276SetModem( modem );
+
+ paConfig = SX1276Read( REG_PACONFIG );
+ paDac = SX1276Read( REG_PADAC );
+
+ paConfig = ( paConfig & RF_PACONFIG_PASELECT_MASK ) | SX1276GetPaSelect( SX1276.Settings.Channel );
+ paConfig = ( paConfig & RF_PACONFIG_MAX_POWER_MASK ) | 0x70;
+
+ if( ( paConfig & RF_PACONFIG_PASELECT_PABOOST ) == RF_PACONFIG_PASELECT_PABOOST )
+ {
+ if( power > 17 )
+ {
+ paDac = ( paDac & RF_PADAC_20DBM_MASK ) | RF_PADAC_20DBM_ON;
+ }
+ else
+ {
+ paDac = ( paDac & RF_PADAC_20DBM_MASK ) | RF_PADAC_20DBM_OFF;
+ }
+ if( ( paDac & RF_PADAC_20DBM_ON ) == RF_PADAC_20DBM_ON )
+ {
+ if( power < 5 )
+ {
+ power = 5;
+ }
+ if( power > 20 )
+ {
+ power = 20;
+ }
+ paConfig = ( paConfig & RF_PACONFIG_OUTPUTPOWER_MASK ) | ( uint8_t )( ( uint16_t )( power - 5 ) & 0x0F );
+ }
+ else
+ {
+ if( power < 2 )
+ {
+ power = 2;
+ }
+ if( power > 17 )
+ {
+ power = 17;
+ }
+ paConfig = ( paConfig & RF_PACONFIG_OUTPUTPOWER_MASK ) | ( uint8_t )( ( uint16_t )( power - 2 ) & 0x0F );
+ }
+ }
+ else
+ {
+ if( power < -1 )
+ {
+ power = -1;
+ }
+ if( power > 14 )
+ {
+ power = 14;
+ }
+ paConfig = ( paConfig & RF_PACONFIG_OUTPUTPOWER_MASK ) | ( uint8_t )( ( uint16_t )( power + 1 ) & 0x0F );
+ }
+ SX1276Write( REG_PACONFIG, paConfig );
+ SX1276Write( REG_PADAC, paDac );
+
+ switch( modem )
+ {
+ case MODEM_FSK:
+ {
+ SX1276.Settings.Fsk.Power = power;
+ SX1276.Settings.Fsk.Fdev = fdev;
+ SX1276.Settings.Fsk.Bandwidth = bandwidth;
+ SX1276.Settings.Fsk.Datarate = datarate;
+ SX1276.Settings.Fsk.PreambleLen = preambleLen;
+ SX1276.Settings.Fsk.FixLen = fixLen;
+ SX1276.Settings.Fsk.CrcOn = crcOn;
+ SX1276.Settings.Fsk.IqInverted = iqInverted;
+ SX1276.Settings.Fsk.TxTimeout = timeout;
+
+ fdev = ( uint16_t )( ( double )fdev / ( double )FREQ_STEP );
+ SX1276Write( REG_FDEVMSB, ( uint8_t )( fdev >> 8 ) );
+ SX1276Write( REG_FDEVLSB, ( uint8_t )( fdev & 0xFF ) );
+
+ datarate = ( uint16_t )( ( double )XTAL_FREQ / ( double )datarate );
+ SX1276Write( REG_BITRATEMSB, ( uint8_t )( datarate >> 8 ) );
+ SX1276Write( REG_BITRATELSB, ( uint8_t )( datarate & 0xFF ) );
+
+ SX1276Write( REG_PREAMBLEMSB, ( preambleLen >> 8 ) & 0x00FF );
+ SX1276Write( REG_PREAMBLELSB, preambleLen & 0xFF );
+
+ SX1276Write( REG_PACKETCONFIG1,
+ ( SX1276Read( REG_PACKETCONFIG1 ) &
+ RF_PACKETCONFIG1_CRC_MASK &
+ RF_PACKETCONFIG1_PACKETFORMAT_MASK ) |
+ ( ( fixLen == 1 ) ? RF_PACKETCONFIG1_PACKETFORMAT_FIXED : RF_PACKETCONFIG1_PACKETFORMAT_VARIABLE ) |
+ ( crcOn << 4 ) );
+
+ }
+ break;
+ case MODEM_LORA:
+ {
+ SX1276.Settings.LoRa.Power = power;
+ if( bandwidth > 2 )
+ {
+ // Fatal error: When using LoRa modem only bandwidths 125, 250 and 500 kHz are supported
+ while( 1 );
+ }
+ bandwidth += 7;
+ SX1276.Settings.LoRa.Bandwidth = bandwidth;
+ SX1276.Settings.LoRa.Datarate = datarate;
+ SX1276.Settings.LoRa.Coderate = coderate;
+ SX1276.Settings.LoRa.PreambleLen = preambleLen;
+ SX1276.Settings.LoRa.FixLen = fixLen;
+ SX1276.Settings.LoRa.FreqHopOn = freqHopOn;
+ SX1276.Settings.LoRa.HopPeriod = hopPeriod;
+ SX1276.Settings.LoRa.CrcOn = crcOn;
+ SX1276.Settings.LoRa.IqInverted = iqInverted;
+ SX1276.Settings.LoRa.TxTimeout = timeout;
+
+ if( datarate > 12 )
+ {
+ datarate = 12;
+ }
+ else if( datarate < 6 )
+ {
+ datarate = 6;
+ }
+ if( ( ( bandwidth == 7 ) && ( ( datarate == 11 ) || ( datarate == 12 ) ) ) ||
+ ( ( bandwidth == 8 ) && ( datarate == 12 ) ) )
+ {
+ SX1276.Settings.LoRa.LowDatarateOptimize = 0x01;
+ }
+ else
+ {
+ SX1276.Settings.LoRa.LowDatarateOptimize = 0x00;
+ }
+
+ if( SX1276.Settings.LoRa.FreqHopOn == true )
+ {
+ SX1276Write( REG_LR_PLLHOP, ( SX1276Read( REG_LR_PLLHOP ) & RFLR_PLLHOP_FASTHOP_MASK ) | RFLR_PLLHOP_FASTHOP_ON );
+ SX1276Write( REG_LR_HOPPERIOD, SX1276.Settings.LoRa.HopPeriod );
+ }
+
+ SX1276Write( REG_LR_MODEMCONFIG1,
+ ( SX1276Read( REG_LR_MODEMCONFIG1 ) &
+ RFLR_MODEMCONFIG1_BW_MASK &
+ RFLR_MODEMCONFIG1_CODINGRATE_MASK &
+ RFLR_MODEMCONFIG1_IMPLICITHEADER_MASK ) |
+ ( bandwidth << 4 ) | ( coderate << 1 ) |
+ fixLen );
+
+ SX1276Write( REG_LR_MODEMCONFIG2,
+ ( SX1276Read( REG_LR_MODEMCONFIG2 ) &
+ RFLR_MODEMCONFIG2_SF_MASK &
+ RFLR_MODEMCONFIG2_RXPAYLOADCRC_MASK ) |
+ ( datarate << 4 ) | ( crcOn << 2 ) );
+
+ SX1276Write( REG_LR_MODEMCONFIG3,
+ ( SX1276Read( REG_LR_MODEMCONFIG3 ) &
+ RFLR_MODEMCONFIG3_LOWDATARATEOPTIMIZE_MASK ) |
+ ( SX1276.Settings.LoRa.LowDatarateOptimize << 3 ) );
+
+ SX1276Write( REG_LR_PREAMBLEMSB, ( preambleLen >> 8 ) & 0x00FF );
+ SX1276Write( REG_LR_PREAMBLELSB, preambleLen & 0xFF );
+
+ if( datarate == 6 )
+ {
+ SX1276Write( REG_LR_DETECTOPTIMIZE,
+ ( SX1276Read( REG_LR_DETECTOPTIMIZE ) &
+ RFLR_DETECTIONOPTIMIZE_MASK ) |
+ RFLR_DETECTIONOPTIMIZE_SF6 );
+ SX1276Write( REG_LR_DETECTIONTHRESHOLD,
+ RFLR_DETECTIONTHRESH_SF6 );
+ }
+ else
+ {
+ SX1276Write( REG_LR_DETECTOPTIMIZE,
+ ( SX1276Read( REG_LR_DETECTOPTIMIZE ) &
+ RFLR_DETECTIONOPTIMIZE_MASK ) |
+ RFLR_DETECTIONOPTIMIZE_SF7_TO_SF12 );
+ SX1276Write( REG_LR_DETECTIONTHRESHOLD,
+ RFLR_DETECTIONTHRESH_SF7_TO_SF12 );
+ }
+ }
+ break;
+ }
+}
+
+uint32_t SX1276GetTimeOnAir( RadioModems_t modem, uint8_t pktLen )
+{
+ uint32_t airTime = 0;
+
+ switch( modem )
+ {
+ case MODEM_FSK:
+ {
+ airTime = round( ( 8 * ( SX1276.Settings.Fsk.PreambleLen +
+ ( ( SX1276Read( REG_SYNCCONFIG ) & ~RF_SYNCCONFIG_SYNCSIZE_MASK ) + 1 ) +
+ ( ( SX1276.Settings.Fsk.FixLen == 0x01 ) ? 0.0 : 1.0 ) +
+ ( ( ( SX1276Read( REG_PACKETCONFIG1 ) & ~RF_PACKETCONFIG1_ADDRSFILTERING_MASK ) != 0x00 ) ? 1.0 : 0 ) +
+ pktLen +
+ ( ( SX1276.Settings.Fsk.CrcOn == 0x01 ) ? 2.0 : 0 ) ) /
+ SX1276.Settings.Fsk.Datarate ) * 1e3 );
+ }
+ break;
+ case MODEM_LORA:
+ {
+ double bw = 0.0;
+ // REMARK: When using LoRa modem only bandwidths 125, 250 and 500 kHz are supported
+ switch( SX1276.Settings.LoRa.Bandwidth )
+ {
+ //case 0: // 7.8 kHz
+ // bw = 78e2;
+ // break;
+ //case 1: // 10.4 kHz
+ // bw = 104e2;
+ // break;
+ //case 2: // 15.6 kHz
+ // bw = 156e2;
+ // break;
+ //case 3: // 20.8 kHz
+ // bw = 208e2;
+ // break;
+ //case 4: // 31.2 kHz
+ // bw = 312e2;
+ // break;
+ //case 5: // 41.4 kHz
+ // bw = 414e2;
+ // break;
+ //case 6: // 62.5 kHz
+ // bw = 625e2;
+ // break;
+ case 7: // 125 kHz
+ bw = 125e3;
+ break;
+ case 8: // 250 kHz
+ bw = 250e3;
+ break;
+ case 9: // 500 kHz
+ bw = 500e3;
+ break;
+ }
+
+ // Symbol rate : time for one symbol (secs)
+ double rs = bw / ( 1 << SX1276.Settings.LoRa.Datarate );
+ double ts = 1 / rs;
+ // time of preamble
+ double tPreamble = ( SX1276.Settings.LoRa.PreambleLen + 4.25 ) * ts;
+ // Symbol length of payload and time
+ double tmp = ceil( ( 8 * pktLen - 4 * SX1276.Settings.LoRa.Datarate +
+ 28 + 16 * SX1276.Settings.LoRa.CrcOn -
+ ( SX1276.Settings.LoRa.FixLen ? 20 : 0 ) ) /
+ ( double )( 4 * SX1276.Settings.LoRa.Datarate -
+ ( ( SX1276.Settings.LoRa.LowDatarateOptimize > 0 ) ? 2 : 0 ) ) ) *
+ ( SX1276.Settings.LoRa.Coderate + 4 );
+ double nPayload = 8 + ( ( tmp > 0 ) ? tmp : 0 );
+ double tPayload = nPayload * ts;
+ // Time on air
+ double tOnAir = tPreamble + tPayload;
+ // return us secs
+ airTime = floor( tOnAir * 1e3 + 0.999 );
+ }
+ break;
+ }
+ return airTime;
+}
+
+void SX1276Send( uint8_t *buffer, uint8_t size )
+{
+ uint32_t txTimeout = 0;
+
+ switch( SX1276.Settings.Modem )
+ {
+ case MODEM_FSK:
+ {
+ SX1276.Settings.FskPacketHandler.NbBytes = 0;
+ SX1276.Settings.FskPacketHandler.Size = size;
+
+ if( SX1276.Settings.Fsk.FixLen == false )
+ {
+ SX1276WriteFifo( ( uint8_t* )&size, 1 );
+ }
+ else
+ {
+ SX1276Write( REG_PAYLOADLENGTH, size );
+ }
+
+ if( ( size > 0 ) && ( size <= 64 ) )
+ {
+ SX1276.Settings.FskPacketHandler.ChunkSize = size;
+ }
+ else
+ {
+ memcpy( RxTxBuffer, buffer, size );
+ SX1276.Settings.FskPacketHandler.ChunkSize = 32;
+ }
+
+ // Write payload buffer
+ SX1276WriteFifo( buffer, SX1276.Settings.FskPacketHandler.ChunkSize );
+ SX1276.Settings.FskPacketHandler.NbBytes += SX1276.Settings.FskPacketHandler.ChunkSize;
+ txTimeout = SX1276.Settings.Fsk.TxTimeout;
+ }
+ break;
+ case MODEM_LORA:
+ {
+ if( SX1276.Settings.LoRa.IqInverted == true )
+ {
+ SX1276Write( REG_LR_INVERTIQ, ( ( SX1276Read( REG_LR_INVERTIQ ) & RFLR_INVERTIQ_TX_MASK & RFLR_INVERTIQ_RX_MASK ) | RFLR_INVERTIQ_RX_OFF | RFLR_INVERTIQ_TX_ON ) );
+ SX1276Write( REG_LR_INVERTIQ2, RFLR_INVERTIQ2_ON );
+ }
+ else
+ {
+ SX1276Write( REG_LR_INVERTIQ, ( ( SX1276Read( REG_LR_INVERTIQ ) & RFLR_INVERTIQ_TX_MASK & RFLR_INVERTIQ_RX_MASK ) | RFLR_INVERTIQ_RX_OFF | RFLR_INVERTIQ_TX_OFF ) );
+ SX1276Write( REG_LR_INVERTIQ2, RFLR_INVERTIQ2_OFF );
+ }
+
+ SX1276.Settings.LoRaPacketHandler.Size = size;
+
+ // Initializes the payload size
+ SX1276Write( REG_LR_PAYLOADLENGTH, size );
+
+ // Full buffer used for Tx
+ SX1276Write( REG_LR_FIFOTXBASEADDR, 0 );
+ SX1276Write( REG_LR_FIFOADDRPTR, 0 );
+
+ // FIFO operations can not take place in Sleep mode
+ if( ( SX1276Read( REG_OPMODE ) & ~RF_OPMODE_MASK ) == RF_OPMODE_SLEEP )
+ {
+ SX1276SetStby( );
+ os_cputime_delay_usecs(1000);
+ }
+ // Write payload buffer
+ SX1276WriteFifo( buffer, size );
+ txTimeout = SX1276.Settings.LoRa.TxTimeout;
+ }
+ break;
+ }
+
+ SX1276SetTx( txTimeout );
+}
+
+void SX1276SetSleep( void )
+{
+ os_cputime_timer_stop(&RxTimeoutTimer);
+ os_cputime_timer_stop(&TxTimeoutTimer);
+
+ SX1276SetOpMode( RF_OPMODE_SLEEP );
+ SX1276.Settings.State = RF_IDLE;
+}
+
+void SX1276SetStby( void )
+{
+ os_cputime_timer_stop(&RxTimeoutTimer);
+ os_cputime_timer_stop(&TxTimeoutTimer);
+
+ SX1276SetOpMode( RF_OPMODE_STANDBY );
+ SX1276.Settings.State = RF_IDLE;
+}
+
+void SX1276SetRx( uint32_t timeout )
+{
+ bool rxContinuous = false;
+
+ switch( SX1276.Settings.Modem )
+ {
+ case MODEM_FSK:
+ {
+ rxContinuous = SX1276.Settings.Fsk.RxContinuous;
+
+ // DIO0=PayloadReady
+ // DIO1=FifoLevel
+ // DIO2=SyncAddr
+ // DIO3=FifoEmpty
+ // DIO4=Preamble
+ // DIO5=ModeReady
+ SX1276Write( REG_DIOMAPPING1, ( SX1276Read( REG_DIOMAPPING1 ) & RF_DIOMAPPING1_DIO0_MASK &
+ RF_DIOMAPPING1_DIO1_MASK &
+ RF_DIOMAPPING1_DIO2_MASK ) |
+ RF_DIOMAPPING1_DIO0_00 |
+ RF_DIOMAPPING1_DIO1_00 |
+ RF_DIOMAPPING1_DIO2_11 );
+
+ SX1276Write( REG_DIOMAPPING2, ( SX1276Read( REG_DIOMAPPING2 ) & RF_DIOMAPPING2_DIO4_MASK &
+ RF_DIOMAPPING2_MAP_MASK ) |
+ RF_DIOMAPPING2_DIO4_11 |
+ RF_DIOMAPPING2_MAP_PREAMBLEDETECT );
+
+ SX1276.Settings.FskPacketHandler.FifoThresh = SX1276Read( REG_FIFOTHRESH ) & 0x3F;
+
+ SX1276Write( REG_RXCONFIG, RF_RXCONFIG_AFCAUTO_ON | RF_RXCONFIG_AGCAUTO_ON | RF_RXCONFIG_RXTRIGER_PREAMBLEDETECT );
+
+ SX1276.Settings.FskPacketHandler.PreambleDetected = false;
+ SX1276.Settings.FskPacketHandler.SyncWordDetected = false;
+ SX1276.Settings.FskPacketHandler.NbBytes = 0;
+ SX1276.Settings.FskPacketHandler.Size = 0;
+ }
+ break;
+ case MODEM_LORA:
+ {
+ if( SX1276.Settings.LoRa.IqInverted == true )
+ {
+ SX1276Write( REG_LR_INVERTIQ, ( ( SX1276Read( REG_LR_INVERTIQ ) & RFLR_INVERTIQ_TX_MASK & RFLR_INVERTIQ_RX_MASK ) | RFLR_INVERTIQ_RX_ON | RFLR_INVERTIQ_TX_OFF ) );
+ SX1276Write( REG_LR_INVERTIQ2, RFLR_INVERTIQ2_ON );
+ }
+ else
+ {
+ SX1276Write( REG_LR_INVERTIQ, ( ( SX1276Read( REG_LR_INVERTIQ ) & RFLR_INVERTIQ_TX_MASK & RFLR_INVERTIQ_RX_MASK ) | RFLR_INVERTIQ_RX_OFF | RFLR_INVERTIQ_TX_OFF ) );
+ SX1276Write( REG_LR_INVERTIQ2, RFLR_INVERTIQ2_OFF );
+ }
+
+ // ERRATA 2.3 - Receiver Spurious Reception of a LoRa Signal
+ if( SX1276.Settings.LoRa.Bandwidth < 9 )
+ {
+ SX1276Write( REG_LR_DETECTOPTIMIZE, SX1276Read( REG_LR_DETECTOPTIMIZE ) & 0x7F );
+ SX1276Write( REG_LR_TEST30, 0x00 );
+ switch( SX1276.Settings.LoRa.Bandwidth )
+ {
+ case 0: // 7.8 kHz
+ SX1276Write( REG_LR_TEST2F, 0x48 );
+ SX1276SetChannel(SX1276.Settings.Channel + 7.81e3 );
+ break;
+ case 1: // 10.4 kHz
+ SX1276Write( REG_LR_TEST2F, 0x44 );
+ SX1276SetChannel(SX1276.Settings.Channel + 10.42e3 );
+ break;
+ case 2: // 15.6 kHz
+ SX1276Write( REG_LR_TEST2F, 0x44 );
+ SX1276SetChannel(SX1276.Settings.Channel + 15.62e3 );
+ break;
+ case 3: // 20.8 kHz
+ SX1276Write( REG_LR_TEST2F, 0x44 );
+ SX1276SetChannel(SX1276.Settings.Channel + 20.83e3 );
+ break;
+ case 4: // 31.2 kHz
+ SX1276Write( REG_LR_TEST2F, 0x44 );
+ SX1276SetChannel(SX1276.Settings.Channel + 31.25e3 );
+ break;
+ case 5: // 41.4 kHz
+ SX1276Write( REG_LR_TEST2F, 0x44 );
+ SX1276SetChannel(SX1276.Settings.Channel + 41.67e3 );
+ break;
+ case 6: // 62.5 kHz
+ SX1276Write( REG_LR_TEST2F, 0x40 );
+ break;
+ case 7: // 125 kHz
+ SX1276Write( REG_LR_TEST2F, 0x40 );
+ break;
+ case 8: // 250 kHz
+ SX1276Write( REG_LR_TEST2F, 0x40 );
+ break;
+ }
+ }
+ else
+ {
+ SX1276Write( REG_LR_DETECTOPTIMIZE, SX1276Read( REG_LR_DETECTOPTIMIZE ) | 0x80 );
+ }
+
+ rxContinuous = SX1276.Settings.LoRa.RxContinuous;
+
+ if( SX1276.Settings.LoRa.FreqHopOn == true )
+ {
+ SX1276Write( REG_LR_IRQFLAGSMASK, //RFLR_IRQFLAGS_RXTIMEOUT |
+ //RFLR_IRQFLAGS_RXDONE |
+ //RFLR_IRQFLAGS_PAYLOADCRCERROR |
+ RFLR_IRQFLAGS_VALIDHEADER |
+ RFLR_IRQFLAGS_TXDONE |
+ RFLR_IRQFLAGS_CADDONE |
+ //RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL |
+ RFLR_IRQFLAGS_CADDETECTED );
+
+ // DIO0=RxDone, DIO2=FhssChangeChannel
+ SX1276Write( REG_DIOMAPPING1, ( SX1276Read( REG_DIOMAPPING1 ) & RFLR_DIOMAPPING1_DIO0_MASK & RFLR_DIOMAPPING1_DIO2_MASK ) | RFLR_DIOMAPPING1_DIO0_00 | RFLR_DIOMAPPING1_DIO2_00 );
+ }
+ else
+ {
+ SX1276Write( REG_LR_IRQFLAGSMASK, //RFLR_IRQFLAGS_RXTIMEOUT |
+ //RFLR_IRQFLAGS_RXDONE |
+ //RFLR_IRQFLAGS_PAYLOADCRCERROR |
+ RFLR_IRQFLAGS_VALIDHEADER |
+ RFLR_IRQFLAGS_TXDONE |
+ RFLR_IRQFLAGS_CADDONE |
+ RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL |
+ RFLR_IRQFLAGS_CADDETECTED );
+
+ // DIO0=RxDone
+ SX1276Write( REG_DIOMAPPING1, ( SX1276Read( REG_DIOMAPPING1 ) & RFLR_DIOMAPPING1_DIO0_MASK ) | RFLR_DIOMAPPING1_DIO0_00 );
+ }
+ SX1276Write( REG_LR_FIFORXBASEADDR, 0 );
+ SX1276Write( REG_LR_FIFOADDRPTR, 0 );
+ }
+ break;
+ }
+
+ memset( RxTxBuffer, 0, ( size_t )RX_BUFFER_SIZE );
+
+ SX1276.Settings.State = RF_RX_RUNNING;
+ if( timeout != 0 )
+ {
+ os_cputime_timer_relative(&RxTimeoutTimer, timeout*1000);
+ }
+
+ if( SX1276.Settings.Modem == MODEM_FSK )
+ {
+ SX1276SetOpMode( RF_OPMODE_RECEIVER );
+
+ if( rxContinuous == false )
+ {
+ rx_timeout_sync_delay =
+ ceil((8.0 * (SX1276.Settings.Fsk.PreambleLen +
+ ((SX1276Read(REG_SYNCCONFIG) &
+ ~RF_SYNCCONFIG_SYNCSIZE_MASK) + 1.0) + 10.0) /
+ (double)SX1276.Settings.Fsk.Datarate) * 1e3) + 4;
+ os_cputime_timer_relative(
+ &RxTimeoutSyncWord, rx_timeout_sync_delay*1000);
+ }
+ }
+ else
+ {
+ if( rxContinuous == true )
+ {
+ SX1276SetOpMode( RFLR_OPMODE_RECEIVER );
+ }
+ else
+ {
+ SX1276SetOpMode( RFLR_OPMODE_RECEIVER_SINGLE );
+ }
+ }
+}
+
+void SX1276SetTx( uint32_t timeout )
+{
+ os_cputime_timer_relative(&TxTimeoutTimer, timeout*1000);
+
+ switch( SX1276.Settings.Modem )
+ {
+ case MODEM_FSK:
+ {
+ // DIO0=PacketSent
+ // DIO1=FifoEmpty
+ // DIO2=FifoFull
+ // DIO3=FifoEmpty
+ // DIO4=LowBat
+ // DIO5=ModeReady
+ SX1276Write( REG_DIOMAPPING1, ( SX1276Read( REG_DIOMAPPING1 ) & RF_DIOMAPPING1_DIO0_MASK &
+ RF_DIOMAPPING1_DIO1_MASK &
+ RF_DIOMAPPING1_DIO2_MASK ) |
+ RF_DIOMAPPING1_DIO1_01 );
+
+ SX1276Write( REG_DIOMAPPING2, ( SX1276Read( REG_DIOMAPPING2 ) & RF_DIOMAPPING2_DIO4_MASK &
+ RF_DIOMAPPING2_MAP_MASK ) );
+ SX1276.Settings.FskPacketHandler.FifoThresh = SX1276Read( REG_FIFOTHRESH ) & 0x3F;
+ }
+ break;
+ case MODEM_LORA:
+ {
+ if( SX1276.Settings.LoRa.FreqHopOn == true )
+ {
+ SX1276Write( REG_LR_IRQFLAGSMASK, RFLR_IRQFLAGS_RXTIMEOUT |
+ RFLR_IRQFLAGS_RXDONE |
+ RFLR_IRQFLAGS_PAYLOADCRCERROR |
+ RFLR_IRQFLAGS_VALIDHEADER |
+ //RFLR_IRQFLAGS_TXDONE |
+ RFLR_IRQFLAGS_CADDONE |
+ //RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL |
+ RFLR_IRQFLAGS_CADDETECTED );
+
+ // DIO0=TxDone, DIO2=FhssChangeChannel
+ SX1276Write( REG_DIOMAPPING1, ( SX1276Read( REG_DIOMAPPING1 ) & RFLR_DIOMAPPING1_DIO0_MASK & RFLR_DIOMAPPING1_DIO2_MASK ) | RFLR_DIOMAPPING1_DIO0_01 | RFLR_DIOMAPPING1_DIO2_00 );
+ }
+ else
+ {
+ SX1276Write( REG_LR_IRQFLAGSMASK, RFLR_IRQFLAGS_RXTIMEOUT |
+ RFLR_IRQFLAGS_RXDONE |
+ RFLR_IRQFLAGS_PAYLOADCRCERROR |
+ RFLR_IRQFLAGS_VALIDHEADER |
+ //RFLR_IRQFLAGS_TXDONE |
+ RFLR_IRQFLAGS_CADDONE |
+ RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL |
+ RFLR_IRQFLAGS_CADDETECTED );
+
+ // DIO0=TxDone
+ SX1276Write( REG_DIOMAPPING1, ( SX1276Read( REG_DIOMAPPING1 ) & RFLR_DIOMAPPING1_DIO0_MASK ) | RFLR_DIOMAPPING1_DIO0_01 );
+ }
+ }
+ break;
+ }
+
+ SX1276.Settings.State = RF_TX_RUNNING;
+ os_cputime_timer_relative(&TxTimeoutTimer, timeout*1000);
+ SX1276SetOpMode( RF_OPMODE_TRANSMITTER );
+}
+
+void SX1276StartCad( void )
+{
+ switch( SX1276.Settings.Modem )
+ {
+ case MODEM_FSK:
+ {
+
+ }
+ break;
+ case MODEM_LORA:
+ {
+ SX1276Write( REG_LR_IRQFLAGSMASK, RFLR_IRQFLAGS_RXTIMEOUT |
+ RFLR_IRQFLAGS_RXDONE |
+ RFLR_IRQFLAGS_PAYLOADCRCERROR |
+ RFLR_IRQFLAGS_VALIDHEADER |
+ RFLR_IRQFLAGS_TXDONE |
+ //RFLR_IRQFLAGS_CADDONE |
+ RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL // |
+ //RFLR_IRQFLAGS_CADDETECTED
+ );
+
+ // DIO3=CADDone
+ SX1276Write( REG_DIOMAPPING1, ( SX1276Read( REG_DIOMAPPING1 ) & RFLR_DIOMAPPING1_DIO0_MASK ) | RFLR_DIOMAPPING1_DIO0_00 );
+
+ SX1276.Settings.State = RF_CAD;
+ SX1276SetOpMode( RFLR_OPMODE_CAD );
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+int16_t SX1276ReadRssi( RadioModems_t modem )
+{
+ int16_t rssi = 0;
+
+ switch( modem )
+ {
+ case MODEM_FSK:
+ rssi = -( SX1276Read( REG_RSSIVALUE ) >> 1 );
+ break;
+ case MODEM_LORA:
+ if( SX1276.Settings.Channel > RF_MID_BAND_THRESH )
+ {
+ rssi = RSSI_OFFSET_HF + SX1276Read( REG_LR_RSSIVALUE );
+ }
+ else
+ {
+ rssi = RSSI_OFFSET_LF + SX1276Read( REG_LR_RSSIVALUE );
+ }
+ break;
+ default:
+ rssi = -1;
+ break;
+ }
+ return rssi;
+}
+
+void SX1276Reset( void )
+{
+ // Set RESET pin to 0
+ hal_gpio_init_out(RADIO_RESET, 0);
+
+ // Wait 1 ms
+ os_cputime_delay_usecs(1000);
+
+ // Configure RESET as input
+ hal_gpio_init_in(RADIO_RESET, HAL_GPIO_PULL_NONE);
+
+ // Wait 6 ms
+ os_cputime_delay_usecs(6000);
+}
+
+void SX1276SetOpMode( uint8_t opMode )
+{
+ if( opMode == RF_OPMODE_SLEEP )
+ {
+ SX1276SetAntSwLowPower( true );
+ }
+ else
+ {
+ SX1276SetAntSwLowPower( false );
+ if( opMode == RF_OPMODE_TRANSMITTER )
+ {
+ SX1276SetAntSw( 1 );
+ }
+ else
+ {
+ SX1276SetAntSw( 0 );
+ }
+ }
+ SX1276Write( REG_OPMODE, ( SX1276Read( REG_OPMODE ) & RF_OPMODE_MASK ) | opMode );
+}
+
+void SX1276SetModem( RadioModems_t modem )
+{
+
+ if( SX1276.Settings.Modem == modem )
+ {
+ return;
+ }
+
+ SX1276.Settings.Modem = modem;
+ switch( SX1276.Settings.Modem )
+ {
+ default:
+ case MODEM_FSK:
+ SX1276SetOpMode( RF_OPMODE_SLEEP );
+ SX1276Write( REG_OPMODE, ( SX1276Read( REG_OPMODE ) & RFLR_OPMODE_LONGRANGEMODE_MASK ) | RFLR_OPMODE_LONGRANGEMODE_OFF );
+
+ SX1276Write( REG_DIOMAPPING1, 0x00 );
+ SX1276Write( REG_DIOMAPPING2, 0x30 ); // DIO5=ModeReady
+ break;
+ case MODEM_LORA:
+ SX1276SetOpMode( RF_OPMODE_SLEEP );
+ SX1276Write( REG_OPMODE, ( SX1276Read( REG_OPMODE ) & RFLR_OPMODE_LONGRANGEMODE_MASK ) | RFLR_OPMODE_LONGRANGEMODE_ON );
+
+ SX1276Write( REG_DIOMAPPING1, 0x00 );
+ SX1276Write( REG_DIOMAPPING2, 0x00 );
+ break;
+ }
+}
+
+void SX1276Write( uint8_t addr, uint8_t data )
+{
+ SX1276WriteBuffer( addr, &data, 1 );
+}
+
+uint8_t SX1276Read( uint8_t addr )
+{
+ uint8_t data;
+ SX1276ReadBuffer( addr, &data, 1 );
+ return data;
+}
+
+void SX1276WriteBuffer( uint8_t addr, uint8_t *buffer, uint8_t size )
+{
+ uint8_t i;
+
+ hal_gpio_write(RADIO_NSS, 0);
+
+ hal_spi_tx_val(RADIO_SPI_IDX, addr | 0x80);
+ for( i = 0; i < size; i++ )
+ {
+ hal_spi_tx_val(RADIO_SPI_IDX, buffer[i]);
+ }
+
+ hal_gpio_write(RADIO_NSS, 1);
+}
+
+void SX1276ReadBuffer( uint8_t addr, uint8_t *buffer, uint8_t size )
+{
+ uint8_t i;
+
+ hal_gpio_write(RADIO_NSS, 0);
+
+ hal_spi_tx_val(RADIO_SPI_IDX, addr & 0x7f);
+ for( i = 0; i < size; i++ )
+ {
+ buffer[i] = hal_spi_tx_val(RADIO_SPI_IDX, 0);
+ }
+
+ hal_gpio_write(RADIO_NSS, 1);
+}
+
+void SX1276WriteFifo( uint8_t *buffer, uint8_t size )
+{
+ SX1276WriteBuffer( 0, buffer, size );
+}
+
+void SX1276ReadFifo( uint8_t *buffer, uint8_t size )
+{
+ SX1276ReadBuffer( 0, buffer, size );
+}
+
+void SX1276SetMaxPayloadLength( RadioModems_t modem, uint8_t max )
+{
+ SX1276SetModem( modem );
+
+ switch( modem )
+ {
+ case MODEM_FSK:
+ if( SX1276.Settings.Fsk.FixLen == false )
+ {
+ SX1276Write( REG_PAYLOADLENGTH, max );
+ }
+ break;
+ case MODEM_LORA:
+ SX1276Write( REG_LR_PAYLOADMAXLENGTH, max );
+ break;
+ }
+}
+
+void SX1276OnTimeoutIrq(void *unused)
+{
+ switch( SX1276.Settings.State )
+ {
+ case RF_RX_RUNNING:
+ if( SX1276.Settings.Modem == MODEM_FSK )
+ {
+ SX1276.Settings.FskPacketHandler.PreambleDetected = false;
+ SX1276.Settings.FskPacketHandler.SyncWordDetected = false;
+ SX1276.Settings.FskPacketHandler.NbBytes = 0;
+ SX1276.Settings.FskPacketHandler.Size = 0;
+
+ // Clear Irqs
+ SX1276Write( REG_IRQFLAGS1, RF_IRQFLAGS1_RSSI |
+ RF_IRQFLAGS1_PREAMBLEDETECT |
+ RF_IRQFLAGS1_SYNCADDRESSMATCH );
+ SX1276Write( REG_IRQFLAGS2, RF_IRQFLAGS2_FIFOOVERRUN );
+
+ if( SX1276.Settings.Fsk.RxContinuous == true )
+ {
+ // Continuous mode restart Rx chain
+ SX1276Write( REG_RXCONFIG, SX1276Read( REG_RXCONFIG ) | RF_RXCONFIG_RESTARTRXWITHOUTPLLLOCK );
+ assert(rx_timeout_sync_delay != (uint32_t)-1);
+ os_cputime_timer_relative(
+ &RxTimeoutSyncWord, rx_timeout_sync_delay*1000);
+ }
+ else
+ {
+ SX1276.Settings.State = RF_IDLE;
+ os_cputime_timer_stop(&RxTimeoutSyncWord);
+ }
+ }
+ SX1276RxTimeout( );
+ break;
+ case RF_TX_RUNNING:
+ SX1276.Settings.State = RF_IDLE;
+ SX1276TxTimeout( );
+ break;
+ default:
+ break;
+ }
+}
+
+void SX1276OnDio0Irq(void *unused)
+{
+ volatile uint8_t irqFlags = 0;
+
+ switch( SX1276.Settings.State )
+ {
+ case RF_RX_RUNNING:
+ //TimerStop( &RxTimeoutTimer );
+ // RxDone interrupt
+ switch( SX1276.Settings.Modem )
+ {
+ case MODEM_FSK:
+ if( SX1276.Settings.Fsk.CrcOn == true )
+ {
+ irqFlags = SX1276Read( REG_IRQFLAGS2 );
+ if( ( irqFlags & RF_IRQFLAGS2_CRCOK ) != RF_IRQFLAGS2_CRCOK )
+ {
+ // Clear Irqs
+ SX1276Write( REG_IRQFLAGS1, RF_IRQFLAGS1_RSSI |
+ RF_IRQFLAGS1_PREAMBLEDETECT |
+ RF_IRQFLAGS1_SYNCADDRESSMATCH );
+ SX1276Write( REG_IRQFLAGS2, RF_IRQFLAGS2_FIFOOVERRUN );
+
+ os_cputime_timer_stop(&RxTimeoutTimer);
+
+ if( SX1276.Settings.Fsk.RxContinuous == false )
+ {
+ os_cputime_timer_stop(&RxTimeoutSyncWord);
+ SX1276.Settings.State = RF_IDLE;
+ }
+ else
+ {
+ // Continuous mode restart Rx chain
+ SX1276Write( REG_RXCONFIG, SX1276Read( REG_RXCONFIG ) | RF_RXCONFIG_RESTARTRXWITHOUTPLLLOCK );
+ assert(rx_timeout_sync_delay != (uint32_t)-1);
+ os_cputime_timer_relative(
+ &RxTimeoutSyncWord, rx_timeout_sync_delay*1000);
+ }
+
+ SX1276RxError( );
+ SX1276.Settings.FskPacketHandler.PreambleDetected = false;
+ SX1276.Settings.FskPacketHandler.SyncWordDetected = false;
+ SX1276.Settings.FskPacketHandler.NbBytes = 0;
+ SX1276.Settings.FskPacketHandler.Size = 0;
+ break;
+ }
+ }
+
+ // Read received packet size
+ if( ( SX1276.Settings.FskPacketHandler.Size == 0 ) && ( SX1276.Settings.FskPacketHandler.NbBytes == 0 ) )
+ {
+ if( SX1276.Settings.Fsk.FixLen == false )
+ {
+ SX1276ReadFifo( ( uint8_t* )&SX1276.Settings.FskPacketHandler.Size, 1 );
+ }
+ else
+ {
+ SX1276.Settings.FskPacketHandler.Size = SX1276Read( REG_PAYLOADLENGTH );
+ }
+ SX1276ReadFifo( RxTxBuffer + SX1276.Settings.FskPacketHandler.NbBytes, SX1276.Settings.FskPacketHandler.Size - SX1276.Settings.FskPacketHandler.NbBytes );
+ SX1276.Settings.FskPacketHandler.NbBytes += ( SX1276.Settings.FskPacketHandler.Size - SX1276.Settings.FskPacketHandler.NbBytes );
+ }
+ else
+ {
+ SX1276ReadFifo( RxTxBuffer + SX1276.Settings.FskPacketHandler.NbBytes, SX1276.Settings.FskPacketHandler.Size - SX1276.Settings.FskPacketHandler.NbBytes );
+ SX1276.Settings.FskPacketHandler.NbBytes += ( SX1276.Settings.FskPacketHandler.Size - SX1276.Settings.FskPacketHandler.NbBytes );
+ }
+
+ if( SX1276.Settings.Fsk.RxContinuous == false )
+ {
+ SX1276.Settings.State = RF_IDLE;
+ assert(rx_timeout_sync_delay != (uint32_t)-1);
+ os_cputime_timer_relative(
+ &RxTimeoutSyncWord, rx_timeout_sync_delay*1000);
+
+ }
+ else
+ {
+ // Continuous mode restart Rx chain
+ SX1276Write( REG_RXCONFIG, SX1276Read( REG_RXCONFIG ) | RF_RXCONFIG_RESTARTRXWITHOUTPLLLOCK );
+ }
+ os_cputime_timer_stop(&RxTimeoutTimer);
+
+ SX1276RxDone( RxTxBuffer, SX1276.Settings.FskPacketHandler.Size, SX1276.Settings.FskPacketHandler.RssiValue, 0 );
+ SX1276.Settings.FskPacketHandler.PreambleDetected = false;
+ SX1276.Settings.FskPacketHandler.SyncWordDetected = false;
+ SX1276.Settings.FskPacketHandler.NbBytes = 0;
+ SX1276.Settings.FskPacketHandler.Size = 0;
+ break;
+ case MODEM_LORA:
+ {
+ int8_t snr = 0;
+
+ // Clear Irq
+ SX1276Write( REG_LR_IRQFLAGS, RFLR_IRQFLAGS_RXDONE);
+
+ irqFlags = SX1276Read( REG_LR_IRQFLAGS );
+ if( ( irqFlags & RFLR_IRQFLAGS_PAYLOADCRCERROR_MASK ) == RFLR_IRQFLAGS_PAYLOADCRCERROR )
+ {
+ // Clear Irq
+ SX1276Write( REG_LR_IRQFLAGS, RFLR_IRQFLAGS_PAYLOADCRCERROR);
+
+ if( SX1276.Settings.LoRa.RxContinuous == false )
+ {
+ SX1276.Settings.State = RF_IDLE;
+ }
+ os_cputime_timer_stop(&RxTimeoutTimer);
+
+ SX1276RxError( );
+ break;
+ }
+
+ SX1276.Settings.LoRaPacketHandler.SnrValue = SX1276Read( REG_LR_PKTSNRVALUE );
+ if( SX1276.Settings.LoRaPacketHandler.SnrValue & 0x80 ) // The SNR sign bit is 1
+ {
+ // Invert and divide by 4
+ snr = ( ( ~SX1276.Settings.LoRaPacketHandler.SnrValue + 1 ) & 0xFF ) >> 2;
+ snr = -snr;
+ }
+ else
+ {
+ // Divide by 4
+ snr = ( SX1276.Settings.LoRaPacketHandler.SnrValue & 0xFF ) >> 2;
+ }
+
+ int16_t rssi = SX1276Read( REG_LR_PKTRSSIVALUE );
+ if( snr < 0 )
+ {
+ if( SX1276.Settings.Channel > RF_MID_BAND_THRESH )
+ {
+ SX1276.Settings.LoRaPacketHandler.RssiValue = RSSI_OFFSET_HF + rssi + ( rssi >> 4 ) +
+ snr;
+ }
+ else
+ {
+ SX1276.Settings.LoRaPacketHandler.RssiValue = RSSI_OFFSET_LF + rssi + ( rssi >> 4 ) +
+ snr;
+ }
+ }
+ else
+ {
+ if( SX1276.Settings.Channel > RF_MID_BAND_THRESH )
+ {
+ SX1276.Settings.LoRaPacketHandler.RssiValue = RSSI_OFFSET_HF + rssi + ( rssi >> 4 );
+ }
+ else
+ {
+ SX1276.Settings.LoRaPacketHandler.RssiValue = RSSI_OFFSET_LF + rssi + ( rssi >> 4 );
+ }
+ }
+
+ SX1276.Settings.LoRaPacketHandler.Size = SX1276Read( REG_LR_RXNBBYTES );
+ SX1276ReadFifo( RxTxBuffer, SX1276.Settings.LoRaPacketHandler.Size );
+
+ if( SX1276.Settings.LoRa.RxContinuous == false )
+ {
+ SX1276.Settings.State = RF_IDLE;
+ }
+ os_cputime_timer_stop(&RxTimeoutTimer);
+
+ SX1276RxDone( RxTxBuffer, SX1276.Settings.LoRaPacketHandler.Size, SX1276.Settings.LoRaPacketHandler.RssiValue, SX1276.Settings.LoRaPacketHandler.SnrValue );
+ }
+ break;
+ default:
+ break;
+ }
+ break;
+ case RF_TX_RUNNING:
+ os_cputime_timer_stop(&TxTimeoutTimer);
+ // TxDone interrupt
+ switch( SX1276.Settings.Modem )
+ {
+ case MODEM_LORA:
+ // Clear Irq
+ SX1276Write( REG_LR_IRQFLAGS, RFLR_IRQFLAGS_TXDONE );
+ // Intentional fall through
+ case MODEM_FSK:
+ default:
+ SX1276.Settings.State = RF_IDLE;
+ SX1276TxDone( );
+ break;
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+void SX1276OnDio1Irq(void *unused)
+{
+ switch( SX1276.Settings.State )
+ {
+ case RF_RX_RUNNING:
+ switch( SX1276.Settings.Modem )
+ {
+ case MODEM_FSK:
+ // FifoLevel interrupt
+ // Read received packet size
+ if( ( SX1276.Settings.FskPacketHandler.Size == 0 ) && ( SX1276.Settings.FskPacketHandler.NbBytes == 0 ) )
+ {
+ if( SX1276.Settings.Fsk.FixLen == false )
+ {
+ SX1276ReadFifo( ( uint8_t* )&SX1276.Settings.FskPacketHandler.Size, 1 );
+ }
+ else
+ {
+ SX1276.Settings.FskPacketHandler.Size = SX1276Read( REG_PAYLOADLENGTH );
+ }
+ }
+
+ if( ( SX1276.Settings.FskPacketHandler.Size - SX1276.Settings.FskPacketHandler.NbBytes ) > SX1276.Settings.FskPacketHandler.FifoThresh )
+ {
+ SX1276ReadFifo( ( RxTxBuffer + SX1276.Settings.FskPacketHandler.NbBytes ), SX1276.Settings.FskPacketHandler.FifoThresh );
+ SX1276.Settings.FskPacketHandler.NbBytes += SX1276.Settings.FskPacketHandler.FifoThresh;
+ }
+ else
+ {
+ SX1276ReadFifo( ( RxTxBuffer + SX1276.Settings.FskPacketHandler.NbBytes ), SX1276.Settings.FskPacketHandler.Size - SX1276.Settings.FskPacketHandler.NbBytes );
+ SX1276.Settings.FskPacketHandler.NbBytes += ( SX1276.Settings.FskPacketHandler.Size - SX1276.Settings.FskPacketHandler.NbBytes );
+ }
+ break;
+ case MODEM_LORA:
+ // Sync time out
+ os_cputime_timer_stop(&RxTimeoutTimer);
+ SX1276.Settings.State = RF_IDLE;
+ SX1276RxTimeout( );
+ break;
+ default:
+ break;
+ }
+ break;
+ case RF_TX_RUNNING:
+ switch( SX1276.Settings.Modem )
+ {
+ case MODEM_FSK:
+ // FifoEmpty interrupt
+ if( ( SX1276.Settings.FskPacketHandler.Size - SX1276.Settings.FskPacketHandler.NbBytes ) > SX1276.Settings.FskPacketHandler.ChunkSize )
+ {
+ SX1276WriteFifo( ( RxTxBuffer + SX1276.Settings.FskPacketHandler.NbBytes ), SX1276.Settings.FskPacketHandler.ChunkSize );
+ SX1276.Settings.FskPacketHandler.NbBytes += SX1276.Settings.FskPacketHandler.ChunkSize;
+ }
+ else
+ {
+ // Write the last chunk of data
+ SX1276WriteFifo( RxTxBuffer + SX1276.Settings.FskPacketHandler.NbBytes, SX1276.Settings.FskPacketHandler.Size - SX1276.Settings.FskPacketHandler.NbBytes );
+ SX1276.Settings.FskPacketHandler.NbBytes += SX1276.Settings.FskPacketHandler.Size - SX1276.Settings.FskPacketHandler.NbBytes;
+ }
+ break;
+ case MODEM_LORA:
+ break;
+ default:
+ break;
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+void SX1276OnDio2Irq(void *unused)
+{
+ switch( SX1276.Settings.State )
+ {
+ case RF_RX_RUNNING:
+ switch( SX1276.Settings.Modem )
+ {
+ case MODEM_FSK:
+ if( ( SX1276.Settings.FskPacketHandler.PreambleDetected == true ) && ( SX1276.Settings.FskPacketHandler.SyncWordDetected == false ) )
+ {
+ os_cputime_timer_stop(&RxTimeoutSyncWord);
+
+ SX1276.Settings.FskPacketHandler.SyncWordDetected = true;
+
+ SX1276.Settings.FskPacketHandler.RssiValue = -( SX1276Read( REG_RSSIVALUE ) >> 1 );
+
+ SX1276.Settings.FskPacketHandler.AfcValue = ( int32_t )( double )( ( ( uint16_t )SX1276Read( REG_AFCMSB ) << 8 ) |
+ ( uint16_t )SX1276Read( REG_AFCLSB ) ) *
+ ( double )FREQ_STEP;
+ SX1276.Settings.FskPacketHandler.RxGain = ( SX1276Read( REG_LNA ) >> 5 ) & 0x07;
+ }
+ break;
+ case MODEM_LORA:
+ if( SX1276.Settings.LoRa.FreqHopOn == true )
+ {
+ // Clear Irq
+ SX1276Write( REG_LR_IRQFLAGS, RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL);
+
+ if( ( RadioEvents != NULL ) && ( RadioEvents->FhssChangeChannel != NULL ) )
+ {
+ RadioEvents->FhssChangeChannel( ( SX1276Read( REG_LR_HOPCHANNEL ) & RFLR_HOPCHANNEL_CHANNEL_MASK ) );
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ break;
+ case RF_TX_RUNNING:
+ switch( SX1276.Settings.Modem )
+ {
+ case MODEM_FSK:
+ break;
+ case MODEM_LORA:
+ if( SX1276.Settings.LoRa.FreqHopOn == true )
+ {
+ // Clear Irq
+ SX1276Write( REG_LR_IRQFLAGS, RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL);
+
+ if( ( RadioEvents != NULL ) && ( RadioEvents->FhssChangeChannel != NULL ) )
+ {
+ RadioEvents->FhssChangeChannel( ( SX1276Read( REG_LR_HOPCHANNEL ) & RFLR_HOPCHANNEL_CHANNEL_MASK ) );
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+void SX1276OnDio3Irq(void *unused)
+{
+ switch( SX1276.Settings.Modem )
+ {
+ case MODEM_FSK:
+ break;
+ case MODEM_LORA:
+ if( ( SX1276Read( REG_LR_IRQFLAGS ) & RFLR_IRQFLAGS_CADDETECTED ) == RFLR_IRQFLAGS_CADDETECTED )
+ {
+ // Clear Irq
+ SX1276Write( REG_LR_IRQFLAGS, RFLR_IRQFLAGS_CADDETECTED | RFLR_IRQFLAGS_CADDONE);
+ if( ( RadioEvents != NULL ) && ( RadioEvents->CadDone != NULL ) )
+ {
+ RadioEvents->CadDone( true );
+ }
+ }
+ else
+ {
+ // Clear Irq
+ SX1276Write( REG_LR_IRQFLAGS, RFLR_IRQFLAGS_CADDONE);
+ if( ( RadioEvents != NULL ) && ( RadioEvents->CadDone != NULL ) )
+ {
+ RadioEvents->CadDone( false );
+ }
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+void SX1276OnDio4Irq(void *unused)
+{
+ switch( SX1276.Settings.Modem )
+ {
+ case MODEM_FSK:
+ {
+ if( SX1276.Settings.FskPacketHandler.PreambleDetected == false )
+ {
+ SX1276.Settings.FskPacketHandler.PreambleDetected = true;
+ }
+ }
+ break;
+ case MODEM_LORA:
+ break;
+ default:
+ break;
+ }
+}
+
+void SX1276OnDio5Irq(void *unused)
+{
+ switch( SX1276.Settings.Modem )
+ {
+ case MODEM_FSK:
+ break;
+ case MODEM_LORA:
+ break;
+ default:
+ break;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9986f68c/hw/drivers/lora/node/radio/sx1276/src/sx1276.h
----------------------------------------------------------------------
diff --git a/hw/drivers/lora/node/radio/sx1276/src/sx1276.h b/hw/drivers/lora/node/radio/sx1276/src/sx1276.h
new file mode 100644
index 0000000..9c82652
--- /dev/null
+++ b/hw/drivers/lora/node/radio/sx1276/src/sx1276.h
@@ -0,0 +1,364 @@
+/*
+ / _____) _ | |
+( (____ _____ ____ _| |_ _____ ____| |__
+ \____ \| ___ | (_ _) ___ |/ ___) _ \
+ _____) ) ____| | | || |_| ____( (___| | | |
+(______/|_____)_|_|_| \__)_____)\____)_| |_|
+ (C)2013 Semtech
+
+Description: Generic SX1276 driver implementation
+
+License: Revised BSD License, see LICENSE.TXT file include in the project
+
+Maintainer: Miguel Luis and Gregory Cristian
+*/
+#ifndef __SX1276_H__
+#define __SX1276_H__
+#include <stdint.h>
+#include <stdbool.h>
+#include "node/radio.h"
+#include "sx1276Regs-Fsk.h"
+#include "sx1276Regs-LoRa.h"
+
+/*!
+ * Radio FSK modem parameters
+ */
+typedef struct
+{
+ int8_t Power;
+ uint32_t Fdev;
+ uint32_t Bandwidth;
+ uint32_t BandwidthAfc;
+ uint32_t Datarate;
+ uint16_t PreambleLen;
+ bool FixLen;
+ uint8_t PayloadLen;
+ bool CrcOn;
+ bool IqInverted;
+ bool RxContinuous;
+ uint32_t TxTimeout;
+}RadioFskSettings_t;
+
+/*!
+ * Radio FSK packet handler state
+ */
+typedef struct
+{
+ uint8_t PreambleDetected;
+ uint8_t SyncWordDetected;
+ int8_t RssiValue;
+ int32_t AfcValue;
+ uint8_t RxGain;
+ uint16_t Size;
+ uint16_t NbBytes;
+ uint8_t FifoThresh;
+ uint8_t ChunkSize;
+}RadioFskPacketHandler_t;
+
+/*!
+ * Radio LoRa modem parameters
+ */
+typedef struct
+{
+ int8_t Power;
+ uint32_t Bandwidth;
+ uint32_t Datarate;
+ bool LowDatarateOptimize;
+ uint8_t Coderate;
+ uint16_t PreambleLen;
+ bool FixLen;
+ uint8_t PayloadLen;
+ bool CrcOn;
+ bool FreqHopOn;
+ uint8_t HopPeriod;
+ bool IqInverted;
+ bool RxContinuous;
+ uint32_t TxTimeout;
+}RadioLoRaSettings_t;
+
+/*!
+ * Radio LoRa packet handler state
+ */
+typedef struct
+{
+ int8_t SnrValue;
+ int16_t RssiValue;
+ uint8_t Size;
+}RadioLoRaPacketHandler_t;
+
+/*!
+ * Radio Settings
+ */
+typedef struct
+{
+ RadioState_t State;
+ RadioModems_t Modem;
+ uint32_t Channel;
+ RadioFskSettings_t Fsk;
+ RadioFskPacketHandler_t FskPacketHandler;
+ RadioLoRaSettings_t LoRa;
+ RadioLoRaPacketHandler_t LoRaPacketHandler;
+}RadioSettings_t;
+
+/*!
+ * Radio hardware and global parameters
+ */
+typedef struct SX1276_s
+{
+ RadioSettings_t Settings;
+}SX1276_t;
+
+/*!
+ * Hardware IO IRQ callback function definition
+ */
+typedef void ( DioIrqHandler )(void *arg);
+
+/*!
+ * SX1276 definitions
+ */
+#define XTAL_FREQ 32000000
+#define FREQ_STEP 61.03515625
+
+#define RX_BUFFER_SIZE 256
+
+/*!
+ * ============================================================================
+ * Public functions prototypes
+ * ============================================================================
+ */
+
+/*!
+ * \brief Initializes the radio
+ *
+ * \param [IN] events Structure containing the driver callback functions
+ */
+void SX1276Init( RadioEvents_t *events );
+
+/*!
+ * Return current radio status
+ *
+ * \param status Radio status.[RF_IDLE, RF_RX_RUNNING, RF_TX_RUNNING]
+ */
+RadioState_t SX1276GetStatus( void );
+
+/*!
+ * \brief Configures the radio with the given modem
+ *
+ * \param [IN] modem Modem to be used [0: FSK, 1: LoRa]
+ */
+void SX1276SetModem( RadioModems_t modem );
+
+/*!
+ * \brief Sets the channels configuration
+ *
+ * \param [IN] freq Channel RF frequency
+ */
+void SX1276SetChannel( 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 SX1276IsChannelFree( 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 SX1276SetRxConfig or
+ * SX1276SetTxConfig functions must be called.
+ *
+ * \retval randomValue 32 bits random value
+ */
+uint32_t SX1276Random( void );
+
+/*!
+ * \brief Sets the reception parameters
+ *
+ * \remark When using LoRa modem only bandwidths 125, 250 and 500 kHz are supported
+ *
+ * \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 lenght 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 bewteen 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 SX1276SetRxConfig( 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
+ *
+ * \remark When using LoRa modem only bandwidths 125, 250 and 500 kHz are supported
+ *
+ * \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 bewteen 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 SX1276SetTxConfig( 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 Computes the packet time on air in us 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 (us) for the given packet payload length
+ */
+uint32_t SX1276GetTimeOnAir( 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 SX1276Send( uint8_t *buffer, uint8_t size );
+
+/*!
+ * \brief Sets the radio in sleep mode
+ */
+void SX1276SetSleep( void );
+
+/*!
+ * \brief Sets the radio in standby mode
+ */
+void SX1276SetStby( void );
+
+/*!
+ * \brief Sets the radio in reception mode for the given time
+ * \param [IN] timeout Reception timeout [ms] [0: continuous, others timeout]
+ */
+void SX1276SetRx( uint32_t timeout );
+
+/*!
+ * \brief Start a Channel Activity Detection
+ */
+void SX1276StartCad( void );
+
+/*!
+ * \brief Reads the current RSSI value
+ *
+ * \retval rssiValue Current RSSI value in [dBm]
+ */
+int16_t SX1276ReadRssi( RadioModems_t modem );
+
+/*!
+ * \brief Writes the radio register at the specified address
+ *
+ * \param [IN]: addr Register address
+ * \param [IN]: data New register value
+ */
+void SX1276Write( 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 SX1276Read( 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 SX1276WriteBuffer( 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 SX1276ReadBuffer( 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 SX1276SetMaxPayloadLength( RadioModems_t modem, uint8_t max );
+
+#endif // __SX1276_H__
[04/40] incubator-mynewt-core git commit: fix: cbor decode error when
keys have sub strings
Posted by ja...@apache.org.
fix: cbor decode error when keys have sub strings
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/551c0a66
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/551c0a66
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/551c0a66
Branch: refs/heads/bluetooth5
Commit: 551c0a66ed86e01ea745dac839e52056094fc9b6
Parents: eb4f289
Author: wesley <we...@wolinke.com>
Authored: Fri Apr 28 13:09:07 2017 +0800
Committer: wesley <we...@wolinke.com>
Committed: Fri Apr 28 13:09:07 2017 +0800
----------------------------------------------------------------------
encoding/cborattr/src/cborattr.c | 3 +-
encoding/cborattr/test/src/test_cborattr.c | 1 +
encoding/cborattr/test/src/test_cborattr.h | 1 +
.../testcases/cborattr_decode_substring_key.c | 111 +++++++++++++++++++
4 files changed, 115 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/551c0a66/encoding/cborattr/src/cborattr.c
----------------------------------------------------------------------
diff --git a/encoding/cborattr/src/cborattr.c b/encoding/cborattr/src/cborattr.c
index d2e731a..6f6912e 100644
--- a/encoding/cborattr/src/cborattr.c
+++ b/encoding/cborattr/src/cborattr.c
@@ -219,7 +219,8 @@ cbor_internal_read_object(CborValue *root_value,
if (cursor->attribute == CBORATTR_ATTR_UNNAMED &&
attrbuf[0] == '\0') {
best_match = cursor;
- } else if (!memcmp(cursor->attribute, attrbuf, len)) {
+ } else if (strlen(cursor->attribute) == len &&
+ !memcmp(cursor->attribute, attrbuf, len)) {
break;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/551c0a66/encoding/cborattr/test/src/test_cborattr.c
----------------------------------------------------------------------
diff --git a/encoding/cborattr/test/src/test_cborattr.c b/encoding/cborattr/test/src/test_cborattr.c
index 8125660..15a892a 100644
--- a/encoding/cborattr/test/src/test_cborattr.c
+++ b/encoding/cborattr/test/src/test_cborattr.c
@@ -32,6 +32,7 @@ TEST_SUITE(test_cborattr_suite)
test_cborattr_decode_string_array();
test_cborattr_decode_object_array();
test_cborattr_decode_unnamed_array();
+ test_cborattr_decode_substring_key();
}
#if MYNEWT_VAL(SELFTEST)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/551c0a66/encoding/cborattr/test/src/test_cborattr.h
----------------------------------------------------------------------
diff --git a/encoding/cborattr/test/src/test_cborattr.h b/encoding/cborattr/test/src/test_cborattr.h
index 1a5757b..2ffe515 100644
--- a/encoding/cborattr/test/src/test_cborattr.h
+++ b/encoding/cborattr/test/src/test_cborattr.h
@@ -47,6 +47,7 @@ TEST_CASE_DECL(test_cborattr_decode_bool_array);
TEST_CASE_DECL(test_cborattr_decode_string_array);
TEST_CASE_DECL(test_cborattr_decode_object_array);
TEST_CASE_DECL(test_cborattr_decode_unnamed_array);
+TEST_CASE_DECL(test_cborattr_decode_substring_key);
#ifdef __cplusplus
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/551c0a66/encoding/cborattr/test/src/testcases/cborattr_decode_substring_key.c
----------------------------------------------------------------------
diff --git a/encoding/cborattr/test/src/testcases/cborattr_decode_substring_key.c b/encoding/cborattr/test/src/testcases/cborattr_decode_substring_key.c
new file mode 100644
index 0000000..6eee774
--- /dev/null
+++ b/encoding/cborattr/test/src/testcases/cborattr_decode_substring_key.c
@@ -0,0 +1,111 @@
+/*
+ * 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.
+ */
+#include "test_cborattr.h"
+
+/*
+ * Where we collect cbor data.
+ */
+static uint8_t test_cbor_buf[1024];
+static int test_cbor_len;
+
+/*
+ * CBOR encoder data structures.
+ */
+static int test_cbor_wr(struct cbor_encoder_writer *, const char *, int);
+static CborEncoder test_encoder;
+static struct cbor_encoder_writer test_writer = {
+ .write = test_cbor_wr
+};
+
+static int
+test_cbor_wr(struct cbor_encoder_writer *cew, const char *data, int len)
+{
+ memcpy(test_cbor_buf + test_cbor_len, data, len);
+ test_cbor_len += len;
+
+ assert(test_cbor_len < sizeof(test_cbor_buf));
+ return 0;
+}
+
+static void
+test_encode_substring_key(void)
+{
+ CborEncoder data;
+
+ cbor_encoder_init(&test_encoder, &test_writer, 0);
+
+ /*
+ * { "a": "A", "aa": "AA", "aaa" : "AAA" }
+ */
+ cbor_encoder_create_map(&test_encoder, &data, CborIndefiniteLength);
+
+ cbor_encode_text_stringz(&data, "a");
+ cbor_encode_text_stringz(&data, "A");
+ cbor_encode_text_stringz(&data, "aa");
+ cbor_encode_text_stringz(&data, "AA");
+ cbor_encode_text_stringz(&data, "aaa");
+ cbor_encode_text_stringz(&data, "AAA");
+
+ cbor_encoder_close_container(&test_encoder, &data);
+}
+
+/*
+ * substring key
+ */
+TEST_CASE(test_cborattr_decode_substring_key)
+{
+ int rc;
+ char test_str_1a[4] = { '\0' };
+ char test_str_2a[4] = { '\0' };
+ char test_str_3a[4] = { '\0' };
+ struct cbor_attr_t test_attrs[] = {
+ [0] = {
+ .attribute = "aaa",
+ .type = CborAttrTextStringType,
+ .addr.string = test_str_3a,
+ .len = sizeof(test_str_3a),
+ .nodefault = true
+ },
+ [1] = {
+ .attribute = "aa",
+ .type = CborAttrTextStringType,
+ .addr.string = test_str_2a,
+ .len = sizeof(test_str_2a),
+ .nodefault = true
+ },
+ [2] = {
+ .attribute = "a",
+ .type = CborAttrTextStringType,
+ .addr.string = test_str_1a,
+ .len = sizeof(test_str_1a),
+ .nodefault = true
+ },
+ [3] = {
+ .attribute = NULL
+ }
+ };
+
+ test_encode_substring_key();
+
+ rc = cbor_read_flat_attrs(test_cbor_buf, test_cbor_len, test_attrs);
+ TEST_ASSERT(rc == 0);
+ TEST_ASSERT(!strcmp(test_str_1a, "A"));
+ TEST_ASSERT(!strcmp(test_str_2a, "AA"));
+ TEST_ASSERT(!strcmp(test_str_3a, "AAA"));
+}
[30/40] incubator-mynewt-core git commit: lorashell;
Enable LORA_NODE_CLI by default.
Posted by ja...@apache.org.
lorashell; Enable LORA_NODE_CLI by default.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/b022ac7c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/b022ac7c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/b022ac7c
Branch: refs/heads/bluetooth5
Commit: b022ac7c08ec7f570dd5216847291adf723983fc
Parents: ae4596c
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed May 3 11:17:27 2017 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed May 3 11:17:27 2017 -0700
----------------------------------------------------------------------
apps/lorashell/syscfg.yml | 1 +
1 file changed, 1 insertion(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b022ac7c/apps/lorashell/syscfg.yml
----------------------------------------------------------------------
diff --git a/apps/lorashell/syscfg.yml b/apps/lorashell/syscfg.yml
index 19b0bf6..a3953d0 100644
--- a/apps/lorashell/syscfg.yml
+++ b/apps/lorashell/syscfg.yml
@@ -26,3 +26,4 @@ syscfg.vals:
STATS_CLI: 1
STATS_NAMES: 1
SHELL_TASK: 1
+ LORA_NODE_CLI: 1
[08/40] incubator-mynewt-core git commit: MYNEWT-741 Port of
LoRaMac-node library
Posted by ja...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/560fa920/hw/drivers/lora/sx1276/src/sx1276Regs-Fsk.h
----------------------------------------------------------------------
diff --git a/hw/drivers/lora/sx1276/src/sx1276Regs-Fsk.h b/hw/drivers/lora/sx1276/src/sx1276Regs-Fsk.h
new file mode 100644
index 0000000..5bdd895
--- /dev/null
+++ b/hw/drivers/lora/sx1276/src/sx1276Regs-Fsk.h
@@ -0,0 +1,1134 @@
+/*
+ / _____) _ | |
+( (____ _____ ____ _| |_ _____ ____| |__
+ \____ \| ___ | (_ _) ___ |/ ___) _ \
+ _____) ) ____| | | || |_| ____( (___| | | |
+(______/|_____)_|_|_| \__)_____)\____)_| |_|
+ (C)2013 Semtech
+
+Description: SX1276 FSK modem registers and bits definitions
+
+License: Revised BSD License, see LICENSE.TXT file include in the project
+
+Maintainer: Miguel Luis and Gregory Cristian
+*/
+#ifndef __SX1276_REGS_FSK_H__
+#define __SX1276_REGS_FSK_H__
+
+/*!
+ * ============================================================================
+ * SX1276 Internal registers Address
+ * ============================================================================
+ */
+#define REG_FIFO 0x00
+// Common settings
+#define REG_OPMODE 0x01
+#define REG_BITRATEMSB 0x02
+#define REG_BITRATELSB 0x03
+#define REG_FDEVMSB 0x04
+#define REG_FDEVLSB 0x05
+#define REG_FRFMSB 0x06
+#define REG_FRFMID 0x07
+#define REG_FRFLSB 0x08
+// Tx settings
+#define REG_PACONFIG 0x09
+#define REG_PARAMP 0x0A
+#define REG_OCP 0x0B
+// Rx settings
+#define REG_LNA 0x0C
+#define REG_RXCONFIG 0x0D
+#define REG_RSSICONFIG 0x0E
+#define REG_RSSICOLLISION 0x0F
+#define REG_RSSITHRESH 0x10
+#define REG_RSSIVALUE 0x11
+#define REG_RXBW 0x12
+#define REG_AFCBW 0x13
+#define REG_OOKPEAK 0x14
+#define REG_OOKFIX 0x15
+#define REG_OOKAVG 0x16
+#define REG_RES17 0x17
+#define REG_RES18 0x18
+#define REG_RES19 0x19
+#define REG_AFCFEI 0x1A
+#define REG_AFCMSB 0x1B
+#define REG_AFCLSB 0x1C
+#define REG_FEIMSB 0x1D
+#define REG_FEILSB 0x1E
+#define REG_PREAMBLEDETECT 0x1F
+#define REG_RXTIMEOUT1 0x20
+#define REG_RXTIMEOUT2 0x21
+#define REG_RXTIMEOUT3 0x22
+#define REG_RXDELAY 0x23
+// Oscillator settings
+#define REG_OSC 0x24
+// Packet handler settings
+#define REG_PREAMBLEMSB 0x25
+#define REG_PREAMBLELSB 0x26
+#define REG_SYNCCONFIG 0x27
+#define REG_SYNCVALUE1 0x28
+#define REG_SYNCVALUE2 0x29
+#define REG_SYNCVALUE3 0x2A
+#define REG_SYNCVALUE4 0x2B
+#define REG_SYNCVALUE5 0x2C
+#define REG_SYNCVALUE6 0x2D
+#define REG_SYNCVALUE7 0x2E
+#define REG_SYNCVALUE8 0x2F
+#define REG_PACKETCONFIG1 0x30
+#define REG_PACKETCONFIG2 0x31
+#define REG_PAYLOADLENGTH 0x32
+#define REG_NODEADRS 0x33
+#define REG_BROADCASTADRS 0x34
+#define REG_FIFOTHRESH 0x35
+// SM settings
+#define REG_SEQCONFIG1 0x36
+#define REG_SEQCONFIG2 0x37
+#define REG_TIMERRESOL 0x38
+#define REG_TIMER1COEF 0x39
+#define REG_TIMER2COEF 0x3A
+// Service settings
+#define REG_IMAGECAL 0x3B
+#define REG_TEMP 0x3C
+#define REG_LOWBAT 0x3D
+// Status
+#define REG_IRQFLAGS1 0x3E
+#define REG_IRQFLAGS2 0x3F
+// I/O settings
+#define REG_DIOMAPPING1 0x40
+#define REG_DIOMAPPING2 0x41
+// Version
+#define REG_VERSION 0x42
+// Additional settings
+#define REG_PLLHOP 0x44
+#define REG_TCXO 0x4B
+#define REG_PADAC 0x4D
+#define REG_FORMERTEMP 0x5B
+#define REG_BITRATEFRAC 0x5D
+#define REG_AGCREF 0x61
+#define REG_AGCTHRESH1 0x62
+#define REG_AGCTHRESH2 0x63
+#define REG_AGCTHRESH3 0x64
+#define REG_PLL 0x70
+
+/*!
+ * ============================================================================
+ * SX1276 FSK bits control definition
+ * ============================================================================
+ */
+
+/*!
+ * RegFifo
+ */
+
+/*!
+ * RegOpMode
+ */
+#define RF_OPMODE_LONGRANGEMODE_MASK 0x7F
+#define RF_OPMODE_LONGRANGEMODE_OFF 0x00
+#define RF_OPMODE_LONGRANGEMODE_ON 0x80
+
+#define RF_OPMODE_MODULATIONTYPE_MASK 0x9F
+#define RF_OPMODE_MODULATIONTYPE_FSK 0x00 // Default
+#define RF_OPMODE_MODULATIONTYPE_OOK 0x20
+
+#define RF_OPMODE_MODULATIONSHAPING_MASK 0xE7
+#define RF_OPMODE_MODULATIONSHAPING_00 0x00 // Default
+#define RF_OPMODE_MODULATIONSHAPING_01 0x08
+#define RF_OPMODE_MODULATIONSHAPING_10 0x10
+#define RF_OPMODE_MODULATIONSHAPING_11 0x18
+
+#define RF_OPMODE_MASK 0xF8
+#define RF_OPMODE_SLEEP 0x00
+#define RF_OPMODE_STANDBY 0x01 // Default
+#define RF_OPMODE_SYNTHESIZER_TX 0x02
+#define RF_OPMODE_TRANSMITTER 0x03
+#define RF_OPMODE_SYNTHESIZER_RX 0x04
+#define RF_OPMODE_RECEIVER 0x05
+
+/*!
+ * RegBitRate (bits/sec)
+ */
+#define RF_BITRATEMSB_1200_BPS 0x68
+#define RF_BITRATELSB_1200_BPS 0x2B
+#define RF_BITRATEMSB_2400_BPS 0x34
+#define RF_BITRATELSB_2400_BPS 0x15
+#define RF_BITRATEMSB_4800_BPS 0x1A // Default
+#define RF_BITRATELSB_4800_BPS 0x0B // Default
+#define RF_BITRATEMSB_9600_BPS 0x0D
+#define RF_BITRATELSB_9600_BPS 0x05
+#define RF_BITRATEMSB_15000_BPS 0x08
+#define RF_BITRATELSB_15000_BPS 0x55
+#define RF_BITRATEMSB_19200_BPS 0x06
+#define RF_BITRATELSB_19200_BPS 0x83
+#define RF_BITRATEMSB_38400_BPS 0x03
+#define RF_BITRATELSB_38400_BPS 0x41
+#define RF_BITRATEMSB_76800_BPS 0x01
+#define RF_BITRATELSB_76800_BPS 0xA1
+#define RF_BITRATEMSB_153600_BPS 0x00
+#define RF_BITRATELSB_153600_BPS 0xD0
+#define RF_BITRATEMSB_57600_BPS 0x02
+#define RF_BITRATELSB_57600_BPS 0x2C
+#define RF_BITRATEMSB_115200_BPS 0x01
+#define RF_BITRATELSB_115200_BPS 0x16
+#define RF_BITRATEMSB_12500_BPS 0x0A
+#define RF_BITRATELSB_12500_BPS 0x00
+#define RF_BITRATEMSB_25000_BPS 0x05
+#define RF_BITRATELSB_25000_BPS 0x00
+#define RF_BITRATEMSB_50000_BPS 0x02
+#define RF_BITRATELSB_50000_BPS 0x80
+#define RF_BITRATEMSB_100000_BPS 0x01
+#define RF_BITRATELSB_100000_BPS 0x40
+#define RF_BITRATEMSB_150000_BPS 0x00
+#define RF_BITRATELSB_150000_BPS 0xD5
+#define RF_BITRATEMSB_200000_BPS 0x00
+#define RF_BITRATELSB_200000_BPS 0xA0
+#define RF_BITRATEMSB_250000_BPS 0x00
+#define RF_BITRATELSB_250000_BPS 0x80
+#define RF_BITRATEMSB_32768_BPS 0x03
+#define RF_BITRATELSB_32768_BPS 0xD1
+
+/*!
+ * RegFdev (Hz)
+ */
+#define RF_FDEVMSB_2000_HZ 0x00
+#define RF_FDEVLSB_2000_HZ 0x21
+#define RF_FDEVMSB_5000_HZ 0x00 // Default
+#define RF_FDEVLSB_5000_HZ 0x52 // Default
+#define RF_FDEVMSB_10000_HZ 0x00
+#define RF_FDEVLSB_10000_HZ 0xA4
+#define RF_FDEVMSB_15000_HZ 0x00
+#define RF_FDEVLSB_15000_HZ 0xF6
+#define RF_FDEVMSB_20000_HZ 0x01
+#define RF_FDEVLSB_20000_HZ 0x48
+#define RF_FDEVMSB_25000_HZ 0x01
+#define RF_FDEVLSB_25000_HZ 0x9A
+#define RF_FDEVMSB_30000_HZ 0x01
+#define RF_FDEVLSB_30000_HZ 0xEC
+#define RF_FDEVMSB_35000_HZ 0x02
+#define RF_FDEVLSB_35000_HZ 0x3D
+#define RF_FDEVMSB_40000_HZ 0x02
+#define RF_FDEVLSB_40000_HZ 0x8F
+#define RF_FDEVMSB_45000_HZ 0x02
+#define RF_FDEVLSB_45000_HZ 0xE1
+#define RF_FDEVMSB_50000_HZ 0x03
+#define RF_FDEVLSB_50000_HZ 0x33
+#define RF_FDEVMSB_55000_HZ 0x03
+#define RF_FDEVLSB_55000_HZ 0x85
+#define RF_FDEVMSB_60000_HZ 0x03
+#define RF_FDEVLSB_60000_HZ 0xD7
+#define RF_FDEVMSB_65000_HZ 0x04
+#define RF_FDEVLSB_65000_HZ 0x29
+#define RF_FDEVMSB_70000_HZ 0x04
+#define RF_FDEVLSB_70000_HZ 0x7B
+#define RF_FDEVMSB_75000_HZ 0x04
+#define RF_FDEVLSB_75000_HZ 0xCD
+#define RF_FDEVMSB_80000_HZ 0x05
+#define RF_FDEVLSB_80000_HZ 0x1F
+#define RF_FDEVMSB_85000_HZ 0x05
+#define RF_FDEVLSB_85000_HZ 0x71
+#define RF_FDEVMSB_90000_HZ 0x05
+#define RF_FDEVLSB_90000_HZ 0xC3
+#define RF_FDEVMSB_95000_HZ 0x06
+#define RF_FDEVLSB_95000_HZ 0x14
+#define RF_FDEVMSB_100000_HZ 0x06
+#define RF_FDEVLSB_100000_HZ 0x66
+#define RF_FDEVMSB_110000_HZ 0x07
+#define RF_FDEVLSB_110000_HZ 0x0A
+#define RF_FDEVMSB_120000_HZ 0x07
+#define RF_FDEVLSB_120000_HZ 0xAE
+#define RF_FDEVMSB_130000_HZ 0x08
+#define RF_FDEVLSB_130000_HZ 0x52
+#define RF_FDEVMSB_140000_HZ 0x08
+#define RF_FDEVLSB_140000_HZ 0xF6
+#define RF_FDEVMSB_150000_HZ 0x09
+#define RF_FDEVLSB_150000_HZ 0x9A
+#define RF_FDEVMSB_160000_HZ 0x0A
+#define RF_FDEVLSB_160000_HZ 0x3D
+#define RF_FDEVMSB_170000_HZ 0x0A
+#define RF_FDEVLSB_170000_HZ 0xE1
+#define RF_FDEVMSB_180000_HZ 0x0B
+#define RF_FDEVLSB_180000_HZ 0x85
+#define RF_FDEVMSB_190000_HZ 0x0C
+#define RF_FDEVLSB_190000_HZ 0x29
+#define RF_FDEVMSB_200000_HZ 0x0C
+#define RF_FDEVLSB_200000_HZ 0xCD
+
+/*!
+ * RegFrf (MHz)
+ */
+#define RF_FRFMSB_863_MHZ 0xD7
+#define RF_FRFMID_863_MHZ 0xC0
+#define RF_FRFLSB_863_MHZ 0x00
+#define RF_FRFMSB_864_MHZ 0xD8
+#define RF_FRFMID_864_MHZ 0x00
+#define RF_FRFLSB_864_MHZ 0x00
+#define RF_FRFMSB_865_MHZ 0xD8
+#define RF_FRFMID_865_MHZ 0x40
+#define RF_FRFLSB_865_MHZ 0x00
+#define RF_FRFMSB_866_MHZ 0xD8
+#define RF_FRFMID_866_MHZ 0x80
+#define RF_FRFLSB_866_MHZ 0x00
+#define RF_FRFMSB_867_MHZ 0xD8
+#define RF_FRFMID_867_MHZ 0xC0
+#define RF_FRFLSB_867_MHZ 0x00
+#define RF_FRFMSB_868_MHZ 0xD9
+#define RF_FRFMID_868_MHZ 0x00
+#define RF_FRFLSB_868_MHZ 0x00
+#define RF_FRFMSB_869_MHZ 0xD9
+#define RF_FRFMID_869_MHZ 0x40
+#define RF_FRFLSB_869_MHZ 0x00
+#define RF_FRFMSB_870_MHZ 0xD9
+#define RF_FRFMID_870_MHZ 0x80
+#define RF_FRFLSB_870_MHZ 0x00
+
+#define RF_FRFMSB_902_MHZ 0xE1
+#define RF_FRFMID_902_MHZ 0x80
+#define RF_FRFLSB_902_MHZ 0x00
+#define RF_FRFMSB_903_MHZ 0xE1
+#define RF_FRFMID_903_MHZ 0xC0
+#define RF_FRFLSB_903_MHZ 0x00
+#define RF_FRFMSB_904_MHZ 0xE2
+#define RF_FRFMID_904_MHZ 0x00
+#define RF_FRFLSB_904_MHZ 0x00
+#define RF_FRFMSB_905_MHZ 0xE2
+#define RF_FRFMID_905_MHZ 0x40
+#define RF_FRFLSB_905_MHZ 0x00
+#define RF_FRFMSB_906_MHZ 0xE2
+#define RF_FRFMID_906_MHZ 0x80
+#define RF_FRFLSB_906_MHZ 0x00
+#define RF_FRFMSB_907_MHZ 0xE2
+#define RF_FRFMID_907_MHZ 0xC0
+#define RF_FRFLSB_907_MHZ 0x00
+#define RF_FRFMSB_908_MHZ 0xE3
+#define RF_FRFMID_908_MHZ 0x00
+#define RF_FRFLSB_908_MHZ 0x00
+#define RF_FRFMSB_909_MHZ 0xE3
+#define RF_FRFMID_909_MHZ 0x40
+#define RF_FRFLSB_909_MHZ 0x00
+#define RF_FRFMSB_910_MHZ 0xE3
+#define RF_FRFMID_910_MHZ 0x80
+#define RF_FRFLSB_910_MHZ 0x00
+#define RF_FRFMSB_911_MHZ 0xE3
+#define RF_FRFMID_911_MHZ 0xC0
+#define RF_FRFLSB_911_MHZ 0x00
+#define RF_FRFMSB_912_MHZ 0xE4
+#define RF_FRFMID_912_MHZ 0x00
+#define RF_FRFLSB_912_MHZ 0x00
+#define RF_FRFMSB_913_MHZ 0xE4
+#define RF_FRFMID_913_MHZ 0x40
+#define RF_FRFLSB_913_MHZ 0x00
+#define RF_FRFMSB_914_MHZ 0xE4
+#define RF_FRFMID_914_MHZ 0x80
+#define RF_FRFLSB_914_MHZ 0x00
+#define RF_FRFMSB_915_MHZ 0xE4 // Default
+#define RF_FRFMID_915_MHZ 0xC0 // Default
+#define RF_FRFLSB_915_MHZ 0x00 // Default
+#define RF_FRFMSB_916_MHZ 0xE5
+#define RF_FRFMID_916_MHZ 0x00
+#define RF_FRFLSB_916_MHZ 0x00
+#define RF_FRFMSB_917_MHZ 0xE5
+#define RF_FRFMID_917_MHZ 0x40
+#define RF_FRFLSB_917_MHZ 0x00
+#define RF_FRFMSB_918_MHZ 0xE5
+#define RF_FRFMID_918_MHZ 0x80
+#define RF_FRFLSB_918_MHZ 0x00
+#define RF_FRFMSB_919_MHZ 0xE5
+#define RF_FRFMID_919_MHZ 0xC0
+#define RF_FRFLSB_919_MHZ 0x00
+#define RF_FRFMSB_920_MHZ 0xE6
+#define RF_FRFMID_920_MHZ 0x00
+#define RF_FRFLSB_920_MHZ 0x00
+#define RF_FRFMSB_921_MHZ 0xE6
+#define RF_FRFMID_921_MHZ 0x40
+#define RF_FRFLSB_921_MHZ 0x00
+#define RF_FRFMSB_922_MHZ 0xE6
+#define RF_FRFMID_922_MHZ 0x80
+#define RF_FRFLSB_922_MHZ 0x00
+#define RF_FRFMSB_923_MHZ 0xE6
+#define RF_FRFMID_923_MHZ 0xC0
+#define RF_FRFLSB_923_MHZ 0x00
+#define RF_FRFMSB_924_MHZ 0xE7
+#define RF_FRFMID_924_MHZ 0x00
+#define RF_FRFLSB_924_MHZ 0x00
+#define RF_FRFMSB_925_MHZ 0xE7
+#define RF_FRFMID_925_MHZ 0x40
+#define RF_FRFLSB_925_MHZ 0x00
+#define RF_FRFMSB_926_MHZ 0xE7
+#define RF_FRFMID_926_MHZ 0x80
+#define RF_FRFLSB_926_MHZ 0x00
+#define RF_FRFMSB_927_MHZ 0xE7
+#define RF_FRFMID_927_MHZ 0xC0
+#define RF_FRFLSB_927_MHZ 0x00
+#define RF_FRFMSB_928_MHZ 0xE8
+#define RF_FRFMID_928_MHZ 0x00
+#define RF_FRFLSB_928_MHZ 0x00
+
+/*!
+ * RegPaConfig
+ */
+#define RF_PACONFIG_PASELECT_MASK 0x7F
+#define RF_PACONFIG_PASELECT_PABOOST 0x80
+#define RF_PACONFIG_PASELECT_RFO 0x00 // Default
+
+#define RF_PACONFIG_MAX_POWER_MASK 0x8F
+
+#define RF_PACONFIG_OUTPUTPOWER_MASK 0xF0
+
+/*!
+ * RegPaRamp
+ */
+#define RF_PARAMP_MODULATIONSHAPING_MASK 0x9F
+#define RF_PARAMP_MODULATIONSHAPING_00 0x00 // Default
+#define RF_PARAMP_MODULATIONSHAPING_01 0x20
+#define RF_PARAMP_MODULATIONSHAPING_10 0x40
+#define RF_PARAMP_MODULATIONSHAPING_11 0x60
+
+#define RF_PARAMP_LOWPNTXPLL_MASK 0xEF
+#define RF_PARAMP_LOWPNTXPLL_OFF 0x10
+#define RF_PARAMP_LOWPNTXPLL_ON 0x00 // Default
+
+#define RF_PARAMP_MASK 0xF0
+#define RF_PARAMP_3400_US 0x00
+#define RF_PARAMP_2000_US 0x01
+#define RF_PARAMP_1000_US 0x02
+#define RF_PARAMP_0500_US 0x03
+#define RF_PARAMP_0250_US 0x04
+#define RF_PARAMP_0125_US 0x05
+#define RF_PARAMP_0100_US 0x06
+#define RF_PARAMP_0062_US 0x07
+#define RF_PARAMP_0050_US 0x08
+#define RF_PARAMP_0040_US 0x09 // Default
+#define RF_PARAMP_0031_US 0x0A
+#define RF_PARAMP_0025_US 0x0B
+#define RF_PARAMP_0020_US 0x0C
+#define RF_PARAMP_0015_US 0x0D
+#define RF_PARAMP_0012_US 0x0E
+#define RF_PARAMP_0010_US 0x0F
+
+/*!
+ * RegOcp
+ */
+#define RF_OCP_MASK 0xDF
+#define RF_OCP_ON 0x20 // Default
+#define RF_OCP_OFF 0x00
+
+#define RF_OCP_TRIM_MASK 0xE0
+#define RF_OCP_TRIM_045_MA 0x00
+#define RF_OCP_TRIM_050_MA 0x01
+#define RF_OCP_TRIM_055_MA 0x02
+#define RF_OCP_TRIM_060_MA 0x03
+#define RF_OCP_TRIM_065_MA 0x04
+#define RF_OCP_TRIM_070_MA 0x05
+#define RF_OCP_TRIM_075_MA 0x06
+#define RF_OCP_TRIM_080_MA 0x07
+#define RF_OCP_TRIM_085_MA 0x08
+#define RF_OCP_TRIM_090_MA 0x09
+#define RF_OCP_TRIM_095_MA 0x0A
+#define RF_OCP_TRIM_100_MA 0x0B // Default
+#define RF_OCP_TRIM_105_MA 0x0C
+#define RF_OCP_TRIM_110_MA 0x0D
+#define RF_OCP_TRIM_115_MA 0x0E
+#define RF_OCP_TRIM_120_MA 0x0F
+#define RF_OCP_TRIM_130_MA 0x10
+#define RF_OCP_TRIM_140_MA 0x11
+#define RF_OCP_TRIM_150_MA 0x12
+#define RF_OCP_TRIM_160_MA 0x13
+#define RF_OCP_TRIM_170_MA 0x14
+#define RF_OCP_TRIM_180_MA 0x15
+#define RF_OCP_TRIM_190_MA 0x16
+#define RF_OCP_TRIM_200_MA 0x17
+#define RF_OCP_TRIM_210_MA 0x18
+#define RF_OCP_TRIM_220_MA 0x19
+#define RF_OCP_TRIM_230_MA 0x1A
+#define RF_OCP_TRIM_240_MA 0x1B
+
+/*!
+ * RegLna
+ */
+#define RF_LNA_GAIN_MASK 0x1F
+#define RF_LNA_GAIN_G1 0x20 // Default
+#define RF_LNA_GAIN_G2 0x40
+#define RF_LNA_GAIN_G3 0x60
+#define RF_LNA_GAIN_G4 0x80
+#define RF_LNA_GAIN_G5 0xA0
+#define RF_LNA_GAIN_G6 0xC0
+
+#define RF_LNA_BOOST_MASK 0xFC
+#define RF_LNA_BOOST_OFF 0x00 // Default
+#define RF_LNA_BOOST_ON 0x03
+
+/*!
+ * RegRxConfig
+ */
+#define RF_RXCONFIG_RESTARTRXONCOLLISION_MASK 0x7F
+#define RF_RXCONFIG_RESTARTRXONCOLLISION_ON 0x80
+#define RF_RXCONFIG_RESTARTRXONCOLLISION_OFF 0x00 // Default
+
+#define RF_RXCONFIG_RESTARTRXWITHOUTPLLLOCK 0x40 // Write only
+
+#define RF_RXCONFIG_RESTARTRXWITHPLLLOCK 0x20 // Write only
+
+#define RF_RXCONFIG_AFCAUTO_MASK 0xEF
+#define RF_RXCONFIG_AFCAUTO_ON 0x10
+#define RF_RXCONFIG_AFCAUTO_OFF 0x00 // Default
+
+#define RF_RXCONFIG_AGCAUTO_MASK 0xF7
+#define RF_RXCONFIG_AGCAUTO_ON 0x08 // Default
+#define RF_RXCONFIG_AGCAUTO_OFF 0x00
+
+#define RF_RXCONFIG_RXTRIGER_MASK 0xF8
+#define RF_RXCONFIG_RXTRIGER_OFF 0x00
+#define RF_RXCONFIG_RXTRIGER_RSSI 0x01
+#define RF_RXCONFIG_RXTRIGER_PREAMBLEDETECT 0x06 // Default
+#define RF_RXCONFIG_RXTRIGER_RSSI_PREAMBLEDETECT 0x07
+
+/*!
+ * RegRssiConfig
+ */
+#define RF_RSSICONFIG_OFFSET_MASK 0x07
+#define RF_RSSICONFIG_OFFSET_P_00_DB 0x00 // Default
+#define RF_RSSICONFIG_OFFSET_P_01_DB 0x08
+#define RF_RSSICONFIG_OFFSET_P_02_DB 0x10
+#define RF_RSSICONFIG_OFFSET_P_03_DB 0x18
+#define RF_RSSICONFIG_OFFSET_P_04_DB 0x20
+#define RF_RSSICONFIG_OFFSET_P_05_DB 0x28
+#define RF_RSSICONFIG_OFFSET_P_06_DB 0x30
+#define RF_RSSICONFIG_OFFSET_P_07_DB 0x38
+#define RF_RSSICONFIG_OFFSET_P_08_DB 0x40
+#define RF_RSSICONFIG_OFFSET_P_09_DB 0x48
+#define RF_RSSICONFIG_OFFSET_P_10_DB 0x50
+#define RF_RSSICONFIG_OFFSET_P_11_DB 0x58
+#define RF_RSSICONFIG_OFFSET_P_12_DB 0x60
+#define RF_RSSICONFIG_OFFSET_P_13_DB 0x68
+#define RF_RSSICONFIG_OFFSET_P_14_DB 0x70
+#define RF_RSSICONFIG_OFFSET_P_15_DB 0x78
+#define RF_RSSICONFIG_OFFSET_M_16_DB 0x80
+#define RF_RSSICONFIG_OFFSET_M_15_DB 0x88
+#define RF_RSSICONFIG_OFFSET_M_14_DB 0x90
+#define RF_RSSICONFIG_OFFSET_M_13_DB 0x98
+#define RF_RSSICONFIG_OFFSET_M_12_DB 0xA0
+#define RF_RSSICONFIG_OFFSET_M_11_DB 0xA8
+#define RF_RSSICONFIG_OFFSET_M_10_DB 0xB0
+#define RF_RSSICONFIG_OFFSET_M_09_DB 0xB8
+#define RF_RSSICONFIG_OFFSET_M_08_DB 0xC0
+#define RF_RSSICONFIG_OFFSET_M_07_DB 0xC8
+#define RF_RSSICONFIG_OFFSET_M_06_DB 0xD0
+#define RF_RSSICONFIG_OFFSET_M_05_DB 0xD8
+#define RF_RSSICONFIG_OFFSET_M_04_DB 0xE0
+#define RF_RSSICONFIG_OFFSET_M_03_DB 0xE8
+#define RF_RSSICONFIG_OFFSET_M_02_DB 0xF0
+#define RF_RSSICONFIG_OFFSET_M_01_DB 0xF8
+
+#define RF_RSSICONFIG_SMOOTHING_MASK 0xF8
+#define RF_RSSICONFIG_SMOOTHING_2 0x00
+#define RF_RSSICONFIG_SMOOTHING_4 0x01
+#define RF_RSSICONFIG_SMOOTHING_8 0x02 // Default
+#define RF_RSSICONFIG_SMOOTHING_16 0x03
+#define RF_RSSICONFIG_SMOOTHING_32 0x04
+#define RF_RSSICONFIG_SMOOTHING_64 0x05
+#define RF_RSSICONFIG_SMOOTHING_128 0x06
+#define RF_RSSICONFIG_SMOOTHING_256 0x07
+
+/*!
+ * RegRssiCollision
+ */
+#define RF_RSSICOLISION_THRESHOLD 0x0A // Default
+
+/*!
+ * RegRssiThresh
+ */
+#define RF_RSSITHRESH_THRESHOLD 0xFF // Default
+
+/*!
+ * RegRssiValue (Read Only)
+ */
+
+/*!
+ * RegRxBw
+ */
+#define RF_RXBW_MANT_MASK 0xE7
+#define RF_RXBW_MANT_16 0x00
+#define RF_RXBW_MANT_20 0x08
+#define RF_RXBW_MANT_24 0x10 // Default
+
+#define RF_RXBW_EXP_MASK 0xF8
+#define RF_RXBW_EXP_0 0x00
+#define RF_RXBW_EXP_1 0x01
+#define RF_RXBW_EXP_2 0x02
+#define RF_RXBW_EXP_3 0x03
+#define RF_RXBW_EXP_4 0x04
+#define RF_RXBW_EXP_5 0x05 // Default
+#define RF_RXBW_EXP_6 0x06
+#define RF_RXBW_EXP_7 0x07
+
+/*!
+ * RegAfcBw
+ */
+#define RF_AFCBW_MANTAFC_MASK 0xE7
+#define RF_AFCBW_MANTAFC_16 0x00
+#define RF_AFCBW_MANTAFC_20 0x08 // Default
+#define RF_AFCBW_MANTAFC_24 0x10
+
+#define RF_AFCBW_EXPAFC_MASK 0xF8
+#define RF_AFCBW_EXPAFC_0 0x00
+#define RF_AFCBW_EXPAFC_1 0x01
+#define RF_AFCBW_EXPAFC_2 0x02
+#define RF_AFCBW_EXPAFC_3 0x03 // Default
+#define RF_AFCBW_EXPAFC_4 0x04
+#define RF_AFCBW_EXPAFC_5 0x05
+#define RF_AFCBW_EXPAFC_6 0x06
+#define RF_AFCBW_EXPAFC_7 0x07
+
+/*!
+ * RegOokPeak
+ */
+#define RF_OOKPEAK_BITSYNC_MASK 0xDF // Default
+#define RF_OOKPEAK_BITSYNC_ON 0x20 // Default
+#define RF_OOKPEAK_BITSYNC_OFF 0x00
+
+#define RF_OOKPEAK_OOKTHRESHTYPE_MASK 0xE7
+#define RF_OOKPEAK_OOKTHRESHTYPE_FIXED 0x00
+#define RF_OOKPEAK_OOKTHRESHTYPE_PEAK 0x08 // Default
+#define RF_OOKPEAK_OOKTHRESHTYPE_AVERAGE 0x10
+
+#define RF_OOKPEAK_OOKPEAKTHRESHSTEP_MASK 0xF8
+#define RF_OOKPEAK_OOKPEAKTHRESHSTEP_0_5_DB 0x00 // Default
+#define RF_OOKPEAK_OOKPEAKTHRESHSTEP_1_0_DB 0x01
+#define RF_OOKPEAK_OOKPEAKTHRESHSTEP_1_5_DB 0x02
+#define RF_OOKPEAK_OOKPEAKTHRESHSTEP_2_0_DB 0x03
+#define RF_OOKPEAK_OOKPEAKTHRESHSTEP_3_0_DB 0x04
+#define RF_OOKPEAK_OOKPEAKTHRESHSTEP_4_0_DB 0x05
+#define RF_OOKPEAK_OOKPEAKTHRESHSTEP_5_0_DB 0x06
+#define RF_OOKPEAK_OOKPEAKTHRESHSTEP_6_0_DB 0x07
+
+/*!
+ * RegOokFix
+ */
+#define RF_OOKFIX_OOKFIXEDTHRESHOLD 0x0C // Default
+
+/*!
+ * RegOokAvg
+ */
+#define RF_OOKAVG_OOKPEAKTHRESHDEC_MASK 0x1F
+#define RF_OOKAVG_OOKPEAKTHRESHDEC_000 0x00 // Default
+#define RF_OOKAVG_OOKPEAKTHRESHDEC_001 0x20
+#define RF_OOKAVG_OOKPEAKTHRESHDEC_010 0x40
+#define RF_OOKAVG_OOKPEAKTHRESHDEC_011 0x60
+#define RF_OOKAVG_OOKPEAKTHRESHDEC_100 0x80
+#define RF_OOKAVG_OOKPEAKTHRESHDEC_101 0xA0
+#define RF_OOKAVG_OOKPEAKTHRESHDEC_110 0xC0
+#define RF_OOKAVG_OOKPEAKTHRESHDEC_111 0xE0
+
+#define RF_OOKAVG_AVERAGEOFFSET_MASK 0xF3
+#define RF_OOKAVG_AVERAGEOFFSET_0_DB 0x00 // Default
+#define RF_OOKAVG_AVERAGEOFFSET_2_DB 0x04
+#define RF_OOKAVG_AVERAGEOFFSET_4_DB 0x08
+#define RF_OOKAVG_AVERAGEOFFSET_6_DB 0x0C
+
+#define RF_OOKAVG_OOKAVERAGETHRESHFILT_MASK 0xFC
+#define RF_OOKAVG_OOKAVERAGETHRESHFILT_00 0x00
+#define RF_OOKAVG_OOKAVERAGETHRESHFILT_01 0x01
+#define RF_OOKAVG_OOKAVERAGETHRESHFILT_10 0x02 // Default
+#define RF_OOKAVG_OOKAVERAGETHRESHFILT_11 0x03
+
+/*!
+ * RegAfcFei
+ */
+#define RF_AFCFEI_AGCSTART 0x10
+
+#define RF_AFCFEI_AFCCLEAR 0x02
+
+#define RF_AFCFEI_AFCAUTOCLEAR_MASK 0xFE
+#define RF_AFCFEI_AFCAUTOCLEAR_ON 0x01
+#define RF_AFCFEI_AFCAUTOCLEAR_OFF 0x00 // Default
+
+/*!
+ * RegAfcMsb (Read Only)
+ */
+
+/*!
+ * RegAfcLsb (Read Only)
+ */
+
+/*!
+ * RegFeiMsb (Read Only)
+ */
+
+/*!
+ * RegFeiLsb (Read Only)
+ */
+
+/*!
+ * RegPreambleDetect
+ */
+#define RF_PREAMBLEDETECT_DETECTOR_MASK 0x7F
+#define RF_PREAMBLEDETECT_DETECTOR_ON 0x80 // Default
+#define RF_PREAMBLEDETECT_DETECTOR_OFF 0x00
+
+#define RF_PREAMBLEDETECT_DETECTORSIZE_MASK 0x9F
+#define RF_PREAMBLEDETECT_DETECTORSIZE_1 0x00
+#define RF_PREAMBLEDETECT_DETECTORSIZE_2 0x20 // Default
+#define RF_PREAMBLEDETECT_DETECTORSIZE_3 0x40
+#define RF_PREAMBLEDETECT_DETECTORSIZE_4 0x60
+
+#define RF_PREAMBLEDETECT_DETECTORTOL_MASK 0xE0
+#define RF_PREAMBLEDETECT_DETECTORTOL_0 0x00
+#define RF_PREAMBLEDETECT_DETECTORTOL_1 0x01
+#define RF_PREAMBLEDETECT_DETECTORTOL_2 0x02
+#define RF_PREAMBLEDETECT_DETECTORTOL_3 0x03
+#define RF_PREAMBLEDETECT_DETECTORTOL_4 0x04
+#define RF_PREAMBLEDETECT_DETECTORTOL_5 0x05
+#define RF_PREAMBLEDETECT_DETECTORTOL_6 0x06
+#define RF_PREAMBLEDETECT_DETECTORTOL_7 0x07
+#define RF_PREAMBLEDETECT_DETECTORTOL_8 0x08
+#define RF_PREAMBLEDETECT_DETECTORTOL_9 0x09
+#define RF_PREAMBLEDETECT_DETECTORTOL_10 0x0A // Default
+#define RF_PREAMBLEDETECT_DETECTORTOL_11 0x0B
+#define RF_PREAMBLEDETECT_DETECTORTOL_12 0x0C
+#define RF_PREAMBLEDETECT_DETECTORTOL_13 0x0D
+#define RF_PREAMBLEDETECT_DETECTORTOL_14 0x0E
+#define RF_PREAMBLEDETECT_DETECTORTOL_15 0x0F
+#define RF_PREAMBLEDETECT_DETECTORTOL_16 0x10
+#define RF_PREAMBLEDETECT_DETECTORTOL_17 0x11
+#define RF_PREAMBLEDETECT_DETECTORTOL_18 0x12
+#define RF_PREAMBLEDETECT_DETECTORTOL_19 0x13
+#define RF_PREAMBLEDETECT_DETECTORTOL_20 0x14
+#define RF_PREAMBLEDETECT_DETECTORTOL_21 0x15
+#define RF_PREAMBLEDETECT_DETECTORTOL_22 0x16
+#define RF_PREAMBLEDETECT_DETECTORTOL_23 0x17
+#define RF_PREAMBLEDETECT_DETECTORTOL_24 0x18
+#define RF_PREAMBLEDETECT_DETECTORTOL_25 0x19
+#define RF_PREAMBLEDETECT_DETECTORTOL_26 0x1A
+#define RF_PREAMBLEDETECT_DETECTORTOL_27 0x1B
+#define RF_PREAMBLEDETECT_DETECTORTOL_28 0x1C
+#define RF_PREAMBLEDETECT_DETECTORTOL_29 0x1D
+#define RF_PREAMBLEDETECT_DETECTORTOL_30 0x1E
+#define RF_PREAMBLEDETECT_DETECTORTOL_31 0x1F
+
+/*!
+ * RegRxTimeout1
+ */
+#define RF_RXTIMEOUT1_TIMEOUTRXRSSI 0x00 // Default
+
+/*!
+ * RegRxTimeout2
+ */
+#define RF_RXTIMEOUT2_TIMEOUTRXPREAMBLE 0x00 // Default
+
+/*!
+ * RegRxTimeout3
+ */
+#define RF_RXTIMEOUT3_TIMEOUTSIGNALSYNC 0x00 // Default
+
+/*!
+ * RegRxDelay
+ */
+#define RF_RXDELAY_INTERPACKETRXDELAY 0x00 // Default
+
+/*!
+ * RegOsc
+ */
+#define RF_OSC_RCCALSTART 0x08
+
+#define RF_OSC_CLKOUT_MASK 0xF8
+#define RF_OSC_CLKOUT_32_MHZ 0x00
+#define RF_OSC_CLKOUT_16_MHZ 0x01
+#define RF_OSC_CLKOUT_8_MHZ 0x02
+#define RF_OSC_CLKOUT_4_MHZ 0x03
+#define RF_OSC_CLKOUT_2_MHZ 0x04
+#define RF_OSC_CLKOUT_1_MHZ 0x05 // Default
+#define RF_OSC_CLKOUT_RC 0x06
+#define RF_OSC_CLKOUT_OFF 0x07
+
+/*!
+ * RegPreambleMsb/RegPreambleLsb
+ */
+#define RF_PREAMBLEMSB_SIZE 0x00 // Default
+#define RF_PREAMBLELSB_SIZE 0x03 // Default
+
+/*!
+ * RegSyncConfig
+ */
+#define RF_SYNCCONFIG_AUTORESTARTRXMODE_MASK 0x3F
+#define RF_SYNCCONFIG_AUTORESTARTRXMODE_WAITPLL_ON 0x80 // Default
+#define RF_SYNCCONFIG_AUTORESTARTRXMODE_WAITPLL_OFF 0x40
+#define RF_SYNCCONFIG_AUTORESTARTRXMODE_OFF 0x00
+
+
+#define RF_SYNCCONFIG_PREAMBLEPOLARITY_MASK 0xDF
+#define RF_SYNCCONFIG_PREAMBLEPOLARITY_55 0x20
+#define RF_SYNCCONFIG_PREAMBLEPOLARITY_AA 0x00 // Default
+
+#define RF_SYNCCONFIG_SYNC_MASK 0xEF
+#define RF_SYNCCONFIG_SYNC_ON 0x10 // Default
+#define RF_SYNCCONFIG_SYNC_OFF 0x00
+
+
+#define RF_SYNCCONFIG_SYNCSIZE_MASK 0xF8
+#define RF_SYNCCONFIG_SYNCSIZE_1 0x00
+#define RF_SYNCCONFIG_SYNCSIZE_2 0x01
+#define RF_SYNCCONFIG_SYNCSIZE_3 0x02
+#define RF_SYNCCONFIG_SYNCSIZE_4 0x03 // Default
+#define RF_SYNCCONFIG_SYNCSIZE_5 0x04
+#define RF_SYNCCONFIG_SYNCSIZE_6 0x05
+#define RF_SYNCCONFIG_SYNCSIZE_7 0x06
+#define RF_SYNCCONFIG_SYNCSIZE_8 0x07
+
+/*!
+ * RegSyncValue1-8
+ */
+#define RF_SYNCVALUE1_SYNCVALUE 0x01 // Default
+#define RF_SYNCVALUE2_SYNCVALUE 0x01 // Default
+#define RF_SYNCVALUE3_SYNCVALUE 0x01 // Default
+#define RF_SYNCVALUE4_SYNCVALUE 0x01 // Default
+#define RF_SYNCVALUE5_SYNCVALUE 0x01 // Default
+#define RF_SYNCVALUE6_SYNCVALUE 0x01 // Default
+#define RF_SYNCVALUE7_SYNCVALUE 0x01 // Default
+#define RF_SYNCVALUE8_SYNCVALUE 0x01 // Default
+
+/*!
+ * RegPacketConfig1
+ */
+#define RF_PACKETCONFIG1_PACKETFORMAT_MASK 0x7F
+#define RF_PACKETCONFIG1_PACKETFORMAT_FIXED 0x00
+#define RF_PACKETCONFIG1_PACKETFORMAT_VARIABLE 0x80 // Default
+
+#define RF_PACKETCONFIG1_DCFREE_MASK 0x9F
+#define RF_PACKETCONFIG1_DCFREE_OFF 0x00 // Default
+#define RF_PACKETCONFIG1_DCFREE_MANCHESTER 0x20
+#define RF_PACKETCONFIG1_DCFREE_WHITENING 0x40
+
+#define RF_PACKETCONFIG1_CRC_MASK 0xEF
+#define RF_PACKETCONFIG1_CRC_ON 0x10 // Default
+#define RF_PACKETCONFIG1_CRC_OFF 0x00
+
+#define RF_PACKETCONFIG1_CRCAUTOCLEAR_MASK 0xF7
+#define RF_PACKETCONFIG1_CRCAUTOCLEAR_ON 0x00 // Default
+#define RF_PACKETCONFIG1_CRCAUTOCLEAR_OFF 0x08
+
+#define RF_PACKETCONFIG1_ADDRSFILTERING_MASK 0xF9
+#define RF_PACKETCONFIG1_ADDRSFILTERING_OFF 0x00 // Default
+#define RF_PACKETCONFIG1_ADDRSFILTERING_NODE 0x02
+#define RF_PACKETCONFIG1_ADDRSFILTERING_NODEBROADCAST 0x04
+
+#define RF_PACKETCONFIG1_CRCWHITENINGTYPE_MASK 0xFE
+#define RF_PACKETCONFIG1_CRCWHITENINGTYPE_CCITT 0x00 // Default
+#define RF_PACKETCONFIG1_CRCWHITENINGTYPE_IBM 0x01
+
+/*!
+ * RegPacketConfig2
+ */
+
+#define RF_PACKETCONFIG2_WMBUS_CRC_ENABLE_MASK 0x7F
+#define RF_PACKETCONFIG2_WMBUS_CRC_ENABLE 0x80
+#define RF_PACKETCONFIG2_WMBUS_CRC_DISABLE 0x00 // Default
+
+#define RF_PACKETCONFIG2_DATAMODE_MASK 0xBF
+#define RF_PACKETCONFIG2_DATAMODE_CONTINUOUS 0x00
+#define RF_PACKETCONFIG2_DATAMODE_PACKET 0x40 // Default
+
+#define RF_PACKETCONFIG2_IOHOME_MASK 0xDF
+#define RF_PACKETCONFIG2_IOHOME_ON 0x20
+#define RF_PACKETCONFIG2_IOHOME_OFF 0x00 // Default
+
+#define RF_PACKETCONFIG2_BEACON_MASK 0xF7
+#define RF_PACKETCONFIG2_BEACON_ON 0x08
+#define RF_PACKETCONFIG2_BEACON_OFF 0x00 // Default
+
+#define RF_PACKETCONFIG2_PAYLOADLENGTH_MSB_MASK 0xF8
+
+/*!
+ * RegPayloadLength
+ */
+#define RF_PAYLOADLENGTH_LENGTH 0x40 // Default
+
+/*!
+ * RegNodeAdrs
+ */
+#define RF_NODEADDRESS_ADDRESS 0x00
+
+/*!
+ * RegBroadcastAdrs
+ */
+#define RF_BROADCASTADDRESS_ADDRESS 0x00
+
+/*!
+ * RegFifoThresh
+ */
+#define RF_FIFOTHRESH_TXSTARTCONDITION_MASK 0x7F
+#define RF_FIFOTHRESH_TXSTARTCONDITION_FIFOTHRESH 0x00 // Default
+#define RF_FIFOTHRESH_TXSTARTCONDITION_FIFONOTEMPTY 0x80
+
+#define RF_FIFOTHRESH_FIFOTHRESHOLD_MASK 0xC0
+#define RF_FIFOTHRESH_FIFOTHRESHOLD_THRESHOLD 0x0F // Default
+
+/*!
+ * RegSeqConfig1
+ */
+#define RF_SEQCONFIG1_SEQUENCER_START 0x80
+
+#define RF_SEQCONFIG1_SEQUENCER_STOP 0x40
+
+#define RF_SEQCONFIG1_IDLEMODE_MASK 0xDF
+#define RF_SEQCONFIG1_IDLEMODE_SLEEP 0x20
+#define RF_SEQCONFIG1_IDLEMODE_STANDBY 0x00 // Default
+
+#define RF_SEQCONFIG1_FROMSTART_MASK 0xE7
+#define RF_SEQCONFIG1_FROMSTART_TOLPS 0x00 // Default
+#define RF_SEQCONFIG1_FROMSTART_TORX 0x08
+#define RF_SEQCONFIG1_FROMSTART_TOTX 0x10
+#define RF_SEQCONFIG1_FROMSTART_TOTX_ONFIFOLEVEL 0x18
+
+#define RF_SEQCONFIG1_LPS_MASK 0xFB
+#define RF_SEQCONFIG1_LPS_SEQUENCER_OFF 0x00 // Default
+#define RF_SEQCONFIG1_LPS_IDLE 0x04
+
+#define RF_SEQCONFIG1_FROMIDLE_MASK 0xFD
+#define RF_SEQCONFIG1_FROMIDLE_TOTX 0x00 // Default
+#define RF_SEQCONFIG1_FROMIDLE_TORX 0x02
+
+#define RF_SEQCONFIG1_FROMTX_MASK 0xFE
+#define RF_SEQCONFIG1_FROMTX_TOLPS 0x00 // Default
+#define RF_SEQCONFIG1_FROMTX_TORX 0x01
+
+/*!
+ * RegSeqConfig2
+ */
+#define RF_SEQCONFIG2_FROMRX_MASK 0x1F
+#define RF_SEQCONFIG2_FROMRX_TOUNUSED_000 0x00 // Default
+#define RF_SEQCONFIG2_FROMRX_TORXPKT_ONPLDRDY 0x20
+#define RF_SEQCONFIG2_FROMRX_TOLPS_ONPLDRDY 0x40
+#define RF_SEQCONFIG2_FROMRX_TORXPKT_ONCRCOK 0x60
+#define RF_SEQCONFIG2_FROMRX_TOSEQUENCEROFF_ONRSSI 0x80
+#define RF_SEQCONFIG2_FROMRX_TOSEQUENCEROFF_ONSYNC 0xA0
+#define RF_SEQCONFIG2_FROMRX_TOSEQUENCEROFF_ONPREAMBLE 0xC0
+#define RF_SEQCONFIG2_FROMRX_TOUNUSED_111 0xE0
+
+#define RF_SEQCONFIG2_FROMRXTIMEOUT_MASK 0xE7
+#define RF_SEQCONFIG2_FROMRXTIMEOUT_TORXRESTART 0x00 // Default
+#define RF_SEQCONFIG2_FROMRXTIMEOUT_TOTX 0x08
+#define RF_SEQCONFIG2_FROMRXTIMEOUT_TOLPS 0x10
+#define RF_SEQCONFIG2_FROMRXTIMEOUT_TOSEQUENCEROFF 0x18
+
+#define RF_SEQCONFIG2_FROMRXPKT_MASK 0xF8
+#define RF_SEQCONFIG2_FROMRXPKT_TOSEQUENCEROFF 0x00 // Default
+#define RF_SEQCONFIG2_FROMRXPKT_TOTX_ONFIFOEMPTY 0x01
+#define RF_SEQCONFIG2_FROMRXPKT_TOLPS 0x02
+#define RF_SEQCONFIG2_FROMRXPKT_TOSYNTHESIZERRX 0x03
+#define RF_SEQCONFIG2_FROMRXPKT_TORX 0x04
+
+/*!
+ * RegTimerResol
+ */
+#define RF_TIMERRESOL_TIMER1RESOL_MASK 0xF3
+#define RF_TIMERRESOL_TIMER1RESOL_OFF 0x00 // Default
+#define RF_TIMERRESOL_TIMER1RESOL_000064_US 0x04
+#define RF_TIMERRESOL_TIMER1RESOL_004100_US 0x08
+#define RF_TIMERRESOL_TIMER1RESOL_262000_US 0x0C
+
+#define RF_TIMERRESOL_TIMER2RESOL_MASK 0xFC
+#define RF_TIMERRESOL_TIMER2RESOL_OFF 0x00 // Default
+#define RF_TIMERRESOL_TIMER2RESOL_000064_US 0x01
+#define RF_TIMERRESOL_TIMER2RESOL_004100_US 0x02
+#define RF_TIMERRESOL_TIMER2RESOL_262000_US 0x03
+
+/*!
+ * RegTimer1Coef
+ */
+#define RF_TIMER1COEF_TIMER1COEFFICIENT 0xF5 // Default
+
+/*!
+ * RegTimer2Coef
+ */
+#define RF_TIMER2COEF_TIMER2COEFFICIENT 0x20 // Default
+
+/*!
+ * RegImageCal
+ */
+#define RF_IMAGECAL_AUTOIMAGECAL_MASK 0x7F
+#define RF_IMAGECAL_AUTOIMAGECAL_ON 0x80
+#define RF_IMAGECAL_AUTOIMAGECAL_OFF 0x00 // Default
+
+#define RF_IMAGECAL_IMAGECAL_MASK 0xBF
+#define RF_IMAGECAL_IMAGECAL_START 0x40
+
+#define RF_IMAGECAL_IMAGECAL_RUNNING 0x20
+#define RF_IMAGECAL_IMAGECAL_DONE 0x00 // Default
+
+#define RF_IMAGECAL_TEMPCHANGE_HIGHER 0x08
+#define RF_IMAGECAL_TEMPCHANGE_LOWER 0x00
+
+#define RF_IMAGECAL_TEMPTHRESHOLD_MASK 0xF9
+#define RF_IMAGECAL_TEMPTHRESHOLD_05 0x00
+#define RF_IMAGECAL_TEMPTHRESHOLD_10 0x02 // Default
+#define RF_IMAGECAL_TEMPTHRESHOLD_15 0x04
+#define RF_IMAGECAL_TEMPTHRESHOLD_20 0x06
+
+#define RF_IMAGECAL_TEMPMONITOR_MASK 0xFE
+#define RF_IMAGECAL_TEMPMONITOR_ON 0x00 // Default
+#define RF_IMAGECAL_TEMPMONITOR_OFF 0x01
+
+/*!
+ * RegTemp (Read Only)
+ */
+
+/*!
+ * RegLowBat
+ */
+#define RF_LOWBAT_MASK 0xF7
+#define RF_LOWBAT_ON 0x08
+#define RF_LOWBAT_OFF 0x00 // Default
+
+#define RF_LOWBAT_TRIM_MASK 0xF8
+#define RF_LOWBAT_TRIM_1695 0x00
+#define RF_LOWBAT_TRIM_1764 0x01
+#define RF_LOWBAT_TRIM_1835 0x02 // Default
+#define RF_LOWBAT_TRIM_1905 0x03
+#define RF_LOWBAT_TRIM_1976 0x04
+#define RF_LOWBAT_TRIM_2045 0x05
+#define RF_LOWBAT_TRIM_2116 0x06
+#define RF_LOWBAT_TRIM_2185 0x07
+
+/*!
+ * RegIrqFlags1
+ */
+#define RF_IRQFLAGS1_MODEREADY 0x80
+
+#define RF_IRQFLAGS1_RXREADY 0x40
+
+#define RF_IRQFLAGS1_TXREADY 0x20
+
+#define RF_IRQFLAGS1_PLLLOCK 0x10
+
+#define RF_IRQFLAGS1_RSSI 0x08
+
+#define RF_IRQFLAGS1_TIMEOUT 0x04
+
+#define RF_IRQFLAGS1_PREAMBLEDETECT 0x02
+
+#define RF_IRQFLAGS1_SYNCADDRESSMATCH 0x01
+
+/*!
+ * RegIrqFlags2
+ */
+#define RF_IRQFLAGS2_FIFOFULL 0x80
+
+#define RF_IRQFLAGS2_FIFOEMPTY 0x40
+
+#define RF_IRQFLAGS2_FIFOLEVEL 0x20
+
+#define RF_IRQFLAGS2_FIFOOVERRUN 0x10
+
+#define RF_IRQFLAGS2_PACKETSENT 0x08
+
+#define RF_IRQFLAGS2_PAYLOADREADY 0x04
+
+#define RF_IRQFLAGS2_CRCOK 0x02
+
+#define RF_IRQFLAGS2_LOWBAT 0x01
+
+/*!
+ * RegDioMapping1
+ */
+#define RF_DIOMAPPING1_DIO0_MASK 0x3F
+#define RF_DIOMAPPING1_DIO0_00 0x00 // Default
+#define RF_DIOMAPPING1_DIO0_01 0x40
+#define RF_DIOMAPPING1_DIO0_10 0x80
+#define RF_DIOMAPPING1_DIO0_11 0xC0
+
+#define RF_DIOMAPPING1_DIO1_MASK 0xCF
+#define RF_DIOMAPPING1_DIO1_00 0x00 // Default
+#define RF_DIOMAPPING1_DIO1_01 0x10
+#define RF_DIOMAPPING1_DIO1_10 0x20
+#define RF_DIOMAPPING1_DIO1_11 0x30
+
+#define RF_DIOMAPPING1_DIO2_MASK 0xF3
+#define RF_DIOMAPPING1_DIO2_00 0x00 // Default
+#define RF_DIOMAPPING1_DIO2_01 0x04
+#define RF_DIOMAPPING1_DIO2_10 0x08
+#define RF_DIOMAPPING1_DIO2_11 0x0C
+
+#define RF_DIOMAPPING1_DIO3_MASK 0xFC
+#define RF_DIOMAPPING1_DIO3_00 0x00 // Default
+#define RF_DIOMAPPING1_DIO3_01 0x01
+#define RF_DIOMAPPING1_DIO3_10 0x02
+#define RF_DIOMAPPING1_DIO3_11 0x03
+
+/*!
+ * RegDioMapping2
+ */
+#define RF_DIOMAPPING2_DIO4_MASK 0x3F
+#define RF_DIOMAPPING2_DIO4_00 0x00 // Default
+#define RF_DIOMAPPING2_DIO4_01 0x40
+#define RF_DIOMAPPING2_DIO4_10 0x80
+#define RF_DIOMAPPING2_DIO4_11 0xC0
+
+#define RF_DIOMAPPING2_DIO5_MASK 0xCF
+#define RF_DIOMAPPING2_DIO5_00 0x00 // Default
+#define RF_DIOMAPPING2_DIO5_01 0x10
+#define RF_DIOMAPPING2_DIO5_10 0x20
+#define RF_DIOMAPPING2_DIO5_11 0x30
+
+#define RF_DIOMAPPING2_MAP_MASK 0xFE
+#define RF_DIOMAPPING2_MAP_PREAMBLEDETECT 0x01
+#define RF_DIOMAPPING2_MAP_RSSI 0x00 // Default
+
+/*!
+ * RegVersion (Read Only)
+ */
+
+/*!
+ * RegPllHop
+ */
+#define RF_PLLHOP_FASTHOP_MASK 0x7F
+#define RF_PLLHOP_FASTHOP_ON 0x80
+#define RF_PLLHOP_FASTHOP_OFF 0x00 // Default
+
+/*!
+ * RegTcxo
+ */
+#define RF_TCXO_TCXOINPUT_MASK 0xEF
+#define RF_TCXO_TCXOINPUT_ON 0x10
+#define RF_TCXO_TCXOINPUT_OFF 0x00 // Default
+
+/*!
+ * RegPaDac
+ */
+#define RF_PADAC_20DBM_MASK 0xF8
+#define RF_PADAC_20DBM_ON 0x07
+#define RF_PADAC_20DBM_OFF 0x04 // Default
+
+/*!
+ * RegFormerTemp
+ */
+
+/*!
+ * RegBitrateFrac
+ */
+#define RF_BITRATEFRAC_MASK 0xF0
+
+/*!
+ * RegAgcRef
+ */
+
+/*!
+ * RegAgcThresh1
+ */
+
+/*!
+ * RegAgcThresh2
+ */
+
+/*!
+ * RegAgcThresh3
+ */
+
+/*!
+ * RegPll
+ */
+#define RF_PLL_BANDWIDTH_MASK 0x3F
+#define RF_PLL_BANDWIDTH_75 0x00
+#define RF_PLL_BANDWIDTH_150 0x40
+#define RF_PLL_BANDWIDTH_225 0x80
+#define RF_PLL_BANDWIDTH_300 0xC0 // Default
+
+#endif // __SX1276_REGS_FSK_H__
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/560fa920/hw/drivers/lora/sx1276/src/sx1276Regs-LoRa.h
----------------------------------------------------------------------
diff --git a/hw/drivers/lora/sx1276/src/sx1276Regs-LoRa.h b/hw/drivers/lora/sx1276/src/sx1276Regs-LoRa.h
new file mode 100644
index 0000000..edce9f7
--- /dev/null
+++ b/hw/drivers/lora/sx1276/src/sx1276Regs-LoRa.h
@@ -0,0 +1,565 @@
+/*
+ / _____) _ | |
+( (____ _____ ____ _| |_ _____ ____| |__
+ \____ \| ___ | (_ _) ___ |/ ___) _ \
+ _____) ) ____| | | || |_| ____( (___| | | |
+(______/|_____)_|_|_| \__)_____)\____)_| |_|
+ (C)2013 Semtech
+
+Description: SX1276 LoRa modem registers and bits definitions
+
+License: Revised BSD License, see LICENSE.TXT file include in the project
+
+Maintainer: Miguel Luis and Gregory Cristian
+*/
+#ifndef __SX1276_REGS_LORA_H__
+#define __SX1276_REGS_LORA_H__
+
+/*!
+ * ============================================================================
+ * SX1276 Internal registers Address
+ * ============================================================================
+ */
+#define REG_LR_FIFO 0x00
+// Common settings
+#define REG_LR_OPMODE 0x01
+#define REG_LR_FRFMSB 0x06
+#define REG_LR_FRFMID 0x07
+#define REG_LR_FRFLSB 0x08
+// Tx settings
+#define REG_LR_PACONFIG 0x09
+#define REG_LR_PARAMP 0x0A
+#define REG_LR_OCP 0x0B
+// Rx settings
+#define REG_LR_LNA 0x0C
+// LoRa registers
+#define REG_LR_FIFOADDRPTR 0x0D
+#define REG_LR_FIFOTXBASEADDR 0x0E
+#define REG_LR_FIFORXBASEADDR 0x0F
+#define REG_LR_FIFORXCURRENTADDR 0x10
+#define REG_LR_IRQFLAGSMASK 0x11
+#define REG_LR_IRQFLAGS 0x12
+#define REG_LR_RXNBBYTES 0x13
+#define REG_LR_RXHEADERCNTVALUEMSB 0x14
+#define REG_LR_RXHEADERCNTVALUELSB 0x15
+#define REG_LR_RXPACKETCNTVALUEMSB 0x16
+#define REG_LR_RXPACKETCNTVALUELSB 0x17
+#define REG_LR_MODEMSTAT 0x18
+#define REG_LR_PKTSNRVALUE 0x19
+#define REG_LR_PKTRSSIVALUE 0x1A
+#define REG_LR_RSSIVALUE 0x1B
+#define REG_LR_HOPCHANNEL 0x1C
+#define REG_LR_MODEMCONFIG1 0x1D
+#define REG_LR_MODEMCONFIG2 0x1E
+#define REG_LR_SYMBTIMEOUTLSB 0x1F
+#define REG_LR_PREAMBLEMSB 0x20
+#define REG_LR_PREAMBLELSB 0x21
+#define REG_LR_PAYLOADLENGTH 0x22
+#define REG_LR_PAYLOADMAXLENGTH 0x23
+#define REG_LR_HOPPERIOD 0x24
+#define REG_LR_FIFORXBYTEADDR 0x25
+#define REG_LR_MODEMCONFIG3 0x26
+#define REG_LR_FEIMSB 0x28
+#define REG_LR_FEIMID 0x29
+#define REG_LR_FEILSB 0x2A
+#define REG_LR_RSSIWIDEBAND 0x2C
+#define REG_LR_TEST2F 0x2F
+#define REG_LR_TEST30 0x30
+#define REG_LR_DETECTOPTIMIZE 0x31
+#define REG_LR_INVERTIQ 0x33
+#define REG_LR_TEST36 0x36
+#define REG_LR_DETECTIONTHRESHOLD 0x37
+#define REG_LR_SYNCWORD 0x39
+#define REG_LR_TEST3A 0x3A
+#define REG_LR_INVERTIQ2 0x3B
+
+// end of documented register in datasheet
+// I/O settings
+#define REG_LR_DIOMAPPING1 0x40
+#define REG_LR_DIOMAPPING2 0x41
+// Version
+#define REG_LR_VERSION 0x42
+// Additional settings
+#define REG_LR_PLLHOP 0x44
+#define REG_LR_TCXO 0x4B
+#define REG_LR_PADAC 0x4D
+#define REG_LR_FORMERTEMP 0x5B
+#define REG_LR_BITRATEFRAC 0x5D
+#define REG_LR_AGCREF 0x61
+#define REG_LR_AGCTHRESH1 0x62
+#define REG_LR_AGCTHRESH2 0x63
+#define REG_LR_AGCTHRESH3 0x64
+#define REG_LR_PLL 0x70
+
+/*!
+ * ============================================================================
+ * SX1276 LoRa bits control definition
+ * ============================================================================
+ */
+
+/*!
+ * RegFifo
+ */
+
+/*!
+ * RegOpMode
+ */
+#define RFLR_OPMODE_LONGRANGEMODE_MASK 0x7F
+#define RFLR_OPMODE_LONGRANGEMODE_OFF 0x00 // Default
+#define RFLR_OPMODE_LONGRANGEMODE_ON 0x80
+
+#define RFLR_OPMODE_ACCESSSHAREDREG_MASK 0xBF
+#define RFLR_OPMODE_ACCESSSHAREDREG_ENABLE 0x40
+#define RFLR_OPMODE_ACCESSSHAREDREG_DISABLE 0x00 // Default
+
+#define RFLR_OPMODE_FREQMODE_ACCESS_MASK 0xF7
+#define RFLR_OPMODE_FREQMODE_ACCESS_LF 0x08 // Default
+#define RFLR_OPMODE_FREQMODE_ACCESS_HF 0x00
+
+#define RFLR_OPMODE_MASK 0xF8
+#define RFLR_OPMODE_SLEEP 0x00
+#define RFLR_OPMODE_STANDBY 0x01 // Default
+#define RFLR_OPMODE_SYNTHESIZER_TX 0x02
+#define RFLR_OPMODE_TRANSMITTER 0x03
+#define RFLR_OPMODE_SYNTHESIZER_RX 0x04
+#define RFLR_OPMODE_RECEIVER 0x05
+// LoRa specific modes
+#define RFLR_OPMODE_RECEIVER_SINGLE 0x06
+#define RFLR_OPMODE_CAD 0x07
+
+/*!
+ * RegFrf (MHz)
+ */
+#define RFLR_FRFMSB_434_MHZ 0x6C // Default
+#define RFLR_FRFMID_434_MHZ 0x80 // Default
+#define RFLR_FRFLSB_434_MHZ 0x00 // Default
+
+/*!
+ * RegPaConfig
+ */
+#define RFLR_PACONFIG_PASELECT_MASK 0x7F
+#define RFLR_PACONFIG_PASELECT_PABOOST 0x80
+#define RFLR_PACONFIG_PASELECT_RFO 0x00 // Default
+
+#define RFLR_PACONFIG_MAX_POWER_MASK 0x8F
+
+#define RFLR_PACONFIG_OUTPUTPOWER_MASK 0xF0
+
+/*!
+ * RegPaRamp
+ */
+#define RFLR_PARAMP_TXBANDFORCE_MASK 0xEF
+#define RFLR_PARAMP_TXBANDFORCE_BAND_SEL 0x10
+#define RFLR_PARAMP_TXBANDFORCE_AUTO 0x00 // Default
+
+#define RFLR_PARAMP_MASK 0xF0
+#define RFLR_PARAMP_3400_US 0x00
+#define RFLR_PARAMP_2000_US 0x01
+#define RFLR_PARAMP_1000_US 0x02
+#define RFLR_PARAMP_0500_US 0x03
+#define RFLR_PARAMP_0250_US 0x04
+#define RFLR_PARAMP_0125_US 0x05
+#define RFLR_PARAMP_0100_US 0x06
+#define RFLR_PARAMP_0062_US 0x07
+#define RFLR_PARAMP_0050_US 0x08
+#define RFLR_PARAMP_0040_US 0x09 // Default
+#define RFLR_PARAMP_0031_US 0x0A
+#define RFLR_PARAMP_0025_US 0x0B
+#define RFLR_PARAMP_0020_US 0x0C
+#define RFLR_PARAMP_0015_US 0x0D
+#define RFLR_PARAMP_0012_US 0x0E
+#define RFLR_PARAMP_0010_US 0x0F
+
+/*!
+ * RegOcp
+ */
+#define RFLR_OCP_MASK 0xDF
+#define RFLR_OCP_ON 0x20 // Default
+#define RFLR_OCP_OFF 0x00
+
+#define RFLR_OCP_TRIM_MASK 0xE0
+#define RFLR_OCP_TRIM_045_MA 0x00
+#define RFLR_OCP_TRIM_050_MA 0x01
+#define RFLR_OCP_TRIM_055_MA 0x02
+#define RFLR_OCP_TRIM_060_MA 0x03
+#define RFLR_OCP_TRIM_065_MA 0x04
+#define RFLR_OCP_TRIM_070_MA 0x05
+#define RFLR_OCP_TRIM_075_MA 0x06
+#define RFLR_OCP_TRIM_080_MA 0x07
+#define RFLR_OCP_TRIM_085_MA 0x08
+#define RFLR_OCP_TRIM_090_MA 0x09
+#define RFLR_OCP_TRIM_095_MA 0x0A
+#define RFLR_OCP_TRIM_100_MA 0x0B // Default
+#define RFLR_OCP_TRIM_105_MA 0x0C
+#define RFLR_OCP_TRIM_110_MA 0x0D
+#define RFLR_OCP_TRIM_115_MA 0x0E
+#define RFLR_OCP_TRIM_120_MA 0x0F
+#define RFLR_OCP_TRIM_130_MA 0x10
+#define RFLR_OCP_TRIM_140_MA 0x11
+#define RFLR_OCP_TRIM_150_MA 0x12
+#define RFLR_OCP_TRIM_160_MA 0x13
+#define RFLR_OCP_TRIM_170_MA 0x14
+#define RFLR_OCP_TRIM_180_MA 0x15
+#define RFLR_OCP_TRIM_190_MA 0x16
+#define RFLR_OCP_TRIM_200_MA 0x17
+#define RFLR_OCP_TRIM_210_MA 0x18
+#define RFLR_OCP_TRIM_220_MA 0x19
+#define RFLR_OCP_TRIM_230_MA 0x1A
+#define RFLR_OCP_TRIM_240_MA 0x1B
+
+/*!
+ * RegLna
+ */
+#define RFLR_LNA_GAIN_MASK 0x1F
+#define RFLR_LNA_GAIN_G1 0x20 // Default
+#define RFLR_LNA_GAIN_G2 0x40
+#define RFLR_LNA_GAIN_G3 0x60
+#define RFLR_LNA_GAIN_G4 0x80
+#define RFLR_LNA_GAIN_G5 0xA0
+#define RFLR_LNA_GAIN_G6 0xC0
+
+#define RFLR_LNA_BOOST_LF_MASK 0xE7
+#define RFLR_LNA_BOOST_LF_DEFAULT 0x00 // Default
+
+#define RFLR_LNA_BOOST_HF_MASK 0xFC
+#define RFLR_LNA_BOOST_HF_OFF 0x00 // Default
+#define RFLR_LNA_BOOST_HF_ON 0x03
+
+/*!
+ * RegFifoAddrPtr
+ */
+#define RFLR_FIFOADDRPTR 0x00 // Default
+
+/*!
+ * RegFifoTxBaseAddr
+ */
+#define RFLR_FIFOTXBASEADDR 0x80 // Default
+
+/*!
+ * RegFifoTxBaseAddr
+ */
+#define RFLR_FIFORXBASEADDR 0x00 // Default
+
+/*!
+ * RegFifoRxCurrentAddr (Read Only)
+ */
+
+/*!
+ * RegIrqFlagsMask
+ */
+#define RFLR_IRQFLAGS_RXTIMEOUT_MASK 0x80
+#define RFLR_IRQFLAGS_RXDONE_MASK 0x40
+#define RFLR_IRQFLAGS_PAYLOADCRCERROR_MASK 0x20
+#define RFLR_IRQFLAGS_VALIDHEADER_MASK 0x10
+#define RFLR_IRQFLAGS_TXDONE_MASK 0x08
+#define RFLR_IRQFLAGS_CADDONE_MASK 0x04
+#define RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL_MASK 0x02
+#define RFLR_IRQFLAGS_CADDETECTED_MASK 0x01
+
+/*!
+ * RegIrqFlags
+ */
+#define RFLR_IRQFLAGS_RXTIMEOUT 0x80
+#define RFLR_IRQFLAGS_RXDONE 0x40
+#define RFLR_IRQFLAGS_PAYLOADCRCERROR 0x20
+#define RFLR_IRQFLAGS_VALIDHEADER 0x10
+#define RFLR_IRQFLAGS_TXDONE 0x08
+#define RFLR_IRQFLAGS_CADDONE 0x04
+#define RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL 0x02
+#define RFLR_IRQFLAGS_CADDETECTED 0x01
+
+/*!
+ * RegFifoRxNbBytes (Read Only)
+ */
+
+/*!
+ * RegRxHeaderCntValueMsb (Read Only)
+ */
+
+/*!
+ * RegRxHeaderCntValueLsb (Read Only)
+ */
+
+/*!
+ * RegRxPacketCntValueMsb (Read Only)
+ */
+
+/*!
+ * RegRxPacketCntValueLsb (Read Only)
+ */
+
+/*!
+ * RegModemStat (Read Only)
+ */
+#define RFLR_MODEMSTAT_RX_CR_MASK 0x1F
+#define RFLR_MODEMSTAT_MODEM_STATUS_MASK 0xE0
+
+/*!
+ * RegPktSnrValue (Read Only)
+ */
+
+/*!
+ * RegPktRssiValue (Read Only)
+ */
+
+/*!
+ * RegRssiValue (Read Only)
+ */
+
+/*!
+ * RegHopChannel (Read Only)
+ */
+#define RFLR_HOPCHANNEL_PLL_LOCK_TIMEOUT_MASK 0x7F
+#define RFLR_HOPCHANNEL_PLL_LOCK_FAIL 0x80
+#define RFLR_HOPCHANNEL_PLL_LOCK_SUCCEED 0x00 // Default
+
+#define RFLR_HOPCHANNEL_CRCONPAYLOAD_MASK 0xBF
+#define RFLR_HOPCHANNEL_CRCONPAYLOAD_ON 0x40
+#define RFLR_HOPCHANNEL_CRCONPAYLOAD_OFF 0x00 // Default
+
+#define RFLR_HOPCHANNEL_CHANNEL_MASK 0x3F
+
+/*!
+ * RegModemConfig1
+ */
+#define RFLR_MODEMCONFIG1_BW_MASK 0x0F
+#define RFLR_MODEMCONFIG1_BW_7_81_KHZ 0x00
+#define RFLR_MODEMCONFIG1_BW_10_41_KHZ 0x10
+#define RFLR_MODEMCONFIG1_BW_15_62_KHZ 0x20
+#define RFLR_MODEMCONFIG1_BW_20_83_KHZ 0x30
+#define RFLR_MODEMCONFIG1_BW_31_25_KHZ 0x40
+#define RFLR_MODEMCONFIG1_BW_41_66_KHZ 0x50
+#define RFLR_MODEMCONFIG1_BW_62_50_KHZ 0x60
+#define RFLR_MODEMCONFIG1_BW_125_KHZ 0x70 // Default
+#define RFLR_MODEMCONFIG1_BW_250_KHZ 0x80
+#define RFLR_MODEMCONFIG1_BW_500_KHZ 0x90
+
+#define RFLR_MODEMCONFIG1_CODINGRATE_MASK 0xF1
+#define RFLR_MODEMCONFIG1_CODINGRATE_4_5 0x02
+#define RFLR_MODEMCONFIG1_CODINGRATE_4_6 0x04 // Default
+#define RFLR_MODEMCONFIG1_CODINGRATE_4_7 0x06
+#define RFLR_MODEMCONFIG1_CODINGRATE_4_8 0x08
+
+#define RFLR_MODEMCONFIG1_IMPLICITHEADER_MASK 0xFE
+#define RFLR_MODEMCONFIG1_IMPLICITHEADER_ON 0x01
+#define RFLR_MODEMCONFIG1_IMPLICITHEADER_OFF 0x00 // Default
+
+/*!
+ * RegModemConfig2
+ */
+#define RFLR_MODEMCONFIG2_SF_MASK 0x0F
+#define RFLR_MODEMCONFIG2_SF_6 0x60
+#define RFLR_MODEMCONFIG2_SF_7 0x70 // Default
+#define RFLR_MODEMCONFIG2_SF_8 0x80
+#define RFLR_MODEMCONFIG2_SF_9 0x90
+#define RFLR_MODEMCONFIG2_SF_10 0xA0
+#define RFLR_MODEMCONFIG2_SF_11 0xB0
+#define RFLR_MODEMCONFIG2_SF_12 0xC0
+
+#define RFLR_MODEMCONFIG2_TXCONTINUOUSMODE_MASK 0xF7
+#define RFLR_MODEMCONFIG2_TXCONTINUOUSMODE_ON 0x08
+#define RFLR_MODEMCONFIG2_TXCONTINUOUSMODE_OFF 0x00
+
+#define RFLR_MODEMCONFIG2_RXPAYLOADCRC_MASK 0xFB
+#define RFLR_MODEMCONFIG2_RXPAYLOADCRC_ON 0x04
+#define RFLR_MODEMCONFIG2_RXPAYLOADCRC_OFF 0x00 // Default
+
+#define RFLR_MODEMCONFIG2_SYMBTIMEOUTMSB_MASK 0xFC
+#define RFLR_MODEMCONFIG2_SYMBTIMEOUTMSB 0x00 // Default
+
+/*!
+ * RegSymbTimeoutLsb
+ */
+#define RFLR_SYMBTIMEOUTLSB_SYMBTIMEOUT 0x64 // Default
+
+/*!
+ * RegPreambleLengthMsb
+ */
+#define RFLR_PREAMBLELENGTHMSB 0x00 // Default
+
+/*!
+ * RegPreambleLengthLsb
+ */
+#define RFLR_PREAMBLELENGTHLSB 0x08 // Default
+
+/*!
+ * RegPayloadLength
+ */
+#define RFLR_PAYLOADLENGTH 0x0E // Default
+
+/*!
+ * RegPayloadMaxLength
+ */
+#define RFLR_PAYLOADMAXLENGTH 0xFF // Default
+
+/*!
+ * RegHopPeriod
+ */
+#define RFLR_HOPPERIOD_FREQFOPPINGPERIOD 0x00 // Default
+
+/*!
+ * RegFifoRxByteAddr (Read Only)
+ */
+
+/*!
+ * RegModemConfig3
+ */
+#define RFLR_MODEMCONFIG3_LOWDATARATEOPTIMIZE_MASK 0xF7
+#define RFLR_MODEMCONFIG3_LOWDATARATEOPTIMIZE_ON 0x08
+#define RFLR_MODEMCONFIG3_LOWDATARATEOPTIMIZE_OFF 0x00 // Default
+
+#define RFLR_MODEMCONFIG3_AGCAUTO_MASK 0xFB
+#define RFLR_MODEMCONFIG3_AGCAUTO_ON 0x04 // Default
+#define RFLR_MODEMCONFIG3_AGCAUTO_OFF 0x00
+
+/*!
+ * RegFeiMsb (Read Only)
+ */
+
+/*!
+ * RegFeiMid (Read Only)
+ */
+
+/*!
+ * RegFeiLsb (Read Only)
+ */
+
+/*!
+ * RegRssiWideband (Read Only)
+ */
+
+/*!
+ * RegDetectOptimize
+ */
+#define RFLR_DETECTIONOPTIMIZE_MASK 0xF8
+#define RFLR_DETECTIONOPTIMIZE_SF7_TO_SF12 0x03 // Default
+#define RFLR_DETECTIONOPTIMIZE_SF6 0x05
+
+/*!
+ * RegInvertIQ
+ */
+#define RFLR_INVERTIQ_RX_MASK 0xBF
+#define RFLR_INVERTIQ_RX_OFF 0x00
+#define RFLR_INVERTIQ_RX_ON 0x40
+#define RFLR_INVERTIQ_TX_MASK 0xFE
+#define RFLR_INVERTIQ_TX_OFF 0x01
+#define RFLR_INVERTIQ_TX_ON 0x00
+
+/*!
+ * RegDetectionThreshold
+ */
+#define RFLR_DETECTIONTHRESH_SF7_TO_SF12 0x0A // Default
+#define RFLR_DETECTIONTHRESH_SF6 0x0C
+
+/*!
+ * RegInvertIQ2
+ */
+#define RFLR_INVERTIQ2_ON 0x19
+#define RFLR_INVERTIQ2_OFF 0x1D
+
+/*!
+ * RegDioMapping1
+ */
+#define RFLR_DIOMAPPING1_DIO0_MASK 0x3F
+#define RFLR_DIOMAPPING1_DIO0_00 0x00 // Default
+#define RFLR_DIOMAPPING1_DIO0_01 0x40
+#define RFLR_DIOMAPPING1_DIO0_10 0x80
+#define RFLR_DIOMAPPING1_DIO0_11 0xC0
+
+#define RFLR_DIOMAPPING1_DIO1_MASK 0xCF
+#define RFLR_DIOMAPPING1_DIO1_00 0x00 // Default
+#define RFLR_DIOMAPPING1_DIO1_01 0x10
+#define RFLR_DIOMAPPING1_DIO1_10 0x20
+#define RFLR_DIOMAPPING1_DIO1_11 0x30
+
+#define RFLR_DIOMAPPING1_DIO2_MASK 0xF3
+#define RFLR_DIOMAPPING1_DIO2_00 0x00 // Default
+#define RFLR_DIOMAPPING1_DIO2_01 0x04
+#define RFLR_DIOMAPPING1_DIO2_10 0x08
+#define RFLR_DIOMAPPING1_DIO2_11 0x0C
+
+#define RFLR_DIOMAPPING1_DIO3_MASK 0xFC
+#define RFLR_DIOMAPPING1_DIO3_00 0x00 // Default
+#define RFLR_DIOMAPPING1_DIO3_01 0x01
+#define RFLR_DIOMAPPING1_DIO3_10 0x02
+#define RFLR_DIOMAPPING1_DIO3_11 0x03
+
+/*!
+ * RegDioMapping2
+ */
+#define RFLR_DIOMAPPING2_DIO4_MASK 0x3F
+#define RFLR_DIOMAPPING2_DIO4_00 0x00 // Default
+#define RFLR_DIOMAPPING2_DIO4_01 0x40
+#define RFLR_DIOMAPPING2_DIO4_10 0x80
+#define RFLR_DIOMAPPING2_DIO4_11 0xC0
+
+#define RFLR_DIOMAPPING2_DIO5_MASK 0xCF
+#define RFLR_DIOMAPPING2_DIO5_00 0x00 // Default
+#define RFLR_DIOMAPPING2_DIO5_01 0x10
+#define RFLR_DIOMAPPING2_DIO5_10 0x20
+#define RFLR_DIOMAPPING2_DIO5_11 0x30
+
+#define RFLR_DIOMAPPING2_MAP_MASK 0xFE
+#define RFLR_DIOMAPPING2_MAP_PREAMBLEDETECT 0x01
+#define RFLR_DIOMAPPING2_MAP_RSSI 0x00 // Default
+
+/*!
+ * RegVersion (Read Only)
+ */
+
+/*!
+ * RegPllHop
+ */
+#define RFLR_PLLHOP_FASTHOP_MASK 0x7F
+#define RFLR_PLLHOP_FASTHOP_ON 0x80
+#define RFLR_PLLHOP_FASTHOP_OFF 0x00 // Default
+
+/*!
+ * RegTcxo
+ */
+#define RFLR_TCXO_TCXOINPUT_MASK 0xEF
+#define RFLR_TCXO_TCXOINPUT_ON 0x10
+#define RFLR_TCXO_TCXOINPUT_OFF 0x00 // Default
+
+/*!
+ * RegPaDac
+ */
+#define RFLR_PADAC_20DBM_MASK 0xF8
+#define RFLR_PADAC_20DBM_ON 0x07
+#define RFLR_PADAC_20DBM_OFF 0x04 // Default
+
+/*!
+ * RegFormerTemp
+ */
+
+/*!
+ * RegBitrateFrac
+ */
+#define RF_BITRATEFRAC_MASK 0xF0
+
+/*!
+ * RegAgcRef
+ */
+
+/*!
+ * RegAgcThresh1
+ */
+
+/*!
+ * RegAgcThresh2
+ */
+
+/*!
+ * RegAgcThresh3
+ */
+
+/*!
+ * RegPll
+ */
+#define RF_PLL_BANDWIDTH_MASK 0x3F
+#define RF_PLL_BANDWIDTH_75 0x00
+#define RF_PLL_BANDWIDTH_150 0x40
+#define RF_PLL_BANDWIDTH_225 0x80
+#define RF_PLL_BANDWIDTH_300 0xC0 // Default
+
+#endif // __SX1276_REGS_LORA_H__
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/560fa920/hw/drivers/lora/sx1276/syscfg.yml
----------------------------------------------------------------------
diff --git a/hw/drivers/lora/sx1276/syscfg.yml b/hw/drivers/lora/sx1276/syscfg.yml
new file mode 100644
index 0000000..9bcffe2
--- /dev/null
+++ b/hw/drivers/lora/sx1276/syscfg.yml
@@ -0,0 +1,27 @@
+#
+# 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:
+ SX1276_SPI_IDX:
+ description:
+ value: -1
+
+ SX1276_SPI_BAUDRATE:
+ description:
+ value: 500
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/560fa920/net/lora/node/pkg.yml
----------------------------------------------------------------------
diff --git a/net/lora/node/pkg.yml b/net/lora/node/pkg.yml
index 694bc01..348765a 100644
--- a/net/lora/node/pkg.yml
+++ b/net/lora/node/pkg.yml
@@ -35,8 +35,7 @@ pkg.deps.LORA_NODE_CLI:
- "@apache-mynewt-core/util/parse"
pkg.req_apis:
- - lora_node_board
- - lora_node_radio
+ - lora_node_driver
pkg.init:
lora_node_init: 200
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/560fa920/net/lora/node/src/mac/LoRaMac.c
----------------------------------------------------------------------
diff --git a/net/lora/node/src/mac/LoRaMac.c b/net/lora/node/src/mac/LoRaMac.c
index e8d4344..473e56e 100644
--- a/net/lora/node/src/mac/LoRaMac.c
+++ b/net/lora/node/src/mac/LoRaMac.c
@@ -17,10 +17,13 @@ License: Revised BSD License, see LICENSE.TXT file include in the project
Maintainer: Miguel Luis ( Semtech ), Gregory Cristian ( Semtech ) and Daniel Jäckle ( STACKFORCE )
*/
+
+#include <string.h>
+
#include "node/radio.h"
-#include "board/board.h"
#include "radio/radio.h"
+#include "node/utilities.h"
#include "node/mac/LoRaMacCrypto.h"
#include "node/mac/LoRaMac.h"
#include "node/mac/LoRaMacTest.h"
[37/40] incubator-mynewt-core git commit: hw: mcu: pic32mz2048efg100:
Implement hal_gpio driver
Posted by ja...@apache.org.
hw: mcu: pic32mz2048efg100: Implement hal_gpio driver
Signed-off-by: Francois Berder <fb...@outlook.fr>
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/32427b41
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/32427b41
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/32427b41
Branch: refs/heads/bluetooth5
Commit: 32427b4128abf57836b98a73800a14c48ea22793
Parents: 5ae5f3d
Author: Francois Berder <fb...@outlook.fr>
Authored: Sun May 7 19:08:53 2017 +0200
Committer: Francois Berder <fb...@outlook.fr>
Committed: Sun May 7 20:07:28 2017 +0200
----------------------------------------------------------------------
.../pic32mz2048efg100/include/mcu/mcu.h | 16 +
.../microchip/pic32mz2048efg100/src/hal_gpio.c | 485 +++++++++++++++++++
2 files changed, 501 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/32427b41/hw/mcu/microchip/pic32mz2048efg100/include/mcu/mcu.h
----------------------------------------------------------------------
diff --git a/hw/mcu/microchip/pic32mz2048efg100/include/mcu/mcu.h b/hw/mcu/microchip/pic32mz2048efg100/include/mcu/mcu.h
index 2be36a9..186bfee 100644
--- a/hw/mcu/microchip/pic32mz2048efg100/include/mcu/mcu.h
+++ b/hw/mcu/microchip/pic32mz2048efg100/include/mcu/mcu.h
@@ -22,4 +22,20 @@
#include "p32mz2048efg100.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define MCU_GPIO_PORTA(pin) ((0 * 16) + (pin & 0xF))
+#define MCU_GPIO_PORTB(pin) ((1 * 16) + (pin & 0xF))
+#define MCU_GPIO_PORTC(pin) ((2 * 16) + (pin & 0xF))
+#define MCU_GPIO_PORTD(pin) ((3 * 16) + (pin & 0xF))
+#define MCU_GPIO_PORTE(pin) ((4 * 16) + (pin & 0xF))
+#define MCU_GPIO_PORTF(pin) ((5 * 16) + (pin & 0xF))
+#define MCU_GPIO_PORTG(pin) ((6 * 16) + (pin & 0xF))
+
+#ifdef __cplusplus
+}
+#endif
+
#endif /* __MCU_MCU_H_ */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/32427b41/hw/mcu/microchip/pic32mz2048efg100/src/hal_gpio.c
----------------------------------------------------------------------
diff --git a/hw/mcu/microchip/pic32mz2048efg100/src/hal_gpio.c b/hw/mcu/microchip/pic32mz2048efg100/src/hal_gpio.c
new file mode 100644
index 0000000..1c98a7a
--- /dev/null
+++ b/hw/mcu/microchip/pic32mz2048efg100/src/hal_gpio.c
@@ -0,0 +1,485 @@
+/**
+ * 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.
+ */
+
+#include <os/os.h>
+#include <hal/hal_gpio.h>
+#include <mcu/mips_hal.h>
+#include <mcu/p32mz2048efg100.h>
+
+#define GPIO_INDEX(pin) ((pin) & 0x0F)
+#define GPIO_PORT(pin) (((pin) >> 4) & 0x0F)
+#define GPIO_MASK(pin) (1 << GPIO_INDEX(pin))
+
+#define LATxCLR(P) (base_address[P].gpio[0x14 / 0x4])
+#define LATxSET(P) (base_address[P].gpio[0x18 / 0x4])
+#define LATxINV(P) (base_address[P].gpio[0x1C / 0x4])
+#define PORTx(P) (base_address[P].gpio[0x0])
+#define CNPUxCLR(P) (base_address[P].gpio[0x34 / 0x4])
+#define CNPUxSET(P) (base_address[P].gpio[0x38 / 0x4])
+#define CNPDxCLR(P) (base_address[P].gpio[0x44 / 0x4])
+#define CNPDxSET(P) (base_address[P].gpio[0x48 / 0x4])
+#define ODCxCLR(P) (base_address[P].gpio[0x24 / 0x4])
+#define CNCONxSET(P) (base_address[P].gpio[0x58 / 0x4])
+#define CNENxCLR(P) (base_address[P].gpio[0x64 / 0x4])
+#define CNENxSET(P) (base_address[P].gpio[0x68 / 0x4])
+#define CNNExCLR(P) (base_address[P].gpio[0x84 / 0x4])
+#define CNNExSET(P) (base_address[P].gpio[0x88 / 0x4])
+#define CNFx(P) (base_address[P].gpio[0x90 / 0x4])
+#define CNFxCLR(P) (base_address[P].gpio[0x94 / 0x4])
+#define ANSELxCLR(P) (base_address[P].ansel[0x04 / 0x4])
+#define TRISxCLR(P) (base_address[P].tris[0x04 / 0x4])
+#define TRISxSET(P) (base_address[P].tris[0x08 / 0x4])
+
+struct hal_gpio_irq_t {
+ int pin;
+ hal_gpio_irq_trig_t trig;
+ hal_gpio_irq_handler_t handler;
+ void *arg;
+};
+
+#define HAL_GPIO_MAX_IRQ (8)
+static struct hal_gpio_irq_t hal_gpio_irqs[HAL_GPIO_MAX_IRQ];
+
+struct pic32_gpio_t {
+ volatile uint32_t * gpio;
+ volatile uint32_t * ansel;
+ volatile uint32_t * tris;
+};
+
+static struct pic32_gpio_t base_address[] = {
+ {
+ .gpio = (volatile uint32_t *)_PORTA_BASE_ADDRESS,
+ .ansel = (volatile uint32_t *)&ANSELA,
+ .tris = (volatile uint32_t *)&TRISA
+ },
+ {
+ .gpio = (volatile uint32_t *)_PORTB_BASE_ADDRESS,
+ .ansel = (volatile uint32_t *)&ANSELB,
+ .tris = (volatile uint32_t *)&TRISB
+ },
+ {
+ .gpio = (volatile uint32_t *)_PORTC_BASE_ADDRESS,
+ .ansel = (volatile uint32_t *)&ANSELC,
+ .tris = (volatile uint32_t *)&TRISC
+ },
+ {
+ .gpio = (volatile uint32_t *)_PORTD_BASE_ADDRESS,
+ .ansel = (volatile uint32_t *)&ANSELD,
+ .tris = (volatile uint32_t *)&TRISD
+ },
+ {
+ .gpio = (volatile uint32_t *)_PORTE_BASE_ADDRESS,
+ .ansel = (volatile uint32_t *)&ANSELE,
+ .tris = (volatile uint32_t *)&TRISE
+ },
+ {
+ .gpio = (volatile uint32_t *)_PORTF_BASE_ADDRESS,
+ .ansel = (volatile uint32_t *)&ANSELF,
+ .tris = (volatile uint32_t *)&TRISF
+ },
+ {
+ .gpio = (volatile uint32_t *)_PORTG_BASE_ADDRESS,
+ .ansel = (volatile uint32_t *)&ANSELG,
+ .tris = (volatile uint32_t *)&TRISG
+ }
+};
+
+static uint8_t
+hal_gpio_find_pin(int pin)
+{
+ uint8_t index = 0;
+
+ while (index < HAL_GPIO_MAX_IRQ) {
+ if (hal_gpio_irqs[index].pin == pin) {
+ break;
+ }
+
+ ++index;
+ }
+
+ return index;
+}
+
+static uint8_t
+hal_gpio_find_empty_slot(void)
+{
+ uint8_t index = 0;
+
+ while (index < HAL_GPIO_MAX_IRQ) {
+ if (hal_gpio_irqs[index].handler == NULL) {
+ break;
+ }
+
+ ++index;
+ }
+
+ return index;
+}
+
+static void
+hal_gpio_handle_isr(uint32_t port)
+{
+ uint8_t index = 0;
+ static unsigned int i = 0;
+ for (index = 0; index < HAL_GPIO_MAX_IRQ; ++index) {
+ uint32_t mask, val;
+
+ if (hal_gpio_irqs[index].handler == NULL) {
+ continue;
+ }
+ if (GPIO_PORT(hal_gpio_irqs[index].pin) != port) {
+ continue;
+ }
+
+ mask = GPIO_MASK(hal_gpio_irqs[index].pin);
+ if (CNFx(port) & mask != mask) {
+ continue;
+ }
+
+ val = PORTx(port) & mask;
+ if ((val && (hal_gpio_irqs[index].trig & HAL_GPIO_TRIG_RISING)) ||
+ (!val && (hal_gpio_irqs[index].trig & HAL_GPIO_TRIG_FALLING))) {
+ hal_gpio_irqs[index].handler(hal_gpio_irqs[index].arg);
+ }
+ CNFxCLR(port) = mask;
+ }
+}
+
+void
+__attribute__((interrupt(IPL1AUTO), vector(_CHANGE_NOTICE_A_VECTOR)))
+hal_gpio_porta_isr(void)
+{
+ hal_gpio_handle_isr(0);
+ IFS3CLR = _IFS3_CNAIF_MASK;
+}
+
+void
+__attribute__((interrupt(IPL1AUTO), vector(_CHANGE_NOTICE_B_VECTOR)))
+hal_gpio_portb_isr(void)
+{
+ hal_gpio_handle_isr(1);
+ IFS3CLR = _IFS3_CNBIF_MASK;
+}
+
+void
+__attribute__((interrupt(IPL1AUTO), vector(_CHANGE_NOTICE_C_VECTOR)))
+hal_gpio_portc_isr(void)
+{
+ hal_gpio_handle_isr(2);
+ IFS3CLR = _IFS3_CNCIF_MASK;
+}
+
+void
+__attribute__((interrupt(IPL1AUTO), vector(_CHANGE_NOTICE_D_VECTOR)))
+hal_gpio_portd_isr(void)
+{
+ hal_gpio_handle_isr(3);
+ IFS3CLR = _IFS3_CNDIF_MASK;
+}
+
+void
+__attribute__((interrupt(IPL1AUTO), vector(_CHANGE_NOTICE_E_VECTOR)))
+hal_gpio_porte_isr(void)
+{
+ hal_gpio_handle_isr(4);
+ IFS3CLR = _IFS3_CNEIF_MASK;
+}
+
+void
+__attribute__((interrupt(IPL1AUTO), vector(_CHANGE_NOTICE_F_VECTOR)))
+hal_gpio_portf_isr(void)
+{
+ hal_gpio_handle_isr(5);
+ IFS3CLR = _IFS3_CNFIF_MASK;
+}
+
+void
+__attribute__((interrupt(IPL1AUTO), vector(_CHANGE_NOTICE_G_VECTOR)))
+hal_gpio_portg_isr(void)
+{
+ hal_gpio_handle_isr(6);
+ IFS3CLR = _IFS3_CNGIF_MASK;
+}
+
+int
+hal_gpio_init_in(int pin, hal_gpio_pull_t pull)
+{
+ uint32_t port = GPIO_PORT(pin);
+ uint32_t mask = GPIO_MASK(pin);
+
+ /* Configure pin as digital */
+ ANSELxCLR(port) = mask;
+
+ ODCxCLR(port) = mask;
+
+ switch (pull) {
+ case HAL_GPIO_PULL_NONE:
+ CNPUxCLR(port) = mask;
+ CNPDxCLR(port) = mask;
+ break;
+
+ case HAL_GPIO_PULL_DOWN:
+ CNPUxCLR(port) = mask;
+ CNPDxSET(port) = mask;
+ break;
+
+ case HAL_GPIO_PULL_UP:
+ CNPUxSET(port) = mask;
+ CNPDxCLR(port) = mask;
+ break;
+
+ default:
+ return -1;
+ }
+
+ /* Configure pin direction as input */
+ TRISxSET(port) = mask;
+
+ return 0;
+}
+
+int
+hal_gpio_init_out(int pin, int val)
+{
+ uint32_t port = GPIO_PORT(pin);
+ uint32_t mask = GPIO_MASK(pin);
+
+ /* Configure pin as digital */
+ ANSELxCLR(port) = mask;
+
+ /* Disable pull-up, pull-down and open drain */
+ CNPUxCLR(port) = mask;
+ CNPDxCLR(port) = mask;
+ ODCxCLR(port) = mask;
+
+ if (val) {
+ LATxSET(port) = mask;
+ } else {
+ LATxCLR(port) = mask;
+ }
+
+ /* Configure pin direction as output */
+ TRISxCLR(port) = mask;
+
+ return 0;
+}
+
+void
+hal_gpio_write(int pin, int val)
+{
+ uint32_t port = GPIO_PORT(pin);
+ uint32_t mask = GPIO_MASK(pin);
+
+ if (val) {
+ LATxSET(port) = mask;
+ } else {
+ LATxCLR(port) = mask;
+ }
+}
+
+int
+hal_gpio_read(int pin)
+{
+ uint32_t port = GPIO_PORT(pin);
+ uint32_t mask = GPIO_MASK(pin);
+
+ return !!(PORTx(port) & mask);
+}
+
+int
+hal_gpio_toggle(int pin)
+{
+ uint32_t port = GPIO_PORT(pin);
+ uint32_t mask = GPIO_MASK(pin);
+
+ LATxINV(port) = mask;
+
+ /*
+ * One instruction cycle is required between a write and a read
+ * operation on the same port.
+ */
+ asm volatile ("nop");
+
+ return !!(PORTx(port) & mask);
+}
+
+int
+hal_gpio_irq_init(int pin, hal_gpio_irq_handler_t handler, void *arg,
+ hal_gpio_irq_trig_t trig, hal_gpio_pull_t pull)
+{
+ uint32_t port = GPIO_PORT(pin);
+ uint32_t mask = GPIO_MASK(pin);
+ uint32_t ctx;
+ int ret;
+ uint8_t index;
+
+ /* HAL_GPIO_TRIG_LOW and HAL_GPIO_TRIG_HIGH are not supported */
+ if (trig == HAL_GPIO_TRIG_LOW ||
+ trig == HAL_GPIO_TRIG_HIGH ||
+ trig == HAL_GPIO_TRIG_NONE) {
+ return -1;
+ }
+
+ /* Remove any existing irq handler attached to the pin */
+ hal_gpio_irq_release(pin);
+ hal_gpio_irq_disable(pin);
+
+ index = hal_gpio_find_empty_slot();
+ if (index == HAL_GPIO_MAX_IRQ) {
+ return -1;
+ }
+
+ ret = hal_gpio_init_in(pin, pull);
+ if (ret < 0) {
+ return ret;
+ }
+
+ __HAL_DISABLE_INTERRUPTS(ctx);
+ hal_gpio_irqs[index].arg = arg;
+ hal_gpio_irqs[index].pin = pin;
+ hal_gpio_irqs[index].trig = trig;
+ hal_gpio_irqs[index].handler = handler;
+ __HAL_ENABLE_INTERRUPTS(ctx);
+
+ return 0;
+}
+
+void
+hal_gpio_irq_release(int pin)
+{
+ uint32_t ctx;
+ uint8_t index = hal_gpio_find_pin(pin);
+ if (index == HAL_GPIO_MAX_IRQ) {
+ return;
+ }
+
+ __HAL_DISABLE_INTERRUPTS(ctx);
+ hal_gpio_irqs[index].handler = NULL;
+ __HAL_ENABLE_INTERRUPTS(ctx);
+}
+
+void
+hal_gpio_irq_enable(int pin)
+{
+ volatile uint32_t dummy;
+ uint32_t port, mask, ctx;
+
+ uint8_t index = hal_gpio_find_pin(pin);
+ if (index == HAL_GPIO_MAX_IRQ)
+ return;
+
+ port = GPIO_PORT(pin);
+ mask = GPIO_MASK(pin);
+
+ __HAL_DISABLE_INTERRUPTS(ctx);
+
+ /* Enable Change Notice module for the port */
+ CNCONxSET(port) = _CNCONA_ON_MASK | _CNCONA_EDGEDETECT_MASK;
+
+ switch (hal_gpio_irqs[index].trig) {
+ case HAL_GPIO_TRIG_RISING:
+ CNENxSET(port) = mask;
+ break;
+ case HAL_GPIO_TRIG_FALLING:
+ CNNExSET(port) = mask;
+ break;
+ case HAL_GPIO_TRIG_BOTH:
+ CNENxSET(port) = mask;
+ CNNExSET(port) = mask;
+ break;
+ default:
+ break;
+ }
+
+ /* Set interrupt priority */
+ switch (port) {
+ case 0:
+ IPC29CLR = (_IPC29_CNAIP_MASK | _IPC29_CNAIS_MASK);
+ IPC29 |= 1 << _IPC29_CNAIP_POSITION;
+ break;
+ case 1:
+ IPC29CLR = (_IPC29_CNBIP_MASK | _IPC29_CNBIS_MASK);
+ IPC29 |= 1 << _IPC29_CNBIP_POSITION;
+ break;
+ case 2:
+ IPC30CLR = (_IPC30_CNCIP_MASK | _IPC30_CNCIS_MASK);
+ IPC30 |= 1 << _IPC30_CNCIP_POSITION;
+ break;
+ case 3:
+ IPC30CLR = (_IPC30_CNDIP_MASK | _IPC30_CNDIS_MASK);
+ IPC30 |= 1 << _IPC30_CNDIP_POSITION;
+ break;
+ case 4:
+ IPC30CLR = (_IPC30_CNEIP_MASK | _IPC30_CNEIS_MASK);
+ IPC30 |= 1 << _IPC30_CNEIP_POSITION;
+ break;
+ case 5:
+ IPC30CLR = (_IPC30_CNFIP_MASK | _IPC30_CNFIS_MASK);
+ IPC30 |= 1 << _IPC30_CNFIP_POSITION;
+ break;
+ case 6:
+ IPC31CLR = (_IPC31_CNGIP_MASK | _IPC31_CNGIS_MASK);
+ IPC31 |= 1 << _IPC31_CNGIP_POSITION;
+ break;
+ }
+
+ /* Clear interrupt flag and enable Change Notice interrupt */
+ switch (port) {
+ case 0:
+ IFS3CLR = _IFS3_CNAIF_MASK;
+ IEC3SET = _IEC3_CNAIE_MASK;
+ break;
+ case 1:
+ IFS3CLR = _IFS3_CNBIF_MASK;
+ IEC3SET = _IEC3_CNBIE_MASK;
+ break;
+ case 2:
+ IFS3CLR = _IFS3_CNCIF_MASK;
+ IEC3SET = _IEC3_CNCIE_MASK;
+ break;
+ case 3:
+ IFS3CLR = _IFS3_CNDIF_MASK;
+ IEC3SET = _IEC3_CNDIE_MASK;
+ break;
+ case 4:
+ IFS3CLR = _IFS3_CNEIF_MASK;
+ IEC3SET = _IEC3_CNEIE_MASK;
+ break;
+ case 5:
+ IFS3CLR = _IFS3_CNFIF_MASK;
+ IEC3SET = _IEC3_CNFIE_MASK;
+ break;
+ case 6:
+ IFS3CLR = _IFS3_CNGIF_MASK;
+ IEC3SET = _IEC3_CNGIE_MASK;
+ break;
+ }
+
+ __HAL_ENABLE_INTERRUPTS(ctx);
+}
+
+void
+hal_gpio_irq_disable(int pin)
+{
+ uint32_t port = GPIO_PORT(pin);
+ uint32_t mask = GPIO_MASK(pin);
+
+ CNENxCLR(port) = mask;
+ CNNExCLR(port) = mask;
+}
\ No newline at end of file
[17/40] incubator-mynewt-core git commit: MYNEWT-741 Port of
LoRaMac-node library
Posted by ja...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9986f68c/hw/drivers/lora/node/radio/sx1276/src/sx1276Regs-Fsk.h
----------------------------------------------------------------------
diff --git a/hw/drivers/lora/node/radio/sx1276/src/sx1276Regs-Fsk.h b/hw/drivers/lora/node/radio/sx1276/src/sx1276Regs-Fsk.h
new file mode 100644
index 0000000..5bdd895
--- /dev/null
+++ b/hw/drivers/lora/node/radio/sx1276/src/sx1276Regs-Fsk.h
@@ -0,0 +1,1134 @@
+/*
+ / _____) _ | |
+( (____ _____ ____ _| |_ _____ ____| |__
+ \____ \| ___ | (_ _) ___ |/ ___) _ \
+ _____) ) ____| | | || |_| ____( (___| | | |
+(______/|_____)_|_|_| \__)_____)\____)_| |_|
+ (C)2013 Semtech
+
+Description: SX1276 FSK modem registers and bits definitions
+
+License: Revised BSD License, see LICENSE.TXT file include in the project
+
+Maintainer: Miguel Luis and Gregory Cristian
+*/
+#ifndef __SX1276_REGS_FSK_H__
+#define __SX1276_REGS_FSK_H__
+
+/*!
+ * ============================================================================
+ * SX1276 Internal registers Address
+ * ============================================================================
+ */
+#define REG_FIFO 0x00
+// Common settings
+#define REG_OPMODE 0x01
+#define REG_BITRATEMSB 0x02
+#define REG_BITRATELSB 0x03
+#define REG_FDEVMSB 0x04
+#define REG_FDEVLSB 0x05
+#define REG_FRFMSB 0x06
+#define REG_FRFMID 0x07
+#define REG_FRFLSB 0x08
+// Tx settings
+#define REG_PACONFIG 0x09
+#define REG_PARAMP 0x0A
+#define REG_OCP 0x0B
+// Rx settings
+#define REG_LNA 0x0C
+#define REG_RXCONFIG 0x0D
+#define REG_RSSICONFIG 0x0E
+#define REG_RSSICOLLISION 0x0F
+#define REG_RSSITHRESH 0x10
+#define REG_RSSIVALUE 0x11
+#define REG_RXBW 0x12
+#define REG_AFCBW 0x13
+#define REG_OOKPEAK 0x14
+#define REG_OOKFIX 0x15
+#define REG_OOKAVG 0x16
+#define REG_RES17 0x17
+#define REG_RES18 0x18
+#define REG_RES19 0x19
+#define REG_AFCFEI 0x1A
+#define REG_AFCMSB 0x1B
+#define REG_AFCLSB 0x1C
+#define REG_FEIMSB 0x1D
+#define REG_FEILSB 0x1E
+#define REG_PREAMBLEDETECT 0x1F
+#define REG_RXTIMEOUT1 0x20
+#define REG_RXTIMEOUT2 0x21
+#define REG_RXTIMEOUT3 0x22
+#define REG_RXDELAY 0x23
+// Oscillator settings
+#define REG_OSC 0x24
+// Packet handler settings
+#define REG_PREAMBLEMSB 0x25
+#define REG_PREAMBLELSB 0x26
+#define REG_SYNCCONFIG 0x27
+#define REG_SYNCVALUE1 0x28
+#define REG_SYNCVALUE2 0x29
+#define REG_SYNCVALUE3 0x2A
+#define REG_SYNCVALUE4 0x2B
+#define REG_SYNCVALUE5 0x2C
+#define REG_SYNCVALUE6 0x2D
+#define REG_SYNCVALUE7 0x2E
+#define REG_SYNCVALUE8 0x2F
+#define REG_PACKETCONFIG1 0x30
+#define REG_PACKETCONFIG2 0x31
+#define REG_PAYLOADLENGTH 0x32
+#define REG_NODEADRS 0x33
+#define REG_BROADCASTADRS 0x34
+#define REG_FIFOTHRESH 0x35
+// SM settings
+#define REG_SEQCONFIG1 0x36
+#define REG_SEQCONFIG2 0x37
+#define REG_TIMERRESOL 0x38
+#define REG_TIMER1COEF 0x39
+#define REG_TIMER2COEF 0x3A
+// Service settings
+#define REG_IMAGECAL 0x3B
+#define REG_TEMP 0x3C
+#define REG_LOWBAT 0x3D
+// Status
+#define REG_IRQFLAGS1 0x3E
+#define REG_IRQFLAGS2 0x3F
+// I/O settings
+#define REG_DIOMAPPING1 0x40
+#define REG_DIOMAPPING2 0x41
+// Version
+#define REG_VERSION 0x42
+// Additional settings
+#define REG_PLLHOP 0x44
+#define REG_TCXO 0x4B
+#define REG_PADAC 0x4D
+#define REG_FORMERTEMP 0x5B
+#define REG_BITRATEFRAC 0x5D
+#define REG_AGCREF 0x61
+#define REG_AGCTHRESH1 0x62
+#define REG_AGCTHRESH2 0x63
+#define REG_AGCTHRESH3 0x64
+#define REG_PLL 0x70
+
+/*!
+ * ============================================================================
+ * SX1276 FSK bits control definition
+ * ============================================================================
+ */
+
+/*!
+ * RegFifo
+ */
+
+/*!
+ * RegOpMode
+ */
+#define RF_OPMODE_LONGRANGEMODE_MASK 0x7F
+#define RF_OPMODE_LONGRANGEMODE_OFF 0x00
+#define RF_OPMODE_LONGRANGEMODE_ON 0x80
+
+#define RF_OPMODE_MODULATIONTYPE_MASK 0x9F
+#define RF_OPMODE_MODULATIONTYPE_FSK 0x00 // Default
+#define RF_OPMODE_MODULATIONTYPE_OOK 0x20
+
+#define RF_OPMODE_MODULATIONSHAPING_MASK 0xE7
+#define RF_OPMODE_MODULATIONSHAPING_00 0x00 // Default
+#define RF_OPMODE_MODULATIONSHAPING_01 0x08
+#define RF_OPMODE_MODULATIONSHAPING_10 0x10
+#define RF_OPMODE_MODULATIONSHAPING_11 0x18
+
+#define RF_OPMODE_MASK 0xF8
+#define RF_OPMODE_SLEEP 0x00
+#define RF_OPMODE_STANDBY 0x01 // Default
+#define RF_OPMODE_SYNTHESIZER_TX 0x02
+#define RF_OPMODE_TRANSMITTER 0x03
+#define RF_OPMODE_SYNTHESIZER_RX 0x04
+#define RF_OPMODE_RECEIVER 0x05
+
+/*!
+ * RegBitRate (bits/sec)
+ */
+#define RF_BITRATEMSB_1200_BPS 0x68
+#define RF_BITRATELSB_1200_BPS 0x2B
+#define RF_BITRATEMSB_2400_BPS 0x34
+#define RF_BITRATELSB_2400_BPS 0x15
+#define RF_BITRATEMSB_4800_BPS 0x1A // Default
+#define RF_BITRATELSB_4800_BPS 0x0B // Default
+#define RF_BITRATEMSB_9600_BPS 0x0D
+#define RF_BITRATELSB_9600_BPS 0x05
+#define RF_BITRATEMSB_15000_BPS 0x08
+#define RF_BITRATELSB_15000_BPS 0x55
+#define RF_BITRATEMSB_19200_BPS 0x06
+#define RF_BITRATELSB_19200_BPS 0x83
+#define RF_BITRATEMSB_38400_BPS 0x03
+#define RF_BITRATELSB_38400_BPS 0x41
+#define RF_BITRATEMSB_76800_BPS 0x01
+#define RF_BITRATELSB_76800_BPS 0xA1
+#define RF_BITRATEMSB_153600_BPS 0x00
+#define RF_BITRATELSB_153600_BPS 0xD0
+#define RF_BITRATEMSB_57600_BPS 0x02
+#define RF_BITRATELSB_57600_BPS 0x2C
+#define RF_BITRATEMSB_115200_BPS 0x01
+#define RF_BITRATELSB_115200_BPS 0x16
+#define RF_BITRATEMSB_12500_BPS 0x0A
+#define RF_BITRATELSB_12500_BPS 0x00
+#define RF_BITRATEMSB_25000_BPS 0x05
+#define RF_BITRATELSB_25000_BPS 0x00
+#define RF_BITRATEMSB_50000_BPS 0x02
+#define RF_BITRATELSB_50000_BPS 0x80
+#define RF_BITRATEMSB_100000_BPS 0x01
+#define RF_BITRATELSB_100000_BPS 0x40
+#define RF_BITRATEMSB_150000_BPS 0x00
+#define RF_BITRATELSB_150000_BPS 0xD5
+#define RF_BITRATEMSB_200000_BPS 0x00
+#define RF_BITRATELSB_200000_BPS 0xA0
+#define RF_BITRATEMSB_250000_BPS 0x00
+#define RF_BITRATELSB_250000_BPS 0x80
+#define RF_BITRATEMSB_32768_BPS 0x03
+#define RF_BITRATELSB_32768_BPS 0xD1
+
+/*!
+ * RegFdev (Hz)
+ */
+#define RF_FDEVMSB_2000_HZ 0x00
+#define RF_FDEVLSB_2000_HZ 0x21
+#define RF_FDEVMSB_5000_HZ 0x00 // Default
+#define RF_FDEVLSB_5000_HZ 0x52 // Default
+#define RF_FDEVMSB_10000_HZ 0x00
+#define RF_FDEVLSB_10000_HZ 0xA4
+#define RF_FDEVMSB_15000_HZ 0x00
+#define RF_FDEVLSB_15000_HZ 0xF6
+#define RF_FDEVMSB_20000_HZ 0x01
+#define RF_FDEVLSB_20000_HZ 0x48
+#define RF_FDEVMSB_25000_HZ 0x01
+#define RF_FDEVLSB_25000_HZ 0x9A
+#define RF_FDEVMSB_30000_HZ 0x01
+#define RF_FDEVLSB_30000_HZ 0xEC
+#define RF_FDEVMSB_35000_HZ 0x02
+#define RF_FDEVLSB_35000_HZ 0x3D
+#define RF_FDEVMSB_40000_HZ 0x02
+#define RF_FDEVLSB_40000_HZ 0x8F
+#define RF_FDEVMSB_45000_HZ 0x02
+#define RF_FDEVLSB_45000_HZ 0xE1
+#define RF_FDEVMSB_50000_HZ 0x03
+#define RF_FDEVLSB_50000_HZ 0x33
+#define RF_FDEVMSB_55000_HZ 0x03
+#define RF_FDEVLSB_55000_HZ 0x85
+#define RF_FDEVMSB_60000_HZ 0x03
+#define RF_FDEVLSB_60000_HZ 0xD7
+#define RF_FDEVMSB_65000_HZ 0x04
+#define RF_FDEVLSB_65000_HZ 0x29
+#define RF_FDEVMSB_70000_HZ 0x04
+#define RF_FDEVLSB_70000_HZ 0x7B
+#define RF_FDEVMSB_75000_HZ 0x04
+#define RF_FDEVLSB_75000_HZ 0xCD
+#define RF_FDEVMSB_80000_HZ 0x05
+#define RF_FDEVLSB_80000_HZ 0x1F
+#define RF_FDEVMSB_85000_HZ 0x05
+#define RF_FDEVLSB_85000_HZ 0x71
+#define RF_FDEVMSB_90000_HZ 0x05
+#define RF_FDEVLSB_90000_HZ 0xC3
+#define RF_FDEVMSB_95000_HZ 0x06
+#define RF_FDEVLSB_95000_HZ 0x14
+#define RF_FDEVMSB_100000_HZ 0x06
+#define RF_FDEVLSB_100000_HZ 0x66
+#define RF_FDEVMSB_110000_HZ 0x07
+#define RF_FDEVLSB_110000_HZ 0x0A
+#define RF_FDEVMSB_120000_HZ 0x07
+#define RF_FDEVLSB_120000_HZ 0xAE
+#define RF_FDEVMSB_130000_HZ 0x08
+#define RF_FDEVLSB_130000_HZ 0x52
+#define RF_FDEVMSB_140000_HZ 0x08
+#define RF_FDEVLSB_140000_HZ 0xF6
+#define RF_FDEVMSB_150000_HZ 0x09
+#define RF_FDEVLSB_150000_HZ 0x9A
+#define RF_FDEVMSB_160000_HZ 0x0A
+#define RF_FDEVLSB_160000_HZ 0x3D
+#define RF_FDEVMSB_170000_HZ 0x0A
+#define RF_FDEVLSB_170000_HZ 0xE1
+#define RF_FDEVMSB_180000_HZ 0x0B
+#define RF_FDEVLSB_180000_HZ 0x85
+#define RF_FDEVMSB_190000_HZ 0x0C
+#define RF_FDEVLSB_190000_HZ 0x29
+#define RF_FDEVMSB_200000_HZ 0x0C
+#define RF_FDEVLSB_200000_HZ 0xCD
+
+/*!
+ * RegFrf (MHz)
+ */
+#define RF_FRFMSB_863_MHZ 0xD7
+#define RF_FRFMID_863_MHZ 0xC0
+#define RF_FRFLSB_863_MHZ 0x00
+#define RF_FRFMSB_864_MHZ 0xD8
+#define RF_FRFMID_864_MHZ 0x00
+#define RF_FRFLSB_864_MHZ 0x00
+#define RF_FRFMSB_865_MHZ 0xD8
+#define RF_FRFMID_865_MHZ 0x40
+#define RF_FRFLSB_865_MHZ 0x00
+#define RF_FRFMSB_866_MHZ 0xD8
+#define RF_FRFMID_866_MHZ 0x80
+#define RF_FRFLSB_866_MHZ 0x00
+#define RF_FRFMSB_867_MHZ 0xD8
+#define RF_FRFMID_867_MHZ 0xC0
+#define RF_FRFLSB_867_MHZ 0x00
+#define RF_FRFMSB_868_MHZ 0xD9
+#define RF_FRFMID_868_MHZ 0x00
+#define RF_FRFLSB_868_MHZ 0x00
+#define RF_FRFMSB_869_MHZ 0xD9
+#define RF_FRFMID_869_MHZ 0x40
+#define RF_FRFLSB_869_MHZ 0x00
+#define RF_FRFMSB_870_MHZ 0xD9
+#define RF_FRFMID_870_MHZ 0x80
+#define RF_FRFLSB_870_MHZ 0x00
+
+#define RF_FRFMSB_902_MHZ 0xE1
+#define RF_FRFMID_902_MHZ 0x80
+#define RF_FRFLSB_902_MHZ 0x00
+#define RF_FRFMSB_903_MHZ 0xE1
+#define RF_FRFMID_903_MHZ 0xC0
+#define RF_FRFLSB_903_MHZ 0x00
+#define RF_FRFMSB_904_MHZ 0xE2
+#define RF_FRFMID_904_MHZ 0x00
+#define RF_FRFLSB_904_MHZ 0x00
+#define RF_FRFMSB_905_MHZ 0xE2
+#define RF_FRFMID_905_MHZ 0x40
+#define RF_FRFLSB_905_MHZ 0x00
+#define RF_FRFMSB_906_MHZ 0xE2
+#define RF_FRFMID_906_MHZ 0x80
+#define RF_FRFLSB_906_MHZ 0x00
+#define RF_FRFMSB_907_MHZ 0xE2
+#define RF_FRFMID_907_MHZ 0xC0
+#define RF_FRFLSB_907_MHZ 0x00
+#define RF_FRFMSB_908_MHZ 0xE3
+#define RF_FRFMID_908_MHZ 0x00
+#define RF_FRFLSB_908_MHZ 0x00
+#define RF_FRFMSB_909_MHZ 0xE3
+#define RF_FRFMID_909_MHZ 0x40
+#define RF_FRFLSB_909_MHZ 0x00
+#define RF_FRFMSB_910_MHZ 0xE3
+#define RF_FRFMID_910_MHZ 0x80
+#define RF_FRFLSB_910_MHZ 0x00
+#define RF_FRFMSB_911_MHZ 0xE3
+#define RF_FRFMID_911_MHZ 0xC0
+#define RF_FRFLSB_911_MHZ 0x00
+#define RF_FRFMSB_912_MHZ 0xE4
+#define RF_FRFMID_912_MHZ 0x00
+#define RF_FRFLSB_912_MHZ 0x00
+#define RF_FRFMSB_913_MHZ 0xE4
+#define RF_FRFMID_913_MHZ 0x40
+#define RF_FRFLSB_913_MHZ 0x00
+#define RF_FRFMSB_914_MHZ 0xE4
+#define RF_FRFMID_914_MHZ 0x80
+#define RF_FRFLSB_914_MHZ 0x00
+#define RF_FRFMSB_915_MHZ 0xE4 // Default
+#define RF_FRFMID_915_MHZ 0xC0 // Default
+#define RF_FRFLSB_915_MHZ 0x00 // Default
+#define RF_FRFMSB_916_MHZ 0xE5
+#define RF_FRFMID_916_MHZ 0x00
+#define RF_FRFLSB_916_MHZ 0x00
+#define RF_FRFMSB_917_MHZ 0xE5
+#define RF_FRFMID_917_MHZ 0x40
+#define RF_FRFLSB_917_MHZ 0x00
+#define RF_FRFMSB_918_MHZ 0xE5
+#define RF_FRFMID_918_MHZ 0x80
+#define RF_FRFLSB_918_MHZ 0x00
+#define RF_FRFMSB_919_MHZ 0xE5
+#define RF_FRFMID_919_MHZ 0xC0
+#define RF_FRFLSB_919_MHZ 0x00
+#define RF_FRFMSB_920_MHZ 0xE6
+#define RF_FRFMID_920_MHZ 0x00
+#define RF_FRFLSB_920_MHZ 0x00
+#define RF_FRFMSB_921_MHZ 0xE6
+#define RF_FRFMID_921_MHZ 0x40
+#define RF_FRFLSB_921_MHZ 0x00
+#define RF_FRFMSB_922_MHZ 0xE6
+#define RF_FRFMID_922_MHZ 0x80
+#define RF_FRFLSB_922_MHZ 0x00
+#define RF_FRFMSB_923_MHZ 0xE6
+#define RF_FRFMID_923_MHZ 0xC0
+#define RF_FRFLSB_923_MHZ 0x00
+#define RF_FRFMSB_924_MHZ 0xE7
+#define RF_FRFMID_924_MHZ 0x00
+#define RF_FRFLSB_924_MHZ 0x00
+#define RF_FRFMSB_925_MHZ 0xE7
+#define RF_FRFMID_925_MHZ 0x40
+#define RF_FRFLSB_925_MHZ 0x00
+#define RF_FRFMSB_926_MHZ 0xE7
+#define RF_FRFMID_926_MHZ 0x80
+#define RF_FRFLSB_926_MHZ 0x00
+#define RF_FRFMSB_927_MHZ 0xE7
+#define RF_FRFMID_927_MHZ 0xC0
+#define RF_FRFLSB_927_MHZ 0x00
+#define RF_FRFMSB_928_MHZ 0xE8
+#define RF_FRFMID_928_MHZ 0x00
+#define RF_FRFLSB_928_MHZ 0x00
+
+/*!
+ * RegPaConfig
+ */
+#define RF_PACONFIG_PASELECT_MASK 0x7F
+#define RF_PACONFIG_PASELECT_PABOOST 0x80
+#define RF_PACONFIG_PASELECT_RFO 0x00 // Default
+
+#define RF_PACONFIG_MAX_POWER_MASK 0x8F
+
+#define RF_PACONFIG_OUTPUTPOWER_MASK 0xF0
+
+/*!
+ * RegPaRamp
+ */
+#define RF_PARAMP_MODULATIONSHAPING_MASK 0x9F
+#define RF_PARAMP_MODULATIONSHAPING_00 0x00 // Default
+#define RF_PARAMP_MODULATIONSHAPING_01 0x20
+#define RF_PARAMP_MODULATIONSHAPING_10 0x40
+#define RF_PARAMP_MODULATIONSHAPING_11 0x60
+
+#define RF_PARAMP_LOWPNTXPLL_MASK 0xEF
+#define RF_PARAMP_LOWPNTXPLL_OFF 0x10
+#define RF_PARAMP_LOWPNTXPLL_ON 0x00 // Default
+
+#define RF_PARAMP_MASK 0xF0
+#define RF_PARAMP_3400_US 0x00
+#define RF_PARAMP_2000_US 0x01
+#define RF_PARAMP_1000_US 0x02
+#define RF_PARAMP_0500_US 0x03
+#define RF_PARAMP_0250_US 0x04
+#define RF_PARAMP_0125_US 0x05
+#define RF_PARAMP_0100_US 0x06
+#define RF_PARAMP_0062_US 0x07
+#define RF_PARAMP_0050_US 0x08
+#define RF_PARAMP_0040_US 0x09 // Default
+#define RF_PARAMP_0031_US 0x0A
+#define RF_PARAMP_0025_US 0x0B
+#define RF_PARAMP_0020_US 0x0C
+#define RF_PARAMP_0015_US 0x0D
+#define RF_PARAMP_0012_US 0x0E
+#define RF_PARAMP_0010_US 0x0F
+
+/*!
+ * RegOcp
+ */
+#define RF_OCP_MASK 0xDF
+#define RF_OCP_ON 0x20 // Default
+#define RF_OCP_OFF 0x00
+
+#define RF_OCP_TRIM_MASK 0xE0
+#define RF_OCP_TRIM_045_MA 0x00
+#define RF_OCP_TRIM_050_MA 0x01
+#define RF_OCP_TRIM_055_MA 0x02
+#define RF_OCP_TRIM_060_MA 0x03
+#define RF_OCP_TRIM_065_MA 0x04
+#define RF_OCP_TRIM_070_MA 0x05
+#define RF_OCP_TRIM_075_MA 0x06
+#define RF_OCP_TRIM_080_MA 0x07
+#define RF_OCP_TRIM_085_MA 0x08
+#define RF_OCP_TRIM_090_MA 0x09
+#define RF_OCP_TRIM_095_MA 0x0A
+#define RF_OCP_TRIM_100_MA 0x0B // Default
+#define RF_OCP_TRIM_105_MA 0x0C
+#define RF_OCP_TRIM_110_MA 0x0D
+#define RF_OCP_TRIM_115_MA 0x0E
+#define RF_OCP_TRIM_120_MA 0x0F
+#define RF_OCP_TRIM_130_MA 0x10
+#define RF_OCP_TRIM_140_MA 0x11
+#define RF_OCP_TRIM_150_MA 0x12
+#define RF_OCP_TRIM_160_MA 0x13
+#define RF_OCP_TRIM_170_MA 0x14
+#define RF_OCP_TRIM_180_MA 0x15
+#define RF_OCP_TRIM_190_MA 0x16
+#define RF_OCP_TRIM_200_MA 0x17
+#define RF_OCP_TRIM_210_MA 0x18
+#define RF_OCP_TRIM_220_MA 0x19
+#define RF_OCP_TRIM_230_MA 0x1A
+#define RF_OCP_TRIM_240_MA 0x1B
+
+/*!
+ * RegLna
+ */
+#define RF_LNA_GAIN_MASK 0x1F
+#define RF_LNA_GAIN_G1 0x20 // Default
+#define RF_LNA_GAIN_G2 0x40
+#define RF_LNA_GAIN_G3 0x60
+#define RF_LNA_GAIN_G4 0x80
+#define RF_LNA_GAIN_G5 0xA0
+#define RF_LNA_GAIN_G6 0xC0
+
+#define RF_LNA_BOOST_MASK 0xFC
+#define RF_LNA_BOOST_OFF 0x00 // Default
+#define RF_LNA_BOOST_ON 0x03
+
+/*!
+ * RegRxConfig
+ */
+#define RF_RXCONFIG_RESTARTRXONCOLLISION_MASK 0x7F
+#define RF_RXCONFIG_RESTARTRXONCOLLISION_ON 0x80
+#define RF_RXCONFIG_RESTARTRXONCOLLISION_OFF 0x00 // Default
+
+#define RF_RXCONFIG_RESTARTRXWITHOUTPLLLOCK 0x40 // Write only
+
+#define RF_RXCONFIG_RESTARTRXWITHPLLLOCK 0x20 // Write only
+
+#define RF_RXCONFIG_AFCAUTO_MASK 0xEF
+#define RF_RXCONFIG_AFCAUTO_ON 0x10
+#define RF_RXCONFIG_AFCAUTO_OFF 0x00 // Default
+
+#define RF_RXCONFIG_AGCAUTO_MASK 0xF7
+#define RF_RXCONFIG_AGCAUTO_ON 0x08 // Default
+#define RF_RXCONFIG_AGCAUTO_OFF 0x00
+
+#define RF_RXCONFIG_RXTRIGER_MASK 0xF8
+#define RF_RXCONFIG_RXTRIGER_OFF 0x00
+#define RF_RXCONFIG_RXTRIGER_RSSI 0x01
+#define RF_RXCONFIG_RXTRIGER_PREAMBLEDETECT 0x06 // Default
+#define RF_RXCONFIG_RXTRIGER_RSSI_PREAMBLEDETECT 0x07
+
+/*!
+ * RegRssiConfig
+ */
+#define RF_RSSICONFIG_OFFSET_MASK 0x07
+#define RF_RSSICONFIG_OFFSET_P_00_DB 0x00 // Default
+#define RF_RSSICONFIG_OFFSET_P_01_DB 0x08
+#define RF_RSSICONFIG_OFFSET_P_02_DB 0x10
+#define RF_RSSICONFIG_OFFSET_P_03_DB 0x18
+#define RF_RSSICONFIG_OFFSET_P_04_DB 0x20
+#define RF_RSSICONFIG_OFFSET_P_05_DB 0x28
+#define RF_RSSICONFIG_OFFSET_P_06_DB 0x30
+#define RF_RSSICONFIG_OFFSET_P_07_DB 0x38
+#define RF_RSSICONFIG_OFFSET_P_08_DB 0x40
+#define RF_RSSICONFIG_OFFSET_P_09_DB 0x48
+#define RF_RSSICONFIG_OFFSET_P_10_DB 0x50
+#define RF_RSSICONFIG_OFFSET_P_11_DB 0x58
+#define RF_RSSICONFIG_OFFSET_P_12_DB 0x60
+#define RF_RSSICONFIG_OFFSET_P_13_DB 0x68
+#define RF_RSSICONFIG_OFFSET_P_14_DB 0x70
+#define RF_RSSICONFIG_OFFSET_P_15_DB 0x78
+#define RF_RSSICONFIG_OFFSET_M_16_DB 0x80
+#define RF_RSSICONFIG_OFFSET_M_15_DB 0x88
+#define RF_RSSICONFIG_OFFSET_M_14_DB 0x90
+#define RF_RSSICONFIG_OFFSET_M_13_DB 0x98
+#define RF_RSSICONFIG_OFFSET_M_12_DB 0xA0
+#define RF_RSSICONFIG_OFFSET_M_11_DB 0xA8
+#define RF_RSSICONFIG_OFFSET_M_10_DB 0xB0
+#define RF_RSSICONFIG_OFFSET_M_09_DB 0xB8
+#define RF_RSSICONFIG_OFFSET_M_08_DB 0xC0
+#define RF_RSSICONFIG_OFFSET_M_07_DB 0xC8
+#define RF_RSSICONFIG_OFFSET_M_06_DB 0xD0
+#define RF_RSSICONFIG_OFFSET_M_05_DB 0xD8
+#define RF_RSSICONFIG_OFFSET_M_04_DB 0xE0
+#define RF_RSSICONFIG_OFFSET_M_03_DB 0xE8
+#define RF_RSSICONFIG_OFFSET_M_02_DB 0xF0
+#define RF_RSSICONFIG_OFFSET_M_01_DB 0xF8
+
+#define RF_RSSICONFIG_SMOOTHING_MASK 0xF8
+#define RF_RSSICONFIG_SMOOTHING_2 0x00
+#define RF_RSSICONFIG_SMOOTHING_4 0x01
+#define RF_RSSICONFIG_SMOOTHING_8 0x02 // Default
+#define RF_RSSICONFIG_SMOOTHING_16 0x03
+#define RF_RSSICONFIG_SMOOTHING_32 0x04
+#define RF_RSSICONFIG_SMOOTHING_64 0x05
+#define RF_RSSICONFIG_SMOOTHING_128 0x06
+#define RF_RSSICONFIG_SMOOTHING_256 0x07
+
+/*!
+ * RegRssiCollision
+ */
+#define RF_RSSICOLISION_THRESHOLD 0x0A // Default
+
+/*!
+ * RegRssiThresh
+ */
+#define RF_RSSITHRESH_THRESHOLD 0xFF // Default
+
+/*!
+ * RegRssiValue (Read Only)
+ */
+
+/*!
+ * RegRxBw
+ */
+#define RF_RXBW_MANT_MASK 0xE7
+#define RF_RXBW_MANT_16 0x00
+#define RF_RXBW_MANT_20 0x08
+#define RF_RXBW_MANT_24 0x10 // Default
+
+#define RF_RXBW_EXP_MASK 0xF8
+#define RF_RXBW_EXP_0 0x00
+#define RF_RXBW_EXP_1 0x01
+#define RF_RXBW_EXP_2 0x02
+#define RF_RXBW_EXP_3 0x03
+#define RF_RXBW_EXP_4 0x04
+#define RF_RXBW_EXP_5 0x05 // Default
+#define RF_RXBW_EXP_6 0x06
+#define RF_RXBW_EXP_7 0x07
+
+/*!
+ * RegAfcBw
+ */
+#define RF_AFCBW_MANTAFC_MASK 0xE7
+#define RF_AFCBW_MANTAFC_16 0x00
+#define RF_AFCBW_MANTAFC_20 0x08 // Default
+#define RF_AFCBW_MANTAFC_24 0x10
+
+#define RF_AFCBW_EXPAFC_MASK 0xF8
+#define RF_AFCBW_EXPAFC_0 0x00
+#define RF_AFCBW_EXPAFC_1 0x01
+#define RF_AFCBW_EXPAFC_2 0x02
+#define RF_AFCBW_EXPAFC_3 0x03 // Default
+#define RF_AFCBW_EXPAFC_4 0x04
+#define RF_AFCBW_EXPAFC_5 0x05
+#define RF_AFCBW_EXPAFC_6 0x06
+#define RF_AFCBW_EXPAFC_7 0x07
+
+/*!
+ * RegOokPeak
+ */
+#define RF_OOKPEAK_BITSYNC_MASK 0xDF // Default
+#define RF_OOKPEAK_BITSYNC_ON 0x20 // Default
+#define RF_OOKPEAK_BITSYNC_OFF 0x00
+
+#define RF_OOKPEAK_OOKTHRESHTYPE_MASK 0xE7
+#define RF_OOKPEAK_OOKTHRESHTYPE_FIXED 0x00
+#define RF_OOKPEAK_OOKTHRESHTYPE_PEAK 0x08 // Default
+#define RF_OOKPEAK_OOKTHRESHTYPE_AVERAGE 0x10
+
+#define RF_OOKPEAK_OOKPEAKTHRESHSTEP_MASK 0xF8
+#define RF_OOKPEAK_OOKPEAKTHRESHSTEP_0_5_DB 0x00 // Default
+#define RF_OOKPEAK_OOKPEAKTHRESHSTEP_1_0_DB 0x01
+#define RF_OOKPEAK_OOKPEAKTHRESHSTEP_1_5_DB 0x02
+#define RF_OOKPEAK_OOKPEAKTHRESHSTEP_2_0_DB 0x03
+#define RF_OOKPEAK_OOKPEAKTHRESHSTEP_3_0_DB 0x04
+#define RF_OOKPEAK_OOKPEAKTHRESHSTEP_4_0_DB 0x05
+#define RF_OOKPEAK_OOKPEAKTHRESHSTEP_5_0_DB 0x06
+#define RF_OOKPEAK_OOKPEAKTHRESHSTEP_6_0_DB 0x07
+
+/*!
+ * RegOokFix
+ */
+#define RF_OOKFIX_OOKFIXEDTHRESHOLD 0x0C // Default
+
+/*!
+ * RegOokAvg
+ */
+#define RF_OOKAVG_OOKPEAKTHRESHDEC_MASK 0x1F
+#define RF_OOKAVG_OOKPEAKTHRESHDEC_000 0x00 // Default
+#define RF_OOKAVG_OOKPEAKTHRESHDEC_001 0x20
+#define RF_OOKAVG_OOKPEAKTHRESHDEC_010 0x40
+#define RF_OOKAVG_OOKPEAKTHRESHDEC_011 0x60
+#define RF_OOKAVG_OOKPEAKTHRESHDEC_100 0x80
+#define RF_OOKAVG_OOKPEAKTHRESHDEC_101 0xA0
+#define RF_OOKAVG_OOKPEAKTHRESHDEC_110 0xC0
+#define RF_OOKAVG_OOKPEAKTHRESHDEC_111 0xE0
+
+#define RF_OOKAVG_AVERAGEOFFSET_MASK 0xF3
+#define RF_OOKAVG_AVERAGEOFFSET_0_DB 0x00 // Default
+#define RF_OOKAVG_AVERAGEOFFSET_2_DB 0x04
+#define RF_OOKAVG_AVERAGEOFFSET_4_DB 0x08
+#define RF_OOKAVG_AVERAGEOFFSET_6_DB 0x0C
+
+#define RF_OOKAVG_OOKAVERAGETHRESHFILT_MASK 0xFC
+#define RF_OOKAVG_OOKAVERAGETHRESHFILT_00 0x00
+#define RF_OOKAVG_OOKAVERAGETHRESHFILT_01 0x01
+#define RF_OOKAVG_OOKAVERAGETHRESHFILT_10 0x02 // Default
+#define RF_OOKAVG_OOKAVERAGETHRESHFILT_11 0x03
+
+/*!
+ * RegAfcFei
+ */
+#define RF_AFCFEI_AGCSTART 0x10
+
+#define RF_AFCFEI_AFCCLEAR 0x02
+
+#define RF_AFCFEI_AFCAUTOCLEAR_MASK 0xFE
+#define RF_AFCFEI_AFCAUTOCLEAR_ON 0x01
+#define RF_AFCFEI_AFCAUTOCLEAR_OFF 0x00 // Default
+
+/*!
+ * RegAfcMsb (Read Only)
+ */
+
+/*!
+ * RegAfcLsb (Read Only)
+ */
+
+/*!
+ * RegFeiMsb (Read Only)
+ */
+
+/*!
+ * RegFeiLsb (Read Only)
+ */
+
+/*!
+ * RegPreambleDetect
+ */
+#define RF_PREAMBLEDETECT_DETECTOR_MASK 0x7F
+#define RF_PREAMBLEDETECT_DETECTOR_ON 0x80 // Default
+#define RF_PREAMBLEDETECT_DETECTOR_OFF 0x00
+
+#define RF_PREAMBLEDETECT_DETECTORSIZE_MASK 0x9F
+#define RF_PREAMBLEDETECT_DETECTORSIZE_1 0x00
+#define RF_PREAMBLEDETECT_DETECTORSIZE_2 0x20 // Default
+#define RF_PREAMBLEDETECT_DETECTORSIZE_3 0x40
+#define RF_PREAMBLEDETECT_DETECTORSIZE_4 0x60
+
+#define RF_PREAMBLEDETECT_DETECTORTOL_MASK 0xE0
+#define RF_PREAMBLEDETECT_DETECTORTOL_0 0x00
+#define RF_PREAMBLEDETECT_DETECTORTOL_1 0x01
+#define RF_PREAMBLEDETECT_DETECTORTOL_2 0x02
+#define RF_PREAMBLEDETECT_DETECTORTOL_3 0x03
+#define RF_PREAMBLEDETECT_DETECTORTOL_4 0x04
+#define RF_PREAMBLEDETECT_DETECTORTOL_5 0x05
+#define RF_PREAMBLEDETECT_DETECTORTOL_6 0x06
+#define RF_PREAMBLEDETECT_DETECTORTOL_7 0x07
+#define RF_PREAMBLEDETECT_DETECTORTOL_8 0x08
+#define RF_PREAMBLEDETECT_DETECTORTOL_9 0x09
+#define RF_PREAMBLEDETECT_DETECTORTOL_10 0x0A // Default
+#define RF_PREAMBLEDETECT_DETECTORTOL_11 0x0B
+#define RF_PREAMBLEDETECT_DETECTORTOL_12 0x0C
+#define RF_PREAMBLEDETECT_DETECTORTOL_13 0x0D
+#define RF_PREAMBLEDETECT_DETECTORTOL_14 0x0E
+#define RF_PREAMBLEDETECT_DETECTORTOL_15 0x0F
+#define RF_PREAMBLEDETECT_DETECTORTOL_16 0x10
+#define RF_PREAMBLEDETECT_DETECTORTOL_17 0x11
+#define RF_PREAMBLEDETECT_DETECTORTOL_18 0x12
+#define RF_PREAMBLEDETECT_DETECTORTOL_19 0x13
+#define RF_PREAMBLEDETECT_DETECTORTOL_20 0x14
+#define RF_PREAMBLEDETECT_DETECTORTOL_21 0x15
+#define RF_PREAMBLEDETECT_DETECTORTOL_22 0x16
+#define RF_PREAMBLEDETECT_DETECTORTOL_23 0x17
+#define RF_PREAMBLEDETECT_DETECTORTOL_24 0x18
+#define RF_PREAMBLEDETECT_DETECTORTOL_25 0x19
+#define RF_PREAMBLEDETECT_DETECTORTOL_26 0x1A
+#define RF_PREAMBLEDETECT_DETECTORTOL_27 0x1B
+#define RF_PREAMBLEDETECT_DETECTORTOL_28 0x1C
+#define RF_PREAMBLEDETECT_DETECTORTOL_29 0x1D
+#define RF_PREAMBLEDETECT_DETECTORTOL_30 0x1E
+#define RF_PREAMBLEDETECT_DETECTORTOL_31 0x1F
+
+/*!
+ * RegRxTimeout1
+ */
+#define RF_RXTIMEOUT1_TIMEOUTRXRSSI 0x00 // Default
+
+/*!
+ * RegRxTimeout2
+ */
+#define RF_RXTIMEOUT2_TIMEOUTRXPREAMBLE 0x00 // Default
+
+/*!
+ * RegRxTimeout3
+ */
+#define RF_RXTIMEOUT3_TIMEOUTSIGNALSYNC 0x00 // Default
+
+/*!
+ * RegRxDelay
+ */
+#define RF_RXDELAY_INTERPACKETRXDELAY 0x00 // Default
+
+/*!
+ * RegOsc
+ */
+#define RF_OSC_RCCALSTART 0x08
+
+#define RF_OSC_CLKOUT_MASK 0xF8
+#define RF_OSC_CLKOUT_32_MHZ 0x00
+#define RF_OSC_CLKOUT_16_MHZ 0x01
+#define RF_OSC_CLKOUT_8_MHZ 0x02
+#define RF_OSC_CLKOUT_4_MHZ 0x03
+#define RF_OSC_CLKOUT_2_MHZ 0x04
+#define RF_OSC_CLKOUT_1_MHZ 0x05 // Default
+#define RF_OSC_CLKOUT_RC 0x06
+#define RF_OSC_CLKOUT_OFF 0x07
+
+/*!
+ * RegPreambleMsb/RegPreambleLsb
+ */
+#define RF_PREAMBLEMSB_SIZE 0x00 // Default
+#define RF_PREAMBLELSB_SIZE 0x03 // Default
+
+/*!
+ * RegSyncConfig
+ */
+#define RF_SYNCCONFIG_AUTORESTARTRXMODE_MASK 0x3F
+#define RF_SYNCCONFIG_AUTORESTARTRXMODE_WAITPLL_ON 0x80 // Default
+#define RF_SYNCCONFIG_AUTORESTARTRXMODE_WAITPLL_OFF 0x40
+#define RF_SYNCCONFIG_AUTORESTARTRXMODE_OFF 0x00
+
+
+#define RF_SYNCCONFIG_PREAMBLEPOLARITY_MASK 0xDF
+#define RF_SYNCCONFIG_PREAMBLEPOLARITY_55 0x20
+#define RF_SYNCCONFIG_PREAMBLEPOLARITY_AA 0x00 // Default
+
+#define RF_SYNCCONFIG_SYNC_MASK 0xEF
+#define RF_SYNCCONFIG_SYNC_ON 0x10 // Default
+#define RF_SYNCCONFIG_SYNC_OFF 0x00
+
+
+#define RF_SYNCCONFIG_SYNCSIZE_MASK 0xF8
+#define RF_SYNCCONFIG_SYNCSIZE_1 0x00
+#define RF_SYNCCONFIG_SYNCSIZE_2 0x01
+#define RF_SYNCCONFIG_SYNCSIZE_3 0x02
+#define RF_SYNCCONFIG_SYNCSIZE_4 0x03 // Default
+#define RF_SYNCCONFIG_SYNCSIZE_5 0x04
+#define RF_SYNCCONFIG_SYNCSIZE_6 0x05
+#define RF_SYNCCONFIG_SYNCSIZE_7 0x06
+#define RF_SYNCCONFIG_SYNCSIZE_8 0x07
+
+/*!
+ * RegSyncValue1-8
+ */
+#define RF_SYNCVALUE1_SYNCVALUE 0x01 // Default
+#define RF_SYNCVALUE2_SYNCVALUE 0x01 // Default
+#define RF_SYNCVALUE3_SYNCVALUE 0x01 // Default
+#define RF_SYNCVALUE4_SYNCVALUE 0x01 // Default
+#define RF_SYNCVALUE5_SYNCVALUE 0x01 // Default
+#define RF_SYNCVALUE6_SYNCVALUE 0x01 // Default
+#define RF_SYNCVALUE7_SYNCVALUE 0x01 // Default
+#define RF_SYNCVALUE8_SYNCVALUE 0x01 // Default
+
+/*!
+ * RegPacketConfig1
+ */
+#define RF_PACKETCONFIG1_PACKETFORMAT_MASK 0x7F
+#define RF_PACKETCONFIG1_PACKETFORMAT_FIXED 0x00
+#define RF_PACKETCONFIG1_PACKETFORMAT_VARIABLE 0x80 // Default
+
+#define RF_PACKETCONFIG1_DCFREE_MASK 0x9F
+#define RF_PACKETCONFIG1_DCFREE_OFF 0x00 // Default
+#define RF_PACKETCONFIG1_DCFREE_MANCHESTER 0x20
+#define RF_PACKETCONFIG1_DCFREE_WHITENING 0x40
+
+#define RF_PACKETCONFIG1_CRC_MASK 0xEF
+#define RF_PACKETCONFIG1_CRC_ON 0x10 // Default
+#define RF_PACKETCONFIG1_CRC_OFF 0x00
+
+#define RF_PACKETCONFIG1_CRCAUTOCLEAR_MASK 0xF7
+#define RF_PACKETCONFIG1_CRCAUTOCLEAR_ON 0x00 // Default
+#define RF_PACKETCONFIG1_CRCAUTOCLEAR_OFF 0x08
+
+#define RF_PACKETCONFIG1_ADDRSFILTERING_MASK 0xF9
+#define RF_PACKETCONFIG1_ADDRSFILTERING_OFF 0x00 // Default
+#define RF_PACKETCONFIG1_ADDRSFILTERING_NODE 0x02
+#define RF_PACKETCONFIG1_ADDRSFILTERING_NODEBROADCAST 0x04
+
+#define RF_PACKETCONFIG1_CRCWHITENINGTYPE_MASK 0xFE
+#define RF_PACKETCONFIG1_CRCWHITENINGTYPE_CCITT 0x00 // Default
+#define RF_PACKETCONFIG1_CRCWHITENINGTYPE_IBM 0x01
+
+/*!
+ * RegPacketConfig2
+ */
+
+#define RF_PACKETCONFIG2_WMBUS_CRC_ENABLE_MASK 0x7F
+#define RF_PACKETCONFIG2_WMBUS_CRC_ENABLE 0x80
+#define RF_PACKETCONFIG2_WMBUS_CRC_DISABLE 0x00 // Default
+
+#define RF_PACKETCONFIG2_DATAMODE_MASK 0xBF
+#define RF_PACKETCONFIG2_DATAMODE_CONTINUOUS 0x00
+#define RF_PACKETCONFIG2_DATAMODE_PACKET 0x40 // Default
+
+#define RF_PACKETCONFIG2_IOHOME_MASK 0xDF
+#define RF_PACKETCONFIG2_IOHOME_ON 0x20
+#define RF_PACKETCONFIG2_IOHOME_OFF 0x00 // Default
+
+#define RF_PACKETCONFIG2_BEACON_MASK 0xF7
+#define RF_PACKETCONFIG2_BEACON_ON 0x08
+#define RF_PACKETCONFIG2_BEACON_OFF 0x00 // Default
+
+#define RF_PACKETCONFIG2_PAYLOADLENGTH_MSB_MASK 0xF8
+
+/*!
+ * RegPayloadLength
+ */
+#define RF_PAYLOADLENGTH_LENGTH 0x40 // Default
+
+/*!
+ * RegNodeAdrs
+ */
+#define RF_NODEADDRESS_ADDRESS 0x00
+
+/*!
+ * RegBroadcastAdrs
+ */
+#define RF_BROADCASTADDRESS_ADDRESS 0x00
+
+/*!
+ * RegFifoThresh
+ */
+#define RF_FIFOTHRESH_TXSTARTCONDITION_MASK 0x7F
+#define RF_FIFOTHRESH_TXSTARTCONDITION_FIFOTHRESH 0x00 // Default
+#define RF_FIFOTHRESH_TXSTARTCONDITION_FIFONOTEMPTY 0x80
+
+#define RF_FIFOTHRESH_FIFOTHRESHOLD_MASK 0xC0
+#define RF_FIFOTHRESH_FIFOTHRESHOLD_THRESHOLD 0x0F // Default
+
+/*!
+ * RegSeqConfig1
+ */
+#define RF_SEQCONFIG1_SEQUENCER_START 0x80
+
+#define RF_SEQCONFIG1_SEQUENCER_STOP 0x40
+
+#define RF_SEQCONFIG1_IDLEMODE_MASK 0xDF
+#define RF_SEQCONFIG1_IDLEMODE_SLEEP 0x20
+#define RF_SEQCONFIG1_IDLEMODE_STANDBY 0x00 // Default
+
+#define RF_SEQCONFIG1_FROMSTART_MASK 0xE7
+#define RF_SEQCONFIG1_FROMSTART_TOLPS 0x00 // Default
+#define RF_SEQCONFIG1_FROMSTART_TORX 0x08
+#define RF_SEQCONFIG1_FROMSTART_TOTX 0x10
+#define RF_SEQCONFIG1_FROMSTART_TOTX_ONFIFOLEVEL 0x18
+
+#define RF_SEQCONFIG1_LPS_MASK 0xFB
+#define RF_SEQCONFIG1_LPS_SEQUENCER_OFF 0x00 // Default
+#define RF_SEQCONFIG1_LPS_IDLE 0x04
+
+#define RF_SEQCONFIG1_FROMIDLE_MASK 0xFD
+#define RF_SEQCONFIG1_FROMIDLE_TOTX 0x00 // Default
+#define RF_SEQCONFIG1_FROMIDLE_TORX 0x02
+
+#define RF_SEQCONFIG1_FROMTX_MASK 0xFE
+#define RF_SEQCONFIG1_FROMTX_TOLPS 0x00 // Default
+#define RF_SEQCONFIG1_FROMTX_TORX 0x01
+
+/*!
+ * RegSeqConfig2
+ */
+#define RF_SEQCONFIG2_FROMRX_MASK 0x1F
+#define RF_SEQCONFIG2_FROMRX_TOUNUSED_000 0x00 // Default
+#define RF_SEQCONFIG2_FROMRX_TORXPKT_ONPLDRDY 0x20
+#define RF_SEQCONFIG2_FROMRX_TOLPS_ONPLDRDY 0x40
+#define RF_SEQCONFIG2_FROMRX_TORXPKT_ONCRCOK 0x60
+#define RF_SEQCONFIG2_FROMRX_TOSEQUENCEROFF_ONRSSI 0x80
+#define RF_SEQCONFIG2_FROMRX_TOSEQUENCEROFF_ONSYNC 0xA0
+#define RF_SEQCONFIG2_FROMRX_TOSEQUENCEROFF_ONPREAMBLE 0xC0
+#define RF_SEQCONFIG2_FROMRX_TOUNUSED_111 0xE0
+
+#define RF_SEQCONFIG2_FROMRXTIMEOUT_MASK 0xE7
+#define RF_SEQCONFIG2_FROMRXTIMEOUT_TORXRESTART 0x00 // Default
+#define RF_SEQCONFIG2_FROMRXTIMEOUT_TOTX 0x08
+#define RF_SEQCONFIG2_FROMRXTIMEOUT_TOLPS 0x10
+#define RF_SEQCONFIG2_FROMRXTIMEOUT_TOSEQUENCEROFF 0x18
+
+#define RF_SEQCONFIG2_FROMRXPKT_MASK 0xF8
+#define RF_SEQCONFIG2_FROMRXPKT_TOSEQUENCEROFF 0x00 // Default
+#define RF_SEQCONFIG2_FROMRXPKT_TOTX_ONFIFOEMPTY 0x01
+#define RF_SEQCONFIG2_FROMRXPKT_TOLPS 0x02
+#define RF_SEQCONFIG2_FROMRXPKT_TOSYNTHESIZERRX 0x03
+#define RF_SEQCONFIG2_FROMRXPKT_TORX 0x04
+
+/*!
+ * RegTimerResol
+ */
+#define RF_TIMERRESOL_TIMER1RESOL_MASK 0xF3
+#define RF_TIMERRESOL_TIMER1RESOL_OFF 0x00 // Default
+#define RF_TIMERRESOL_TIMER1RESOL_000064_US 0x04
+#define RF_TIMERRESOL_TIMER1RESOL_004100_US 0x08
+#define RF_TIMERRESOL_TIMER1RESOL_262000_US 0x0C
+
+#define RF_TIMERRESOL_TIMER2RESOL_MASK 0xFC
+#define RF_TIMERRESOL_TIMER2RESOL_OFF 0x00 // Default
+#define RF_TIMERRESOL_TIMER2RESOL_000064_US 0x01
+#define RF_TIMERRESOL_TIMER2RESOL_004100_US 0x02
+#define RF_TIMERRESOL_TIMER2RESOL_262000_US 0x03
+
+/*!
+ * RegTimer1Coef
+ */
+#define RF_TIMER1COEF_TIMER1COEFFICIENT 0xF5 // Default
+
+/*!
+ * RegTimer2Coef
+ */
+#define RF_TIMER2COEF_TIMER2COEFFICIENT 0x20 // Default
+
+/*!
+ * RegImageCal
+ */
+#define RF_IMAGECAL_AUTOIMAGECAL_MASK 0x7F
+#define RF_IMAGECAL_AUTOIMAGECAL_ON 0x80
+#define RF_IMAGECAL_AUTOIMAGECAL_OFF 0x00 // Default
+
+#define RF_IMAGECAL_IMAGECAL_MASK 0xBF
+#define RF_IMAGECAL_IMAGECAL_START 0x40
+
+#define RF_IMAGECAL_IMAGECAL_RUNNING 0x20
+#define RF_IMAGECAL_IMAGECAL_DONE 0x00 // Default
+
+#define RF_IMAGECAL_TEMPCHANGE_HIGHER 0x08
+#define RF_IMAGECAL_TEMPCHANGE_LOWER 0x00
+
+#define RF_IMAGECAL_TEMPTHRESHOLD_MASK 0xF9
+#define RF_IMAGECAL_TEMPTHRESHOLD_05 0x00
+#define RF_IMAGECAL_TEMPTHRESHOLD_10 0x02 // Default
+#define RF_IMAGECAL_TEMPTHRESHOLD_15 0x04
+#define RF_IMAGECAL_TEMPTHRESHOLD_20 0x06
+
+#define RF_IMAGECAL_TEMPMONITOR_MASK 0xFE
+#define RF_IMAGECAL_TEMPMONITOR_ON 0x00 // Default
+#define RF_IMAGECAL_TEMPMONITOR_OFF 0x01
+
+/*!
+ * RegTemp (Read Only)
+ */
+
+/*!
+ * RegLowBat
+ */
+#define RF_LOWBAT_MASK 0xF7
+#define RF_LOWBAT_ON 0x08
+#define RF_LOWBAT_OFF 0x00 // Default
+
+#define RF_LOWBAT_TRIM_MASK 0xF8
+#define RF_LOWBAT_TRIM_1695 0x00
+#define RF_LOWBAT_TRIM_1764 0x01
+#define RF_LOWBAT_TRIM_1835 0x02 // Default
+#define RF_LOWBAT_TRIM_1905 0x03
+#define RF_LOWBAT_TRIM_1976 0x04
+#define RF_LOWBAT_TRIM_2045 0x05
+#define RF_LOWBAT_TRIM_2116 0x06
+#define RF_LOWBAT_TRIM_2185 0x07
+
+/*!
+ * RegIrqFlags1
+ */
+#define RF_IRQFLAGS1_MODEREADY 0x80
+
+#define RF_IRQFLAGS1_RXREADY 0x40
+
+#define RF_IRQFLAGS1_TXREADY 0x20
+
+#define RF_IRQFLAGS1_PLLLOCK 0x10
+
+#define RF_IRQFLAGS1_RSSI 0x08
+
+#define RF_IRQFLAGS1_TIMEOUT 0x04
+
+#define RF_IRQFLAGS1_PREAMBLEDETECT 0x02
+
+#define RF_IRQFLAGS1_SYNCADDRESSMATCH 0x01
+
+/*!
+ * RegIrqFlags2
+ */
+#define RF_IRQFLAGS2_FIFOFULL 0x80
+
+#define RF_IRQFLAGS2_FIFOEMPTY 0x40
+
+#define RF_IRQFLAGS2_FIFOLEVEL 0x20
+
+#define RF_IRQFLAGS2_FIFOOVERRUN 0x10
+
+#define RF_IRQFLAGS2_PACKETSENT 0x08
+
+#define RF_IRQFLAGS2_PAYLOADREADY 0x04
+
+#define RF_IRQFLAGS2_CRCOK 0x02
+
+#define RF_IRQFLAGS2_LOWBAT 0x01
+
+/*!
+ * RegDioMapping1
+ */
+#define RF_DIOMAPPING1_DIO0_MASK 0x3F
+#define RF_DIOMAPPING1_DIO0_00 0x00 // Default
+#define RF_DIOMAPPING1_DIO0_01 0x40
+#define RF_DIOMAPPING1_DIO0_10 0x80
+#define RF_DIOMAPPING1_DIO0_11 0xC0
+
+#define RF_DIOMAPPING1_DIO1_MASK 0xCF
+#define RF_DIOMAPPING1_DIO1_00 0x00 // Default
+#define RF_DIOMAPPING1_DIO1_01 0x10
+#define RF_DIOMAPPING1_DIO1_10 0x20
+#define RF_DIOMAPPING1_DIO1_11 0x30
+
+#define RF_DIOMAPPING1_DIO2_MASK 0xF3
+#define RF_DIOMAPPING1_DIO2_00 0x00 // Default
+#define RF_DIOMAPPING1_DIO2_01 0x04
+#define RF_DIOMAPPING1_DIO2_10 0x08
+#define RF_DIOMAPPING1_DIO2_11 0x0C
+
+#define RF_DIOMAPPING1_DIO3_MASK 0xFC
+#define RF_DIOMAPPING1_DIO3_00 0x00 // Default
+#define RF_DIOMAPPING1_DIO3_01 0x01
+#define RF_DIOMAPPING1_DIO3_10 0x02
+#define RF_DIOMAPPING1_DIO3_11 0x03
+
+/*!
+ * RegDioMapping2
+ */
+#define RF_DIOMAPPING2_DIO4_MASK 0x3F
+#define RF_DIOMAPPING2_DIO4_00 0x00 // Default
+#define RF_DIOMAPPING2_DIO4_01 0x40
+#define RF_DIOMAPPING2_DIO4_10 0x80
+#define RF_DIOMAPPING2_DIO4_11 0xC0
+
+#define RF_DIOMAPPING2_DIO5_MASK 0xCF
+#define RF_DIOMAPPING2_DIO5_00 0x00 // Default
+#define RF_DIOMAPPING2_DIO5_01 0x10
+#define RF_DIOMAPPING2_DIO5_10 0x20
+#define RF_DIOMAPPING2_DIO5_11 0x30
+
+#define RF_DIOMAPPING2_MAP_MASK 0xFE
+#define RF_DIOMAPPING2_MAP_PREAMBLEDETECT 0x01
+#define RF_DIOMAPPING2_MAP_RSSI 0x00 // Default
+
+/*!
+ * RegVersion (Read Only)
+ */
+
+/*!
+ * RegPllHop
+ */
+#define RF_PLLHOP_FASTHOP_MASK 0x7F
+#define RF_PLLHOP_FASTHOP_ON 0x80
+#define RF_PLLHOP_FASTHOP_OFF 0x00 // Default
+
+/*!
+ * RegTcxo
+ */
+#define RF_TCXO_TCXOINPUT_MASK 0xEF
+#define RF_TCXO_TCXOINPUT_ON 0x10
+#define RF_TCXO_TCXOINPUT_OFF 0x00 // Default
+
+/*!
+ * RegPaDac
+ */
+#define RF_PADAC_20DBM_MASK 0xF8
+#define RF_PADAC_20DBM_ON 0x07
+#define RF_PADAC_20DBM_OFF 0x04 // Default
+
+/*!
+ * RegFormerTemp
+ */
+
+/*!
+ * RegBitrateFrac
+ */
+#define RF_BITRATEFRAC_MASK 0xF0
+
+/*!
+ * RegAgcRef
+ */
+
+/*!
+ * RegAgcThresh1
+ */
+
+/*!
+ * RegAgcThresh2
+ */
+
+/*!
+ * RegAgcThresh3
+ */
+
+/*!
+ * RegPll
+ */
+#define RF_PLL_BANDWIDTH_MASK 0x3F
+#define RF_PLL_BANDWIDTH_75 0x00
+#define RF_PLL_BANDWIDTH_150 0x40
+#define RF_PLL_BANDWIDTH_225 0x80
+#define RF_PLL_BANDWIDTH_300 0xC0 // Default
+
+#endif // __SX1276_REGS_FSK_H__
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9986f68c/hw/drivers/lora/node/radio/sx1276/src/sx1276Regs-LoRa.h
----------------------------------------------------------------------
diff --git a/hw/drivers/lora/node/radio/sx1276/src/sx1276Regs-LoRa.h b/hw/drivers/lora/node/radio/sx1276/src/sx1276Regs-LoRa.h
new file mode 100644
index 0000000..edce9f7
--- /dev/null
+++ b/hw/drivers/lora/node/radio/sx1276/src/sx1276Regs-LoRa.h
@@ -0,0 +1,565 @@
+/*
+ / _____) _ | |
+( (____ _____ ____ _| |_ _____ ____| |__
+ \____ \| ___ | (_ _) ___ |/ ___) _ \
+ _____) ) ____| | | || |_| ____( (___| | | |
+(______/|_____)_|_|_| \__)_____)\____)_| |_|
+ (C)2013 Semtech
+
+Description: SX1276 LoRa modem registers and bits definitions
+
+License: Revised BSD License, see LICENSE.TXT file include in the project
+
+Maintainer: Miguel Luis and Gregory Cristian
+*/
+#ifndef __SX1276_REGS_LORA_H__
+#define __SX1276_REGS_LORA_H__
+
+/*!
+ * ============================================================================
+ * SX1276 Internal registers Address
+ * ============================================================================
+ */
+#define REG_LR_FIFO 0x00
+// Common settings
+#define REG_LR_OPMODE 0x01
+#define REG_LR_FRFMSB 0x06
+#define REG_LR_FRFMID 0x07
+#define REG_LR_FRFLSB 0x08
+// Tx settings
+#define REG_LR_PACONFIG 0x09
+#define REG_LR_PARAMP 0x0A
+#define REG_LR_OCP 0x0B
+// Rx settings
+#define REG_LR_LNA 0x0C
+// LoRa registers
+#define REG_LR_FIFOADDRPTR 0x0D
+#define REG_LR_FIFOTXBASEADDR 0x0E
+#define REG_LR_FIFORXBASEADDR 0x0F
+#define REG_LR_FIFORXCURRENTADDR 0x10
+#define REG_LR_IRQFLAGSMASK 0x11
+#define REG_LR_IRQFLAGS 0x12
+#define REG_LR_RXNBBYTES 0x13
+#define REG_LR_RXHEADERCNTVALUEMSB 0x14
+#define REG_LR_RXHEADERCNTVALUELSB 0x15
+#define REG_LR_RXPACKETCNTVALUEMSB 0x16
+#define REG_LR_RXPACKETCNTVALUELSB 0x17
+#define REG_LR_MODEMSTAT 0x18
+#define REG_LR_PKTSNRVALUE 0x19
+#define REG_LR_PKTRSSIVALUE 0x1A
+#define REG_LR_RSSIVALUE 0x1B
+#define REG_LR_HOPCHANNEL 0x1C
+#define REG_LR_MODEMCONFIG1 0x1D
+#define REG_LR_MODEMCONFIG2 0x1E
+#define REG_LR_SYMBTIMEOUTLSB 0x1F
+#define REG_LR_PREAMBLEMSB 0x20
+#define REG_LR_PREAMBLELSB 0x21
+#define REG_LR_PAYLOADLENGTH 0x22
+#define REG_LR_PAYLOADMAXLENGTH 0x23
+#define REG_LR_HOPPERIOD 0x24
+#define REG_LR_FIFORXBYTEADDR 0x25
+#define REG_LR_MODEMCONFIG3 0x26
+#define REG_LR_FEIMSB 0x28
+#define REG_LR_FEIMID 0x29
+#define REG_LR_FEILSB 0x2A
+#define REG_LR_RSSIWIDEBAND 0x2C
+#define REG_LR_TEST2F 0x2F
+#define REG_LR_TEST30 0x30
+#define REG_LR_DETECTOPTIMIZE 0x31
+#define REG_LR_INVERTIQ 0x33
+#define REG_LR_TEST36 0x36
+#define REG_LR_DETECTIONTHRESHOLD 0x37
+#define REG_LR_SYNCWORD 0x39
+#define REG_LR_TEST3A 0x3A
+#define REG_LR_INVERTIQ2 0x3B
+
+// end of documented register in datasheet
+// I/O settings
+#define REG_LR_DIOMAPPING1 0x40
+#define REG_LR_DIOMAPPING2 0x41
+// Version
+#define REG_LR_VERSION 0x42
+// Additional settings
+#define REG_LR_PLLHOP 0x44
+#define REG_LR_TCXO 0x4B
+#define REG_LR_PADAC 0x4D
+#define REG_LR_FORMERTEMP 0x5B
+#define REG_LR_BITRATEFRAC 0x5D
+#define REG_LR_AGCREF 0x61
+#define REG_LR_AGCTHRESH1 0x62
+#define REG_LR_AGCTHRESH2 0x63
+#define REG_LR_AGCTHRESH3 0x64
+#define REG_LR_PLL 0x70
+
+/*!
+ * ============================================================================
+ * SX1276 LoRa bits control definition
+ * ============================================================================
+ */
+
+/*!
+ * RegFifo
+ */
+
+/*!
+ * RegOpMode
+ */
+#define RFLR_OPMODE_LONGRANGEMODE_MASK 0x7F
+#define RFLR_OPMODE_LONGRANGEMODE_OFF 0x00 // Default
+#define RFLR_OPMODE_LONGRANGEMODE_ON 0x80
+
+#define RFLR_OPMODE_ACCESSSHAREDREG_MASK 0xBF
+#define RFLR_OPMODE_ACCESSSHAREDREG_ENABLE 0x40
+#define RFLR_OPMODE_ACCESSSHAREDREG_DISABLE 0x00 // Default
+
+#define RFLR_OPMODE_FREQMODE_ACCESS_MASK 0xF7
+#define RFLR_OPMODE_FREQMODE_ACCESS_LF 0x08 // Default
+#define RFLR_OPMODE_FREQMODE_ACCESS_HF 0x00
+
+#define RFLR_OPMODE_MASK 0xF8
+#define RFLR_OPMODE_SLEEP 0x00
+#define RFLR_OPMODE_STANDBY 0x01 // Default
+#define RFLR_OPMODE_SYNTHESIZER_TX 0x02
+#define RFLR_OPMODE_TRANSMITTER 0x03
+#define RFLR_OPMODE_SYNTHESIZER_RX 0x04
+#define RFLR_OPMODE_RECEIVER 0x05
+// LoRa specific modes
+#define RFLR_OPMODE_RECEIVER_SINGLE 0x06
+#define RFLR_OPMODE_CAD 0x07
+
+/*!
+ * RegFrf (MHz)
+ */
+#define RFLR_FRFMSB_434_MHZ 0x6C // Default
+#define RFLR_FRFMID_434_MHZ 0x80 // Default
+#define RFLR_FRFLSB_434_MHZ 0x00 // Default
+
+/*!
+ * RegPaConfig
+ */
+#define RFLR_PACONFIG_PASELECT_MASK 0x7F
+#define RFLR_PACONFIG_PASELECT_PABOOST 0x80
+#define RFLR_PACONFIG_PASELECT_RFO 0x00 // Default
+
+#define RFLR_PACONFIG_MAX_POWER_MASK 0x8F
+
+#define RFLR_PACONFIG_OUTPUTPOWER_MASK 0xF0
+
+/*!
+ * RegPaRamp
+ */
+#define RFLR_PARAMP_TXBANDFORCE_MASK 0xEF
+#define RFLR_PARAMP_TXBANDFORCE_BAND_SEL 0x10
+#define RFLR_PARAMP_TXBANDFORCE_AUTO 0x00 // Default
+
+#define RFLR_PARAMP_MASK 0xF0
+#define RFLR_PARAMP_3400_US 0x00
+#define RFLR_PARAMP_2000_US 0x01
+#define RFLR_PARAMP_1000_US 0x02
+#define RFLR_PARAMP_0500_US 0x03
+#define RFLR_PARAMP_0250_US 0x04
+#define RFLR_PARAMP_0125_US 0x05
+#define RFLR_PARAMP_0100_US 0x06
+#define RFLR_PARAMP_0062_US 0x07
+#define RFLR_PARAMP_0050_US 0x08
+#define RFLR_PARAMP_0040_US 0x09 // Default
+#define RFLR_PARAMP_0031_US 0x0A
+#define RFLR_PARAMP_0025_US 0x0B
+#define RFLR_PARAMP_0020_US 0x0C
+#define RFLR_PARAMP_0015_US 0x0D
+#define RFLR_PARAMP_0012_US 0x0E
+#define RFLR_PARAMP_0010_US 0x0F
+
+/*!
+ * RegOcp
+ */
+#define RFLR_OCP_MASK 0xDF
+#define RFLR_OCP_ON 0x20 // Default
+#define RFLR_OCP_OFF 0x00
+
+#define RFLR_OCP_TRIM_MASK 0xE0
+#define RFLR_OCP_TRIM_045_MA 0x00
+#define RFLR_OCP_TRIM_050_MA 0x01
+#define RFLR_OCP_TRIM_055_MA 0x02
+#define RFLR_OCP_TRIM_060_MA 0x03
+#define RFLR_OCP_TRIM_065_MA 0x04
+#define RFLR_OCP_TRIM_070_MA 0x05
+#define RFLR_OCP_TRIM_075_MA 0x06
+#define RFLR_OCP_TRIM_080_MA 0x07
+#define RFLR_OCP_TRIM_085_MA 0x08
+#define RFLR_OCP_TRIM_090_MA 0x09
+#define RFLR_OCP_TRIM_095_MA 0x0A
+#define RFLR_OCP_TRIM_100_MA 0x0B // Default
+#define RFLR_OCP_TRIM_105_MA 0x0C
+#define RFLR_OCP_TRIM_110_MA 0x0D
+#define RFLR_OCP_TRIM_115_MA 0x0E
+#define RFLR_OCP_TRIM_120_MA 0x0F
+#define RFLR_OCP_TRIM_130_MA 0x10
+#define RFLR_OCP_TRIM_140_MA 0x11
+#define RFLR_OCP_TRIM_150_MA 0x12
+#define RFLR_OCP_TRIM_160_MA 0x13
+#define RFLR_OCP_TRIM_170_MA 0x14
+#define RFLR_OCP_TRIM_180_MA 0x15
+#define RFLR_OCP_TRIM_190_MA 0x16
+#define RFLR_OCP_TRIM_200_MA 0x17
+#define RFLR_OCP_TRIM_210_MA 0x18
+#define RFLR_OCP_TRIM_220_MA 0x19
+#define RFLR_OCP_TRIM_230_MA 0x1A
+#define RFLR_OCP_TRIM_240_MA 0x1B
+
+/*!
+ * RegLna
+ */
+#define RFLR_LNA_GAIN_MASK 0x1F
+#define RFLR_LNA_GAIN_G1 0x20 // Default
+#define RFLR_LNA_GAIN_G2 0x40
+#define RFLR_LNA_GAIN_G3 0x60
+#define RFLR_LNA_GAIN_G4 0x80
+#define RFLR_LNA_GAIN_G5 0xA0
+#define RFLR_LNA_GAIN_G6 0xC0
+
+#define RFLR_LNA_BOOST_LF_MASK 0xE7
+#define RFLR_LNA_BOOST_LF_DEFAULT 0x00 // Default
+
+#define RFLR_LNA_BOOST_HF_MASK 0xFC
+#define RFLR_LNA_BOOST_HF_OFF 0x00 // Default
+#define RFLR_LNA_BOOST_HF_ON 0x03
+
+/*!
+ * RegFifoAddrPtr
+ */
+#define RFLR_FIFOADDRPTR 0x00 // Default
+
+/*!
+ * RegFifoTxBaseAddr
+ */
+#define RFLR_FIFOTXBASEADDR 0x80 // Default
+
+/*!
+ * RegFifoTxBaseAddr
+ */
+#define RFLR_FIFORXBASEADDR 0x00 // Default
+
+/*!
+ * RegFifoRxCurrentAddr (Read Only)
+ */
+
+/*!
+ * RegIrqFlagsMask
+ */
+#define RFLR_IRQFLAGS_RXTIMEOUT_MASK 0x80
+#define RFLR_IRQFLAGS_RXDONE_MASK 0x40
+#define RFLR_IRQFLAGS_PAYLOADCRCERROR_MASK 0x20
+#define RFLR_IRQFLAGS_VALIDHEADER_MASK 0x10
+#define RFLR_IRQFLAGS_TXDONE_MASK 0x08
+#define RFLR_IRQFLAGS_CADDONE_MASK 0x04
+#define RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL_MASK 0x02
+#define RFLR_IRQFLAGS_CADDETECTED_MASK 0x01
+
+/*!
+ * RegIrqFlags
+ */
+#define RFLR_IRQFLAGS_RXTIMEOUT 0x80
+#define RFLR_IRQFLAGS_RXDONE 0x40
+#define RFLR_IRQFLAGS_PAYLOADCRCERROR 0x20
+#define RFLR_IRQFLAGS_VALIDHEADER 0x10
+#define RFLR_IRQFLAGS_TXDONE 0x08
+#define RFLR_IRQFLAGS_CADDONE 0x04
+#define RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL 0x02
+#define RFLR_IRQFLAGS_CADDETECTED 0x01
+
+/*!
+ * RegFifoRxNbBytes (Read Only)
+ */
+
+/*!
+ * RegRxHeaderCntValueMsb (Read Only)
+ */
+
+/*!
+ * RegRxHeaderCntValueLsb (Read Only)
+ */
+
+/*!
+ * RegRxPacketCntValueMsb (Read Only)
+ */
+
+/*!
+ * RegRxPacketCntValueLsb (Read Only)
+ */
+
+/*!
+ * RegModemStat (Read Only)
+ */
+#define RFLR_MODEMSTAT_RX_CR_MASK 0x1F
+#define RFLR_MODEMSTAT_MODEM_STATUS_MASK 0xE0
+
+/*!
+ * RegPktSnrValue (Read Only)
+ */
+
+/*!
+ * RegPktRssiValue (Read Only)
+ */
+
+/*!
+ * RegRssiValue (Read Only)
+ */
+
+/*!
+ * RegHopChannel (Read Only)
+ */
+#define RFLR_HOPCHANNEL_PLL_LOCK_TIMEOUT_MASK 0x7F
+#define RFLR_HOPCHANNEL_PLL_LOCK_FAIL 0x80
+#define RFLR_HOPCHANNEL_PLL_LOCK_SUCCEED 0x00 // Default
+
+#define RFLR_HOPCHANNEL_CRCONPAYLOAD_MASK 0xBF
+#define RFLR_HOPCHANNEL_CRCONPAYLOAD_ON 0x40
+#define RFLR_HOPCHANNEL_CRCONPAYLOAD_OFF 0x00 // Default
+
+#define RFLR_HOPCHANNEL_CHANNEL_MASK 0x3F
+
+/*!
+ * RegModemConfig1
+ */
+#define RFLR_MODEMCONFIG1_BW_MASK 0x0F
+#define RFLR_MODEMCONFIG1_BW_7_81_KHZ 0x00
+#define RFLR_MODEMCONFIG1_BW_10_41_KHZ 0x10
+#define RFLR_MODEMCONFIG1_BW_15_62_KHZ 0x20
+#define RFLR_MODEMCONFIG1_BW_20_83_KHZ 0x30
+#define RFLR_MODEMCONFIG1_BW_31_25_KHZ 0x40
+#define RFLR_MODEMCONFIG1_BW_41_66_KHZ 0x50
+#define RFLR_MODEMCONFIG1_BW_62_50_KHZ 0x60
+#define RFLR_MODEMCONFIG1_BW_125_KHZ 0x70 // Default
+#define RFLR_MODEMCONFIG1_BW_250_KHZ 0x80
+#define RFLR_MODEMCONFIG1_BW_500_KHZ 0x90
+
+#define RFLR_MODEMCONFIG1_CODINGRATE_MASK 0xF1
+#define RFLR_MODEMCONFIG1_CODINGRATE_4_5 0x02
+#define RFLR_MODEMCONFIG1_CODINGRATE_4_6 0x04 // Default
+#define RFLR_MODEMCONFIG1_CODINGRATE_4_7 0x06
+#define RFLR_MODEMCONFIG1_CODINGRATE_4_8 0x08
+
+#define RFLR_MODEMCONFIG1_IMPLICITHEADER_MASK 0xFE
+#define RFLR_MODEMCONFIG1_IMPLICITHEADER_ON 0x01
+#define RFLR_MODEMCONFIG1_IMPLICITHEADER_OFF 0x00 // Default
+
+/*!
+ * RegModemConfig2
+ */
+#define RFLR_MODEMCONFIG2_SF_MASK 0x0F
+#define RFLR_MODEMCONFIG2_SF_6 0x60
+#define RFLR_MODEMCONFIG2_SF_7 0x70 // Default
+#define RFLR_MODEMCONFIG2_SF_8 0x80
+#define RFLR_MODEMCONFIG2_SF_9 0x90
+#define RFLR_MODEMCONFIG2_SF_10 0xA0
+#define RFLR_MODEMCONFIG2_SF_11 0xB0
+#define RFLR_MODEMCONFIG2_SF_12 0xC0
+
+#define RFLR_MODEMCONFIG2_TXCONTINUOUSMODE_MASK 0xF7
+#define RFLR_MODEMCONFIG2_TXCONTINUOUSMODE_ON 0x08
+#define RFLR_MODEMCONFIG2_TXCONTINUOUSMODE_OFF 0x00
+
+#define RFLR_MODEMCONFIG2_RXPAYLOADCRC_MASK 0xFB
+#define RFLR_MODEMCONFIG2_RXPAYLOADCRC_ON 0x04
+#define RFLR_MODEMCONFIG2_RXPAYLOADCRC_OFF 0x00 // Default
+
+#define RFLR_MODEMCONFIG2_SYMBTIMEOUTMSB_MASK 0xFC
+#define RFLR_MODEMCONFIG2_SYMBTIMEOUTMSB 0x00 // Default
+
+/*!
+ * RegSymbTimeoutLsb
+ */
+#define RFLR_SYMBTIMEOUTLSB_SYMBTIMEOUT 0x64 // Default
+
+/*!
+ * RegPreambleLengthMsb
+ */
+#define RFLR_PREAMBLELENGTHMSB 0x00 // Default
+
+/*!
+ * RegPreambleLengthLsb
+ */
+#define RFLR_PREAMBLELENGTHLSB 0x08 // Default
+
+/*!
+ * RegPayloadLength
+ */
+#define RFLR_PAYLOADLENGTH 0x0E // Default
+
+/*!
+ * RegPayloadMaxLength
+ */
+#define RFLR_PAYLOADMAXLENGTH 0xFF // Default
+
+/*!
+ * RegHopPeriod
+ */
+#define RFLR_HOPPERIOD_FREQFOPPINGPERIOD 0x00 // Default
+
+/*!
+ * RegFifoRxByteAddr (Read Only)
+ */
+
+/*!
+ * RegModemConfig3
+ */
+#define RFLR_MODEMCONFIG3_LOWDATARATEOPTIMIZE_MASK 0xF7
+#define RFLR_MODEMCONFIG3_LOWDATARATEOPTIMIZE_ON 0x08
+#define RFLR_MODEMCONFIG3_LOWDATARATEOPTIMIZE_OFF 0x00 // Default
+
+#define RFLR_MODEMCONFIG3_AGCAUTO_MASK 0xFB
+#define RFLR_MODEMCONFIG3_AGCAUTO_ON 0x04 // Default
+#define RFLR_MODEMCONFIG3_AGCAUTO_OFF 0x00
+
+/*!
+ * RegFeiMsb (Read Only)
+ */
+
+/*!
+ * RegFeiMid (Read Only)
+ */
+
+/*!
+ * RegFeiLsb (Read Only)
+ */
+
+/*!
+ * RegRssiWideband (Read Only)
+ */
+
+/*!
+ * RegDetectOptimize
+ */
+#define RFLR_DETECTIONOPTIMIZE_MASK 0xF8
+#define RFLR_DETECTIONOPTIMIZE_SF7_TO_SF12 0x03 // Default
+#define RFLR_DETECTIONOPTIMIZE_SF6 0x05
+
+/*!
+ * RegInvertIQ
+ */
+#define RFLR_INVERTIQ_RX_MASK 0xBF
+#define RFLR_INVERTIQ_RX_OFF 0x00
+#define RFLR_INVERTIQ_RX_ON 0x40
+#define RFLR_INVERTIQ_TX_MASK 0xFE
+#define RFLR_INVERTIQ_TX_OFF 0x01
+#define RFLR_INVERTIQ_TX_ON 0x00
+
+/*!
+ * RegDetectionThreshold
+ */
+#define RFLR_DETECTIONTHRESH_SF7_TO_SF12 0x0A // Default
+#define RFLR_DETECTIONTHRESH_SF6 0x0C
+
+/*!
+ * RegInvertIQ2
+ */
+#define RFLR_INVERTIQ2_ON 0x19
+#define RFLR_INVERTIQ2_OFF 0x1D
+
+/*!
+ * RegDioMapping1
+ */
+#define RFLR_DIOMAPPING1_DIO0_MASK 0x3F
+#define RFLR_DIOMAPPING1_DIO0_00 0x00 // Default
+#define RFLR_DIOMAPPING1_DIO0_01 0x40
+#define RFLR_DIOMAPPING1_DIO0_10 0x80
+#define RFLR_DIOMAPPING1_DIO0_11 0xC0
+
+#define RFLR_DIOMAPPING1_DIO1_MASK 0xCF
+#define RFLR_DIOMAPPING1_DIO1_00 0x00 // Default
+#define RFLR_DIOMAPPING1_DIO1_01 0x10
+#define RFLR_DIOMAPPING1_DIO1_10 0x20
+#define RFLR_DIOMAPPING1_DIO1_11 0x30
+
+#define RFLR_DIOMAPPING1_DIO2_MASK 0xF3
+#define RFLR_DIOMAPPING1_DIO2_00 0x00 // Default
+#define RFLR_DIOMAPPING1_DIO2_01 0x04
+#define RFLR_DIOMAPPING1_DIO2_10 0x08
+#define RFLR_DIOMAPPING1_DIO2_11 0x0C
+
+#define RFLR_DIOMAPPING1_DIO3_MASK 0xFC
+#define RFLR_DIOMAPPING1_DIO3_00 0x00 // Default
+#define RFLR_DIOMAPPING1_DIO3_01 0x01
+#define RFLR_DIOMAPPING1_DIO3_10 0x02
+#define RFLR_DIOMAPPING1_DIO3_11 0x03
+
+/*!
+ * RegDioMapping2
+ */
+#define RFLR_DIOMAPPING2_DIO4_MASK 0x3F
+#define RFLR_DIOMAPPING2_DIO4_00 0x00 // Default
+#define RFLR_DIOMAPPING2_DIO4_01 0x40
+#define RFLR_DIOMAPPING2_DIO4_10 0x80
+#define RFLR_DIOMAPPING2_DIO4_11 0xC0
+
+#define RFLR_DIOMAPPING2_DIO5_MASK 0xCF
+#define RFLR_DIOMAPPING2_DIO5_00 0x00 // Default
+#define RFLR_DIOMAPPING2_DIO5_01 0x10
+#define RFLR_DIOMAPPING2_DIO5_10 0x20
+#define RFLR_DIOMAPPING2_DIO5_11 0x30
+
+#define RFLR_DIOMAPPING2_MAP_MASK 0xFE
+#define RFLR_DIOMAPPING2_MAP_PREAMBLEDETECT 0x01
+#define RFLR_DIOMAPPING2_MAP_RSSI 0x00 // Default
+
+/*!
+ * RegVersion (Read Only)
+ */
+
+/*!
+ * RegPllHop
+ */
+#define RFLR_PLLHOP_FASTHOP_MASK 0x7F
+#define RFLR_PLLHOP_FASTHOP_ON 0x80
+#define RFLR_PLLHOP_FASTHOP_OFF 0x00 // Default
+
+/*!
+ * RegTcxo
+ */
+#define RFLR_TCXO_TCXOINPUT_MASK 0xEF
+#define RFLR_TCXO_TCXOINPUT_ON 0x10
+#define RFLR_TCXO_TCXOINPUT_OFF 0x00 // Default
+
+/*!
+ * RegPaDac
+ */
+#define RFLR_PADAC_20DBM_MASK 0xF8
+#define RFLR_PADAC_20DBM_ON 0x07
+#define RFLR_PADAC_20DBM_OFF 0x04 // Default
+
+/*!
+ * RegFormerTemp
+ */
+
+/*!
+ * RegBitrateFrac
+ */
+#define RF_BITRATEFRAC_MASK 0xF0
+
+/*!
+ * RegAgcRef
+ */
+
+/*!
+ * RegAgcThresh1
+ */
+
+/*!
+ * RegAgcThresh2
+ */
+
+/*!
+ * RegAgcThresh3
+ */
+
+/*!
+ * RegPll
+ */
+#define RF_PLL_BANDWIDTH_MASK 0x3F
+#define RF_PLL_BANDWIDTH_75 0x00
+#define RF_PLL_BANDWIDTH_150 0x40
+#define RF_PLL_BANDWIDTH_225 0x80
+#define RF_PLL_BANDWIDTH_300 0xC0 // Default
+
+#endif // __SX1276_REGS_LORA_H__
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9986f68c/net/lora/node/LICENSE.txt
----------------------------------------------------------------------
diff --git a/net/lora/node/LICENSE.txt b/net/lora/node/LICENSE.txt
new file mode 100644
index 0000000..82695a7
--- /dev/null
+++ b/net/lora/node/LICENSE.txt
@@ -0,0 +1,25 @@
+--- Revised BSD License ---
+Copyright (c) 2013, SEMTECH S.A.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of the Semtech corporation nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL SEMTECH S.A. BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9986f68c/net/lora/node/README.md
----------------------------------------------------------------------
diff --git a/net/lora/node/README.md b/net/lora/node/README.md
new file mode 100644
index 0000000..758120b
--- /dev/null
+++ b/net/lora/node/README.md
@@ -0,0 +1,28 @@
+<!--
+#
+# 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.
+#
+-->
+
+# loramac-node
+
+This is a Mynewt port of the Semtech LoRaWAN endpoint stack. This package depends on two drivers:
+ * loramac-net radio - Facilitates communication with a particular type of LoRa modem. This package exports the Radio_s definition containing the function pointers required by this stack.
+ * loramac-net board - Contains MCU or BSP specific definition needed for handling interrupts triggered by the LoRa radio.
+
+Sample drivers of both types can be found at: @apache-mynewt-core/hw/drivers/loramc-node.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9986f68c/net/lora/node/include/node/lora.h
----------------------------------------------------------------------
diff --git a/net/lora/node/include/node/lora.h b/net/lora/node/include/node/lora.h
new file mode 100644
index 0000000..f658f6e
--- /dev/null
+++ b/net/lora/node/include/node/lora.h
@@ -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.
+ */
+
+#ifndef H_LORA_
+#define H_LORA_
+
+#include "stats/stats.h"
+
+STATS_SECT_START(lora_stats)
+ STATS_SECT_ENTRY(rx_error)
+ STATS_SECT_ENTRY(rx_success)
+ STATS_SECT_ENTRY(rx_timeout)
+ STATS_SECT_ENTRY(tx_success)
+ STATS_SECT_ENTRY(tx_timeout)
+STATS_SECT_END
+extern STATS_SECT_DECL(lora_stats) lora_stats;
+
+#endif
[33/40] incubator-mynewt-core git commit: fixed console read function
and typo in hal_uart
Posted by ja...@apache.org.
fixed console read function and typo in hal_uart
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/0a5821d5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/0a5821d5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/0a5821d5
Branch: refs/heads/bluetooth5
Commit: 0a5821d5b60a1af82dd5399f3126228ae9a52f2b
Parents: 9022af6
Author: julian <ju...@imgtec.com>
Authored: Fri Apr 28 15:33:57 2017 +0100
Committer: julian <ju...@imgtec.com>
Committed: Thu May 4 16:58:45 2017 +0100
----------------------------------------------------------------------
hw/mcu/microchip/pic32mz2048efg100/src/hal_uart.c | 2 +-
sys/console/full/src/console.c | 6 +++++-
sys/console/minimal/src/console.c | 6 +++++-
3 files changed, 11 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0a5821d5/hw/mcu/microchip/pic32mz2048efg100/src/hal_uart.c
----------------------------------------------------------------------
diff --git a/hw/mcu/microchip/pic32mz2048efg100/src/hal_uart.c b/hw/mcu/microchip/pic32mz2048efg100/src/hal_uart.c
index 5131f57..aa33c2c 100644
--- a/hw/mcu/microchip/pic32mz2048efg100/src/hal_uart.c
+++ b/hw/mcu/microchip/pic32mz2048efg100/src/hal_uart.c
@@ -245,7 +245,7 @@ __attribute__((interrupt(IPL1AUTO), vector(_UART2_TX_VECTOR))) uart_2_tx_isr(voi
}
void
-__attribute__((interrupt(IPL1AUTO), vector(_UART3_RX_VECTOR))) uart_3_tx_rx_isr(void)
+__attribute__((interrupt(IPL1AUTO), vector(_UART3_RX_VECTOR))) uart_3_rx_isr(void)
{
uart_receive_ready(2);
IFS4CLR = _IFS4_U3RXIF_MASK;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0a5821d5/sys/console/full/src/console.c
----------------------------------------------------------------------
diff --git a/sys/console/full/src/console.c b/sys/console/full/src/console.c
index 1bc4c3e..389d92f 100644
--- a/sys/console/full/src/console.c
+++ b/sys/console/full/src/console.c
@@ -116,7 +116,11 @@ console_read(char *str, int cnt, int *newline)
}
cmd = ev->ev_arg;
len = strlen(cmd->line);
- strncpy(str, cmd->line, len+1);
+ if (cnt < len) {
+ len = cnt;
+ }
+ memcpy(str, cmd->line, len);
+ str[len] = '\0';
os_eventq_put(avail_queue, ev);
*newline = 1;
return len;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0a5821d5/sys/console/minimal/src/console.c
----------------------------------------------------------------------
diff --git a/sys/console/minimal/src/console.c b/sys/console/minimal/src/console.c
index 0dbccaf..21f9d20 100644
--- a/sys/console/minimal/src/console.c
+++ b/sys/console/minimal/src/console.c
@@ -86,7 +86,11 @@ console_read(char *str, int cnt, int *newline)
}
cmd = ev->ev_arg;
len = strlen(cmd->line);
- strncpy(str, cmd->line, len+1);
+ if (cnt < len) {
+ len = cnt;
+ }
+ memcpy(str, cmd->line, len);
+ str[len] = '\0';
os_eventq_put(avail_queue, ev);
*newline = 1;
return len;
[07/40] incubator-mynewt-core git commit: This closes #252.
Posted by ja...@apache.org.
This closes #252.
Merge branch 'master' of https://github.com/antoinealb/incubator-mynewt-core
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/369df92d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/369df92d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/369df92d
Branch: refs/heads/bluetooth5
Commit: 369df92d33a8bea2d4d6cb481a9d06aceb2661cd
Parents: 2c8cdfb 6e75818
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Fri Apr 28 17:22:38 2017 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Fri Apr 28 17:22:38 2017 -0700
----------------------------------------------------------------------
hw/bsp/nrf51-blenano/src/hal_bsp.c | 31 +++++++++++++++++++++++++++++++
hw/bsp/nrf51-blenano/syscfg.yml | 26 ++++++++++++++++++++++++++
2 files changed, 57 insertions(+)
----------------------------------------------------------------------
[35/40] incubator-mynewt-core git commit: removed file with bad
license
Posted by ja...@apache.org.
removed file with bad license
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/9022af60
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/9022af60
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/9022af60
Branch: refs/heads/bluetooth5
Commit: 9022af60f42b68949400c98338b3232000c1a102
Parents: 0163ea6
Author: julian <ju...@imgtec.com>
Authored: Fri Apr 28 10:58:17 2017 +0100
Committer: julian <ju...@imgtec.com>
Committed: Thu May 4 16:58:45 2017 +0100
----------------------------------------------------------------------
kernel/os/src/arch/pic32/stubs/sbrk.c | 305 -----------------------------
1 file changed, 305 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9022af60/kernel/os/src/arch/pic32/stubs/sbrk.c
----------------------------------------------------------------------
diff --git a/kernel/os/src/arch/pic32/stubs/sbrk.c b/kernel/os/src/arch/pic32/stubs/sbrk.c
deleted file mode 100644
index a59f3c3..0000000
--- a/kernel/os/src/arch/pic32/stubs/sbrk.c
+++ /dev/null
@@ -1,305 +0,0 @@
-#ident "c/stubs/sbrk.c: Copyright (c) MIPS Technologies, Inc. All rights reserved."
-
-/*
- * Unpublished work (c) MIPS Technologies, Inc. All rights reserved.
- * Unpublished rights reserved under the copyright laws of the United
- * States of America and other countries.
- *
- * This code is confidential and proprietary to MIPS Technologies,
- * Inc. ("MIPS Technologies") and may be disclosed only as permitted in
- * writing by MIPS Technologies. Any copying, reproducing, modifying,
- * use or disclosure of this code (in whole or in part) that is not
- * expressly permitted in writing by MIPS Technologies is strictly
- * prohibited. At a minimum, this code is protected under trade secret,
- * unfair competition, and copyright laws. Violations thereof may result
- * in criminal penalties and fines.
- *
- * MIPS Technologies reserves the right to change this code to improve
- * function, design or otherwise. MIPS Technologies does not assume any
- * liability arising out of the application or use of this code, or of
- * any error or omission in such code. Any warranties, whether express,
- * statutory, implied or otherwise, including but not limited to the
- * implied warranties of merchantability or fitness for a particular
- * purpose, are excluded. Except as expressly provided in any written
- * license agreement from MIPS Technologies, the furnishing of this
- * code does not give recipient any license to any intellectual property
- * rights, including any patent rights, that cover this code.
- *
- * This code shall not be exported, reexported, transferred, or released,
- * directly or indirectly, in violation of the law of any country or
- * international law, regulation, treaty, Executive Order, statute,
- * amendments or supplements thereto. Should a conflict arise regarding
- * the export, reexport, transfer, or release of this code, the laws of
- * the United States of America shall be the governing law.
- *
- * This code may only be disclosed to the United States government
- * ("Government"), or to Government users, with prior written consent
- * from MIPS Technologies. This code constitutes one or more of the
- * following: commercial computer software, commercial computer software
- * documentation or other commercial items. If the user of this code,
- * or any related documentation of any kind, including related technical
- * data or manuals, is an agency, department, or other entity of the
- * Government, the use, duplication, reproduction, release, modification,
- * disclosure, or transfer of this code, or any related documentation
- * of any kind, is restricted in accordance with Federal Acquisition
- * Regulation 12.212 for civilian agencies and Defense Federal Acquisition
- * Regulation Supplement 227.7202 for military agencies. The use of this
- * code by the Government is further restricted in accordance with the
- * terms of the license agreement(s) and/or applicable contract terms
- * and conditions covering this code from MIPS Technologies.
- *
- *
- */
-
-/*
- * sbrk.c: a generic sbrk() emulation.
- */
-
-#include <string.h>
-#include <errno.h>
-
-#include <sys/kmem.h>
-
-/* memory layout */
-struct sbd_region {
- _paddr_t base;
- size_t size;
- int type;
-};
-
-/* _minbrk and _maxbrk can be set by startup code, or by a linker
- script, so we don't want them in bss where they'll get cleared, so
- they can't be common, but they must be capable of being
- overridden. */
-void * _minbrk __attribute__((weak)) = 0;
-void * _maxbrk __attribute__((weak)) = 0;
-
-extern int errno;
-extern char _end[];
-
-#if 0
-static pthread_mutex_t sbmx = PTHREAD_MUTEX_INITIALIZER;
-#endif
-
-static void * curbrk = 0;
-
-#ifndef MINHEAP
-#define MINHEAP (1 * 1024)
-#endif
-
-#ifndef MAXSTACK
-#define MAXSTACK (32 * 1024)
-#endif
-
-#ifndef PAGESIZE
-#define PAGESIZE 128
-#endif
-
-#define SBD_MEM_END 0
-#define SBD_MEM_RAM 1
-
-int
-getpagesize ()
-{
- return PAGESIZE;
-}
-
-
-/*
- * The _sbd_memlayout() function returns a pointer to a phys memory
- * region table, but note that at present sbrk() only uses the first
- * entry.
- *
- * This function can be overridden by the board-specific code
- * if it has some other way to determine the real size of
- * physical memory (e.g. reading the memory controller).
- */
-
-const struct sbd_region * _sbd_memlayout (void);
-#pragma weak _sbd_memlayout=_stub_sbd_memlayout
-const struct sbd_region *_stub_sbd_memlayout (void);
-
-const struct sbd_region *
-_stub_sbd_memlayout (void)
-{
- static struct sbd_region mem[2];
- extern char _heap[];
- extern char _min_heap_size[];
-
- mem[0].type = SBD_MEM_RAM;
- mem[0].base = (_paddr_t)(&_heap);
- mem[0].size = (size_t)(&_min_heap_size);
-
- return mem;
-}
-
-
-/*
- * Initialise the sbrk heap.
- *
- * This function is hard-wired to the idea that the code is linked to
- * KSEG0 or KSEG1 addresses. It could just about cope with being
- * linked to run in KUSEG, as long as there's a one-to-one mapping
- * from virtual to physical address. If you are playing real virtual
- * memory games then the functions in the module will have to be
- * replaced.
- */
-
-void
-_sbrk_init (void)
-{
- const struct sbd_region * layout;
- void * minva, * maxva;
- _paddr_t rbase, rtop, min, max;
- extern char _heap[];
- extern char _min_heap_size[];
-
- if (curbrk)
- return;
-
- if (_minbrk)
- /* user specified heap start */
- minva = _minbrk;
- else
- /* usually heap starts after data & bss segment */
-#if (__C32_VERSION__ > 200)
- minva = &_heap;
-#else
- minva = _end;
-#endif
-
- if (_maxbrk)
- /* user specified heap top */
- maxva = _maxbrk;
- else {
- /* usually stack is at top of memory, and
- heap grows up towards base of stack */
-#if (__C32_VERSION__ > 200)
- maxva = (void*)(&_heap) + (size_t)(&_min_heap_size);
-#else
- char * sp;
- __asm__ ("move %0,$sp" : "=d" (sp));
- maxva = sp - MAXSTACK;
-#endif
- }
-
- /* convert min/max to physical addresses */
- if (IS_KVA01 (minva))
- min = KVA_TO_PA (minva);
- else
- /* use virtual address */
- min = (_paddr_t) minva;
-
- if (IS_KVA01 (maxva))
- max = KVA_TO_PA (maxva);
- else
- max = (_paddr_t) maxva;
-
- /* determine physical memory layout */
- layout = _sbd_memlayout ();
-
- /* base of heap must be inside memory region #0 */
- rbase = layout[0].base;
- rtop = rbase + layout[0].size;
- if (min < rbase || min >= rtop) {
- if (rbase >= KVA_TO_PA (_end))
- /* no overlap of region with data - use region base */
- min = rbase;
- else
- /* can't determine a good heap base */
- /* XXX could try _end in case of bad _minbrk setting */
- return;
- }
-
- /* end of heap must be inside memory region #0 (and above base) */
- if (max < min || max >= rtop) {
- if (rtop > min)
- /* use top of region as top of heap */
- /* XXX what about poss overlap with stack? */
- max = rtop;
- else
- /* can't determine a good heap top */
- return;
- }
-
- /* put minbrk/maxbrk in same kernel virtual segment as data */
- if (IS_KVA1 (_end)) {
- /* kseg1: uncached data segment */
- _minbrk = PA_TO_KVA1 (min);
- _maxbrk = PA_TO_KVA1 (max);
- }
- else if (IS_KVA0 (_end)) {
- /* kseg0: cached data segmnt */
- _minbrk = PA_TO_KVA0 (min);
- _maxbrk = PA_TO_KVA0 (max);
- }
- else {
- /* kuseg: use virtual addresses */
- _minbrk = (void *) min;
- _minbrk = (void *) max;
- }
-
- curbrk = _minbrk;
-}
-
-
-void *
-_sbrk (int n)
-{
- void *newbrk, *p;
-
-#if 0
- pthread_mutex_lock (&sbmx);
-#endif
- if (!curbrk) {
- _sbrk_init ();
- if (!curbrk) {
- errno = ENOMEM;
-#if 0
- pthread_mutex_unlock (&sbmx);
-#endif
- return (void *)-1;
- }
- }
-
- p = curbrk;
- newbrk = curbrk + n;
- if (n > 0) {
- if (newbrk < curbrk || newbrk > _maxbrk) {
- errno = ENOMEM;
-#if 0
- pthread_mutex_unlock (&sbmx);
-#endif
- return (void *)-1;
- }
- } else {
- if (newbrk > curbrk || newbrk < _minbrk) {
- errno = EINVAL;
-#if 0
- pthread_mutex_unlock (&sbmx);
-#endif
- return (void *)-1;
- }
- }
- curbrk = newbrk;
-
-#if 0
- pthread_mutex_unlock (&sbmx);
-#endif
-
- return p;
-}
-
-void *
-sbrk (int n)
-{
- void *p;
-
- p = _sbrk(n);
-
- /* sbrk defined to return zeroed pages */
- if ((n > 0) && (p != (void *)-1))
- memset (p, 0, n);
-
- return p;
-}
[15/40] incubator-mynewt-core git commit: MYNEWT-741 Port of
LoRaMac-node library
Posted by ja...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9986f68c/net/lora/node/include/node/radio.h
----------------------------------------------------------------------
diff --git a/net/lora/node/include/node/radio.h b/net/lora/node/include/node/radio.h
new file mode 100644
index 0000000..6923ec9
--- /dev/null
+++ b/net/lora/node/include/node/radio.h
@@ -0,0 +1,337 @@
+/*
+ / _____) _ | |
+( (____ _____ ____ _| |_ _____ ____| |__
+ \____ \| ___ | (_ _) ___ |/ ___) _ \
+ _____) ) ____| | | || |_| ____( (___| | | |
+(______/|_____)_|_|_| \__)_____)\____)_| |_|
+ (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__
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9986f68c/net/lora/node/include/node/timer.h
----------------------------------------------------------------------
diff --git a/net/lora/node/include/node/timer.h b/net/lora/node/include/node/timer.h
new file mode 100644
index 0000000..424dc32
--- /dev/null
+++ b/net/lora/node/include/node/timer.h
@@ -0,0 +1,38 @@
+/*
+ / _____) _ | |
+((____ _____ ____ _| |_ _____ ____| |__
+ \____ \| ___ | (_ _) ___ |/ ___) _ \
+ _____)) ____| | | || |_| ____((___| | | |
+(______/|_____)_|_|_| \__)_____)\____)_| |_|
+ (C)2013 Semtech
+
+Description: Timer objects and scheduling management
+
+License: Revised BSD License, see LICENSE.TXT file include in the project
+
+Maintainer: Miguel Luis and Gregory Cristian
+*/
+#ifndef __TIMER_H__
+#define __TIMER_H__
+
+#include <inttypes.h>
+#include <stdbool.h>
+struct hal_timer;
+
+/*!
+ * \brief Return the Time elapsed since a fix moment in Time
+ *
+ * \param [IN] savedTime fix moment in Time
+ * \retval time returns elapsed time
+ */
+uint32_t TimerGetElapsedTime(uint32_t savedTime);
+
+/*!
+ * \brief Return the Time elapsed since a fix moment in Time
+ *
+ * \param [IN] eventInFuture fix moment in the future
+ * \retval time returns difference between now and future event
+ */
+uint32_t TimerGetFutureTime(uint32_t eventInFuture);
+
+#endif // __TIMER_H__
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9986f68c/net/lora/node/include/node/utilities.h
----------------------------------------------------------------------
diff --git a/net/lora/node/include/node/utilities.h b/net/lora/node/include/node/utilities.h
new file mode 100644
index 0000000..8816351
--- /dev/null
+++ b/net/lora/node/include/node/utilities.h
@@ -0,0 +1,72 @@
+/*
+ / _____) _ | |
+( (____ _____ ____ _| |_ _____ ____| |__
+ \____ \| ___ | (_ _) ___ |/ ___) _ \
+ _____) ) ____| | | || |_| ____( (___| | | |
+(______/|_____)_|_|_| \__)_____)\____)_| |_|
+ (C)2013 Semtech
+
+Description: Helper functions implementation
+
+License: Revised BSD License, see LICENSE.TXT file include in the project
+
+Maintainer: Miguel Luis and Gregory Cristian
+*/
+#ifndef __UTILITIES_H__
+#define __UTILITIES_H__
+
+#include <inttypes.h>
+
+/*!
+ * \brief Returns the minimum value between a and b
+ *
+ * \param [IN] a 1st value
+ * \param [IN] b 2nd value
+ * \retval minValue Minimum value
+ */
+#define MIN( a, b ) ( ( ( a ) < ( b ) ) ? ( a ) : ( b ) )
+
+/*!
+ * \brief Returns the maximum value between a and b
+ *
+ * \param [IN] a 1st value
+ * \param [IN] b 2nd value
+ * \retval maxValue Maximum value
+ */
+#define MAX( a, b ) ( ( ( a ) > ( b ) ) ? ( a ) : ( b ) )
+
+/*!
+ * \brief Returns 2 raised to the power of n
+ *
+ * \param [IN] n power value
+ * \retval result of raising 2 to the power n
+ */
+#define POW2( n ) ( 1 << n )
+
+/*!
+ * \brief Computes a random number between min and max
+ *
+ * \param [IN] min range minimum value
+ * \param [IN] max range maximum value
+ * \retval random random value in range min..max
+ */
+int32_t randr( int32_t min, int32_t max );
+
+/*!
+ * \brief Copies size elements of src array to dst array reversing the byte order
+ *
+ * \param [OUT] dst Destination array
+ * \param [IN] src Source array
+ * \param [IN] size Number of bytes to be copied
+ */
+void memcpyr( uint8_t *dst, const uint8_t *src, uint16_t size );
+
+/*!
+ * \brief Converts a nibble to an hexadecimal character
+ *
+ * \param [IN] a Nibble to be converted
+ * \retval hexChar Converted hexadecimal character
+ */
+int8_t Nibble2HexChar( uint8_t a );
+
+#endif // __UTILITIES_H__
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9986f68c/net/lora/node/pkg.yml
----------------------------------------------------------------------
diff --git a/net/lora/node/pkg.yml b/net/lora/node/pkg.yml
new file mode 100644
index 0000000..694bc01
--- /dev/null
+++ b/net/lora/node/pkg.yml
@@ -0,0 +1,42 @@
+#
+# 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.
+#
+
+pkg.name: net/lora/node
+pkg.description: Mynewt port of the Semtech LoRaWAN endpoint stack.
+pkg.author: "Semtech"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+ - lora
+
+pkg.cflags:
+ # Allow declarations inside for loops.
+ - "-std=c99"
+
+pkg.deps:
+
+pkg.deps.LORA_NODE_CLI:
+ - "@apache-mynewt-core/sys/shell"
+ - "@apache-mynewt-core/util/parse"
+
+pkg.req_apis:
+ - lora_node_board
+ - lora_node_radio
+
+pkg.init:
+ lora_node_init: 200
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9986f68c/net/lora/node/src/lora_cli.c
----------------------------------------------------------------------
diff --git a/net/lora/node/src/lora_cli.c b/net/lora/node/src/lora_cli.c
new file mode 100644
index 0000000..99156fb
--- /dev/null
+++ b/net/lora/node/src/lora_cli.c
@@ -0,0 +1,569 @@
+/*
+ * 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.
+ */
+
+#include "syscfg/syscfg.h"
+
+#if MYNEWT_VAL(LORA_NODE_CLI)
+
+#include <inttypes.h>
+#include <string.h>
+
+#include "sysinit/sysinit.h"
+#include "shell/shell.h"
+#include "console/console.h"
+#include "node/radio.h"
+#include "parse/parse.h"
+
+static int lora_cli_cmd_fn(int argc, char **argv);
+static int lora_cli_set_freq(int argc, char **argv);
+static int lora_cli_tx_cfg(int argc, char **argv);
+static int lora_cli_rx_cfg(int argc, char **argv);
+static int lora_cli_tx(int argc, char **argv);
+static int lora_cli_rx(int argc, char **argv);
+static int lora_cli_max_payload_len(int argc, char **argv);
+
+static struct shell_cmd lora_cli_cmd = {
+ .sc_cmd = "lora",
+ .sc_cmd_func = lora_cli_cmd_fn,
+};
+
+static struct shell_cmd lora_cli_subcmds[] = {
+ {
+ .sc_cmd = "set_freq",
+ .sc_cmd_func = lora_cli_set_freq,
+ },
+ {
+ .sc_cmd = "tx_cfg",
+ .sc_cmd_func = lora_cli_tx_cfg,
+ },
+ {
+ .sc_cmd = "rx_cfg",
+ .sc_cmd_func = lora_cli_rx_cfg,
+ },
+ {
+ .sc_cmd = "tx",
+ .sc_cmd_func = lora_cli_tx,
+ },
+ {
+ .sc_cmd = "rx",
+ .sc_cmd_func = lora_cli_rx,
+ },
+ {
+ .sc_cmd = "max_payload_len",
+ .sc_cmd_func = lora_cli_max_payload_len,
+ },
+};
+
+static int
+lora_cli_cmd_fn(int argc, char **argv)
+{
+ const struct shell_cmd *subcmd;
+ const char *err;
+ int rc;
+ int i;
+
+ if (argc <= 1) {
+ rc = 1;
+ err = NULL;
+ goto err;
+ }
+
+ for (i = 0;
+ i < sizeof lora_cli_subcmds / sizeof lora_cli_subcmds[0];
+ i++) {
+
+ subcmd = lora_cli_subcmds + i;
+ if (strcmp(argv[1], subcmd->sc_cmd) == 0) {
+ rc = subcmd->sc_cmd_func(argc - 1, argv + 1);
+ return rc;
+ }
+ }
+
+ rc = 1;
+ err = "invalid lora command";
+
+err:
+ if (err != NULL) {
+ console_printf("error: %s\n", err);
+ }
+
+ console_printf(
+"usage:\n"
+" lora set_freq\n"
+" lora tx_cfg\n"
+" lora rx_cfg\n"
+" lora tx\n"
+" lora rx\n"
+" lora max_payload_len\n");
+
+ return rc;
+}
+
+static int
+lora_cli_set_freq(int argc, char **argv)
+{
+ const char *err;
+ uint32_t freq;
+ int rc;
+
+ if (argc <= 1) {
+ rc = 1;
+ err = NULL;
+ goto err;
+ }
+
+ freq = parse_ull(argv[1], &rc);
+ if (rc != 0) {
+ err = "invalid frequency";
+ goto err;
+ }
+
+ Radio.SetChannel(freq);
+ return 0;
+
+err:
+ if (err != NULL) {
+ console_printf("error: %s\n", err);
+ }
+
+ console_printf(
+"usage:\n"
+" lora set_freq <hz>\n");
+
+ return rc;
+}
+
+static int
+lora_cli_tx_cfg(int argc, char **argv)
+{
+ RadioModems_t modem;
+ const char *err;
+ char **arg;
+ uint32_t bandwidth;
+ uint32_t datarate;
+ uint32_t timeout;
+ uint32_t fdev;
+ uint16_t preamble_len;
+ uint8_t hop_period;
+ uint8_t coderate;
+ int8_t power;
+ int freq_hop_on;
+ int iq_inverted;
+ int fix_len;
+ int crc_on;
+ int rc;
+
+ if (argc <= 13) {
+ rc = 1;
+ err = NULL;
+ goto err;
+ }
+
+ arg = argv + 1;
+
+ modem = parse_ull_bounds(*arg, 0, 1, &rc);
+ if (rc != 0) {
+ goto err;
+ }
+ arg++;
+
+ power = parse_ll_bounds(*arg, INT8_MIN, INT8_MAX, &rc);
+ if (rc != 0) {
+ goto err;
+ }
+ arg++;
+
+ fdev = parse_ull_bounds(*arg, 0, UINT32_MAX, &rc);
+ if (rc != 0) {
+ goto err;
+ }
+ arg++;
+
+ bandwidth = parse_ull_bounds(*arg, 0, UINT32_MAX, &rc);
+ if (rc != 0) {
+ goto err;
+ }
+ arg++;
+
+ datarate = parse_ull_bounds(*arg, 0, UINT32_MAX, &rc);
+ if (rc != 0) {
+ goto err;
+ }
+ arg++;
+
+ coderate = parse_ull_bounds(*arg, 0, UINT8_MAX, &rc);
+ if (rc != 0) {
+ goto err;
+ }
+ arg++;
+
+ preamble_len = parse_ull_bounds(*arg, 0, UINT16_MAX, &rc);
+ if (rc != 0) {
+ goto err;
+ }
+ arg++;
+
+ fix_len = parse_ull_bounds(*arg, 0, 1, &rc);
+ if (rc != 0) {
+ goto err;
+ }
+ arg++;
+
+ crc_on = parse_ull_bounds(*arg, 0, 1, &rc);
+ if (rc != 0) {
+ goto err;
+ }
+ arg++;
+
+ freq_hop_on = parse_ull_bounds(*arg, 0, 1, &rc);
+ if (rc != 0) {
+ goto err;
+ }
+ arg++;
+
+ hop_period = parse_ull_bounds(*arg, 0, UINT8_MAX, &rc);
+ if (rc != 0) {
+ goto err;
+ }
+ arg++;
+
+ iq_inverted = parse_ull_bounds(*arg, 0, 1, &rc);
+ if (rc != 0) {
+ goto err;
+ }
+ arg++;
+
+ timeout = parse_ull_bounds(*arg, 0, UINT32_MAX, &rc);
+ if (rc != 0) {
+ goto err;
+ }
+ arg++;
+
+ Radio.SetTxConfig(modem,
+ power,
+ fdev,
+ bandwidth,
+ datarate,
+ coderate,
+ preamble_len,
+ fix_len,
+ crc_on,
+ freq_hop_on,
+ hop_period,
+ iq_inverted,
+ timeout);
+
+ return 0;
+
+err:
+ if (err != NULL) {
+ console_printf("error: %s\n", err);
+ }
+
+ console_printf(
+"usage:\n"
+" lora tx_cfg <modem-type (0/1)> <power> <frequency-deviation>\n"
+" <bandwidth> <data-rate> <code-rate> <preamble-length>\n"
+" <fixed-length (0/1)> <crc-on (0/1)>\n"
+" <frequency-hopping (0/1)> <hop-period> <iq-inverted (0/1)>\n"
+" <timeout>\n");
+
+ return rc;
+}
+
+static int
+lora_cli_rx_cfg(int argc, char **argv)
+{
+ RadioModems_t modem;
+ const char *err;
+ char **arg;
+ uint32_t bandwidth_afc;
+ uint32_t bandwidth;
+ uint32_t datarate;
+ uint16_t preamble_len;
+ uint16_t symb_timeout;
+ uint8_t payload_len;
+ uint8_t hop_period;
+ uint8_t coderate;
+ int rx_continuous;
+ int freq_hop_on;
+ int iq_inverted;
+ int fix_len;
+ int crc_on;
+ int rc;
+
+ if (argc <= 14) {
+ rc = 1;
+ err = NULL;
+ goto err;
+ }
+
+ arg = argv + 1;
+
+ modem = parse_ull_bounds(*arg, 0, 1, &rc);
+ if (rc != 0) {
+ err = "invalid modem type";
+ goto err;
+ }
+ arg++;
+
+ bandwidth = parse_ull_bounds(*arg, 0, UINT32_MAX, &rc);
+ if (rc != 0) {
+ err = "invalid bandwidth";
+ goto err;
+ }
+ arg++;
+
+ datarate = parse_ull_bounds(*arg, 0, UINT32_MAX, &rc);
+ if (rc != 0) {
+ err = "invalid data rate";
+ goto err;
+ }
+ arg++;
+
+ coderate = parse_ull_bounds(*arg, 0, UINT8_MAX, &rc);
+ if (rc != 0) {
+ err = "invalid code rate";
+ goto err;
+ }
+ arg++;
+
+ bandwidth_afc = parse_ull_bounds(*arg, 0, UINT32_MAX, &rc);
+ if (rc != 0) {
+ err = "invalid bandwidtch_afc";
+ goto err;
+ }
+ arg++;
+
+ preamble_len = parse_ull_bounds(*arg, 0, UINT16_MAX, &rc);
+ if (rc != 0) {
+ err = "invalid preamble length";
+ goto err;
+ }
+ arg++;
+
+ symb_timeout = parse_ull_bounds(*arg, 0, UINT16_MAX, &rc);
+ if (rc != 0) {
+ err = "invalid symbol timeout";
+ goto err;
+ }
+ arg++;
+
+ fix_len = parse_ull_bounds(*arg, 0, 1, &rc);
+ if (rc != 0) {
+ err = "invalid fixed length value";
+ goto err;
+ }
+ arg++;
+
+ payload_len = parse_ull_bounds(*arg, 0, UINT8_MAX, &rc);
+ if (rc != 0) {
+ err = "invalid payload length";
+ goto err;
+ }
+ arg++;
+
+ crc_on = parse_ull_bounds(*arg, 0, 1, &rc);
+ if (rc != 0) {
+ err = "invalid crc on value";
+ goto err;
+ }
+ arg++;
+
+ freq_hop_on = parse_ull_bounds(*arg, 0, 1, &rc);
+ if (rc != 0) {
+ err = "invalid frequency hopping value";
+ goto err;
+ }
+ arg++;
+
+ hop_period = parse_ull_bounds(*arg, 0, UINT8_MAX, &rc);
+ if (rc != 0) {
+ err = "invalid hop period";
+ goto err;
+ }
+ arg++;
+
+ iq_inverted = parse_ull_bounds(*arg, 0, 1, &rc);
+ if (rc != 0) {
+ err = "invalid iq inverted value";
+ goto err;
+ }
+ arg++;
+
+ rx_continuous = parse_ull_bounds(*arg, 0, 1, &rc);
+ if (rc != 0) {
+ err = "invalid rx continuous value";
+ goto err;
+ }
+ arg++;
+
+ Radio.SetRxConfig(modem,
+ bandwidth,
+ datarate,
+ coderate,
+ bandwidth_afc,
+ preamble_len,
+ symb_timeout,
+ fix_len,
+ payload_len,
+ crc_on,
+ freq_hop_on,
+ hop_period,
+ iq_inverted,
+ rx_continuous);
+
+ return 0;
+
+err:
+ if (err != NULL) {
+ console_printf("error: %s\n", err);
+ }
+
+ console_printf(
+"usage:\n"
+" lora rx_cfg <modem-type (0/1)> <bandwidth> <data-rate> <code-rate>\n"
+" <bandwidtch-afc> <preamble-length> <symbol-timeout>\n"
+" <fixed-length (0/1)> <payload-length> <crc-on (0/1)>\n"
+" <frequency-hopping (0/1)> <hop-period> <iq-inverted (0/1)>\n"
+" <rx-continuous (0/1)>\n");
+
+ return rc;
+}
+
+static int
+lora_cli_tx(int argc, char **argv)
+{
+ uint8_t buf[UINT8_MAX];
+ const char *err;
+ int buf_sz;
+ int rc;
+
+ if (argc <= 1) {
+ rc = 1;
+ err = NULL;
+ goto err;
+ }
+
+ rc = parse_byte_stream(argv[1], sizeof buf, buf, &buf_sz);
+ if (rc != 0) {
+ err = "invalid payload";
+ goto err;
+ }
+
+ Radio.Send(buf, buf_sz);
+ return 0;
+
+err:
+ if (err != NULL) {
+ console_printf("error: %s\n", err);
+ }
+
+ console_printf(
+"usage:\n"
+" lora tx <0xXX:0xXX:...>\n");
+
+ return rc;
+}
+
+static int
+lora_cli_rx(int argc, char **argv)
+{
+ const char *err;
+ uint32_t timeout;
+ int rc;
+
+ if (argc <= 1) {
+ rc = 1;
+ err = NULL;
+ goto err;
+ }
+
+ timeout = parse_ull_bounds(argv[1], 0, UINT32_MAX, &rc);
+ if (rc != 0) {
+ err = "invalid timeout";
+ goto err;
+ }
+
+ Radio.Rx(timeout);
+ return 0;
+
+err:
+ if (err != NULL) {
+ console_printf("error: %s\n", err);
+ }
+
+ console_printf(
+"usage:\n"
+" lora rx <timeout>\n");
+
+ return rc;
+}
+
+static int
+lora_cli_max_payload_len(int argc, char **argv)
+{
+ RadioModems_t modem;
+ const char *err;
+ uint8_t len;
+ int rc;
+
+ if (argc <= 2) {
+ rc = 1;
+ err = NULL;
+ goto err;
+ }
+
+ modem = parse_ull_bounds(argv[1], 0, 1, &rc);
+ if (rc != 0) {
+ err = "invalid modem type";
+ goto err;
+ }
+
+ len = parse_ull_bounds(argv[2], 0, UINT8_MAX, &rc);
+ if (rc != 0) {
+ err = "invalid length";
+ goto err;
+ }
+
+ Radio.SetMaxPayloadLength(modem, len);
+ return 0;
+
+err:
+ if (err != NULL) {
+ console_printf("error: %s\n", err);
+ }
+
+ console_printf(
+"usage:\n"
+" lora max_payload_len <length>\n");
+
+ return rc;
+}
+
+void
+lora_cli_init(void)
+{
+ int rc;
+
+ rc = shell_cmd_register(&lora_cli_cmd);
+ SYSINIT_PANIC_ASSERT_MSG(rc == 0, "Failed to register lora CLI command");
+}
+
+#endif /* MYNEWT_VAL(LORA_NODE_CLI) */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9986f68c/net/lora/node/src/lora_node.c
----------------------------------------------------------------------
diff --git a/net/lora/node/src/lora_node.c b/net/lora/node/src/lora_node.c
new file mode 100644
index 0000000..57a2b1f
--- /dev/null
+++ b/net/lora/node/src/lora_node.c
@@ -0,0 +1,48 @@
+/*
+ * 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.
+ */
+
+#include "sysinit/sysinit.h"
+#include "syscfg/syscfg.h"
+#include "node/lora.h"
+#include "lora_priv.h"
+
+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)
+
+void
+lora_node_init(void)
+{
+ int rc;
+
+ 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);
+
+#if MYNEWT_VAL(LORA_NODE_CLI)
+ lora_cli_init();
+#endif
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9986f68c/net/lora/node/src/lora_priv.h
----------------------------------------------------------------------
diff --git a/net/lora/node/src/lora_priv.h b/net/lora/node/src/lora_priv.h
new file mode 100644
index 0000000..bf0dd28
--- /dev/null
+++ b/net/lora/node/src/lora_priv.h
@@ -0,0 +1,44 @@
+/*
+ * 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.
+ */
+
+#ifndef H_LORA_PRIV_
+#define H_LORA_PRIV_
+
+#include "syscfg/syscfg.h"
+
+#if MYNEWT_VAL(LORA_NODE_FREQ_BAND) == 433
+#define USE_BAND_433
+
+#elif MYNEWT_VAL(LORA_NODE_FREQ_BAND) == 470
+#define USE_BAND_470
+
+#elif MYNEWT_VAL(LORA_NODE_FREQ_BAND) == 780
+#define USE_BAND_780
+
+#elif MYNEWT_VAL(LORA_NODE_FREQ_BAND) == 868
+#define USE_BAND_868
+
+#elif MYNEWT_VAL(LORA_NODE_FREQ_BAND) == 915
+#define USE_BAND_915
+
+#endif
+
+void lora_cli_init(void);
+
+#endif
[39/40] incubator-mynewt-core git commit: Merge branch 'master' into
bluetooth5
Posted by ja...@apache.org.
Merge branch 'master' into bluetooth5
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/10e041be
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/10e041be
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/10e041be
Branch: refs/heads/bluetooth5
Commit: 10e041be14edd747b16ea515b9c1b34bb06811b7
Parents: 4cab052 debf64f
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Mon May 8 15:48:48 2017 +0200
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon May 8 15:48:48 2017 +0200
----------------------------------------------------------------------
apps/iptest/src/main.c | 4 +-
apps/loraping/pkg.yml | 47 +
apps/loraping/src/loraping.h | 27 +
apps/loraping/src/main.c | 277 ++
apps/loraping/src/rxinfo.c | 139 +
apps/lorashell/pkg.yml | 34 +
apps/lorashell/src/main.c | 514 ++
apps/lorashell/syscfg.yml | 29 +
compiler/xc32/compiler.yml | 4 +-
compiler/xc32/pkg.yml | 3 +
encoding/cborattr/src/cborattr.c | 3 +-
encoding/cborattr/test/src/test_cborattr.c | 1 +
encoding/cborattr/test/src/test_cborattr.h | 1 +
.../testcases/cborattr_decode_substring_key.c | 111 +
hw/bsp/nrf51-blenano/src/hal_bsp.c | 31 +
hw/bsp/nrf51-blenano/syscfg.yml | 26 +
hw/bsp/pic32mx470_6lp_clicker/pkg.yml | 4 +-
hw/bsp/pic32mx470_6lp_clicker/src/hal_bsp.c | 2 +-
hw/bsp/pic32mz2048_wi-fire/pkg.yml | 2 +
hw/bsp/pic32mz2048_wi-fire/src/hal_bsp.c | 2 +-
hw/bsp/pic32mz2048_wi-fire/src/os_bsp.c | 2 +-
.../src/arch/cortex_m4/startup_STM32F429x.s | 3 -
hw/bsp/telee02/pkg.yml | 3 +
hw/bsp/telee02/syscfg.yml | 1 +
hw/drivers/lora/sx1276/LICENSE.txt | 25 +
hw/drivers/lora/sx1276/include/radio/radio.h | 33 +
hw/drivers/lora/sx1276/pkg.yml | 32 +
hw/drivers/lora/sx1276/src/sx1276-board.c | 179 +
hw/drivers/lora/sx1276/src/sx1276-board.h | 127 +
hw/drivers/lora/sx1276/src/sx1276.c | 1824 +++++++
hw/drivers/lora/sx1276/src/sx1276.h | 364 ++
hw/drivers/lora/sx1276/src/sx1276Regs-Fsk.h | 1134 +++++
hw/drivers/lora/sx1276/src/sx1276Regs-LoRa.h | 565 +++
hw/drivers/lora/sx1276/syscfg.yml | 27 +
hw/drivers/lwip/stm32_eth/src/stm32_eth.c | 2 +-
hw/mcu/microchip/pic32mx470f512h/pkg.yml | 2 -
.../pic32mz2048efg100/include/mcu/mcu.h | 16 +
hw/mcu/microchip/pic32mz2048efg100/pkg.yml | 2 -
.../microchip/pic32mz2048efg100/src/hal_gpio.c | 485 ++
.../microchip/pic32mz2048efg100/src/hal_uart.c | 2 +-
.../arch/pic32/startup/cache-err-exception.S | 129 +
kernel/os/src/arch/pic32/startup/crt0.S | 623 +++
.../src/arch/pic32/startup/general-exception.S | 141 +
.../pic32/startup/simple-tlb-refill-exception.S | 135 +
.../stubs/default-bootstrap-exception-handler.c | 58 +
.../stubs/default-cache-err-exception-handler.c | 56 +
.../stubs/default-general-exception-handler.c | 54 +
.../src/arch/pic32/stubs/default-nmi-handler.S | 63 +
.../src/arch/pic32/stubs/default-on-bootstrap.c | 43 +
.../os/src/arch/pic32/stubs/default-on-reset.c | 43 +
...efault-simple-tlb-refill-exception-handler.c | 56 +
.../os/src/arch/pic32/stubs/pic32_init_cache.S | 299 ++
.../arch/pic32/stubs/pic32_init_tlb_ebi_sqi.S | 145 +
kernel/os/src/os_callout.c | 6 +-
net/lora/node/LICENSE.txt | 25 +
net/lora/node/README.md | 28 +
net/lora/node/include/node/lora.h | 34 +
.../node/include/node/mac/LoRaMac-definitions.h | 610 +++
net/lora/node/include/node/mac/LoRaMac.h | 1830 ++++++++
net/lora/node/include/node/mac/LoRaMacCrypto.h | 111 +
net/lora/node/include/node/mac/LoRaMacTest.h | 81 +
net/lora/node/include/node/radio.h | 337 ++
net/lora/node/include/node/utilities.h | 79 +
net/lora/node/pkg.yml | 41 +
net/lora/node/src/lora_cli.c | 569 +++
net/lora/node/src/lora_node.c | 48 +
net/lora/node/src/lora_priv.h | 44 +
net/lora/node/src/mac/LoRaMac.c | 4442 ++++++++++++++++++
net/lora/node/src/mac/LoRaMacCrypto.c | 203 +
net/lora/node/src/mac/aes.h | 160 +
net/lora/node/src/mac/cmac.h | 63 +
net/lora/node/src/utilities.c | 67 +
net/lora/node/syscfg.yml | 39 +
net/nimble/controller/src/ble_ll_conn_hci.c | 12 +-
net/nimble/host/src/ble_hs_dbg.c | 7 +-
net/nimble/host/src/ble_hs_hci_evt.c | 5 +-
sys/console/full/src/console.c | 6 +-
sys/console/minimal/src/console.c | 6 +-
util/parse/include/parse/parse.h | 47 +
util/parse/pkg.yml | 32 +
util/parse/src/parse.c | 263 ++
81 files changed, 17091 insertions(+), 38 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/10e041be/net/nimble/controller/src/ble_ll_conn_hci.c
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/10e041be/net/nimble/host/src/ble_hs_dbg.c
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/10e041be/net/nimble/host/src/ble_hs_hci_evt.c
----------------------------------------------------------------------
[31/40] incubator-mynewt-core git commit: moved cflags from MCU to
BSP as they were non-functional, implemented suggestion for console read
Posted by ja...@apache.org.
moved cflags from MCU to BSP as they were non-functional, implemented suggestion for console read
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/ecf379be
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/ecf379be
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/ecf379be
Branch: refs/heads/bluetooth5
Commit: ecf379bea71f943752765fa48f3c890dad505119
Parents: 0a5821d
Author: julian <ju...@imgtec.com>
Authored: Tue May 2 14:14:19 2017 +0100
Committer: julian <ju...@imgtec.com>
Committed: Thu May 4 16:58:45 2017 +0100
----------------------------------------------------------------------
hw/bsp/pic32mx470_6lp_clicker/pkg.yml | 4 +++-
hw/bsp/pic32mz2048_wi-fire/pkg.yml | 2 ++
hw/mcu/microchip/pic32mx470f512h/pkg.yml | 2 --
hw/mcu/microchip/pic32mz2048efg100/pkg.yml | 2 --
sys/console/full/src/console.c | 4 ++--
sys/console/minimal/src/console.c | 4 ++--
6 files changed, 9 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ecf379be/hw/bsp/pic32mx470_6lp_clicker/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/pic32mx470_6lp_clicker/pkg.yml b/hw/bsp/pic32mx470_6lp_clicker/pkg.yml
index 2e4242c..3b3db18 100644
--- a/hw/bsp/pic32mx470_6lp_clicker/pkg.yml
+++ b/hw/bsp/pic32mx470_6lp_clicker/pkg.yml
@@ -26,7 +26,9 @@ pkg.keywords:
- pic32
- microchip
- clicker
-
+
+pkg.cflags:
+ - -mprocessor=32MX470F512H
pkg.lflags:
- -Wl,--defsym=_min_heap_size=0x400
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ecf379be/hw/bsp/pic32mz2048_wi-fire/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/pic32mz2048_wi-fire/pkg.yml b/hw/bsp/pic32mz2048_wi-fire/pkg.yml
index ebd831b..f5f4827 100644
--- a/hw/bsp/pic32mz2048_wi-fire/pkg.yml
+++ b/hw/bsp/pic32mz2048_wi-fire/pkg.yml
@@ -27,6 +27,8 @@ pkg.keywords:
- microchip
- clicker
+pkg.cflags:
+ - -mprocessor=32MZ2048EFG100
pkg.lflags:
- -Wl,--defsym=_min_heap_size=0x400
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ecf379be/hw/mcu/microchip/pic32mx470f512h/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/mcu/microchip/pic32mx470f512h/pkg.yml b/hw/mcu/microchip/pic32mx470f512h/pkg.yml
index 824984e..a2497e1 100644
--- a/hw/mcu/microchip/pic32mx470f512h/pkg.yml
+++ b/hw/mcu/microchip/pic32mx470f512h/pkg.yml
@@ -24,8 +24,6 @@ pkg.homepage: "http://mynewt.apache.org/"
pkg.keywords:
- pic32
-pkg.cflags:
- - -mprocessor=32MX470F512H
pkg.deps:
- hw/hal
- compiler/xc32
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ecf379be/hw/mcu/microchip/pic32mz2048efg100/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/mcu/microchip/pic32mz2048efg100/pkg.yml b/hw/mcu/microchip/pic32mz2048efg100/pkg.yml
index a3ad428..cbd4d4c 100644
--- a/hw/mcu/microchip/pic32mz2048efg100/pkg.yml
+++ b/hw/mcu/microchip/pic32mz2048efg100/pkg.yml
@@ -24,8 +24,6 @@ pkg.homepage: "http://mynewt.apache.org/"
pkg.keywords:
- pic32
-pkg.cflags:
- - -mprocessor=32MZ2048EFG100
pkg.deps:
- hw/hal
- compiler/xc32
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ecf379be/sys/console/full/src/console.c
----------------------------------------------------------------------
diff --git a/sys/console/full/src/console.c b/sys/console/full/src/console.c
index 389d92f..c9d81f1 100644
--- a/sys/console/full/src/console.c
+++ b/sys/console/full/src/console.c
@@ -116,8 +116,8 @@ console_read(char *str, int cnt, int *newline)
}
cmd = ev->ev_arg;
len = strlen(cmd->line);
- if (cnt < len) {
- len = cnt;
+ if ((cnt - 1) < len) {
+ len = cnt - 1;
}
memcpy(str, cmd->line, len);
str[len] = '\0';
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ecf379be/sys/console/minimal/src/console.c
----------------------------------------------------------------------
diff --git a/sys/console/minimal/src/console.c b/sys/console/minimal/src/console.c
index 21f9d20..0b88ab9 100644
--- a/sys/console/minimal/src/console.c
+++ b/sys/console/minimal/src/console.c
@@ -86,8 +86,8 @@ console_read(char *str, int cnt, int *newline)
}
cmd = ev->ev_arg;
len = strlen(cmd->line);
- if (cnt < len) {
- len = cnt;
+ if ((cnt - 1) < len) {
+ len = cnt - 1;
}
memcpy(str, cmd->line, len);
str[len] = '\0';
[25/40] incubator-mynewt-core git commit: This closes #248.
Posted by ja...@apache.org.
This closes #248.
Merge remote-tracking branch 'ccollins476ad/loramac-node'
* ccollins476ad/loramac-node:
MYNEWT-741 Fix loraping app.
MYNEWT-741 Lora cleanup
MYNEWT-741 lorashell - Tx predictable payloads
MYNEWT-741 Port of LoRaMac-node library
MYNEWT-741 Port of LoRaMac-node library
MYNEWT-740 Rudimentary Text parsing package.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/702dc23e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/702dc23e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/702dc23e
Branch: refs/heads/bluetooth5
Commit: 702dc23e8e35056d71bf42636fa31e251398e2ae
Parents: 25ec579 f3b97d5
Author: Christopher Collins <cc...@apache.org>
Authored: Fri Apr 28 17:28:23 2017 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Fri Apr 28 17:28:23 2017 -0700
----------------------------------------------------------------------
apps/loraping/pkg.yml | 47 +
apps/loraping/src/loraping.h | 27 +
apps/loraping/src/main.c | 277 ++
apps/loraping/src/rxinfo.c | 139 +
apps/lorashell/pkg.yml | 34 +
apps/lorashell/src/main.c | 514 ++
apps/lorashell/syscfg.yml | 27 +
hw/bsp/telee02/pkg.yml | 3 +
hw/bsp/telee02/syscfg.yml | 1 +
hw/drivers/lora/sx1276/LICENSE.txt | 25 +
hw/drivers/lora/sx1276/include/radio/radio.h | 33 +
hw/drivers/lora/sx1276/pkg.yml | 32 +
hw/drivers/lora/sx1276/src/sx1276-board.c | 179 +
hw/drivers/lora/sx1276/src/sx1276-board.h | 127 +
hw/drivers/lora/sx1276/src/sx1276.c | 1824 +++++++
hw/drivers/lora/sx1276/src/sx1276.h | 364 ++
hw/drivers/lora/sx1276/src/sx1276Regs-Fsk.h | 1134 +++++
hw/drivers/lora/sx1276/src/sx1276Regs-LoRa.h | 565 +++
hw/drivers/lora/sx1276/syscfg.yml | 27 +
net/lora/node/LICENSE.txt | 25 +
net/lora/node/README.md | 28 +
net/lora/node/include/node/lora.h | 34 +
.../node/include/node/mac/LoRaMac-definitions.h | 610 +++
net/lora/node/include/node/mac/LoRaMac.h | 1830 ++++++++
net/lora/node/include/node/mac/LoRaMacCrypto.h | 111 +
net/lora/node/include/node/mac/LoRaMacTest.h | 81 +
net/lora/node/include/node/radio.h | 337 ++
net/lora/node/include/node/utilities.h | 79 +
net/lora/node/pkg.yml | 41 +
net/lora/node/src/lora_cli.c | 569 +++
net/lora/node/src/lora_node.c | 48 +
net/lora/node/src/lora_priv.h | 44 +
net/lora/node/src/mac/LoRaMac.c | 4442 ++++++++++++++++++
net/lora/node/src/mac/LoRaMacCrypto.c | 203 +
net/lora/node/src/mac/aes.h | 160 +
net/lora/node/src/mac/cmac.h | 63 +
net/lora/node/src/utilities.c | 67 +
net/lora/node/syscfg.yml | 39 +
38 files changed, 14190 insertions(+)
----------------------------------------------------------------------
[11/40] incubator-mynewt-core git commit: MYNEWT-741 Port of
LoRaMac-node library
Posted by ja...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/560fa920/hw/drivers/lora/node/radio/sx1276/src/sx1276.c
----------------------------------------------------------------------
diff --git a/hw/drivers/lora/node/radio/sx1276/src/sx1276.c b/hw/drivers/lora/node/radio/sx1276/src/sx1276.c
deleted file mode 100644
index 60007e5..0000000
--- a/hw/drivers/lora/node/radio/sx1276/src/sx1276.c
+++ /dev/null
@@ -1,1826 +0,0 @@
-/*
- / _____) _ | |
-( (____ _____ ____ _| |_ _____ ____| |__
- \____ \| ___ | (_ _) ___ |/ ___) _ \
- _____) ) ____| | | || |_| ____( (___| | | |
-(______/|_____)_|_|_| \__)_____)\____)_| |_|
- (C)2013 Semtech
-
-Description: Generic SX1276 driver implementation
-
-License: Revised BSD License, see LICENSE.TXT file include in the project
-
-Maintainer: Miguel Luis, Gregory Cristian and Wael Guibene
-*/
-#include <assert.h>
-#include <math.h>
-#include <string.h>
-#include "syscfg/syscfg.h"
-#include "hal/hal_gpio.h"
-#include "hal/hal_spi.h"
-#include "os/os.h"
-#include "node/lora.h"
-#include "node/radio.h"
-#include "board/board.h"
-#include "sx1276.h"
-#include "sx1276-board.h"
-
-/*
- * Local types definition
- */
-
-/*!
- * Radio registers definition
- */
-typedef struct
-{
- RadioModems_t Modem;
- uint8_t Addr;
- uint8_t Value;
-}RadioRegisters_t;
-
-/*!
- * FSK bandwidth definition
- */
-typedef struct
-{
- uint32_t bandwidth;
- uint8_t RegValue;
-}FskBandwidth_t;
-
-
-/*
- * Private functions prototypes
- */
-
-/*!
- * Performs the Rx chain calibration for LF and HF bands
- * \remark Must be called just after the reset so all registers are at their
- * default values
- */
-static void RxChainCalibration( void );
-
-/*!
- * \brief Resets the SX1276
- */
-void SX1276Reset( void );
-
-/*!
- * \brief Sets the SX1276 in transmission mode for the given time
- * \param [IN] timeout Transmission timeout [ms] [0: continuous, others timeout]
- */
-void SX1276SetTx( uint32_t timeout );
-
-/*!
- * \brief Writes the buffer contents to the SX1276 FIFO
- *
- * \param [IN] buffer Buffer containing data to be put on the FIFO.
- * \param [IN] size Number of bytes to be written to the FIFO
- */
-void SX1276WriteFifo( uint8_t *buffer, uint8_t size );
-
-/*!
- * \brief Reads the contents of the SX1276 FIFO
- *
- * \param [OUT] buffer Buffer where to copy the FIFO read data.
- * \param [IN] size Number of bytes to be read from the FIFO
- */
-void SX1276ReadFifo( uint8_t *buffer, uint8_t size );
-
-/*!
- * \brief Sets the SX1276 operating mode
- *
- * \param [IN] opMode New operating mode
- */
-void SX1276SetOpMode( uint8_t opMode );
-
-/*
- * SX1276 DIO IRQ callback functions prototype
- */
-
-/*!
- * \brief DIO 0 IRQ callback
- */
-void SX1276OnDio0Irq(void *unused);
-
-/*!
- * \brief DIO 1 IRQ callback
- */
-void SX1276OnDio1Irq(void *unused);
-
-/*!
- * \brief DIO 2 IRQ callback
- */
-void SX1276OnDio2Irq(void *unused);
-
-/*!
- * \brief DIO 3 IRQ callback
- */
-void SX1276OnDio3Irq(void *unused);
-
-/*!
- * \brief DIO 4 IRQ callback
- */
-void SX1276OnDio4Irq(void *unused);
-
-/*!
- * \brief DIO 5 IRQ callback
- */
-void SX1276OnDio5Irq(void *unused);
-
-/*!
- * \brief Tx & Rx timeout timer callback
- */
-void SX1276OnTimeoutIrq(void *unused);
-
-/*
- * Private global constants
- */
-
-/*!
- * Radio hardware registers initialization
- *
- * \remark RADIO_INIT_REGISTERS_VALUE is defined in sx1276-board.h file
- */
-const RadioRegisters_t RadioRegsInit[] = RADIO_INIT_REGISTERS_VALUE;
-
-/*!
- * Constant values need to compute the RSSI value
- */
-#define RSSI_OFFSET_LF -164
-#define RSSI_OFFSET_HF -157
-
-/*!
- * Precomputed FSK bandwidth registers values
- */
-const FskBandwidth_t FskBandwidths[] =
-{
- { 2600 , 0x17 },
- { 3100 , 0x0F },
- { 3900 , 0x07 },
- { 5200 , 0x16 },
- { 6300 , 0x0E },
- { 7800 , 0x06 },
- { 10400 , 0x15 },
- { 12500 , 0x0D },
- { 15600 , 0x05 },
- { 20800 , 0x14 },
- { 25000 , 0x0C },
- { 31300 , 0x04 },
- { 41700 , 0x13 },
- { 50000 , 0x0B },
- { 62500 , 0x03 },
- { 83333 , 0x12 },
- { 100000, 0x0A },
- { 125000, 0x02 },
- { 166700, 0x11 },
- { 200000, 0x09 },
- { 250000, 0x01 },
- { 300000, 0x00 }, // Invalid Bandwidth
-};
-
-/*
- * Private global variables
- */
-
-/*!
- * Radio callbacks variable
- */
-static RadioEvents_t *RadioEvents;
-
-/*!
- * Reception buffer
- */
-static uint8_t RxTxBuffer[RX_BUFFER_SIZE];
-
-/*
- * Public global variables
- */
-
-/*!
- * Radio hardware and global parameters
- */
-SX1276_t SX1276;
-
-/*!
- * Hardware DIO IRQ callback initialization
- */
-DioIrqHandler *DioIrq[] = { SX1276OnDio0Irq, SX1276OnDio1Irq,
- SX1276OnDio2Irq, SX1276OnDio3Irq,
- SX1276OnDio4Irq, NULL };
-
-/*!
- * Tx and Rx timers
- */
-struct hal_timer TxTimeoutTimer;
-struct hal_timer RxTimeoutTimer;
-struct hal_timer RxTimeoutSyncWord;
-
-static uint32_t rx_timeout_sync_delay = -1;
-
-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 );
- }
-}
-
-static void
-SX1276RxError( void )
-{
- STATS_INC(lora_stats, rx_error);
-
- if( ( RadioEvents != NULL ) && ( RadioEvents->RxError != NULL ) )
- {
- RadioEvents->RxError( );
- }
-}
-
-static void
-SX1276RxTimeout( void )
-{
- STATS_INC(lora_stats, rx_timeout);
-
- if( ( RadioEvents != NULL ) && ( RadioEvents->RxTimeout != NULL ) )
- {
- RadioEvents->RxTimeout( );
- }
-}
-
-static void
-SX1276TxDone( void )
-{
- STATS_INC(lora_stats, tx_success);
-
- if( ( RadioEvents != NULL ) && ( RadioEvents->TxDone != NULL ) )
- {
- RadioEvents->TxDone( );
- }
-}
-
-static void
-SX1276TxTimeout( void )
-{
- STATS_INC(lora_stats, tx_timeout);
-
- if( ( RadioEvents != NULL ) && ( RadioEvents->TxTimeout != NULL ) )
- {
- RadioEvents->TxTimeout( );
- }
-}
-
-/*
- * Radio driver functions implementation
- */
-
-void SX1276Init( RadioEvents_t *events )
-{
- uint8_t i;
-
- RadioEvents = events;
-
- // Initialize driver timeout timers
- os_cputime_timer_init(&TxTimeoutTimer, SX1276OnTimeoutIrq, NULL);
- os_cputime_timer_init(&RxTimeoutTimer, SX1276OnTimeoutIrq, NULL);
- os_cputime_timer_init(&RxTimeoutSyncWord, SX1276OnTimeoutIrq, NULL);
-
- SX1276Reset( );
-
- RxChainCalibration( );
-
- SX1276SetOpMode( RF_OPMODE_SLEEP );
-
- SX1276IoIrqInit( DioIrq );
-
- for( i = 0; i < sizeof( RadioRegsInit ) / sizeof( RadioRegisters_t ); i++ )
- {
- SX1276SetModem( RadioRegsInit[i].Modem );
- SX1276Write( RadioRegsInit[i].Addr, RadioRegsInit[i].Value );
- }
-
- SX1276SetModem( MODEM_FSK );
-
- SX1276.Settings.State = RF_IDLE;
-}
-
-RadioState_t SX1276GetStatus( void )
-{
- return SX1276.Settings.State;
-}
-
-void SX1276SetChannel( uint32_t freq )
-{
- SX1276.Settings.Channel = freq;
- freq = ( uint32_t )( ( double )freq / ( double )FREQ_STEP );
- SX1276Write( REG_FRFMSB, ( uint8_t )( ( freq >> 16 ) & 0xFF ) );
- SX1276Write( REG_FRFMID, ( uint8_t )( ( freq >> 8 ) & 0xFF ) );
- SX1276Write( REG_FRFLSB, ( uint8_t )( freq & 0xFF ) );
-}
-
-bool SX1276IsChannelFree( RadioModems_t modem, uint32_t freq, int16_t rssiThresh )
-{
- int16_t rssi = 0;
-
- SX1276SetModem( modem );
-
- SX1276SetChannel( freq );
-
- SX1276SetOpMode( RF_OPMODE_RECEIVER );
-
- os_cputime_delay_usecs(1000);
-
- rssi = SX1276ReadRssi( modem );
-
- SX1276SetSleep( );
-
- if( rssi > rssiThresh )
- {
- return false;
- }
- return true;
-}
-
-uint32_t SX1276Random( void )
-{
- uint8_t i;
- uint32_t rnd = 0;
-
- /*
- * Radio setup for random number generation
- */
- // Set LoRa modem ON
- SX1276SetModem( MODEM_LORA );
-
- // Disable LoRa modem interrupts
- SX1276Write( REG_LR_IRQFLAGSMASK, RFLR_IRQFLAGS_RXTIMEOUT |
- RFLR_IRQFLAGS_RXDONE |
- RFLR_IRQFLAGS_PAYLOADCRCERROR |
- RFLR_IRQFLAGS_VALIDHEADER |
- RFLR_IRQFLAGS_TXDONE |
- RFLR_IRQFLAGS_CADDONE |
- RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL |
- RFLR_IRQFLAGS_CADDETECTED );
-
- // Set radio in continuous reception
- SX1276SetOpMode( RF_OPMODE_RECEIVER );
-
- for( i = 0; i < 32; i++ )
- {
- os_cputime_delay_usecs(1000);
- // Unfiltered RSSI value reading. Only takes the LSB value
- rnd |= ( ( uint32_t )SX1276Read( REG_LR_RSSIWIDEBAND ) & 0x01 ) << i;
- }
-
- SX1276SetSleep( );
-
- return rnd;
-}
-
-/*!
- * Performs the Rx chain calibration for LF and HF bands
- * \remark Must be called just after the reset so all registers are at their
- * default values
- */
-static void RxChainCalibration( void )
-{
- uint8_t regPaConfigInitVal;
- uint32_t initialFreq;
-
- // Save context
- regPaConfigInitVal = SX1276Read( REG_PACONFIG );
- initialFreq = ( double )( ( ( uint32_t )SX1276Read( REG_FRFMSB ) << 16 ) |
- ( ( uint32_t )SX1276Read( REG_FRFMID ) << 8 ) |
- ( ( uint32_t )SX1276Read( REG_FRFLSB ) ) ) * ( double )FREQ_STEP;
-
- // Cut the PA just in case, RFO output, power = -1 dBm
- SX1276Write( REG_PACONFIG, 0x00 );
-
- // Launch Rx chain calibration for LF band
- SX1276Write( REG_IMAGECAL, ( SX1276Read( REG_IMAGECAL ) & RF_IMAGECAL_IMAGECAL_MASK ) | RF_IMAGECAL_IMAGECAL_START );
- while( ( SX1276Read( REG_IMAGECAL ) & RF_IMAGECAL_IMAGECAL_RUNNING ) == RF_IMAGECAL_IMAGECAL_RUNNING )
- {
- }
-
- // Sets a Frequency in HF band
- SX1276SetChannel( 868000000 );
-
- // Launch Rx chain calibration for HF band
- SX1276Write( REG_IMAGECAL, ( SX1276Read( REG_IMAGECAL ) & RF_IMAGECAL_IMAGECAL_MASK ) | RF_IMAGECAL_IMAGECAL_START );
- while( ( SX1276Read( REG_IMAGECAL ) & RF_IMAGECAL_IMAGECAL_RUNNING ) == RF_IMAGECAL_IMAGECAL_RUNNING )
- {
- }
-
- // Restore context
- SX1276Write( REG_PACONFIG, regPaConfigInitVal );
- SX1276SetChannel( initialFreq );
-}
-
-/*!
- * Returns the known FSK bandwidth registers value
- *
- * \param [IN] bandwidth Bandwidth value in Hz
- * \retval regValue Bandwidth register value.
- */
-static uint8_t GetFskBandwidthRegValue( uint32_t bandwidth )
-{
- uint8_t i;
-
- for( i = 0; i < ( sizeof( FskBandwidths ) / sizeof( FskBandwidth_t ) ) - 1; i++ )
- {
- if( ( bandwidth >= FskBandwidths[i].bandwidth ) && ( bandwidth < FskBandwidths[i + 1].bandwidth ) )
- {
- return FskBandwidths[i].RegValue;
- }
- }
- // ERROR: Value not found
- while( 1 );
-}
-
-void SX1276SetRxConfig( 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 )
-{
- SX1276SetModem( modem );
-
- switch( modem )
- {
- case MODEM_FSK:
- {
- SX1276.Settings.Fsk.Bandwidth = bandwidth;
- SX1276.Settings.Fsk.Datarate = datarate;
- SX1276.Settings.Fsk.BandwidthAfc = bandwidthAfc;
- SX1276.Settings.Fsk.FixLen = fixLen;
- SX1276.Settings.Fsk.PayloadLen = payloadLen;
- SX1276.Settings.Fsk.CrcOn = crcOn;
- SX1276.Settings.Fsk.IqInverted = iqInverted;
- SX1276.Settings.Fsk.RxContinuous = rxContinuous;
- SX1276.Settings.Fsk.PreambleLen = preambleLen;
-
- datarate = ( uint16_t )( ( double )XTAL_FREQ / ( double )datarate );
- SX1276Write( REG_BITRATEMSB, ( uint8_t )( datarate >> 8 ) );
- SX1276Write( REG_BITRATELSB, ( uint8_t )( datarate & 0xFF ) );
-
- SX1276Write( REG_RXBW, GetFskBandwidthRegValue( bandwidth ) );
- SX1276Write( REG_AFCBW, GetFskBandwidthRegValue( bandwidthAfc ) );
-
- SX1276Write( REG_PREAMBLEMSB, ( uint8_t )( ( preambleLen >> 8 ) & 0xFF ) );
- SX1276Write( REG_PREAMBLELSB, ( uint8_t )( preambleLen & 0xFF ) );
-
- if( fixLen == 1 )
- {
- SX1276Write( REG_PAYLOADLENGTH, payloadLen );
- }
- else
- {
- SX1276Write( REG_PAYLOADLENGTH, 0xFF ); // Set payload length to the maximum
- }
-
- SX1276Write( REG_PACKETCONFIG1,
- ( SX1276Read( REG_PACKETCONFIG1 ) &
- RF_PACKETCONFIG1_CRC_MASK &
- RF_PACKETCONFIG1_PACKETFORMAT_MASK ) |
- ( ( fixLen == 1 ) ? RF_PACKETCONFIG1_PACKETFORMAT_FIXED : RF_PACKETCONFIG1_PACKETFORMAT_VARIABLE ) |
- ( crcOn << 4 ) );
- }
- break;
- case MODEM_LORA:
- {
- if( bandwidth > 2 )
- {
- // Fatal error: When using LoRa modem only bandwidths 125, 250 and 500 kHz are supported
- while( 1 );
- }
- bandwidth += 7;
- SX1276.Settings.LoRa.Bandwidth = bandwidth;
- SX1276.Settings.LoRa.Datarate = datarate;
- SX1276.Settings.LoRa.Coderate = coderate;
- SX1276.Settings.LoRa.PreambleLen = preambleLen;
- SX1276.Settings.LoRa.FixLen = fixLen;
- SX1276.Settings.LoRa.PayloadLen = payloadLen;
- SX1276.Settings.LoRa.CrcOn = crcOn;
- SX1276.Settings.LoRa.FreqHopOn = freqHopOn;
- SX1276.Settings.LoRa.HopPeriod = hopPeriod;
- SX1276.Settings.LoRa.IqInverted = iqInverted;
- SX1276.Settings.LoRa.RxContinuous = rxContinuous;
-
- if( datarate > 12 )
- {
- datarate = 12;
- }
- else if( datarate < 6 )
- {
- datarate = 6;
- }
-
- if( ( ( bandwidth == 7 ) && ( ( datarate == 11 ) || ( datarate == 12 ) ) ) ||
- ( ( bandwidth == 8 ) && ( datarate == 12 ) ) )
- {
- SX1276.Settings.LoRa.LowDatarateOptimize = 0x01;
- }
- else
- {
- SX1276.Settings.LoRa.LowDatarateOptimize = 0x00;
- }
-
- SX1276Write( REG_LR_MODEMCONFIG1,
- ( SX1276Read( REG_LR_MODEMCONFIG1 ) &
- RFLR_MODEMCONFIG1_BW_MASK &
- RFLR_MODEMCONFIG1_CODINGRATE_MASK &
- RFLR_MODEMCONFIG1_IMPLICITHEADER_MASK ) |
- ( bandwidth << 4 ) | ( coderate << 1 ) |
- fixLen );
-
- SX1276Write( REG_LR_MODEMCONFIG2,
- ( SX1276Read( REG_LR_MODEMCONFIG2 ) &
- RFLR_MODEMCONFIG2_SF_MASK &
- RFLR_MODEMCONFIG2_RXPAYLOADCRC_MASK &
- RFLR_MODEMCONFIG2_SYMBTIMEOUTMSB_MASK ) |
- ( datarate << 4 ) | ( crcOn << 2 ) |
- ( ( symbTimeout >> 8 ) & ~RFLR_MODEMCONFIG2_SYMBTIMEOUTMSB_MASK ) );
-
- SX1276Write( REG_LR_MODEMCONFIG3,
- ( SX1276Read( REG_LR_MODEMCONFIG3 ) &
- RFLR_MODEMCONFIG3_LOWDATARATEOPTIMIZE_MASK ) |
- ( SX1276.Settings.LoRa.LowDatarateOptimize << 3 ) );
-
- SX1276Write( REG_LR_SYMBTIMEOUTLSB, ( uint8_t )( symbTimeout & 0xFF ) );
-
- SX1276Write( REG_LR_PREAMBLEMSB, ( uint8_t )( ( preambleLen >> 8 ) & 0xFF ) );
- SX1276Write( REG_LR_PREAMBLELSB, ( uint8_t )( preambleLen & 0xFF ) );
-
- if( fixLen == 1 )
- {
- SX1276Write( REG_LR_PAYLOADLENGTH, payloadLen );
- }
-
- if( SX1276.Settings.LoRa.FreqHopOn == true )
- {
- SX1276Write( REG_LR_PLLHOP, ( SX1276Read( REG_LR_PLLHOP ) & RFLR_PLLHOP_FASTHOP_MASK ) | RFLR_PLLHOP_FASTHOP_ON );
- SX1276Write( REG_LR_HOPPERIOD, SX1276.Settings.LoRa.HopPeriod );
- }
-
- if( ( bandwidth == 9 ) && ( SX1276.Settings.Channel > RF_MID_BAND_THRESH ) )
- {
- // ERRATA 2.1 - Sensitivity Optimization with a 500 kHz Bandwidth
- SX1276Write( REG_LR_TEST36, 0x02 );
- SX1276Write( REG_LR_TEST3A, 0x64 );
- }
- else if( bandwidth == 9 )
- {
- // ERRATA 2.1 - Sensitivity Optimization with a 500 kHz Bandwidth
- SX1276Write( REG_LR_TEST36, 0x02 );
- SX1276Write( REG_LR_TEST3A, 0x7F );
- }
- else
- {
- // ERRATA 2.1 - Sensitivity Optimization with a 500 kHz Bandwidth
- SX1276Write( REG_LR_TEST36, 0x03 );
- }
-
- if( datarate == 6 )
- {
- SX1276Write( REG_LR_DETECTOPTIMIZE,
- ( SX1276Read( REG_LR_DETECTOPTIMIZE ) &
- RFLR_DETECTIONOPTIMIZE_MASK ) |
- RFLR_DETECTIONOPTIMIZE_SF6 );
- SX1276Write( REG_LR_DETECTIONTHRESHOLD,
- RFLR_DETECTIONTHRESH_SF6 );
- }
- else
- {
- SX1276Write( REG_LR_DETECTOPTIMIZE,
- ( SX1276Read( REG_LR_DETECTOPTIMIZE ) &
- RFLR_DETECTIONOPTIMIZE_MASK ) |
- RFLR_DETECTIONOPTIMIZE_SF7_TO_SF12 );
- SX1276Write( REG_LR_DETECTIONTHRESHOLD,
- RFLR_DETECTIONTHRESH_SF7_TO_SF12 );
- }
- }
- break;
- }
-}
-
-void SX1276SetTxConfig( 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 )
-{
- uint8_t paConfig = 0;
- uint8_t paDac = 0;
-
- SX1276SetModem( modem );
-
- paConfig = SX1276Read( REG_PACONFIG );
- paDac = SX1276Read( REG_PADAC );
-
- paConfig = ( paConfig & RF_PACONFIG_PASELECT_MASK ) | SX1276GetPaSelect( SX1276.Settings.Channel );
- paConfig = ( paConfig & RF_PACONFIG_MAX_POWER_MASK ) | 0x70;
-
- if( ( paConfig & RF_PACONFIG_PASELECT_PABOOST ) == RF_PACONFIG_PASELECT_PABOOST )
- {
- if( power > 17 )
- {
- paDac = ( paDac & RF_PADAC_20DBM_MASK ) | RF_PADAC_20DBM_ON;
- }
- else
- {
- paDac = ( paDac & RF_PADAC_20DBM_MASK ) | RF_PADAC_20DBM_OFF;
- }
- if( ( paDac & RF_PADAC_20DBM_ON ) == RF_PADAC_20DBM_ON )
- {
- if( power < 5 )
- {
- power = 5;
- }
- if( power > 20 )
- {
- power = 20;
- }
- paConfig = ( paConfig & RF_PACONFIG_OUTPUTPOWER_MASK ) | ( uint8_t )( ( uint16_t )( power - 5 ) & 0x0F );
- }
- else
- {
- if( power < 2 )
- {
- power = 2;
- }
- if( power > 17 )
- {
- power = 17;
- }
- paConfig = ( paConfig & RF_PACONFIG_OUTPUTPOWER_MASK ) | ( uint8_t )( ( uint16_t )( power - 2 ) & 0x0F );
- }
- }
- else
- {
- if( power < -1 )
- {
- power = -1;
- }
- if( power > 14 )
- {
- power = 14;
- }
- paConfig = ( paConfig & RF_PACONFIG_OUTPUTPOWER_MASK ) | ( uint8_t )( ( uint16_t )( power + 1 ) & 0x0F );
- }
- SX1276Write( REG_PACONFIG, paConfig );
- SX1276Write( REG_PADAC, paDac );
-
- switch( modem )
- {
- case MODEM_FSK:
- {
- SX1276.Settings.Fsk.Power = power;
- SX1276.Settings.Fsk.Fdev = fdev;
- SX1276.Settings.Fsk.Bandwidth = bandwidth;
- SX1276.Settings.Fsk.Datarate = datarate;
- SX1276.Settings.Fsk.PreambleLen = preambleLen;
- SX1276.Settings.Fsk.FixLen = fixLen;
- SX1276.Settings.Fsk.CrcOn = crcOn;
- SX1276.Settings.Fsk.IqInverted = iqInverted;
- SX1276.Settings.Fsk.TxTimeout = timeout;
-
- fdev = ( uint16_t )( ( double )fdev / ( double )FREQ_STEP );
- SX1276Write( REG_FDEVMSB, ( uint8_t )( fdev >> 8 ) );
- SX1276Write( REG_FDEVLSB, ( uint8_t )( fdev & 0xFF ) );
-
- datarate = ( uint16_t )( ( double )XTAL_FREQ / ( double )datarate );
- SX1276Write( REG_BITRATEMSB, ( uint8_t )( datarate >> 8 ) );
- SX1276Write( REG_BITRATELSB, ( uint8_t )( datarate & 0xFF ) );
-
- SX1276Write( REG_PREAMBLEMSB, ( preambleLen >> 8 ) & 0x00FF );
- SX1276Write( REG_PREAMBLELSB, preambleLen & 0xFF );
-
- SX1276Write( REG_PACKETCONFIG1,
- ( SX1276Read( REG_PACKETCONFIG1 ) &
- RF_PACKETCONFIG1_CRC_MASK &
- RF_PACKETCONFIG1_PACKETFORMAT_MASK ) |
- ( ( fixLen == 1 ) ? RF_PACKETCONFIG1_PACKETFORMAT_FIXED : RF_PACKETCONFIG1_PACKETFORMAT_VARIABLE ) |
- ( crcOn << 4 ) );
-
- }
- break;
- case MODEM_LORA:
- {
- SX1276.Settings.LoRa.Power = power;
- if( bandwidth > 2 )
- {
- // Fatal error: When using LoRa modem only bandwidths 125, 250 and 500 kHz are supported
- while( 1 );
- }
- bandwidth += 7;
- SX1276.Settings.LoRa.Bandwidth = bandwidth;
- SX1276.Settings.LoRa.Datarate = datarate;
- SX1276.Settings.LoRa.Coderate = coderate;
- SX1276.Settings.LoRa.PreambleLen = preambleLen;
- SX1276.Settings.LoRa.FixLen = fixLen;
- SX1276.Settings.LoRa.FreqHopOn = freqHopOn;
- SX1276.Settings.LoRa.HopPeriod = hopPeriod;
- SX1276.Settings.LoRa.CrcOn = crcOn;
- SX1276.Settings.LoRa.IqInverted = iqInverted;
- SX1276.Settings.LoRa.TxTimeout = timeout;
-
- if( datarate > 12 )
- {
- datarate = 12;
- }
- else if( datarate < 6 )
- {
- datarate = 6;
- }
- if( ( ( bandwidth == 7 ) && ( ( datarate == 11 ) || ( datarate == 12 ) ) ) ||
- ( ( bandwidth == 8 ) && ( datarate == 12 ) ) )
- {
- SX1276.Settings.LoRa.LowDatarateOptimize = 0x01;
- }
- else
- {
- SX1276.Settings.LoRa.LowDatarateOptimize = 0x00;
- }
-
- if( SX1276.Settings.LoRa.FreqHopOn == true )
- {
- SX1276Write( REG_LR_PLLHOP, ( SX1276Read( REG_LR_PLLHOP ) & RFLR_PLLHOP_FASTHOP_MASK ) | RFLR_PLLHOP_FASTHOP_ON );
- SX1276Write( REG_LR_HOPPERIOD, SX1276.Settings.LoRa.HopPeriod );
- }
-
- SX1276Write( REG_LR_MODEMCONFIG1,
- ( SX1276Read( REG_LR_MODEMCONFIG1 ) &
- RFLR_MODEMCONFIG1_BW_MASK &
- RFLR_MODEMCONFIG1_CODINGRATE_MASK &
- RFLR_MODEMCONFIG1_IMPLICITHEADER_MASK ) |
- ( bandwidth << 4 ) | ( coderate << 1 ) |
- fixLen );
-
- SX1276Write( REG_LR_MODEMCONFIG2,
- ( SX1276Read( REG_LR_MODEMCONFIG2 ) &
- RFLR_MODEMCONFIG2_SF_MASK &
- RFLR_MODEMCONFIG2_RXPAYLOADCRC_MASK ) |
- ( datarate << 4 ) | ( crcOn << 2 ) );
-
- SX1276Write( REG_LR_MODEMCONFIG3,
- ( SX1276Read( REG_LR_MODEMCONFIG3 ) &
- RFLR_MODEMCONFIG3_LOWDATARATEOPTIMIZE_MASK ) |
- ( SX1276.Settings.LoRa.LowDatarateOptimize << 3 ) );
-
- SX1276Write( REG_LR_PREAMBLEMSB, ( preambleLen >> 8 ) & 0x00FF );
- SX1276Write( REG_LR_PREAMBLELSB, preambleLen & 0xFF );
-
- if( datarate == 6 )
- {
- SX1276Write( REG_LR_DETECTOPTIMIZE,
- ( SX1276Read( REG_LR_DETECTOPTIMIZE ) &
- RFLR_DETECTIONOPTIMIZE_MASK ) |
- RFLR_DETECTIONOPTIMIZE_SF6 );
- SX1276Write( REG_LR_DETECTIONTHRESHOLD,
- RFLR_DETECTIONTHRESH_SF6 );
- }
- else
- {
- SX1276Write( REG_LR_DETECTOPTIMIZE,
- ( SX1276Read( REG_LR_DETECTOPTIMIZE ) &
- RFLR_DETECTIONOPTIMIZE_MASK ) |
- RFLR_DETECTIONOPTIMIZE_SF7_TO_SF12 );
- SX1276Write( REG_LR_DETECTIONTHRESHOLD,
- RFLR_DETECTIONTHRESH_SF7_TO_SF12 );
- }
- }
- break;
- }
-}
-
-uint32_t SX1276GetTimeOnAir( RadioModems_t modem, uint8_t pktLen )
-{
- uint32_t airTime = 0;
-
- switch( modem )
- {
- case MODEM_FSK:
- {
- airTime = round( ( 8 * ( SX1276.Settings.Fsk.PreambleLen +
- ( ( SX1276Read( REG_SYNCCONFIG ) & ~RF_SYNCCONFIG_SYNCSIZE_MASK ) + 1 ) +
- ( ( SX1276.Settings.Fsk.FixLen == 0x01 ) ? 0.0 : 1.0 ) +
- ( ( ( SX1276Read( REG_PACKETCONFIG1 ) & ~RF_PACKETCONFIG1_ADDRSFILTERING_MASK ) != 0x00 ) ? 1.0 : 0 ) +
- pktLen +
- ( ( SX1276.Settings.Fsk.CrcOn == 0x01 ) ? 2.0 : 0 ) ) /
- SX1276.Settings.Fsk.Datarate ) * 1e3 );
- }
- break;
- case MODEM_LORA:
- {
- double bw = 0.0;
- // REMARK: When using LoRa modem only bandwidths 125, 250 and 500 kHz are supported
- switch( SX1276.Settings.LoRa.Bandwidth )
- {
- //case 0: // 7.8 kHz
- // bw = 78e2;
- // break;
- //case 1: // 10.4 kHz
- // bw = 104e2;
- // break;
- //case 2: // 15.6 kHz
- // bw = 156e2;
- // break;
- //case 3: // 20.8 kHz
- // bw = 208e2;
- // break;
- //case 4: // 31.2 kHz
- // bw = 312e2;
- // break;
- //case 5: // 41.4 kHz
- // bw = 414e2;
- // break;
- //case 6: // 62.5 kHz
- // bw = 625e2;
- // break;
- case 7: // 125 kHz
- bw = 125e3;
- break;
- case 8: // 250 kHz
- bw = 250e3;
- break;
- case 9: // 500 kHz
- bw = 500e3;
- break;
- }
-
- // Symbol rate : time for one symbol (secs)
- double rs = bw / ( 1 << SX1276.Settings.LoRa.Datarate );
- double ts = 1 / rs;
- // time of preamble
- double tPreamble = ( SX1276.Settings.LoRa.PreambleLen + 4.25 ) * ts;
- // Symbol length of payload and time
- double tmp = ceil( ( 8 * pktLen - 4 * SX1276.Settings.LoRa.Datarate +
- 28 + 16 * SX1276.Settings.LoRa.CrcOn -
- ( SX1276.Settings.LoRa.FixLen ? 20 : 0 ) ) /
- ( double )( 4 * SX1276.Settings.LoRa.Datarate -
- ( ( SX1276.Settings.LoRa.LowDatarateOptimize > 0 ) ? 2 : 0 ) ) ) *
- ( SX1276.Settings.LoRa.Coderate + 4 );
- double nPayload = 8 + ( ( tmp > 0 ) ? tmp : 0 );
- double tPayload = nPayload * ts;
- // Time on air
- double tOnAir = tPreamble + tPayload;
- // return us secs
- airTime = floor( tOnAir * 1e3 + 0.999 );
- }
- break;
- }
- return airTime;
-}
-
-void SX1276Send( uint8_t *buffer, uint8_t size )
-{
- uint32_t txTimeout = 0;
-
- switch( SX1276.Settings.Modem )
- {
- case MODEM_FSK:
- {
- SX1276.Settings.FskPacketHandler.NbBytes = 0;
- SX1276.Settings.FskPacketHandler.Size = size;
-
- if( SX1276.Settings.Fsk.FixLen == false )
- {
- SX1276WriteFifo( ( uint8_t* )&size, 1 );
- }
- else
- {
- SX1276Write( REG_PAYLOADLENGTH, size );
- }
-
- if( ( size > 0 ) && ( size <= 64 ) )
- {
- SX1276.Settings.FskPacketHandler.ChunkSize = size;
- }
- else
- {
- memcpy( RxTxBuffer, buffer, size );
- SX1276.Settings.FskPacketHandler.ChunkSize = 32;
- }
-
- // Write payload buffer
- SX1276WriteFifo( buffer, SX1276.Settings.FskPacketHandler.ChunkSize );
- SX1276.Settings.FskPacketHandler.NbBytes += SX1276.Settings.FskPacketHandler.ChunkSize;
- txTimeout = SX1276.Settings.Fsk.TxTimeout;
- }
- break;
- case MODEM_LORA:
- {
- if( SX1276.Settings.LoRa.IqInverted == true )
- {
- SX1276Write( REG_LR_INVERTIQ, ( ( SX1276Read( REG_LR_INVERTIQ ) & RFLR_INVERTIQ_TX_MASK & RFLR_INVERTIQ_RX_MASK ) | RFLR_INVERTIQ_RX_OFF | RFLR_INVERTIQ_TX_ON ) );
- SX1276Write( REG_LR_INVERTIQ2, RFLR_INVERTIQ2_ON );
- }
- else
- {
- SX1276Write( REG_LR_INVERTIQ, ( ( SX1276Read( REG_LR_INVERTIQ ) & RFLR_INVERTIQ_TX_MASK & RFLR_INVERTIQ_RX_MASK ) | RFLR_INVERTIQ_RX_OFF | RFLR_INVERTIQ_TX_OFF ) );
- SX1276Write( REG_LR_INVERTIQ2, RFLR_INVERTIQ2_OFF );
- }
-
- SX1276.Settings.LoRaPacketHandler.Size = size;
-
- // Initializes the payload size
- SX1276Write( REG_LR_PAYLOADLENGTH, size );
-
- // Full buffer used for Tx
- SX1276Write( REG_LR_FIFOTXBASEADDR, 0 );
- SX1276Write( REG_LR_FIFOADDRPTR, 0 );
-
- // FIFO operations can not take place in Sleep mode
- if( ( SX1276Read( REG_OPMODE ) & ~RF_OPMODE_MASK ) == RF_OPMODE_SLEEP )
- {
- SX1276SetStby( );
- os_cputime_delay_usecs(1000);
- }
- // Write payload buffer
- SX1276WriteFifo( buffer, size );
- txTimeout = SX1276.Settings.LoRa.TxTimeout;
- }
- break;
- }
-
- SX1276SetTx( txTimeout );
-}
-
-void SX1276SetSleep( void )
-{
- os_cputime_timer_stop(&RxTimeoutTimer);
- os_cputime_timer_stop(&TxTimeoutTimer);
-
- SX1276SetOpMode( RF_OPMODE_SLEEP );
- SX1276.Settings.State = RF_IDLE;
-}
-
-void SX1276SetStby( void )
-{
- os_cputime_timer_stop(&RxTimeoutTimer);
- os_cputime_timer_stop(&TxTimeoutTimer);
-
- SX1276SetOpMode( RF_OPMODE_STANDBY );
- SX1276.Settings.State = RF_IDLE;
-}
-
-void SX1276SetRx( uint32_t timeout )
-{
- bool rxContinuous = false;
-
- switch( SX1276.Settings.Modem )
- {
- case MODEM_FSK:
- {
- rxContinuous = SX1276.Settings.Fsk.RxContinuous;
-
- // DIO0=PayloadReady
- // DIO1=FifoLevel
- // DIO2=SyncAddr
- // DIO3=FifoEmpty
- // DIO4=Preamble
- // DIO5=ModeReady
- SX1276Write( REG_DIOMAPPING1, ( SX1276Read( REG_DIOMAPPING1 ) & RF_DIOMAPPING1_DIO0_MASK &
- RF_DIOMAPPING1_DIO1_MASK &
- RF_DIOMAPPING1_DIO2_MASK ) |
- RF_DIOMAPPING1_DIO0_00 |
- RF_DIOMAPPING1_DIO1_00 |
- RF_DIOMAPPING1_DIO2_11 );
-
- SX1276Write( REG_DIOMAPPING2, ( SX1276Read( REG_DIOMAPPING2 ) & RF_DIOMAPPING2_DIO4_MASK &
- RF_DIOMAPPING2_MAP_MASK ) |
- RF_DIOMAPPING2_DIO4_11 |
- RF_DIOMAPPING2_MAP_PREAMBLEDETECT );
-
- SX1276.Settings.FskPacketHandler.FifoThresh = SX1276Read( REG_FIFOTHRESH ) & 0x3F;
-
- SX1276Write( REG_RXCONFIG, RF_RXCONFIG_AFCAUTO_ON | RF_RXCONFIG_AGCAUTO_ON | RF_RXCONFIG_RXTRIGER_PREAMBLEDETECT );
-
- SX1276.Settings.FskPacketHandler.PreambleDetected = false;
- SX1276.Settings.FskPacketHandler.SyncWordDetected = false;
- SX1276.Settings.FskPacketHandler.NbBytes = 0;
- SX1276.Settings.FskPacketHandler.Size = 0;
- }
- break;
- case MODEM_LORA:
- {
- if( SX1276.Settings.LoRa.IqInverted == true )
- {
- SX1276Write( REG_LR_INVERTIQ, ( ( SX1276Read( REG_LR_INVERTIQ ) & RFLR_INVERTIQ_TX_MASK & RFLR_INVERTIQ_RX_MASK ) | RFLR_INVERTIQ_RX_ON | RFLR_INVERTIQ_TX_OFF ) );
- SX1276Write( REG_LR_INVERTIQ2, RFLR_INVERTIQ2_ON );
- }
- else
- {
- SX1276Write( REG_LR_INVERTIQ, ( ( SX1276Read( REG_LR_INVERTIQ ) & RFLR_INVERTIQ_TX_MASK & RFLR_INVERTIQ_RX_MASK ) | RFLR_INVERTIQ_RX_OFF | RFLR_INVERTIQ_TX_OFF ) );
- SX1276Write( REG_LR_INVERTIQ2, RFLR_INVERTIQ2_OFF );
- }
-
- // ERRATA 2.3 - Receiver Spurious Reception of a LoRa Signal
- if( SX1276.Settings.LoRa.Bandwidth < 9 )
- {
- SX1276Write( REG_LR_DETECTOPTIMIZE, SX1276Read( REG_LR_DETECTOPTIMIZE ) & 0x7F );
- SX1276Write( REG_LR_TEST30, 0x00 );
- switch( SX1276.Settings.LoRa.Bandwidth )
- {
- case 0: // 7.8 kHz
- SX1276Write( REG_LR_TEST2F, 0x48 );
- SX1276SetChannel(SX1276.Settings.Channel + 7.81e3 );
- break;
- case 1: // 10.4 kHz
- SX1276Write( REG_LR_TEST2F, 0x44 );
- SX1276SetChannel(SX1276.Settings.Channel + 10.42e3 );
- break;
- case 2: // 15.6 kHz
- SX1276Write( REG_LR_TEST2F, 0x44 );
- SX1276SetChannel(SX1276.Settings.Channel + 15.62e3 );
- break;
- case 3: // 20.8 kHz
- SX1276Write( REG_LR_TEST2F, 0x44 );
- SX1276SetChannel(SX1276.Settings.Channel + 20.83e3 );
- break;
- case 4: // 31.2 kHz
- SX1276Write( REG_LR_TEST2F, 0x44 );
- SX1276SetChannel(SX1276.Settings.Channel + 31.25e3 );
- break;
- case 5: // 41.4 kHz
- SX1276Write( REG_LR_TEST2F, 0x44 );
- SX1276SetChannel(SX1276.Settings.Channel + 41.67e3 );
- break;
- case 6: // 62.5 kHz
- SX1276Write( REG_LR_TEST2F, 0x40 );
- break;
- case 7: // 125 kHz
- SX1276Write( REG_LR_TEST2F, 0x40 );
- break;
- case 8: // 250 kHz
- SX1276Write( REG_LR_TEST2F, 0x40 );
- break;
- }
- }
- else
- {
- SX1276Write( REG_LR_DETECTOPTIMIZE, SX1276Read( REG_LR_DETECTOPTIMIZE ) | 0x80 );
- }
-
- rxContinuous = SX1276.Settings.LoRa.RxContinuous;
-
- if( SX1276.Settings.LoRa.FreqHopOn == true )
- {
- SX1276Write( REG_LR_IRQFLAGSMASK, //RFLR_IRQFLAGS_RXTIMEOUT |
- //RFLR_IRQFLAGS_RXDONE |
- //RFLR_IRQFLAGS_PAYLOADCRCERROR |
- RFLR_IRQFLAGS_VALIDHEADER |
- RFLR_IRQFLAGS_TXDONE |
- RFLR_IRQFLAGS_CADDONE |
- //RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL |
- RFLR_IRQFLAGS_CADDETECTED );
-
- // DIO0=RxDone, DIO2=FhssChangeChannel
- SX1276Write( REG_DIOMAPPING1, ( SX1276Read( REG_DIOMAPPING1 ) & RFLR_DIOMAPPING1_DIO0_MASK & RFLR_DIOMAPPING1_DIO2_MASK ) | RFLR_DIOMAPPING1_DIO0_00 | RFLR_DIOMAPPING1_DIO2_00 );
- }
- else
- {
- SX1276Write( REG_LR_IRQFLAGSMASK, //RFLR_IRQFLAGS_RXTIMEOUT |
- //RFLR_IRQFLAGS_RXDONE |
- //RFLR_IRQFLAGS_PAYLOADCRCERROR |
- RFLR_IRQFLAGS_VALIDHEADER |
- RFLR_IRQFLAGS_TXDONE |
- RFLR_IRQFLAGS_CADDONE |
- RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL |
- RFLR_IRQFLAGS_CADDETECTED );
-
- // DIO0=RxDone
- SX1276Write( REG_DIOMAPPING1, ( SX1276Read( REG_DIOMAPPING1 ) & RFLR_DIOMAPPING1_DIO0_MASK ) | RFLR_DIOMAPPING1_DIO0_00 );
- }
- SX1276Write( REG_LR_FIFORXBASEADDR, 0 );
- SX1276Write( REG_LR_FIFOADDRPTR, 0 );
- }
- break;
- }
-
- memset( RxTxBuffer, 0, ( size_t )RX_BUFFER_SIZE );
-
- SX1276.Settings.State = RF_RX_RUNNING;
- if( timeout != 0 )
- {
- os_cputime_timer_relative(&RxTimeoutTimer, timeout*1000);
- }
-
- if( SX1276.Settings.Modem == MODEM_FSK )
- {
- SX1276SetOpMode( RF_OPMODE_RECEIVER );
-
- if( rxContinuous == false )
- {
- rx_timeout_sync_delay =
- ceil((8.0 * (SX1276.Settings.Fsk.PreambleLen +
- ((SX1276Read(REG_SYNCCONFIG) &
- ~RF_SYNCCONFIG_SYNCSIZE_MASK) + 1.0) + 10.0) /
- (double)SX1276.Settings.Fsk.Datarate) * 1e3) + 4;
- os_cputime_timer_relative(
- &RxTimeoutSyncWord, rx_timeout_sync_delay*1000);
- }
- }
- else
- {
- if( rxContinuous == true )
- {
- SX1276SetOpMode( RFLR_OPMODE_RECEIVER );
- }
- else
- {
- SX1276SetOpMode( RFLR_OPMODE_RECEIVER_SINGLE );
- }
- }
-}
-
-void SX1276SetTx( uint32_t timeout )
-{
- os_cputime_timer_relative(&TxTimeoutTimer, timeout*1000);
-
- switch( SX1276.Settings.Modem )
- {
- case MODEM_FSK:
- {
- // DIO0=PacketSent
- // DIO1=FifoEmpty
- // DIO2=FifoFull
- // DIO3=FifoEmpty
- // DIO4=LowBat
- // DIO5=ModeReady
- SX1276Write( REG_DIOMAPPING1, ( SX1276Read( REG_DIOMAPPING1 ) & RF_DIOMAPPING1_DIO0_MASK &
- RF_DIOMAPPING1_DIO1_MASK &
- RF_DIOMAPPING1_DIO2_MASK ) |
- RF_DIOMAPPING1_DIO1_01 );
-
- SX1276Write( REG_DIOMAPPING2, ( SX1276Read( REG_DIOMAPPING2 ) & RF_DIOMAPPING2_DIO4_MASK &
- RF_DIOMAPPING2_MAP_MASK ) );
- SX1276.Settings.FskPacketHandler.FifoThresh = SX1276Read( REG_FIFOTHRESH ) & 0x3F;
- }
- break;
- case MODEM_LORA:
- {
- if( SX1276.Settings.LoRa.FreqHopOn == true )
- {
- SX1276Write( REG_LR_IRQFLAGSMASK, RFLR_IRQFLAGS_RXTIMEOUT |
- RFLR_IRQFLAGS_RXDONE |
- RFLR_IRQFLAGS_PAYLOADCRCERROR |
- RFLR_IRQFLAGS_VALIDHEADER |
- //RFLR_IRQFLAGS_TXDONE |
- RFLR_IRQFLAGS_CADDONE |
- //RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL |
- RFLR_IRQFLAGS_CADDETECTED );
-
- // DIO0=TxDone, DIO2=FhssChangeChannel
- SX1276Write( REG_DIOMAPPING1, ( SX1276Read( REG_DIOMAPPING1 ) & RFLR_DIOMAPPING1_DIO0_MASK & RFLR_DIOMAPPING1_DIO2_MASK ) | RFLR_DIOMAPPING1_DIO0_01 | RFLR_DIOMAPPING1_DIO2_00 );
- }
- else
- {
- SX1276Write( REG_LR_IRQFLAGSMASK, RFLR_IRQFLAGS_RXTIMEOUT |
- RFLR_IRQFLAGS_RXDONE |
- RFLR_IRQFLAGS_PAYLOADCRCERROR |
- RFLR_IRQFLAGS_VALIDHEADER |
- //RFLR_IRQFLAGS_TXDONE |
- RFLR_IRQFLAGS_CADDONE |
- RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL |
- RFLR_IRQFLAGS_CADDETECTED );
-
- // DIO0=TxDone
- SX1276Write( REG_DIOMAPPING1, ( SX1276Read( REG_DIOMAPPING1 ) & RFLR_DIOMAPPING1_DIO0_MASK ) | RFLR_DIOMAPPING1_DIO0_01 );
- }
- }
- break;
- }
-
- SX1276.Settings.State = RF_TX_RUNNING;
- os_cputime_timer_relative(&TxTimeoutTimer, timeout*1000);
- SX1276SetOpMode( RF_OPMODE_TRANSMITTER );
-}
-
-void SX1276StartCad( void )
-{
- switch( SX1276.Settings.Modem )
- {
- case MODEM_FSK:
- {
-
- }
- break;
- case MODEM_LORA:
- {
- SX1276Write( REG_LR_IRQFLAGSMASK, RFLR_IRQFLAGS_RXTIMEOUT |
- RFLR_IRQFLAGS_RXDONE |
- RFLR_IRQFLAGS_PAYLOADCRCERROR |
- RFLR_IRQFLAGS_VALIDHEADER |
- RFLR_IRQFLAGS_TXDONE |
- //RFLR_IRQFLAGS_CADDONE |
- RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL // |
- //RFLR_IRQFLAGS_CADDETECTED
- );
-
- // DIO3=CADDone
- SX1276Write( REG_DIOMAPPING1, ( SX1276Read( REG_DIOMAPPING1 ) & RFLR_DIOMAPPING1_DIO0_MASK ) | RFLR_DIOMAPPING1_DIO0_00 );
-
- SX1276.Settings.State = RF_CAD;
- SX1276SetOpMode( RFLR_OPMODE_CAD );
- }
- break;
- default:
- break;
- }
-}
-
-int16_t SX1276ReadRssi( RadioModems_t modem )
-{
- int16_t rssi = 0;
-
- switch( modem )
- {
- case MODEM_FSK:
- rssi = -( SX1276Read( REG_RSSIVALUE ) >> 1 );
- break;
- case MODEM_LORA:
- if( SX1276.Settings.Channel > RF_MID_BAND_THRESH )
- {
- rssi = RSSI_OFFSET_HF + SX1276Read( REG_LR_RSSIVALUE );
- }
- else
- {
- rssi = RSSI_OFFSET_LF + SX1276Read( REG_LR_RSSIVALUE );
- }
- break;
- default:
- rssi = -1;
- break;
- }
- return rssi;
-}
-
-void SX1276Reset( void )
-{
- // Set RESET pin to 0
- hal_gpio_init_out(RADIO_RESET, 0);
-
- // Wait 1 ms
- os_cputime_delay_usecs(1000);
-
- // Configure RESET as input
- hal_gpio_init_in(RADIO_RESET, HAL_GPIO_PULL_NONE);
-
- // Wait 6 ms
- os_cputime_delay_usecs(6000);
-}
-
-void SX1276SetOpMode( uint8_t opMode )
-{
- if( opMode == RF_OPMODE_SLEEP )
- {
- SX1276SetAntSwLowPower( true );
- }
- else
- {
- SX1276SetAntSwLowPower( false );
- if( opMode == RF_OPMODE_TRANSMITTER )
- {
- SX1276SetAntSw( 1 );
- }
- else
- {
- SX1276SetAntSw( 0 );
- }
- }
- SX1276Write( REG_OPMODE, ( SX1276Read( REG_OPMODE ) & RF_OPMODE_MASK ) | opMode );
-}
-
-void SX1276SetModem( RadioModems_t modem )
-{
-
- if( SX1276.Settings.Modem == modem )
- {
- return;
- }
-
- SX1276.Settings.Modem = modem;
- switch( SX1276.Settings.Modem )
- {
- default:
- case MODEM_FSK:
- SX1276SetOpMode( RF_OPMODE_SLEEP );
- SX1276Write( REG_OPMODE, ( SX1276Read( REG_OPMODE ) & RFLR_OPMODE_LONGRANGEMODE_MASK ) | RFLR_OPMODE_LONGRANGEMODE_OFF );
-
- SX1276Write( REG_DIOMAPPING1, 0x00 );
- SX1276Write( REG_DIOMAPPING2, 0x30 ); // DIO5=ModeReady
- break;
- case MODEM_LORA:
- SX1276SetOpMode( RF_OPMODE_SLEEP );
- SX1276Write( REG_OPMODE, ( SX1276Read( REG_OPMODE ) & RFLR_OPMODE_LONGRANGEMODE_MASK ) | RFLR_OPMODE_LONGRANGEMODE_ON );
-
- SX1276Write( REG_DIOMAPPING1, 0x00 );
- SX1276Write( REG_DIOMAPPING2, 0x00 );
- break;
- }
-}
-
-void SX1276Write( uint8_t addr, uint8_t data )
-{
- SX1276WriteBuffer( addr, &data, 1 );
-}
-
-uint8_t SX1276Read( uint8_t addr )
-{
- uint8_t data;
- SX1276ReadBuffer( addr, &data, 1 );
- return data;
-}
-
-void SX1276WriteBuffer( uint8_t addr, uint8_t *buffer, uint8_t size )
-{
- uint8_t i;
-
- hal_gpio_write(RADIO_NSS, 0);
-
- hal_spi_tx_val(RADIO_SPI_IDX, addr | 0x80);
- for( i = 0; i < size; i++ )
- {
- hal_spi_tx_val(RADIO_SPI_IDX, buffer[i]);
- }
-
- hal_gpio_write(RADIO_NSS, 1);
-}
-
-void SX1276ReadBuffer( uint8_t addr, uint8_t *buffer, uint8_t size )
-{
- uint8_t i;
-
- hal_gpio_write(RADIO_NSS, 0);
-
- hal_spi_tx_val(RADIO_SPI_IDX, addr & 0x7f);
- for( i = 0; i < size; i++ )
- {
- buffer[i] = hal_spi_tx_val(RADIO_SPI_IDX, 0);
- }
-
- hal_gpio_write(RADIO_NSS, 1);
-}
-
-void SX1276WriteFifo( uint8_t *buffer, uint8_t size )
-{
- SX1276WriteBuffer( 0, buffer, size );
-}
-
-void SX1276ReadFifo( uint8_t *buffer, uint8_t size )
-{
- SX1276ReadBuffer( 0, buffer, size );
-}
-
-void SX1276SetMaxPayloadLength( RadioModems_t modem, uint8_t max )
-{
- SX1276SetModem( modem );
-
- switch( modem )
- {
- case MODEM_FSK:
- if( SX1276.Settings.Fsk.FixLen == false )
- {
- SX1276Write( REG_PAYLOADLENGTH, max );
- }
- break;
- case MODEM_LORA:
- SX1276Write( REG_LR_PAYLOADMAXLENGTH, max );
- break;
- }
-}
-
-void SX1276OnTimeoutIrq(void *unused)
-{
- switch( SX1276.Settings.State )
- {
- case RF_RX_RUNNING:
- if( SX1276.Settings.Modem == MODEM_FSK )
- {
- SX1276.Settings.FskPacketHandler.PreambleDetected = false;
- SX1276.Settings.FskPacketHandler.SyncWordDetected = false;
- SX1276.Settings.FskPacketHandler.NbBytes = 0;
- SX1276.Settings.FskPacketHandler.Size = 0;
-
- // Clear Irqs
- SX1276Write( REG_IRQFLAGS1, RF_IRQFLAGS1_RSSI |
- RF_IRQFLAGS1_PREAMBLEDETECT |
- RF_IRQFLAGS1_SYNCADDRESSMATCH );
- SX1276Write( REG_IRQFLAGS2, RF_IRQFLAGS2_FIFOOVERRUN );
-
- if( SX1276.Settings.Fsk.RxContinuous == true )
- {
- // Continuous mode restart Rx chain
- SX1276Write( REG_RXCONFIG, SX1276Read( REG_RXCONFIG ) | RF_RXCONFIG_RESTARTRXWITHOUTPLLLOCK );
- assert(rx_timeout_sync_delay != (uint32_t)-1);
- os_cputime_timer_relative(
- &RxTimeoutSyncWord, rx_timeout_sync_delay*1000);
- }
- else
- {
- SX1276.Settings.State = RF_IDLE;
- os_cputime_timer_stop(&RxTimeoutSyncWord);
- }
- }
- SX1276RxTimeout( );
- break;
- case RF_TX_RUNNING:
- SX1276.Settings.State = RF_IDLE;
- SX1276TxTimeout( );
- break;
- default:
- break;
- }
-}
-
-void SX1276OnDio0Irq(void *unused)
-{
- volatile uint8_t irqFlags = 0;
-
- switch( SX1276.Settings.State )
- {
- case RF_RX_RUNNING:
- //TimerStop( &RxTimeoutTimer );
- // RxDone interrupt
- switch( SX1276.Settings.Modem )
- {
- case MODEM_FSK:
- if( SX1276.Settings.Fsk.CrcOn == true )
- {
- irqFlags = SX1276Read( REG_IRQFLAGS2 );
- if( ( irqFlags & RF_IRQFLAGS2_CRCOK ) != RF_IRQFLAGS2_CRCOK )
- {
- // Clear Irqs
- SX1276Write( REG_IRQFLAGS1, RF_IRQFLAGS1_RSSI |
- RF_IRQFLAGS1_PREAMBLEDETECT |
- RF_IRQFLAGS1_SYNCADDRESSMATCH );
- SX1276Write( REG_IRQFLAGS2, RF_IRQFLAGS2_FIFOOVERRUN );
-
- os_cputime_timer_stop(&RxTimeoutTimer);
-
- if( SX1276.Settings.Fsk.RxContinuous == false )
- {
- os_cputime_timer_stop(&RxTimeoutSyncWord);
- SX1276.Settings.State = RF_IDLE;
- }
- else
- {
- // Continuous mode restart Rx chain
- SX1276Write( REG_RXCONFIG, SX1276Read( REG_RXCONFIG ) | RF_RXCONFIG_RESTARTRXWITHOUTPLLLOCK );
- assert(rx_timeout_sync_delay != (uint32_t)-1);
- os_cputime_timer_relative(
- &RxTimeoutSyncWord, rx_timeout_sync_delay*1000);
- }
-
- SX1276RxError( );
- SX1276.Settings.FskPacketHandler.PreambleDetected = false;
- SX1276.Settings.FskPacketHandler.SyncWordDetected = false;
- SX1276.Settings.FskPacketHandler.NbBytes = 0;
- SX1276.Settings.FskPacketHandler.Size = 0;
- break;
- }
- }
-
- // Read received packet size
- if( ( SX1276.Settings.FskPacketHandler.Size == 0 ) && ( SX1276.Settings.FskPacketHandler.NbBytes == 0 ) )
- {
- if( SX1276.Settings.Fsk.FixLen == false )
- {
- SX1276ReadFifo( ( uint8_t* )&SX1276.Settings.FskPacketHandler.Size, 1 );
- }
- else
- {
- SX1276.Settings.FskPacketHandler.Size = SX1276Read( REG_PAYLOADLENGTH );
- }
- SX1276ReadFifo( RxTxBuffer + SX1276.Settings.FskPacketHandler.NbBytes, SX1276.Settings.FskPacketHandler.Size - SX1276.Settings.FskPacketHandler.NbBytes );
- SX1276.Settings.FskPacketHandler.NbBytes += ( SX1276.Settings.FskPacketHandler.Size - SX1276.Settings.FskPacketHandler.NbBytes );
- }
- else
- {
- SX1276ReadFifo( RxTxBuffer + SX1276.Settings.FskPacketHandler.NbBytes, SX1276.Settings.FskPacketHandler.Size - SX1276.Settings.FskPacketHandler.NbBytes );
- SX1276.Settings.FskPacketHandler.NbBytes += ( SX1276.Settings.FskPacketHandler.Size - SX1276.Settings.FskPacketHandler.NbBytes );
- }
-
- if( SX1276.Settings.Fsk.RxContinuous == false )
- {
- SX1276.Settings.State = RF_IDLE;
- assert(rx_timeout_sync_delay != (uint32_t)-1);
- os_cputime_timer_relative(
- &RxTimeoutSyncWord, rx_timeout_sync_delay*1000);
-
- }
- else
- {
- // Continuous mode restart Rx chain
- SX1276Write( REG_RXCONFIG, SX1276Read( REG_RXCONFIG ) | RF_RXCONFIG_RESTARTRXWITHOUTPLLLOCK );
- }
- os_cputime_timer_stop(&RxTimeoutTimer);
-
- SX1276RxDone( RxTxBuffer, SX1276.Settings.FskPacketHandler.Size, SX1276.Settings.FskPacketHandler.RssiValue, 0 );
- SX1276.Settings.FskPacketHandler.PreambleDetected = false;
- SX1276.Settings.FskPacketHandler.SyncWordDetected = false;
- SX1276.Settings.FskPacketHandler.NbBytes = 0;
- SX1276.Settings.FskPacketHandler.Size = 0;
- break;
- case MODEM_LORA:
- {
- int8_t snr = 0;
-
- // Clear Irq
- SX1276Write( REG_LR_IRQFLAGS, RFLR_IRQFLAGS_RXDONE);
-
- irqFlags = SX1276Read( REG_LR_IRQFLAGS );
- if( ( irqFlags & RFLR_IRQFLAGS_PAYLOADCRCERROR_MASK ) == RFLR_IRQFLAGS_PAYLOADCRCERROR )
- {
- // Clear Irq
- SX1276Write( REG_LR_IRQFLAGS, RFLR_IRQFLAGS_PAYLOADCRCERROR);
-
- if( SX1276.Settings.LoRa.RxContinuous == false )
- {
- SX1276.Settings.State = RF_IDLE;
- }
- os_cputime_timer_stop(&RxTimeoutTimer);
-
- SX1276RxError( );
- break;
- }
-
- SX1276.Settings.LoRaPacketHandler.SnrValue = SX1276Read( REG_LR_PKTSNRVALUE );
- if( SX1276.Settings.LoRaPacketHandler.SnrValue & 0x80 ) // The SNR sign bit is 1
- {
- // Invert and divide by 4
- snr = ( ( ~SX1276.Settings.LoRaPacketHandler.SnrValue + 1 ) & 0xFF ) >> 2;
- snr = -snr;
- }
- else
- {
- // Divide by 4
- snr = ( SX1276.Settings.LoRaPacketHandler.SnrValue & 0xFF ) >> 2;
- }
-
- int16_t rssi = SX1276Read( REG_LR_PKTRSSIVALUE );
- if( snr < 0 )
- {
- if( SX1276.Settings.Channel > RF_MID_BAND_THRESH )
- {
- SX1276.Settings.LoRaPacketHandler.RssiValue = RSSI_OFFSET_HF + rssi + ( rssi >> 4 ) +
- snr;
- }
- else
- {
- SX1276.Settings.LoRaPacketHandler.RssiValue = RSSI_OFFSET_LF + rssi + ( rssi >> 4 ) +
- snr;
- }
- }
- else
- {
- if( SX1276.Settings.Channel > RF_MID_BAND_THRESH )
- {
- SX1276.Settings.LoRaPacketHandler.RssiValue = RSSI_OFFSET_HF + rssi + ( rssi >> 4 );
- }
- else
- {
- SX1276.Settings.LoRaPacketHandler.RssiValue = RSSI_OFFSET_LF + rssi + ( rssi >> 4 );
- }
- }
-
- SX1276.Settings.LoRaPacketHandler.Size = SX1276Read( REG_LR_RXNBBYTES );
- SX1276ReadFifo( RxTxBuffer, SX1276.Settings.LoRaPacketHandler.Size );
-
- if( SX1276.Settings.LoRa.RxContinuous == false )
- {
- SX1276.Settings.State = RF_IDLE;
- }
- os_cputime_timer_stop(&RxTimeoutTimer);
-
- SX1276RxDone( RxTxBuffer, SX1276.Settings.LoRaPacketHandler.Size, SX1276.Settings.LoRaPacketHandler.RssiValue, SX1276.Settings.LoRaPacketHandler.SnrValue );
- }
- break;
- default:
- break;
- }
- break;
- case RF_TX_RUNNING:
- os_cputime_timer_stop(&TxTimeoutTimer);
- // TxDone interrupt
- switch( SX1276.Settings.Modem )
- {
- case MODEM_LORA:
- // Clear Irq
- SX1276Write( REG_LR_IRQFLAGS, RFLR_IRQFLAGS_TXDONE );
- // Intentional fall through
- case MODEM_FSK:
- default:
- SX1276.Settings.State = RF_IDLE;
- SX1276TxDone( );
- break;
- }
- break;
- default:
- break;
- }
-}
-
-void SX1276OnDio1Irq(void *unused)
-{
- switch( SX1276.Settings.State )
- {
- case RF_RX_RUNNING:
- switch( SX1276.Settings.Modem )
- {
- case MODEM_FSK:
- // FifoLevel interrupt
- // Read received packet size
- if( ( SX1276.Settings.FskPacketHandler.Size == 0 ) && ( SX1276.Settings.FskPacketHandler.NbBytes == 0 ) )
- {
- if( SX1276.Settings.Fsk.FixLen == false )
- {
- SX1276ReadFifo( ( uint8_t* )&SX1276.Settings.FskPacketHandler.Size, 1 );
- }
- else
- {
- SX1276.Settings.FskPacketHandler.Size = SX1276Read( REG_PAYLOADLENGTH );
- }
- }
-
- if( ( SX1276.Settings.FskPacketHandler.Size - SX1276.Settings.FskPacketHandler.NbBytes ) > SX1276.Settings.FskPacketHandler.FifoThresh )
- {
- SX1276ReadFifo( ( RxTxBuffer + SX1276.Settings.FskPacketHandler.NbBytes ), SX1276.Settings.FskPacketHandler.FifoThresh );
- SX1276.Settings.FskPacketHandler.NbBytes += SX1276.Settings.FskPacketHandler.FifoThresh;
- }
- else
- {
- SX1276ReadFifo( ( RxTxBuffer + SX1276.Settings.FskPacketHandler.NbBytes ), SX1276.Settings.FskPacketHandler.Size - SX1276.Settings.FskPacketHandler.NbBytes );
- SX1276.Settings.FskPacketHandler.NbBytes += ( SX1276.Settings.FskPacketHandler.Size - SX1276.Settings.FskPacketHandler.NbBytes );
- }
- break;
- case MODEM_LORA:
- // Sync time out
- os_cputime_timer_stop(&RxTimeoutTimer);
- SX1276.Settings.State = RF_IDLE;
- SX1276RxTimeout( );
- break;
- default:
- break;
- }
- break;
- case RF_TX_RUNNING:
- switch( SX1276.Settings.Modem )
- {
- case MODEM_FSK:
- // FifoEmpty interrupt
- if( ( SX1276.Settings.FskPacketHandler.Size - SX1276.Settings.FskPacketHandler.NbBytes ) > SX1276.Settings.FskPacketHandler.ChunkSize )
- {
- SX1276WriteFifo( ( RxTxBuffer + SX1276.Settings.FskPacketHandler.NbBytes ), SX1276.Settings.FskPacketHandler.ChunkSize );
- SX1276.Settings.FskPacketHandler.NbBytes += SX1276.Settings.FskPacketHandler.ChunkSize;
- }
- else
- {
- // Write the last chunk of data
- SX1276WriteFifo( RxTxBuffer + SX1276.Settings.FskPacketHandler.NbBytes, SX1276.Settings.FskPacketHandler.Size - SX1276.Settings.FskPacketHandler.NbBytes );
- SX1276.Settings.FskPacketHandler.NbBytes += SX1276.Settings.FskPacketHandler.Size - SX1276.Settings.FskPacketHandler.NbBytes;
- }
- break;
- case MODEM_LORA:
- break;
- default:
- break;
- }
- break;
- default:
- break;
- }
-}
-
-void SX1276OnDio2Irq(void *unused)
-{
- switch( SX1276.Settings.State )
- {
- case RF_RX_RUNNING:
- switch( SX1276.Settings.Modem )
- {
- case MODEM_FSK:
- if( ( SX1276.Settings.FskPacketHandler.PreambleDetected == true ) && ( SX1276.Settings.FskPacketHandler.SyncWordDetected == false ) )
- {
- os_cputime_timer_stop(&RxTimeoutSyncWord);
-
- SX1276.Settings.FskPacketHandler.SyncWordDetected = true;
-
- SX1276.Settings.FskPacketHandler.RssiValue = -( SX1276Read( REG_RSSIVALUE ) >> 1 );
-
- SX1276.Settings.FskPacketHandler.AfcValue = ( int32_t )( double )( ( ( uint16_t )SX1276Read( REG_AFCMSB ) << 8 ) |
- ( uint16_t )SX1276Read( REG_AFCLSB ) ) *
- ( double )FREQ_STEP;
- SX1276.Settings.FskPacketHandler.RxGain = ( SX1276Read( REG_LNA ) >> 5 ) & 0x07;
- }
- break;
- case MODEM_LORA:
- if( SX1276.Settings.LoRa.FreqHopOn == true )
- {
- // Clear Irq
- SX1276Write( REG_LR_IRQFLAGS, RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL);
-
- if( ( RadioEvents != NULL ) && ( RadioEvents->FhssChangeChannel != NULL ) )
- {
- RadioEvents->FhssChangeChannel( ( SX1276Read( REG_LR_HOPCHANNEL ) & RFLR_HOPCHANNEL_CHANNEL_MASK ) );
- }
- }
- break;
- default:
- break;
- }
- break;
- case RF_TX_RUNNING:
- switch( SX1276.Settings.Modem )
- {
- case MODEM_FSK:
- break;
- case MODEM_LORA:
- if( SX1276.Settings.LoRa.FreqHopOn == true )
- {
- // Clear Irq
- SX1276Write( REG_LR_IRQFLAGS, RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL);
-
- if( ( RadioEvents != NULL ) && ( RadioEvents->FhssChangeChannel != NULL ) )
- {
- RadioEvents->FhssChangeChannel( ( SX1276Read( REG_LR_HOPCHANNEL ) & RFLR_HOPCHANNEL_CHANNEL_MASK ) );
- }
- }
- break;
- default:
- break;
- }
- break;
- default:
- break;
- }
-}
-
-void SX1276OnDio3Irq(void *unused)
-{
- switch( SX1276.Settings.Modem )
- {
- case MODEM_FSK:
- break;
- case MODEM_LORA:
- if( ( SX1276Read( REG_LR_IRQFLAGS ) & RFLR_IRQFLAGS_CADDETECTED ) == RFLR_IRQFLAGS_CADDETECTED )
- {
- // Clear Irq
- SX1276Write( REG_LR_IRQFLAGS, RFLR_IRQFLAGS_CADDETECTED | RFLR_IRQFLAGS_CADDONE);
- if( ( RadioEvents != NULL ) && ( RadioEvents->CadDone != NULL ) )
- {
- RadioEvents->CadDone( true );
- }
- }
- else
- {
- // Clear Irq
- SX1276Write( REG_LR_IRQFLAGS, RFLR_IRQFLAGS_CADDONE);
- if( ( RadioEvents != NULL ) && ( RadioEvents->CadDone != NULL ) )
- {
- RadioEvents->CadDone( false );
- }
- }
- break;
- default:
- break;
- }
-}
-
-void SX1276OnDio4Irq(void *unused)
-{
- switch( SX1276.Settings.Modem )
- {
- case MODEM_FSK:
- {
- if( SX1276.Settings.FskPacketHandler.PreambleDetected == false )
- {
- SX1276.Settings.FskPacketHandler.PreambleDetected = true;
- }
- }
- break;
- case MODEM_LORA:
- break;
- default:
- break;
- }
-}
-
-void SX1276OnDio5Irq(void *unused)
-{
- switch( SX1276.Settings.Modem )
- {
- case MODEM_FSK:
- break;
- case MODEM_LORA:
- break;
- default:
- break;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/560fa920/hw/drivers/lora/node/radio/sx1276/src/sx1276.h
----------------------------------------------------------------------
diff --git a/hw/drivers/lora/node/radio/sx1276/src/sx1276.h b/hw/drivers/lora/node/radio/sx1276/src/sx1276.h
deleted file mode 100644
index 9c82652..0000000
--- a/hw/drivers/lora/node/radio/sx1276/src/sx1276.h
+++ /dev/null
@@ -1,364 +0,0 @@
-/*
- / _____) _ | |
-( (____ _____ ____ _| |_ _____ ____| |__
- \____ \| ___ | (_ _) ___ |/ ___) _ \
- _____) ) ____| | | || |_| ____( (___| | | |
-(______/|_____)_|_|_| \__)_____)\____)_| |_|
- (C)2013 Semtech
-
-Description: Generic SX1276 driver implementation
-
-License: Revised BSD License, see LICENSE.TXT file include in the project
-
-Maintainer: Miguel Luis and Gregory Cristian
-*/
-#ifndef __SX1276_H__
-#define __SX1276_H__
-#include <stdint.h>
-#include <stdbool.h>
-#include "node/radio.h"
-#include "sx1276Regs-Fsk.h"
-#include "sx1276Regs-LoRa.h"
-
-/*!
- * Radio FSK modem parameters
- */
-typedef struct
-{
- int8_t Power;
- uint32_t Fdev;
- uint32_t Bandwidth;
- uint32_t BandwidthAfc;
- uint32_t Datarate;
- uint16_t PreambleLen;
- bool FixLen;
- uint8_t PayloadLen;
- bool CrcOn;
- bool IqInverted;
- bool RxContinuous;
- uint32_t TxTimeout;
-}RadioFskSettings_t;
-
-/*!
- * Radio FSK packet handler state
- */
-typedef struct
-{
- uint8_t PreambleDetected;
- uint8_t SyncWordDetected;
- int8_t RssiValue;
- int32_t AfcValue;
- uint8_t RxGain;
- uint16_t Size;
- uint16_t NbBytes;
- uint8_t FifoThresh;
- uint8_t ChunkSize;
-}RadioFskPacketHandler_t;
-
-/*!
- * Radio LoRa modem parameters
- */
-typedef struct
-{
- int8_t Power;
- uint32_t Bandwidth;
- uint32_t Datarate;
- bool LowDatarateOptimize;
- uint8_t Coderate;
- uint16_t PreambleLen;
- bool FixLen;
- uint8_t PayloadLen;
- bool CrcOn;
- bool FreqHopOn;
- uint8_t HopPeriod;
- bool IqInverted;
- bool RxContinuous;
- uint32_t TxTimeout;
-}RadioLoRaSettings_t;
-
-/*!
- * Radio LoRa packet handler state
- */
-typedef struct
-{
- int8_t SnrValue;
- int16_t RssiValue;
- uint8_t Size;
-}RadioLoRaPacketHandler_t;
-
-/*!
- * Radio Settings
- */
-typedef struct
-{
- RadioState_t State;
- RadioModems_t Modem;
- uint32_t Channel;
- RadioFskSettings_t Fsk;
- RadioFskPacketHandler_t FskPacketHandler;
- RadioLoRaSettings_t LoRa;
- RadioLoRaPacketHandler_t LoRaPacketHandler;
-}RadioSettings_t;
-
-/*!
- * Radio hardware and global parameters
- */
-typedef struct SX1276_s
-{
- RadioSettings_t Settings;
-}SX1276_t;
-
-/*!
- * Hardware IO IRQ callback function definition
- */
-typedef void ( DioIrqHandler )(void *arg);
-
-/*!
- * SX1276 definitions
- */
-#define XTAL_FREQ 32000000
-#define FREQ_STEP 61.03515625
-
-#define RX_BUFFER_SIZE 256
-
-/*!
- * ============================================================================
- * Public functions prototypes
- * ============================================================================
- */
-
-/*!
- * \brief Initializes the radio
- *
- * \param [IN] events Structure containing the driver callback functions
- */
-void SX1276Init( RadioEvents_t *events );
-
-/*!
- * Return current radio status
- *
- * \param status Radio status.[RF_IDLE, RF_RX_RUNNING, RF_TX_RUNNING]
- */
-RadioState_t SX1276GetStatus( void );
-
-/*!
- * \brief Configures the radio with the given modem
- *
- * \param [IN] modem Modem to be used [0: FSK, 1: LoRa]
- */
-void SX1276SetModem( RadioModems_t modem );
-
-/*!
- * \brief Sets the channels configuration
- *
- * \param [IN] freq Channel RF frequency
- */
-void SX1276SetChannel( 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 SX1276IsChannelFree( 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 SX1276SetRxConfig or
- * SX1276SetTxConfig functions must be called.
- *
- * \retval randomValue 32 bits random value
- */
-uint32_t SX1276Random( void );
-
-/*!
- * \brief Sets the reception parameters
- *
- * \remark When using LoRa modem only bandwidths 125, 250 and 500 kHz are supported
- *
- * \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 lenght 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 bewteen 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 SX1276SetRxConfig( 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
- *
- * \remark When using LoRa modem only bandwidths 125, 250 and 500 kHz are supported
- *
- * \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 bewteen 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 SX1276SetTxConfig( 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 Computes the packet time on air in us 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 (us) for the given packet payload length
- */
-uint32_t SX1276GetTimeOnAir( 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 SX1276Send( uint8_t *buffer, uint8_t size );
-
-/*!
- * \brief Sets the radio in sleep mode
- */
-void SX1276SetSleep( void );
-
-/*!
- * \brief Sets the radio in standby mode
- */
-void SX1276SetStby( void );
-
-/*!
- * \brief Sets the radio in reception mode for the given time
- * \param [IN] timeout Reception timeout [ms] [0: continuous, others timeout]
- */
-void SX1276SetRx( uint32_t timeout );
-
-/*!
- * \brief Start a Channel Activity Detection
- */
-void SX1276StartCad( void );
-
-/*!
- * \brief Reads the current RSSI value
- *
- * \retval rssiValue Current RSSI value in [dBm]
- */
-int16_t SX1276ReadRssi( RadioModems_t modem );
-
-/*!
- * \brief Writes the radio register at the specified address
- *
- * \param [IN]: addr Register address
- * \param [IN]: data New register value
- */
-void SX1276Write( 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 SX1276Read( 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 SX1276WriteBuffer( 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 SX1276ReadBuffer( 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 SX1276SetMaxPayloadLength( RadioModems_t modem, uint8_t max );
-
-#endif // __SX1276_H__
[34/40] incubator-mynewt-core git commit: specifically set DMTCNT as
the default triggers a warning
Posted by ja...@apache.org.
specifically set DMTCNT as the default triggers a warning
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/54a8c92a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/54a8c92a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/54a8c92a
Branch: refs/heads/bluetooth5
Commit: 54a8c92ad8ae3ff5b102cd30a3cd20fd9f77c866
Parents: ecf379b
Author: julian <ju...@imgtec.com>
Authored: Thu May 4 16:57:40 2017 +0100
Committer: julian <ju...@imgtec.com>
Committed: Thu May 4 16:58:45 2017 +0100
----------------------------------------------------------------------
hw/bsp/pic32mz2048_wi-fire/src/os_bsp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/54a8c92a/hw/bsp/pic32mz2048_wi-fire/src/os_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/pic32mz2048_wi-fire/src/os_bsp.c b/hw/bsp/pic32mz2048_wi-fire/src/os_bsp.c
index 4b9c0a6..af46cea 100644
--- a/hw/bsp/pic32mz2048_wi-fire/src/os_bsp.c
+++ b/hw/bsp/pic32mz2048_wi-fire/src/os_bsp.c
@@ -31,7 +31,7 @@
/* JTAG on, WDT off */
#pragma config JTAGEN=1, FWDTEN=0
/* DMT off, primary oscilator EC mode, PLL */
-#pragma config FDMTEN=0, POSCMOD=0, FNOSC=1
+#pragma config FDMTEN=0, POSCMOD=0, FNOSC=1, DMTCNT=1
/* 24MHz posc input to pll, div by 3, multiply by 50, div by 2 -> 200mhz*/
#pragma config FPLLODIV=1, FPLLMULT=49, FPLLICLK=0, FPLLRNG=1, FPLLIDIV=2
/* USB off */
[06/40] incubator-mynewt-core git commit: This closes #251.
Posted by ja...@apache.org.
This closes #251.
Merge branch 'cbor_substring_key' of https://github.com/wesley-wu/incubator-mynewt-core
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/2c8cdfb4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/2c8cdfb4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/2c8cdfb4
Branch: refs/heads/bluetooth5
Commit: 2c8cdfb46d27b5ee99e1eb7da29f2a814bd1c3a8
Parents: eb4f289 551c0a6
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Fri Apr 28 17:20:15 2017 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Fri Apr 28 17:20:15 2017 -0700
----------------------------------------------------------------------
encoding/cborattr/src/cborattr.c | 3 +-
encoding/cborattr/test/src/test_cborattr.c | 1 +
encoding/cborattr/test/src/test_cborattr.h | 1 +
.../testcases/cborattr_decode_substring_key.c | 111 +++++++++++++++++++
4 files changed, 115 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
[10/40] incubator-mynewt-core git commit: MYNEWT-741 Port of
LoRaMac-node library
Posted by ja...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/560fa920/hw/drivers/lora/node/radio/sx1276/src/sx1276Regs-Fsk.h
----------------------------------------------------------------------
diff --git a/hw/drivers/lora/node/radio/sx1276/src/sx1276Regs-Fsk.h b/hw/drivers/lora/node/radio/sx1276/src/sx1276Regs-Fsk.h
deleted file mode 100644
index 5bdd895..0000000
--- a/hw/drivers/lora/node/radio/sx1276/src/sx1276Regs-Fsk.h
+++ /dev/null
@@ -1,1134 +0,0 @@
-/*
- / _____) _ | |
-( (____ _____ ____ _| |_ _____ ____| |__
- \____ \| ___ | (_ _) ___ |/ ___) _ \
- _____) ) ____| | | || |_| ____( (___| | | |
-(______/|_____)_|_|_| \__)_____)\____)_| |_|
- (C)2013 Semtech
-
-Description: SX1276 FSK modem registers and bits definitions
-
-License: Revised BSD License, see LICENSE.TXT file include in the project
-
-Maintainer: Miguel Luis and Gregory Cristian
-*/
-#ifndef __SX1276_REGS_FSK_H__
-#define __SX1276_REGS_FSK_H__
-
-/*!
- * ============================================================================
- * SX1276 Internal registers Address
- * ============================================================================
- */
-#define REG_FIFO 0x00
-// Common settings
-#define REG_OPMODE 0x01
-#define REG_BITRATEMSB 0x02
-#define REG_BITRATELSB 0x03
-#define REG_FDEVMSB 0x04
-#define REG_FDEVLSB 0x05
-#define REG_FRFMSB 0x06
-#define REG_FRFMID 0x07
-#define REG_FRFLSB 0x08
-// Tx settings
-#define REG_PACONFIG 0x09
-#define REG_PARAMP 0x0A
-#define REG_OCP 0x0B
-// Rx settings
-#define REG_LNA 0x0C
-#define REG_RXCONFIG 0x0D
-#define REG_RSSICONFIG 0x0E
-#define REG_RSSICOLLISION 0x0F
-#define REG_RSSITHRESH 0x10
-#define REG_RSSIVALUE 0x11
-#define REG_RXBW 0x12
-#define REG_AFCBW 0x13
-#define REG_OOKPEAK 0x14
-#define REG_OOKFIX 0x15
-#define REG_OOKAVG 0x16
-#define REG_RES17 0x17
-#define REG_RES18 0x18
-#define REG_RES19 0x19
-#define REG_AFCFEI 0x1A
-#define REG_AFCMSB 0x1B
-#define REG_AFCLSB 0x1C
-#define REG_FEIMSB 0x1D
-#define REG_FEILSB 0x1E
-#define REG_PREAMBLEDETECT 0x1F
-#define REG_RXTIMEOUT1 0x20
-#define REG_RXTIMEOUT2 0x21
-#define REG_RXTIMEOUT3 0x22
-#define REG_RXDELAY 0x23
-// Oscillator settings
-#define REG_OSC 0x24
-// Packet handler settings
-#define REG_PREAMBLEMSB 0x25
-#define REG_PREAMBLELSB 0x26
-#define REG_SYNCCONFIG 0x27
-#define REG_SYNCVALUE1 0x28
-#define REG_SYNCVALUE2 0x29
-#define REG_SYNCVALUE3 0x2A
-#define REG_SYNCVALUE4 0x2B
-#define REG_SYNCVALUE5 0x2C
-#define REG_SYNCVALUE6 0x2D
-#define REG_SYNCVALUE7 0x2E
-#define REG_SYNCVALUE8 0x2F
-#define REG_PACKETCONFIG1 0x30
-#define REG_PACKETCONFIG2 0x31
-#define REG_PAYLOADLENGTH 0x32
-#define REG_NODEADRS 0x33
-#define REG_BROADCASTADRS 0x34
-#define REG_FIFOTHRESH 0x35
-// SM settings
-#define REG_SEQCONFIG1 0x36
-#define REG_SEQCONFIG2 0x37
-#define REG_TIMERRESOL 0x38
-#define REG_TIMER1COEF 0x39
-#define REG_TIMER2COEF 0x3A
-// Service settings
-#define REG_IMAGECAL 0x3B
-#define REG_TEMP 0x3C
-#define REG_LOWBAT 0x3D
-// Status
-#define REG_IRQFLAGS1 0x3E
-#define REG_IRQFLAGS2 0x3F
-// I/O settings
-#define REG_DIOMAPPING1 0x40
-#define REG_DIOMAPPING2 0x41
-// Version
-#define REG_VERSION 0x42
-// Additional settings
-#define REG_PLLHOP 0x44
-#define REG_TCXO 0x4B
-#define REG_PADAC 0x4D
-#define REG_FORMERTEMP 0x5B
-#define REG_BITRATEFRAC 0x5D
-#define REG_AGCREF 0x61
-#define REG_AGCTHRESH1 0x62
-#define REG_AGCTHRESH2 0x63
-#define REG_AGCTHRESH3 0x64
-#define REG_PLL 0x70
-
-/*!
- * ============================================================================
- * SX1276 FSK bits control definition
- * ============================================================================
- */
-
-/*!
- * RegFifo
- */
-
-/*!
- * RegOpMode
- */
-#define RF_OPMODE_LONGRANGEMODE_MASK 0x7F
-#define RF_OPMODE_LONGRANGEMODE_OFF 0x00
-#define RF_OPMODE_LONGRANGEMODE_ON 0x80
-
-#define RF_OPMODE_MODULATIONTYPE_MASK 0x9F
-#define RF_OPMODE_MODULATIONTYPE_FSK 0x00 // Default
-#define RF_OPMODE_MODULATIONTYPE_OOK 0x20
-
-#define RF_OPMODE_MODULATIONSHAPING_MASK 0xE7
-#define RF_OPMODE_MODULATIONSHAPING_00 0x00 // Default
-#define RF_OPMODE_MODULATIONSHAPING_01 0x08
-#define RF_OPMODE_MODULATIONSHAPING_10 0x10
-#define RF_OPMODE_MODULATIONSHAPING_11 0x18
-
-#define RF_OPMODE_MASK 0xF8
-#define RF_OPMODE_SLEEP 0x00
-#define RF_OPMODE_STANDBY 0x01 // Default
-#define RF_OPMODE_SYNTHESIZER_TX 0x02
-#define RF_OPMODE_TRANSMITTER 0x03
-#define RF_OPMODE_SYNTHESIZER_RX 0x04
-#define RF_OPMODE_RECEIVER 0x05
-
-/*!
- * RegBitRate (bits/sec)
- */
-#define RF_BITRATEMSB_1200_BPS 0x68
-#define RF_BITRATELSB_1200_BPS 0x2B
-#define RF_BITRATEMSB_2400_BPS 0x34
-#define RF_BITRATELSB_2400_BPS 0x15
-#define RF_BITRATEMSB_4800_BPS 0x1A // Default
-#define RF_BITRATELSB_4800_BPS 0x0B // Default
-#define RF_BITRATEMSB_9600_BPS 0x0D
-#define RF_BITRATELSB_9600_BPS 0x05
-#define RF_BITRATEMSB_15000_BPS 0x08
-#define RF_BITRATELSB_15000_BPS 0x55
-#define RF_BITRATEMSB_19200_BPS 0x06
-#define RF_BITRATELSB_19200_BPS 0x83
-#define RF_BITRATEMSB_38400_BPS 0x03
-#define RF_BITRATELSB_38400_BPS 0x41
-#define RF_BITRATEMSB_76800_BPS 0x01
-#define RF_BITRATELSB_76800_BPS 0xA1
-#define RF_BITRATEMSB_153600_BPS 0x00
-#define RF_BITRATELSB_153600_BPS 0xD0
-#define RF_BITRATEMSB_57600_BPS 0x02
-#define RF_BITRATELSB_57600_BPS 0x2C
-#define RF_BITRATEMSB_115200_BPS 0x01
-#define RF_BITRATELSB_115200_BPS 0x16
-#define RF_BITRATEMSB_12500_BPS 0x0A
-#define RF_BITRATELSB_12500_BPS 0x00
-#define RF_BITRATEMSB_25000_BPS 0x05
-#define RF_BITRATELSB_25000_BPS 0x00
-#define RF_BITRATEMSB_50000_BPS 0x02
-#define RF_BITRATELSB_50000_BPS 0x80
-#define RF_BITRATEMSB_100000_BPS 0x01
-#define RF_BITRATELSB_100000_BPS 0x40
-#define RF_BITRATEMSB_150000_BPS 0x00
-#define RF_BITRATELSB_150000_BPS 0xD5
-#define RF_BITRATEMSB_200000_BPS 0x00
-#define RF_BITRATELSB_200000_BPS 0xA0
-#define RF_BITRATEMSB_250000_BPS 0x00
-#define RF_BITRATELSB_250000_BPS 0x80
-#define RF_BITRATEMSB_32768_BPS 0x03
-#define RF_BITRATELSB_32768_BPS 0xD1
-
-/*!
- * RegFdev (Hz)
- */
-#define RF_FDEVMSB_2000_HZ 0x00
-#define RF_FDEVLSB_2000_HZ 0x21
-#define RF_FDEVMSB_5000_HZ 0x00 // Default
-#define RF_FDEVLSB_5000_HZ 0x52 // Default
-#define RF_FDEVMSB_10000_HZ 0x00
-#define RF_FDEVLSB_10000_HZ 0xA4
-#define RF_FDEVMSB_15000_HZ 0x00
-#define RF_FDEVLSB_15000_HZ 0xF6
-#define RF_FDEVMSB_20000_HZ 0x01
-#define RF_FDEVLSB_20000_HZ 0x48
-#define RF_FDEVMSB_25000_HZ 0x01
-#define RF_FDEVLSB_25000_HZ 0x9A
-#define RF_FDEVMSB_30000_HZ 0x01
-#define RF_FDEVLSB_30000_HZ 0xEC
-#define RF_FDEVMSB_35000_HZ 0x02
-#define RF_FDEVLSB_35000_HZ 0x3D
-#define RF_FDEVMSB_40000_HZ 0x02
-#define RF_FDEVLSB_40000_HZ 0x8F
-#define RF_FDEVMSB_45000_HZ 0x02
-#define RF_FDEVLSB_45000_HZ 0xE1
-#define RF_FDEVMSB_50000_HZ 0x03
-#define RF_FDEVLSB_50000_HZ 0x33
-#define RF_FDEVMSB_55000_HZ 0x03
-#define RF_FDEVLSB_55000_HZ 0x85
-#define RF_FDEVMSB_60000_HZ 0x03
-#define RF_FDEVLSB_60000_HZ 0xD7
-#define RF_FDEVMSB_65000_HZ 0x04
-#define RF_FDEVLSB_65000_HZ 0x29
-#define RF_FDEVMSB_70000_HZ 0x04
-#define RF_FDEVLSB_70000_HZ 0x7B
-#define RF_FDEVMSB_75000_HZ 0x04
-#define RF_FDEVLSB_75000_HZ 0xCD
-#define RF_FDEVMSB_80000_HZ 0x05
-#define RF_FDEVLSB_80000_HZ 0x1F
-#define RF_FDEVMSB_85000_HZ 0x05
-#define RF_FDEVLSB_85000_HZ 0x71
-#define RF_FDEVMSB_90000_HZ 0x05
-#define RF_FDEVLSB_90000_HZ 0xC3
-#define RF_FDEVMSB_95000_HZ 0x06
-#define RF_FDEVLSB_95000_HZ 0x14
-#define RF_FDEVMSB_100000_HZ 0x06
-#define RF_FDEVLSB_100000_HZ 0x66
-#define RF_FDEVMSB_110000_HZ 0x07
-#define RF_FDEVLSB_110000_HZ 0x0A
-#define RF_FDEVMSB_120000_HZ 0x07
-#define RF_FDEVLSB_120000_HZ 0xAE
-#define RF_FDEVMSB_130000_HZ 0x08
-#define RF_FDEVLSB_130000_HZ 0x52
-#define RF_FDEVMSB_140000_HZ 0x08
-#define RF_FDEVLSB_140000_HZ 0xF6
-#define RF_FDEVMSB_150000_HZ 0x09
-#define RF_FDEVLSB_150000_HZ 0x9A
-#define RF_FDEVMSB_160000_HZ 0x0A
-#define RF_FDEVLSB_160000_HZ 0x3D
-#define RF_FDEVMSB_170000_HZ 0x0A
-#define RF_FDEVLSB_170000_HZ 0xE1
-#define RF_FDEVMSB_180000_HZ 0x0B
-#define RF_FDEVLSB_180000_HZ 0x85
-#define RF_FDEVMSB_190000_HZ 0x0C
-#define RF_FDEVLSB_190000_HZ 0x29
-#define RF_FDEVMSB_200000_HZ 0x0C
-#define RF_FDEVLSB_200000_HZ 0xCD
-
-/*!
- * RegFrf (MHz)
- */
-#define RF_FRFMSB_863_MHZ 0xD7
-#define RF_FRFMID_863_MHZ 0xC0
-#define RF_FRFLSB_863_MHZ 0x00
-#define RF_FRFMSB_864_MHZ 0xD8
-#define RF_FRFMID_864_MHZ 0x00
-#define RF_FRFLSB_864_MHZ 0x00
-#define RF_FRFMSB_865_MHZ 0xD8
-#define RF_FRFMID_865_MHZ 0x40
-#define RF_FRFLSB_865_MHZ 0x00
-#define RF_FRFMSB_866_MHZ 0xD8
-#define RF_FRFMID_866_MHZ 0x80
-#define RF_FRFLSB_866_MHZ 0x00
-#define RF_FRFMSB_867_MHZ 0xD8
-#define RF_FRFMID_867_MHZ 0xC0
-#define RF_FRFLSB_867_MHZ 0x00
-#define RF_FRFMSB_868_MHZ 0xD9
-#define RF_FRFMID_868_MHZ 0x00
-#define RF_FRFLSB_868_MHZ 0x00
-#define RF_FRFMSB_869_MHZ 0xD9
-#define RF_FRFMID_869_MHZ 0x40
-#define RF_FRFLSB_869_MHZ 0x00
-#define RF_FRFMSB_870_MHZ 0xD9
-#define RF_FRFMID_870_MHZ 0x80
-#define RF_FRFLSB_870_MHZ 0x00
-
-#define RF_FRFMSB_902_MHZ 0xE1
-#define RF_FRFMID_902_MHZ 0x80
-#define RF_FRFLSB_902_MHZ 0x00
-#define RF_FRFMSB_903_MHZ 0xE1
-#define RF_FRFMID_903_MHZ 0xC0
-#define RF_FRFLSB_903_MHZ 0x00
-#define RF_FRFMSB_904_MHZ 0xE2
-#define RF_FRFMID_904_MHZ 0x00
-#define RF_FRFLSB_904_MHZ 0x00
-#define RF_FRFMSB_905_MHZ 0xE2
-#define RF_FRFMID_905_MHZ 0x40
-#define RF_FRFLSB_905_MHZ 0x00
-#define RF_FRFMSB_906_MHZ 0xE2
-#define RF_FRFMID_906_MHZ 0x80
-#define RF_FRFLSB_906_MHZ 0x00
-#define RF_FRFMSB_907_MHZ 0xE2
-#define RF_FRFMID_907_MHZ 0xC0
-#define RF_FRFLSB_907_MHZ 0x00
-#define RF_FRFMSB_908_MHZ 0xE3
-#define RF_FRFMID_908_MHZ 0x00
-#define RF_FRFLSB_908_MHZ 0x00
-#define RF_FRFMSB_909_MHZ 0xE3
-#define RF_FRFMID_909_MHZ 0x40
-#define RF_FRFLSB_909_MHZ 0x00
-#define RF_FRFMSB_910_MHZ 0xE3
-#define RF_FRFMID_910_MHZ 0x80
-#define RF_FRFLSB_910_MHZ 0x00
-#define RF_FRFMSB_911_MHZ 0xE3
-#define RF_FRFMID_911_MHZ 0xC0
-#define RF_FRFLSB_911_MHZ 0x00
-#define RF_FRFMSB_912_MHZ 0xE4
-#define RF_FRFMID_912_MHZ 0x00
-#define RF_FRFLSB_912_MHZ 0x00
-#define RF_FRFMSB_913_MHZ 0xE4
-#define RF_FRFMID_913_MHZ 0x40
-#define RF_FRFLSB_913_MHZ 0x00
-#define RF_FRFMSB_914_MHZ 0xE4
-#define RF_FRFMID_914_MHZ 0x80
-#define RF_FRFLSB_914_MHZ 0x00
-#define RF_FRFMSB_915_MHZ 0xE4 // Default
-#define RF_FRFMID_915_MHZ 0xC0 // Default
-#define RF_FRFLSB_915_MHZ 0x00 // Default
-#define RF_FRFMSB_916_MHZ 0xE5
-#define RF_FRFMID_916_MHZ 0x00
-#define RF_FRFLSB_916_MHZ 0x00
-#define RF_FRFMSB_917_MHZ 0xE5
-#define RF_FRFMID_917_MHZ 0x40
-#define RF_FRFLSB_917_MHZ 0x00
-#define RF_FRFMSB_918_MHZ 0xE5
-#define RF_FRFMID_918_MHZ 0x80
-#define RF_FRFLSB_918_MHZ 0x00
-#define RF_FRFMSB_919_MHZ 0xE5
-#define RF_FRFMID_919_MHZ 0xC0
-#define RF_FRFLSB_919_MHZ 0x00
-#define RF_FRFMSB_920_MHZ 0xE6
-#define RF_FRFMID_920_MHZ 0x00
-#define RF_FRFLSB_920_MHZ 0x00
-#define RF_FRFMSB_921_MHZ 0xE6
-#define RF_FRFMID_921_MHZ 0x40
-#define RF_FRFLSB_921_MHZ 0x00
-#define RF_FRFMSB_922_MHZ 0xE6
-#define RF_FRFMID_922_MHZ 0x80
-#define RF_FRFLSB_922_MHZ 0x00
-#define RF_FRFMSB_923_MHZ 0xE6
-#define RF_FRFMID_923_MHZ 0xC0
-#define RF_FRFLSB_923_MHZ 0x00
-#define RF_FRFMSB_924_MHZ 0xE7
-#define RF_FRFMID_924_MHZ 0x00
-#define RF_FRFLSB_924_MHZ 0x00
-#define RF_FRFMSB_925_MHZ 0xE7
-#define RF_FRFMID_925_MHZ 0x40
-#define RF_FRFLSB_925_MHZ 0x00
-#define RF_FRFMSB_926_MHZ 0xE7
-#define RF_FRFMID_926_MHZ 0x80
-#define RF_FRFLSB_926_MHZ 0x00
-#define RF_FRFMSB_927_MHZ 0xE7
-#define RF_FRFMID_927_MHZ 0xC0
-#define RF_FRFLSB_927_MHZ 0x00
-#define RF_FRFMSB_928_MHZ 0xE8
-#define RF_FRFMID_928_MHZ 0x00
-#define RF_FRFLSB_928_MHZ 0x00
-
-/*!
- * RegPaConfig
- */
-#define RF_PACONFIG_PASELECT_MASK 0x7F
-#define RF_PACONFIG_PASELECT_PABOOST 0x80
-#define RF_PACONFIG_PASELECT_RFO 0x00 // Default
-
-#define RF_PACONFIG_MAX_POWER_MASK 0x8F
-
-#define RF_PACONFIG_OUTPUTPOWER_MASK 0xF0
-
-/*!
- * RegPaRamp
- */
-#define RF_PARAMP_MODULATIONSHAPING_MASK 0x9F
-#define RF_PARAMP_MODULATIONSHAPING_00 0x00 // Default
-#define RF_PARAMP_MODULATIONSHAPING_01 0x20
-#define RF_PARAMP_MODULATIONSHAPING_10 0x40
-#define RF_PARAMP_MODULATIONSHAPING_11 0x60
-
-#define RF_PARAMP_LOWPNTXPLL_MASK 0xEF
-#define RF_PARAMP_LOWPNTXPLL_OFF 0x10
-#define RF_PARAMP_LOWPNTXPLL_ON 0x00 // Default
-
-#define RF_PARAMP_MASK 0xF0
-#define RF_PARAMP_3400_US 0x00
-#define RF_PARAMP_2000_US 0x01
-#define RF_PARAMP_1000_US 0x02
-#define RF_PARAMP_0500_US 0x03
-#define RF_PARAMP_0250_US 0x04
-#define RF_PARAMP_0125_US 0x05
-#define RF_PARAMP_0100_US 0x06
-#define RF_PARAMP_0062_US 0x07
-#define RF_PARAMP_0050_US 0x08
-#define RF_PARAMP_0040_US 0x09 // Default
-#define RF_PARAMP_0031_US 0x0A
-#define RF_PARAMP_0025_US 0x0B
-#define RF_PARAMP_0020_US 0x0C
-#define RF_PARAMP_0015_US 0x0D
-#define RF_PARAMP_0012_US 0x0E
-#define RF_PARAMP_0010_US 0x0F
-
-/*!
- * RegOcp
- */
-#define RF_OCP_MASK 0xDF
-#define RF_OCP_ON 0x20 // Default
-#define RF_OCP_OFF 0x00
-
-#define RF_OCP_TRIM_MASK 0xE0
-#define RF_OCP_TRIM_045_MA 0x00
-#define RF_OCP_TRIM_050_MA 0x01
-#define RF_OCP_TRIM_055_MA 0x02
-#define RF_OCP_TRIM_060_MA 0x03
-#define RF_OCP_TRIM_065_MA 0x04
-#define RF_OCP_TRIM_070_MA 0x05
-#define RF_OCP_TRIM_075_MA 0x06
-#define RF_OCP_TRIM_080_MA 0x07
-#define RF_OCP_TRIM_085_MA 0x08
-#define RF_OCP_TRIM_090_MA 0x09
-#define RF_OCP_TRIM_095_MA 0x0A
-#define RF_OCP_TRIM_100_MA 0x0B // Default
-#define RF_OCP_TRIM_105_MA 0x0C
-#define RF_OCP_TRIM_110_MA 0x0D
-#define RF_OCP_TRIM_115_MA 0x0E
-#define RF_OCP_TRIM_120_MA 0x0F
-#define RF_OCP_TRIM_130_MA 0x10
-#define RF_OCP_TRIM_140_MA 0x11
-#define RF_OCP_TRIM_150_MA 0x12
-#define RF_OCP_TRIM_160_MA 0x13
-#define RF_OCP_TRIM_170_MA 0x14
-#define RF_OCP_TRIM_180_MA 0x15
-#define RF_OCP_TRIM_190_MA 0x16
-#define RF_OCP_TRIM_200_MA 0x17
-#define RF_OCP_TRIM_210_MA 0x18
-#define RF_OCP_TRIM_220_MA 0x19
-#define RF_OCP_TRIM_230_MA 0x1A
-#define RF_OCP_TRIM_240_MA 0x1B
-
-/*!
- * RegLna
- */
-#define RF_LNA_GAIN_MASK 0x1F
-#define RF_LNA_GAIN_G1 0x20 // Default
-#define RF_LNA_GAIN_G2 0x40
-#define RF_LNA_GAIN_G3 0x60
-#define RF_LNA_GAIN_G4 0x80
-#define RF_LNA_GAIN_G5 0xA0
-#define RF_LNA_GAIN_G6 0xC0
-
-#define RF_LNA_BOOST_MASK 0xFC
-#define RF_LNA_BOOST_OFF 0x00 // Default
-#define RF_LNA_BOOST_ON 0x03
-
-/*!
- * RegRxConfig
- */
-#define RF_RXCONFIG_RESTARTRXONCOLLISION_MASK 0x7F
-#define RF_RXCONFIG_RESTARTRXONCOLLISION_ON 0x80
-#define RF_RXCONFIG_RESTARTRXONCOLLISION_OFF 0x00 // Default
-
-#define RF_RXCONFIG_RESTARTRXWITHOUTPLLLOCK 0x40 // Write only
-
-#define RF_RXCONFIG_RESTARTRXWITHPLLLOCK 0x20 // Write only
-
-#define RF_RXCONFIG_AFCAUTO_MASK 0xEF
-#define RF_RXCONFIG_AFCAUTO_ON 0x10
-#define RF_RXCONFIG_AFCAUTO_OFF 0x00 // Default
-
-#define RF_RXCONFIG_AGCAUTO_MASK 0xF7
-#define RF_RXCONFIG_AGCAUTO_ON 0x08 // Default
-#define RF_RXCONFIG_AGCAUTO_OFF 0x00
-
-#define RF_RXCONFIG_RXTRIGER_MASK 0xF8
-#define RF_RXCONFIG_RXTRIGER_OFF 0x00
-#define RF_RXCONFIG_RXTRIGER_RSSI 0x01
-#define RF_RXCONFIG_RXTRIGER_PREAMBLEDETECT 0x06 // Default
-#define RF_RXCONFIG_RXTRIGER_RSSI_PREAMBLEDETECT 0x07
-
-/*!
- * RegRssiConfig
- */
-#define RF_RSSICONFIG_OFFSET_MASK 0x07
-#define RF_RSSICONFIG_OFFSET_P_00_DB 0x00 // Default
-#define RF_RSSICONFIG_OFFSET_P_01_DB 0x08
-#define RF_RSSICONFIG_OFFSET_P_02_DB 0x10
-#define RF_RSSICONFIG_OFFSET_P_03_DB 0x18
-#define RF_RSSICONFIG_OFFSET_P_04_DB 0x20
-#define RF_RSSICONFIG_OFFSET_P_05_DB 0x28
-#define RF_RSSICONFIG_OFFSET_P_06_DB 0x30
-#define RF_RSSICONFIG_OFFSET_P_07_DB 0x38
-#define RF_RSSICONFIG_OFFSET_P_08_DB 0x40
-#define RF_RSSICONFIG_OFFSET_P_09_DB 0x48
-#define RF_RSSICONFIG_OFFSET_P_10_DB 0x50
-#define RF_RSSICONFIG_OFFSET_P_11_DB 0x58
-#define RF_RSSICONFIG_OFFSET_P_12_DB 0x60
-#define RF_RSSICONFIG_OFFSET_P_13_DB 0x68
-#define RF_RSSICONFIG_OFFSET_P_14_DB 0x70
-#define RF_RSSICONFIG_OFFSET_P_15_DB 0x78
-#define RF_RSSICONFIG_OFFSET_M_16_DB 0x80
-#define RF_RSSICONFIG_OFFSET_M_15_DB 0x88
-#define RF_RSSICONFIG_OFFSET_M_14_DB 0x90
-#define RF_RSSICONFIG_OFFSET_M_13_DB 0x98
-#define RF_RSSICONFIG_OFFSET_M_12_DB 0xA0
-#define RF_RSSICONFIG_OFFSET_M_11_DB 0xA8
-#define RF_RSSICONFIG_OFFSET_M_10_DB 0xB0
-#define RF_RSSICONFIG_OFFSET_M_09_DB 0xB8
-#define RF_RSSICONFIG_OFFSET_M_08_DB 0xC0
-#define RF_RSSICONFIG_OFFSET_M_07_DB 0xC8
-#define RF_RSSICONFIG_OFFSET_M_06_DB 0xD0
-#define RF_RSSICONFIG_OFFSET_M_05_DB 0xD8
-#define RF_RSSICONFIG_OFFSET_M_04_DB 0xE0
-#define RF_RSSICONFIG_OFFSET_M_03_DB 0xE8
-#define RF_RSSICONFIG_OFFSET_M_02_DB 0xF0
-#define RF_RSSICONFIG_OFFSET_M_01_DB 0xF8
-
-#define RF_RSSICONFIG_SMOOTHING_MASK 0xF8
-#define RF_RSSICONFIG_SMOOTHING_2 0x00
-#define RF_RSSICONFIG_SMOOTHING_4 0x01
-#define RF_RSSICONFIG_SMOOTHING_8 0x02 // Default
-#define RF_RSSICONFIG_SMOOTHING_16 0x03
-#define RF_RSSICONFIG_SMOOTHING_32 0x04
-#define RF_RSSICONFIG_SMOOTHING_64 0x05
-#define RF_RSSICONFIG_SMOOTHING_128 0x06
-#define RF_RSSICONFIG_SMOOTHING_256 0x07
-
-/*!
- * RegRssiCollision
- */
-#define RF_RSSICOLISION_THRESHOLD 0x0A // Default
-
-/*!
- * RegRssiThresh
- */
-#define RF_RSSITHRESH_THRESHOLD 0xFF // Default
-
-/*!
- * RegRssiValue (Read Only)
- */
-
-/*!
- * RegRxBw
- */
-#define RF_RXBW_MANT_MASK 0xE7
-#define RF_RXBW_MANT_16 0x00
-#define RF_RXBW_MANT_20 0x08
-#define RF_RXBW_MANT_24 0x10 // Default
-
-#define RF_RXBW_EXP_MASK 0xF8
-#define RF_RXBW_EXP_0 0x00
-#define RF_RXBW_EXP_1 0x01
-#define RF_RXBW_EXP_2 0x02
-#define RF_RXBW_EXP_3 0x03
-#define RF_RXBW_EXP_4 0x04
-#define RF_RXBW_EXP_5 0x05 // Default
-#define RF_RXBW_EXP_6 0x06
-#define RF_RXBW_EXP_7 0x07
-
-/*!
- * RegAfcBw
- */
-#define RF_AFCBW_MANTAFC_MASK 0xE7
-#define RF_AFCBW_MANTAFC_16 0x00
-#define RF_AFCBW_MANTAFC_20 0x08 // Default
-#define RF_AFCBW_MANTAFC_24 0x10
-
-#define RF_AFCBW_EXPAFC_MASK 0xF8
-#define RF_AFCBW_EXPAFC_0 0x00
-#define RF_AFCBW_EXPAFC_1 0x01
-#define RF_AFCBW_EXPAFC_2 0x02
-#define RF_AFCBW_EXPAFC_3 0x03 // Default
-#define RF_AFCBW_EXPAFC_4 0x04
-#define RF_AFCBW_EXPAFC_5 0x05
-#define RF_AFCBW_EXPAFC_6 0x06
-#define RF_AFCBW_EXPAFC_7 0x07
-
-/*!
- * RegOokPeak
- */
-#define RF_OOKPEAK_BITSYNC_MASK 0xDF // Default
-#define RF_OOKPEAK_BITSYNC_ON 0x20 // Default
-#define RF_OOKPEAK_BITSYNC_OFF 0x00
-
-#define RF_OOKPEAK_OOKTHRESHTYPE_MASK 0xE7
-#define RF_OOKPEAK_OOKTHRESHTYPE_FIXED 0x00
-#define RF_OOKPEAK_OOKTHRESHTYPE_PEAK 0x08 // Default
-#define RF_OOKPEAK_OOKTHRESHTYPE_AVERAGE 0x10
-
-#define RF_OOKPEAK_OOKPEAKTHRESHSTEP_MASK 0xF8
-#define RF_OOKPEAK_OOKPEAKTHRESHSTEP_0_5_DB 0x00 // Default
-#define RF_OOKPEAK_OOKPEAKTHRESHSTEP_1_0_DB 0x01
-#define RF_OOKPEAK_OOKPEAKTHRESHSTEP_1_5_DB 0x02
-#define RF_OOKPEAK_OOKPEAKTHRESHSTEP_2_0_DB 0x03
-#define RF_OOKPEAK_OOKPEAKTHRESHSTEP_3_0_DB 0x04
-#define RF_OOKPEAK_OOKPEAKTHRESHSTEP_4_0_DB 0x05
-#define RF_OOKPEAK_OOKPEAKTHRESHSTEP_5_0_DB 0x06
-#define RF_OOKPEAK_OOKPEAKTHRESHSTEP_6_0_DB 0x07
-
-/*!
- * RegOokFix
- */
-#define RF_OOKFIX_OOKFIXEDTHRESHOLD 0x0C // Default
-
-/*!
- * RegOokAvg
- */
-#define RF_OOKAVG_OOKPEAKTHRESHDEC_MASK 0x1F
-#define RF_OOKAVG_OOKPEAKTHRESHDEC_000 0x00 // Default
-#define RF_OOKAVG_OOKPEAKTHRESHDEC_001 0x20
-#define RF_OOKAVG_OOKPEAKTHRESHDEC_010 0x40
-#define RF_OOKAVG_OOKPEAKTHRESHDEC_011 0x60
-#define RF_OOKAVG_OOKPEAKTHRESHDEC_100 0x80
-#define RF_OOKAVG_OOKPEAKTHRESHDEC_101 0xA0
-#define RF_OOKAVG_OOKPEAKTHRESHDEC_110 0xC0
-#define RF_OOKAVG_OOKPEAKTHRESHDEC_111 0xE0
-
-#define RF_OOKAVG_AVERAGEOFFSET_MASK 0xF3
-#define RF_OOKAVG_AVERAGEOFFSET_0_DB 0x00 // Default
-#define RF_OOKAVG_AVERAGEOFFSET_2_DB 0x04
-#define RF_OOKAVG_AVERAGEOFFSET_4_DB 0x08
-#define RF_OOKAVG_AVERAGEOFFSET_6_DB 0x0C
-
-#define RF_OOKAVG_OOKAVERAGETHRESHFILT_MASK 0xFC
-#define RF_OOKAVG_OOKAVERAGETHRESHFILT_00 0x00
-#define RF_OOKAVG_OOKAVERAGETHRESHFILT_01 0x01
-#define RF_OOKAVG_OOKAVERAGETHRESHFILT_10 0x02 // Default
-#define RF_OOKAVG_OOKAVERAGETHRESHFILT_11 0x03
-
-/*!
- * RegAfcFei
- */
-#define RF_AFCFEI_AGCSTART 0x10
-
-#define RF_AFCFEI_AFCCLEAR 0x02
-
-#define RF_AFCFEI_AFCAUTOCLEAR_MASK 0xFE
-#define RF_AFCFEI_AFCAUTOCLEAR_ON 0x01
-#define RF_AFCFEI_AFCAUTOCLEAR_OFF 0x00 // Default
-
-/*!
- * RegAfcMsb (Read Only)
- */
-
-/*!
- * RegAfcLsb (Read Only)
- */
-
-/*!
- * RegFeiMsb (Read Only)
- */
-
-/*!
- * RegFeiLsb (Read Only)
- */
-
-/*!
- * RegPreambleDetect
- */
-#define RF_PREAMBLEDETECT_DETECTOR_MASK 0x7F
-#define RF_PREAMBLEDETECT_DETECTOR_ON 0x80 // Default
-#define RF_PREAMBLEDETECT_DETECTOR_OFF 0x00
-
-#define RF_PREAMBLEDETECT_DETECTORSIZE_MASK 0x9F
-#define RF_PREAMBLEDETECT_DETECTORSIZE_1 0x00
-#define RF_PREAMBLEDETECT_DETECTORSIZE_2 0x20 // Default
-#define RF_PREAMBLEDETECT_DETECTORSIZE_3 0x40
-#define RF_PREAMBLEDETECT_DETECTORSIZE_4 0x60
-
-#define RF_PREAMBLEDETECT_DETECTORTOL_MASK 0xE0
-#define RF_PREAMBLEDETECT_DETECTORTOL_0 0x00
-#define RF_PREAMBLEDETECT_DETECTORTOL_1 0x01
-#define RF_PREAMBLEDETECT_DETECTORTOL_2 0x02
-#define RF_PREAMBLEDETECT_DETECTORTOL_3 0x03
-#define RF_PREAMBLEDETECT_DETECTORTOL_4 0x04
-#define RF_PREAMBLEDETECT_DETECTORTOL_5 0x05
-#define RF_PREAMBLEDETECT_DETECTORTOL_6 0x06
-#define RF_PREAMBLEDETECT_DETECTORTOL_7 0x07
-#define RF_PREAMBLEDETECT_DETECTORTOL_8 0x08
-#define RF_PREAMBLEDETECT_DETECTORTOL_9 0x09
-#define RF_PREAMBLEDETECT_DETECTORTOL_10 0x0A // Default
-#define RF_PREAMBLEDETECT_DETECTORTOL_11 0x0B
-#define RF_PREAMBLEDETECT_DETECTORTOL_12 0x0C
-#define RF_PREAMBLEDETECT_DETECTORTOL_13 0x0D
-#define RF_PREAMBLEDETECT_DETECTORTOL_14 0x0E
-#define RF_PREAMBLEDETECT_DETECTORTOL_15 0x0F
-#define RF_PREAMBLEDETECT_DETECTORTOL_16 0x10
-#define RF_PREAMBLEDETECT_DETECTORTOL_17 0x11
-#define RF_PREAMBLEDETECT_DETECTORTOL_18 0x12
-#define RF_PREAMBLEDETECT_DETECTORTOL_19 0x13
-#define RF_PREAMBLEDETECT_DETECTORTOL_20 0x14
-#define RF_PREAMBLEDETECT_DETECTORTOL_21 0x15
-#define RF_PREAMBLEDETECT_DETECTORTOL_22 0x16
-#define RF_PREAMBLEDETECT_DETECTORTOL_23 0x17
-#define RF_PREAMBLEDETECT_DETECTORTOL_24 0x18
-#define RF_PREAMBLEDETECT_DETECTORTOL_25 0x19
-#define RF_PREAMBLEDETECT_DETECTORTOL_26 0x1A
-#define RF_PREAMBLEDETECT_DETECTORTOL_27 0x1B
-#define RF_PREAMBLEDETECT_DETECTORTOL_28 0x1C
-#define RF_PREAMBLEDETECT_DETECTORTOL_29 0x1D
-#define RF_PREAMBLEDETECT_DETECTORTOL_30 0x1E
-#define RF_PREAMBLEDETECT_DETECTORTOL_31 0x1F
-
-/*!
- * RegRxTimeout1
- */
-#define RF_RXTIMEOUT1_TIMEOUTRXRSSI 0x00 // Default
-
-/*!
- * RegRxTimeout2
- */
-#define RF_RXTIMEOUT2_TIMEOUTRXPREAMBLE 0x00 // Default
-
-/*!
- * RegRxTimeout3
- */
-#define RF_RXTIMEOUT3_TIMEOUTSIGNALSYNC 0x00 // Default
-
-/*!
- * RegRxDelay
- */
-#define RF_RXDELAY_INTERPACKETRXDELAY 0x00 // Default
-
-/*!
- * RegOsc
- */
-#define RF_OSC_RCCALSTART 0x08
-
-#define RF_OSC_CLKOUT_MASK 0xF8
-#define RF_OSC_CLKOUT_32_MHZ 0x00
-#define RF_OSC_CLKOUT_16_MHZ 0x01
-#define RF_OSC_CLKOUT_8_MHZ 0x02
-#define RF_OSC_CLKOUT_4_MHZ 0x03
-#define RF_OSC_CLKOUT_2_MHZ 0x04
-#define RF_OSC_CLKOUT_1_MHZ 0x05 // Default
-#define RF_OSC_CLKOUT_RC 0x06
-#define RF_OSC_CLKOUT_OFF 0x07
-
-/*!
- * RegPreambleMsb/RegPreambleLsb
- */
-#define RF_PREAMBLEMSB_SIZE 0x00 // Default
-#define RF_PREAMBLELSB_SIZE 0x03 // Default
-
-/*!
- * RegSyncConfig
- */
-#define RF_SYNCCONFIG_AUTORESTARTRXMODE_MASK 0x3F
-#define RF_SYNCCONFIG_AUTORESTARTRXMODE_WAITPLL_ON 0x80 // Default
-#define RF_SYNCCONFIG_AUTORESTARTRXMODE_WAITPLL_OFF 0x40
-#define RF_SYNCCONFIG_AUTORESTARTRXMODE_OFF 0x00
-
-
-#define RF_SYNCCONFIG_PREAMBLEPOLARITY_MASK 0xDF
-#define RF_SYNCCONFIG_PREAMBLEPOLARITY_55 0x20
-#define RF_SYNCCONFIG_PREAMBLEPOLARITY_AA 0x00 // Default
-
-#define RF_SYNCCONFIG_SYNC_MASK 0xEF
-#define RF_SYNCCONFIG_SYNC_ON 0x10 // Default
-#define RF_SYNCCONFIG_SYNC_OFF 0x00
-
-
-#define RF_SYNCCONFIG_SYNCSIZE_MASK 0xF8
-#define RF_SYNCCONFIG_SYNCSIZE_1 0x00
-#define RF_SYNCCONFIG_SYNCSIZE_2 0x01
-#define RF_SYNCCONFIG_SYNCSIZE_3 0x02
-#define RF_SYNCCONFIG_SYNCSIZE_4 0x03 // Default
-#define RF_SYNCCONFIG_SYNCSIZE_5 0x04
-#define RF_SYNCCONFIG_SYNCSIZE_6 0x05
-#define RF_SYNCCONFIG_SYNCSIZE_7 0x06
-#define RF_SYNCCONFIG_SYNCSIZE_8 0x07
-
-/*!
- * RegSyncValue1-8
- */
-#define RF_SYNCVALUE1_SYNCVALUE 0x01 // Default
-#define RF_SYNCVALUE2_SYNCVALUE 0x01 // Default
-#define RF_SYNCVALUE3_SYNCVALUE 0x01 // Default
-#define RF_SYNCVALUE4_SYNCVALUE 0x01 // Default
-#define RF_SYNCVALUE5_SYNCVALUE 0x01 // Default
-#define RF_SYNCVALUE6_SYNCVALUE 0x01 // Default
-#define RF_SYNCVALUE7_SYNCVALUE 0x01 // Default
-#define RF_SYNCVALUE8_SYNCVALUE 0x01 // Default
-
-/*!
- * RegPacketConfig1
- */
-#define RF_PACKETCONFIG1_PACKETFORMAT_MASK 0x7F
-#define RF_PACKETCONFIG1_PACKETFORMAT_FIXED 0x00
-#define RF_PACKETCONFIG1_PACKETFORMAT_VARIABLE 0x80 // Default
-
-#define RF_PACKETCONFIG1_DCFREE_MASK 0x9F
-#define RF_PACKETCONFIG1_DCFREE_OFF 0x00 // Default
-#define RF_PACKETCONFIG1_DCFREE_MANCHESTER 0x20
-#define RF_PACKETCONFIG1_DCFREE_WHITENING 0x40
-
-#define RF_PACKETCONFIG1_CRC_MASK 0xEF
-#define RF_PACKETCONFIG1_CRC_ON 0x10 // Default
-#define RF_PACKETCONFIG1_CRC_OFF 0x00
-
-#define RF_PACKETCONFIG1_CRCAUTOCLEAR_MASK 0xF7
-#define RF_PACKETCONFIG1_CRCAUTOCLEAR_ON 0x00 // Default
-#define RF_PACKETCONFIG1_CRCAUTOCLEAR_OFF 0x08
-
-#define RF_PACKETCONFIG1_ADDRSFILTERING_MASK 0xF9
-#define RF_PACKETCONFIG1_ADDRSFILTERING_OFF 0x00 // Default
-#define RF_PACKETCONFIG1_ADDRSFILTERING_NODE 0x02
-#define RF_PACKETCONFIG1_ADDRSFILTERING_NODEBROADCAST 0x04
-
-#define RF_PACKETCONFIG1_CRCWHITENINGTYPE_MASK 0xFE
-#define RF_PACKETCONFIG1_CRCWHITENINGTYPE_CCITT 0x00 // Default
-#define RF_PACKETCONFIG1_CRCWHITENINGTYPE_IBM 0x01
-
-/*!
- * RegPacketConfig2
- */
-
-#define RF_PACKETCONFIG2_WMBUS_CRC_ENABLE_MASK 0x7F
-#define RF_PACKETCONFIG2_WMBUS_CRC_ENABLE 0x80
-#define RF_PACKETCONFIG2_WMBUS_CRC_DISABLE 0x00 // Default
-
-#define RF_PACKETCONFIG2_DATAMODE_MASK 0xBF
-#define RF_PACKETCONFIG2_DATAMODE_CONTINUOUS 0x00
-#define RF_PACKETCONFIG2_DATAMODE_PACKET 0x40 // Default
-
-#define RF_PACKETCONFIG2_IOHOME_MASK 0xDF
-#define RF_PACKETCONFIG2_IOHOME_ON 0x20
-#define RF_PACKETCONFIG2_IOHOME_OFF 0x00 // Default
-
-#define RF_PACKETCONFIG2_BEACON_MASK 0xF7
-#define RF_PACKETCONFIG2_BEACON_ON 0x08
-#define RF_PACKETCONFIG2_BEACON_OFF 0x00 // Default
-
-#define RF_PACKETCONFIG2_PAYLOADLENGTH_MSB_MASK 0xF8
-
-/*!
- * RegPayloadLength
- */
-#define RF_PAYLOADLENGTH_LENGTH 0x40 // Default
-
-/*!
- * RegNodeAdrs
- */
-#define RF_NODEADDRESS_ADDRESS 0x00
-
-/*!
- * RegBroadcastAdrs
- */
-#define RF_BROADCASTADDRESS_ADDRESS 0x00
-
-/*!
- * RegFifoThresh
- */
-#define RF_FIFOTHRESH_TXSTARTCONDITION_MASK 0x7F
-#define RF_FIFOTHRESH_TXSTARTCONDITION_FIFOTHRESH 0x00 // Default
-#define RF_FIFOTHRESH_TXSTARTCONDITION_FIFONOTEMPTY 0x80
-
-#define RF_FIFOTHRESH_FIFOTHRESHOLD_MASK 0xC0
-#define RF_FIFOTHRESH_FIFOTHRESHOLD_THRESHOLD 0x0F // Default
-
-/*!
- * RegSeqConfig1
- */
-#define RF_SEQCONFIG1_SEQUENCER_START 0x80
-
-#define RF_SEQCONFIG1_SEQUENCER_STOP 0x40
-
-#define RF_SEQCONFIG1_IDLEMODE_MASK 0xDF
-#define RF_SEQCONFIG1_IDLEMODE_SLEEP 0x20
-#define RF_SEQCONFIG1_IDLEMODE_STANDBY 0x00 // Default
-
-#define RF_SEQCONFIG1_FROMSTART_MASK 0xE7
-#define RF_SEQCONFIG1_FROMSTART_TOLPS 0x00 // Default
-#define RF_SEQCONFIG1_FROMSTART_TORX 0x08
-#define RF_SEQCONFIG1_FROMSTART_TOTX 0x10
-#define RF_SEQCONFIG1_FROMSTART_TOTX_ONFIFOLEVEL 0x18
-
-#define RF_SEQCONFIG1_LPS_MASK 0xFB
-#define RF_SEQCONFIG1_LPS_SEQUENCER_OFF 0x00 // Default
-#define RF_SEQCONFIG1_LPS_IDLE 0x04
-
-#define RF_SEQCONFIG1_FROMIDLE_MASK 0xFD
-#define RF_SEQCONFIG1_FROMIDLE_TOTX 0x00 // Default
-#define RF_SEQCONFIG1_FROMIDLE_TORX 0x02
-
-#define RF_SEQCONFIG1_FROMTX_MASK 0xFE
-#define RF_SEQCONFIG1_FROMTX_TOLPS 0x00 // Default
-#define RF_SEQCONFIG1_FROMTX_TORX 0x01
-
-/*!
- * RegSeqConfig2
- */
-#define RF_SEQCONFIG2_FROMRX_MASK 0x1F
-#define RF_SEQCONFIG2_FROMRX_TOUNUSED_000 0x00 // Default
-#define RF_SEQCONFIG2_FROMRX_TORXPKT_ONPLDRDY 0x20
-#define RF_SEQCONFIG2_FROMRX_TOLPS_ONPLDRDY 0x40
-#define RF_SEQCONFIG2_FROMRX_TORXPKT_ONCRCOK 0x60
-#define RF_SEQCONFIG2_FROMRX_TOSEQUENCEROFF_ONRSSI 0x80
-#define RF_SEQCONFIG2_FROMRX_TOSEQUENCEROFF_ONSYNC 0xA0
-#define RF_SEQCONFIG2_FROMRX_TOSEQUENCEROFF_ONPREAMBLE 0xC0
-#define RF_SEQCONFIG2_FROMRX_TOUNUSED_111 0xE0
-
-#define RF_SEQCONFIG2_FROMRXTIMEOUT_MASK 0xE7
-#define RF_SEQCONFIG2_FROMRXTIMEOUT_TORXRESTART 0x00 // Default
-#define RF_SEQCONFIG2_FROMRXTIMEOUT_TOTX 0x08
-#define RF_SEQCONFIG2_FROMRXTIMEOUT_TOLPS 0x10
-#define RF_SEQCONFIG2_FROMRXTIMEOUT_TOSEQUENCEROFF 0x18
-
-#define RF_SEQCONFIG2_FROMRXPKT_MASK 0xF8
-#define RF_SEQCONFIG2_FROMRXPKT_TOSEQUENCEROFF 0x00 // Default
-#define RF_SEQCONFIG2_FROMRXPKT_TOTX_ONFIFOEMPTY 0x01
-#define RF_SEQCONFIG2_FROMRXPKT_TOLPS 0x02
-#define RF_SEQCONFIG2_FROMRXPKT_TOSYNTHESIZERRX 0x03
-#define RF_SEQCONFIG2_FROMRXPKT_TORX 0x04
-
-/*!
- * RegTimerResol
- */
-#define RF_TIMERRESOL_TIMER1RESOL_MASK 0xF3
-#define RF_TIMERRESOL_TIMER1RESOL_OFF 0x00 // Default
-#define RF_TIMERRESOL_TIMER1RESOL_000064_US 0x04
-#define RF_TIMERRESOL_TIMER1RESOL_004100_US 0x08
-#define RF_TIMERRESOL_TIMER1RESOL_262000_US 0x0C
-
-#define RF_TIMERRESOL_TIMER2RESOL_MASK 0xFC
-#define RF_TIMERRESOL_TIMER2RESOL_OFF 0x00 // Default
-#define RF_TIMERRESOL_TIMER2RESOL_000064_US 0x01
-#define RF_TIMERRESOL_TIMER2RESOL_004100_US 0x02
-#define RF_TIMERRESOL_TIMER2RESOL_262000_US 0x03
-
-/*!
- * RegTimer1Coef
- */
-#define RF_TIMER1COEF_TIMER1COEFFICIENT 0xF5 // Default
-
-/*!
- * RegTimer2Coef
- */
-#define RF_TIMER2COEF_TIMER2COEFFICIENT 0x20 // Default
-
-/*!
- * RegImageCal
- */
-#define RF_IMAGECAL_AUTOIMAGECAL_MASK 0x7F
-#define RF_IMAGECAL_AUTOIMAGECAL_ON 0x80
-#define RF_IMAGECAL_AUTOIMAGECAL_OFF 0x00 // Default
-
-#define RF_IMAGECAL_IMAGECAL_MASK 0xBF
-#define RF_IMAGECAL_IMAGECAL_START 0x40
-
-#define RF_IMAGECAL_IMAGECAL_RUNNING 0x20
-#define RF_IMAGECAL_IMAGECAL_DONE 0x00 // Default
-
-#define RF_IMAGECAL_TEMPCHANGE_HIGHER 0x08
-#define RF_IMAGECAL_TEMPCHANGE_LOWER 0x00
-
-#define RF_IMAGECAL_TEMPTHRESHOLD_MASK 0xF9
-#define RF_IMAGECAL_TEMPTHRESHOLD_05 0x00
-#define RF_IMAGECAL_TEMPTHRESHOLD_10 0x02 // Default
-#define RF_IMAGECAL_TEMPTHRESHOLD_15 0x04
-#define RF_IMAGECAL_TEMPTHRESHOLD_20 0x06
-
-#define RF_IMAGECAL_TEMPMONITOR_MASK 0xFE
-#define RF_IMAGECAL_TEMPMONITOR_ON 0x00 // Default
-#define RF_IMAGECAL_TEMPMONITOR_OFF 0x01
-
-/*!
- * RegTemp (Read Only)
- */
-
-/*!
- * RegLowBat
- */
-#define RF_LOWBAT_MASK 0xF7
-#define RF_LOWBAT_ON 0x08
-#define RF_LOWBAT_OFF 0x00 // Default
-
-#define RF_LOWBAT_TRIM_MASK 0xF8
-#define RF_LOWBAT_TRIM_1695 0x00
-#define RF_LOWBAT_TRIM_1764 0x01
-#define RF_LOWBAT_TRIM_1835 0x02 // Default
-#define RF_LOWBAT_TRIM_1905 0x03
-#define RF_LOWBAT_TRIM_1976 0x04
-#define RF_LOWBAT_TRIM_2045 0x05
-#define RF_LOWBAT_TRIM_2116 0x06
-#define RF_LOWBAT_TRIM_2185 0x07
-
-/*!
- * RegIrqFlags1
- */
-#define RF_IRQFLAGS1_MODEREADY 0x80
-
-#define RF_IRQFLAGS1_RXREADY 0x40
-
-#define RF_IRQFLAGS1_TXREADY 0x20
-
-#define RF_IRQFLAGS1_PLLLOCK 0x10
-
-#define RF_IRQFLAGS1_RSSI 0x08
-
-#define RF_IRQFLAGS1_TIMEOUT 0x04
-
-#define RF_IRQFLAGS1_PREAMBLEDETECT 0x02
-
-#define RF_IRQFLAGS1_SYNCADDRESSMATCH 0x01
-
-/*!
- * RegIrqFlags2
- */
-#define RF_IRQFLAGS2_FIFOFULL 0x80
-
-#define RF_IRQFLAGS2_FIFOEMPTY 0x40
-
-#define RF_IRQFLAGS2_FIFOLEVEL 0x20
-
-#define RF_IRQFLAGS2_FIFOOVERRUN 0x10
-
-#define RF_IRQFLAGS2_PACKETSENT 0x08
-
-#define RF_IRQFLAGS2_PAYLOADREADY 0x04
-
-#define RF_IRQFLAGS2_CRCOK 0x02
-
-#define RF_IRQFLAGS2_LOWBAT 0x01
-
-/*!
- * RegDioMapping1
- */
-#define RF_DIOMAPPING1_DIO0_MASK 0x3F
-#define RF_DIOMAPPING1_DIO0_00 0x00 // Default
-#define RF_DIOMAPPING1_DIO0_01 0x40
-#define RF_DIOMAPPING1_DIO0_10 0x80
-#define RF_DIOMAPPING1_DIO0_11 0xC0
-
-#define RF_DIOMAPPING1_DIO1_MASK 0xCF
-#define RF_DIOMAPPING1_DIO1_00 0x00 // Default
-#define RF_DIOMAPPING1_DIO1_01 0x10
-#define RF_DIOMAPPING1_DIO1_10 0x20
-#define RF_DIOMAPPING1_DIO1_11 0x30
-
-#define RF_DIOMAPPING1_DIO2_MASK 0xF3
-#define RF_DIOMAPPING1_DIO2_00 0x00 // Default
-#define RF_DIOMAPPING1_DIO2_01 0x04
-#define RF_DIOMAPPING1_DIO2_10 0x08
-#define RF_DIOMAPPING1_DIO2_11 0x0C
-
-#define RF_DIOMAPPING1_DIO3_MASK 0xFC
-#define RF_DIOMAPPING1_DIO3_00 0x00 // Default
-#define RF_DIOMAPPING1_DIO3_01 0x01
-#define RF_DIOMAPPING1_DIO3_10 0x02
-#define RF_DIOMAPPING1_DIO3_11 0x03
-
-/*!
- * RegDioMapping2
- */
-#define RF_DIOMAPPING2_DIO4_MASK 0x3F
-#define RF_DIOMAPPING2_DIO4_00 0x00 // Default
-#define RF_DIOMAPPING2_DIO4_01 0x40
-#define RF_DIOMAPPING2_DIO4_10 0x80
-#define RF_DIOMAPPING2_DIO4_11 0xC0
-
-#define RF_DIOMAPPING2_DIO5_MASK 0xCF
-#define RF_DIOMAPPING2_DIO5_00 0x00 // Default
-#define RF_DIOMAPPING2_DIO5_01 0x10
-#define RF_DIOMAPPING2_DIO5_10 0x20
-#define RF_DIOMAPPING2_DIO5_11 0x30
-
-#define RF_DIOMAPPING2_MAP_MASK 0xFE
-#define RF_DIOMAPPING2_MAP_PREAMBLEDETECT 0x01
-#define RF_DIOMAPPING2_MAP_RSSI 0x00 // Default
-
-/*!
- * RegVersion (Read Only)
- */
-
-/*!
- * RegPllHop
- */
-#define RF_PLLHOP_FASTHOP_MASK 0x7F
-#define RF_PLLHOP_FASTHOP_ON 0x80
-#define RF_PLLHOP_FASTHOP_OFF 0x00 // Default
-
-/*!
- * RegTcxo
- */
-#define RF_TCXO_TCXOINPUT_MASK 0xEF
-#define RF_TCXO_TCXOINPUT_ON 0x10
-#define RF_TCXO_TCXOINPUT_OFF 0x00 // Default
-
-/*!
- * RegPaDac
- */
-#define RF_PADAC_20DBM_MASK 0xF8
-#define RF_PADAC_20DBM_ON 0x07
-#define RF_PADAC_20DBM_OFF 0x04 // Default
-
-/*!
- * RegFormerTemp
- */
-
-/*!
- * RegBitrateFrac
- */
-#define RF_BITRATEFRAC_MASK 0xF0
-
-/*!
- * RegAgcRef
- */
-
-/*!
- * RegAgcThresh1
- */
-
-/*!
- * RegAgcThresh2
- */
-
-/*!
- * RegAgcThresh3
- */
-
-/*!
- * RegPll
- */
-#define RF_PLL_BANDWIDTH_MASK 0x3F
-#define RF_PLL_BANDWIDTH_75 0x00
-#define RF_PLL_BANDWIDTH_150 0x40
-#define RF_PLL_BANDWIDTH_225 0x80
-#define RF_PLL_BANDWIDTH_300 0xC0 // Default
-
-#endif // __SX1276_REGS_FSK_H__
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/560fa920/hw/drivers/lora/node/radio/sx1276/src/sx1276Regs-LoRa.h
----------------------------------------------------------------------
diff --git a/hw/drivers/lora/node/radio/sx1276/src/sx1276Regs-LoRa.h b/hw/drivers/lora/node/radio/sx1276/src/sx1276Regs-LoRa.h
deleted file mode 100644
index edce9f7..0000000
--- a/hw/drivers/lora/node/radio/sx1276/src/sx1276Regs-LoRa.h
+++ /dev/null
@@ -1,565 +0,0 @@
-/*
- / _____) _ | |
-( (____ _____ ____ _| |_ _____ ____| |__
- \____ \| ___ | (_ _) ___ |/ ___) _ \
- _____) ) ____| | | || |_| ____( (___| | | |
-(______/|_____)_|_|_| \__)_____)\____)_| |_|
- (C)2013 Semtech
-
-Description: SX1276 LoRa modem registers and bits definitions
-
-License: Revised BSD License, see LICENSE.TXT file include in the project
-
-Maintainer: Miguel Luis and Gregory Cristian
-*/
-#ifndef __SX1276_REGS_LORA_H__
-#define __SX1276_REGS_LORA_H__
-
-/*!
- * ============================================================================
- * SX1276 Internal registers Address
- * ============================================================================
- */
-#define REG_LR_FIFO 0x00
-// Common settings
-#define REG_LR_OPMODE 0x01
-#define REG_LR_FRFMSB 0x06
-#define REG_LR_FRFMID 0x07
-#define REG_LR_FRFLSB 0x08
-// Tx settings
-#define REG_LR_PACONFIG 0x09
-#define REG_LR_PARAMP 0x0A
-#define REG_LR_OCP 0x0B
-// Rx settings
-#define REG_LR_LNA 0x0C
-// LoRa registers
-#define REG_LR_FIFOADDRPTR 0x0D
-#define REG_LR_FIFOTXBASEADDR 0x0E
-#define REG_LR_FIFORXBASEADDR 0x0F
-#define REG_LR_FIFORXCURRENTADDR 0x10
-#define REG_LR_IRQFLAGSMASK 0x11
-#define REG_LR_IRQFLAGS 0x12
-#define REG_LR_RXNBBYTES 0x13
-#define REG_LR_RXHEADERCNTVALUEMSB 0x14
-#define REG_LR_RXHEADERCNTVALUELSB 0x15
-#define REG_LR_RXPACKETCNTVALUEMSB 0x16
-#define REG_LR_RXPACKETCNTVALUELSB 0x17
-#define REG_LR_MODEMSTAT 0x18
-#define REG_LR_PKTSNRVALUE 0x19
-#define REG_LR_PKTRSSIVALUE 0x1A
-#define REG_LR_RSSIVALUE 0x1B
-#define REG_LR_HOPCHANNEL 0x1C
-#define REG_LR_MODEMCONFIG1 0x1D
-#define REG_LR_MODEMCONFIG2 0x1E
-#define REG_LR_SYMBTIMEOUTLSB 0x1F
-#define REG_LR_PREAMBLEMSB 0x20
-#define REG_LR_PREAMBLELSB 0x21
-#define REG_LR_PAYLOADLENGTH 0x22
-#define REG_LR_PAYLOADMAXLENGTH 0x23
-#define REG_LR_HOPPERIOD 0x24
-#define REG_LR_FIFORXBYTEADDR 0x25
-#define REG_LR_MODEMCONFIG3 0x26
-#define REG_LR_FEIMSB 0x28
-#define REG_LR_FEIMID 0x29
-#define REG_LR_FEILSB 0x2A
-#define REG_LR_RSSIWIDEBAND 0x2C
-#define REG_LR_TEST2F 0x2F
-#define REG_LR_TEST30 0x30
-#define REG_LR_DETECTOPTIMIZE 0x31
-#define REG_LR_INVERTIQ 0x33
-#define REG_LR_TEST36 0x36
-#define REG_LR_DETECTIONTHRESHOLD 0x37
-#define REG_LR_SYNCWORD 0x39
-#define REG_LR_TEST3A 0x3A
-#define REG_LR_INVERTIQ2 0x3B
-
-// end of documented register in datasheet
-// I/O settings
-#define REG_LR_DIOMAPPING1 0x40
-#define REG_LR_DIOMAPPING2 0x41
-// Version
-#define REG_LR_VERSION 0x42
-// Additional settings
-#define REG_LR_PLLHOP 0x44
-#define REG_LR_TCXO 0x4B
-#define REG_LR_PADAC 0x4D
-#define REG_LR_FORMERTEMP 0x5B
-#define REG_LR_BITRATEFRAC 0x5D
-#define REG_LR_AGCREF 0x61
-#define REG_LR_AGCTHRESH1 0x62
-#define REG_LR_AGCTHRESH2 0x63
-#define REG_LR_AGCTHRESH3 0x64
-#define REG_LR_PLL 0x70
-
-/*!
- * ============================================================================
- * SX1276 LoRa bits control definition
- * ============================================================================
- */
-
-/*!
- * RegFifo
- */
-
-/*!
- * RegOpMode
- */
-#define RFLR_OPMODE_LONGRANGEMODE_MASK 0x7F
-#define RFLR_OPMODE_LONGRANGEMODE_OFF 0x00 // Default
-#define RFLR_OPMODE_LONGRANGEMODE_ON 0x80
-
-#define RFLR_OPMODE_ACCESSSHAREDREG_MASK 0xBF
-#define RFLR_OPMODE_ACCESSSHAREDREG_ENABLE 0x40
-#define RFLR_OPMODE_ACCESSSHAREDREG_DISABLE 0x00 // Default
-
-#define RFLR_OPMODE_FREQMODE_ACCESS_MASK 0xF7
-#define RFLR_OPMODE_FREQMODE_ACCESS_LF 0x08 // Default
-#define RFLR_OPMODE_FREQMODE_ACCESS_HF 0x00
-
-#define RFLR_OPMODE_MASK 0xF8
-#define RFLR_OPMODE_SLEEP 0x00
-#define RFLR_OPMODE_STANDBY 0x01 // Default
-#define RFLR_OPMODE_SYNTHESIZER_TX 0x02
-#define RFLR_OPMODE_TRANSMITTER 0x03
-#define RFLR_OPMODE_SYNTHESIZER_RX 0x04
-#define RFLR_OPMODE_RECEIVER 0x05
-// LoRa specific modes
-#define RFLR_OPMODE_RECEIVER_SINGLE 0x06
-#define RFLR_OPMODE_CAD 0x07
-
-/*!
- * RegFrf (MHz)
- */
-#define RFLR_FRFMSB_434_MHZ 0x6C // Default
-#define RFLR_FRFMID_434_MHZ 0x80 // Default
-#define RFLR_FRFLSB_434_MHZ 0x00 // Default
-
-/*!
- * RegPaConfig
- */
-#define RFLR_PACONFIG_PASELECT_MASK 0x7F
-#define RFLR_PACONFIG_PASELECT_PABOOST 0x80
-#define RFLR_PACONFIG_PASELECT_RFO 0x00 // Default
-
-#define RFLR_PACONFIG_MAX_POWER_MASK 0x8F
-
-#define RFLR_PACONFIG_OUTPUTPOWER_MASK 0xF0
-
-/*!
- * RegPaRamp
- */
-#define RFLR_PARAMP_TXBANDFORCE_MASK 0xEF
-#define RFLR_PARAMP_TXBANDFORCE_BAND_SEL 0x10
-#define RFLR_PARAMP_TXBANDFORCE_AUTO 0x00 // Default
-
-#define RFLR_PARAMP_MASK 0xF0
-#define RFLR_PARAMP_3400_US 0x00
-#define RFLR_PARAMP_2000_US 0x01
-#define RFLR_PARAMP_1000_US 0x02
-#define RFLR_PARAMP_0500_US 0x03
-#define RFLR_PARAMP_0250_US 0x04
-#define RFLR_PARAMP_0125_US 0x05
-#define RFLR_PARAMP_0100_US 0x06
-#define RFLR_PARAMP_0062_US 0x07
-#define RFLR_PARAMP_0050_US 0x08
-#define RFLR_PARAMP_0040_US 0x09 // Default
-#define RFLR_PARAMP_0031_US 0x0A
-#define RFLR_PARAMP_0025_US 0x0B
-#define RFLR_PARAMP_0020_US 0x0C
-#define RFLR_PARAMP_0015_US 0x0D
-#define RFLR_PARAMP_0012_US 0x0E
-#define RFLR_PARAMP_0010_US 0x0F
-
-/*!
- * RegOcp
- */
-#define RFLR_OCP_MASK 0xDF
-#define RFLR_OCP_ON 0x20 // Default
-#define RFLR_OCP_OFF 0x00
-
-#define RFLR_OCP_TRIM_MASK 0xE0
-#define RFLR_OCP_TRIM_045_MA 0x00
-#define RFLR_OCP_TRIM_050_MA 0x01
-#define RFLR_OCP_TRIM_055_MA 0x02
-#define RFLR_OCP_TRIM_060_MA 0x03
-#define RFLR_OCP_TRIM_065_MA 0x04
-#define RFLR_OCP_TRIM_070_MA 0x05
-#define RFLR_OCP_TRIM_075_MA 0x06
-#define RFLR_OCP_TRIM_080_MA 0x07
-#define RFLR_OCP_TRIM_085_MA 0x08
-#define RFLR_OCP_TRIM_090_MA 0x09
-#define RFLR_OCP_TRIM_095_MA 0x0A
-#define RFLR_OCP_TRIM_100_MA 0x0B // Default
-#define RFLR_OCP_TRIM_105_MA 0x0C
-#define RFLR_OCP_TRIM_110_MA 0x0D
-#define RFLR_OCP_TRIM_115_MA 0x0E
-#define RFLR_OCP_TRIM_120_MA 0x0F
-#define RFLR_OCP_TRIM_130_MA 0x10
-#define RFLR_OCP_TRIM_140_MA 0x11
-#define RFLR_OCP_TRIM_150_MA 0x12
-#define RFLR_OCP_TRIM_160_MA 0x13
-#define RFLR_OCP_TRIM_170_MA 0x14
-#define RFLR_OCP_TRIM_180_MA 0x15
-#define RFLR_OCP_TRIM_190_MA 0x16
-#define RFLR_OCP_TRIM_200_MA 0x17
-#define RFLR_OCP_TRIM_210_MA 0x18
-#define RFLR_OCP_TRIM_220_MA 0x19
-#define RFLR_OCP_TRIM_230_MA 0x1A
-#define RFLR_OCP_TRIM_240_MA 0x1B
-
-/*!
- * RegLna
- */
-#define RFLR_LNA_GAIN_MASK 0x1F
-#define RFLR_LNA_GAIN_G1 0x20 // Default
-#define RFLR_LNA_GAIN_G2 0x40
-#define RFLR_LNA_GAIN_G3 0x60
-#define RFLR_LNA_GAIN_G4 0x80
-#define RFLR_LNA_GAIN_G5 0xA0
-#define RFLR_LNA_GAIN_G6 0xC0
-
-#define RFLR_LNA_BOOST_LF_MASK 0xE7
-#define RFLR_LNA_BOOST_LF_DEFAULT 0x00 // Default
-
-#define RFLR_LNA_BOOST_HF_MASK 0xFC
-#define RFLR_LNA_BOOST_HF_OFF 0x00 // Default
-#define RFLR_LNA_BOOST_HF_ON 0x03
-
-/*!
- * RegFifoAddrPtr
- */
-#define RFLR_FIFOADDRPTR 0x00 // Default
-
-/*!
- * RegFifoTxBaseAddr
- */
-#define RFLR_FIFOTXBASEADDR 0x80 // Default
-
-/*!
- * RegFifoTxBaseAddr
- */
-#define RFLR_FIFORXBASEADDR 0x00 // Default
-
-/*!
- * RegFifoRxCurrentAddr (Read Only)
- */
-
-/*!
- * RegIrqFlagsMask
- */
-#define RFLR_IRQFLAGS_RXTIMEOUT_MASK 0x80
-#define RFLR_IRQFLAGS_RXDONE_MASK 0x40
-#define RFLR_IRQFLAGS_PAYLOADCRCERROR_MASK 0x20
-#define RFLR_IRQFLAGS_VALIDHEADER_MASK 0x10
-#define RFLR_IRQFLAGS_TXDONE_MASK 0x08
-#define RFLR_IRQFLAGS_CADDONE_MASK 0x04
-#define RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL_MASK 0x02
-#define RFLR_IRQFLAGS_CADDETECTED_MASK 0x01
-
-/*!
- * RegIrqFlags
- */
-#define RFLR_IRQFLAGS_RXTIMEOUT 0x80
-#define RFLR_IRQFLAGS_RXDONE 0x40
-#define RFLR_IRQFLAGS_PAYLOADCRCERROR 0x20
-#define RFLR_IRQFLAGS_VALIDHEADER 0x10
-#define RFLR_IRQFLAGS_TXDONE 0x08
-#define RFLR_IRQFLAGS_CADDONE 0x04
-#define RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL 0x02
-#define RFLR_IRQFLAGS_CADDETECTED 0x01
-
-/*!
- * RegFifoRxNbBytes (Read Only)
- */
-
-/*!
- * RegRxHeaderCntValueMsb (Read Only)
- */
-
-/*!
- * RegRxHeaderCntValueLsb (Read Only)
- */
-
-/*!
- * RegRxPacketCntValueMsb (Read Only)
- */
-
-/*!
- * RegRxPacketCntValueLsb (Read Only)
- */
-
-/*!
- * RegModemStat (Read Only)
- */
-#define RFLR_MODEMSTAT_RX_CR_MASK 0x1F
-#define RFLR_MODEMSTAT_MODEM_STATUS_MASK 0xE0
-
-/*!
- * RegPktSnrValue (Read Only)
- */
-
-/*!
- * RegPktRssiValue (Read Only)
- */
-
-/*!
- * RegRssiValue (Read Only)
- */
-
-/*!
- * RegHopChannel (Read Only)
- */
-#define RFLR_HOPCHANNEL_PLL_LOCK_TIMEOUT_MASK 0x7F
-#define RFLR_HOPCHANNEL_PLL_LOCK_FAIL 0x80
-#define RFLR_HOPCHANNEL_PLL_LOCK_SUCCEED 0x00 // Default
-
-#define RFLR_HOPCHANNEL_CRCONPAYLOAD_MASK 0xBF
-#define RFLR_HOPCHANNEL_CRCONPAYLOAD_ON 0x40
-#define RFLR_HOPCHANNEL_CRCONPAYLOAD_OFF 0x00 // Default
-
-#define RFLR_HOPCHANNEL_CHANNEL_MASK 0x3F
-
-/*!
- * RegModemConfig1
- */
-#define RFLR_MODEMCONFIG1_BW_MASK 0x0F
-#define RFLR_MODEMCONFIG1_BW_7_81_KHZ 0x00
-#define RFLR_MODEMCONFIG1_BW_10_41_KHZ 0x10
-#define RFLR_MODEMCONFIG1_BW_15_62_KHZ 0x20
-#define RFLR_MODEMCONFIG1_BW_20_83_KHZ 0x30
-#define RFLR_MODEMCONFIG1_BW_31_25_KHZ 0x40
-#define RFLR_MODEMCONFIG1_BW_41_66_KHZ 0x50
-#define RFLR_MODEMCONFIG1_BW_62_50_KHZ 0x60
-#define RFLR_MODEMCONFIG1_BW_125_KHZ 0x70 // Default
-#define RFLR_MODEMCONFIG1_BW_250_KHZ 0x80
-#define RFLR_MODEMCONFIG1_BW_500_KHZ 0x90
-
-#define RFLR_MODEMCONFIG1_CODINGRATE_MASK 0xF1
-#define RFLR_MODEMCONFIG1_CODINGRATE_4_5 0x02
-#define RFLR_MODEMCONFIG1_CODINGRATE_4_6 0x04 // Default
-#define RFLR_MODEMCONFIG1_CODINGRATE_4_7 0x06
-#define RFLR_MODEMCONFIG1_CODINGRATE_4_8 0x08
-
-#define RFLR_MODEMCONFIG1_IMPLICITHEADER_MASK 0xFE
-#define RFLR_MODEMCONFIG1_IMPLICITHEADER_ON 0x01
-#define RFLR_MODEMCONFIG1_IMPLICITHEADER_OFF 0x00 // Default
-
-/*!
- * RegModemConfig2
- */
-#define RFLR_MODEMCONFIG2_SF_MASK 0x0F
-#define RFLR_MODEMCONFIG2_SF_6 0x60
-#define RFLR_MODEMCONFIG2_SF_7 0x70 // Default
-#define RFLR_MODEMCONFIG2_SF_8 0x80
-#define RFLR_MODEMCONFIG2_SF_9 0x90
-#define RFLR_MODEMCONFIG2_SF_10 0xA0
-#define RFLR_MODEMCONFIG2_SF_11 0xB0
-#define RFLR_MODEMCONFIG2_SF_12 0xC0
-
-#define RFLR_MODEMCONFIG2_TXCONTINUOUSMODE_MASK 0xF7
-#define RFLR_MODEMCONFIG2_TXCONTINUOUSMODE_ON 0x08
-#define RFLR_MODEMCONFIG2_TXCONTINUOUSMODE_OFF 0x00
-
-#define RFLR_MODEMCONFIG2_RXPAYLOADCRC_MASK 0xFB
-#define RFLR_MODEMCONFIG2_RXPAYLOADCRC_ON 0x04
-#define RFLR_MODEMCONFIG2_RXPAYLOADCRC_OFF 0x00 // Default
-
-#define RFLR_MODEMCONFIG2_SYMBTIMEOUTMSB_MASK 0xFC
-#define RFLR_MODEMCONFIG2_SYMBTIMEOUTMSB 0x00 // Default
-
-/*!
- * RegSymbTimeoutLsb
- */
-#define RFLR_SYMBTIMEOUTLSB_SYMBTIMEOUT 0x64 // Default
-
-/*!
- * RegPreambleLengthMsb
- */
-#define RFLR_PREAMBLELENGTHMSB 0x00 // Default
-
-/*!
- * RegPreambleLengthLsb
- */
-#define RFLR_PREAMBLELENGTHLSB 0x08 // Default
-
-/*!
- * RegPayloadLength
- */
-#define RFLR_PAYLOADLENGTH 0x0E // Default
-
-/*!
- * RegPayloadMaxLength
- */
-#define RFLR_PAYLOADMAXLENGTH 0xFF // Default
-
-/*!
- * RegHopPeriod
- */
-#define RFLR_HOPPERIOD_FREQFOPPINGPERIOD 0x00 // Default
-
-/*!
- * RegFifoRxByteAddr (Read Only)
- */
-
-/*!
- * RegModemConfig3
- */
-#define RFLR_MODEMCONFIG3_LOWDATARATEOPTIMIZE_MASK 0xF7
-#define RFLR_MODEMCONFIG3_LOWDATARATEOPTIMIZE_ON 0x08
-#define RFLR_MODEMCONFIG3_LOWDATARATEOPTIMIZE_OFF 0x00 // Default
-
-#define RFLR_MODEMCONFIG3_AGCAUTO_MASK 0xFB
-#define RFLR_MODEMCONFIG3_AGCAUTO_ON 0x04 // Default
-#define RFLR_MODEMCONFIG3_AGCAUTO_OFF 0x00
-
-/*!
- * RegFeiMsb (Read Only)
- */
-
-/*!
- * RegFeiMid (Read Only)
- */
-
-/*!
- * RegFeiLsb (Read Only)
- */
-
-/*!
- * RegRssiWideband (Read Only)
- */
-
-/*!
- * RegDetectOptimize
- */
-#define RFLR_DETECTIONOPTIMIZE_MASK 0xF8
-#define RFLR_DETECTIONOPTIMIZE_SF7_TO_SF12 0x03 // Default
-#define RFLR_DETECTIONOPTIMIZE_SF6 0x05
-
-/*!
- * RegInvertIQ
- */
-#define RFLR_INVERTIQ_RX_MASK 0xBF
-#define RFLR_INVERTIQ_RX_OFF 0x00
-#define RFLR_INVERTIQ_RX_ON 0x40
-#define RFLR_INVERTIQ_TX_MASK 0xFE
-#define RFLR_INVERTIQ_TX_OFF 0x01
-#define RFLR_INVERTIQ_TX_ON 0x00
-
-/*!
- * RegDetectionThreshold
- */
-#define RFLR_DETECTIONTHRESH_SF7_TO_SF12 0x0A // Default
-#define RFLR_DETECTIONTHRESH_SF6 0x0C
-
-/*!
- * RegInvertIQ2
- */
-#define RFLR_INVERTIQ2_ON 0x19
-#define RFLR_INVERTIQ2_OFF 0x1D
-
-/*!
- * RegDioMapping1
- */
-#define RFLR_DIOMAPPING1_DIO0_MASK 0x3F
-#define RFLR_DIOMAPPING1_DIO0_00 0x00 // Default
-#define RFLR_DIOMAPPING1_DIO0_01 0x40
-#define RFLR_DIOMAPPING1_DIO0_10 0x80
-#define RFLR_DIOMAPPING1_DIO0_11 0xC0
-
-#define RFLR_DIOMAPPING1_DIO1_MASK 0xCF
-#define RFLR_DIOMAPPING1_DIO1_00 0x00 // Default
-#define RFLR_DIOMAPPING1_DIO1_01 0x10
-#define RFLR_DIOMAPPING1_DIO1_10 0x20
-#define RFLR_DIOMAPPING1_DIO1_11 0x30
-
-#define RFLR_DIOMAPPING1_DIO2_MASK 0xF3
-#define RFLR_DIOMAPPING1_DIO2_00 0x00 // Default
-#define RFLR_DIOMAPPING1_DIO2_01 0x04
-#define RFLR_DIOMAPPING1_DIO2_10 0x08
-#define RFLR_DIOMAPPING1_DIO2_11 0x0C
-
-#define RFLR_DIOMAPPING1_DIO3_MASK 0xFC
-#define RFLR_DIOMAPPING1_DIO3_00 0x00 // Default
-#define RFLR_DIOMAPPING1_DIO3_01 0x01
-#define RFLR_DIOMAPPING1_DIO3_10 0x02
-#define RFLR_DIOMAPPING1_DIO3_11 0x03
-
-/*!
- * RegDioMapping2
- */
-#define RFLR_DIOMAPPING2_DIO4_MASK 0x3F
-#define RFLR_DIOMAPPING2_DIO4_00 0x00 // Default
-#define RFLR_DIOMAPPING2_DIO4_01 0x40
-#define RFLR_DIOMAPPING2_DIO4_10 0x80
-#define RFLR_DIOMAPPING2_DIO4_11 0xC0
-
-#define RFLR_DIOMAPPING2_DIO5_MASK 0xCF
-#define RFLR_DIOMAPPING2_DIO5_00 0x00 // Default
-#define RFLR_DIOMAPPING2_DIO5_01 0x10
-#define RFLR_DIOMAPPING2_DIO5_10 0x20
-#define RFLR_DIOMAPPING2_DIO5_11 0x30
-
-#define RFLR_DIOMAPPING2_MAP_MASK 0xFE
-#define RFLR_DIOMAPPING2_MAP_PREAMBLEDETECT 0x01
-#define RFLR_DIOMAPPING2_MAP_RSSI 0x00 // Default
-
-/*!
- * RegVersion (Read Only)
- */
-
-/*!
- * RegPllHop
- */
-#define RFLR_PLLHOP_FASTHOP_MASK 0x7F
-#define RFLR_PLLHOP_FASTHOP_ON 0x80
-#define RFLR_PLLHOP_FASTHOP_OFF 0x00 // Default
-
-/*!
- * RegTcxo
- */
-#define RFLR_TCXO_TCXOINPUT_MASK 0xEF
-#define RFLR_TCXO_TCXOINPUT_ON 0x10
-#define RFLR_TCXO_TCXOINPUT_OFF 0x00 // Default
-
-/*!
- * RegPaDac
- */
-#define RFLR_PADAC_20DBM_MASK 0xF8
-#define RFLR_PADAC_20DBM_ON 0x07
-#define RFLR_PADAC_20DBM_OFF 0x04 // Default
-
-/*!
- * RegFormerTemp
- */
-
-/*!
- * RegBitrateFrac
- */
-#define RF_BITRATEFRAC_MASK 0xF0
-
-/*!
- * RegAgcRef
- */
-
-/*!
- * RegAgcThresh1
- */
-
-/*!
- * RegAgcThresh2
- */
-
-/*!
- * RegAgcThresh3
- */
-
-/*!
- * RegPll
- */
-#define RF_PLL_BANDWIDTH_MASK 0x3F
-#define RF_PLL_BANDWIDTH_75 0x00
-#define RF_PLL_BANDWIDTH_150 0x40
-#define RF_PLL_BANDWIDTH_225 0x80
-#define RF_PLL_BANDWIDTH_300 0xC0 // Default
-
-#endif // __SX1276_REGS_LORA_H__
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/560fa920/hw/drivers/lora/sx1276/LICENSE.txt
----------------------------------------------------------------------
diff --git a/hw/drivers/lora/sx1276/LICENSE.txt b/hw/drivers/lora/sx1276/LICENSE.txt
new file mode 100644
index 0000000..82695a7
--- /dev/null
+++ b/hw/drivers/lora/sx1276/LICENSE.txt
@@ -0,0 +1,25 @@
+--- Revised BSD License ---
+Copyright (c) 2013, SEMTECH S.A.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of the Semtech corporation nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL SEMTECH S.A. BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/560fa920/hw/drivers/lora/sx1276/include/radio/radio.h
----------------------------------------------------------------------
diff --git a/hw/drivers/lora/sx1276/include/radio/radio.h b/hw/drivers/lora/sx1276/include/radio/radio.h
new file mode 100644
index 0000000..6f23183
--- /dev/null
+++ b/hw/drivers/lora/sx1276/include/radio/radio.h
@@ -0,0 +1,33 @@
+/*
+ / _____) _ | |
+( (____ _____ ____ _| |_ _____ ____| |__
+ \____ \| ___ | (_ _) ___ |/ ___) _ \
+ _____) ) ____| | | || |_| ____( (___| | | |
+(______/|_____)_|_|_| \__)_____)\____)_| |_|
+ (C)2013 Semtech
+
+Description: Generic SX1276 driver implementation
+
+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_
+
+/*!
+ * 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 )
+
+#endif /* H_RADIO_RADIO */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/560fa920/hw/drivers/lora/sx1276/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/drivers/lora/sx1276/pkg.yml b/hw/drivers/lora/sx1276/pkg.yml
new file mode 100644
index 0000000..8f8d69e
--- /dev/null
+++ b/hw/drivers/lora/sx1276/pkg.yml
@@ -0,0 +1,32 @@
+#
+# 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.
+#
+
+pkg.name: hw/drivers/lora/sx1276
+pkg.description: LoRaMac-node radio driver for the SX1276 modem.
+pkg.author: "Semtech"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+ - lora
+
+pkg.deps:
+ - "@apache-mynewt-core/kernel/os"
+ - "@apache-mynewt-core/net/lora/node"
+
+pkg.apis:
+ - lora_node_driver
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/560fa920/hw/drivers/lora/sx1276/src/sx1276-board.c
----------------------------------------------------------------------
diff --git a/hw/drivers/lora/sx1276/src/sx1276-board.c b/hw/drivers/lora/sx1276/src/sx1276-board.c
new file mode 100644
index 0000000..a6bdf9b
--- /dev/null
+++ b/hw/drivers/lora/sx1276/src/sx1276-board.c
@@ -0,0 +1,179 @@
+/*
+ / _____) _ | |
+( (____ _____ ____ _| |_ _____ ____| |__
+ \____ \| ___ | (_ _) ___ |/ ___) _ \
+ _____) ) ____| | | || |_| ____( (___| | | |
+(______/|_____)_|_|_| \__)_____)\____)_| |_|
+ (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
+*/
+#include <assert.h>
+#include "hal/hal_spi.h"
+#include "bsp/bsp.h"
+#include "node/radio.h"
+#include "sx1276.h"
+#include "sx1276-board.h"
+
+/*!
+ * Flag used to set the RF switch control pins in low power mode when the radio is not active.
+ */
+static bool RadioIsActive = false;
+
+/*!
+ * Radio driver structure initialization
+ */
+const struct Radio_s Radio =
+{
+ .Init = SX1276Init,
+ .GetStatus = SX1276GetStatus,
+ .SetModem = SX1276SetModem,
+ .SetChannel = SX1276SetChannel,
+ .IsChannelFree = SX1276IsChannelFree,
+ .Random = SX1276Random,
+ .SetRxConfig = SX1276SetRxConfig,
+ .SetTxConfig = SX1276SetTxConfig,
+ .CheckRfFrequency = SX1276CheckRfFrequency,
+ .TimeOnAir = SX1276GetTimeOnAir,
+ .Send = SX1276Send,
+ .Sleep = SX1276SetSleep,
+ .Standby = SX1276SetStby,
+ .Rx = SX1276SetRx,
+ .StartCad = SX1276StartCad,
+ .Rssi = SX1276ReadRssi,
+ .Write = SX1276Write,
+ .Read = SX1276Read,
+ .WriteBuffer = SX1276WriteBuffer,
+ .ReadBuffer = SX1276ReadBuffer,
+ .SetMaxPayloadLength = SX1276SetMaxPayloadLength
+};
+
+void SX1276IoInit( void )
+{
+ struct hal_spi_settings spi_settings;
+ int rc;
+
+ rc = hal_gpio_init_out(SX1276_RXTX, 1);
+ assert(rc == 0);
+
+ rc = hal_gpio_init_out(RADIO_NSS, 1);
+ assert(rc == 0);
+
+ spi_settings.data_order = HAL_SPI_MSB_FIRST;
+ spi_settings.data_mode = HAL_SPI_MODE0;
+ spi_settings.baudrate = MYNEWT_VAL(SX1276_SPI_BAUDRATE);
+ spi_settings.word_size = HAL_SPI_WORD_SIZE_8BIT;
+
+ rc = hal_spi_config(RADIO_SPI_IDX, &spi_settings);
+ assert(rc == 0);
+
+ rc = hal_spi_enable(RADIO_SPI_IDX);
+ assert(rc == 0);
+}
+
+void SX1276IoIrqInit( DioIrqHandler **irqHandlers )
+{
+ int rc;
+
+ rc = hal_gpio_irq_init(SX1276_DIO0, irqHandlers[0], NULL,
+ HAL_GPIO_TRIG_RISING, HAL_GPIO_PULL_NONE);
+ assert(rc == 0);
+ hal_gpio_irq_enable(SX1276_DIO0);
+
+ rc = hal_gpio_irq_init(SX1276_DIO1, irqHandlers[1], NULL,
+ HAL_GPIO_TRIG_RISING, HAL_GPIO_PULL_NONE);
+ assert(rc == 0);
+ hal_gpio_irq_enable(SX1276_DIO1);
+
+ rc = hal_gpio_irq_init(SX1276_DIO2, irqHandlers[2], NULL,
+ HAL_GPIO_TRIG_RISING, HAL_GPIO_PULL_NONE);
+ assert(rc == 0);
+ hal_gpio_irq_enable(SX1276_DIO2);
+
+ rc = hal_gpio_irq_init(SX1276_DIO3, irqHandlers[3], NULL,
+ HAL_GPIO_TRIG_RISING, HAL_GPIO_PULL_NONE);
+ assert(rc == 0);
+ hal_gpio_irq_enable(SX1276_DIO3);
+
+ rc = hal_gpio_irq_init(SX1276_DIO4, irqHandlers[4], NULL,
+ HAL_GPIO_TRIG_RISING, HAL_GPIO_PULL_NONE);
+ assert(rc == 0);
+ hal_gpio_irq_enable(SX1276_DIO4);
+
+ rc = hal_gpio_irq_init(SX1276_DIO5, irqHandlers[5], NULL,
+ HAL_GPIO_TRIG_RISING, HAL_GPIO_PULL_NONE);
+ assert(rc == 0);
+ hal_gpio_irq_enable(SX1276_DIO5);
+}
+
+void SX1276IoDeInit( void )
+{
+ hal_gpio_irq_release(SX1276_DIO0);
+ hal_gpio_irq_release(SX1276_DIO1);
+ hal_gpio_irq_release(SX1276_DIO2);
+ hal_gpio_irq_release(SX1276_DIO3);
+ hal_gpio_irq_release(SX1276_DIO4);
+ hal_gpio_irq_release(SX1276_DIO5);
+}
+
+uint8_t SX1276GetPaSelect( uint32_t channel )
+{
+ if( channel < RF_MID_BAND_THRESH )
+ {
+ return RF_PACONFIG_PASELECT_PABOOST;
+ }
+ else
+ {
+ return RF_PACONFIG_PASELECT_RFO;
+ }
+}
+
+void SX1276SetAntSwLowPower( bool status )
+{
+ if( RadioIsActive != status )
+ {
+ RadioIsActive = status;
+
+ if( status == false )
+ {
+ SX1276AntSwInit( );
+ }
+ else
+ {
+ SX1276AntSwDeInit( );
+ }
+ }
+}
+
+void SX1276AntSwInit( void )
+{
+ // Consider turning off GPIO pins for low power. They are always on right
+ // now. GPIOTE library uses 0.5uA max when on, typical 0.1uA.
+}
+
+void SX1276AntSwDeInit( void )
+{
+ // Consider this for low power - ie turning off GPIO pins
+}
+
+void SX1276SetAntSw( uint8_t rxTx )
+{
+ if( rxTx != 0 ) // 1: TX, 0: RX
+ {
+ hal_gpio_write(SX1276_RXTX, 1);
+ }
+ else
+ {
+ hal_gpio_write(SX1276_RXTX, 0);
+ }
+}
+
+bool SX1276CheckRfFrequency( uint32_t frequency )
+{
+ // Implement check. Currently all frequencies are supported
+ return true;
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/560fa920/hw/drivers/lora/sx1276/src/sx1276-board.h
----------------------------------------------------------------------
diff --git a/hw/drivers/lora/sx1276/src/sx1276-board.h b/hw/drivers/lora/sx1276/src/sx1276-board.h
new file mode 100644
index 0000000..25f62ed
--- /dev/null
+++ b/hw/drivers/lora/sx1276/src/sx1276-board.h
@@ -0,0 +1,127 @@
+/*
+ / _____) _ | |
+( (____ _____ ____ _| |_ _____ ____| |__
+ \____ \| ___ | (_ _) ___ |/ ___) _ \
+ _____) ) ____| | | || |_| ____( (___| | | |
+(______/|_____)_|_|_| \__)_____)\____)_| |_|
+ (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(SPI_0_MASTER_SS_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 );
+
+/*!
+ * \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 );
+
+/*!
+ * \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 hal_pin_rxtx (int val);
+
+/*!
+ * Radio hardware and global parameters
+ */
+extern SX1276_t SX1276;
+
+#endif // __SX1276_ARCH_H__
[16/40] incubator-mynewt-core git commit: MYNEWT-741 Port of
LoRaMac-node library
Posted by ja...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9986f68c/net/lora/node/include/node/mac/LoRaMac-definitions.h
----------------------------------------------------------------------
diff --git a/net/lora/node/include/node/mac/LoRaMac-definitions.h b/net/lora/node/include/node/mac/LoRaMac-definitions.h
new file mode 100644
index 0000000..72b1f39
--- /dev/null
+++ b/net/lora/node/include/node/mac/LoRaMac-definitions.h
@@ -0,0 +1,610 @@
+/*
+ / _____) _ | |
+( (____ _____ ____ _| |_ _____ ____| |__
+ \____ \| ___ | (_ _) ___ |/ ___) _ \
+ _____) ) ____| | | || |_| ____( (___| | | |
+(______/|_____)_|_|_| \__)_____)\____)_| |_|
+ (C)2013 Semtech
+
+Description: LoRa MAC layer global definitions
+
+License: Revised BSD License, see LICENSE.TXT file include in the project
+
+Maintainer: Miguel Luis and Gregory Cristian
+*/
+#ifndef __LORAMAC_BOARD_H__
+#define __LORAMAC_BOARD_H__
+
+#include "lora_priv.h"
+
+/*!
+ * Returns individual channel mask
+ *
+ * \param[IN] channelIndex Channel index 1 based
+ * \retval channelMask
+ */
+#define LC( channelIndex ) ( uint16_t )( 1 << ( channelIndex - 1 ) )
+
+#if defined( USE_BAND_433 )
+
+/*!
+ * LoRaMac maximum number of channels
+ */
+#define LORA_MAX_NB_CHANNELS 16
+
+/*!
+ * Minimal datarate that can be used by the node
+ */
+#define LORAMAC_TX_MIN_DATARATE DR_0
+
+/*!
+ * Maximal datarate that can be used by the node
+ */
+#define LORAMAC_TX_MAX_DATARATE DR_7
+
+/*!
+ * Minimal datarate that can be used by the node
+ */
+#define LORAMAC_RX_MIN_DATARATE DR_0
+
+/*!
+ * Maximal datarate that can be used by the node
+ */
+#define LORAMAC_RX_MAX_DATARATE DR_7
+
+/*!
+ * Default datarate used by the node
+ */
+#define LORAMAC_DEFAULT_DATARATE DR_0
+
+/*!
+ * Minimal Rx1 receive datarate offset
+ */
+#define LORAMAC_MIN_RX1_DR_OFFSET 0
+
+/*!
+ * Maximal Rx1 receive datarate offset
+ */
+#define LORAMAC_MAX_RX1_DR_OFFSET 5
+
+/*!
+ * Minimal Tx output power that can be used by the node
+ */
+#define LORAMAC_MIN_TX_POWER TX_POWER_M5_DBM
+
+/*!
+ * Maximal Tx output power that can be used by the node
+ */
+#define LORAMAC_MAX_TX_POWER TX_POWER_10_DBM
+
+/*!
+ * Default Tx output power used by the node
+ */
+#define LORAMAC_DEFAULT_TX_POWER TX_POWER_10_DBM
+
+/*!
+ * LoRaMac TxPower definition
+ */
+#define TX_POWER_10_DBM 0
+#define TX_POWER_07_DBM 1
+#define TX_POWER_04_DBM 2
+#define TX_POWER_01_DBM 3
+#define TX_POWER_M2_DBM 4
+#define TX_POWER_M5_DBM 5
+
+/*!
+ * LoRaMac datarates definition
+ */
+#define DR_0 0 // SF12 - BW125
+#define DR_1 1 // SF11 - BW125
+#define DR_2 2 // SF10 - BW125
+#define DR_3 3 // SF9 - BW125
+#define DR_4 4 // SF8 - BW125
+#define DR_5 5 // SF7 - BW125
+#define DR_6 6 // SF7 - BW250
+#define DR_7 7 // FSK
+
+/*!
+ * Verification of default datarate
+ */
+#if ( LORAMAC_DEFAULT_DATARATE > DR_5 )
+#error "A default DR higher than DR_5 may lead to connectivity loss."
+#endif
+
+/*!
+ * Second reception window channel definition.
+ */
+// Channel = { Frequency [Hz], Datarate }
+#define RX_WND_2_CHANNEL { 434665000, DR_0 }
+
+/*!
+ * LoRaMac maximum number of bands
+ */
+#define LORA_MAX_NB_BANDS 1
+
+// Band = { DutyCycle, TxMaxPower, LastTxDoneTime, TimeOff }
+#define BAND0 { 100, TX_POWER_10_DBM, 0, 0 } // 1.0 %
+
+/*!
+ * LoRaMac default channels
+ */
+// Channel = { Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band }
+#define LC1 { 433175000, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 }
+#define LC2 { 433375000, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 }
+#define LC3 { 433575000, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 }
+
+/*!
+ * LoRaMac channels which are allowed for the join procedure
+ */
+#define JOIN_CHANNELS ( uint16_t )( LC( 1 ) | LC( 2 ) | LC( 3 ) )
+
+#elif defined( USE_BAND_470 )
+
+/*!
+ * LoRaMac maximum number of channels
+ */
+#define LORA_MAX_NB_CHANNELS 96
+
+/*!
+ * Minimal datarate that can be used by the node
+ */
+#define LORAMAC_TX_MIN_DATARATE DR_0
+
+/*!
+ * Maximal datarate that can be used by the node
+ */
+#define LORAMAC_TX_MAX_DATARATE DR_5
+
+/*!
+ * Minimal datarate that can be used by the node
+ */
+#define LORAMAC_RX_MIN_DATARATE DR_0
+
+/*!
+ * Maximal datarate that can be used by the node
+ */
+#define LORAMAC_RX_MAX_DATARATE DR_5
+
+/*!
+ * Default datarate used by the node
+ */
+#define LORAMAC_DEFAULT_DATARATE DR_0
+
+/*!
+ * Minimal Rx1 receive datarate offset
+ */
+#define LORAMAC_MIN_RX1_DR_OFFSET 0
+
+/*!
+ * Maximal Rx1 receive datarate offset
+ */
+#define LORAMAC_MAX_RX1_DR_OFFSET 3
+
+/*!
+ * Minimal Tx output power that can be used by the node
+ */
+#define LORAMAC_MIN_TX_POWER TX_POWER_2_DBM
+
+/*!
+ * Maximal Tx output power that can be used by the node
+ */
+#define LORAMAC_MAX_TX_POWER TX_POWER_17_DBM
+
+/*!
+ * Default Tx output power used by the node
+ */
+#define LORAMAC_DEFAULT_TX_POWER TX_POWER_14_DBM
+
+/*!
+ * LoRaMac TxPower definition
+ */
+#define TX_POWER_17_DBM 0
+#define TX_POWER_16_DBM 1
+#define TX_POWER_14_DBM 2
+#define TX_POWER_12_DBM 3
+#define TX_POWER_10_DBM 4
+#define TX_POWER_7_DBM 5
+#define TX_POWER_5_DBM 6
+#define TX_POWER_2_DBM 7
+
+
+/*!
+ * LoRaMac datarates definition
+ */
+#define DR_0 0 // SF12 - BW125 |
+#define DR_1 1 // SF11 - BW125 |
+#define DR_2 2 // SF10 - BW125 |
+#define DR_3 3 // SF9 - BW125 |
+#define DR_4 4 // SF8 - BW125 |
+#define DR_5 5 // SF7 - BW125 |
+
+/*!
+ * Second reception window channel definition.
+ */
+// Channel = { Frequency [Hz], Datarate }
+#define RX_WND_2_CHANNEL { 505300000, DR_0 }
+
+/*!
+ * LoRaMac maximum number of bands
+ */
+#define LORA_MAX_NB_BANDS 1
+
+// Band = { DutyCycle, TxMaxPower, LastTxDoneTime, TimeOff }
+#define BAND0 { 1, TX_POWER_17_DBM, 0, 0 } // 100.0 %
+
+#elif defined( USE_BAND_780 )
+
+/*!
+ * LoRaMac maximum number of channels
+ */
+#define LORA_MAX_NB_CHANNELS 16
+
+/*!
+ * Minimal datarate that can be used by the node
+ */
+#define LORAMAC_TX_MIN_DATARATE DR_0
+
+/*!
+ * Maximal datarate that can be used by the node
+ */
+#define LORAMAC_TX_MAX_DATARATE DR_7
+
+/*!
+ * Minimal datarate that can be used by the node
+ */
+#define LORAMAC_RX_MIN_DATARATE DR_0
+
+/*!
+ * Maximal datarate that can be used by the node
+ */
+#define LORAMAC_RX_MAX_DATARATE DR_7
+
+/*!
+ * Default datarate used by the node
+ */
+#define LORAMAC_DEFAULT_DATARATE DR_0
+
+/*!
+ * Minimal Rx1 receive datarate offset
+ */
+#define LORAMAC_MIN_RX1_DR_OFFSET 0
+
+/*!
+ * Maximal Rx1 receive datarate offset
+ */
+#define LORAMAC_MAX_RX1_DR_OFFSET 5
+
+/*!
+ * Minimal Tx output power that can be used by the node
+ */
+#define LORAMAC_MIN_TX_POWER TX_POWER_M5_DBM
+
+/*!
+ * Maximal Tx output power that can be used by the node
+ */
+#define LORAMAC_MAX_TX_POWER TX_POWER_10_DBM
+
+/*!
+ * Default Tx output power used by the node
+ */
+#define LORAMAC_DEFAULT_TX_POWER TX_POWER_10_DBM
+
+/*!
+ * LoRaMac TxPower definition
+ */
+#define TX_POWER_10_DBM 0
+#define TX_POWER_07_DBM 1
+#define TX_POWER_04_DBM 2
+#define TX_POWER_01_DBM 3
+#define TX_POWER_M2_DBM 4
+#define TX_POWER_M5_DBM 5
+
+/*!
+ * LoRaMac datarates definition
+ */
+#define DR_0 0 // SF12 - BW125
+#define DR_1 1 // SF11 - BW125
+#define DR_2 2 // SF10 - BW125
+#define DR_3 3 // SF9 - BW125
+#define DR_4 4 // SF8 - BW125
+#define DR_5 5 // SF7 - BW125
+#define DR_6 6 // SF7 - BW250
+#define DR_7 7 // FSK
+
+/*!
+ * Verification of default datarate
+ */
+#if ( LORAMAC_DEFAULT_DATARATE > DR_5 )
+#error "A default DR higher than DR_5 may lead to connectivity loss."
+#endif
+
+/*!
+ * Second reception window channel definition.
+ */
+// Channel = { Frequency [Hz], Datarate }
+#define RX_WND_2_CHANNEL { 786000000, DR_0 }
+
+/*!
+ * LoRaMac maximum number of bands
+ */
+#define LORA_MAX_NB_BANDS 1
+
+// Band = { DutyCycle, TxMaxPower, LastTxDoneTime, TimeOff }
+#define BAND0 { 100, TX_POWER_10_DBM, 0, 0 } // 1.0 %
+
+/*!
+ * LoRaMac default channels
+ */
+// Channel = { Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band }
+#define LC1 { 779500000, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 }
+#define LC2 { 779700000, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 }
+#define LC3 { 779900000, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 }
+
+/*!
+ * LoRaMac channels which are allowed for the join procedure
+ */
+#define JOIN_CHANNELS ( uint16_t )( LC( 1 ) | LC( 2 ) | LC( 3 ) )
+
+#elif defined( USE_BAND_868 )
+
+/*!
+ * LoRaMac maximum number of channels
+ */
+#define LORA_MAX_NB_CHANNELS 16
+
+/*!
+ * Minimal datarate that can be used by the node
+ */
+#define LORAMAC_TX_MIN_DATARATE DR_0
+
+/*!
+ * Maximal datarate that can be used by the node
+ */
+#define LORAMAC_TX_MAX_DATARATE DR_7
+
+/*!
+ * Minimal datarate that can be used by the node
+ */
+#define LORAMAC_RX_MIN_DATARATE DR_0
+
+/*!
+ * Maximal datarate that can be used by the node
+ */
+#define LORAMAC_RX_MAX_DATARATE DR_7
+
+/*!
+ * Default datarate used by the node
+ */
+#define LORAMAC_DEFAULT_DATARATE DR_0
+
+/*!
+ * Minimal Rx1 receive datarate offset
+ */
+#define LORAMAC_MIN_RX1_DR_OFFSET 0
+
+/*!
+ * Maximal Rx1 receive datarate offset
+ */
+#define LORAMAC_MAX_RX1_DR_OFFSET 5
+
+/*!
+ * Minimal Tx output power that can be used by the node
+ */
+#define LORAMAC_MIN_TX_POWER TX_POWER_02_DBM
+
+/*!
+ * Maximal Tx output power that can be used by the node
+ */
+#define LORAMAC_MAX_TX_POWER TX_POWER_20_DBM
+
+/*!
+ * Default Tx output power used by the node
+ */
+#define LORAMAC_DEFAULT_TX_POWER TX_POWER_14_DBM
+
+/*!
+ * LoRaMac TxPower definition
+ */
+#define TX_POWER_20_DBM 0
+#define TX_POWER_14_DBM 1
+#define TX_POWER_11_DBM 2
+#define TX_POWER_08_DBM 3
+#define TX_POWER_05_DBM 4
+#define TX_POWER_02_DBM 5
+
+/*!
+ * LoRaMac datarates definition
+ */
+#define DR_0 0 // SF12 - BW125
+#define DR_1 1 // SF11 - BW125
+#define DR_2 2 // SF10 - BW125
+#define DR_3 3 // SF9 - BW125
+#define DR_4 4 // SF8 - BW125
+#define DR_5 5 // SF7 - BW125
+#define DR_6 6 // SF7 - BW250
+#define DR_7 7 // FSK
+
+/*!
+ * Verification of default datarate
+ */
+#if ( LORAMAC_DEFAULT_DATARATE > DR_5 )
+#error "A default DR higher than DR_5 may lead to connectivity loss."
+#endif
+
+/*!
+ * Second reception window channel definition.
+ */
+// Channel = { Frequency [Hz], Datarate }
+#define RX_WND_2_CHANNEL { 869525000, DR_0 }
+
+/*!
+ * LoRaMac maximum number of bands
+ */
+#define LORA_MAX_NB_BANDS 5
+
+/*!
+ * LoRaMac EU868 default bands
+ */
+typedef enum
+{
+ BAND_G1_0,
+ BAND_G1_1,
+ BAND_G1_2,
+ BAND_G1_3,
+ BAND_G1_4,
+}BandId_t;
+
+// Band = { DutyCycle, TxMaxPower, LastTxDoneTime, TimeOff }
+#define BAND0 { 100 , TX_POWER_14_DBM, 0, 0 } // 1.0 %
+#define BAND1 { 100 , TX_POWER_14_DBM, 0, 0 } // 1.0 %
+#define BAND2 { 1000, TX_POWER_14_DBM, 0, 0 } // 0.1 %
+#define BAND3 { 10 , TX_POWER_14_DBM, 0, 0 } // 10.0 %
+#define BAND4 { 100 , TX_POWER_14_DBM, 0, 0 } // 1.0 %
+
+/*!
+ * LoRaMac default channels
+ */
+// Channel = { Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band }
+#define LC1 { 868100000, { ( ( DR_5 << 4 ) | DR_0 ) }, 1 }
+#define LC2 { 868300000, { ( ( DR_5 << 4 ) | DR_0 ) }, 1 }
+#define LC3 { 868500000, { ( ( DR_5 << 4 ) | DR_0 ) }, 1 }
+
+/*!
+ * LoRaMac channels which are allowed for the join procedure
+ */
+#define JOIN_CHANNELS ( uint16_t )( LC( 1 ) | LC( 2 ) | LC( 3 ) )
+
+#elif defined( USE_BAND_915 ) || defined( USE_BAND_915_HYBRID )
+
+/*!
+ * LoRaMac maximum number of channels
+ */
+#define LORA_MAX_NB_CHANNELS 72
+
+/*!
+ * Minimal datarate that can be used by the node
+ */
+#define LORAMAC_TX_MIN_DATARATE DR_0
+
+/*!
+ * Maximal datarate that can be used by the node
+ */
+#define LORAMAC_TX_MAX_DATARATE DR_4
+
+/*!
+ * Minimal datarate that can be used by the node
+ */
+#define LORAMAC_RX_MIN_DATARATE DR_8
+
+/*!
+ * Maximal datarate that can be used by the node
+ */
+#define LORAMAC_RX_MAX_DATARATE DR_13
+
+/*!
+ * Default datarate used by the node
+ */
+#define LORAMAC_DEFAULT_DATARATE DR_0
+
+/*!
+ * Minimal Rx1 receive datarate offset
+ */
+#define LORAMAC_MIN_RX1_DR_OFFSET 0
+
+/*!
+ * Maximal Rx1 receive datarate offset
+ */
+#define LORAMAC_MAX_RX1_DR_OFFSET 3
+
+/*!
+ * Minimal Tx output power that can be used by the node
+ */
+#define LORAMAC_MIN_TX_POWER TX_POWER_10_DBM
+
+/*!
+ * Maximal Tx output power that can be used by the node
+ */
+#define LORAMAC_MAX_TX_POWER TX_POWER_30_DBM
+
+/*!
+ * Default Tx output power used by the node
+ */
+#define LORAMAC_DEFAULT_TX_POWER TX_POWER_20_DBM
+
+/*!
+ * LoRaMac TxPower definition
+ */
+#define TX_POWER_30_DBM 0
+#define TX_POWER_28_DBM 1
+#define TX_POWER_26_DBM 2
+#define TX_POWER_24_DBM 3
+#define TX_POWER_22_DBM 4
+#define TX_POWER_20_DBM 5
+#define TX_POWER_18_DBM 6
+#define TX_POWER_16_DBM 7
+#define TX_POWER_14_DBM 8
+#define TX_POWER_12_DBM 9
+#define TX_POWER_10_DBM 10
+
+/*!
+ * LoRaMac datarates definition
+ */
+#define DR_0 0 // SF10 - BW125 |
+#define DR_1 1 // SF9 - BW125 |
+#define DR_2 2 // SF8 - BW125 +-> Up link
+#define DR_3 3 // SF7 - BW125 |
+#define DR_4 4 // SF8 - BW500 |
+#define DR_5 5 // RFU
+#define DR_6 6 // RFU
+#define DR_7 7 // RFU
+#define DR_8 8 // SF12 - BW500 |
+#define DR_9 9 // SF11 - BW500 |
+#define DR_10 10 // SF10 - BW500 |
+#define DR_11 11 // SF9 - BW500 |
+#define DR_12 12 // SF8 - BW500 +-> Down link
+#define DR_13 13 // SF7 - BW500 |
+#define DR_14 14 // RFU |
+#define DR_15 15 // RFU |
+
+/*!
+ * Second reception window channel definition.
+ */
+// Channel = { Frequency [Hz], Datarate }
+#define RX_WND_2_CHANNEL { 923300000, DR_8 }
+
+/*!
+ * LoRaMac maximum number of bands
+ */
+#define LORA_MAX_NB_BANDS 1
+
+// Band = { DutyCycle, TxMaxPower, LastTxDoneTime, TimeOff }
+#define BAND0 { 1, TX_POWER_20_DBM, 0, 0 } // 100.0 %
+
+/*!
+ * LoRaMac default channels
+ */
+// Channel = { Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band }
+/*
+ * US band channels are initialized using a loop in LoRaMacInit function
+ * \code
+ * // 125 kHz channels
+ * for( uint8_t i = 0; i < LORA_MAX_NB_CHANNELS - 8; i++ )
+ * {
+ * Channels[i].Frequency = 902.3e6 + i * 200e3;
+ * Channels[i].DrRange.Value = ( DR_3 << 4 ) | DR_0;
+ * Channels[i].Band = 0;
+ * }
+ * // 500 kHz channels
+ * for( uint8_t i = LORA_MAX_NB_CHANNELS - 8; i < LORA_MAX_NB_CHANNELS; i++ )
+ * {
+ * Channels[i].Frequency = 903.0e6 + ( i - ( LORA_MAX_NB_CHANNELS - 8 ) ) * 1.6e6;
+ * Channels[i].DrRange.Value = ( DR_4 << 4 ) | DR_4;
+ * Channels[i].Band = 0;
+ * }
+ * \endcode
+ */
+#else
+ #error "Please define a frequency band in the compiler options."
+#endif
+
+#endif // __LORAMAC_BOARD_H__
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9986f68c/net/lora/node/include/node/mac/LoRaMac.h
----------------------------------------------------------------------
diff --git a/net/lora/node/include/node/mac/LoRaMac.h b/net/lora/node/include/node/mac/LoRaMac.h
new file mode 100644
index 0000000..4613f8d
--- /dev/null
+++ b/net/lora/node/include/node/mac/LoRaMac.h
@@ -0,0 +1,1830 @@
+/*!
+ * \file LoRaMac.h
+ *
+ * \brief LoRa MAC layer implementation
+ *
+ * \copyright Revised BSD License, see section \ref LICENSE.
+ *
+ * \code
+ * ______ _
+ * / _____) _ | |
+ * ( (____ _____ ____ _| |_ _____ ____| |__
+ * \____ \| ___ | (_ _) ___ |/ ___) _ \
+ * _____) ) ____| | | || |_| ____( (___| | | |
+ * (______/|_____)_|_|_| \__)_____)\____)_| |_|
+ * (C)2013 Semtech
+ *
+ * ___ _____ _ ___ _ _____ ___ ___ ___ ___
+ * / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __|
+ * \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _|
+ * |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___|
+ * embedded.connectivity.solutions===============
+ *
+ * \endcode
+ *
+ * \author Miguel Luis ( Semtech )
+ *
+ * \author Gregory Cristian ( Semtech )
+ *
+ * \author Daniel Jäckle ( STACKFORCE )
+ *
+ * \defgroup LORAMAC LoRa MAC layer implementation
+ * This module specifies the API implementation of the LoRaMAC layer.
+ * This is a placeholder for a detailed description of the LoRaMac
+ * layer and the supported features.
+ * \{
+ *
+ * \example classA/LoRaMote/main.c
+ * LoRaWAN class A application example for the LoRaMote.
+ *
+ * \example classB/LoRaMote/main.c
+ * LoRaWAN class B application example for the LoRaMote.
+ *
+ * \example classC/LoRaMote/main.c
+ * LoRaWAN class C application example for the LoRaMote.
+ */
+#ifndef __LORAMAC_H__
+#define __LORAMAC_H__
+
+// Includes board dependent definitions such as channels frequencies
+#include "LoRaMac-definitions.h"
+#include "node/timer.h"
+
+
+/*!
+ * Beacon interval in ms
+ */
+#define BEACON_INTERVAL 128000
+
+/*!
+ * Class A&B receive delay 1 in ms
+ */
+#define RECEIVE_DELAY1 1000
+
+/*!
+ * Class A&B receive delay 2 in ms
+ */
+#define RECEIVE_DELAY2 2000
+
+/*!
+ * Join accept receive delay 1 in ms
+ */
+#define JOIN_ACCEPT_DELAY1 5000
+
+/*!
+ * Join accept receive delay 2 in ms
+ */
+#define JOIN_ACCEPT_DELAY2 6000
+
+/*!
+ * Class A&B maximum receive window delay in ms
+ */
+#define MAX_RX_WINDOW 3000
+
+/*!
+ * Maximum allowed gap for the FCNT field
+ */
+#define MAX_FCNT_GAP 16384
+
+/*!
+ * ADR acknowledgement counter limit
+ */
+#define ADR_ACK_LIMIT 64
+
+/*!
+ * Number of ADR acknowledgement requests before returning to default datarate
+ */
+#define ADR_ACK_DELAY 32
+
+/*!
+ * Number of seconds after the start of the second reception window without
+ * receiving an acknowledge.
+ * AckTimeout = \ref ACK_TIMEOUT + Random( -\ref ACK_TIMEOUT_RND, \ref ACK_TIMEOUT_RND )
+ */
+#define ACK_TIMEOUT 2000
+
+/*!
+ * Random number of seconds after the start of the second reception window without
+ * receiving an acknowledge
+ * AckTimeout = \ref ACK_TIMEOUT + Random( -\ref ACK_TIMEOUT_RND, \ref ACK_TIMEOUT_RND )
+ */
+#define ACK_TIMEOUT_RND 1000
+
+/*!
+ * Check the Mac layer state every MAC_STATE_CHECK_TIMEOUT in ms
+ */
+#define MAC_STATE_CHECK_TIMEOUT 1000
+
+/*!
+ * Maximum number of times the MAC layer tries to get an acknowledge.
+ */
+#define MAX_ACK_RETRIES 8
+
+/*!
+ * RSSI free threshold [dBm]
+ */
+#define RSSI_FREE_TH ( int8_t )( -90 )
+
+/*!
+ * Frame direction definition for up-link communications
+ */
+#define UP_LINK 0
+
+/*!
+ * Frame direction definition for down-link communications
+ */
+#define DOWN_LINK 1
+
+/*!
+ * Sets the length of the LoRaMAC footer field.
+ * Mainly indicates the MIC field length
+ */
+#define LORAMAC_MFR_LEN 4
+
+/*!
+ * LoRaWAN devices classes definition
+ */
+typedef enum eDeviceClass
+{
+ /*!
+ * LoRaWAN device class A
+ *
+ * LoRaWAN Specification V1.0.1, chapter 3ff
+ */
+ CLASS_A,
+ /*!
+ * LoRaWAN device class B
+ *
+ * LoRaWAN Specification V1.0.1, chapter 8ff
+ */
+ CLASS_B,
+ /*!
+ * LoRaWAN device class C
+ *
+ * LoRaWAN Specification V1.0.1, chapter 17ff
+ */
+ CLASS_C,
+}DeviceClass_t;
+
+/*!
+ * LoRaMAC channels parameters definition
+ */
+typedef union uDrRange
+{
+ /*!
+ * Byte-access to the bits
+ */
+ int8_t Value;
+ /*!
+ * Structure to store the minimum and the maximum datarate
+ */
+ struct sFields
+ {
+ /*!
+ * Minimum data rate
+ *
+ * EU868 - [DR_0, DR_1, DR_2, DR_3, DR_4, DR_5, DR_6, DR_7]
+ *
+ * US915 - [DR_0, DR_1, DR_2, DR_3, DR_4]
+ */
+ int8_t Min : 4;
+ /*!
+ * Maximum data rate
+ *
+ * EU868 - [DR_0, DR_1, DR_2, DR_3, DR_4, DR_5, DR_6, DR_7]
+ *
+ * US915 - [DR_0, DR_1, DR_2, DR_3, DR_4]
+ */
+ int8_t Max : 4;
+ }Fields;
+}DrRange_t;
+
+/*!
+ * LoRaMAC band parameters definition
+ */
+typedef struct sBand
+{
+ /*!
+ * Duty cycle
+ */
+ uint16_t DCycle;
+ /*!
+ * Maximum Tx power
+ */
+ int8_t TxMaxPower;
+ /*!
+ * Time stamp of the last Tx frame
+ */
+ uint32_t LastTxDoneTime;
+ /*!
+ * Holds the time where the device is off
+ */
+ uint32_t TimeOff;
+}Band_t;
+
+/*!
+ * LoRaMAC channel definition
+ */
+typedef struct sChannelParams
+{
+ /*!
+ * Frequency in Hz
+ */
+ uint32_t Frequency;
+ /*!
+ * Data rate definition
+ */
+ DrRange_t DrRange;
+ /*!
+ * Band index
+ */
+ uint8_t Band;
+}ChannelParams_t;
+
+/*!
+ * LoRaMAC receive window 2 channel parameters
+ */
+typedef struct sRx2ChannelParams
+{
+ /*!
+ * Frequency in Hz
+ */
+ uint32_t Frequency;
+ /*!
+ * Data rate
+ *
+ * EU868 - [DR_0, DR_1, DR_2, DR_3, DR_4, DR_5, DR_6, DR_7]
+ *
+ * US915 - [DR_8, DR_9, DR_10, DR_11, DR_12, DR_13]
+ */
+ uint8_t Datarate;
+}Rx2ChannelParams_t;
+
+/*!
+ * Global MAC layer parameters
+ */
+typedef struct sLoRaMacParams
+{
+ /*!
+ * Channels TX power
+ */
+ int8_t ChannelsTxPower;
+ /*!
+ * Channels data rate
+ */
+ int8_t ChannelsDatarate;
+ /*!
+ * LoRaMac maximum time a reception window stays open
+ */
+ uint32_t MaxRxWindow;
+ /*!
+ * Receive delay 1
+ */
+ uint32_t ReceiveDelay1;
+ /*!
+ * Receive delay 2
+ */
+ uint32_t ReceiveDelay2;
+ /*!
+ * Join accept delay 1
+ */
+ uint32_t JoinAcceptDelay1;
+ /*!
+ * Join accept delay 1
+ */
+ uint32_t JoinAcceptDelay2;
+ /*!
+ * Number of uplink messages repetitions [1:15] (unconfirmed messages only)
+ */
+ uint8_t ChannelsNbRep;
+ /*!
+ * Datarate offset between uplink and downlink on first window
+ */
+ uint8_t Rx1DrOffset;
+ /*!
+ * LoRaMAC 2nd reception window settings
+ */
+ Rx2ChannelParams_t Rx2Channel;
+ /*!
+ * Mask indicating which channels are enabled
+ */
+ uint16_t ChannelsMask[6];
+}LoRaMacParams_t;
+
+/*!
+ * LoRaMAC multicast channel parameter
+ */
+typedef struct sMulticastParams
+{
+ /*!
+ * Address
+ */
+ uint32_t Address;
+ /*!
+ * Network session key
+ */
+ uint8_t NwkSKey[16];
+ /*!
+ * Application session key
+ */
+ uint8_t AppSKey[16];
+ /*!
+ * Downlink counter
+ */
+ uint32_t DownLinkCounter;
+ /*!
+ * Reference pointer to the next multicast channel parameters in the list
+ */
+ struct sMulticastParams *Next;
+}MulticastParams_t;
+
+/*!
+ * LoRaMAC frame types
+ *
+ * LoRaWAN Specification V1.0.1, chapter 4.2.1, table 1
+ */
+typedef enum eLoRaMacFrameType
+{
+ /*!
+ * LoRaMAC join request frame
+ */
+ FRAME_TYPE_JOIN_REQ = 0x00,
+ /*!
+ * LoRaMAC join accept frame
+ */
+ FRAME_TYPE_JOIN_ACCEPT = 0x01,
+ /*!
+ * LoRaMAC unconfirmed up-link frame
+ */
+ FRAME_TYPE_DATA_UNCONFIRMED_UP = 0x02,
+ /*!
+ * LoRaMAC unconfirmed down-link frame
+ */
+ FRAME_TYPE_DATA_UNCONFIRMED_DOWN = 0x03,
+ /*!
+ * LoRaMAC confirmed up-link frame
+ */
+ FRAME_TYPE_DATA_CONFIRMED_UP = 0x04,
+ /*!
+ * LoRaMAC confirmed down-link frame
+ */
+ FRAME_TYPE_DATA_CONFIRMED_DOWN = 0x05,
+ /*!
+ * LoRaMAC RFU frame
+ */
+ FRAME_TYPE_RFU = 0x06,
+ /*!
+ * LoRaMAC proprietary frame
+ */
+ FRAME_TYPE_PROPRIETARY = 0x07,
+}LoRaMacFrameType_t;
+
+/*!
+ * LoRaMAC mote MAC commands
+ *
+ * LoRaWAN Specification V1.0.1, chapter 5, table 4
+ */
+typedef enum eLoRaMacMoteCmd
+{
+ /*!
+ * LinkCheckReq
+ */
+ MOTE_MAC_LINK_CHECK_REQ = 0x02,
+ /*!
+ * LinkADRAns
+ */
+ MOTE_MAC_LINK_ADR_ANS = 0x03,
+ /*!
+ * DutyCycleAns
+ */
+ MOTE_MAC_DUTY_CYCLE_ANS = 0x04,
+ /*!
+ * RXParamSetupAns
+ */
+ MOTE_MAC_RX_PARAM_SETUP_ANS = 0x05,
+ /*!
+ * DevStatusAns
+ */
+ MOTE_MAC_DEV_STATUS_ANS = 0x06,
+ /*!
+ * NewChannelAns
+ */
+ MOTE_MAC_NEW_CHANNEL_ANS = 0x07,
+ /*!
+ * RXTimingSetupAns
+ */
+ MOTE_MAC_RX_TIMING_SETUP_ANS = 0x08,
+}LoRaMacMoteCmd_t;
+
+/*!
+ * LoRaMAC server MAC commands
+ *
+ * LoRaWAN Specification V1.0.1 chapter 5, table 4
+ */
+typedef enum eLoRaMacSrvCmd
+{
+ /*!
+ * LinkCheckAns
+ */
+ SRV_MAC_LINK_CHECK_ANS = 0x02,
+ /*!
+ * LinkADRReq
+ */
+ SRV_MAC_LINK_ADR_REQ = 0x03,
+ /*!
+ * DutyCycleReq
+ */
+ SRV_MAC_DUTY_CYCLE_REQ = 0x04,
+ /*!
+ * RXParamSetupReq
+ */
+ SRV_MAC_RX_PARAM_SETUP_REQ = 0x05,
+ /*!
+ * DevStatusReq
+ */
+ SRV_MAC_DEV_STATUS_REQ = 0x06,
+ /*!
+ * NewChannelReq
+ */
+ SRV_MAC_NEW_CHANNEL_REQ = 0x07,
+ /*!
+ * RXTimingSetupReq
+ */
+ SRV_MAC_RX_TIMING_SETUP_REQ = 0x08,
+}LoRaMacSrvCmd_t;
+
+/*!
+ * LoRaMAC Battery level indicator
+ */
+typedef enum eLoRaMacBatteryLevel
+{
+ /*!
+ * External power source
+ */
+ BAT_LEVEL_EXT_SRC = 0x00,
+ /*!
+ * Battery level empty
+ */
+ BAT_LEVEL_EMPTY = 0x01,
+ /*!
+ * Battery level full
+ */
+ BAT_LEVEL_FULL = 0xFE,
+ /*!
+ * Battery level - no measurement available
+ */
+ BAT_LEVEL_NO_MEASURE = 0xFF,
+}LoRaMacBatteryLevel_t;
+
+/*!
+ * LoRaMAC header field definition (MHDR field)
+ *
+ * LoRaWAN Specification V1.0.1, chapter 4.2
+ */
+typedef union uLoRaMacHeader
+{
+ /*!
+ * Byte-access to the bits
+ */
+ uint8_t Value;
+ /*!
+ * Structure containing single access to header bits
+ */
+ struct sHdrBits
+ {
+ /*!
+ * Major version
+ */
+ uint8_t Major : 2;
+ /*!
+ * RFU
+ */
+ uint8_t RFU : 3;
+ /*!
+ * Message type
+ */
+ uint8_t MType : 3;
+ }Bits;
+}LoRaMacHeader_t;
+
+/*!
+ * LoRaMAC frame control field definition (FCtrl)
+ *
+ * LoRaWAN Specification V1.0.1, chapter 4.3.1
+ */
+typedef union uLoRaMacFrameCtrl
+{
+ /*!
+ * Byte-access to the bits
+ */
+ uint8_t Value;
+ /*!
+ * Structure containing single access to bits
+ */
+ struct sCtrlBits
+ {
+ /*!
+ * Frame options length
+ */
+ uint8_t FOptsLen : 4;
+ /*!
+ * Frame pending bit
+ */
+ uint8_t FPending : 1;
+ /*!
+ * Message acknowledge bit
+ */
+ uint8_t Ack : 1;
+ /*!
+ * ADR acknowledgment request bit
+ */
+ uint8_t AdrAckReq : 1;
+ /*!
+ * ADR control in frame header
+ */
+ uint8_t Adr : 1;
+ }Bits;
+}LoRaMacFrameCtrl_t;
+
+/*!
+ * Enumeration containing the status of the operation of a MAC service
+ */
+typedef enum eLoRaMacEventInfoStatus
+{
+ /*!
+ * Service performed successfully
+ */
+ LORAMAC_EVENT_INFO_STATUS_OK = 0,
+ /*!
+ * An error occurred during the execution of the service
+ */
+ LORAMAC_EVENT_INFO_STATUS_ERROR,
+ /*!
+ * A Tx timeout occurred
+ */
+ LORAMAC_EVENT_INFO_STATUS_TX_TIMEOUT,
+ /*!
+ * An Rx timeout occurred on receive window 2
+ */
+ LORAMAC_EVENT_INFO_STATUS_RX2_TIMEOUT,
+ /*!
+ * An Rx error occurred on receive window 2
+ */
+ LORAMAC_EVENT_INFO_STATUS_RX2_ERROR,
+ /*!
+ * An error occurred in the join procedure
+ */
+ LORAMAC_EVENT_INFO_STATUS_JOIN_FAIL,
+ /*!
+ * A frame with an invalid downlink counter was received. The
+ * downlink counter of the frame was equal to the local copy
+ * of the downlink counter of the node.
+ */
+ LORAMAC_EVENT_INFO_STATUS_DOWNLINK_REPEATED,
+ /*!
+ * The MAC could not retransmit a frame since the MAC decreased the datarate. The
+ * payload size is not applicable for the datarate.
+ */
+ LORAMAC_EVENT_INFO_STATUS_TX_DR_PAYLOAD_SIZE_ERROR,
+ /*!
+ * The node has lost MAX_FCNT_GAP or more frames.
+ */
+ LORAMAC_EVENT_INFO_STATUS_DOWNLINK_TOO_MANY_FRAMES_LOSS,
+ /*!
+ * An address error occurred
+ */
+ LORAMAC_EVENT_INFO_STATUS_ADDRESS_FAIL,
+ /*!
+ * message integrity check failure
+ */
+ LORAMAC_EVENT_INFO_STATUS_MIC_FAIL,
+}LoRaMacEventInfoStatus_t;
+
+/*!
+ * LoRaMac tx/rx operation state
+ */
+typedef union eLoRaMacFlags_t
+{
+ /*!
+ * Byte-access to the bits
+ */
+ uint8_t Value;
+ /*!
+ * Structure containing single access to bits
+ */
+ struct sMacFlagBits
+ {
+ /*!
+ * MCPS-Req pending
+ */
+ uint8_t McpsReq : 1;
+ /*!
+ * MCPS-Ind pending
+ */
+ uint8_t McpsInd : 1;
+ /*!
+ * MLME-Req pending
+ */
+ uint8_t MlmeReq : 1;
+ /*!
+ * MAC cycle done
+ */
+ uint8_t MacDone : 1;
+ }Bits;
+}LoRaMacFlags_t;
+
+/*!
+ *
+ * \brief LoRaMAC data services
+ *
+ * \details The following table list the primitives which are supported by the
+ * specific MAC data service:
+ *
+ * Name | Request | Indication | Response | Confirm
+ * --------------------- | :-----: | :--------: | :------: | :-----:
+ * \ref MCPS_UNCONFIRMED | YES | YES | NO | YES
+ * \ref MCPS_CONFIRMED | YES | YES | NO | YES
+ * \ref MCPS_MULTICAST | NO | YES | NO | NO
+ * \ref MCPS_PROPRIETARY | YES | YES | NO | YES
+ *
+ * The following table provides links to the function implementations of the
+ * related MCPS primitives:
+ *
+ * Primitive | Function
+ * ---------------- | :---------------------:
+ * MCPS-Request | \ref LoRaMacMlmeRequest
+ * MCPS-Confirm | MacMcpsConfirm in \ref LoRaMacPrimitives_t
+ * MCPS-Indication | MacMcpsIndication in \ref LoRaMacPrimitives_t
+ */
+typedef enum eMcps
+{
+ /*!
+ * Unconfirmed LoRaMAC frame
+ */
+ MCPS_UNCONFIRMED,
+ /*!
+ * Confirmed LoRaMAC frame
+ */
+ MCPS_CONFIRMED,
+ /*!
+ * Multicast LoRaMAC frame
+ */
+ MCPS_MULTICAST,
+ /*!
+ * Proprietary frame
+ */
+ MCPS_PROPRIETARY,
+}Mcps_t;
+
+/*!
+ * LoRaMAC MCPS-Request for an unconfirmed frame
+ */
+typedef struct sMcpsReqUnconfirmed
+{
+ /*!
+ * Frame port field. Must be set if the payload is not empty. Use the
+ * application specific frame port values: [1...223]
+ *
+ * LoRaWAN Specification V1.0.1, chapter 4.3.2
+ */
+ uint8_t fPort;
+ /*!
+ * Pointer to the buffer of the frame payload
+ */
+ void *fBuffer;
+ /*!
+ * Size of the frame payload
+ */
+ uint16_t fBufferSize;
+ /*!
+ * Uplink datarate, if ADR is off
+ */
+ int8_t Datarate;
+}McpsReqUnconfirmed_t;
+
+/*!
+ * LoRaMAC MCPS-Request for a confirmed frame
+ */
+typedef struct sMcpsReqConfirmed
+{
+ /*!
+ * Frame port field. Must be set if the payload is not empty. Use the
+ * application specific frame port values: [1...223]
+ *
+ * LoRaWAN Specification V1.0.1, chapter 4.3.2
+ */
+ uint8_t fPort;
+ /*!
+ * Pointer to the buffer of the frame payload
+ */
+ void *fBuffer;
+ /*!
+ * Size of the frame payload
+ */
+ uint16_t fBufferSize;
+ /*!
+ * Uplink datarate, if ADR is off
+ */
+ int8_t Datarate;
+ /*!
+ * Number of trials to transmit the frame, if the LoRaMAC layer did not
+ * receive an acknowledgment. The MAC performs a datarate adaptation,
+ * according to the LoRaWAN Specification V1.0.1, chapter 19.4, according
+ * to the following table:
+ *
+ * Transmission nb | Data Rate
+ * ----------------|-----------
+ * 1 (first) | DR
+ * 2 | DR
+ * 3 | max(DR-1,0)
+ * 4 | max(DR-1,0)
+ * 5 | max(DR-2,0)
+ * 6 | max(DR-2,0)
+ * 7 | max(DR-3,0)
+ * 8 | max(DR-3,0)
+ *
+ * Note, that if NbTrials is set to 1 or 2, the MAC will not decrease
+ * the datarate, in case the LoRaMAC layer did not receive an acknowledgment
+ */
+ uint8_t NbTrials;
+}McpsReqConfirmed_t;
+
+/*!
+ * LoRaMAC MCPS-Request for a proprietary frame
+ */
+typedef struct sMcpsReqProprietary
+{
+ /*!
+ * Pointer to the buffer of the frame payload
+ */
+ void *fBuffer;
+ /*!
+ * Size of the frame payload
+ */
+ uint16_t fBufferSize;
+ /*!
+ * Uplink datarate, if ADR is off
+ */
+ int8_t Datarate;
+}McpsReqProprietary_t;
+
+/*!
+ * LoRaMAC MCPS-Request structure
+ */
+typedef struct sMcpsReq
+{
+ /*!
+ * MCPS-Request type
+ */
+ Mcps_t Type;
+
+ /*!
+ * MCPS-Request parameters
+ */
+ union uMcpsParam
+ {
+ /*!
+ * MCPS-Request parameters for an unconfirmed frame
+ */
+ McpsReqUnconfirmed_t Unconfirmed;
+ /*!
+ * MCPS-Request parameters for a confirmed frame
+ */
+ McpsReqConfirmed_t Confirmed;
+ /*!
+ * MCPS-Request parameters for a proprietary frame
+ */
+ McpsReqProprietary_t Proprietary;
+ }Req;
+}McpsReq_t;
+
+/*!
+ * LoRaMAC MCPS-Confirm
+ */
+typedef struct sMcpsConfirm
+{
+ /*!
+ * Holds the previously performed MCPS-Request
+ */
+ Mcps_t McpsRequest;
+ /*!
+ * Status of the operation
+ */
+ LoRaMacEventInfoStatus_t Status;
+ /*!
+ * Uplink datarate
+ */
+ uint8_t Datarate;
+ /*!
+ * Transmission power
+ */
+ int8_t TxPower;
+ /*!
+ * Set if an acknowledgement was received
+ */
+ bool AckReceived;
+ /*!
+ * Provides the number of retransmissions
+ */
+ uint8_t NbRetries;
+ /*!
+ * The transmission time on air of the frame
+ */
+ uint32_t TxTimeOnAir;
+ /*!
+ * The uplink counter value related to the frame
+ */
+ uint32_t UpLinkCounter;
+ /*!
+ * The uplink frequency related to the frame
+ */
+ uint32_t UpLinkFrequency;
+}McpsConfirm_t;
+
+/*!
+ * LoRaMAC MCPS-Indication primitive
+ */
+typedef struct sMcpsIndication
+{
+ /*!
+ * MCPS-Indication type
+ */
+ Mcps_t McpsIndication;
+ /*!
+ * Status of the operation
+ */
+ LoRaMacEventInfoStatus_t Status;
+ /*!
+ * Multicast
+ */
+ uint8_t Multicast;
+ /*!
+ * Application port
+ */
+ uint8_t Port;
+ /*!
+ * Downlink datarate
+ */
+ uint8_t RxDatarate;
+ /*!
+ * Frame pending status
+ */
+ uint8_t FramePending;
+ /*!
+ * Pointer to the received data stream
+ */
+ uint8_t *Buffer;
+ /*!
+ * Size of the received data stream
+ */
+ uint8_t BufferSize;
+ /*!
+ * Indicates, if data is available
+ */
+ bool RxData;
+ /*!
+ * Rssi of the received packet
+ */
+ int16_t Rssi;
+ /*!
+ * Snr of the received packet
+ */
+ uint8_t Snr;
+ /*!
+ * Receive window
+ *
+ * [0: Rx window 1, 1: Rx window 2]
+ */
+ uint8_t RxSlot;
+ /*!
+ * Set if an acknowledgement was received
+ */
+ bool AckReceived;
+ /*!
+ * The downlink counter value for the received frame
+ */
+ uint32_t DownLinkCounter;
+}McpsIndication_t;
+
+/*!
+ * \brief LoRaMAC management services
+ *
+ * \details The following table list the primitives which are supported by the
+ * specific MAC management service:
+ *
+ * Name | Request | Indication | Response | Confirm
+ * --------------------- | :-----: | :--------: | :------: | :-----:
+ * \ref MLME_JOIN | YES | NO | NO | YES
+ * \ref MLME_LINK_CHECK | YES | NO | NO | YES
+ * \ref MLME_TXCW | YES | NO | NO | YES
+ *
+ * The following table provides links to the function implementations of the
+ * related MLME primitives.
+ *
+ * Primitive | Function
+ * ---------------- | :---------------------:
+ * MLME-Request | \ref LoRaMacMlmeRequest
+ * MLME-Confirm | MacMlmeConfirm in \ref LoRaMacPrimitives_t
+ */
+typedef enum eMlme
+{
+ /*!
+ * Initiates the Over-the-Air activation
+ *
+ * LoRaWAN Specification V1.0.1, chapter 6.2
+ */
+ MLME_JOIN,
+ /*!
+ * LinkCheckReq - Connectivity validation
+ *
+ * LoRaWAN Specification V1.0.1, chapter 5, table 4
+ */
+ MLME_LINK_CHECK,
+ /*!
+ * Sets Tx continuous wave mode
+ *
+ * LoRaWAN end-device certification
+ */
+ MLME_TXCW,
+}Mlme_t;
+
+/*!
+ * LoRaMAC MLME-Request for the join service
+ */
+typedef struct sMlmeReqJoin
+{
+ /*!
+ * Globally unique end-device identifier
+ *
+ * LoRaWAN Specification V1.0.1, chapter 6.2.1
+ */
+ uint8_t *DevEui;
+ /*!
+ * Application identifier
+ *
+ * LoRaWAN Specification V1.0.1, chapter 6.1.2
+ */
+ uint8_t *AppEui;
+ /*!
+ * AES-128 application key
+ *
+ * LoRaWAN Specification V1.0.1, chapter 6.2.2
+ */
+ uint8_t *AppKey;
+ /*!
+ * Number of trials for the join request.
+ */
+ uint8_t NbTrials;
+}MlmeReqJoin_t;
+
+/*!
+ * LoRaMAC MLME-Request for Tx continuous wave mode
+ */
+typedef struct sMlmeReqTxCw
+{
+ /*!
+ * Time in seconds while the radio is kept in continuous wave mode
+ */
+ uint16_t Timeout;
+}MlmeReqTxCw_t;
+
+/*!
+ * LoRaMAC MLME-Request structure
+ */
+typedef struct sMlmeReq
+{
+ /*!
+ * MLME-Request type
+ */
+ Mlme_t Type;
+
+ /*!
+ * MLME-Request parameters
+ */
+ union uMlmeParam
+ {
+ /*!
+ * MLME-Request parameters for a join request
+ */
+ MlmeReqJoin_t Join;
+ /*!
+ * MLME-Request parameters for Tx continuous mode request
+ */
+ MlmeReqTxCw_t TxCw;
+ }Req;
+}MlmeReq_t;
+
+/*!
+ * LoRaMAC MLME-Confirm primitive
+ */
+typedef struct sMlmeConfirm
+{
+ /*!
+ * Holds the previously performed MLME-Request
+ */
+ Mlme_t MlmeRequest;
+ /*!
+ * Status of the operation
+ */
+ LoRaMacEventInfoStatus_t Status;
+ /*!
+ * The transmission time on air of the frame
+ */
+ uint32_t TxTimeOnAir;
+ /*!
+ * Demodulation margin. Contains the link margin [dB] of the last
+ * successfully received LinkCheckReq
+ */
+ uint8_t DemodMargin;
+ /*!
+ * Number of gateways which received the last LinkCheckReq
+ */
+ uint8_t NbGateways;
+ /*!
+ * Provides the number of retransmissions
+ */
+ uint8_t NbRetries;
+}MlmeConfirm_t;
+
+/*!
+ * LoRa Mac Information Base (MIB)
+ *
+ * The following table lists the MIB parameters and the related attributes:
+ *
+ * Attribute | Get | Set
+ * --------------------------------- | :-: | :-:
+ * \ref MIB_DEVICE_CLASS | YES | YES
+ * \ref MIB_NETWORK_JOINED | YES | YES
+ * \ref MIB_ADR | YES | YES
+ * \ref MIB_NET_ID | YES | YES
+ * \ref MIB_DEV_ADDR | YES | YES
+ * \ref MIB_NWK_SKEY | YES | YES
+ * \ref MIB_APP_SKEY | YES | YES
+ * \ref MIB_PUBLIC_NETWORK | YES | YES
+ * \ref MIB_REPEATER_SUPPORT | YES | YES
+ * \ref MIB_CHANNELS | YES | NO
+ * \ref MIB_RX2_CHANNEL | YES | YES
+ * \ref MIB_CHANNELS_MASK | YES | YES
+ * \ref MIB_CHANNELS_DEFAULT_MASK | YES | YES
+ * \ref MIB_CHANNELS_NB_REP | YES | YES
+ * \ref MIB_MAX_RX_WINDOW_DURATION | YES | YES
+ * \ref MIB_RECEIVE_DELAY_1 | YES | YES
+ * \ref MIB_RECEIVE_DELAY_2 | YES | YES
+ * \ref MIB_JOIN_ACCEPT_DELAY_1 | YES | YES
+ * \ref MIB_JOIN_ACCEPT_DELAY_2 | YES | YES
+ * \ref MIB_CHANNELS_DATARATE | YES | YES
+ * \ref MIB_CHANNELS_DEFAULT_DATARATE| YES | YES
+ * \ref MIB_CHANNELS_TX_POWER | YES | YES
+ * \ref MIB_CHANNELS_DEFAULT_TX_POWER| YES | YES
+ * \ref MIB_UPLINK_COUNTER | YES | YES
+ * \ref MIB_DOWNLINK_COUNTER | YES | YES
+ * \ref MIB_MULTICAST_CHANNEL | YES | NO
+ *
+ * The following table provides links to the function implementations of the
+ * related MIB primitives:
+ *
+ * Primitive | Function
+ * ---------------- | :---------------------:
+ * MIB-Set | \ref LoRaMacMibSetRequestConfirm
+ * MIB-Get | \ref LoRaMacMibGetRequestConfirm
+ */
+typedef enum eMib
+{
+ /*!
+ * LoRaWAN device class
+ *
+ * LoRaWAN Specification V1.0.1
+ */
+ MIB_DEVICE_CLASS,
+ /*!
+ * LoRaWAN Network joined attribute
+ *
+ * LoRaWAN Specification V1.0.1
+ */
+ MIB_NETWORK_JOINED,
+ /*!
+ * Adaptive data rate
+ *
+ * LoRaWAN Specification V1.0.1, chapter 4.3.1.1
+ *
+ * [true: ADR enabled, false: ADR disabled]
+ */
+ MIB_ADR,
+ /*!
+ * Network identifier
+ *
+ * LoRaWAN Specification V1.0.1, chapter 6.1.1
+ */
+ MIB_NET_ID,
+ /*!
+ * End-device address
+ *
+ * LoRaWAN Specification V1.0.1, chapter 6.1.1
+ */
+ MIB_DEV_ADDR,
+ /*!
+ * Network session key
+ *
+ * LoRaWAN Specification V1.0.1, chapter 6.1.3
+ */
+ MIB_NWK_SKEY,
+ /*!
+ * Application session key
+ *
+ * LoRaWAN Specification V1.0.1, chapter 6.1.4
+ */
+ MIB_APP_SKEY,
+ /*!
+ * Set the network type to public or private
+ *
+ * LoRaWAN Specification V1.0.1, chapter 7
+ *
+ * [true: public network, false: private network]
+ */
+ MIB_PUBLIC_NETWORK,
+ /*!
+ * Support the operation with repeaters
+ *
+ * LoRaWAN Specification V1.0.1, chapter 7
+ *
+ * [true: repeater support enabled, false: repeater support disabled]
+ */
+ MIB_REPEATER_SUPPORT,
+ /*!
+ * Communication channels. A get request will return a
+ * pointer which references the first entry of the channel list. The
+ * list is of size LORA_MAX_NB_CHANNELS
+ *
+ * LoRaWAN Specification V1.0.1, chapter 7
+ */
+ MIB_CHANNELS,
+ /*!
+ * Set receive window 2 channel
+ *
+ * LoRaWAN Specification V1.0.1, chapter 3.3.2
+ */
+ MIB_RX2_CHANNEL,
+ /*!
+ * Set receive window 2 channel
+ *
+ * LoRaWAN Specification V1.0.1, chapter 3.3.2
+ */
+ MIB_RX2_DEFAULT_CHANNEL,
+ /*!
+ * LoRaWAN channels mask
+ *
+ * LoRaWAN Specification V1.0.1, chapter 7
+ */
+ MIB_CHANNELS_MASK,
+ /*!
+ * LoRaWAN default channels mask
+ *
+ * LoRaWAN Specification V1.0.1, chapter 7
+ */
+ MIB_CHANNELS_DEFAULT_MASK,
+ /*!
+ * Set the number of repetitions on a channel
+ *
+ * LoRaWAN Specification V1.0.1, chapter 5.2
+ */
+ MIB_CHANNELS_NB_REP,
+ /*!
+ * Maximum receive window duration in [ms]
+ *
+ * LoRaWAN Specification V1.0.1, chapter 3.3.3
+ */
+ MIB_MAX_RX_WINDOW_DURATION,
+ /*!
+ * Receive delay 1 in [ms]
+ *
+ * LoRaWAN Specification V1.0.1, chapter 7
+ */
+ MIB_RECEIVE_DELAY_1,
+ /*!
+ * Receive delay 2 in [ms]
+ *
+ * LoRaWAN Specification V1.0.1, chapter 7
+ */
+ MIB_RECEIVE_DELAY_2,
+ /*!
+ * Join accept delay 1 in [ms]
+ *
+ * LoRaWAN Specification V1.0.1, chapter 7
+ */
+ MIB_JOIN_ACCEPT_DELAY_1,
+ /*!
+ * Join accept delay 2 in [ms]
+ *
+ * LoRaWAN Specification V1.0.1, chapter 7
+ */
+ MIB_JOIN_ACCEPT_DELAY_2,
+ /*!
+ * Default Data rate of a channel
+ *
+ * LoRaWAN Specification V1.0.1, chapter 7
+ *
+ * EU868 - [DR_0, DR_1, DR_2, DR_3, DR_4, DR_5, DR_6, DR_7]
+ *
+ * US915 - [DR_0, DR_1, DR_2, DR_3, DR_4, DR_8, DR_9, DR_10, DR_11, DR_12, DR_13]
+ */
+ MIB_CHANNELS_DEFAULT_DATARATE,
+ /*!
+ * Data rate of a channel
+ *
+ * LoRaWAN Specification V1.0.1, chapter 7
+ *
+ * EU868 - [DR_0, DR_1, DR_2, DR_3, DR_4, DR_5, DR_6, DR_7]
+ *
+ * US915 - [DR_0, DR_1, DR_2, DR_3, DR_4, DR_8, DR_9, DR_10, DR_11, DR_12, DR_13]
+ */
+ MIB_CHANNELS_DATARATE,
+ /*!
+ * Transmission power of a channel
+ *
+ * LoRaWAN Specification V1.0.1, chapter 7
+ *
+ * EU868 - [TX_POWER_20_DBM, TX_POWER_14_DBM, TX_POWER_11_DBM,
+ * TX_POWER_08_DBM, TX_POWER_05_DBM, TX_POWER_02_DBM]
+ *
+ * US915 - [TX_POWER_30_DBM, TX_POWER_28_DBM, TX_POWER_26_DBM,
+ * TX_POWER_24_DBM, TX_POWER_22_DBM, TX_POWER_20_DBM,
+ * TX_POWER_18_DBM, TX_POWER_14_DBM, TX_POWER_12_DBM,
+ * TX_POWER_10_DBM]
+ */
+ MIB_CHANNELS_TX_POWER,
+ /*!
+ * Transmission power of a channel
+ *
+ * LoRaWAN Specification V1.0.1, chapter 7
+ *
+ * EU868 - [TX_POWER_20_DBM, TX_POWER_14_DBM, TX_POWER_11_DBM,
+ * TX_POWER_08_DBM, TX_POWER_05_DBM, TX_POWER_02_DBM]
+ *
+ * US915 - [TX_POWER_30_DBM, TX_POWER_28_DBM, TX_POWER_26_DBM,
+ * TX_POWER_24_DBM, TX_POWER_22_DBM, TX_POWER_20_DBM,
+ * TX_POWER_18_DBM, TX_POWER_14_DBM, TX_POWER_12_DBM,
+ * TX_POWER_10_DBM]
+ */
+ MIB_CHANNELS_DEFAULT_TX_POWER,
+ /*!
+ * LoRaWAN Up-link counter
+ *
+ * LoRaWAN Specification V1.0.1, chapter 4.3.1.5
+ */
+ MIB_UPLINK_COUNTER,
+ /*!
+ * LoRaWAN Down-link counter
+ *
+ * LoRaWAN Specification V1.0.1, chapter 4.3.1.5
+ */
+ MIB_DOWNLINK_COUNTER,
+ /*!
+ * Multicast channels. A get request will return a pointer to the first
+ * entry of the multicast channel linked list. If the pointer is equal to
+ * NULL, the list is empty.
+ */
+ MIB_MULTICAST_CHANNEL,
+}Mib_t;
+
+/*!
+ * LoRaMAC MIB parameters
+ */
+typedef union uMibParam
+{
+ /*!
+ * LoRaWAN device class
+ *
+ * Related MIB type: \ref MIB_DEVICE_CLASS
+ */
+ DeviceClass_t Class;
+ /*!
+ * LoRaWAN network joined attribute
+ *
+ * Related MIB type: \ref MIB_NETWORK_JOINED
+ */
+ bool IsNetworkJoined;
+ /*!
+ * Activation state of ADR
+ *
+ * Related MIB type: \ref MIB_ADR
+ */
+ bool AdrEnable;
+ /*!
+ * Network identifier
+ *
+ * Related MIB type: \ref MIB_NET_ID
+ */
+ uint32_t NetID;
+ /*!
+ * End-device address
+ *
+ * Related MIB type: \ref MIB_DEV_ADDR
+ */
+ uint32_t DevAddr;
+ /*!
+ * Network session key
+ *
+ * Related MIB type: \ref MIB_NWK_SKEY
+ */
+ uint8_t *NwkSKey;
+ /*!
+ * Application session key
+ *
+ * Related MIB type: \ref MIB_APP_SKEY
+ */
+ uint8_t *AppSKey;
+ /*!
+ * Enable or disable a public network
+ *
+ * Related MIB type: \ref MIB_PUBLIC_NETWORK
+ */
+ bool EnablePublicNetwork;
+ /*!
+ * Enable or disable repeater support
+ *
+ * Related MIB type: \ref MIB_REPEATER_SUPPORT
+ */
+ bool EnableRepeaterSupport;
+ /*!
+ * LoRaWAN Channel
+ *
+ * Related MIB type: \ref MIB_CHANNELS
+ */
+ ChannelParams_t* ChannelList;
+ /*!
+ * Channel for the receive window 2
+ *
+ * Related MIB type: \ref MIB_RX2_CHANNEL
+ */
+ Rx2ChannelParams_t Rx2Channel;
+ /*!
+ * Channel for the receive window 2
+ *
+ * Related MIB type: \ref MIB_RX2_DEFAULT_CHANNEL
+ */
+ Rx2ChannelParams_t Rx2DefaultChannel;
+ /*!
+ * Channel mask
+ *
+ * Related MIB type: \ref MIB_CHANNELS_MASK
+ */
+ uint16_t* ChannelsMask;
+ /*!
+ * Default channel mask
+ *
+ * Related MIB type: \ref MIB_CHANNELS_DEFAULT_MASK
+ */
+ uint16_t* ChannelsDefaultMask;
+ /*!
+ * Number of frame repetitions
+ *
+ * Related MIB type: \ref MIB_CHANNELS_NB_REP
+ */
+ uint8_t ChannelNbRep;
+ /*!
+ * Maximum receive window duration
+ *
+ * Related MIB type: \ref MIB_MAX_RX_WINDOW_DURATION
+ */
+ uint32_t MaxRxWindow;
+ /*!
+ * Receive delay 1
+ *
+ * Related MIB type: \ref MIB_RECEIVE_DELAY_1
+ */
+ uint32_t ReceiveDelay1;
+ /*!
+ * Receive delay 2
+ *
+ * Related MIB type: \ref MIB_RECEIVE_DELAY_2
+ */
+ uint32_t ReceiveDelay2;
+ /*!
+ * Join accept delay 1
+ *
+ * Related MIB type: \ref MIB_JOIN_ACCEPT_DELAY_1
+ */
+ uint32_t JoinAcceptDelay1;
+ /*!
+ * Join accept delay 2
+ *
+ * Related MIB type: \ref MIB_JOIN_ACCEPT_DELAY_2
+ */
+ uint32_t JoinAcceptDelay2;
+ /*!
+ * Channels data rate
+ *
+ * Related MIB type: \ref MIB_CHANNELS_DEFAULT_DATARATE
+ */
+ int8_t ChannelsDefaultDatarate;
+ /*!
+ * Channels data rate
+ *
+ * Related MIB type: \ref MIB_CHANNELS_DATARATE
+ */
+ int8_t ChannelsDatarate;
+ /*!
+ * Channels TX power
+ *
+ * Related MIB type: \ref MIB_CHANNELS_DEFAULT_TX_POWER
+ */
+ int8_t ChannelsDefaultTxPower;
+ /*!
+ * Channels TX power
+ *
+ * Related MIB type: \ref MIB_CHANNELS_TX_POWER
+ */
+ int8_t ChannelsTxPower;
+ /*!
+ * LoRaWAN Up-link counter
+ *
+ * Related MIB type: \ref MIB_UPLINK_COUNTER
+ */
+ uint32_t UpLinkCounter;
+ /*!
+ * LoRaWAN Down-link counter
+ *
+ * Related MIB type: \ref MIB_DOWNLINK_COUNTER
+ */
+ uint32_t DownLinkCounter;
+ /*!
+ * Multicast channel
+ *
+ * Related MIB type: \ref MIB_MULTICAST_CHANNEL
+ */
+ MulticastParams_t* MulticastList;
+}MibParam_t;
+
+/*!
+ * LoRaMAC MIB-RequestConfirm structure
+ */
+typedef struct eMibRequestConfirm
+{
+ /*!
+ * MIB-Request type
+ */
+ Mib_t Type;
+
+ /*!
+ * MLME-RequestConfirm parameters
+ */
+ MibParam_t Param;
+}MibRequestConfirm_t;
+
+/*!
+ * LoRaMAC tx information
+ */
+typedef struct sLoRaMacTxInfo
+{
+ /*!
+ * Defines the size of the applicative payload which can be processed
+ */
+ uint8_t MaxPossiblePayload;
+ /*!
+ * The current payload size, dependent on the current datarate
+ */
+ uint8_t CurrentPayloadSize;
+}LoRaMacTxInfo_t;
+
+/*!
+ * LoRaMAC Status
+ */
+typedef enum eLoRaMacStatus
+{
+ /*!
+ * Service started successfully
+ */
+ LORAMAC_STATUS_OK,
+ /*!
+ * Service not started - LoRaMAC is busy
+ */
+ LORAMAC_STATUS_BUSY,
+ /*!
+ * Service unknown
+ */
+ LORAMAC_STATUS_SERVICE_UNKNOWN,
+ /*!
+ * Service not started - invalid parameter
+ */
+ LORAMAC_STATUS_PARAMETER_INVALID,
+ /*!
+ * Service not started - invalid frequency
+ */
+ LORAMAC_STATUS_FREQUENCY_INVALID,
+ /*!
+ * Service not started - invalid datarate
+ */
+ LORAMAC_STATUS_DATARATE_INVALID,
+ /*!
+ * Service not started - invalid frequency and datarate
+ */
+ LORAMAC_STATUS_FREQ_AND_DR_INVALID,
+ /*!
+ * Service not started - the device is not in a LoRaWAN
+ */
+ LORAMAC_STATUS_NO_NETWORK_JOINED,
+ /*!
+ * Service not started - payload lenght error
+ */
+ LORAMAC_STATUS_LENGTH_ERROR,
+ /*!
+ * Service not started - payload lenght error
+ */
+ LORAMAC_STATUS_MAC_CMD_LENGTH_ERROR,
+ /*!
+ * Service not started - the device is switched off
+ */
+ LORAMAC_STATUS_DEVICE_OFF,
+}LoRaMacStatus_t;
+
+/*!
+ * LoRaMAC events structure
+ * Used to notify upper layers of MAC events
+ */
+typedef struct sLoRaMacPrimitives
+{
+ /*!
+ * \brief MCPS-Confirm primitive
+ *
+ * \param [OUT] MCPS-Confirm parameters
+ */
+ void ( *MacMcpsConfirm )( McpsConfirm_t *McpsConfirm );
+ /*!
+ * \brief MCPS-Indication primitive
+ *
+ * \param [OUT] MCPS-Indication parameters
+ */
+ void ( *MacMcpsIndication )( McpsIndication_t *McpsIndication );
+ /*!
+ * \brief MLME-Confirm primitive
+ *
+ * \param [OUT] MLME-Confirm parameters
+ */
+ void ( *MacMlmeConfirm )( MlmeConfirm_t *MlmeConfirm );
+}LoRaMacPrimitives_t;
+
+typedef struct sLoRaMacCallback
+{
+ /*!
+ * \brief Measures the battery level
+ *
+ * \retval Battery level [0: node is connected to an external
+ * power source, 1..254: battery level, where 1 is the minimum
+ * and 254 is the maximum value, 255: the node was not able
+ * to measure the battery level]
+ */
+ uint8_t ( *GetBatteryLevel )( void );
+}LoRaMacCallback_t;
+
+/*!
+ * \brief LoRaMAC layer initialization
+ *
+ * \details In addition to the initialization of the LoRaMAC layer, this
+ * function initializes the callback primitives of the MCPS and
+ * MLME services. Every data field of \ref LoRaMacPrimitives_t must be
+ * set to a valid callback function.
+ *
+ * \param [IN] events - Pointer to a structure defining the LoRaMAC
+ * event functions. Refer to \ref LoRaMacPrimitives_t.
+ *
+ * \param [IN] events - Pointer to a structure defining the LoRaMAC
+ * callback functions. Refer to \ref LoRaMacCallback_t.
+ *
+ * \retval LoRaMacStatus_t Status of the operation. Possible returns are:
+ * returns are:
+ * \ref LORAMAC_STATUS_OK,
+ * \ref LORAMAC_STATUS_PARAMETER_INVALID.
+ */
+LoRaMacStatus_t LoRaMacInitialization( LoRaMacPrimitives_t *primitives, LoRaMacCallback_t *callbacks );
+
+/*!
+ * \brief Queries the LoRaMAC if it is possible to send the next frame with
+ * a given payload size. The LoRaMAC takes scheduled MAC commands into
+ * account and reports, when the frame can be send or not.
+ *
+ * \param [IN] size - Size of applicative payload to be send next
+ *
+ * \param [OUT] txInfo - The structure \ref LoRaMacTxInfo_t contains
+ * information about the actual maximum payload possible
+ * ( according to the configured datarate or the next
+ * datarate according to ADR ), and the maximum frame
+ * size, taking the scheduled MAC commands into account.
+ *
+ * \retval LoRaMacStatus_t Status of the operation. When the parameters are
+ * not valid, the function returns \ref LORAMAC_STATUS_PARAMETER_INVALID.
+ * In case of a length error caused by the applicative payload size, the
+ * function returns LORAMAC_STATUS_LENGTH_ERROR. In case of a length error
+ * due to additional MAC commands in the queue, the function returns
+ * LORAMAC_STATUS_MAC_CMD_LENGTH_ERROR. In case the query is valid, and
+ * the LoRaMAC is able to send the frame, the function returns LORAMAC_STATUS_OK. *
+ */
+LoRaMacStatus_t LoRaMacQueryTxPossible( uint8_t size, LoRaMacTxInfo_t* txInfo );
+
+/*!
+ * \brief LoRaMAC channel add service
+ *
+ * \details Adds a new channel to the channel list and activates the id in
+ * the channel mask. For the US915 band, all channels are enabled
+ * by default. It is not possible to activate less than 6 125 kHz
+ * channels.
+ *
+ * \param [IN] id - Id of the channel. Possible values are:
+ *
+ * 0-15 for EU868
+ * 0-72 for US915
+ *
+ * \param [IN] params - Channel parameters to set.
+ *
+ * \retval LoRaMacStatus_t Status of the operation. Possible returns are:
+ * \ref LORAMAC_STATUS_OK,
+ * \ref LORAMAC_STATUS_BUSY,
+ * \ref LORAMAC_STATUS_PARAMETER_INVALID.
+ */
+LoRaMacStatus_t LoRaMacChannelAdd( uint8_t id, ChannelParams_t params );
+
+/*!
+ * \brief LoRaMAC channel remove service
+ *
+ * \details Deactivates the id in the channel mask.
+ *
+ * \param [IN] id - Id of the channel.
+ *
+ * \retval LoRaMacStatus_t Status of the operation. Possible returns are:
+ * \ref LORAMAC_STATUS_OK,
+ * \ref LORAMAC_STATUS_BUSY,
+ * \ref LORAMAC_STATUS_PARAMETER_INVALID.
+ */
+LoRaMacStatus_t LoRaMacChannelRemove( uint8_t id );
+
+/*!
+ * \brief LoRaMAC multicast channel link service
+ *
+ * \details Links a multicast channel into the linked list.
+ *
+ * \param [IN] channelParam - Multicast channel parameters to link.
+ *
+ * \retval LoRaMacStatus_t Status of the operation. Possible returns are:
+ * \ref LORAMAC_STATUS_OK,
+ * \ref LORAMAC_STATUS_BUSY,
+ * \ref LORAMAC_STATUS_PARAMETER_INVALID.
+ */
+LoRaMacStatus_t LoRaMacMulticastChannelLink( MulticastParams_t *channelParam );
+
+/*!
+ * \brief LoRaMAC multicast channel unlink service
+ *
+ * \details Unlinks a multicast channel from the linked list.
+ *
+ * \param [IN] channelParam - Multicast channel parameters to unlink.
+ *
+ * \retval LoRaMacStatus_t Status of the operation. Possible returns are:
+ * \ref LORAMAC_STATUS_OK,
+ * \ref LORAMAC_STATUS_BUSY,
+ * \ref LORAMAC_STATUS_PARAMETER_INVALID.
+ */
+LoRaMacStatus_t LoRaMacMulticastChannelUnlink( MulticastParams_t *channelParam );
+
+/*!
+ * \brief LoRaMAC MIB-Get
+ *
+ * \details The mac information base service to get attributes of the LoRaMac
+ * layer.
+ *
+ * The following code-snippet shows how to use the API to get the
+ * parameter AdrEnable, defined by the enumeration type
+ * \ref MIB_ADR.
+ * \code
+ * MibRequestConfirm_t mibReq;
+ * mibReq.Type = MIB_ADR;
+ *
+ * if( LoRaMacMibGetRequestConfirm( &mibReq ) == LORAMAC_STATUS_OK )
+ * {
+ * // LoRaMAC updated the parameter mibParam.AdrEnable
+ * }
+ * \endcode
+ *
+ * \param [IN] mibRequest - MIB-GET-Request to perform. Refer to \ref MibRequestConfirm_t.
+ *
+ * \retval LoRaMacStatus_t Status of the operation. Possible returns are:
+ * \ref LORAMAC_STATUS_OK,
+ * \ref LORAMAC_STATUS_SERVICE_UNKNOWN,
+ * \ref LORAMAC_STATUS_PARAMETER_INVALID.
+ */
+LoRaMacStatus_t LoRaMacMibGetRequestConfirm( MibRequestConfirm_t *mibGet );
+
+/*!
+ * \brief LoRaMAC MIB-Set
+ *
+ * \details The mac information base service to set attributes of the LoRaMac
+ * layer.
+ *
+ * The following code-snippet shows how to use the API to set the
+ * parameter AdrEnable, defined by the enumeration type
+ * \ref MIB_ADR.
+ *
+ * \code
+ * MibRequestConfirm_t mibReq;
+ * mibReq.Type = MIB_ADR;
+ * mibReq.Param.AdrEnable = true;
+ *
+ * if( LoRaMacMibGetRequestConfirm( &mibReq ) == LORAMAC_STATUS_OK )
+ * {
+ * // LoRaMAC updated the parameter
+ * }
+ * \endcode
+ *
+ * \param [IN] mibRequest - MIB-SET-Request to perform. Refer to \ref MibRequestConfirm_t.
+ *
+ * \retval LoRaMacStatus_t Status of the operation. Possible returns are:
+ * \ref LORAMAC_STATUS_OK,
+ * \ref LORAMAC_STATUS_BUSY,
+ * \ref LORAMAC_STATUS_SERVICE_UNKNOWN,
+ * \ref LORAMAC_STATUS_PARAMETER_INVALID.
+ */
+LoRaMacStatus_t LoRaMacMibSetRequestConfirm( MibRequestConfirm_t *mibSet );
+
+/*!
+ * \brief LoRaMAC MLME-Request
+ *
+ * \details The Mac layer management entity handles management services. The
+ * following code-snippet shows how to use the API to perform a
+ * network join request.
+ *
+ * \code
+ * static uint8_t DevEui[] =
+ * {
+ * 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+ * };
+ * static uint8_t AppEui[] =
+ * {
+ * 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+ * };
+ * static uint8_t AppKey[] =
+ * {
+ * 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6,
+ * 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C
+ * };
+ *
+ * MlmeReq_t mlmeReq;
+ * mlmeReq.Type = MLME_JOIN;
+ * mlmeReq.Req.Join.DevEui = DevEui;
+ * mlmeReq.Req.Join.AppEui = AppEui;
+ * mlmeReq.Req.Join.AppKey = AppKey;
+ *
+ * if( LoRaMacMlmeRequest( &mlmeReq ) == LORAMAC_STATUS_OK )
+ * {
+ * // Service started successfully. Waiting for the Mlme-Confirm event
+ * }
+ * \endcode
+ *
+ * \param [IN] mlmeRequest - MLME-Request to perform. Refer to \ref MlmeReq_t.
+ *
+ * \retval LoRaMacStatus_t Status of the operation. Possible returns are:
+ * \ref LORAMAC_STATUS_OK,
+ * \ref LORAMAC_STATUS_BUSY,
+ * \ref LORAMAC_STATUS_SERVICE_UNKNOWN,
+ * \ref LORAMAC_STATUS_PARAMETER_INVALID,
+ * \ref LORAMAC_STATUS_NO_NETWORK_JOINED,
+ * \ref LORAMAC_STATUS_LENGTH_ERROR,
+ * \ref LORAMAC_STATUS_DEVICE_OFF.
+ */
+LoRaMacStatus_t LoRaMacMlmeRequest( MlmeReq_t *mlmeRequest );
+
+/*!
+ * \brief LoRaMAC MCPS-Request
+ *
+ * \details The Mac Common Part Sublayer handles data services. The following
+ * code-snippet shows how to use the API to send an unconfirmed
+ * LoRaMAC frame.
+ *
+ * \code
+ * uint8_t myBuffer[] = { 1, 2, 3 };
+ *
+ * McpsReq_t mcpsReq;
+ * mcpsReq.Type = MCPS_UNCONFIRMED;
+ * mcpsReq.Req.Unconfirmed.fPort = 1;
+ * mcpsReq.Req.Unconfirmed.fBuffer = myBuffer;
+ * mcpsReq.Req.Unconfirmed.fBufferSize = sizeof( myBuffer );
+ *
+ * if( LoRaMacMcpsRequest( &mcpsReq ) == LORAMAC_STATUS_OK )
+ * {
+ * // Service started successfully. Waiting for the MCPS-Confirm event
+ * }
+ * \endcode
+ *
+ * \param [IN] mcpsRequest - MCPS-Request to perform. Refer to \ref McpsReq_t.
+ *
+ * \retval LoRaMacStatus_t Status of the operation. Possible returns are:
+ * \ref LORAMAC_STATUS_OK,
+ * \ref LORAMAC_STATUS_BUSY,
+ * \ref LORAMAC_STATUS_SERVICE_UNKNOWN,
+ * \ref LORAMAC_STATUS_PARAMETER_INVALID,
+ * \ref LORAMAC_STATUS_NO_NETWORK_JOINED,
+ * \ref LORAMAC_STATUS_LENGTH_ERROR,
+ * \ref LORAMAC_STATUS_DEVICE_OFF.
+ */
+LoRaMacStatus_t LoRaMacMcpsRequest( McpsReq_t *mcpsRequest );
+
+/*! \} defgroup LORAMAC */
+
+#endif // __LORAMAC_H__
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9986f68c/net/lora/node/include/node/mac/LoRaMacCrypto.h
----------------------------------------------------------------------
diff --git a/net/lora/node/include/node/mac/LoRaMacCrypto.h b/net/lora/node/include/node/mac/LoRaMacCrypto.h
new file mode 100644
index 0000000..f5f4c95
--- /dev/null
+++ b/net/lora/node/include/node/mac/LoRaMacCrypto.h
@@ -0,0 +1,111 @@
+/*!
+ * \file LoRaMacCrypto.h
+ *
+ * \brief LoRa MAC layer cryptography implementation
+ *
+ * \copyright Revised BSD License, see section \ref LICENSE.
+ *
+ * \code
+ * ______ _
+ * / _____) _ | |
+ * ( (____ _____ ____ _| |_ _____ ____| |__
+ * \____ \| ___ | (_ _) ___ |/ ___) _ \
+ * _____) ) ____| | | || |_| ____( (___| | | |
+ * (______/|_____)_|_|_| \__)_____)\____)_| |_|
+ * (C)2013 Semtech
+ *
+ * ___ _____ _ ___ _ _____ ___ ___ ___ ___
+ * / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __|
+ * \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _|
+ * |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___|
+ * embedded.connectivity.solutions===============
+ *
+ * \endcode
+ *
+ * \author Miguel Luis ( Semtech )
+ *
+ * \author Gregory Cristian ( Semtech )
+ *
+ * \author Daniel Jäckle ( STACKFORCE )
+ *
+ * \defgroup LORAMAC_CRYPTO LoRa MAC layer cryptography implementation
+ * This module covers the implementation of cryptographic functions
+ * of the LoRaMAC layer.
+ * \{
+ */
+#ifndef __LORAMAC_CRYPTO_H__
+#define __LORAMAC_CRYPTO_H__
+
+/*!
+ * Computes the LoRaMAC frame MIC field
+ *
+ * \param [IN] buffer - Data buffer
+ * \param [IN] size - Data buffer size
+ * \param [IN] key - AES key to be used
+ * \param [IN] address - Frame address
+ * \param [IN] dir - Frame direction [0: uplink, 1: downlink]
+ * \param [IN] sequenceCounter - Frame sequence counter
+ * \param [OUT] mic - Computed MIC field
+ */
+void LoRaMacComputeMic( const uint8_t *buffer, uint16_t size, const uint8_t *key, uint32_t address, uint8_t dir, uint32_t sequenceCounter, uint32_t *mic );
+
+/*!
+ * Computes the LoRaMAC payload encryption
+ *
+ * \param [IN] buffer - Data buffer
+ * \param [IN] size - Data buffer size
+ * \param [IN] key - AES key to be used
+ * \param [IN] address - Frame address
+ * \param [IN] dir - Frame direction [0: uplink, 1: downlink]
+ * \param [IN] sequenceCounter - Frame sequence counter
+ * \param [OUT] encBuffer - Encrypted buffer
+ */
+void LoRaMacPayloadEncrypt( const uint8_t *buffer, uint16_t size, const uint8_t *key, uint32_t address, uint8_t dir, uint32_t sequenceCounter, uint8_t *encBuffer );
+
+/*!
+ * Computes the LoRaMAC payload decryption
+ *
+ * \param [IN] buffer - Data buffer
+ * \param [IN] size - Data buffer size
+ * \param [IN] key - AES key to be used
+ * \param [IN] address - Frame address
+ * \param [IN] dir - Frame direction [0: uplink, 1: downlink]
+ * \param [IN] sequenceCounter - Frame sequence counter
+ * \param [OUT] decBuffer - Decrypted buffer
+ */
+void LoRaMacPayloadDecrypt( const uint8_t *buffer, uint16_t size, const uint8_t *key, uint32_t address, uint8_t dir, uint32_t sequenceCounter, uint8_t *decBuffer );
+
+/*!
+ * Computes the LoRaMAC Join Request frame MIC field
+ *
+ * \param [IN] buffer - Data buffer
+ * \param [IN] size - Data buffer size
+ * \param [IN] key - AES key to be used
+ * \param [OUT] mic - Computed MIC field
+ */
+void LoRaMacJoinComputeMic( const uint8_t *buffer, uint16_t size, const uint8_t *key, uint32_t *mic );
+
+/*!
+ * Computes the LoRaMAC join frame decryption
+ *
+ * \param [IN] buffer - Data buffer
+ * \param [IN] size - Data buffer size
+ * \param [IN] key - AES key to be used
+ * \param [OUT] decBuffer - Decrypted buffer
+ */
+void LoRaMacJoinDecrypt( const uint8_t *buffer, uint16_t size, const uint8_t *key, uint8_t *decBuffer );
+
+/*!
+ * Computes the LoRaMAC join frame decryption
+ *
+ * \param [IN] key - AES key to be used
+ * \param [IN] appNonce - Application nonce
+ * \param [IN] devNonce - Device nonce
+ * \param [OUT] nwkSKey - Network session key
+ * \param [OUT] appSKey - Application session key
+ */
+void LoRaMacJoinComputeSKeys( const uint8_t *key, const uint8_t *appNonce, uint16_t devNonce, uint8_t *nwkSKey, uint8_t *appSKey );
+
+/*! \} defgroup LORAMAC */
+
+#endif // __LORAMAC_CRYPTO_H__
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9986f68c/net/lora/node/include/node/mac/LoRaMacTest.h
----------------------------------------------------------------------
diff --git a/net/lora/node/include/node/mac/LoRaMacTest.h b/net/lora/node/include/node/mac/LoRaMacTest.h
new file mode 100644
index 0000000..016dfcf
--- /dev/null
+++ b/net/lora/node/include/node/mac/LoRaMacTest.h
@@ -0,0 +1,81 @@
+/*!
+ * \file LoRaMacTest.h
+ *
+ * \brief LoRa MAC layer test function implementation
+ *
+ * \copyright Revised BSD License, see section \ref LICENSE.
+ *
+ * \code
+ * ______ _
+ * / _____) _ | |
+ * ( (____ _____ ____ _| |_ _____ ____| |__
+ * \____ \| ___ | (_ _) ___ |/ ___) _ \
+ * _____) ) ____| | | || |_| ____( (___| | | |
+ * (______/|_____)_|_|_| \__)_____)\____)_| |_|
+ * (C)2013 Semtech
+ *
+ * ___ _____ _ ___ _ _____ ___ ___ ___ ___
+ * / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __|
+ * \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _|
+ * |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___|
+ * embedded.connectivity.solutions===============
+ *
+ * \endcode
+ *
+ * \author Miguel Luis ( Semtech )
+ *
+ * \author Gregory Cristian ( Semtech )
+ *
+ * \author Daniel Jäckle ( STACKFORCE )
+ *
+ * \defgroup LORAMACTEST LoRa MAC layer test function implementation
+ * This module specifies the API implementation of test function of the LoRaMAC layer.
+ * The functions in this file are only for testing purposes only.
+ * \{
+ */
+#ifndef __LORAMACTEST_H__
+#define __LORAMACTEST_H__
+
+/*!
+ * \brief Enabled or disables the reception windows
+ *
+ * \details This is a test function. It shall be used for testing purposes only.
+ * Changing this attribute may lead to a non-conformance LoRaMac operation.
+ *
+ * \param [IN] enable - Enabled or disables the reception windows
+ */
+void LoRaMacTestRxWindowsOn( bool enable );
+
+/*!
+ * \brief Enables the MIC field test
+ *
+ * \details This is a test function. It shall be used for testing purposes only.
+ * Changing this attribute may lead to a non-conformance LoRaMac operation.
+ *
+ * \param [IN] txPacketCounter - Fixed Tx packet counter value
+ */
+void LoRaMacTestSetMic( uint16_t txPacketCounter );
+
+/*!
+ * \brief Enabled or disables the duty cycle
+ *
+ * \details This is a test function. It shall be used for testing purposes only.
+ * Changing this attribute may lead to a non-conformance LoRaMac operation.
+ *
+ * \param [IN] enable - Enabled or disables the duty cycle
+ */
+void LoRaMacTestSetDutyCycleOn( bool enable );
+
+/*!
+ * \brief Sets the channel index
+ *
+ * \details This is a test function. It shall be used for testing purposes only.
+ * Changing this attribute may lead to a non-conformance LoRaMac operation.
+ *
+ * \param [IN] channel - Channel index
+ */
+void LoRaMacTestSetChannel( uint8_t channel );
+
+/*! \} defgroup LORAMACTEST */
+
+#endif // __LORAMACTEST_H__
[02/40] incubator-mynewt-core git commit: MYNEWT-740 Rudimentary Text
parsing package.
Posted by ja...@apache.org.
MYNEWT-740 Rudimentary Text parsing package.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/46d08164
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/46d08164
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/46d08164
Branch: refs/heads/bluetooth5
Commit: 46d08164db6c21c4c6dc9e8b871b54c1d3eecabf
Parents: 5ec317d
Author: Christopher Collins <cc...@apache.org>
Authored: Mon Apr 24 19:13:53 2017 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Apr 24 19:33:16 2017 -0700
----------------------------------------------------------------------
util/parse/include/parse/parse.h | 47 ++++++
util/parse/pkg.yml | 32 +++++
util/parse/src/parse.c | 263 ++++++++++++++++++++++++++++++++++
3 files changed, 342 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/46d08164/util/parse/include/parse/parse.h
----------------------------------------------------------------------
diff --git a/util/parse/include/parse/parse.h b/util/parse/include/parse/parse.h
new file mode 100644
index 0000000..39be885
--- /dev/null
+++ b/util/parse/include/parse/parse.h
@@ -0,0 +1,47 @@
+/*
+ * 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.
+ */
+
+#ifndef H_UTIL_PARSE_
+#define H_UTIL_PARSE_
+
+long long
+parse_ll_bounds(const char *sval, long long min, long long max,
+ int *out_status);
+
+unsigned long long
+parse_ull_bounds(const char *sval,
+ unsigned long long min, unsigned long long max,
+ int *out_status);
+long long
+parse_ll(const char *sval, int *out_status);
+
+long long
+parse_ull(const char *sval, int *out_status);
+
+int
+parse_byte_stream_delim(const char *sval, const char *delims, int max_len,
+ uint8_t *dst, int *out_len);
+
+int
+parse_byte_stream(const char *sval, int max_len, uint8_t *dst, int *out_len);
+
+int
+parse_byte_stream_exact_length(const char *sval, uint8_t *dst, int len);
+
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/46d08164/util/parse/pkg.yml
----------------------------------------------------------------------
diff --git a/util/parse/pkg.yml b/util/parse/pkg.yml
new file mode 100644
index 0000000..69389f7
--- /dev/null
+++ b/util/parse/pkg.yml
@@ -0,0 +1,32 @@
+#
+# 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.
+#
+
+pkg.name: util/parse
+pkg.description: Library containing miscellaneous utilities.
+pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+ - parse
+
+pkg.cflags:
+ # Required for [U]LLONG_{MIN,MAX}
+ - "-std=c99"
+
+pkg.deps:
+ - "@apache-mynewt-core/sys/defs"
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/46d08164/util/parse/src/parse.c
----------------------------------------------------------------------
diff --git a/util/parse/src/parse.c b/util/parse/src/parse.c
new file mode 100644
index 0000000..c278592
--- /dev/null
+++ b/util/parse/src/parse.c
@@ -0,0 +1,263 @@
+/*
+ * 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.
+ */
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <limits.h>
+#include <inttypes.h>
+#include <errno.h>
+#include <assert.h>
+#include "defs/error.h"
+
+/**
+ * Determines which numeric base the specified string should be parsed with.
+ * Strings with leading zeroes are not parsed as octal.
+ */
+static int
+parse_num_base(const char *sval)
+{
+ /* Skip optional sign. */
+ if (sval[0] == '+' || sval[0] == '-') {
+ sval++;
+ }
+
+ if (sval[0] == '0' && sval[1] == 'x') {
+ return 0;
+ } else {
+ return 10;
+ }
+}
+
+/**
+ * Parses a long long within an imposed range.
+ *
+ * @param sval The string to parse.
+ * @param min Values less than this are rejected.
+ * @param max Values greater than this are rejected.
+ * @param out_status Written on completion;
+ * 0: success;
+ * SYS_EINVAL: invalid string or number out of
+ * range.
+ *
+ * @return The parsed number on success;
+ * unspecified on error.
+ */
+long long
+parse_ll_bounds(const char *sval, long long min, long long max,
+ int *out_status)
+{
+ char *endptr;
+ long long llval;
+
+ llval = strtoll(sval, &endptr, parse_num_base(sval));
+ if (sval[0] != '\0' && *endptr == '\0' &&
+ llval >= min && llval <= max) {
+
+ *out_status = 0;
+ return llval;
+ }
+
+ *out_status = SYS_EINVAL;
+ return 0;
+}
+
+/**
+ * Parses an unsigned long long within an imposed range.
+ *
+ * @param sval The string to parse.
+ * @param min Values less than this are rejected.
+ * @param max Values greater than this are rejected.
+ * @param out_status Written on completion;
+ * 0: success;
+ * SYS_EINVAL: invalid string or number out of
+ * range.
+ *
+ * @return The parsed number on success;
+ * unspecified on error.
+ */
+unsigned long long
+parse_ull_bounds(const char *sval,
+ unsigned long long min, unsigned long long max,
+ int *out_status)
+{
+ char *endptr;
+ unsigned long long ullval;
+
+ ullval = strtoull(sval, &endptr, parse_num_base(sval));
+ if (sval[0] != '\0' && *endptr == '\0' &&
+ ullval >= min && ullval <= max) {
+
+ *out_status = 0;
+ return ullval;
+ }
+
+ *out_status = SYS_EINVAL;
+ return 0;
+}
+
+/**
+ * Parses a long long.
+ *
+ * @param sval The string to parse.
+ * @param out_status Written on completion;
+ * 0: success;
+ * SYS_EINVAL: invalid string or number out of
+ * range.
+ *
+ * @return The parsed number on success;
+ * unspecified on error.
+ */
+long long
+parse_ll(const char *sval, int *out_status)
+{
+ return parse_ll_bounds(sval, LLONG_MIN, LLONG_MAX, out_status);
+}
+
+/**
+ * Parses an unsigned long long.
+ *
+ * @param sval The string to parse.
+ * @param out_status Written on completion;
+ * 0: success;
+ * SYS_EINVAL: invalid string or number out of
+ * range.
+ *
+ * @return The parsed number on success;
+ * unspecified on error.
+ */
+long long
+parse_ull(const char *sval, int *out_status)
+{
+ return parse_ull_bounds(sval, 0, ULLONG_MAX, out_status);
+}
+
+/**
+ * Parses a stream of bytes with the specified delimiter(s).
+ *
+ * @param sval The string to parse.
+ * @param delims String containing delimiters; each character
+ * can act as a delimiter.
+ * @param max_len The maximum number of bytes to write.
+ * @param dst The destination buffer to write bytes to.
+ * @param out_len Written on success; total number of bytes
+ * written to the destination buffer.
+ *
+ * @return 0 on success;
+ * SYS_EINVAL on invalid byte stream;
+ * SYS_ERANGE if result only partially written to
+ * buffer due to insufficient space.
+ */
+int
+parse_byte_stream_delim(const char *sval, const char *delims, int max_len,
+ uint8_t *dst, int *out_len)
+{
+ unsigned long ul;
+ const char *cur;
+ char *endptr;
+ int i;
+
+ i = 0;
+ cur = sval;
+ while (*cur != '\0') {
+ if (i >= max_len) {
+ return SYS_ERANGE;
+ }
+
+ ul = strtoul(cur, &endptr, parse_num_base(cur));
+ if (endptr == cur) {
+ return SYS_EINVAL;
+ }
+ cur = endptr;
+
+ if (*cur != '\0') {
+ if (strspn(cur, delims) != 1) {
+ return SYS_EINVAL;
+ }
+ cur++;
+ if (*cur == '\0') {
+ /* Ended with a delimiter. */
+ return SYS_EINVAL;
+ }
+ }
+
+ if (ul > UINT8_MAX) {
+ return SYS_EINVAL;
+ }
+
+ dst[i] = ul;
+ i++;
+ }
+
+ *out_len = i;
+
+ return 0;
+}
+
+/**
+ * Parses a stream of bytes using ':' or '-' as delimiters.
+ *
+ * @param sval The string to parse.
+ * @param max_len The maximum number of bytes to write.
+ * @param dst The destination buffer to write bytes to.
+ * @param out_len Written on success; total number of bytes
+ * written to the destination buffer.
+ *
+ * @return 0 on success;
+ * SYS_EINVAL on invalid byte stream;
+ * SYS_ERANGE if result only partially written to
+ * buffer due to insufficient space.
+ */
+int
+parse_byte_stream(const char *sval, int max_len, uint8_t *dst, int *out_len)
+{
+ return parse_byte_stream_delim(sval, ":-", max_len, dst, out_len);
+}
+
+/**
+ * Parses a stream of bytes using ':' or '-' as delimiters. The number of
+ * bytes must be the exact value specified.
+ *
+ * @param sval The string to parse.
+ * @param max_len The maximum number of bytes to write.
+ * @param dst The destination buffer to write bytes to.
+ * @param len Number of bytes to parse.
+ *
+ * @return 0 on success;
+ * SYS_EINVAL on invalid byte stream or if source
+ * string contains an unexpected number of
+ * bytes;
+ */
+int
+parse_byte_stream_exact_length(const char *sval, uint8_t *dst, int len)
+{
+ int actual_len;
+ int rc;
+
+ rc = parse_byte_stream(sval, len, dst, &actual_len);
+ if (rc != 0) {
+ return rc;
+ }
+
+ if (actual_len != len) {
+ return SYS_EINVAL;
+ }
+
+ return 0;
+}
[20/40] incubator-mynewt-core git commit: MYNEWT-740 Rudimentary Text
parsing package.
Posted by ja...@apache.org.
MYNEWT-740 Rudimentary Text parsing package.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/8374b5a1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/8374b5a1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/8374b5a1
Branch: refs/heads/bluetooth5
Commit: 8374b5a179253c5ab2d091e6677a80b168a58090
Parents: 369df92
Author: Christopher Collins <cc...@apache.org>
Authored: Mon Apr 24 19:13:53 2017 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Fri Apr 28 17:27:51 2017 -0700
----------------------------------------------------------------------
util/parse/include/parse/parse.h | 47 ++++++
util/parse/pkg.yml | 32 +++++
util/parse/src/parse.c | 263 ++++++++++++++++++++++++++++++++++
3 files changed, 342 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8374b5a1/util/parse/include/parse/parse.h
----------------------------------------------------------------------
diff --git a/util/parse/include/parse/parse.h b/util/parse/include/parse/parse.h
new file mode 100644
index 0000000..39be885
--- /dev/null
+++ b/util/parse/include/parse/parse.h
@@ -0,0 +1,47 @@
+/*
+ * 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.
+ */
+
+#ifndef H_UTIL_PARSE_
+#define H_UTIL_PARSE_
+
+long long
+parse_ll_bounds(const char *sval, long long min, long long max,
+ int *out_status);
+
+unsigned long long
+parse_ull_bounds(const char *sval,
+ unsigned long long min, unsigned long long max,
+ int *out_status);
+long long
+parse_ll(const char *sval, int *out_status);
+
+long long
+parse_ull(const char *sval, int *out_status);
+
+int
+parse_byte_stream_delim(const char *sval, const char *delims, int max_len,
+ uint8_t *dst, int *out_len);
+
+int
+parse_byte_stream(const char *sval, int max_len, uint8_t *dst, int *out_len);
+
+int
+parse_byte_stream_exact_length(const char *sval, uint8_t *dst, int len);
+
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8374b5a1/util/parse/pkg.yml
----------------------------------------------------------------------
diff --git a/util/parse/pkg.yml b/util/parse/pkg.yml
new file mode 100644
index 0000000..69389f7
--- /dev/null
+++ b/util/parse/pkg.yml
@@ -0,0 +1,32 @@
+#
+# 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.
+#
+
+pkg.name: util/parse
+pkg.description: Library containing miscellaneous utilities.
+pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+ - parse
+
+pkg.cflags:
+ # Required for [U]LLONG_{MIN,MAX}
+ - "-std=c99"
+
+pkg.deps:
+ - "@apache-mynewt-core/sys/defs"
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8374b5a1/util/parse/src/parse.c
----------------------------------------------------------------------
diff --git a/util/parse/src/parse.c b/util/parse/src/parse.c
new file mode 100644
index 0000000..c278592
--- /dev/null
+++ b/util/parse/src/parse.c
@@ -0,0 +1,263 @@
+/*
+ * 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.
+ */
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <limits.h>
+#include <inttypes.h>
+#include <errno.h>
+#include <assert.h>
+#include "defs/error.h"
+
+/**
+ * Determines which numeric base the specified string should be parsed with.
+ * Strings with leading zeroes are not parsed as octal.
+ */
+static int
+parse_num_base(const char *sval)
+{
+ /* Skip optional sign. */
+ if (sval[0] == '+' || sval[0] == '-') {
+ sval++;
+ }
+
+ if (sval[0] == '0' && sval[1] == 'x') {
+ return 0;
+ } else {
+ return 10;
+ }
+}
+
+/**
+ * Parses a long long within an imposed range.
+ *
+ * @param sval The string to parse.
+ * @param min Values less than this are rejected.
+ * @param max Values greater than this are rejected.
+ * @param out_status Written on completion;
+ * 0: success;
+ * SYS_EINVAL: invalid string or number out of
+ * range.
+ *
+ * @return The parsed number on success;
+ * unspecified on error.
+ */
+long long
+parse_ll_bounds(const char *sval, long long min, long long max,
+ int *out_status)
+{
+ char *endptr;
+ long long llval;
+
+ llval = strtoll(sval, &endptr, parse_num_base(sval));
+ if (sval[0] != '\0' && *endptr == '\0' &&
+ llval >= min && llval <= max) {
+
+ *out_status = 0;
+ return llval;
+ }
+
+ *out_status = SYS_EINVAL;
+ return 0;
+}
+
+/**
+ * Parses an unsigned long long within an imposed range.
+ *
+ * @param sval The string to parse.
+ * @param min Values less than this are rejected.
+ * @param max Values greater than this are rejected.
+ * @param out_status Written on completion;
+ * 0: success;
+ * SYS_EINVAL: invalid string or number out of
+ * range.
+ *
+ * @return The parsed number on success;
+ * unspecified on error.
+ */
+unsigned long long
+parse_ull_bounds(const char *sval,
+ unsigned long long min, unsigned long long max,
+ int *out_status)
+{
+ char *endptr;
+ unsigned long long ullval;
+
+ ullval = strtoull(sval, &endptr, parse_num_base(sval));
+ if (sval[0] != '\0' && *endptr == '\0' &&
+ ullval >= min && ullval <= max) {
+
+ *out_status = 0;
+ return ullval;
+ }
+
+ *out_status = SYS_EINVAL;
+ return 0;
+}
+
+/**
+ * Parses a long long.
+ *
+ * @param sval The string to parse.
+ * @param out_status Written on completion;
+ * 0: success;
+ * SYS_EINVAL: invalid string or number out of
+ * range.
+ *
+ * @return The parsed number on success;
+ * unspecified on error.
+ */
+long long
+parse_ll(const char *sval, int *out_status)
+{
+ return parse_ll_bounds(sval, LLONG_MIN, LLONG_MAX, out_status);
+}
+
+/**
+ * Parses an unsigned long long.
+ *
+ * @param sval The string to parse.
+ * @param out_status Written on completion;
+ * 0: success;
+ * SYS_EINVAL: invalid string or number out of
+ * range.
+ *
+ * @return The parsed number on success;
+ * unspecified on error.
+ */
+long long
+parse_ull(const char *sval, int *out_status)
+{
+ return parse_ull_bounds(sval, 0, ULLONG_MAX, out_status);
+}
+
+/**
+ * Parses a stream of bytes with the specified delimiter(s).
+ *
+ * @param sval The string to parse.
+ * @param delims String containing delimiters; each character
+ * can act as a delimiter.
+ * @param max_len The maximum number of bytes to write.
+ * @param dst The destination buffer to write bytes to.
+ * @param out_len Written on success; total number of bytes
+ * written to the destination buffer.
+ *
+ * @return 0 on success;
+ * SYS_EINVAL on invalid byte stream;
+ * SYS_ERANGE if result only partially written to
+ * buffer due to insufficient space.
+ */
+int
+parse_byte_stream_delim(const char *sval, const char *delims, int max_len,
+ uint8_t *dst, int *out_len)
+{
+ unsigned long ul;
+ const char *cur;
+ char *endptr;
+ int i;
+
+ i = 0;
+ cur = sval;
+ while (*cur != '\0') {
+ if (i >= max_len) {
+ return SYS_ERANGE;
+ }
+
+ ul = strtoul(cur, &endptr, parse_num_base(cur));
+ if (endptr == cur) {
+ return SYS_EINVAL;
+ }
+ cur = endptr;
+
+ if (*cur != '\0') {
+ if (strspn(cur, delims) != 1) {
+ return SYS_EINVAL;
+ }
+ cur++;
+ if (*cur == '\0') {
+ /* Ended with a delimiter. */
+ return SYS_EINVAL;
+ }
+ }
+
+ if (ul > UINT8_MAX) {
+ return SYS_EINVAL;
+ }
+
+ dst[i] = ul;
+ i++;
+ }
+
+ *out_len = i;
+
+ return 0;
+}
+
+/**
+ * Parses a stream of bytes using ':' or '-' as delimiters.
+ *
+ * @param sval The string to parse.
+ * @param max_len The maximum number of bytes to write.
+ * @param dst The destination buffer to write bytes to.
+ * @param out_len Written on success; total number of bytes
+ * written to the destination buffer.
+ *
+ * @return 0 on success;
+ * SYS_EINVAL on invalid byte stream;
+ * SYS_ERANGE if result only partially written to
+ * buffer due to insufficient space.
+ */
+int
+parse_byte_stream(const char *sval, int max_len, uint8_t *dst, int *out_len)
+{
+ return parse_byte_stream_delim(sval, ":-", max_len, dst, out_len);
+}
+
+/**
+ * Parses a stream of bytes using ':' or '-' as delimiters. The number of
+ * bytes must be the exact value specified.
+ *
+ * @param sval The string to parse.
+ * @param max_len The maximum number of bytes to write.
+ * @param dst The destination buffer to write bytes to.
+ * @param len Number of bytes to parse.
+ *
+ * @return 0 on success;
+ * SYS_EINVAL on invalid byte stream or if source
+ * string contains an unexpected number of
+ * bytes;
+ */
+int
+parse_byte_stream_exact_length(const char *sval, uint8_t *dst, int len)
+{
+ int actual_len;
+ int rc;
+
+ rc = parse_byte_stream(sval, len, dst, &actual_len);
+ if (rc != 0) {
+ return rc;
+ }
+
+ if (actual_len != len) {
+ return SYS_EINVAL;
+ }
+
+ return 0;
+}
[27/40] incubator-mynewt-core git commit: This closes #254.
Posted by ja...@apache.org.
This closes #254.
Merge branch 'os_callout' of https://github.com/wesley-wu/incubator-mynewt-core
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/4f89ca82
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/4f89ca82
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/4f89ca82
Branch: refs/heads/bluetooth5
Commit: 4f89ca820d37aabfe6519c3481c264cb69b2cffa
Parents: 702dc23 4dfbd54
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon May 1 09:21:03 2017 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon May 1 09:21:03 2017 -0700
----------------------------------------------------------------------
kernel/os/src/os_callout.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
[05/40] incubator-mynewt-core git commit: Add I2C support in BLE nano
BSP
Posted by ja...@apache.org.
Add I2C support in BLE nano BSP
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/6e75818f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/6e75818f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/6e75818f
Branch: refs/heads/bluetooth5
Commit: 6e75818f224e6e384e64813eadb0db69777f1a6e
Parents: eb4f289
Author: Antoine Albertelli <an...@antoinealb.net>
Authored: Fri Apr 28 10:32:50 2017 +0200
Committer: Antoine Albertelli <an...@antoinealb.net>
Committed: Fri Apr 28 10:33:21 2017 +0200
----------------------------------------------------------------------
hw/bsp/nrf51-blenano/src/hal_bsp.c | 31 +++++++++++++++++++++++++++++++
hw/bsp/nrf51-blenano/syscfg.yml | 26 ++++++++++++++++++++++++++
2 files changed, 57 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6e75818f/hw/bsp/nrf51-blenano/src/hal_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51-blenano/src/hal_bsp.c b/hw/bsp/nrf51-blenano/src/hal_bsp.c
index 3f47f78..97b5004 100644
--- a/hw/bsp/nrf51-blenano/src/hal_bsp.c
+++ b/hw/bsp/nrf51-blenano/src/hal_bsp.c
@@ -32,6 +32,10 @@
#include "hal/hal_spi.h"
#include "os/os_dev.h"
+#if MYNEWT_VAL(I2C_0) || MYNEWT_VAL(I2C_1)
+#include "hal/hal_i2c.h"
+#endif
+
#if MYNEWT_VAL(UART_0)
#include "uart/uart.h"
#include "uart_hal/uart_hal.h"
@@ -66,6 +70,23 @@ static const struct nrf51_hal_spi_cfg os_bsp_spi1s_cfg = {
};
#endif
+#if MYNEWT_VAL(I2C_0)
+static const struct nrf51_hal_i2c_cfg os_bsp_i2c0_cfg = {
+ .sda_pin = MYNEWT_VAL(I2C_0_SDA_PIN),
+ .scl_pin = MYNEWT_VAL(I2C_0_SCL_PIN),
+ .i2c_frequency = MYNEWT_VAL(I2C_0_FREQUENCY),
+};
+#endif
+
+#if MYNEWT_VAL(I2C_1)
+static const struct nrf51_hal_i2c_cfg os_bsp_i2c1_cfg = {
+ .sda_pin = MYNEWT_VAL(I2C_1_SDA_PIN),
+ .scl_pin = MYNEWT_VAL(I2C_1_SCL_PIN),
+ .i2c_frequency = MYNEWT_VAL(I2C_1_FREQUENCY),
+};
+#endif
+
+
/*
* What memory to include in coredump.
*/
@@ -173,4 +194,14 @@ hal_bsp_init(void)
rc = hal_spi_init(1, (void *)&os_bsp_spi1s_cfg, HAL_SPI_TYPE_SLAVE);
assert(rc == 0);
#endif
+
+#if MYNEWT_VAL(I2C_0)
+ rc = hal_i2c_init(0, (void *)&os_bsp_i2c0_cfg);
+ assert(rc == 0);
+#endif
+
+#if MYNEWT_VAL(I2C_1)
+ rc = hal_i2c_init(1, (void *)&os_bsp_i2c1_cfg);
+ assert(rc == 0);
+#endif
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6e75818f/hw/bsp/nrf51-blenano/syscfg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51-blenano/syscfg.yml b/hw/bsp/nrf51-blenano/syscfg.yml
index 86128f8..2b128ae 100644
--- a/hw/bsp/nrf51-blenano/syscfg.yml
+++ b/hw/bsp/nrf51-blenano/syscfg.yml
@@ -54,6 +54,32 @@ syscfg.defs:
description: 'SPI 1 slave'
value: 0
+ I2C_0:
+ description: 'I2C0 enable'
+ value: 0
+ I2C_0_SDA_PIN:
+ description: 'Data pin for I2C0'
+ value: 6
+ I2C_0_SCL_PIN:
+ description: 'Clock pin for I2C0'
+ value: 7
+ I2C_0_FREQUENCY:
+ description: 'Bus frequency in KHz for I2C0'
+ value: 100
+
+ I2C_1:
+ description: 'I2C1 enable'
+ value: 0
+ I2C_1_SDA_PIN:
+ description: 'Data pin for I2C1'
+ value: 28
+ I2C_1_SCL_PIN:
+ description: 'Clock pin for I2C1'
+ value: 29
+ I2C_1_FREQUENCY:
+ description: 'Bus frequency in KHz for I2C1'
+ value: 100
+
TIMER_0:
description: 'NRF51 Timer 0'
value: 1
[32/40] incubator-mynewt-core git commit: updated PIC32 to use custom
startup code
Posted by ja...@apache.org.
updated PIC32 to use custom startup code
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/0163ea6c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/0163ea6c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/0163ea6c
Branch: refs/heads/bluetooth5
Commit: 0163ea6cbf5b2ee95b118da7448e03eecacc3d7a
Parents: b022ac7
Author: julian <ju...@imgtec.com>
Authored: Fri Apr 28 10:48:43 2017 +0100
Committer: julian <ju...@imgtec.com>
Committed: Thu May 4 16:58:45 2017 +0100
----------------------------------------------------------------------
compiler/xc32/compiler.yml | 4 +-
compiler/xc32/pkg.yml | 3 +
hw/bsp/pic32mx470_6lp_clicker/src/hal_bsp.c | 2 +-
hw/bsp/pic32mz2048_wi-fire/src/hal_bsp.c | 2 +-
.../src/arch/cortex_m4/startup_STM32F429x.s | 3 -
.../arch/pic32/startup/cache-err-exception.S | 129 ++++
kernel/os/src/arch/pic32/startup/crt0.S | 623 +++++++++++++++++++
.../src/arch/pic32/startup/general-exception.S | 141 +++++
.../pic32/startup/simple-tlb-refill-exception.S | 135 ++++
.../stubs/default-bootstrap-exception-handler.c | 58 ++
.../stubs/default-cache-err-exception-handler.c | 56 ++
.../stubs/default-general-exception-handler.c | 54 ++
.../src/arch/pic32/stubs/default-nmi-handler.S | 63 ++
.../src/arch/pic32/stubs/default-on-bootstrap.c | 43 ++
.../os/src/arch/pic32/stubs/default-on-reset.c | 43 ++
...efault-simple-tlb-refill-exception-handler.c | 56 ++
.../os/src/arch/pic32/stubs/pic32_init_cache.S | 299 +++++++++
.../arch/pic32/stubs/pic32_init_tlb_ebi_sqi.S | 145 +++++
kernel/os/src/arch/pic32/stubs/sbrk.c | 305 +++++++++
19 files changed, 2157 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0163ea6c/compiler/xc32/compiler.yml
----------------------------------------------------------------------
diff --git a/compiler/xc32/compiler.yml b/compiler/xc32/compiler.yml
index 611497e..fcd4a91 100644
--- a/compiler/xc32/compiler.yml
+++ b/compiler/xc32/compiler.yml
@@ -24,13 +24,13 @@ compiler.path.objdump: "xc32-objdump"
compiler.path.objsize: "xc32-size"
compiler.path.objcopy: "xc32-objcopy"
-compiler.flags.base: -std=gnu11
+compiler.flags.base: -std=gnu11 -msmart-io=0
compiler.flags.default: [compiler.flags.base, -O2, -g3]
compiler.flags.optimized: [compiler.flags.base, -Os -g3]
compiler.flags.debug: [compiler.flags.base, -g3]
compiler.as.flags: [-x, assembler-with-cpp]
-compiler.ld.flags:
+compiler.ld.flags: -nostartfiles -nostdlib -static-libgcc -lgcc
compiler.ld.resolve_circular_deps: true
compiler.ld.mapfile: true
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0163ea6c/compiler/xc32/pkg.yml
----------------------------------------------------------------------
diff --git a/compiler/xc32/pkg.yml b/compiler/xc32/pkg.yml
index 94b8c44..ef99ff5 100644
--- a/compiler/xc32/pkg.yml
+++ b/compiler/xc32/pkg.yml
@@ -25,3 +25,6 @@ pkg.homepage: "http://mynewt.apache.org/"
pkg.keywords:
- pic32
- compiler
+
+pkg.deps:
+ - libc/baselibc
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0163ea6c/hw/bsp/pic32mx470_6lp_clicker/src/hal_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/pic32mx470_6lp_clicker/src/hal_bsp.c b/hw/bsp/pic32mx470_6lp_clicker/src/hal_bsp.c
index c1187c6..87fcfa6 100644
--- a/hw/bsp/pic32mx470_6lp_clicker/src/hal_bsp.c
+++ b/hw/bsp/pic32mx470_6lp_clicker/src/hal_bsp.c
@@ -21,7 +21,7 @@
#include <assert.h>
const struct hal_flash *
-bsp_flash_dev(uint8_t id)
+hal_bsp_flash_dev(uint8_t id)
{
return 0;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0163ea6c/hw/bsp/pic32mz2048_wi-fire/src/hal_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/pic32mz2048_wi-fire/src/hal_bsp.c b/hw/bsp/pic32mz2048_wi-fire/src/hal_bsp.c
index c1187c6..87fcfa6 100644
--- a/hw/bsp/pic32mz2048_wi-fire/src/hal_bsp.c
+++ b/hw/bsp/pic32mz2048_wi-fire/src/hal_bsp.c
@@ -21,7 +21,7 @@
#include <assert.h>
const struct hal_flash *
-bsp_flash_dev(uint8_t id)
+hal_bsp_flash_dev(uint8_t id)
{
return 0;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0163ea6c/hw/bsp/stm32f429discovery/src/arch/cortex_m4/startup_STM32F429x.s
----------------------------------------------------------------------
diff --git a/hw/bsp/stm32f429discovery/src/arch/cortex_m4/startup_STM32F429x.s b/hw/bsp/stm32f429discovery/src/arch/cortex_m4/startup_STM32F429x.s
index f1bdc8a..8174e5f 100644
--- a/hw/bsp/stm32f429discovery/src/arch/cortex_m4/startup_STM32F429x.s
+++ b/hw/bsp/stm32f429discovery/src/arch/cortex_m4/startup_STM32F429x.s
@@ -556,6 +556,3 @@ g_pfnVectors:
.thumb_set DMA2D_IRQHandler,Default_Handler
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
-
-
-
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0163ea6c/kernel/os/src/arch/pic32/startup/cache-err-exception.S
----------------------------------------------------------------------
diff --git a/kernel/os/src/arch/pic32/startup/cache-err-exception.S b/kernel/os/src/arch/pic32/startup/cache-err-exception.S
new file mode 100644
index 0000000..ec35687
--- /dev/null
+++ b/kernel/os/src/arch/pic32/startup/cache-err-exception.S
@@ -0,0 +1,129 @@
+/*********************************************************************
+ *
+ * Cache Error Exception
+ *
+ *********************************************************************
+ * Filename: cache-err-exception.S
+ *
+ * Processor: PIC32
+ *
+ * Compiler: MPLAB XC32 v1.00
+ * MPLAB X IDE
+ * Company: Microchip Technology Inc.
+ *
+ * Software License Agreement
+ *
+ * Copyright (c) 2014, Microchip Technology Inc. and its subsidiaries ("Microchip")
+ * All rights reserved.
+ *
+ * This software is developed by Microchip Technology Inc. and its
+ * subsidiaries ("Microchip").
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * 3. Microchip's name may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * MICROCHIP BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING BUT NOT LIMITED TO
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWSOEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ********************************************************************/
+
+#include <xc.h>
+#ifdef __LIBBUILD__
+ .file 1 "cache-err-exception.S"
+ .loc 1 0
+#endif
+ ###################
+ # Default Simple TLB-Refill handler
+ ###################
+
+ .weak __exception_handler_break
+
+ .section .text._cache_err_exception_context, code
+ .set noreorder
+ .set noat
+ .set nomips16
+ .globl _cache_err_exception_context
+ .ent _cache_err_exception_context
+
+_cache_err_exception_context:
+
+ # Save off the non-callee saved registers that may get mucked with
+ addiu sp, sp, -88
+ sw $1, 4(sp)
+ sw v0, 8(sp)
+ sw v1, 12(sp)
+ sw a0, 16(sp)
+ sw a1, 20(sp)
+ sw a2, 24(sp)
+ sw a3, 28(sp)
+ sw t0, 32(sp)
+ sw t1, 36(sp)
+ sw t2, 40(sp)
+ sw t3, 44(sp)
+ sw t4, 48(sp)
+ sw t5, 52(sp)
+ sw t6, 56(sp)
+ sw t7, 60(sp)
+ sw t8, 64(sp)
+ sw t9, 68(sp)
+ sw ra, 72(sp)
+ mflo t0
+ sw t0, 76(sp)
+ mfhi t0
+ sw t0, 80(sp)
+
+ # Pass Cause and Status to the handler function
+0: mfc0 a0, _CP0_CAUSE
+ mfc0 a1, _CP0_STATUS
+ la v0, _cache_err_exception_handler
+ jalr v0
+ nop
+
+ lw t0, 80(sp)
+ mthi t0
+ lw t0, 76(sp)
+ mtlo t0
+
+ lw $1, 4(sp)
+ lw v0, 8(sp)
+ lw v1, 12(sp)
+ lw a0, 16(sp)
+ lw a1, 20(sp)
+ lw a2, 24(sp)
+ lw a3, 28(sp)
+ lw t0, 32(sp)
+ lw t1, 36(sp)
+ lw t2, 40(sp)
+ lw t3, 44(sp)
+ lw t4, 48(sp)
+ lw t5, 52(sp)
+ lw t6, 56(sp)
+ lw t7, 60(sp)
+ lw t8, 64(sp)
+ lw t9, 68(sp)
+ lw ra, 72(sp)
+ addiu sp, sp, 88
+
+ ehb
+ eret
+
+ .end _cache_err_exception_context
+
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0163ea6c/kernel/os/src/arch/pic32/startup/crt0.S
----------------------------------------------------------------------
diff --git a/kernel/os/src/arch/pic32/startup/crt0.S b/kernel/os/src/arch/pic32/startup/crt0.S
new file mode 100644
index 0000000..88397d2
--- /dev/null
+++ b/kernel/os/src/arch/pic32/startup/crt0.S
@@ -0,0 +1,623 @@
+/*********************************************************************
+ *
+ * C Runtime Startup
+ *
+ *********************************************************************
+ * Filename: crt0.S
+ *
+ * Processor: PIC32
+ *
+ * Compiler: MPLAB XC32
+ * MPLAB X IDE
+ * Company: Microchip Technology Inc.
+ *
+ * Software License Agreement
+ *
+ * Copyright (c) 2014, Microchip Technology Inc. and its subsidiaries ("Microchip")
+ * All rights reserved.
+ *
+ * This software is developed by Microchip Technology Inc. and its
+ * subsidiaries ("Microchip").
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * 3. Microchip's name may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * MICROCHIP BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING BUT NOT LIMITED TO
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWSOEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ********************************************************************/
+
+#include "xc.h"
+#include <cp0defs.h>
+
+#ifdef __LIBBUILD__
+ # Replace the standard debugging information with a simple filename. This
+ # prevents the library build directory from showing up in MPLAB IDE. It
+ # also effectively disables source-line debugging.
+ .file 1 "libpic32/startup/crt0.S"
+ .loc 1 0
+#endif
+
+#if (__XC32_VERSION > 1000) && !defined(CPP_INIT)
+#define CPP_INIT
+#endif
+
+#if !defined(PIC32_SRS_SET_COUNT)
+# if defined(__PIC32_SRS_SET_COUNT)
+# define PIC32_SRS_SET_COUNT __PIC32_SRS_SET_COUNT
+# else
+# warning PIC32_SRS_SET_COUNT not defined on build line
+# define PIC32_SRS_SET_COUNT 2
+# endif
+#endif
+
+#if defined(__PIC32MX) || defined(__PIC32MM) || defined(__PIC32MZ)
+#define INIT_DATA 1
+#endif
+
+/* This file contains 32-bit assembly code */
+ .set nomips16
+
+ ##################################################################
+ # Entry point of the entire application
+ ##################################################################
+ .section .reset,code,keep
+ .align 2
+ .set noreorder
+ .ent _reset
+
+############################
+# Begin ISA switching code #
+############################
+
+#if defined (__mips_micromips)
+ .set micromips
+#endif
+
+#if (defined(__PIC32_HAS_MICROMIPS)) && (defined(__PIC32_HAS_MIPS32R2))
+_reset:
+ .word 0x10000003 /* MIPS32: branch forward 0x10 bytes from here */
+ /* MicroMIPS: ADDI32 $0, $0, 0x0007 (nop) */
+ /* DO NOT change the relative branch */
+
+ .word 0x00000000 /* NOP */
+__reset_micromips_isa:
+ .set micromips
+ jal _startup
+ nop
+
+ .align 2
+ /* Device not in proper ISA mode */
+ .set nomicromips
+__reset_switch_isa:
+ jal _startup
+ nop
+
+#else
+
+_reset:
+ jal _startup
+ nop
+
+#endif /* __PIC32_HAS_MICROMIPS */
+
+ .align 2
+ .end _reset
+ .globl _reset
+ .size _reset, .-_reset
+
+ .section .reset.startup,code,keep
+ .align 2
+ .set noreorder
+
+#if defined (__mips_micromips)
+ .set micromips
+#else
+ .set nomicromips
+#endif
+
+############################
+# End ISA switching code #
+############################
+
+ ##################################################################
+ # Startup code
+ ##################################################################
+ .align 2
+ .globl _startup
+ .set noreorder
+ .ent _startup
+_startup:
+ ##################################################################
+ # If entered because of an NMI, jump to the NMI handler.
+ ##################################################################
+ mfc0 k0,_CP0_STATUS
+ ext k0,k0,19,1 # Extract NMI bit
+ beqz k0,_no_nmi
+ nop
+ la k0,_nmi_handler
+ jr k0
+ nop
+_no_nmi:
+
+ ##################################################################
+ # Initialize Stack Pointer
+ # _stack is initialized by the linker script to point to the
+ # starting location of the stack in DRM
+ ##################################################################
+ la sp,_stack
+
+ ##################################################################
+ # Initialize Global Pointer
+ # _gp is initialized by the linker script to point to "middle"
+ # of the small variables region
+ ##################################################################
+ la gp,_gp
+
+#if (PIC32_SRS_SET_COUNT == 2)
+ ##################################################################
+ # Initialize Global Pointer in Shadow Set
+ # The SRSCtl's PSS field must be set to the shadow set in which
+ # to initialize the global pointer. Since we have only a
+ # single shadow set (besides the normal), we will initialize
+ # SRSCtl<PSS> to SRSCtl<HSS>. We then write the global pointer
+ # to the previous shadow set to ensure that on interrupt, the
+ # global pointer has been initialized.
+ ##################################################################
+ mfc0 t1,_CP0_SRSCTL # Read SRSCtl register
+ add t3,t1,zero # Save off current SRSCtl
+ ext t2,t1,26,4 # to obtain HSS field
+ ins t1,t2,6,4 # Put HSS field
+ mtc0 t1,_CP0_SRSCTL # into SRSCtl<PSS>
+ ehb # Clear hazard before using new SRSCTL
+ wrpgpr gp,gp # Set global pointer in PSS
+ mtc0 t3,_CP0_SRSCTL # Restore SRSCtl
+ ehb
+
+#elif (PIC32_SRS_SET_COUNT > 2)
+ ##################################################################
+ # Initialize Global Pointer in Shadow Set(s)
+ # The SRSCtl PSS field must be set to the shadow set in which
+ # to initialize the global pointer. We will initialize
+ # SRSCtl<PSS> to the number of reg sets and work down to set zero.
+ # We write the global pointer to the previous shadow set to
+ # ensure that on interrupt, the global pointer has been
+ # initialized.
+ ##################################################################
+ mfc0 t1,_CP0_SRSCTL # Read SRSCtl register
+ add t3,t1,zero # Save off current SRSCtl
+
+ li t2,(PIC32_SRS_SET_COUNT-1)
+
+1: ins t1,t2,6,4 # Put next shadow set field
+ mtc0 t1,_CP0_SRSCTL # into SRSCtl<PSS>
+ ehb # Clear hazard before using new SRSCTL
+ wrpgpr gp,gp # Set global pointer in PSS
+
+ addiu t2,t2,-1 # Next lower shadow set
+ # Loop for all sets
+ bne t2,$0,1b # Down to zero (normal GPR set)
+ nop
+
+ mtc0 t3,_CP0_SRSCTL # Restore SRSCtl
+ ehb
+
+#endif /* (PIC32_SRS_SET_COUNT > 2) */
+
+ ##################################################################
+ # Call the "on reset" procedure
+ ##################################################################
+ la t0,_on_reset
+ jalr t0
+ nop
+
+#if defined(INIT_MMU_MZ_FIXED) || defined(__PIC32_HAS_MMU_MZ_FIXED)
+ ##################################################################
+ # Initialize TLB for fixed mapping to EBI and SQI
+ ##################################################################
+ .extern __pic32_tlb_init_ebi_sqi
+ la t0,__pic32_tlb_init_ebi_sqi
+ jalr t0
+ nop
+#endif
+
+#if defined(INIT_L1_CACHE) || defined(__PIC32_HAS_L1CACHE)
+ ##################################################################
+ # Initialize L1 cache register
+ ##################################################################
+ .extern __pic32_init_cache
+
+ la t0,__pic32_init_cache
+ jalr t0
+ nop
+#endif
+
+ ##################################################################
+ # Clear uninitialized data sections
+ ##################################################################
+_start_bss_init:
+ la t0,_bss_begin
+ la t1,_bss_end
+ b _bss_check
+ nop
+
+_bss_init:
+ sw zero,0x0(t0)
+ sw zero,0x4(t0)
+ sw zero,0x8(t0)
+ sw zero,0xc(t0)
+ addu t0,16
+_bss_check:
+ bltu t0,t1,_bss_init
+ nop
+
+#if defined(INIT_DATA) || defined(__PIC32_HAS_INIT_DATA)
+ ##################################################################
+ # Initialize data using the linker-generated .dinit table
+ ##################################################################
+ .equiv FMT_CLEAR,0
+ .equiv FMT_COPY,1
+_dinit_init:
+ la t0,_dinit_addr
+
+#define SRC t0
+#define DST t1
+#define LEN t2
+#define FMT t3
+
+0: lw DST,0(SRC)
+ beqz DST,9f
+ addu SRC,4
+ lw LEN,0(SRC)
+ addu SRC,4
+ lw FMT,0(SRC)
+ beq FMT,$0,_dinit_clear
+ addu SRC,4
+
+_dinit_copy:
+ lbu t4,0(SRC)
+ subu LEN,1
+ addu SRC,1
+ sb t4,0(DST)
+ bne LEN,$0,_dinit_copy
+ addu DST,1
+
+ b _dinit_end
+ nop
+
+_dinit_clear:
+ sb $0,(DST)
+ subu LEN,1
+ bne LEN,$0,_dinit_clear
+ addu DST,1
+
+_dinit_end:
+ addu SRC,3
+ addiu LEN,$0,0xFFFFFFFC
+ and SRC,LEN,SRC
+ lw DST,0(SRC)
+ bne DST,$0,0b
+ nop
+9:
+
+#endif /* INIT_DATA */
+
+ ##################################################################
+ # If there are no RAM functions, skip the next section --
+ # initializing bus matrix registers.
+ ##################################################################
+ la t1,_ramfunc_begin
+ beqz t1,_ramfunc_done
+ nop
+
+#if defined(INIT_SSX) || defined(__PIC32_HAS_SSX)
+ /* No initialization required */
+#else /* Use BMX */
+ ##################################################################
+ # Initialize bus matrix registers if RAM functions exist in the
+ # application
+ ##################################################################
+ la t1,_bmxdkpba_address
+ la t2,BMXDKPBA
+ sw t1,0(t2)
+ la t1,_bmxdudba_address
+ la t2,BMXDUDBA
+ sw t1,0(t2)
+ la t1,_bmxdupba_address
+ la t2,BMXDUPBA
+ sw t1,0(t2)
+#endif /* INIT_SSX */
+
+_ramfunc_done:
+
+ ##################################################################
+ # Initialize CP0 registers
+ ##################################################################
+ # Initialize Count register
+ ##################################################################
+ mtc0 zero,_CP0_COUNT
+
+ ##################################################################
+ # Initialize Compare register
+ ##################################################################
+ li t2,-1
+ mtc0 t2,_CP0_COMPARE
+
+ ##################################################################
+ # Ensure BEV set and Initialize EBase register
+ ##################################################################
+ li t0, (1<<22)
+ mfc0 t2,_CP0_STATUS
+ or t2,t0,t2 # Set BEV bit 22
+ mtc0 t2,_CP0_STATUS
+
+ la t1,_ebase_address
+ ehb
+ mtc0 t1,_CP0_EBASE
+
+ ##################################################################
+ # Initialize PRISS register to a safer default for devices that
+ # have it. The application should re-initialize it to an
+ # application-specific value.
+ #
+ # We do NOT do this by default.
+ ##################################################################
+#if defined(USE_DEFAULT_PRISS_VALUE)
+#if defined(_PRISS_PRI7SS_POSITION)
+#if (PIC32_SRS_SET_COUNT >= 7)
+ li t2, 0x76540000
+ addiu t2, t2, 0x3210
+ lui t1, %hi(PRISS)
+ sw t2, %lo(PRISS)(t1)
+#elif (PIC32_SRS_SET_COUNT <= 2)
+ li t2, 0x10000000
+ lui t1, %hi(PRISS)
+ sw t2, %lo(PRISS)(t1)
+#endif /* PIC32_SRS_SET_COUNT */
+#endif /* _PRISS_PRI7SS_POSITION */
+#endif /* USE_DEFAULT_PRISS_VALUE */
+
+ ##################################################################
+ # Initialize IntCtl/INTCON.VS register with _vector_spacing
+ ##################################################################
+ la t1,_vector_spacing
+#if defined(INIT_INTCONVS) || defined(__PIC32_HAS_INTCONVS)
+ la t0, INTCON
+ lw t2, 0(t0)
+ li t2, 0
+ ins t2, t1, 16, 7
+#if defined(__PIC32MM) && defined(_INTCON_MVEC_MASK)
+ ori t2, t2, _INTCON_MVEC_MASK
+#endif
+ sw t2, 0(t0)
+#endif
+ li t2,0 # Clear t2 and
+ ins t2,t1,5,5 # shift value to VS field
+ mtc0 t2,_CP0_INTCTL
+
+ ##################################################################
+ # Initialize CAUSE registers
+ # - Enable counting of Count register <DC = 0>
+ # - Use special exception vector <IV = 1>
+ # - Clear pending software interrupts <IP1:IP0 = 0>
+ ##################################################################
+ li t1,0x00800000
+ mtc0 t1,_CP0_CAUSE
+
+ ##################################################################
+ # Initialize STATUS register
+ # - Access to Coprocessor 0 not allowed in user mode <CU0 = 0>
+ # - User mode uses configured endianness <RE = 0>
+ # - Preserve Bootstrap Exception vectors <BEV>
+ # - Preserve soft reset <SR> and non-maskable interrupt <NMI>
+ # - CorExtend enabled based on whether CorExtend User Defined
+ # Instructions have been implemented <CEE = Config<UDI>>
+ # - Disable any pending interrupts <IM7..IM2 = 0, IM1..IM0 = 0>
+ # - Disable hardware interrupts <IPL7:IPL2 = 0>
+ # - Base mode is Kernel mode <UM = 0>
+ # - Error level is normal <ERL = 0>
+ # - Exception level is normal <EXL = 0>
+ # - Interrupts are disabled <IE = 0>
+ # - DSPr2 ASE is enabled for devices that support it <MX = 1>
+ # - FPU64 is enabled for devices that support it <CU1=1> & <FR=1>
+ ##################################################################
+ mfc0 t0,_CP0_CONFIG
+ ext t1,t0,22,1 # Extract UDI from Config register
+ sll t1,t1,17 # Move UDI to Status.CEE location
+ mfc0 t0,_CP0_STATUS
+ and t0,t0,0x00580000 # Preserve SR, NMI, and BEV
+#if defined(INIT_DSPR2) || defined(__PIC32_HAS_DSPR2)
+ li t2, 0x01000000 # Set the Status.MX bit to enable DSP
+ or t0,t2,t0
+#endif
+#if defined(INIT_FPU64) || defined(__PIC32_HAS_FPU64)
+ li t2, 0x24000000 # Set the Status.CU1 and Status.FR bits to
+ or t0,t2,t0 # enable the FPU in FR64 mode
+#endif
+
+ or t0,t1,t0 # Include Status.CEE (from UDI)
+ mtc0 t0,_CP0_STATUS
+
+#if defined(PIC32WK) && defined(_CP0_CONFIG3) && defined (__mips_micromips)
+ # Ensure that the ISAONEXEC bit is set for the microMIPS ISA for the PIC32WK family
+ # _bsc0 (_CP0_CONFIG3, _CP0_CONFIG3_SELECT, ISAONEXEC_MASK)
+ li t1,0x10000 # ISAONEXEC bit
+ mfc0 t0,_CP0_CONFIG3
+ or t1,t0,t1
+ mtc0 t1,_CP0_CONFIG3
+
+#endif /* PIC32WK && __mips_micromips */
+
+#if defined(INIT_FPU64) || defined(__PIC32_HAS_FPU64)
+ # FPU Control and Status
+ li t2,0x1000000 # FCSR: RM=0, FS=1, FO=0, FN=0
+ # Enables: 0b00000 E=1, V=0, Z=0, O=0, U=0, I=0
+ ctc1 t2, $31 # High perf on denormal operands & tiny results
+#endif
+ ehb
+
+ ##################################################################
+ # Call the "on bootstrap" procedure
+ ##################################################################
+ la t0,_on_bootstrap
+ jalr t0
+ nop
+
+ ##################################################################
+ # Initialize Status<BEV> for normal exception vectors
+ ##################################################################
+ mfc0 t0,_CP0_STATUS
+ and t0,t0,0xffbfffff # Clear BEV
+ mtc0 t0,_CP0_STATUS
+
+ ##################################################################
+ # Call main. We do this via a thunk in the text section so that
+ # a normal jump and link can be used, enabling the startup code
+ # to work properly whether main is written in MIPS16 or MIPS32
+ # code. I.e., the linker will correctly adjust the JAL to JALX if
+ # necessary
+ ##################################################################
+ and a0,a0,0
+ and a1,a1,0
+ la t0,_main_entry
+ jr t0
+ nop
+
+ .end _startup
+
+ ##################################################################
+ # Boot Exception Vector Handler
+ # Jumps to _bootstrap_exception_handler
+ ##################################################################
+ .section .bev_handler,code,keep
+ .align 2
+ .set noreorder
+ .ent _bev_exception
+_bev_exception:
+ la k0,_bootstrap_exception_handler
+ jr k0
+ nop
+
+ .end _bev_exception
+
+ ##################################################################
+ # General Exception Vector Handler
+ # Jumps to _general_exception_context
+ ##################################################################
+ .section .gen_handler,code
+ .align 2
+ .set noreorder
+ .ent _gen_exception
+_gen_exception:
+0: la k0,_general_exception_context
+ jr k0
+ nop
+
+ .end _gen_exception
+
+#if defined(INIT_MMU_MZ_FIXED) || defined(__PIC32_HAS_MMU_MZ_FIXED)
+ ##################################################################
+ # Simple TLB-Refill Exception Vector
+ # Jumps to _simple_tlb_refill_exception_context
+ ##################################################################
+ .section .simple_tlb_refill_vector,code,keep
+ .align 2
+ .set noreorder
+ .ent simple_tlb_refill_vector
+simple_tlb_refill_vector:
+ la k0,_simple_tlb_refill_exception_context
+ jr k0
+ nop
+
+ .end simple_tlb_refill_vector
+#endif
+
+#if defined(INIT_L1_CACHE) || defined(__PIC32_HAS_L1CACHE)
+ ##################################################################
+ # Cache-Error Exception Vector Handler
+ # Jumps to _cache_err_exception_context
+ ##################################################################
+ .section .cache_err_vector,code,keep
+ .align 2
+ .set noreorder
+ .ent _cache_err_vector
+_cache_err_vector:
+ la k0,_cache_err_exception_context
+ jr k0
+ nop
+
+ .end _cache_err_vector
+#endif
+
+ .section .text.main_entry,code,keep
+ .align 2
+ .ent _main_entry
+_main_entry:
+
+#if defined(CPP_INIT)
+ .weak _init
+ # call .init section to run constructors etc
+ lui a0,%hi(_init)
+ addiu sp,sp,-24
+ addiu a0,a0,%lo(_init)
+ beq a0,$0,2f
+ sw $31,20(sp) #,
+ jalr a0
+ nop
+2:
+#endif
+ and a0,a0,0
+ and a1,a1,0
+
+ ##################################################################
+
+ # Call _start
+ ##################################################################
+ la t0,_start
+ jalr t0
+ nop
+
+#if defined(CALL_EXIT)
+ ##################################################################
+ # Call exit()
+ ##################################################################
+ jal exit
+ nop
+#endif
+
+ ##################################################################
+ # Just in case, go into infinite loop
+ # Call a software breakpoint only with -mdebugger compiler option
+ ##################################################################
+ .weak __exception_handler_break
+__crt0_exit:
+1:
+ la v0,__exception_handler_break
+ beq v0,0,0f
+ nop
+ jalr v0
+ nop
+
+0: b 1b
+ nop
+
+ .globl __crt0_exit
+ .end _main_entry
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0163ea6c/kernel/os/src/arch/pic32/startup/general-exception.S
----------------------------------------------------------------------
diff --git a/kernel/os/src/arch/pic32/startup/general-exception.S b/kernel/os/src/arch/pic32/startup/general-exception.S
new file mode 100644
index 0000000..ce30284
--- /dev/null
+++ b/kernel/os/src/arch/pic32/startup/general-exception.S
@@ -0,0 +1,141 @@
+/*********************************************************************
+ *
+ * General Exception
+ *
+ *********************************************************************
+ * Filename: general-exception.S
+ *
+ * Processor: PIC32
+ *
+ * Compiler: MPLAB XC32 v1.00
+ * MPLAB X IDE
+ * Company: Microchip Technology Inc.
+ *
+ * Software License Agreement
+ *
+ * Copyright (c) 2014, Microchip Technology Inc. and its subsidiaries ("Microchip")
+ * All rights reserved.
+ *
+ * This software is developed by Microchip Technology Inc. and its
+ * subsidiaries ("Microchip").
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * 3. Microchip's name may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * MICROCHIP BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING BUT NOT LIMITED TO
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWSOEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ********************************************************************/
+
+#include <xc.h>
+#ifdef __LIBBUILD__
+ .file 1 "general-exception.S"
+ .loc 1 0
+#endif
+ ###################
+ # Default general exception handler
+ ###################
+
+ .extern _general_exception_handler
+
+ .section .text.general_exception, code
+ .set noreorder
+ .set noat
+ .set nomips16
+ .globl _general_exception_context
+ .ent _general_exception_context
+
+_general_exception_context:
+
+ # Save off the non-callee saved registers that may get mucked with
+ addiu sp, sp, -88
+ sw $1, 4(sp)
+ sw v0, 8(sp)
+ sw v1, 12(sp)
+ sw a0, 16(sp)
+ sw a1, 20(sp)
+ sw a2, 24(sp)
+ sw a3, 28(sp)
+ sw t0, 32(sp)
+ sw t1, 36(sp)
+ sw t2, 40(sp)
+ sw t3, 44(sp)
+ sw t4, 48(sp)
+ sw t5, 52(sp)
+ sw t6, 56(sp)
+ sw t7, 60(sp)
+ sw t8, 64(sp)
+ sw t9, 68(sp)
+ sw ra, 72(sp)
+ mflo t0
+ sw t0, 76(sp)
+ mfhi t0
+ sw t0, 80(sp)
+
+#if defined(__PIC__)
+ lw t9,%call16(_general_exception_handler)(gp)
+ nop
+ # Pass Cause and Status to the handler function
+ mfc0 a0, _CP0_CAUSE
+ mfc0 a1, _CP0_STATUS
+ jalr t9
+ nop
+#else
+ la k0,_general_exception_handler
+ nop
+
+ # Pass Cause and Status to the handler function
+ mfc0 a0, _CP0_CAUSE
+ mfc0 a1, _CP0_STATUS
+ jalr k0
+ nop
+#endif
+
+ lw t0, 80(sp)
+ mthi t0
+ lw t0, 76(sp)
+ mtlo t0
+
+ lw $1, 4(sp)
+ lw v0, 8(sp)
+ lw v1, 12(sp)
+ lw a0, 16(sp)
+ lw a1, 20(sp)
+ lw a2, 24(sp)
+ lw a3, 28(sp)
+ lw t0, 32(sp)
+ lw t1, 36(sp)
+ lw t2, 40(sp)
+ lw t3, 44(sp)
+ lw t4, 48(sp)
+ lw t5, 52(sp)
+ lw t6, 56(sp)
+ lw t7, 60(sp)
+ lw t8, 64(sp)
+ lw t9, 68(sp)
+ lw ra, 72(sp)
+ addiu sp, sp, 88
+
+ ehb
+ eret
+
+ .end _general_exception_context
+
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0163ea6c/kernel/os/src/arch/pic32/startup/simple-tlb-refill-exception.S
----------------------------------------------------------------------
diff --git a/kernel/os/src/arch/pic32/startup/simple-tlb-refill-exception.S b/kernel/os/src/arch/pic32/startup/simple-tlb-refill-exception.S
new file mode 100644
index 0000000..900d129
--- /dev/null
+++ b/kernel/os/src/arch/pic32/startup/simple-tlb-refill-exception.S
@@ -0,0 +1,135 @@
+/*********************************************************************
+ *
+ * Simple TLB-Refill Exception
+ *
+ *********************************************************************
+ * Filename: simple-tlb-refill-exception.S
+ *
+ * Processor: PIC32
+ *
+ * Compiler: MPLAB XC32 v1.00
+ * MPLAB X IDE
+ * Company: Microchip Technology Inc.
+ *
+ * Software License Agreement
+ *
+ * Copyright (c) 2014, Microchip Technology Inc. and its subsidiaries ("Microchip")
+ * All rights reserved.
+ *
+ * This software is developed by Microchip Technology Inc. and its
+ * subsidiaries ("Microchip").
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * 3. Microchip's name may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * MICROCHIP BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING BUT NOT LIMITED TO
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWSOEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ********************************************************************/
+
+#include <xc.h>
+#ifdef __LIBBUILD__
+ .file 1 "simple-tlb-refill-exception.S"
+ .loc 1 0
+#endif
+ ###################
+ # Default Simple TLB-Refill handler
+ ###################
+
+ .weak __exception_handler_break
+
+ .section .text.simple_tlb_refill_context, code
+ .set noreorder
+ .set noat
+ .set nomips16
+ .globl _simple_tlb_refill_exception_context
+ .ent _simple_tlb_refill_exception_context
+
+_simple_tlb_refill_exception_context:
+
+ # Save off the non-callee saved registers that may get mucked with
+ addiu sp, sp, -88
+ sw $1, 4(sp)
+ sw v0, 8(sp)
+ sw v1, 12(sp)
+ sw a0, 16(sp)
+ sw a1, 20(sp)
+ sw a2, 24(sp)
+ sw a3, 28(sp)
+ sw t0, 32(sp)
+ sw t1, 36(sp)
+ sw t2, 40(sp)
+ sw t3, 44(sp)
+ sw t4, 48(sp)
+ sw t5, 52(sp)
+ sw t6, 56(sp)
+ sw t7, 60(sp)
+ sw t8, 64(sp)
+ sw t9, 68(sp)
+ sw ra, 72(sp)
+ mflo t0
+ sw t0, 76(sp)
+ mfhi t0
+ sw t0, 80(sp)
+
+ # Pass Cause and Status to the handler function
+0: mfc0 a0, _CP0_CAUSE
+ mfc0 a1, _CP0_STATUS
+#if defined(__PIC__)
+ lw t9, %call16(_simple_tlb_refill_exception_handler)(gp)
+ jalr t9
+ nop
+#else
+ la v0, _simple_tlb_refill_exception_handler
+ jalr v0
+ nop
+#endif
+
+ lw t0, 80(sp)
+ mthi t0
+ lw t0, 76(sp)
+ mtlo t0
+
+ lw $1, 4(sp)
+ lw v0, 8(sp)
+ lw v1, 12(sp)
+ lw a0, 16(sp)
+ lw a1, 20(sp)
+ lw a2, 24(sp)
+ lw a3, 28(sp)
+ lw t0, 32(sp)
+ lw t1, 36(sp)
+ lw t2, 40(sp)
+ lw t3, 44(sp)
+ lw t4, 48(sp)
+ lw t5, 52(sp)
+ lw t6, 56(sp)
+ lw t7, 60(sp)
+ lw t8, 64(sp)
+ lw t9, 68(sp)
+ lw ra, 72(sp)
+ addiu sp, sp, 88
+
+ ehb # do we need this? Execution hazard barriers?
+ eret
+
+ .end _simple_tlb_refill_exception_context
+
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0163ea6c/kernel/os/src/arch/pic32/stubs/default-bootstrap-exception-handler.c
----------------------------------------------------------------------
diff --git a/kernel/os/src/arch/pic32/stubs/default-bootstrap-exception-handler.c b/kernel/os/src/arch/pic32/stubs/default-bootstrap-exception-handler.c
new file mode 100644
index 0000000..9b582b9
--- /dev/null
+++ b/kernel/os/src/arch/pic32/stubs/default-bootstrap-exception-handler.c
@@ -0,0 +1,58 @@
+/*********************************************************************
+ *
+ * Default Bootstrap Exception Handler Implementation
+ *
+ *********************************************************************
+ * Filename: default-bootstrap-exception-handler.c
+ *
+ * Processor: PIC32
+ *
+ * Compiler: MPLAB C Compiler for PIC32 MCUs
+ * MPLAB IDE
+ * Company: Microchip Technology Inc.
+ *
+ * Software License Agreement
+ *
+ * The software supplied herewith by Microchip Technology Incorporated
+ * (the 'Company') for its PIC32/PIC24F Microcontroller is intended
+ * and supplied to you, the Company's customer, for use solely and
+ * exclusively on Microchip PIC32/PIC24F Microcontroller products.
+ * The software is owned by the Company and/or its supplier, and is
+ * protected under applicable copyright laws. All rights are reserved.
+ * Any use in violation of the foregoing restrictions may subject the
+ * user to criminal sanctions under applicable laws, as well as to
+ * civil liability for the breach of the terms and conditions of this
+ * license.
+ *
+ * THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION. NO WARRANTIES,
+ * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
+ * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
+ * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
+ * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
+ *
+ ********************************************************************/
+
+/* This is a default definition of a bootstrap exception handler function.
+ * It does nothing and just does a software reset. If the user
+ * application supplies a handler function, this function will not be
+ * referenced and thus not pulled in from the library.
+ */
+
+extern void __attribute__((nomips16, noreturn, far, weak)) __pic32_software_reset();
+void __attribute__((weak)) __exception_handler_break(void);
+extern void _DEBUGGER __attribute__((weak));
+
+void
+__attribute__((weak, nomips16, noreturn)) _bootstrap_exception_handler (void)
+{
+ if (&_DEBUGGER != 0 && __exception_handler_break)
+ __asm__ volatile ("sdbbp 0");
+
+ if (__pic32_software_reset)
+ __pic32_software_reset();
+
+ while(1);
+}
+
+
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0163ea6c/kernel/os/src/arch/pic32/stubs/default-cache-err-exception-handler.c
----------------------------------------------------------------------
diff --git a/kernel/os/src/arch/pic32/stubs/default-cache-err-exception-handler.c b/kernel/os/src/arch/pic32/stubs/default-cache-err-exception-handler.c
new file mode 100644
index 0000000..1f0f008
--- /dev/null
+++ b/kernel/os/src/arch/pic32/stubs/default-cache-err-exception-handler.c
@@ -0,0 +1,56 @@
+/*********************************************************************
+ *
+ * Default Cache-Error Exception Handler Implementation
+ *
+ *********************************************************************
+ * Filename: default-cache-err-exception-handler.c
+ *
+ * Processor: PIC32
+ *
+ * Compiler: MPLAB C Compiler for PIC32 MCUs
+ * MPLAB IDE
+ * Company: Microchip Technology Inc.
+ *
+ * Software License Agreement
+ *
+ * The software supplied herewith by Microchip Technology Incorporated
+ * (the 'Company') for its PIC32/PIC24F Microcontroller is intended
+ * and supplied to you, the Company's customer, for use solely and
+ * exclusively on Microchip PIC32/PIC24F Microcontroller products.
+ * The software is owned by the Company and/or its supplier, and is
+ * protected under applicable copyright laws. All rights are reserved.
+ * Any use in violation of the foregoing restrictions may subject the
+ * user to criminal sanctions under applicable laws, as well as to
+ * civil liability for the breach of the terms and conditions of this
+ * license.
+ *
+ * THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION. NO WARRANTIES,
+ * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
+ * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
+ * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
+ * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
+ *
+ ********************************************************************/
+/* This is a default definition of a cache-error exception handler function.
+ * It does nothing and just does a software reset. If the user
+ * application supplies a handler function, this function will not be
+ * referenced and thus not pulled in from the library.
+ */
+
+extern void __attribute__((nomips16, noreturn, far, weak)) __pic32_software_reset();
+void __attribute__((weak)) __exception_handler_break(void);
+extern void _DEBUGGER __attribute__((weak));
+
+void
+__attribute__((weak, nomips16, noreturn)) _cache_err_exception_handler (void)
+{
+ if (&_DEBUGGER != 0 && __exception_handler_break)
+ __asm__ volatile ("sdbbp 0");
+
+ if (__pic32_software_reset)
+ __pic32_software_reset();
+
+ while(1);
+}
+
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0163ea6c/kernel/os/src/arch/pic32/stubs/default-general-exception-handler.c
----------------------------------------------------------------------
diff --git a/kernel/os/src/arch/pic32/stubs/default-general-exception-handler.c b/kernel/os/src/arch/pic32/stubs/default-general-exception-handler.c
new file mode 100644
index 0000000..ed71330
--- /dev/null
+++ b/kernel/os/src/arch/pic32/stubs/default-general-exception-handler.c
@@ -0,0 +1,54 @@
+/*********************************************************************
+ *
+ * Default General Exception Handler Implementation
+ *
+ *********************************************************************
+ * Filename: default-general-exception-handler.c
+ *
+ * Processor: PIC32
+ *
+ * Compiler: MPLAB C Compiler for PIC32 MCUs
+ * MPLAB IDE
+ * Company: Microchip Technology Inc.
+ *
+ * Software License Agreement
+ *
+ * The software supplied herewith by Microchip Technology Incorporated
+ * (the 'Company') for its PIC32/PIC24F Microcontroller is intended
+ * and supplied to you, the Company's customer, for use solely and
+ * exclusively on Microchip PIC32/PIC24F Microcontroller products.
+ * The software is owned by the Company and/or its supplier, and is
+ * protected under applicable copyright laws. All rights are reserved.
+ * Any use in violation of the foregoing restrictions may subject the
+ * user to criminal sanctions under applicable laws, as well as to
+ * civil liability for the breach of the terms and conditions of this
+ * license.
+ *
+ * THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION. NO WARRANTIES,
+ * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
+ * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
+ * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
+ * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
+ *
+ ********************************************************************/
+/* This is a default definition of a general exception handler function.
+ * It does nothing and just does a software reset. If the user
+ * application supplies a handler function, this function will not be
+ * referenced and thus not pulled in from the library.
+ */
+extern void __attribute__((nomips16, noreturn, far, weak)) __pic32_software_reset();
+void __attribute__((weak)) __exception_handler_break(void);
+extern void _DEBUGGER __attribute__((weak));
+
+void
+__attribute__((weak, nomips16, noreturn)) _general_exception_handler (void)
+{
+ if (&_DEBUGGER != 0 && __exception_handler_break)
+ __asm__ volatile ("sdbbp 0");
+
+ if (__pic32_software_reset)
+ __pic32_software_reset();
+
+ while(1);
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0163ea6c/kernel/os/src/arch/pic32/stubs/default-nmi-handler.S
----------------------------------------------------------------------
diff --git a/kernel/os/src/arch/pic32/stubs/default-nmi-handler.S b/kernel/os/src/arch/pic32/stubs/default-nmi-handler.S
new file mode 100644
index 0000000..5d14c2f
--- /dev/null
+++ b/kernel/os/src/arch/pic32/stubs/default-nmi-handler.S
@@ -0,0 +1,63 @@
+/*********************************************************************
+ *
+ * Default NMI Handler Implementation
+ *
+ *********************************************************************
+ * Filename: default-nmi-handler.S
+ *
+ * Processor: PIC32
+ *
+ * Compiler: MPLAB XC32
+ * MPLAB X IDE
+ * Company: Microchip Technology Inc.
+ *
+ * Software License Agreement
+ *
+ * The software supplied herewith by Microchip Technology Incorporated
+ * (the 'Company') for its PIC32/PIC24F Microcontroller is intended
+ * and supplied to you, the Company's customer, for use solely and
+ * exclusively on Microchip PIC32/PIC24F Microcontroller products.
+ * The software is owned by the Company and/or its supplier, and is
+ * protected under applicable copyright laws. All rights are reserved.
+ * Any use in violation of the foregoing restrictions may subject the
+ * user to criminal sanctions under applicable laws, as well as to
+ * civil liability for the breach of the terms and conditions of this
+ * license.
+ *
+ * THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION. NO WARRANTIES,
+ * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
+ * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
+ * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
+ * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
+ *
+ ********************************************************************/
+
+#include <xc.h>
+#ifdef __LIBBUILD__
+ .file 1 "Microchip PIC32 Library"
+ .loc 1 0
+#endif
+ .text
+ .align 2
+ .weak _nmi_handler
+ .set nomips16
+ .ent _nmi_handler
+_nmi_handler:
+ .frame sp,0,$31 # vars= 0, regs= 0/0, args= 0, gp= 0
+ .mask 0x00000000,0
+ .fmask 0x00000000,0
+ .set noreorder
+
+ mfc0 k0, _CP0_STATUS # retrieve STATUS
+ lui k1, ~(_CP0_STATUS_BEV_MASK >> 16) & 0xffff
+ ori k1, k1, ~_CP0_STATUS_BEV_MASK & 0xffff
+ and k0, k0, k1 # Clear BEV
+ mtc0 k0, _CP0_STATUS # store STATUS
+ eret
+
+ .set macro
+ .set reorder
+ .end _nmi_handler
+ .size _nmi_handler, .-_nmi_handler
+
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0163ea6c/kernel/os/src/arch/pic32/stubs/default-on-bootstrap.c
----------------------------------------------------------------------
diff --git a/kernel/os/src/arch/pic32/stubs/default-on-bootstrap.c b/kernel/os/src/arch/pic32/stubs/default-on-bootstrap.c
new file mode 100644
index 0000000..442816d
--- /dev/null
+++ b/kernel/os/src/arch/pic32/stubs/default-on-bootstrap.c
@@ -0,0 +1,43 @@
+/*********************************************************************
+ *
+ * Default _on_bootstrap Implementation
+ *
+ *********************************************************************
+ * Filename: default-on-bootstrap.c
+ *
+ * Processor: PIC32
+ *
+ * Compiler: MPLAB C Compiler for PIC32 MCUs
+ * MPLAB IDE
+ * Company: Microchip Technology Inc.
+ *
+ * Software License Agreement
+ *
+ * The software supplied herewith by Microchip Technology Incorporated
+ * (the 'Company') for its PIC32/PIC24F Microcontroller is intended
+ * and supplied to you, the Company's customer, for use solely and
+ * exclusively on Microchip PIC32/PIC24F Microcontroller products.
+ * The software is owned by the Company and/or its supplier, and is
+ * protected under applicable copyright laws. All rights are reserved.
+ * Any use in violation of the foregoing restrictions may subject the
+ * user to criminal sanctions under applicable laws, as well as to
+ * civil liability for the breach of the terms and conditions of this
+ * license.
+ *
+ * THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION. NO WARRANTIES,
+ * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
+ * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
+ * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
+ * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
+ *
+ ********************************************************************/
+/* This is a default definition of an _on_bootstrap() function.
+ * It does nothing and just goes returns. If the user
+ * application supplies a handler function, this function will not be
+ * referenced and thus not pulled in from the library.
+ */
+void
+__attribute__((weak)) _on_bootstrap (void)
+{
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0163ea6c/kernel/os/src/arch/pic32/stubs/default-on-reset.c
----------------------------------------------------------------------
diff --git a/kernel/os/src/arch/pic32/stubs/default-on-reset.c b/kernel/os/src/arch/pic32/stubs/default-on-reset.c
new file mode 100644
index 0000000..9a11b33
--- /dev/null
+++ b/kernel/os/src/arch/pic32/stubs/default-on-reset.c
@@ -0,0 +1,43 @@
+/*********************************************************************
+ *
+ * Default _on_reset Implementation
+ *
+ *********************************************************************
+ * Filename: default-on-reset.c
+ *
+ * Processor: PIC32
+ *
+ * Compiler: MPLAB C Compiler for PIC32 MCUs
+ * MPLAB IDE
+ * Company: Microchip Technology Inc.
+ *
+ * Software License Agreement
+ *
+ * The software supplied herewith by Microchip Technology Incorporated
+ * (the 'Company') for its PIC32/PIC24F Microcontroller is intended
+ * and supplied to you, the Company's customer, for use solely and
+ * exclusively on Microchip PIC32/PIC24F Microcontroller products.
+ * The software is owned by the Company and/or its supplier, and is
+ * protected under applicable copyright laws. All rights are reserved.
+ * Any use in violation of the foregoing restrictions may subject the
+ * user to criminal sanctions under applicable laws, as well as to
+ * civil liability for the breach of the terms and conditions of this
+ * license.
+ *
+ * THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION. NO WARRANTIES,
+ * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
+ * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
+ * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
+ * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
+ *
+ ********************************************************************/
+/* This is a default definition of an _on_reset() function.
+ * It does nothing and just goes returns. If the user
+ * application supplies a handler function, this function will not be
+ * referenced and thus not pulled in from the library.
+ */
+void
+__attribute__((weak)) _on_reset (void)
+{
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0163ea6c/kernel/os/src/arch/pic32/stubs/default-simple-tlb-refill-exception-handler.c
----------------------------------------------------------------------
diff --git a/kernel/os/src/arch/pic32/stubs/default-simple-tlb-refill-exception-handler.c b/kernel/os/src/arch/pic32/stubs/default-simple-tlb-refill-exception-handler.c
new file mode 100644
index 0000000..4ede8f7
--- /dev/null
+++ b/kernel/os/src/arch/pic32/stubs/default-simple-tlb-refill-exception-handler.c
@@ -0,0 +1,56 @@
+/*********************************************************************
+ *
+ * Default Simple TLB-Refill Exception Handler Implementation
+ *
+ *********************************************************************
+ * Filename: default-simple-tlb-refill-exception-handler.c
+ *
+ * Processor: PIC32
+ *
+ * Compiler: MPLAB C Compiler for PIC32 MCUs
+ * MPLAB IDE
+ * Company: Microchip Technology Inc.
+ *
+ * Software License Agreement
+ *
+ * The software supplied herewith by Microchip Technology Incorporated
+ * (the 'Company') for its PIC32/PIC24F Microcontroller is intended
+ * and supplied to you, the Company's customer, for use solely and
+ * exclusively on Microchip PIC32/PIC24F Microcontroller products.
+ * The software is owned by the Company and/or its supplier, and is
+ * protected under applicable copyright laws. All rights are reserved.
+ * Any use in violation of the foregoing restrictions may subject the
+ * user to criminal sanctions under applicable laws, as well as to
+ * civil liability for the breach of the terms and conditions of this
+ * license.
+ *
+ * THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION. NO WARRANTIES,
+ * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
+ * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
+ * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
+ * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
+ *
+ ********************************************************************/
+/* This is a default definition of a simple tlb-refill exception handler function.
+ * It does nothing and just does a software reset. If the user
+ * application supplies a handler function, this function will not be
+ * referenced and thus not pulled in from the library.
+ */
+
+extern void __attribute__((nomips16, noreturn, far, weak)) __pic32_software_reset();
+void __attribute__((weak)) __exception_handler_break(void);
+extern void _DEBUGGER __attribute__((weak));
+
+void
+__attribute__((weak, nomips16, noreturn)) _simple_tlb_refill_exception_handler (void)
+{
+ if (&_DEBUGGER != 0 && __exception_handler_break)
+ __asm__ volatile ("sdbbp 0");
+
+ if (__pic32_software_reset)
+ __pic32_software_reset();
+
+ while(1);
+}
+
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0163ea6c/kernel/os/src/arch/pic32/stubs/pic32_init_cache.S
----------------------------------------------------------------------
diff --git a/kernel/os/src/arch/pic32/stubs/pic32_init_cache.S b/kernel/os/src/arch/pic32/stubs/pic32_init_cache.S
new file mode 100644
index 0000000..af7cd68
--- /dev/null
+++ b/kernel/os/src/arch/pic32/stubs/pic32_init_cache.S
@@ -0,0 +1,299 @@
+/*-------------------------------------------------------------------------
+ *
+ * Copyright (c) 2014, Microchip Technology Inc. and its subsidiaries ("Microchip")
+ * All rights reserved.
+ *
+ * This software is developed by Microchip Technology Inc. and its
+ * subsidiaries ("Microchip").
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * 3. Microchip's name may not be used to endorse or promote products
+ * derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR PURPOSE ARE DISCLAIMED. IN NO EVENT
+ * SHALL MICROCHIP BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING BUT NOT LIMITED TO
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWSOEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *-------------------------------------------------------------------------*/
+
+#include <xc.h>
+#include <cp0defs.h>
+
+ /* Symbols defined in linker script */
+ .weak __pic32_init_cache_program_base_addr
+ .weak __pic32_init_cache_data_base_addr
+
+/* Cache Coherency Attributes */
+#define _CACHE_WRITEBACK_WRITEALLOCATE 3
+#define _CACHE_WRITETHROUGH_WRITEALLOCATE 1
+#define _CACHE_WRITETHROUGH_NOWRITEALLOCATE 0
+#define _CACHE_DISABLE 2
+
+#ifndef _CP0_ERRCTL
+#define _CP0_ERRCTL $26, 0
+#endif
+
+#ifndef _CP0_TAGLO
+#define _CP0_TAGLO $28, 0
+#endif
+
+/* Set __PIC32_CACHE_MODE to the desired coherency attribute */
+#define __PIC32_CACHE_MODE _CACHE_WRITEBACK_WRITEALLOCATE
+
+/* ==================================== */
+#define Index_Store_Tag_I 0x08
+#define Index_Store_Tag_D 0x09
+
+#define tmp t0
+#define cfg t1
+#define icachesize t2
+#define ilinesize t3
+#define iways t4
+#define dcachesize t5
+#define dlinesize t6
+#define dways t7
+#define save_ra v1
+
+#define INIT_L1_CACHE
+#if defined(INIT_L1_CACHE)
+.sdata; .globl __pic32_icache_size; .type __pic32_icache_size,@object; .size __pic32_icache_size,4; __pic32_icache_size:; .word -1
+.sdata; .globl __pic32_icache_linesize; .type __pic32_icache_linesize,@object; .size __pic32_icache_linesize,4; __pic32_icache_linesize:; .word -1
+.sdata; .globl __pic32_icache_ways; .type __pic32_icache_ways,@object; .size __pic32_icache_ways,4; __pic32_icache_ways:; .word 1
+
+.sdata; .globl __pic32_dcache_size; .type __pic32_dcache_size,@object; .size __pic32_dcache_size,4; __pic32_dcache_size:; .word -1
+.sdata; .globl __pic32_dcache_linesize; .type __pic32_dcache_linesize,@object; .size __pic32_dcache_linesize,4; __pic32_dcache_linesize:; .word -1
+.sdata; .globl __pic32_dcache_ways; .type __pic32_dcache_ways,@object; .size __pic32_dcache_ways,4; __pic32_dcache_ways:; .word 1
+
+.sdata; .globl __pic32_scache_size; .type __pic32_scache_size,@object; .size __pic32_scache_size,4; __pic32_scache_size:; .word -1
+.sdata; .globl __pic32_scache_linesize; .type __pic32_scache_linesize,@object; .size __pic32_scache_linesize,4; __pic32_scache_linesize:; .word -1
+.sdata; .globl __pic32_scache_ways; .type __pic32_scache_ways,@object; .size __pic32_scache_ways,4; __pic32_scache_ways:; .word 1
+
+.section .cache_init.cache, code
+ .set nomips16
+ .ent __size_cache; __size_cache:
+ mfc0 cfg,_CP0_CONFIG
+
+ li icachesize,0
+ li ilinesize,0
+ li dcachesize,0
+ li dlinesize,0
+
+ /* Check that we have Config1 */
+ and tmp,cfg,_CP0_CONFIG_M_MASK
+ mfc0 cfg,_CP0_CONFIG1
+ beqz tmp,9f
+ nop
+
+ /* Get icache line size (log2) */
+ and tmp,cfg,_CP0_CONFIG1_IL_MASK
+ srl tmp,_CP0_CONFIG1_IL_POSITION
+ beqz tmp,8f # no i-cache
+ addu tmp,1
+
+ /* Get number of icache ways */
+ and iways,cfg,_CP0_CONFIG1_IA_MASK
+ srl iways,_CP0_CONFIG1_IA_POSITION
+ addu iways,1
+ move icachesize,iways
+
+ /* total icache size = lines/way * linesize *ways */
+ li ilinesize,1
+ sll ilinesize,tmp
+ sll icachesize,tmp
+
+ /* get icache lines per way */
+ and tmp,cfg,_CP0_CONFIG1_IS_MASK
+ srl tmp,_CP0_CONFIG1_IS_POSITION
+ addu tmp,6
+ sll icachesize,tmp
+
+ /* Get dcache line size (log2) */
+8: and tmp,cfg,_CP0_CONFIG1_DL_MASK
+ srl tmp,_CP0_CONFIG1_DL_POSITION
+ beqz tmp,8f # no d-cache
+ addu tmp,1
+
+ /* Get number of dcache ways */
+ and dways,cfg,_CP0_CONFIG1_DA_MASK
+ srl dways,_CP0_CONFIG1_DA_POSITION
+ addu dways,1
+ move dcachesize,dways
+
+ /* Total dcache size = lines/way * linesize * ways */
+ li dlinesize,1
+ sll dlinesize,tmp
+ sll dcachesize,tmp
+
+ and tmp,cfg,_CP0_CONFIG1_DS_MASK
+ srl tmp,_CP0_CONFIG1_DS_POSITION
+ addu tmp,6
+ sll dcachesize,tmp
+
+#undef cfg
+#undef tmp
+
+8:
+9: j ra
+ nop
+ .size __size_cache,.-__size_cache; .end __size_cache;
+
+/*
+ * void __pic32_size_cache()
+ *
+ * Work out size of I & D caches (assume already initialized)
+ */
+ .section .cache_init.pic32_size_cache, code
+ .set nomips16
+ .globl __pic32_size_cache; .ent __pic32_size_cache;
+
+__pic32_size_cache:
+ lw t0,__pic32_icache_size
+ move a3,ra
+ bgtz t0,8f # already known?
+
+ bal __size_cache
+ move ra,a3
+
+..savesize:
+ sw icachesize,__pic32_icache_size
+ sw dcachesize,__pic32_dcache_size
+ sw ilinesize,__pic32_icache_linesize
+ sw dlinesize,__pic32_dcache_linesize
+ sw iways,__pic32_icache_ways
+ sw dways,__pic32_dcache_ways
+
+8: j ra
+ nop
+ .size __pic32_size_cache,.-__pic32_size_cache; .end __pic32_size_cache
+
+/*
+ * void __pic32_init_cache()
+ *
+ * Work out size and initialize I & D caches.
+ */
+ .section .cache_init.pic32_init_cache, code
+ .set nomips16
+ .globl __pic32_init_cache; .ent __pic32_init_cache;
+__pic32_init_cache:
+
+ move save_ra,ra
+ bal __size_cache
+
+ /* Run uncached */
+ .set noreorder
+ .set nomacro
+#if 0
+ bal 1f
+ #
+ li cfg,0xa0000000
+1: or cfg,ra
+ addu cfg,16
+ jr cfg
+ move ra,v1
+#endif
+
+ /*
+ * The caches may be in an indeterminate state, so we force an
+ * invalidate, load/fill, and invalidate for each line.
+ */
+
+ /* Disable all i/u and cache exceptions */
+ .set macro
+ .set noreorder
+ # Disable interrupts and set UM=1
+ # Save current status in tmp
+ mfc0 t0,_CP0_STATUS
+ li t1,~_CP0_STATUS_IE_MASK
+ and t1,t0
+ or t1,_CP0_STATUS_ERL_MASK
+ mtc0 t1,_CP0_STATUS
+ ehb
+
+ mtc0 zero,_CP0_ERRCTL
+ mtc0 zero,_CP0_TAGLO # 4K taglo / 2*K itaglo
+ ehb
+
+ /* Initialize primary instruction cache */
+ .set noreorder
+4: la a0,__pic32_init_cache_program_base_addr
+ bne a0,zero,0f
+ /* Use a default if the symbol is not defined */
+ li a0,0x9D000000 /* KSEG0_PROGRAM_BASE */
+0: beqz icachesize,8f # icachesize
+ addu a1,a0,icachesize # limit = base + icachesize
+1: addu a0,ilinesize # line size
+ bne a0,a1,1b
+ cache Index_Store_Tag_I,-4(a0) # BDSLOT: clear tag
+
+
+ /* Initialize primary data cache */
+ .set noreorder
+8: la a0,__pic32_init_cache_data_base_addr
+ bne a0,zero,0f
+ /* Use a default if the symbol is not defined */
+ li a0,0x80000000 /* KSEG_DATA_BASE */
+
+0: beqz dcachesize,8f
+ addu a1,a0,dcachesize # limit = base + dcachesize
+1: addu a0,dlinesize
+ bne a0,a1,1b
+ cache Index_Store_Tag_D,-4(a0) # BDSLOT: clear tag
+
+ .set reorder
+
+8: sync
+
+ /* Store the sizes only after the caches are initialized */
+4: sw icachesize,__pic32_icache_size
+ sw dcachesize,__pic32_dcache_size
+ sw ilinesize,__pic32_icache_linesize
+ sw dlinesize,__pic32_dcache_linesize
+ sw iways,__pic32_icache_ways
+ sw dways,__pic32_dcache_ways
+
+ .set noreorder
+
+ # restore status
+ mtc0 t0,_CP0_STATUS
+ ehb
+
+ # Configure Cache Mode
+ mfc0 t1, _CP0_CONFIG
+ ori t1, _CP0_CONFIG_K0_MASK
+ xori t1, _CP0_CONFIG_K0_MASK
+ ori t1, __PIC32_CACHE_MODE
+ mtc0 t1, _CP0_CONFIG
+ ehb
+
+ .set reorder
+
+ move ra, save_ra
+ jr ra
+ nop
+ .size __pic32_init_cache,.-__pic32_init_cache; .end __pic32_init_cache;
+#endif /* INIT_L1_CACHE */
+
+#undef _CACHE_WRITEBACK_WRITEALLOCATE
+#undef _CACHE_WRITETHROUGH_WRITEALLOCATE
+#undef _CACHE_WRITETHROUGH_NOWRITEALLOCATE
+#undef _CACHE_DISABLE
+
+#undef _CP0_ERRCTL
+#undef _CP0_TAGLO
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0163ea6c/kernel/os/src/arch/pic32/stubs/pic32_init_tlb_ebi_sqi.S
----------------------------------------------------------------------
diff --git a/kernel/os/src/arch/pic32/stubs/pic32_init_tlb_ebi_sqi.S b/kernel/os/src/arch/pic32/stubs/pic32_init_tlb_ebi_sqi.S
new file mode 100644
index 0000000..045f5af
--- /dev/null
+++ b/kernel/os/src/arch/pic32/stubs/pic32_init_tlb_ebi_sqi.S
@@ -0,0 +1,145 @@
+/*-------------------------------------------------------------------------
+ *
+ * Copyright (c) 2014, Microchip Technology Inc. and its subsidiaries ("Microchip")
+ * All rights reserved.
+ *
+ * This software is developed by Microchip Technology Inc. and its
+ * subsidiaries ("Microchip").
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * 3. Microchip's name may not be used to endorse or promote products
+ * derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY MICROCHIP "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR PURPOSE ARE DISCLAIMED. IN NO EVENT
+ * SHALL MICROCHIP BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING BUT NOT LIMITED TO
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWSOEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *-------------------------------------------------------------------------*/
+
+#include <xc.h>
+#include <cp0defs.h>
+
+#define CFG1_MMUSSHIFT 25
+
+ .weak __pic32_tlb_init_values_count
+ .weak __pic32_tlb_init_values_begin
+ .weak __pic32_tlb_init_values_end
+
+ .section .tlb.__pic32_tlb_init_ebi_sqi, code, keep
+ .set nomips16
+ .set noreorder
+
+ .global __pic32_tlb_init_ebi_sqi
+ .ent __pic32_tlb_init_ebi_sqi
+
+__pic32_tlb_init_ebi_sqi:
+ /* Determine if we have a TLB */
+ /* Read C0 Config0 */
+ mfc0 v1, _CP0_CONFIG
+ /* check MT field */
+ ext v1, v1, 7, 3
+ li a3, 0x1
+ bne v1, a3, __done_init_tlb
+
+ /* read C0 Config1 */
+ mfc0 v0, _CP0_CONFIG1
+
+__start_init_tlb:
+ /* Extract MMU Size */
+ ext v1, v0, CFG1_MMUSSHIFT, 6
+
+ mtc0 zero, _CP0_ENTRYLO0
+ mtc0 zero, _CP0_ENTRYLO1
+ mtc0 zero, _CP0_PAGEMASK
+ mtc0 zero, _CP0_WIRED
+
+ move a0, $0
+ lui a0, 0x8000
+
+__next_tlb_entry_pair:
+ mtc0 v1, _CP0_INDEX
+ mtc0 a0, _CP0_ENTRYHI
+
+ ehb
+ tlbwi
+
+ add a0, (2<<13)
+ add v1, -1
+ bne v1, zero, __next_tlb_entry_pair
+ nop
+
+ /* Get the count of the entries in the table from a linker-script symbol */
+__count_tlb_init_values:
+ lui a0, %hi(__pic32_tlb_init_values_count)
+ ori a0, %lo(__pic32_tlb_init_values_count)
+
+__device_tlb_entries:
+ /* Set lowest count (a0) TLB entries as fixed (entry 0 and entry 1) */
+ mtc0 a0, _CP0_WIRED
+
+ /* Point a1 to the beginning of the linker-script generated table */
+ la a1, __pic32_tlb_init_values_begin
+ la a2, __pic32_tlb_init_values_end
+ move a3, zero /* index */
+
+ /* Loop through the tables until we have done the correct number of iterations. */
+ /* When the current pointer (a1) points to the end of the table (a2) we are done. */
+1:
+ beq a1, a2, __done_init_tlb /* done */
+
+ /* Create one page table entry consisting of two 16MB physical pages */
+ /* 16MB page mask for Entry 0 */
+ lui t1,0x01FF /* in branch delay slot */
+ ori t1,t1,0xE000
+
+ mtc0 t1, _CP0_PAGEMASK
+
+ /* TLB entry index */
+ mtc0 a3, _CP0_INDEX
+
+ /* Each entry consists of three words */
+ lw t0, 0(a1) /* ENTRYHI */
+ lw t1, 4(a1) /* ENTRYLO0 */
+ lw t2, 8(a1) /* ENTRYLO1 */
+
+ /* physical base address <31:12>, cacheable (write back), dirty, global set */
+ /* First 32MB page in Entrylo0 */
+ mtc0 t1, _CP0_ENTRYLO0
+
+ /* Second 32MB page in EntryLo1 */
+ mtc0 t2, _CP0_ENTRYLO1
+
+ /* virtual base address (ASID 0) */
+ mtc0 t0, _CP0_ENTRYHI
+ ehb
+ tlbwi
+
+ /* Next entry */
+ add a1, 12 /* Point to next entry (WORD_SIZE * 3) */
+ add a3, 1 /* Increment index */
+ b 1b
+ nop
+
+__done_init_tlb:
+ jr ra
+ nop
+
+.size __pic32_tlb_init_ebi_sqi,.-__pic32_tlb_init_ebi_sqi; .end __pic32_tlb_init_ebi_sqi;
+
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0163ea6c/kernel/os/src/arch/pic32/stubs/sbrk.c
----------------------------------------------------------------------
diff --git a/kernel/os/src/arch/pic32/stubs/sbrk.c b/kernel/os/src/arch/pic32/stubs/sbrk.c
new file mode 100644
index 0000000..a59f3c3
--- /dev/null
+++ b/kernel/os/src/arch/pic32/stubs/sbrk.c
@@ -0,0 +1,305 @@
+#ident "c/stubs/sbrk.c: Copyright (c) MIPS Technologies, Inc. All rights reserved."
+
+/*
+ * Unpublished work (c) MIPS Technologies, Inc. All rights reserved.
+ * Unpublished rights reserved under the copyright laws of the United
+ * States of America and other countries.
+ *
+ * This code is confidential and proprietary to MIPS Technologies,
+ * Inc. ("MIPS Technologies") and may be disclosed only as permitted in
+ * writing by MIPS Technologies. Any copying, reproducing, modifying,
+ * use or disclosure of this code (in whole or in part) that is not
+ * expressly permitted in writing by MIPS Technologies is strictly
+ * prohibited. At a minimum, this code is protected under trade secret,
+ * unfair competition, and copyright laws. Violations thereof may result
+ * in criminal penalties and fines.
+ *
+ * MIPS Technologies reserves the right to change this code to improve
+ * function, design or otherwise. MIPS Technologies does not assume any
+ * liability arising out of the application or use of this code, or of
+ * any error or omission in such code. Any warranties, whether express,
+ * statutory, implied or otherwise, including but not limited to the
+ * implied warranties of merchantability or fitness for a particular
+ * purpose, are excluded. Except as expressly provided in any written
+ * license agreement from MIPS Technologies, the furnishing of this
+ * code does not give recipient any license to any intellectual property
+ * rights, including any patent rights, that cover this code.
+ *
+ * This code shall not be exported, reexported, transferred, or released,
+ * directly or indirectly, in violation of the law of any country or
+ * international law, regulation, treaty, Executive Order, statute,
+ * amendments or supplements thereto. Should a conflict arise regarding
+ * the export, reexport, transfer, or release of this code, the laws of
+ * the United States of America shall be the governing law.
+ *
+ * This code may only be disclosed to the United States government
+ * ("Government"), or to Government users, with prior written consent
+ * from MIPS Technologies. This code constitutes one or more of the
+ * following: commercial computer software, commercial computer software
+ * documentation or other commercial items. If the user of this code,
+ * or any related documentation of any kind, including related technical
+ * data or manuals, is an agency, department, or other entity of the
+ * Government, the use, duplication, reproduction, release, modification,
+ * disclosure, or transfer of this code, or any related documentation
+ * of any kind, is restricted in accordance with Federal Acquisition
+ * Regulation 12.212 for civilian agencies and Defense Federal Acquisition
+ * Regulation Supplement 227.7202 for military agencies. The use of this
+ * code by the Government is further restricted in accordance with the
+ * terms of the license agreement(s) and/or applicable contract terms
+ * and conditions covering this code from MIPS Technologies.
+ *
+ *
+ */
+
+/*
+ * sbrk.c: a generic sbrk() emulation.
+ */
+
+#include <string.h>
+#include <errno.h>
+
+#include <sys/kmem.h>
+
+/* memory layout */
+struct sbd_region {
+ _paddr_t base;
+ size_t size;
+ int type;
+};
+
+/* _minbrk and _maxbrk can be set by startup code, or by a linker
+ script, so we don't want them in bss where they'll get cleared, so
+ they can't be common, but they must be capable of being
+ overridden. */
+void * _minbrk __attribute__((weak)) = 0;
+void * _maxbrk __attribute__((weak)) = 0;
+
+extern int errno;
+extern char _end[];
+
+#if 0
+static pthread_mutex_t sbmx = PTHREAD_MUTEX_INITIALIZER;
+#endif
+
+static void * curbrk = 0;
+
+#ifndef MINHEAP
+#define MINHEAP (1 * 1024)
+#endif
+
+#ifndef MAXSTACK
+#define MAXSTACK (32 * 1024)
+#endif
+
+#ifndef PAGESIZE
+#define PAGESIZE 128
+#endif
+
+#define SBD_MEM_END 0
+#define SBD_MEM_RAM 1
+
+int
+getpagesize ()
+{
+ return PAGESIZE;
+}
+
+
+/*
+ * The _sbd_memlayout() function returns a pointer to a phys memory
+ * region table, but note that at present sbrk() only uses the first
+ * entry.
+ *
+ * This function can be overridden by the board-specific code
+ * if it has some other way to determine the real size of
+ * physical memory (e.g. reading the memory controller).
+ */
+
+const struct sbd_region * _sbd_memlayout (void);
+#pragma weak _sbd_memlayout=_stub_sbd_memlayout
+const struct sbd_region *_stub_sbd_memlayout (void);
+
+const struct sbd_region *
+_stub_sbd_memlayout (void)
+{
+ static struct sbd_region mem[2];
+ extern char _heap[];
+ extern char _min_heap_size[];
+
+ mem[0].type = SBD_MEM_RAM;
+ mem[0].base = (_paddr_t)(&_heap);
+ mem[0].size = (size_t)(&_min_heap_size);
+
+ return mem;
+}
+
+
+/*
+ * Initialise the sbrk heap.
+ *
+ * This function is hard-wired to the idea that the code is linked to
+ * KSEG0 or KSEG1 addresses. It could just about cope with being
+ * linked to run in KUSEG, as long as there's a one-to-one mapping
+ * from virtual to physical address. If you are playing real virtual
+ * memory games then the functions in the module will have to be
+ * replaced.
+ */
+
+void
+_sbrk_init (void)
+{
+ const struct sbd_region * layout;
+ void * minva, * maxva;
+ _paddr_t rbase, rtop, min, max;
+ extern char _heap[];
+ extern char _min_heap_size[];
+
+ if (curbrk)
+ return;
+
+ if (_minbrk)
+ /* user specified heap start */
+ minva = _minbrk;
+ else
+ /* usually heap starts after data & bss segment */
+#if (__C32_VERSION__ > 200)
+ minva = &_heap;
+#else
+ minva = _end;
+#endif
+
+ if (_maxbrk)
+ /* user specified heap top */
+ maxva = _maxbrk;
+ else {
+ /* usually stack is at top of memory, and
+ heap grows up towards base of stack */
+#if (__C32_VERSION__ > 200)
+ maxva = (void*)(&_heap) + (size_t)(&_min_heap_size);
+#else
+ char * sp;
+ __asm__ ("move %0,$sp" : "=d" (sp));
+ maxva = sp - MAXSTACK;
+#endif
+ }
+
+ /* convert min/max to physical addresses */
+ if (IS_KVA01 (minva))
+ min = KVA_TO_PA (minva);
+ else
+ /* use virtual address */
+ min = (_paddr_t) minva;
+
+ if (IS_KVA01 (maxva))
+ max = KVA_TO_PA (maxva);
+ else
+ max = (_paddr_t) maxva;
+
+ /* determine physical memory layout */
+ layout = _sbd_memlayout ();
+
+ /* base of heap must be inside memory region #0 */
+ rbase = layout[0].base;
+ rtop = rbase + layout[0].size;
+ if (min < rbase || min >= rtop) {
+ if (rbase >= KVA_TO_PA (_end))
+ /* no overlap of region with data - use region base */
+ min = rbase;
+ else
+ /* can't determine a good heap base */
+ /* XXX could try _end in case of bad _minbrk setting */
+ return;
+ }
+
+ /* end of heap must be inside memory region #0 (and above base) */
+ if (max < min || max >= rtop) {
+ if (rtop > min)
+ /* use top of region as top of heap */
+ /* XXX what about poss overlap with stack? */
+ max = rtop;
+ else
+ /* can't determine a good heap top */
+ return;
+ }
+
+ /* put minbrk/maxbrk in same kernel virtual segment as data */
+ if (IS_KVA1 (_end)) {
+ /* kseg1: uncached data segment */
+ _minbrk = PA_TO_KVA1 (min);
+ _maxbrk = PA_TO_KVA1 (max);
+ }
+ else if (IS_KVA0 (_end)) {
+ /* kseg0: cached data segmnt */
+ _minbrk = PA_TO_KVA0 (min);
+ _maxbrk = PA_TO_KVA0 (max);
+ }
+ else {
+ /* kuseg: use virtual addresses */
+ _minbrk = (void *) min;
+ _minbrk = (void *) max;
+ }
+
+ curbrk = _minbrk;
+}
+
+
+void *
+_sbrk (int n)
+{
+ void *newbrk, *p;
+
+#if 0
+ pthread_mutex_lock (&sbmx);
+#endif
+ if (!curbrk) {
+ _sbrk_init ();
+ if (!curbrk) {
+ errno = ENOMEM;
+#if 0
+ pthread_mutex_unlock (&sbmx);
+#endif
+ return (void *)-1;
+ }
+ }
+
+ p = curbrk;
+ newbrk = curbrk + n;
+ if (n > 0) {
+ if (newbrk < curbrk || newbrk > _maxbrk) {
+ errno = ENOMEM;
+#if 0
+ pthread_mutex_unlock (&sbmx);
+#endif
+ return (void *)-1;
+ }
+ } else {
+ if (newbrk > curbrk || newbrk < _minbrk) {
+ errno = EINVAL;
+#if 0
+ pthread_mutex_unlock (&sbmx);
+#endif
+ return (void *)-1;
+ }
+ }
+ curbrk = newbrk;
+
+#if 0
+ pthread_mutex_unlock (&sbmx);
+#endif
+
+ return p;
+}
+
+void *
+sbrk (int n)
+{
+ void *p;
+
+ p = _sbrk(n);
+
+ /* sbrk defined to return zeroed pages */
+ if ((n > 0) && (p != (void *)-1))
+ memset (p, 0, n);
+
+ return p;
+}
[22/40] incubator-mynewt-core git commit: MYNEWT-741 Lora cleanup
Posted by ja...@apache.org.
MYNEWT-741 Lora cleanup
* Combine lora_misc.c and timer.c --> utilities.c
* Use existing swap_buf() instead of new memcpyr().
* Add Apache header to utilities.c
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/1eb96f4d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/1eb96f4d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/1eb96f4d
Branch: refs/heads/bluetooth5
Commit: 1eb96f4dc3d034bfd6584238713ce15a471a77f0
Parents: 3fe2ef7
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Apr 27 15:43:37 2017 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Fri Apr 28 17:27:52 2017 -0700
----------------------------------------------------------------------
net/lora/node/include/node/mac/LoRaMac.h | 2 +-
net/lora/node/include/node/timer.h | 38 ---------------
net/lora/node/include/node/utilities.h | 25 ++++++----
net/lora/node/src/mac/LoRaMac.c | 6 +--
net/lora/node/src/misc.c | 45 ------------------
net/lora/node/src/timer.c | 15 ------
net/lora/node/src/utilities.c | 67 +++++++++++++++++++++++++++
7 files changed, 87 insertions(+), 111 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1eb96f4d/net/lora/node/include/node/mac/LoRaMac.h
----------------------------------------------------------------------
diff --git a/net/lora/node/include/node/mac/LoRaMac.h b/net/lora/node/include/node/mac/LoRaMac.h
index 4613f8d..5619387 100644
--- a/net/lora/node/include/node/mac/LoRaMac.h
+++ b/net/lora/node/include/node/mac/LoRaMac.h
@@ -48,7 +48,7 @@
// Includes board dependent definitions such as channels frequencies
#include "LoRaMac-definitions.h"
-#include "node/timer.h"
+#include "node/utilities.h"
/*!
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1eb96f4d/net/lora/node/include/node/timer.h
----------------------------------------------------------------------
diff --git a/net/lora/node/include/node/timer.h b/net/lora/node/include/node/timer.h
deleted file mode 100644
index 424dc32..0000000
--- a/net/lora/node/include/node/timer.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- / _____) _ | |
-((____ _____ ____ _| |_ _____ ____| |__
- \____ \| ___ | (_ _) ___ |/ ___) _ \
- _____)) ____| | | || |_| ____((___| | | |
-(______/|_____)_|_|_| \__)_____)\____)_| |_|
- (C)2013 Semtech
-
-Description: Timer objects and scheduling management
-
-License: Revised BSD License, see LICENSE.TXT file include in the project
-
-Maintainer: Miguel Luis and Gregory Cristian
-*/
-#ifndef __TIMER_H__
-#define __TIMER_H__
-
-#include <inttypes.h>
-#include <stdbool.h>
-struct hal_timer;
-
-/*!
- * \brief Return the Time elapsed since a fix moment in Time
- *
- * \param [IN] savedTime fix moment in Time
- * \retval time returns elapsed time
- */
-uint32_t TimerGetElapsedTime(uint32_t savedTime);
-
-/*!
- * \brief Return the Time elapsed since a fix moment in Time
- *
- * \param [IN] eventInFuture fix moment in the future
- * \retval time returns difference between now and future event
- */
-uint32_t TimerGetFutureTime(uint32_t eventInFuture);
-
-#endif // __TIMER_H__
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1eb96f4d/net/lora/node/include/node/utilities.h
----------------------------------------------------------------------
diff --git a/net/lora/node/include/node/utilities.h b/net/lora/node/include/node/utilities.h
index 8816351..44ab629 100644
--- a/net/lora/node/include/node/utilities.h
+++ b/net/lora/node/include/node/utilities.h
@@ -53,15 +53,6 @@ Maintainer: Miguel Luis and Gregory Cristian
int32_t randr( int32_t min, int32_t max );
/*!
- * \brief Copies size elements of src array to dst array reversing the byte order
- *
- * \param [OUT] dst Destination array
- * \param [IN] src Source array
- * \param [IN] size Number of bytes to be copied
- */
-void memcpyr( uint8_t *dst, const uint8_t *src, uint16_t size );
-
-/*!
* \brief Converts a nibble to an hexadecimal character
*
* \param [IN] a Nibble to be converted
@@ -69,4 +60,20 @@ void memcpyr( uint8_t *dst, const uint8_t *src, uint16_t size );
*/
int8_t Nibble2HexChar( uint8_t a );
+/*!
+ * \brief Return the Time elapsed since a fix moment in Time
+ *
+ * \param [IN] savedTime fix moment in Time
+ * \retval time returns elapsed time
+ */
+uint32_t TimerGetElapsedTime( uint32_t savedTime );
+
+/*!
+ * \brief Return the Time elapsed since a fix moment in Time
+ *
+ * \param [IN] eventInFuture fix moment in the future
+ * \retval time returns difference between now and future event
+ */
+uint32_t TimerGetFutureTime( uint32_t eventInFuture );
+
#endif // __UTILITIES_H__
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1eb96f4d/net/lora/node/src/mac/LoRaMac.c
----------------------------------------------------------------------
diff --git a/net/lora/node/src/mac/LoRaMac.c b/net/lora/node/src/mac/LoRaMac.c
index 473e56e..cb8f942 100644
--- a/net/lora/node/src/mac/LoRaMac.c
+++ b/net/lora/node/src/mac/LoRaMac.c
@@ -28,8 +28,8 @@ Maintainer: Miguel Luis ( Semtech ), Gregory Cristian ( Semtech ) and Daniel Jä
#include "node/mac/LoRaMac.h"
#include "node/mac/LoRaMacTest.h"
+#include "os/os.h"
#include "hal/hal_timer.h"
-#include "os/os_cputime.h"
#include "lora_priv.h"
@@ -3120,9 +3120,9 @@ LoRaMacStatus_t PrepareFrame( LoRaMacHeader_t *macHdr, LoRaMacFrameCtrl_t *fCtrl
LoRaMacBufferPktLen = pktHeaderLen;
- memcpyr( LoRaMacBuffer + LoRaMacBufferPktLen, LoRaMacAppEui, 8 );
+ swap_buf( LoRaMacBuffer + LoRaMacBufferPktLen, LoRaMacAppEui, 8 );
LoRaMacBufferPktLen += 8;
- memcpyr( LoRaMacBuffer + LoRaMacBufferPktLen, LoRaMacDevEui, 8 );
+ swap_buf( LoRaMacBuffer + LoRaMacBufferPktLen, LoRaMacDevEui, 8 );
LoRaMacBufferPktLen += 8;
LoRaMacDevNonce = Radio.Random( );
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1eb96f4d/net/lora/node/src/misc.c
----------------------------------------------------------------------
diff --git a/net/lora/node/src/misc.c b/net/lora/node/src/misc.c
deleted file mode 100644
index 3d4576a..0000000
--- a/net/lora/node/src/misc.c
+++ /dev/null
@@ -1,45 +0,0 @@
-#include <stdlib.h>
-
-#include "syscfg/syscfg.h"
-#include "node/utilities.h"
-#include "lora_priv.h"
-
-int32_t
-randr(int32_t min, int32_t max)
-{
- return rand() % (max - min + 1) + min;
-}
-
-void
-memcpyr( uint8_t *dst, const uint8_t *src, uint16_t size )
-{
- dst = dst + ( size - 1 );
- while( size-- )
- {
- *dst-- = *src++;
- }
-}
-
-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);
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1eb96f4d/net/lora/node/src/timer.c
----------------------------------------------------------------------
diff --git a/net/lora/node/src/timer.c b/net/lora/node/src/timer.c
deleted file mode 100644
index d445b01..0000000
--- a/net/lora/node/src/timer.c
+++ /dev/null
@@ -1,15 +0,0 @@
-#include "os/os.h"
-#include "node/timer.h"
-#include "node/utilities.h"
-
-uint32_t
-TimerGetElapsedTime(uint32_t savedTime)
-{
- return savedTime - os_cputime_get32();
-}
-
-uint32_t
-TimerGetFutureTime(uint32_t eventInFuture)
-{
- return os_cputime_get32() + eventInFuture;
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1eb96f4d/net/lora/node/src/utilities.c
----------------------------------------------------------------------
diff --git a/net/lora/node/src/utilities.c b/net/lora/node/src/utilities.c
new file mode 100644
index 0000000..2122a86
--- /dev/null
+++ b/net/lora/node/src/utilities.c
@@ -0,0 +1,67 @@
+/*
+ * 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.
+ */
+
+#include <stdlib.h>
+
+#include "syscfg/syscfg.h"
+#include "os/os.h"
+#include "node/utilities.h"
+#include "lora_priv.h"
+
+int32_t
+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)
+{
+ return savedTime - os_cputime_get32();
+}
+
+uint32_t
+TimerGetFutureTime(uint32_t eventInFuture)
+{
+ return os_cputime_get32() + eventInFuture;
+}
[09/40] incubator-mynewt-core git commit: MYNEWT-741 Port of
LoRaMac-node library
Posted by ja...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/560fa920/hw/drivers/lora/sx1276/src/sx1276.c
----------------------------------------------------------------------
diff --git a/hw/drivers/lora/sx1276/src/sx1276.c b/hw/drivers/lora/sx1276/src/sx1276.c
new file mode 100644
index 0000000..82c85a2
--- /dev/null
+++ b/hw/drivers/lora/sx1276/src/sx1276.c
@@ -0,0 +1,1824 @@
+/*
+ / _____) _ | |
+( (____ _____ ____ _| |_ _____ ____| |__
+ \____ \| ___ | (_ _) ___ |/ ___) _ \
+ _____) ) ____| | | || |_| ____( (___| | | |
+(______/|_____)_|_|_| \__)_____)\____)_| |_|
+ (C)2013 Semtech
+
+Description: Generic SX1276 driver implementation
+
+License: Revised BSD License, see LICENSE.TXT file include in the project
+
+Maintainer: Miguel Luis, Gregory Cristian and Wael Guibene
+*/
+#include <assert.h>
+#include <math.h>
+#include <string.h>
+#include "sysinit/sysinit.h"
+#include "syscfg/syscfg.h"
+#include "hal/hal_gpio.h"
+#include "hal/hal_spi.h"
+#include "bsp/bsp.h"
+#include "os/os.h"
+#include "node/lora.h"
+#include "node/radio.h"
+#include "sx1276.h"
+#include "sx1276-board.h"
+
+/*
+ * Local types definition
+ */
+
+/*!
+ * Radio registers definition
+ */
+typedef struct
+{
+ RadioModems_t Modem;
+ uint8_t Addr;
+ uint8_t Value;
+}RadioRegisters_t;
+
+/*!
+ * FSK bandwidth definition
+ */
+typedef struct
+{
+ uint32_t bandwidth;
+ uint8_t RegValue;
+}FskBandwidth_t;
+
+
+/*
+ * Private functions prototypes
+ */
+
+/*!
+ * Performs the Rx chain calibration for LF and HF bands
+ * \remark Must be called just after the reset so all registers are at their
+ * default values
+ */
+static void RxChainCalibration( void );
+
+/*!
+ * \brief Resets the SX1276
+ */
+void SX1276Reset( void );
+
+/*!
+ * \brief Sets the SX1276 in transmission mode for the given time
+ * \param [IN] timeout Transmission timeout [ms] [0: continuous, others timeout]
+ */
+void SX1276SetTx( uint32_t timeout );
+
+/*!
+ * \brief Writes the buffer contents to the SX1276 FIFO
+ *
+ * \param [IN] buffer Buffer containing data to be put on the FIFO.
+ * \param [IN] size Number of bytes to be written to the FIFO
+ */
+void SX1276WriteFifo( uint8_t *buffer, uint8_t size );
+
+/*!
+ * \brief Reads the contents of the SX1276 FIFO
+ *
+ * \param [OUT] buffer Buffer where to copy the FIFO read data.
+ * \param [IN] size Number of bytes to be read from the FIFO
+ */
+void SX1276ReadFifo( uint8_t *buffer, uint8_t size );
+
+/*!
+ * \brief Sets the SX1276 operating mode
+ *
+ * \param [IN] opMode New operating mode
+ */
+void SX1276SetOpMode( uint8_t opMode );
+
+/*
+ * SX1276 DIO IRQ callback functions prototype
+ */
+
+/*!
+ * \brief DIO 0 IRQ callback
+ */
+void SX1276OnDio0Irq(void *unused);
+
+/*!
+ * \brief DIO 1 IRQ callback
+ */
+void SX1276OnDio1Irq(void *unused);
+
+/*!
+ * \brief DIO 2 IRQ callback
+ */
+void SX1276OnDio2Irq(void *unused);
+
+/*!
+ * \brief DIO 3 IRQ callback
+ */
+void SX1276OnDio3Irq(void *unused);
+
+/*!
+ * \brief DIO 4 IRQ callback
+ */
+void SX1276OnDio4Irq(void *unused);
+
+/*!
+ * \brief DIO 5 IRQ callback
+ */
+void SX1276OnDio5Irq(void *unused);
+
+/*!
+ * \brief Tx & Rx timeout timer callback
+ */
+void SX1276OnTimeoutIrq(void *unused);
+
+/*
+ * Private global constants
+ */
+
+/*!
+ * Radio hardware registers initialization
+ *
+ * \remark RADIO_INIT_REGISTERS_VALUE is defined in sx1276-board.h file
+ */
+const RadioRegisters_t RadioRegsInit[] = RADIO_INIT_REGISTERS_VALUE;
+
+/*!
+ * Constant values need to compute the RSSI value
+ */
+#define RSSI_OFFSET_LF -164
+#define RSSI_OFFSET_HF -157
+
+/*!
+ * Precomputed FSK bandwidth registers values
+ */
+const FskBandwidth_t FskBandwidths[] =
+{
+ { 2600 , 0x17 },
+ { 3100 , 0x0F },
+ { 3900 , 0x07 },
+ { 5200 , 0x16 },
+ { 6300 , 0x0E },
+ { 7800 , 0x06 },
+ { 10400 , 0x15 },
+ { 12500 , 0x0D },
+ { 15600 , 0x05 },
+ { 20800 , 0x14 },
+ { 25000 , 0x0C },
+ { 31300 , 0x04 },
+ { 41700 , 0x13 },
+ { 50000 , 0x0B },
+ { 62500 , 0x03 },
+ { 83333 , 0x12 },
+ { 100000, 0x0A },
+ { 125000, 0x02 },
+ { 166700, 0x11 },
+ { 200000, 0x09 },
+ { 250000, 0x01 },
+ { 300000, 0x00 }, // Invalid Bandwidth
+};
+
+/*!
+ * Radio callbacks variable
+ */
+static RadioEvents_t *RadioEvents;
+
+/*!
+ * Reception buffer
+ */
+static uint8_t RxTxBuffer[RX_BUFFER_SIZE];
+
+/*
+ * Public global variables
+ */
+
+/*!
+ * Radio hardware and global parameters
+ */
+SX1276_t SX1276;
+
+/*!
+ * Hardware DIO IRQ callback initialization
+ */
+DioIrqHandler *DioIrq[] = { SX1276OnDio0Irq, SX1276OnDio1Irq,
+ SX1276OnDio2Irq, SX1276OnDio3Irq,
+ SX1276OnDio4Irq, NULL };
+
+/*!
+ * Tx and Rx timers
+ */
+struct hal_timer TxTimeoutTimer;
+struct hal_timer RxTimeoutTimer;
+struct hal_timer RxTimeoutSyncWord;
+
+static uint32_t rx_timeout_sync_delay = -1;
+
+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 );
+ }
+}
+
+static void
+SX1276RxError( void )
+{
+ STATS_INC(lora_stats, rx_error);
+
+ if( ( RadioEvents != NULL ) && ( RadioEvents->RxError != NULL ) )
+ {
+ RadioEvents->RxError( );
+ }
+}
+
+static void
+SX1276RxTimeout( void )
+{
+ STATS_INC(lora_stats, rx_timeout);
+
+ if( ( RadioEvents != NULL ) && ( RadioEvents->RxTimeout != NULL ) )
+ {
+ RadioEvents->RxTimeout( );
+ }
+}
+
+static void
+SX1276TxDone( void )
+{
+ STATS_INC(lora_stats, tx_success);
+
+ if( ( RadioEvents != NULL ) && ( RadioEvents->TxDone != NULL ) )
+ {
+ RadioEvents->TxDone( );
+ }
+}
+
+static void
+SX1276TxTimeout( void )
+{
+ STATS_INC(lora_stats, tx_timeout);
+
+ if( ( RadioEvents != NULL ) && ( RadioEvents->TxTimeout != NULL ) )
+ {
+ RadioEvents->TxTimeout( );
+ }
+}
+
+/*
+ * Radio driver functions implementation
+ */
+
+void SX1276Init( RadioEvents_t *events )
+{
+ uint8_t i;
+
+ RadioEvents = events;
+
+ // Initialize driver timeout timers
+ os_cputime_timer_init(&TxTimeoutTimer, SX1276OnTimeoutIrq, NULL);
+ os_cputime_timer_init(&RxTimeoutTimer, SX1276OnTimeoutIrq, NULL);
+ os_cputime_timer_init(&RxTimeoutSyncWord, SX1276OnTimeoutIrq, NULL);
+
+ SX1276IoInit( );
+ SX1276IoIrqInit( DioIrq );
+
+ SX1276Reset( );
+
+ RxChainCalibration( );
+
+ SX1276SetOpMode( RF_OPMODE_SLEEP );
+
+ for( i = 0; i < sizeof( RadioRegsInit ) / sizeof( RadioRegisters_t ); i++ )
+ {
+ SX1276SetModem( RadioRegsInit[i].Modem );
+ SX1276Write( RadioRegsInit[i].Addr, RadioRegsInit[i].Value );
+ }
+
+ SX1276SetModem( MODEM_FSK );
+
+ SX1276.Settings.State = RF_IDLE;
+}
+
+RadioState_t SX1276GetStatus( void )
+{
+ return SX1276.Settings.State;
+}
+
+void SX1276SetChannel( uint32_t freq )
+{
+ SX1276.Settings.Channel = freq;
+ freq = ( uint32_t )( ( double )freq / ( double )FREQ_STEP );
+ SX1276Write( REG_FRFMSB, ( uint8_t )( ( freq >> 16 ) & 0xFF ) );
+ SX1276Write( REG_FRFMID, ( uint8_t )( ( freq >> 8 ) & 0xFF ) );
+ SX1276Write( REG_FRFLSB, ( uint8_t )( freq & 0xFF ) );
+}
+
+bool SX1276IsChannelFree( RadioModems_t modem, uint32_t freq, int16_t rssiThresh )
+{
+ int16_t rssi = 0;
+
+ SX1276SetModem( modem );
+
+ SX1276SetChannel( freq );
+
+ SX1276SetOpMode( RF_OPMODE_RECEIVER );
+
+ os_cputime_delay_usecs(1000);
+
+ rssi = SX1276ReadRssi( modem );
+
+ SX1276SetSleep( );
+
+ if( rssi > rssiThresh )
+ {
+ return false;
+ }
+ return true;
+}
+
+uint32_t SX1276Random( void )
+{
+ uint8_t i;
+ uint32_t rnd = 0;
+
+ /*
+ * Radio setup for random number generation
+ */
+ // Set LoRa modem ON
+ SX1276SetModem( MODEM_LORA );
+
+ // Disable LoRa modem interrupts
+ SX1276Write( REG_LR_IRQFLAGSMASK, RFLR_IRQFLAGS_RXTIMEOUT |
+ RFLR_IRQFLAGS_RXDONE |
+ RFLR_IRQFLAGS_PAYLOADCRCERROR |
+ RFLR_IRQFLAGS_VALIDHEADER |
+ RFLR_IRQFLAGS_TXDONE |
+ RFLR_IRQFLAGS_CADDONE |
+ RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL |
+ RFLR_IRQFLAGS_CADDETECTED );
+
+ // Set radio in continuous reception
+ SX1276SetOpMode( RF_OPMODE_RECEIVER );
+
+ for( i = 0; i < 32; i++ )
+ {
+ os_cputime_delay_usecs(1000);
+ // Unfiltered RSSI value reading. Only takes the LSB value
+ rnd |= ( ( uint32_t )SX1276Read( REG_LR_RSSIWIDEBAND ) & 0x01 ) << i;
+ }
+
+ SX1276SetSleep( );
+
+ return rnd;
+}
+
+/*!
+ * Performs the Rx chain calibration for LF and HF bands
+ * \remark Must be called just after the reset so all registers are at their
+ * default values
+ */
+static void RxChainCalibration( void )
+{
+ uint8_t regPaConfigInitVal;
+ uint32_t initialFreq;
+
+ // Save context
+ regPaConfigInitVal = SX1276Read( REG_PACONFIG );
+ initialFreq = ( double )( ( ( uint32_t )SX1276Read( REG_FRFMSB ) << 16 ) |
+ ( ( uint32_t )SX1276Read( REG_FRFMID ) << 8 ) |
+ ( ( uint32_t )SX1276Read( REG_FRFLSB ) ) ) * ( double )FREQ_STEP;
+
+ // Cut the PA just in case, RFO output, power = -1 dBm
+ SX1276Write( REG_PACONFIG, 0x00 );
+
+ // Launch Rx chain calibration for LF band
+ SX1276Write( REG_IMAGECAL, ( SX1276Read( REG_IMAGECAL ) & RF_IMAGECAL_IMAGECAL_MASK ) | RF_IMAGECAL_IMAGECAL_START );
+ while( ( SX1276Read( REG_IMAGECAL ) & RF_IMAGECAL_IMAGECAL_RUNNING ) == RF_IMAGECAL_IMAGECAL_RUNNING )
+ {
+ }
+
+ // Sets a Frequency in HF band
+ SX1276SetChannel( 868000000 );
+
+ // Launch Rx chain calibration for HF band
+ SX1276Write( REG_IMAGECAL, ( SX1276Read( REG_IMAGECAL ) & RF_IMAGECAL_IMAGECAL_MASK ) | RF_IMAGECAL_IMAGECAL_START );
+ while( ( SX1276Read( REG_IMAGECAL ) & RF_IMAGECAL_IMAGECAL_RUNNING ) == RF_IMAGECAL_IMAGECAL_RUNNING )
+ {
+ }
+
+ // Restore context
+ SX1276Write( REG_PACONFIG, regPaConfigInitVal );
+ SX1276SetChannel( initialFreq );
+}
+
+/*!
+ * Returns the known FSK bandwidth registers value
+ *
+ * \param [IN] bandwidth Bandwidth value in Hz
+ * \retval regValue Bandwidth register value.
+ */
+static uint8_t GetFskBandwidthRegValue( uint32_t bandwidth )
+{
+ uint8_t i;
+
+ for( i = 0; i < ( sizeof( FskBandwidths ) / sizeof( FskBandwidth_t ) ) - 1; i++ )
+ {
+ if( ( bandwidth >= FskBandwidths[i].bandwidth ) && ( bandwidth < FskBandwidths[i + 1].bandwidth ) )
+ {
+ return FskBandwidths[i].RegValue;
+ }
+ }
+ // ERROR: Value not found
+ while( 1 );
+}
+
+void SX1276SetRxConfig( 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 )
+{
+ SX1276SetModem( modem );
+
+ switch( modem )
+ {
+ case MODEM_FSK:
+ {
+ SX1276.Settings.Fsk.Bandwidth = bandwidth;
+ SX1276.Settings.Fsk.Datarate = datarate;
+ SX1276.Settings.Fsk.BandwidthAfc = bandwidthAfc;
+ SX1276.Settings.Fsk.FixLen = fixLen;
+ SX1276.Settings.Fsk.PayloadLen = payloadLen;
+ SX1276.Settings.Fsk.CrcOn = crcOn;
+ SX1276.Settings.Fsk.IqInverted = iqInverted;
+ SX1276.Settings.Fsk.RxContinuous = rxContinuous;
+ SX1276.Settings.Fsk.PreambleLen = preambleLen;
+
+ datarate = ( uint16_t )( ( double )XTAL_FREQ / ( double )datarate );
+ SX1276Write( REG_BITRATEMSB, ( uint8_t )( datarate >> 8 ) );
+ SX1276Write( REG_BITRATELSB, ( uint8_t )( datarate & 0xFF ) );
+
+ SX1276Write( REG_RXBW, GetFskBandwidthRegValue( bandwidth ) );
+ SX1276Write( REG_AFCBW, GetFskBandwidthRegValue( bandwidthAfc ) );
+
+ SX1276Write( REG_PREAMBLEMSB, ( uint8_t )( ( preambleLen >> 8 ) & 0xFF ) );
+ SX1276Write( REG_PREAMBLELSB, ( uint8_t )( preambleLen & 0xFF ) );
+
+ if( fixLen == 1 )
+ {
+ SX1276Write( REG_PAYLOADLENGTH, payloadLen );
+ }
+ else
+ {
+ SX1276Write( REG_PAYLOADLENGTH, 0xFF ); // Set payload length to the maximum
+ }
+
+ SX1276Write( REG_PACKETCONFIG1,
+ ( SX1276Read( REG_PACKETCONFIG1 ) &
+ RF_PACKETCONFIG1_CRC_MASK &
+ RF_PACKETCONFIG1_PACKETFORMAT_MASK ) |
+ ( ( fixLen == 1 ) ? RF_PACKETCONFIG1_PACKETFORMAT_FIXED : RF_PACKETCONFIG1_PACKETFORMAT_VARIABLE ) |
+ ( crcOn << 4 ) );
+ }
+ break;
+ case MODEM_LORA:
+ {
+ if( bandwidth > 2 )
+ {
+ // Fatal error: When using LoRa modem only bandwidths 125, 250 and 500 kHz are supported
+ while( 1 );
+ }
+ bandwidth += 7;
+ SX1276.Settings.LoRa.Bandwidth = bandwidth;
+ SX1276.Settings.LoRa.Datarate = datarate;
+ SX1276.Settings.LoRa.Coderate = coderate;
+ SX1276.Settings.LoRa.PreambleLen = preambleLen;
+ SX1276.Settings.LoRa.FixLen = fixLen;
+ SX1276.Settings.LoRa.PayloadLen = payloadLen;
+ SX1276.Settings.LoRa.CrcOn = crcOn;
+ SX1276.Settings.LoRa.FreqHopOn = freqHopOn;
+ SX1276.Settings.LoRa.HopPeriod = hopPeriod;
+ SX1276.Settings.LoRa.IqInverted = iqInverted;
+ SX1276.Settings.LoRa.RxContinuous = rxContinuous;
+
+ if( datarate > 12 )
+ {
+ datarate = 12;
+ }
+ else if( datarate < 6 )
+ {
+ datarate = 6;
+ }
+
+ if( ( ( bandwidth == 7 ) && ( ( datarate == 11 ) || ( datarate == 12 ) ) ) ||
+ ( ( bandwidth == 8 ) && ( datarate == 12 ) ) )
+ {
+ SX1276.Settings.LoRa.LowDatarateOptimize = 0x01;
+ }
+ else
+ {
+ SX1276.Settings.LoRa.LowDatarateOptimize = 0x00;
+ }
+
+ SX1276Write( REG_LR_MODEMCONFIG1,
+ ( SX1276Read( REG_LR_MODEMCONFIG1 ) &
+ RFLR_MODEMCONFIG1_BW_MASK &
+ RFLR_MODEMCONFIG1_CODINGRATE_MASK &
+ RFLR_MODEMCONFIG1_IMPLICITHEADER_MASK ) |
+ ( bandwidth << 4 ) | ( coderate << 1 ) |
+ fixLen );
+
+ SX1276Write( REG_LR_MODEMCONFIG2,
+ ( SX1276Read( REG_LR_MODEMCONFIG2 ) &
+ RFLR_MODEMCONFIG2_SF_MASK &
+ RFLR_MODEMCONFIG2_RXPAYLOADCRC_MASK &
+ RFLR_MODEMCONFIG2_SYMBTIMEOUTMSB_MASK ) |
+ ( datarate << 4 ) | ( crcOn << 2 ) |
+ ( ( symbTimeout >> 8 ) & ~RFLR_MODEMCONFIG2_SYMBTIMEOUTMSB_MASK ) );
+
+ SX1276Write( REG_LR_MODEMCONFIG3,
+ ( SX1276Read( REG_LR_MODEMCONFIG3 ) &
+ RFLR_MODEMCONFIG3_LOWDATARATEOPTIMIZE_MASK ) |
+ ( SX1276.Settings.LoRa.LowDatarateOptimize << 3 ) );
+
+ SX1276Write( REG_LR_SYMBTIMEOUTLSB, ( uint8_t )( symbTimeout & 0xFF ) );
+
+ SX1276Write( REG_LR_PREAMBLEMSB, ( uint8_t )( ( preambleLen >> 8 ) & 0xFF ) );
+ SX1276Write( REG_LR_PREAMBLELSB, ( uint8_t )( preambleLen & 0xFF ) );
+
+ if( fixLen == 1 )
+ {
+ SX1276Write( REG_LR_PAYLOADLENGTH, payloadLen );
+ }
+
+ if( SX1276.Settings.LoRa.FreqHopOn == true )
+ {
+ SX1276Write( REG_LR_PLLHOP, ( SX1276Read( REG_LR_PLLHOP ) & RFLR_PLLHOP_FASTHOP_MASK ) | RFLR_PLLHOP_FASTHOP_ON );
+ SX1276Write( REG_LR_HOPPERIOD, SX1276.Settings.LoRa.HopPeriod );
+ }
+
+ if( ( bandwidth == 9 ) && ( SX1276.Settings.Channel > RF_MID_BAND_THRESH ) )
+ {
+ // ERRATA 2.1 - Sensitivity Optimization with a 500 kHz Bandwidth
+ SX1276Write( REG_LR_TEST36, 0x02 );
+ SX1276Write( REG_LR_TEST3A, 0x64 );
+ }
+ else if( bandwidth == 9 )
+ {
+ // ERRATA 2.1 - Sensitivity Optimization with a 500 kHz Bandwidth
+ SX1276Write( REG_LR_TEST36, 0x02 );
+ SX1276Write( REG_LR_TEST3A, 0x7F );
+ }
+ else
+ {
+ // ERRATA 2.1 - Sensitivity Optimization with a 500 kHz Bandwidth
+ SX1276Write( REG_LR_TEST36, 0x03 );
+ }
+
+ if( datarate == 6 )
+ {
+ SX1276Write( REG_LR_DETECTOPTIMIZE,
+ ( SX1276Read( REG_LR_DETECTOPTIMIZE ) &
+ RFLR_DETECTIONOPTIMIZE_MASK ) |
+ RFLR_DETECTIONOPTIMIZE_SF6 );
+ SX1276Write( REG_LR_DETECTIONTHRESHOLD,
+ RFLR_DETECTIONTHRESH_SF6 );
+ }
+ else
+ {
+ SX1276Write( REG_LR_DETECTOPTIMIZE,
+ ( SX1276Read( REG_LR_DETECTOPTIMIZE ) &
+ RFLR_DETECTIONOPTIMIZE_MASK ) |
+ RFLR_DETECTIONOPTIMIZE_SF7_TO_SF12 );
+ SX1276Write( REG_LR_DETECTIONTHRESHOLD,
+ RFLR_DETECTIONTHRESH_SF7_TO_SF12 );
+ }
+ }
+ break;
+ }
+}
+
+void SX1276SetTxConfig( 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 )
+{
+ uint8_t paConfig = 0;
+ uint8_t paDac = 0;
+
+ SX1276SetModem( modem );
+
+ paConfig = SX1276Read( REG_PACONFIG );
+ paDac = SX1276Read( REG_PADAC );
+
+ paConfig = ( paConfig & RF_PACONFIG_PASELECT_MASK ) | SX1276GetPaSelect( SX1276.Settings.Channel );
+ paConfig = ( paConfig & RF_PACONFIG_MAX_POWER_MASK ) | 0x70;
+
+ if( ( paConfig & RF_PACONFIG_PASELECT_PABOOST ) == RF_PACONFIG_PASELECT_PABOOST )
+ {
+ if( power > 17 )
+ {
+ paDac = ( paDac & RF_PADAC_20DBM_MASK ) | RF_PADAC_20DBM_ON;
+ }
+ else
+ {
+ paDac = ( paDac & RF_PADAC_20DBM_MASK ) | RF_PADAC_20DBM_OFF;
+ }
+ if( ( paDac & RF_PADAC_20DBM_ON ) == RF_PADAC_20DBM_ON )
+ {
+ if( power < 5 )
+ {
+ power = 5;
+ }
+ if( power > 20 )
+ {
+ power = 20;
+ }
+ paConfig = ( paConfig & RF_PACONFIG_OUTPUTPOWER_MASK ) | ( uint8_t )( ( uint16_t )( power - 5 ) & 0x0F );
+ }
+ else
+ {
+ if( power < 2 )
+ {
+ power = 2;
+ }
+ if( power > 17 )
+ {
+ power = 17;
+ }
+ paConfig = ( paConfig & RF_PACONFIG_OUTPUTPOWER_MASK ) | ( uint8_t )( ( uint16_t )( power - 2 ) & 0x0F );
+ }
+ }
+ else
+ {
+ if( power < -1 )
+ {
+ power = -1;
+ }
+ if( power > 14 )
+ {
+ power = 14;
+ }
+ paConfig = ( paConfig & RF_PACONFIG_OUTPUTPOWER_MASK ) | ( uint8_t )( ( uint16_t )( power + 1 ) & 0x0F );
+ }
+ SX1276Write( REG_PACONFIG, paConfig );
+ SX1276Write( REG_PADAC, paDac );
+
+ switch( modem )
+ {
+ case MODEM_FSK:
+ {
+ SX1276.Settings.Fsk.Power = power;
+ SX1276.Settings.Fsk.Fdev = fdev;
+ SX1276.Settings.Fsk.Bandwidth = bandwidth;
+ SX1276.Settings.Fsk.Datarate = datarate;
+ SX1276.Settings.Fsk.PreambleLen = preambleLen;
+ SX1276.Settings.Fsk.FixLen = fixLen;
+ SX1276.Settings.Fsk.CrcOn = crcOn;
+ SX1276.Settings.Fsk.IqInverted = iqInverted;
+ SX1276.Settings.Fsk.TxTimeout = timeout;
+
+ fdev = ( uint16_t )( ( double )fdev / ( double )FREQ_STEP );
+ SX1276Write( REG_FDEVMSB, ( uint8_t )( fdev >> 8 ) );
+ SX1276Write( REG_FDEVLSB, ( uint8_t )( fdev & 0xFF ) );
+
+ datarate = ( uint16_t )( ( double )XTAL_FREQ / ( double )datarate );
+ SX1276Write( REG_BITRATEMSB, ( uint8_t )( datarate >> 8 ) );
+ SX1276Write( REG_BITRATELSB, ( uint8_t )( datarate & 0xFF ) );
+
+ SX1276Write( REG_PREAMBLEMSB, ( preambleLen >> 8 ) & 0x00FF );
+ SX1276Write( REG_PREAMBLELSB, preambleLen & 0xFF );
+
+ SX1276Write( REG_PACKETCONFIG1,
+ ( SX1276Read( REG_PACKETCONFIG1 ) &
+ RF_PACKETCONFIG1_CRC_MASK &
+ RF_PACKETCONFIG1_PACKETFORMAT_MASK ) |
+ ( ( fixLen == 1 ) ? RF_PACKETCONFIG1_PACKETFORMAT_FIXED : RF_PACKETCONFIG1_PACKETFORMAT_VARIABLE ) |
+ ( crcOn << 4 ) );
+
+ }
+ break;
+ case MODEM_LORA:
+ {
+ SX1276.Settings.LoRa.Power = power;
+ if( bandwidth > 2 )
+ {
+ // Fatal error: When using LoRa modem only bandwidths 125, 250 and 500 kHz are supported
+ while( 1 );
+ }
+ bandwidth += 7;
+ SX1276.Settings.LoRa.Bandwidth = bandwidth;
+ SX1276.Settings.LoRa.Datarate = datarate;
+ SX1276.Settings.LoRa.Coderate = coderate;
+ SX1276.Settings.LoRa.PreambleLen = preambleLen;
+ SX1276.Settings.LoRa.FixLen = fixLen;
+ SX1276.Settings.LoRa.FreqHopOn = freqHopOn;
+ SX1276.Settings.LoRa.HopPeriod = hopPeriod;
+ SX1276.Settings.LoRa.CrcOn = crcOn;
+ SX1276.Settings.LoRa.IqInverted = iqInverted;
+ SX1276.Settings.LoRa.TxTimeout = timeout;
+
+ if( datarate > 12 )
+ {
+ datarate = 12;
+ }
+ else if( datarate < 6 )
+ {
+ datarate = 6;
+ }
+ if( ( ( bandwidth == 7 ) && ( ( datarate == 11 ) || ( datarate == 12 ) ) ) ||
+ ( ( bandwidth == 8 ) && ( datarate == 12 ) ) )
+ {
+ SX1276.Settings.LoRa.LowDatarateOptimize = 0x01;
+ }
+ else
+ {
+ SX1276.Settings.LoRa.LowDatarateOptimize = 0x00;
+ }
+
+ if( SX1276.Settings.LoRa.FreqHopOn == true )
+ {
+ SX1276Write( REG_LR_PLLHOP, ( SX1276Read( REG_LR_PLLHOP ) & RFLR_PLLHOP_FASTHOP_MASK ) | RFLR_PLLHOP_FASTHOP_ON );
+ SX1276Write( REG_LR_HOPPERIOD, SX1276.Settings.LoRa.HopPeriod );
+ }
+
+ SX1276Write( REG_LR_MODEMCONFIG1,
+ ( SX1276Read( REG_LR_MODEMCONFIG1 ) &
+ RFLR_MODEMCONFIG1_BW_MASK &
+ RFLR_MODEMCONFIG1_CODINGRATE_MASK &
+ RFLR_MODEMCONFIG1_IMPLICITHEADER_MASK ) |
+ ( bandwidth << 4 ) | ( coderate << 1 ) |
+ fixLen );
+
+ SX1276Write( REG_LR_MODEMCONFIG2,
+ ( SX1276Read( REG_LR_MODEMCONFIG2 ) &
+ RFLR_MODEMCONFIG2_SF_MASK &
+ RFLR_MODEMCONFIG2_RXPAYLOADCRC_MASK ) |
+ ( datarate << 4 ) | ( crcOn << 2 ) );
+
+ SX1276Write( REG_LR_MODEMCONFIG3,
+ ( SX1276Read( REG_LR_MODEMCONFIG3 ) &
+ RFLR_MODEMCONFIG3_LOWDATARATEOPTIMIZE_MASK ) |
+ ( SX1276.Settings.LoRa.LowDatarateOptimize << 3 ) );
+
+ SX1276Write( REG_LR_PREAMBLEMSB, ( preambleLen >> 8 ) & 0x00FF );
+ SX1276Write( REG_LR_PREAMBLELSB, preambleLen & 0xFF );
+
+ if( datarate == 6 )
+ {
+ SX1276Write( REG_LR_DETECTOPTIMIZE,
+ ( SX1276Read( REG_LR_DETECTOPTIMIZE ) &
+ RFLR_DETECTIONOPTIMIZE_MASK ) |
+ RFLR_DETECTIONOPTIMIZE_SF6 );
+ SX1276Write( REG_LR_DETECTIONTHRESHOLD,
+ RFLR_DETECTIONTHRESH_SF6 );
+ }
+ else
+ {
+ SX1276Write( REG_LR_DETECTOPTIMIZE,
+ ( SX1276Read( REG_LR_DETECTOPTIMIZE ) &
+ RFLR_DETECTIONOPTIMIZE_MASK ) |
+ RFLR_DETECTIONOPTIMIZE_SF7_TO_SF12 );
+ SX1276Write( REG_LR_DETECTIONTHRESHOLD,
+ RFLR_DETECTIONTHRESH_SF7_TO_SF12 );
+ }
+ }
+ break;
+ }
+}
+
+uint32_t SX1276GetTimeOnAir( RadioModems_t modem, uint8_t pktLen )
+{
+ uint32_t airTime = 0;
+
+ switch( modem )
+ {
+ case MODEM_FSK:
+ {
+ airTime = round( ( 8 * ( SX1276.Settings.Fsk.PreambleLen +
+ ( ( SX1276Read( REG_SYNCCONFIG ) & ~RF_SYNCCONFIG_SYNCSIZE_MASK ) + 1 ) +
+ ( ( SX1276.Settings.Fsk.FixLen == 0x01 ) ? 0.0 : 1.0 ) +
+ ( ( ( SX1276Read( REG_PACKETCONFIG1 ) & ~RF_PACKETCONFIG1_ADDRSFILTERING_MASK ) != 0x00 ) ? 1.0 : 0 ) +
+ pktLen +
+ ( ( SX1276.Settings.Fsk.CrcOn == 0x01 ) ? 2.0 : 0 ) ) /
+ SX1276.Settings.Fsk.Datarate ) * 1e3 );
+ }
+ break;
+ case MODEM_LORA:
+ {
+ double bw = 0.0;
+ // REMARK: When using LoRa modem only bandwidths 125, 250 and 500 kHz are supported
+ switch( SX1276.Settings.LoRa.Bandwidth )
+ {
+ //case 0: // 7.8 kHz
+ // bw = 78e2;
+ // break;
+ //case 1: // 10.4 kHz
+ // bw = 104e2;
+ // break;
+ //case 2: // 15.6 kHz
+ // bw = 156e2;
+ // break;
+ //case 3: // 20.8 kHz
+ // bw = 208e2;
+ // break;
+ //case 4: // 31.2 kHz
+ // bw = 312e2;
+ // break;
+ //case 5: // 41.4 kHz
+ // bw = 414e2;
+ // break;
+ //case 6: // 62.5 kHz
+ // bw = 625e2;
+ // break;
+ case 7: // 125 kHz
+ bw = 125e3;
+ break;
+ case 8: // 250 kHz
+ bw = 250e3;
+ break;
+ case 9: // 500 kHz
+ bw = 500e3;
+ break;
+ }
+
+ // Symbol rate : time for one symbol (secs)
+ double rs = bw / ( 1 << SX1276.Settings.LoRa.Datarate );
+ double ts = 1 / rs;
+ // time of preamble
+ double tPreamble = ( SX1276.Settings.LoRa.PreambleLen + 4.25 ) * ts;
+ // Symbol length of payload and time
+ double tmp = ceil( ( 8 * pktLen - 4 * SX1276.Settings.LoRa.Datarate +
+ 28 + 16 * SX1276.Settings.LoRa.CrcOn -
+ ( SX1276.Settings.LoRa.FixLen ? 20 : 0 ) ) /
+ ( double )( 4 * SX1276.Settings.LoRa.Datarate -
+ ( ( SX1276.Settings.LoRa.LowDatarateOptimize > 0 ) ? 2 : 0 ) ) ) *
+ ( SX1276.Settings.LoRa.Coderate + 4 );
+ double nPayload = 8 + ( ( tmp > 0 ) ? tmp : 0 );
+ double tPayload = nPayload * ts;
+ // Time on air
+ double tOnAir = tPreamble + tPayload;
+ // return us secs
+ airTime = floor( tOnAir * 1e3 + 0.999 );
+ }
+ break;
+ }
+ return airTime;
+}
+
+void SX1276Send( uint8_t *buffer, uint8_t size )
+{
+ uint32_t txTimeout = 0;
+
+ switch( SX1276.Settings.Modem )
+ {
+ case MODEM_FSK:
+ {
+ SX1276.Settings.FskPacketHandler.NbBytes = 0;
+ SX1276.Settings.FskPacketHandler.Size = size;
+
+ if( SX1276.Settings.Fsk.FixLen == false )
+ {
+ SX1276WriteFifo( ( uint8_t* )&size, 1 );
+ }
+ else
+ {
+ SX1276Write( REG_PAYLOADLENGTH, size );
+ }
+
+ if( ( size > 0 ) && ( size <= 64 ) )
+ {
+ SX1276.Settings.FskPacketHandler.ChunkSize = size;
+ }
+ else
+ {
+ memcpy( RxTxBuffer, buffer, size );
+ SX1276.Settings.FskPacketHandler.ChunkSize = 32;
+ }
+
+ // Write payload buffer
+ SX1276WriteFifo( buffer, SX1276.Settings.FskPacketHandler.ChunkSize );
+ SX1276.Settings.FskPacketHandler.NbBytes += SX1276.Settings.FskPacketHandler.ChunkSize;
+ txTimeout = SX1276.Settings.Fsk.TxTimeout;
+ }
+ break;
+ case MODEM_LORA:
+ {
+ if( SX1276.Settings.LoRa.IqInverted == true )
+ {
+ SX1276Write( REG_LR_INVERTIQ, ( ( SX1276Read( REG_LR_INVERTIQ ) & RFLR_INVERTIQ_TX_MASK & RFLR_INVERTIQ_RX_MASK ) | RFLR_INVERTIQ_RX_OFF | RFLR_INVERTIQ_TX_ON ) );
+ SX1276Write( REG_LR_INVERTIQ2, RFLR_INVERTIQ2_ON );
+ }
+ else
+ {
+ SX1276Write( REG_LR_INVERTIQ, ( ( SX1276Read( REG_LR_INVERTIQ ) & RFLR_INVERTIQ_TX_MASK & RFLR_INVERTIQ_RX_MASK ) | RFLR_INVERTIQ_RX_OFF | RFLR_INVERTIQ_TX_OFF ) );
+ SX1276Write( REG_LR_INVERTIQ2, RFLR_INVERTIQ2_OFF );
+ }
+
+ SX1276.Settings.LoRaPacketHandler.Size = size;
+
+ // Initializes the payload size
+ SX1276Write( REG_LR_PAYLOADLENGTH, size );
+
+ // Full buffer used for Tx
+ SX1276Write( REG_LR_FIFOTXBASEADDR, 0 );
+ SX1276Write( REG_LR_FIFOADDRPTR, 0 );
+
+ // FIFO operations can not take place in Sleep mode
+ if( ( SX1276Read( REG_OPMODE ) & ~RF_OPMODE_MASK ) == RF_OPMODE_SLEEP )
+ {
+ SX1276SetStby( );
+ os_cputime_delay_usecs(1000);
+ }
+ // Write payload buffer
+ SX1276WriteFifo( buffer, size );
+ txTimeout = SX1276.Settings.LoRa.TxTimeout;
+ }
+ break;
+ }
+
+ SX1276SetTx( txTimeout );
+}
+
+void SX1276SetSleep( void )
+{
+ os_cputime_timer_stop(&RxTimeoutTimer);
+ os_cputime_timer_stop(&TxTimeoutTimer);
+
+ SX1276SetOpMode( RF_OPMODE_SLEEP );
+ SX1276.Settings.State = RF_IDLE;
+}
+
+void SX1276SetStby( void )
+{
+ os_cputime_timer_stop(&RxTimeoutTimer);
+ os_cputime_timer_stop(&TxTimeoutTimer);
+
+ SX1276SetOpMode( RF_OPMODE_STANDBY );
+ SX1276.Settings.State = RF_IDLE;
+}
+
+void SX1276SetRx( uint32_t timeout )
+{
+ bool rxContinuous = false;
+
+ switch( SX1276.Settings.Modem )
+ {
+ case MODEM_FSK:
+ {
+ rxContinuous = SX1276.Settings.Fsk.RxContinuous;
+
+ // DIO0=PayloadReady
+ // DIO1=FifoLevel
+ // DIO2=SyncAddr
+ // DIO3=FifoEmpty
+ // DIO4=Preamble
+ // DIO5=ModeReady
+ SX1276Write( REG_DIOMAPPING1, ( SX1276Read( REG_DIOMAPPING1 ) & RF_DIOMAPPING1_DIO0_MASK &
+ RF_DIOMAPPING1_DIO1_MASK &
+ RF_DIOMAPPING1_DIO2_MASK ) |
+ RF_DIOMAPPING1_DIO0_00 |
+ RF_DIOMAPPING1_DIO1_00 |
+ RF_DIOMAPPING1_DIO2_11 );
+
+ SX1276Write( REG_DIOMAPPING2, ( SX1276Read( REG_DIOMAPPING2 ) & RF_DIOMAPPING2_DIO4_MASK &
+ RF_DIOMAPPING2_MAP_MASK ) |
+ RF_DIOMAPPING2_DIO4_11 |
+ RF_DIOMAPPING2_MAP_PREAMBLEDETECT );
+
+ SX1276.Settings.FskPacketHandler.FifoThresh = SX1276Read( REG_FIFOTHRESH ) & 0x3F;
+
+ SX1276Write( REG_RXCONFIG, RF_RXCONFIG_AFCAUTO_ON | RF_RXCONFIG_AGCAUTO_ON | RF_RXCONFIG_RXTRIGER_PREAMBLEDETECT );
+
+ SX1276.Settings.FskPacketHandler.PreambleDetected = false;
+ SX1276.Settings.FskPacketHandler.SyncWordDetected = false;
+ SX1276.Settings.FskPacketHandler.NbBytes = 0;
+ SX1276.Settings.FskPacketHandler.Size = 0;
+ }
+ break;
+ case MODEM_LORA:
+ {
+ if( SX1276.Settings.LoRa.IqInverted == true )
+ {
+ SX1276Write( REG_LR_INVERTIQ, ( ( SX1276Read( REG_LR_INVERTIQ ) & RFLR_INVERTIQ_TX_MASK & RFLR_INVERTIQ_RX_MASK ) | RFLR_INVERTIQ_RX_ON | RFLR_INVERTIQ_TX_OFF ) );
+ SX1276Write( REG_LR_INVERTIQ2, RFLR_INVERTIQ2_ON );
+ }
+ else
+ {
+ SX1276Write( REG_LR_INVERTIQ, ( ( SX1276Read( REG_LR_INVERTIQ ) & RFLR_INVERTIQ_TX_MASK & RFLR_INVERTIQ_RX_MASK ) | RFLR_INVERTIQ_RX_OFF | RFLR_INVERTIQ_TX_OFF ) );
+ SX1276Write( REG_LR_INVERTIQ2, RFLR_INVERTIQ2_OFF );
+ }
+
+ // ERRATA 2.3 - Receiver Spurious Reception of a LoRa Signal
+ if( SX1276.Settings.LoRa.Bandwidth < 9 )
+ {
+ SX1276Write( REG_LR_DETECTOPTIMIZE, SX1276Read( REG_LR_DETECTOPTIMIZE ) & 0x7F );
+ SX1276Write( REG_LR_TEST30, 0x00 );
+ switch( SX1276.Settings.LoRa.Bandwidth )
+ {
+ case 0: // 7.8 kHz
+ SX1276Write( REG_LR_TEST2F, 0x48 );
+ SX1276SetChannel(SX1276.Settings.Channel + 7.81e3 );
+ break;
+ case 1: // 10.4 kHz
+ SX1276Write( REG_LR_TEST2F, 0x44 );
+ SX1276SetChannel(SX1276.Settings.Channel + 10.42e3 );
+ break;
+ case 2: // 15.6 kHz
+ SX1276Write( REG_LR_TEST2F, 0x44 );
+ SX1276SetChannel(SX1276.Settings.Channel + 15.62e3 );
+ break;
+ case 3: // 20.8 kHz
+ SX1276Write( REG_LR_TEST2F, 0x44 );
+ SX1276SetChannel(SX1276.Settings.Channel + 20.83e3 );
+ break;
+ case 4: // 31.2 kHz
+ SX1276Write( REG_LR_TEST2F, 0x44 );
+ SX1276SetChannel(SX1276.Settings.Channel + 31.25e3 );
+ break;
+ case 5: // 41.4 kHz
+ SX1276Write( REG_LR_TEST2F, 0x44 );
+ SX1276SetChannel(SX1276.Settings.Channel + 41.67e3 );
+ break;
+ case 6: // 62.5 kHz
+ SX1276Write( REG_LR_TEST2F, 0x40 );
+ break;
+ case 7: // 125 kHz
+ SX1276Write( REG_LR_TEST2F, 0x40 );
+ break;
+ case 8: // 250 kHz
+ SX1276Write( REG_LR_TEST2F, 0x40 );
+ break;
+ }
+ }
+ else
+ {
+ SX1276Write( REG_LR_DETECTOPTIMIZE, SX1276Read( REG_LR_DETECTOPTIMIZE ) | 0x80 );
+ }
+
+ rxContinuous = SX1276.Settings.LoRa.RxContinuous;
+
+ if( SX1276.Settings.LoRa.FreqHopOn == true )
+ {
+ SX1276Write( REG_LR_IRQFLAGSMASK, //RFLR_IRQFLAGS_RXTIMEOUT |
+ //RFLR_IRQFLAGS_RXDONE |
+ //RFLR_IRQFLAGS_PAYLOADCRCERROR |
+ RFLR_IRQFLAGS_VALIDHEADER |
+ RFLR_IRQFLAGS_TXDONE |
+ RFLR_IRQFLAGS_CADDONE |
+ //RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL |
+ RFLR_IRQFLAGS_CADDETECTED );
+
+ // DIO0=RxDone, DIO2=FhssChangeChannel
+ SX1276Write( REG_DIOMAPPING1, ( SX1276Read( REG_DIOMAPPING1 ) & RFLR_DIOMAPPING1_DIO0_MASK & RFLR_DIOMAPPING1_DIO2_MASK ) | RFLR_DIOMAPPING1_DIO0_00 | RFLR_DIOMAPPING1_DIO2_00 );
+ }
+ else
+ {
+ SX1276Write( REG_LR_IRQFLAGSMASK, //RFLR_IRQFLAGS_RXTIMEOUT |
+ //RFLR_IRQFLAGS_RXDONE |
+ //RFLR_IRQFLAGS_PAYLOADCRCERROR |
+ RFLR_IRQFLAGS_VALIDHEADER |
+ RFLR_IRQFLAGS_TXDONE |
+ RFLR_IRQFLAGS_CADDONE |
+ RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL |
+ RFLR_IRQFLAGS_CADDETECTED );
+
+ // DIO0=RxDone
+ SX1276Write( REG_DIOMAPPING1, ( SX1276Read( REG_DIOMAPPING1 ) & RFLR_DIOMAPPING1_DIO0_MASK ) | RFLR_DIOMAPPING1_DIO0_00 );
+ }
+ SX1276Write( REG_LR_FIFORXBASEADDR, 0 );
+ SX1276Write( REG_LR_FIFOADDRPTR, 0 );
+ }
+ break;
+ }
+
+ memset( RxTxBuffer, 0, ( size_t )RX_BUFFER_SIZE );
+
+ SX1276.Settings.State = RF_RX_RUNNING;
+ if( timeout != 0 )
+ {
+ os_cputime_timer_relative(&RxTimeoutTimer, timeout*1000);
+ }
+
+ if( SX1276.Settings.Modem == MODEM_FSK )
+ {
+ SX1276SetOpMode( RF_OPMODE_RECEIVER );
+
+ if( rxContinuous == false )
+ {
+ rx_timeout_sync_delay =
+ ceil((8.0 * (SX1276.Settings.Fsk.PreambleLen +
+ ((SX1276Read(REG_SYNCCONFIG) &
+ ~RF_SYNCCONFIG_SYNCSIZE_MASK) + 1.0) + 10.0) /
+ (double)SX1276.Settings.Fsk.Datarate) * 1e3) + 4;
+ os_cputime_timer_relative(
+ &RxTimeoutSyncWord, rx_timeout_sync_delay*1000);
+ }
+ }
+ else
+ {
+ if( rxContinuous == true )
+ {
+ SX1276SetOpMode( RFLR_OPMODE_RECEIVER );
+ }
+ else
+ {
+ SX1276SetOpMode( RFLR_OPMODE_RECEIVER_SINGLE );
+ }
+ }
+}
+
+void SX1276SetTx( uint32_t timeout )
+{
+ os_cputime_timer_relative(&TxTimeoutTimer, timeout*1000);
+
+ switch( SX1276.Settings.Modem )
+ {
+ case MODEM_FSK:
+ {
+ // DIO0=PacketSent
+ // DIO1=FifoEmpty
+ // DIO2=FifoFull
+ // DIO3=FifoEmpty
+ // DIO4=LowBat
+ // DIO5=ModeReady
+ SX1276Write( REG_DIOMAPPING1, ( SX1276Read( REG_DIOMAPPING1 ) & RF_DIOMAPPING1_DIO0_MASK &
+ RF_DIOMAPPING1_DIO1_MASK &
+ RF_DIOMAPPING1_DIO2_MASK ) |
+ RF_DIOMAPPING1_DIO1_01 );
+
+ SX1276Write( REG_DIOMAPPING2, ( SX1276Read( REG_DIOMAPPING2 ) & RF_DIOMAPPING2_DIO4_MASK &
+ RF_DIOMAPPING2_MAP_MASK ) );
+ SX1276.Settings.FskPacketHandler.FifoThresh = SX1276Read( REG_FIFOTHRESH ) & 0x3F;
+ }
+ break;
+ case MODEM_LORA:
+ {
+ if( SX1276.Settings.LoRa.FreqHopOn == true )
+ {
+ SX1276Write( REG_LR_IRQFLAGSMASK, RFLR_IRQFLAGS_RXTIMEOUT |
+ RFLR_IRQFLAGS_RXDONE |
+ RFLR_IRQFLAGS_PAYLOADCRCERROR |
+ RFLR_IRQFLAGS_VALIDHEADER |
+ //RFLR_IRQFLAGS_TXDONE |
+ RFLR_IRQFLAGS_CADDONE |
+ //RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL |
+ RFLR_IRQFLAGS_CADDETECTED );
+
+ // DIO0=TxDone, DIO2=FhssChangeChannel
+ SX1276Write( REG_DIOMAPPING1, ( SX1276Read( REG_DIOMAPPING1 ) & RFLR_DIOMAPPING1_DIO0_MASK & RFLR_DIOMAPPING1_DIO2_MASK ) | RFLR_DIOMAPPING1_DIO0_01 | RFLR_DIOMAPPING1_DIO2_00 );
+ }
+ else
+ {
+ SX1276Write( REG_LR_IRQFLAGSMASK, RFLR_IRQFLAGS_RXTIMEOUT |
+ RFLR_IRQFLAGS_RXDONE |
+ RFLR_IRQFLAGS_PAYLOADCRCERROR |
+ RFLR_IRQFLAGS_VALIDHEADER |
+ //RFLR_IRQFLAGS_TXDONE |
+ RFLR_IRQFLAGS_CADDONE |
+ RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL |
+ RFLR_IRQFLAGS_CADDETECTED );
+
+ // DIO0=TxDone
+ SX1276Write( REG_DIOMAPPING1, ( SX1276Read( REG_DIOMAPPING1 ) & RFLR_DIOMAPPING1_DIO0_MASK ) | RFLR_DIOMAPPING1_DIO0_01 );
+ }
+ }
+ break;
+ }
+
+ SX1276.Settings.State = RF_TX_RUNNING;
+ os_cputime_timer_relative(&TxTimeoutTimer, timeout*1000);
+ SX1276SetOpMode( RF_OPMODE_TRANSMITTER );
+}
+
+void SX1276StartCad( void )
+{
+ switch( SX1276.Settings.Modem )
+ {
+ case MODEM_FSK:
+ {
+
+ }
+ break;
+ case MODEM_LORA:
+ {
+ SX1276Write( REG_LR_IRQFLAGSMASK, RFLR_IRQFLAGS_RXTIMEOUT |
+ RFLR_IRQFLAGS_RXDONE |
+ RFLR_IRQFLAGS_PAYLOADCRCERROR |
+ RFLR_IRQFLAGS_VALIDHEADER |
+ RFLR_IRQFLAGS_TXDONE |
+ //RFLR_IRQFLAGS_CADDONE |
+ RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL // |
+ //RFLR_IRQFLAGS_CADDETECTED
+ );
+
+ // DIO3=CADDone
+ SX1276Write( REG_DIOMAPPING1, ( SX1276Read( REG_DIOMAPPING1 ) & RFLR_DIOMAPPING1_DIO0_MASK ) | RFLR_DIOMAPPING1_DIO0_00 );
+
+ SX1276.Settings.State = RF_CAD;
+ SX1276SetOpMode( RFLR_OPMODE_CAD );
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+int16_t SX1276ReadRssi( RadioModems_t modem )
+{
+ int16_t rssi = 0;
+
+ switch( modem )
+ {
+ case MODEM_FSK:
+ rssi = -( SX1276Read( REG_RSSIVALUE ) >> 1 );
+ break;
+ case MODEM_LORA:
+ if( SX1276.Settings.Channel > RF_MID_BAND_THRESH )
+ {
+ rssi = RSSI_OFFSET_HF + SX1276Read( REG_LR_RSSIVALUE );
+ }
+ else
+ {
+ rssi = RSSI_OFFSET_LF + SX1276Read( REG_LR_RSSIVALUE );
+ }
+ break;
+ default:
+ rssi = -1;
+ break;
+ }
+ return rssi;
+}
+
+void SX1276Reset( void )
+{
+ // Set RESET pin to 0
+ hal_gpio_init_out(SX1276_NRESET, 0);
+
+ // Wait 1 ms
+ os_cputime_delay_usecs(1000);
+
+ // Configure RESET as input
+ hal_gpio_init_in(SX1276_NRESET, HAL_GPIO_PULL_NONE);
+
+ // Wait 6 ms
+ os_cputime_delay_usecs(6000);
+}
+
+void SX1276SetOpMode( uint8_t opMode )
+{
+ if( opMode == RF_OPMODE_SLEEP )
+ {
+ SX1276SetAntSwLowPower( true );
+ }
+ else
+ {
+ SX1276SetAntSwLowPower( false );
+ if( opMode == RF_OPMODE_TRANSMITTER )
+ {
+ SX1276SetAntSw( 1 );
+ }
+ else
+ {
+ SX1276SetAntSw( 0 );
+ }
+ }
+ SX1276Write( REG_OPMODE, ( SX1276Read( REG_OPMODE ) & RF_OPMODE_MASK ) | opMode );
+}
+
+void SX1276SetModem( RadioModems_t modem )
+{
+
+ if( SX1276.Settings.Modem == modem )
+ {
+ return;
+ }
+
+ SX1276.Settings.Modem = modem;
+ switch( SX1276.Settings.Modem )
+ {
+ default:
+ case MODEM_FSK:
+ SX1276SetOpMode( RF_OPMODE_SLEEP );
+ SX1276Write( REG_OPMODE, ( SX1276Read( REG_OPMODE ) & RFLR_OPMODE_LONGRANGEMODE_MASK ) | RFLR_OPMODE_LONGRANGEMODE_OFF );
+
+ SX1276Write( REG_DIOMAPPING1, 0x00 );
+ SX1276Write( REG_DIOMAPPING2, 0x30 ); // DIO5=ModeReady
+ break;
+ case MODEM_LORA:
+ SX1276SetOpMode( RF_OPMODE_SLEEP );
+ SX1276Write( REG_OPMODE, ( SX1276Read( REG_OPMODE ) & RFLR_OPMODE_LONGRANGEMODE_MASK ) | RFLR_OPMODE_LONGRANGEMODE_ON );
+
+ SX1276Write( REG_DIOMAPPING1, 0x00 );
+ SX1276Write( REG_DIOMAPPING2, 0x00 );
+ break;
+ }
+}
+
+void SX1276Write( uint8_t addr, uint8_t data )
+{
+ SX1276WriteBuffer( addr, &data, 1 );
+}
+
+uint8_t SX1276Read( uint8_t addr )
+{
+ uint8_t data;
+ SX1276ReadBuffer( addr, &data, 1 );
+ return data;
+}
+
+void SX1276WriteBuffer( uint8_t addr, uint8_t *buffer, uint8_t size )
+{
+ uint8_t i;
+
+ hal_gpio_write(RADIO_NSS, 0);
+
+ hal_spi_tx_val(RADIO_SPI_IDX, addr | 0x80);
+ for( i = 0; i < size; i++ )
+ {
+ hal_spi_tx_val(RADIO_SPI_IDX, buffer[i]);
+ }
+
+ hal_gpio_write(RADIO_NSS, 1);
+}
+
+void SX1276ReadBuffer( uint8_t addr, uint8_t *buffer, uint8_t size )
+{
+ uint8_t i;
+
+ hal_gpio_write(RADIO_NSS, 0);
+
+ hal_spi_tx_val(RADIO_SPI_IDX, addr & 0x7f);
+ for( i = 0; i < size; i++ )
+ {
+ buffer[i] = hal_spi_tx_val(RADIO_SPI_IDX, 0);
+ }
+
+ hal_gpio_write(RADIO_NSS, 1);
+}
+
+void SX1276WriteFifo( uint8_t *buffer, uint8_t size )
+{
+ SX1276WriteBuffer( 0, buffer, size );
+}
+
+void SX1276ReadFifo( uint8_t *buffer, uint8_t size )
+{
+ SX1276ReadBuffer( 0, buffer, size );
+}
+
+void SX1276SetMaxPayloadLength( RadioModems_t modem, uint8_t max )
+{
+ SX1276SetModem( modem );
+
+ switch( modem )
+ {
+ case MODEM_FSK:
+ if( SX1276.Settings.Fsk.FixLen == false )
+ {
+ SX1276Write( REG_PAYLOADLENGTH, max );
+ }
+ break;
+ case MODEM_LORA:
+ SX1276Write( REG_LR_PAYLOADMAXLENGTH, max );
+ break;
+ }
+}
+
+void SX1276OnTimeoutIrq(void *unused)
+{
+ switch( SX1276.Settings.State )
+ {
+ case RF_RX_RUNNING:
+ if( SX1276.Settings.Modem == MODEM_FSK )
+ {
+ SX1276.Settings.FskPacketHandler.PreambleDetected = false;
+ SX1276.Settings.FskPacketHandler.SyncWordDetected = false;
+ SX1276.Settings.FskPacketHandler.NbBytes = 0;
+ SX1276.Settings.FskPacketHandler.Size = 0;
+
+ // Clear Irqs
+ SX1276Write( REG_IRQFLAGS1, RF_IRQFLAGS1_RSSI |
+ RF_IRQFLAGS1_PREAMBLEDETECT |
+ RF_IRQFLAGS1_SYNCADDRESSMATCH );
+ SX1276Write( REG_IRQFLAGS2, RF_IRQFLAGS2_FIFOOVERRUN );
+
+ if( SX1276.Settings.Fsk.RxContinuous == true )
+ {
+ // Continuous mode restart Rx chain
+ SX1276Write( REG_RXCONFIG, SX1276Read( REG_RXCONFIG ) | RF_RXCONFIG_RESTARTRXWITHOUTPLLLOCK );
+ assert(rx_timeout_sync_delay != (uint32_t)-1);
+ os_cputime_timer_relative(
+ &RxTimeoutSyncWord, rx_timeout_sync_delay*1000);
+ }
+ else
+ {
+ SX1276.Settings.State = RF_IDLE;
+ os_cputime_timer_stop(&RxTimeoutSyncWord);
+ }
+ }
+ SX1276RxTimeout( );
+ break;
+ case RF_TX_RUNNING:
+ SX1276.Settings.State = RF_IDLE;
+ SX1276TxTimeout( );
+ break;
+ default:
+ break;
+ }
+}
+
+void SX1276OnDio0Irq(void *unused)
+{
+ volatile uint8_t irqFlags = 0;
+
+ switch( SX1276.Settings.State )
+ {
+ case RF_RX_RUNNING:
+ //TimerStop( &RxTimeoutTimer );
+ // RxDone interrupt
+ switch( SX1276.Settings.Modem )
+ {
+ case MODEM_FSK:
+ if( SX1276.Settings.Fsk.CrcOn == true )
+ {
+ irqFlags = SX1276Read( REG_IRQFLAGS2 );
+ if( ( irqFlags & RF_IRQFLAGS2_CRCOK ) != RF_IRQFLAGS2_CRCOK )
+ {
+ // Clear Irqs
+ SX1276Write( REG_IRQFLAGS1, RF_IRQFLAGS1_RSSI |
+ RF_IRQFLAGS1_PREAMBLEDETECT |
+ RF_IRQFLAGS1_SYNCADDRESSMATCH );
+ SX1276Write( REG_IRQFLAGS2, RF_IRQFLAGS2_FIFOOVERRUN );
+
+ os_cputime_timer_stop(&RxTimeoutTimer);
+
+ if( SX1276.Settings.Fsk.RxContinuous == false )
+ {
+ os_cputime_timer_stop(&RxTimeoutSyncWord);
+ SX1276.Settings.State = RF_IDLE;
+ }
+ else
+ {
+ // Continuous mode restart Rx chain
+ SX1276Write( REG_RXCONFIG, SX1276Read( REG_RXCONFIG ) | RF_RXCONFIG_RESTARTRXWITHOUTPLLLOCK );
+ assert(rx_timeout_sync_delay != (uint32_t)-1);
+ os_cputime_timer_relative(
+ &RxTimeoutSyncWord, rx_timeout_sync_delay*1000);
+ }
+
+ SX1276RxError( );
+ SX1276.Settings.FskPacketHandler.PreambleDetected = false;
+ SX1276.Settings.FskPacketHandler.SyncWordDetected = false;
+ SX1276.Settings.FskPacketHandler.NbBytes = 0;
+ SX1276.Settings.FskPacketHandler.Size = 0;
+ break;
+ }
+ }
+
+ // Read received packet size
+ if( ( SX1276.Settings.FskPacketHandler.Size == 0 ) && ( SX1276.Settings.FskPacketHandler.NbBytes == 0 ) )
+ {
+ if( SX1276.Settings.Fsk.FixLen == false )
+ {
+ SX1276ReadFifo( ( uint8_t* )&SX1276.Settings.FskPacketHandler.Size, 1 );
+ }
+ else
+ {
+ SX1276.Settings.FskPacketHandler.Size = SX1276Read( REG_PAYLOADLENGTH );
+ }
+ SX1276ReadFifo( RxTxBuffer + SX1276.Settings.FskPacketHandler.NbBytes, SX1276.Settings.FskPacketHandler.Size - SX1276.Settings.FskPacketHandler.NbBytes );
+ SX1276.Settings.FskPacketHandler.NbBytes += ( SX1276.Settings.FskPacketHandler.Size - SX1276.Settings.FskPacketHandler.NbBytes );
+ }
+ else
+ {
+ SX1276ReadFifo( RxTxBuffer + SX1276.Settings.FskPacketHandler.NbBytes, SX1276.Settings.FskPacketHandler.Size - SX1276.Settings.FskPacketHandler.NbBytes );
+ SX1276.Settings.FskPacketHandler.NbBytes += ( SX1276.Settings.FskPacketHandler.Size - SX1276.Settings.FskPacketHandler.NbBytes );
+ }
+
+ if( SX1276.Settings.Fsk.RxContinuous == false )
+ {
+ SX1276.Settings.State = RF_IDLE;
+ assert(rx_timeout_sync_delay != (uint32_t)-1);
+ os_cputime_timer_relative(
+ &RxTimeoutSyncWord, rx_timeout_sync_delay*1000);
+
+ }
+ else
+ {
+ // Continuous mode restart Rx chain
+ SX1276Write( REG_RXCONFIG, SX1276Read( REG_RXCONFIG ) | RF_RXCONFIG_RESTARTRXWITHOUTPLLLOCK );
+ }
+ os_cputime_timer_stop(&RxTimeoutTimer);
+
+ SX1276RxDone( RxTxBuffer, SX1276.Settings.FskPacketHandler.Size, SX1276.Settings.FskPacketHandler.RssiValue, 0 );
+ SX1276.Settings.FskPacketHandler.PreambleDetected = false;
+ SX1276.Settings.FskPacketHandler.SyncWordDetected = false;
+ SX1276.Settings.FskPacketHandler.NbBytes = 0;
+ SX1276.Settings.FskPacketHandler.Size = 0;
+ break;
+ case MODEM_LORA:
+ {
+ int8_t snr = 0;
+
+ // Clear Irq
+ SX1276Write( REG_LR_IRQFLAGS, RFLR_IRQFLAGS_RXDONE);
+
+ irqFlags = SX1276Read( REG_LR_IRQFLAGS );
+ if( ( irqFlags & RFLR_IRQFLAGS_PAYLOADCRCERROR_MASK ) == RFLR_IRQFLAGS_PAYLOADCRCERROR )
+ {
+ // Clear Irq
+ SX1276Write( REG_LR_IRQFLAGS, RFLR_IRQFLAGS_PAYLOADCRCERROR);
+
+ if( SX1276.Settings.LoRa.RxContinuous == false )
+ {
+ SX1276.Settings.State = RF_IDLE;
+ }
+ os_cputime_timer_stop(&RxTimeoutTimer);
+
+ SX1276RxError( );
+ break;
+ }
+
+ SX1276.Settings.LoRaPacketHandler.SnrValue = SX1276Read( REG_LR_PKTSNRVALUE );
+ if( SX1276.Settings.LoRaPacketHandler.SnrValue & 0x80 ) // The SNR sign bit is 1
+ {
+ // Invert and divide by 4
+ snr = ( ( ~SX1276.Settings.LoRaPacketHandler.SnrValue + 1 ) & 0xFF ) >> 2;
+ snr = -snr;
+ }
+ else
+ {
+ // Divide by 4
+ snr = ( SX1276.Settings.LoRaPacketHandler.SnrValue & 0xFF ) >> 2;
+ }
+
+ int16_t rssi = SX1276Read( REG_LR_PKTRSSIVALUE );
+ if( snr < 0 )
+ {
+ if( SX1276.Settings.Channel > RF_MID_BAND_THRESH )
+ {
+ SX1276.Settings.LoRaPacketHandler.RssiValue = RSSI_OFFSET_HF + rssi + ( rssi >> 4 ) +
+ snr;
+ }
+ else
+ {
+ SX1276.Settings.LoRaPacketHandler.RssiValue = RSSI_OFFSET_LF + rssi + ( rssi >> 4 ) +
+ snr;
+ }
+ }
+ else
+ {
+ if( SX1276.Settings.Channel > RF_MID_BAND_THRESH )
+ {
+ SX1276.Settings.LoRaPacketHandler.RssiValue = RSSI_OFFSET_HF + rssi + ( rssi >> 4 );
+ }
+ else
+ {
+ SX1276.Settings.LoRaPacketHandler.RssiValue = RSSI_OFFSET_LF + rssi + ( rssi >> 4 );
+ }
+ }
+
+ SX1276.Settings.LoRaPacketHandler.Size = SX1276Read( REG_LR_RXNBBYTES );
+ SX1276ReadFifo( RxTxBuffer, SX1276.Settings.LoRaPacketHandler.Size );
+
+ if( SX1276.Settings.LoRa.RxContinuous == false )
+ {
+ SX1276.Settings.State = RF_IDLE;
+ }
+ os_cputime_timer_stop(&RxTimeoutTimer);
+
+ SX1276RxDone( RxTxBuffer, SX1276.Settings.LoRaPacketHandler.Size, SX1276.Settings.LoRaPacketHandler.RssiValue, SX1276.Settings.LoRaPacketHandler.SnrValue );
+ }
+ break;
+ default:
+ break;
+ }
+ break;
+ case RF_TX_RUNNING:
+ os_cputime_timer_stop(&TxTimeoutTimer);
+ // TxDone interrupt
+ switch( SX1276.Settings.Modem )
+ {
+ case MODEM_LORA:
+ // Clear Irq
+ SX1276Write( REG_LR_IRQFLAGS, RFLR_IRQFLAGS_TXDONE );
+ // Intentional fall through
+ case MODEM_FSK:
+ default:
+ SX1276.Settings.State = RF_IDLE;
+ SX1276TxDone( );
+ break;
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+void SX1276OnDio1Irq(void *unused)
+{
+ switch( SX1276.Settings.State )
+ {
+ case RF_RX_RUNNING:
+ switch( SX1276.Settings.Modem )
+ {
+ case MODEM_FSK:
+ // FifoLevel interrupt
+ // Read received packet size
+ if( ( SX1276.Settings.FskPacketHandler.Size == 0 ) && ( SX1276.Settings.FskPacketHandler.NbBytes == 0 ) )
+ {
+ if( SX1276.Settings.Fsk.FixLen == false )
+ {
+ SX1276ReadFifo( ( uint8_t* )&SX1276.Settings.FskPacketHandler.Size, 1 );
+ }
+ else
+ {
+ SX1276.Settings.FskPacketHandler.Size = SX1276Read( REG_PAYLOADLENGTH );
+ }
+ }
+
+ if( ( SX1276.Settings.FskPacketHandler.Size - SX1276.Settings.FskPacketHandler.NbBytes ) > SX1276.Settings.FskPacketHandler.FifoThresh )
+ {
+ SX1276ReadFifo( ( RxTxBuffer + SX1276.Settings.FskPacketHandler.NbBytes ), SX1276.Settings.FskPacketHandler.FifoThresh );
+ SX1276.Settings.FskPacketHandler.NbBytes += SX1276.Settings.FskPacketHandler.FifoThresh;
+ }
+ else
+ {
+ SX1276ReadFifo( ( RxTxBuffer + SX1276.Settings.FskPacketHandler.NbBytes ), SX1276.Settings.FskPacketHandler.Size - SX1276.Settings.FskPacketHandler.NbBytes );
+ SX1276.Settings.FskPacketHandler.NbBytes += ( SX1276.Settings.FskPacketHandler.Size - SX1276.Settings.FskPacketHandler.NbBytes );
+ }
+ break;
+ case MODEM_LORA:
+ // Sync time out
+ os_cputime_timer_stop(&RxTimeoutTimer);
+ SX1276.Settings.State = RF_IDLE;
+ SX1276RxTimeout( );
+ break;
+ default:
+ break;
+ }
+ break;
+ case RF_TX_RUNNING:
+ switch( SX1276.Settings.Modem )
+ {
+ case MODEM_FSK:
+ // FifoEmpty interrupt
+ if( ( SX1276.Settings.FskPacketHandler.Size - SX1276.Settings.FskPacketHandler.NbBytes ) > SX1276.Settings.FskPacketHandler.ChunkSize )
+ {
+ SX1276WriteFifo( ( RxTxBuffer + SX1276.Settings.FskPacketHandler.NbBytes ), SX1276.Settings.FskPacketHandler.ChunkSize );
+ SX1276.Settings.FskPacketHandler.NbBytes += SX1276.Settings.FskPacketHandler.ChunkSize;
+ }
+ else
+ {
+ // Write the last chunk of data
+ SX1276WriteFifo( RxTxBuffer + SX1276.Settings.FskPacketHandler.NbBytes, SX1276.Settings.FskPacketHandler.Size - SX1276.Settings.FskPacketHandler.NbBytes );
+ SX1276.Settings.FskPacketHandler.NbBytes += SX1276.Settings.FskPacketHandler.Size - SX1276.Settings.FskPacketHandler.NbBytes;
+ }
+ break;
+ case MODEM_LORA:
+ break;
+ default:
+ break;
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+void SX1276OnDio2Irq(void *unused)
+{
+ switch( SX1276.Settings.State )
+ {
+ case RF_RX_RUNNING:
+ switch( SX1276.Settings.Modem )
+ {
+ case MODEM_FSK:
+ if( ( SX1276.Settings.FskPacketHandler.PreambleDetected == true ) && ( SX1276.Settings.FskPacketHandler.SyncWordDetected == false ) )
+ {
+ os_cputime_timer_stop(&RxTimeoutSyncWord);
+
+ SX1276.Settings.FskPacketHandler.SyncWordDetected = true;
+
+ SX1276.Settings.FskPacketHandler.RssiValue = -( SX1276Read( REG_RSSIVALUE ) >> 1 );
+
+ SX1276.Settings.FskPacketHandler.AfcValue = ( int32_t )( double )( ( ( uint16_t )SX1276Read( REG_AFCMSB ) << 8 ) |
+ ( uint16_t )SX1276Read( REG_AFCLSB ) ) *
+ ( double )FREQ_STEP;
+ SX1276.Settings.FskPacketHandler.RxGain = ( SX1276Read( REG_LNA ) >> 5 ) & 0x07;
+ }
+ break;
+ case MODEM_LORA:
+ if( SX1276.Settings.LoRa.FreqHopOn == true )
+ {
+ // Clear Irq
+ SX1276Write( REG_LR_IRQFLAGS, RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL);
+
+ if( ( RadioEvents != NULL ) && ( RadioEvents->FhssChangeChannel != NULL ) )
+ {
+ RadioEvents->FhssChangeChannel( ( SX1276Read( REG_LR_HOPCHANNEL ) & RFLR_HOPCHANNEL_CHANNEL_MASK ) );
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ break;
+ case RF_TX_RUNNING:
+ switch( SX1276.Settings.Modem )
+ {
+ case MODEM_FSK:
+ break;
+ case MODEM_LORA:
+ if( SX1276.Settings.LoRa.FreqHopOn == true )
+ {
+ // Clear Irq
+ SX1276Write( REG_LR_IRQFLAGS, RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL);
+
+ if( ( RadioEvents != NULL ) && ( RadioEvents->FhssChangeChannel != NULL ) )
+ {
+ RadioEvents->FhssChangeChannel( ( SX1276Read( REG_LR_HOPCHANNEL ) & RFLR_HOPCHANNEL_CHANNEL_MASK ) );
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+void SX1276OnDio3Irq(void *unused)
+{
+ switch( SX1276.Settings.Modem )
+ {
+ case MODEM_FSK:
+ break;
+ case MODEM_LORA:
+ if( ( SX1276Read( REG_LR_IRQFLAGS ) & RFLR_IRQFLAGS_CADDETECTED ) == RFLR_IRQFLAGS_CADDETECTED )
+ {
+ // Clear Irq
+ SX1276Write( REG_LR_IRQFLAGS, RFLR_IRQFLAGS_CADDETECTED | RFLR_IRQFLAGS_CADDONE);
+ if( ( RadioEvents != NULL ) && ( RadioEvents->CadDone != NULL ) )
+ {
+ RadioEvents->CadDone( true );
+ }
+ }
+ else
+ {
+ // Clear Irq
+ SX1276Write( REG_LR_IRQFLAGS, RFLR_IRQFLAGS_CADDONE);
+ if( ( RadioEvents != NULL ) && ( RadioEvents->CadDone != NULL ) )
+ {
+ RadioEvents->CadDone( false );
+ }
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+void SX1276OnDio4Irq(void *unused)
+{
+ switch( SX1276.Settings.Modem )
+ {
+ case MODEM_FSK:
+ {
+ if( SX1276.Settings.FskPacketHandler.PreambleDetected == false )
+ {
+ SX1276.Settings.FskPacketHandler.PreambleDetected = true;
+ }
+ }
+ break;
+ case MODEM_LORA:
+ break;
+ default:
+ break;
+ }
+}
+
+void SX1276OnDio5Irq(void *unused)
+{
+ switch( SX1276.Settings.Modem )
+ {
+ case MODEM_FSK:
+ break;
+ case MODEM_LORA:
+ break;
+ default:
+ break;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/560fa920/hw/drivers/lora/sx1276/src/sx1276.h
----------------------------------------------------------------------
diff --git a/hw/drivers/lora/sx1276/src/sx1276.h b/hw/drivers/lora/sx1276/src/sx1276.h
new file mode 100644
index 0000000..9c82652
--- /dev/null
+++ b/hw/drivers/lora/sx1276/src/sx1276.h
@@ -0,0 +1,364 @@
+/*
+ / _____) _ | |
+( (____ _____ ____ _| |_ _____ ____| |__
+ \____ \| ___ | (_ _) ___ |/ ___) _ \
+ _____) ) ____| | | || |_| ____( (___| | | |
+(______/|_____)_|_|_| \__)_____)\____)_| |_|
+ (C)2013 Semtech
+
+Description: Generic SX1276 driver implementation
+
+License: Revised BSD License, see LICENSE.TXT file include in the project
+
+Maintainer: Miguel Luis and Gregory Cristian
+*/
+#ifndef __SX1276_H__
+#define __SX1276_H__
+#include <stdint.h>
+#include <stdbool.h>
+#include "node/radio.h"
+#include "sx1276Regs-Fsk.h"
+#include "sx1276Regs-LoRa.h"
+
+/*!
+ * Radio FSK modem parameters
+ */
+typedef struct
+{
+ int8_t Power;
+ uint32_t Fdev;
+ uint32_t Bandwidth;
+ uint32_t BandwidthAfc;
+ uint32_t Datarate;
+ uint16_t PreambleLen;
+ bool FixLen;
+ uint8_t PayloadLen;
+ bool CrcOn;
+ bool IqInverted;
+ bool RxContinuous;
+ uint32_t TxTimeout;
+}RadioFskSettings_t;
+
+/*!
+ * Radio FSK packet handler state
+ */
+typedef struct
+{
+ uint8_t PreambleDetected;
+ uint8_t SyncWordDetected;
+ int8_t RssiValue;
+ int32_t AfcValue;
+ uint8_t RxGain;
+ uint16_t Size;
+ uint16_t NbBytes;
+ uint8_t FifoThresh;
+ uint8_t ChunkSize;
+}RadioFskPacketHandler_t;
+
+/*!
+ * Radio LoRa modem parameters
+ */
+typedef struct
+{
+ int8_t Power;
+ uint32_t Bandwidth;
+ uint32_t Datarate;
+ bool LowDatarateOptimize;
+ uint8_t Coderate;
+ uint16_t PreambleLen;
+ bool FixLen;
+ uint8_t PayloadLen;
+ bool CrcOn;
+ bool FreqHopOn;
+ uint8_t HopPeriod;
+ bool IqInverted;
+ bool RxContinuous;
+ uint32_t TxTimeout;
+}RadioLoRaSettings_t;
+
+/*!
+ * Radio LoRa packet handler state
+ */
+typedef struct
+{
+ int8_t SnrValue;
+ int16_t RssiValue;
+ uint8_t Size;
+}RadioLoRaPacketHandler_t;
+
+/*!
+ * Radio Settings
+ */
+typedef struct
+{
+ RadioState_t State;
+ RadioModems_t Modem;
+ uint32_t Channel;
+ RadioFskSettings_t Fsk;
+ RadioFskPacketHandler_t FskPacketHandler;
+ RadioLoRaSettings_t LoRa;
+ RadioLoRaPacketHandler_t LoRaPacketHandler;
+}RadioSettings_t;
+
+/*!
+ * Radio hardware and global parameters
+ */
+typedef struct SX1276_s
+{
+ RadioSettings_t Settings;
+}SX1276_t;
+
+/*!
+ * Hardware IO IRQ callback function definition
+ */
+typedef void ( DioIrqHandler )(void *arg);
+
+/*!
+ * SX1276 definitions
+ */
+#define XTAL_FREQ 32000000
+#define FREQ_STEP 61.03515625
+
+#define RX_BUFFER_SIZE 256
+
+/*!
+ * ============================================================================
+ * Public functions prototypes
+ * ============================================================================
+ */
+
+/*!
+ * \brief Initializes the radio
+ *
+ * \param [IN] events Structure containing the driver callback functions
+ */
+void SX1276Init( RadioEvents_t *events );
+
+/*!
+ * Return current radio status
+ *
+ * \param status Radio status.[RF_IDLE, RF_RX_RUNNING, RF_TX_RUNNING]
+ */
+RadioState_t SX1276GetStatus( void );
+
+/*!
+ * \brief Configures the radio with the given modem
+ *
+ * \param [IN] modem Modem to be used [0: FSK, 1: LoRa]
+ */
+void SX1276SetModem( RadioModems_t modem );
+
+/*!
+ * \brief Sets the channels configuration
+ *
+ * \param [IN] freq Channel RF frequency
+ */
+void SX1276SetChannel( 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 SX1276IsChannelFree( 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 SX1276SetRxConfig or
+ * SX1276SetTxConfig functions must be called.
+ *
+ * \retval randomValue 32 bits random value
+ */
+uint32_t SX1276Random( void );
+
+/*!
+ * \brief Sets the reception parameters
+ *
+ * \remark When using LoRa modem only bandwidths 125, 250 and 500 kHz are supported
+ *
+ * \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 lenght 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 bewteen 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 SX1276SetRxConfig( 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
+ *
+ * \remark When using LoRa modem only bandwidths 125, 250 and 500 kHz are supported
+ *
+ * \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 bewteen 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 SX1276SetTxConfig( 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 Computes the packet time on air in us 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 (us) for the given packet payload length
+ */
+uint32_t SX1276GetTimeOnAir( 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 SX1276Send( uint8_t *buffer, uint8_t size );
+
+/*!
+ * \brief Sets the radio in sleep mode
+ */
+void SX1276SetSleep( void );
+
+/*!
+ * \brief Sets the radio in standby mode
+ */
+void SX1276SetStby( void );
+
+/*!
+ * \brief Sets the radio in reception mode for the given time
+ * \param [IN] timeout Reception timeout [ms] [0: continuous, others timeout]
+ */
+void SX1276SetRx( uint32_t timeout );
+
+/*!
+ * \brief Start a Channel Activity Detection
+ */
+void SX1276StartCad( void );
+
+/*!
+ * \brief Reads the current RSSI value
+ *
+ * \retval rssiValue Current RSSI value in [dBm]
+ */
+int16_t SX1276ReadRssi( RadioModems_t modem );
+
+/*!
+ * \brief Writes the radio register at the specified address
+ *
+ * \param [IN]: addr Register address
+ * \param [IN]: data New register value
+ */
+void SX1276Write( 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 SX1276Read( 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 SX1276WriteBuffer( 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 SX1276ReadBuffer( 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 SX1276SetMaxPayloadLength( RadioModems_t modem, uint8_t max );
+
+#endif // __SX1276_H__
[29/40] incubator-mynewt-core git commit: iptest, stm32_eth;
console_printf() function prototype has changed.
Posted by ja...@apache.org.
iptest, stm32_eth; console_printf() function prototype has changed.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/ae4596c4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/ae4596c4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/ae4596c4
Branch: refs/heads/bluetooth5
Commit: ae4596c41b724c97a06bcee136fd9e1044fb1304
Parents: a819c9b
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed May 3 11:09:15 2017 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed May 3 11:09:15 2017 -0700
----------------------------------------------------------------------
apps/iptest/src/main.c | 4 ++--
hw/drivers/lwip/stm32_eth/src/stm32_eth.c | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ae4596c4/apps/iptest/src/main.c
----------------------------------------------------------------------
diff --git a/apps/iptest/src/main.c b/apps/iptest/src/main.c
index 3ec726e..96820a2 100755
--- a/apps/iptest/src/main.c
+++ b/apps/iptest/src/main.c
@@ -299,9 +299,9 @@ net_cli(int argc, char **argv)
console_printf(" %s/%d\n", addr_str, itf_addr.mifa_plen);
}
}
-#ifndef ARCH_sim
+#if MYNEWT_VAL(MCU_STM32F4) || MYNEWT_VAL(MCU_STM32F7)
} else if (!strcmp(argv[1], "mii")) {
- extern int stm32_mii_dump(void (*func)(const char *fmt, ...));
+ extern int stm32_mii_dump(int (*func)(const char *fmt, ...));
stm32_mii_dump(console_printf);
#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ae4596c4/hw/drivers/lwip/stm32_eth/src/stm32_eth.c
----------------------------------------------------------------------
diff --git a/hw/drivers/lwip/stm32_eth/src/stm32_eth.c b/hw/drivers/lwip/stm32_eth/src/stm32_eth.c
index c9f028d..6aa8a8d 100755
--- a/hw/drivers/lwip/stm32_eth/src/stm32_eth.c
+++ b/hw/drivers/lwip/stm32_eth/src/stm32_eth.c
@@ -462,7 +462,7 @@ stm32_lwip_init(struct netif *nif)
}
int
-stm32_mii_dump(void (*func)(const char *fmt, ...))
+stm32_mii_dump(int (*func)(const char *fmt, ...))
{
int i;
struct stm32_eth_state *ses = &stm32_eth_state;
[26/40] incubator-mynewt-core git commit: os_callout: directly call
callback function in tick interrupt context if have't event queue
Posted by ja...@apache.org.
os_callout: directly call callback function in tick interrupt context if have't event queue
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/4dfbd54b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/4dfbd54b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/4dfbd54b
Branch: refs/heads/bluetooth5
Commit: 4dfbd54ba3a9360573de12fc69e7a28ad877c56d
Parents: 702dc23
Author: wesley <we...@wolinke.com>
Authored: Mon May 1 16:15:45 2017 +0800
Committer: wesley <we...@wolinke.com>
Committed: Mon May 1 16:15:45 2017 +0800
----------------------------------------------------------------------
kernel/os/src/os_callout.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4dfbd54b/kernel/os/src/os_callout.c
----------------------------------------------------------------------
diff --git a/kernel/os/src/os_callout.c b/kernel/os/src/os_callout.c
index bc152fd..2e29826 100644
--- a/kernel/os/src/os_callout.c
+++ b/kernel/os/src/os_callout.c
@@ -160,7 +160,11 @@ os_callout_tick(void)
OS_EXIT_CRITICAL(sr);
if (c) {
- os_eventq_put(c->c_evq, &c->c_ev);
+ if (c->c_evq) {
+ os_eventq_put(c->c_evq, &c->c_ev);
+ } else {
+ c->c_ev.ev_cb(&c->c_ev);
+ }
} else {
break;
}
[13/40] incubator-mynewt-core git commit: MYNEWT-741 Port of
LoRaMac-node library
Posted by ja...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9986f68c/net/lora/node/src/mac/LoRaMacCrypto.c
----------------------------------------------------------------------
diff --git a/net/lora/node/src/mac/LoRaMacCrypto.c b/net/lora/node/src/mac/LoRaMacCrypto.c
new file mode 100644
index 0000000..81f93ed
--- /dev/null
+++ b/net/lora/node/src/mac/LoRaMacCrypto.c
@@ -0,0 +1,203 @@
+/*
+ / _____) _ | |
+( (____ _____ ____ _| |_ _____ ____| |__
+ \____ \| ___ | (_ _) ___ |/ ___) _ \
+ _____) ) ____| | | || |_| ____( (___| | | |
+(______/|_____)_|_|_| \__)_____)\____)_| |_|
+ (C)2013 Semtech
+ ___ _____ _ ___ _ _____ ___ ___ ___ ___
+/ __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __|
+\__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _|
+|___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___|
+embedded.connectivity.solutions===============
+
+Description: LoRa MAC layer implementation
+
+License: Revised BSD License, see LICENSE.TXT file include in the project
+
+Maintainer: Miguel Luis ( Semtech ), Gregory Cristian ( Semtech ) and Daniel Jäckle ( STACKFORCE )
+*/
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include "node/utilities.h"
+
+#include "aes.h"
+#include "cmac.h"
+
+#include "node/mac/LoRaMacCrypto.h"
+
+/*!
+ * CMAC/AES Message Integrity Code (MIC) Block B0 size
+ */
+#define LORAMAC_MIC_BLOCK_B0_SIZE 16
+
+/*!
+ * MIC field computation initial data
+ */
+static uint8_t MicBlockB0[] = { 0x49, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+ };
+
+/*!
+ * Contains the computed MIC field.
+ *
+ * \remark Only the 4 first bytes are used
+ */
+static uint8_t Mic[16];
+
+/*!
+ * Encryption aBlock and sBlock
+ */
+static uint8_t aBlock[] = { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+ };
+static uint8_t sBlock[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+ };
+
+/*!
+ * AES computation context variable
+ */
+static aes_context AesContext;
+
+/*!
+ * CMAC computation context variable
+ */
+//static AES_CMAC_CTX AesCmacCtx[1];
+
+/*!
+ * \brief Computes the LoRaMAC frame MIC field
+ *
+ * \param [IN] buffer Data buffer
+ * \param [IN] size Data buffer size
+ * \param [IN] key AES key to be used
+ * \param [IN] address Frame address
+ * \param [IN] dir Frame direction [0: uplink, 1: downlink]
+ * \param [IN] sequenceCounter Frame sequence counter
+ * \param [OUT] mic Computed MIC field
+ */
+void LoRaMacComputeMic( const uint8_t *buffer, uint16_t size, const uint8_t *key, uint32_t address, uint8_t dir, uint32_t sequenceCounter, uint32_t *mic )
+{
+ MicBlockB0[5] = dir;
+
+ MicBlockB0[6] = ( address ) & 0xFF;
+ MicBlockB0[7] = ( address >> 8 ) & 0xFF;
+ MicBlockB0[8] = ( address >> 16 ) & 0xFF;
+ MicBlockB0[9] = ( address >> 24 ) & 0xFF;
+
+ MicBlockB0[10] = ( sequenceCounter ) & 0xFF;
+ MicBlockB0[11] = ( sequenceCounter >> 8 ) & 0xFF;
+ MicBlockB0[12] = ( sequenceCounter >> 16 ) & 0xFF;
+ MicBlockB0[13] = ( sequenceCounter >> 24 ) & 0xFF;
+
+ MicBlockB0[15] = size & 0xFF;
+
+ //AES_CMAC_Init( AesCmacCtx );
+
+ //AES_CMAC_SetKey( AesCmacCtx, key );
+
+ //AES_CMAC_Update( AesCmacCtx, MicBlockB0, LORAMAC_MIC_BLOCK_B0_SIZE );
+
+ //AES_CMAC_Update( AesCmacCtx, buffer, size & 0xFF );
+
+ //AES_CMAC_Final( Mic, AesCmacCtx );
+
+ *mic = ( uint32_t )( ( uint32_t )Mic[3] << 24 | ( uint32_t )Mic[2] << 16 | ( uint32_t )Mic[1] << 8 | ( uint32_t )Mic[0] );
+}
+
+void LoRaMacPayloadEncrypt( const uint8_t *buffer, uint16_t size, const uint8_t *key, uint32_t address, uint8_t dir, uint32_t sequenceCounter, uint8_t *encBuffer )
+{
+ uint16_t i;
+ uint8_t bufferIndex = 0;
+ uint16_t ctr = 1;
+
+ memset( AesContext.ksch, '\0', 240 );
+ //aes_set_key( key, 16, &AesContext );
+
+ aBlock[5] = dir;
+
+ aBlock[6] = ( address ) & 0xFF;
+ aBlock[7] = ( address >> 8 ) & 0xFF;
+ aBlock[8] = ( address >> 16 ) & 0xFF;
+ aBlock[9] = ( address >> 24 ) & 0xFF;
+
+ aBlock[10] = ( sequenceCounter ) & 0xFF;
+ aBlock[11] = ( sequenceCounter >> 8 ) & 0xFF;
+ aBlock[12] = ( sequenceCounter >> 16 ) & 0xFF;
+ aBlock[13] = ( sequenceCounter >> 24 ) & 0xFF;
+
+ while( size >= 16 )
+ {
+ aBlock[15] = ( ( ctr ) & 0xFF );
+ ctr++;
+ //aes_encrypt( aBlock, sBlock, &AesContext );
+ for( i = 0; i < 16; i++ )
+ {
+ encBuffer[bufferIndex + i] = buffer[bufferIndex + i] ^ sBlock[i];
+ }
+ size -= 16;
+ bufferIndex += 16;
+ }
+
+ if( size > 0 )
+ {
+ aBlock[15] = ( ( ctr ) & 0xFF );
+ //aes_encrypt( aBlock, sBlock, &AesContext );
+ for( i = 0; i < size; i++ )
+ {
+ encBuffer[bufferIndex + i] = buffer[bufferIndex + i] ^ sBlock[i];
+ }
+ }
+}
+
+void LoRaMacPayloadDecrypt( const uint8_t *buffer, uint16_t size, const uint8_t *key, uint32_t address, uint8_t dir, uint32_t sequenceCounter, uint8_t *decBuffer )
+{
+ LoRaMacPayloadEncrypt( buffer, size, key, address, dir, sequenceCounter, decBuffer );
+}
+
+void LoRaMacJoinComputeMic( const uint8_t *buffer, uint16_t size, const uint8_t *key, uint32_t *mic )
+{
+ //AES_CMAC_Init( AesCmacCtx );
+
+ //AES_CMAC_SetKey( AesCmacCtx, key );
+
+ //AES_CMAC_Update( AesCmacCtx, buffer, size & 0xFF );
+
+ //AES_CMAC_Final( Mic, AesCmacCtx );
+
+ *mic = ( uint32_t )( ( uint32_t )Mic[3] << 24 | ( uint32_t )Mic[2] << 16 | ( uint32_t )Mic[1] << 8 | ( uint32_t )Mic[0] );
+}
+
+void LoRaMacJoinDecrypt( const uint8_t *buffer, uint16_t size, const uint8_t *key, uint8_t *decBuffer )
+{
+ memset( AesContext.ksch, '\0', 240 );
+ //aes_set_key( key, 16, &AesContext );
+ //aes_encrypt( buffer, decBuffer, &AesContext );
+ // Check if optional CFList is included
+ if( size >= 16 )
+ {
+ //aes_encrypt( buffer + 16, decBuffer + 16, &AesContext );
+ }
+}
+
+void LoRaMacJoinComputeSKeys( const uint8_t *key, const uint8_t *appNonce, uint16_t devNonce, uint8_t *nwkSKey, uint8_t *appSKey )
+{
+ uint8_t nonce[16];
+ uint8_t *pDevNonce = ( uint8_t * )&devNonce;
+
+ memset( AesContext.ksch, '\0', 240 );
+ //aes_set_key( key, 16, &AesContext );
+
+ memset( nonce, 0, sizeof( nonce ) );
+ nonce[0] = 0x01;
+ memcpy( nonce + 1, appNonce, 6 );
+ memcpy( nonce + 7, pDevNonce, 2 );
+ //aes_encrypt( nonce, nwkSKey, &AesContext );
+
+ memset( nonce, 0, sizeof( nonce ) );
+ nonce[0] = 0x02;
+ memcpy( nonce + 1, appNonce, 6 );
+ memcpy( nonce + 7, pDevNonce, 2 );
+ //aes_encrypt( nonce, appSKey, &AesContext );
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9986f68c/net/lora/node/src/mac/aes.h
----------------------------------------------------------------------
diff --git a/net/lora/node/src/mac/aes.h b/net/lora/node/src/mac/aes.h
new file mode 100644
index 0000000..5fdc143
--- /dev/null
+++ b/net/lora/node/src/mac/aes.h
@@ -0,0 +1,160 @@
+/*
+ ---------------------------------------------------------------------------
+ Copyright (c) 1998-2008, Brian Gladman, Worcester, UK. All rights reserved.
+
+ LICENSE TERMS
+
+ The redistribution and use of this software (with or without changes)
+ is allowed without the payment of fees or royalties provided that:
+
+ 1. source code distributions include the above copyright notice, this
+ list of conditions and the following disclaimer;
+
+ 2. binary distributions include the above copyright notice, this list
+ of conditions and the following disclaimer in their documentation;
+
+ 3. the name of the copyright holder is not used to endorse products
+ built using this software without specific written permission.
+
+ DISCLAIMER
+
+ This software is provided 'as is' with no explicit or implied warranties
+ in respect of its properties, including, but not limited to, correctness
+ and/or fitness for purpose.
+ ---------------------------------------------------------------------------
+ Issue 09/09/2006
+
+ This is an AES implementation that uses only 8-bit byte operations on the
+ cipher state.
+ */
+
+#ifndef AES_H
+#define AES_H
+
+#if 1
+# define AES_ENC_PREKEYED /* AES encryption with a precomputed key schedule */
+#endif
+#if 0
+# define AES_DEC_PREKEYED /* AES decryption with a precomputed key schedule */
+#endif
+#if 0
+# define AES_ENC_128_OTFK /* AES encryption with 'on the fly' 128 bit keying */
+#endif
+#if 0
+# define AES_DEC_128_OTFK /* AES decryption with 'on the fly' 128 bit keying */
+#endif
+#if 0
+# define AES_ENC_256_OTFK /* AES encryption with 'on the fly' 256 bit keying */
+#endif
+#if 0
+# define AES_DEC_256_OTFK /* AES decryption with 'on the fly' 256 bit keying */
+#endif
+
+#define N_ROW 4
+#define N_COL 4
+#define N_BLOCK (N_ROW * N_COL)
+#define N_MAX_ROUNDS 14
+
+typedef uint8_t return_type;
+
+/* Warning: The key length for 256 bit keys overflows a byte
+ (see comment below)
+*/
+
+typedef uint8_t length_type;
+
+typedef struct
+{ uint8_t ksch[(N_MAX_ROUNDS + 1) * N_BLOCK];
+ uint8_t rnd;
+} aes_context;
+
+/* The following calls are for a precomputed key schedule
+
+ NOTE: If the length_type used for the key length is an
+ unsigned 8-bit character, a key length of 256 bits must
+ be entered as a length in bytes (valid inputs are hence
+ 128, 192, 16, 24 and 32).
+*/
+
+#if defined( AES_ENC_PREKEYED ) || defined( AES_DEC_PREKEYED )
+
+return_type aes_set_key( const uint8_t key[],
+ length_type keylen,
+ aes_context ctx[1] );
+#endif
+
+#if defined( AES_ENC_PREKEYED )
+
+return_type aes_encrypt( const uint8_t in[N_BLOCK],
+ uint8_t out[N_BLOCK],
+ const aes_context ctx[1] );
+
+return_type aes_cbc_encrypt( const uint8_t *in,
+ uint8_t *out,
+ int32_t n_block,
+ uint8_t iv[N_BLOCK],
+ const aes_context ctx[1] );
+#endif
+
+#if defined( AES_DEC_PREKEYED )
+
+return_type aes_decrypt( const uint8_t in[N_BLOCK],
+ uint8_t out[N_BLOCK],
+ const aes_context ctx[1] );
+
+return_type aes_cbc_decrypt( const uint8_t *in,
+ uint8_t *out,
+ int32_t n_block,
+ uint8_t iv[N_BLOCK],
+ const aes_context ctx[1] );
+#endif
+
+/* The following calls are for 'on the fly' keying. In this case the
+ encryption and decryption keys are different.
+
+ The encryption subroutines take a key in an array of bytes in
+ key[L] where L is 16, 24 or 32 bytes for key lengths of 128,
+ 192, and 256 bits respectively. They then encrypts the input
+ data, in[] with this key and put the reult in the output array
+ out[]. In addition, the second key array, o_key[L], is used
+ to output the key that is needed by the decryption subroutine
+ to reverse the encryption operation. The two key arrays can
+ be the same array but in this case the original key will be
+ overwritten.
+
+ In the same way, the decryption subroutines output keys that
+ can be used to reverse their effect when used for encryption.
+
+ Only 128 and 256 bit keys are supported in these 'on the fly'
+ modes.
+*/
+
+#if defined( AES_ENC_128_OTFK )
+void aes_encrypt_128( const uint8_t in[N_BLOCK],
+ uint8_t out[N_BLOCK],
+ const uint8_t key[N_BLOCK],
+ uint8_t o_key[N_BLOCK] );
+#endif
+
+#if defined( AES_DEC_128_OTFK )
+void aes_decrypt_128( const uint8_t in[N_BLOCK],
+ uint8_t out[N_BLOCK],
+ const uint8_t key[N_BLOCK],
+ uint8_t o_key[N_BLOCK] );
+#endif
+
+#if defined( AES_ENC_256_OTFK )
+void aes_encrypt_256( const uint8_t in[N_BLOCK],
+ uint8_t out[N_BLOCK],
+ const uint8_t key[2 * N_BLOCK],
+ uint8_t o_key[2 * N_BLOCK] );
+#endif
+
+#if defined( AES_DEC_256_OTFK )
+void aes_decrypt_256( const uint8_t in[N_BLOCK],
+ uint8_t out[N_BLOCK],
+ const uint8_t key[2 * N_BLOCK],
+ uint8_t o_key[2 * N_BLOCK] );
+#endif
+
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9986f68c/net/lora/node/src/mac/cmac.h
----------------------------------------------------------------------
diff --git a/net/lora/node/src/mac/cmac.h b/net/lora/node/src/mac/cmac.h
new file mode 100644
index 0000000..c12e970
--- /dev/null
+++ b/net/lora/node/src/mac/cmac.h
@@ -0,0 +1,63 @@
+/**************************************************************************
+Copyright (C) 2009 Lander Casado, Philippas Tsigas
+
+All rights reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files
+(the "Software"), to deal with the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimers. Redistributions in
+binary form must reproduce the above copyright notice, this list of
+conditions and the following disclaimers in the documentation and/or
+other materials provided with the distribution.
+
+In no event shall the authors or copyright holders be liable for any special,
+incidental, indirect or consequential damages of any kind, or any damages
+whatsoever resulting from loss of use, data or profits, whether or not
+advised of the possibility of damage, and on any theory of liability,
+arising out of or in connection with the use or performance of this software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS WITH THE SOFTWARE
+
+*****************************************************************************/
+
+#ifndef _CMAC_H_
+#define _CMAC_H_
+
+#include "aes.h"
+
+#define AES_CMAC_KEY_LENGTH 16
+#define AES_CMAC_DIGEST_LENGTH 16
+
+typedef struct _AES_CMAC_CTX {
+ aes_context rijndael;
+ uint8_t X[16];
+ uint8_t M_last[16];
+ uint32_t M_n;
+ } AES_CMAC_CTX;
+
+//#include <sys/cdefs.h>
+
+//__BEGIN_DECLS
+void AES_CMAC_Init(AES_CMAC_CTX * ctx);
+void AES_CMAC_SetKey(AES_CMAC_CTX * ctx, const uint8_t key[AES_CMAC_KEY_LENGTH]);
+void AES_CMAC_Update(AES_CMAC_CTX * ctx, const uint8_t * data, uint32_t len);
+ // __attribute__((__bounded__(__string__,2,3)));
+void AES_CMAC_Final(uint8_t digest[AES_CMAC_DIGEST_LENGTH], AES_CMAC_CTX * ctx);
+ // __attribute__((__bounded__(__minbytes__,1,AES_CMAC_DIGEST_LENGTH)));
+//__END_DECLS
+
+#endif /* _CMAC_H_ */
+
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9986f68c/net/lora/node/src/misc.c
----------------------------------------------------------------------
diff --git a/net/lora/node/src/misc.c b/net/lora/node/src/misc.c
new file mode 100644
index 0000000..3d4576a
--- /dev/null
+++ b/net/lora/node/src/misc.c
@@ -0,0 +1,45 @@
+#include <stdlib.h>
+
+#include "syscfg/syscfg.h"
+#include "node/utilities.h"
+#include "lora_priv.h"
+
+int32_t
+randr(int32_t min, int32_t max)
+{
+ return rand() % (max - min + 1) + min;
+}
+
+void
+memcpyr( uint8_t *dst, const uint8_t *src, uint16_t size )
+{
+ dst = dst + ( size - 1 );
+ while( size-- )
+ {
+ *dst-- = *src++;
+ }
+}
+
+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);
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9986f68c/net/lora/node/src/timer.c
----------------------------------------------------------------------
diff --git a/net/lora/node/src/timer.c b/net/lora/node/src/timer.c
new file mode 100644
index 0000000..d445b01
--- /dev/null
+++ b/net/lora/node/src/timer.c
@@ -0,0 +1,15 @@
+#include "os/os.h"
+#include "node/timer.h"
+#include "node/utilities.h"
+
+uint32_t
+TimerGetElapsedTime(uint32_t savedTime)
+{
+ return savedTime - os_cputime_get32();
+}
+
+uint32_t
+TimerGetFutureTime(uint32_t eventInFuture)
+{
+ return os_cputime_get32() + eventInFuture;
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9986f68c/net/lora/node/syscfg.yml
----------------------------------------------------------------------
diff --git a/net/lora/node/syscfg.yml b/net/lora/node/syscfg.yml
new file mode 100644
index 0000000..43fd05b
--- /dev/null
+++ b/net/lora/node/syscfg.yml
@@ -0,0 +1,39 @@
+#
+# 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 lora/node hardware
+ drivers.
+ value: 1
+
+ LORA_NODE_FREQ_BAND:
+ description: >
+ Which frequency band to use. Valid values are:
+ o 433
+ o 470
+ o 780
+ o 868
+ o 915
+ value: 868
+
+ LORA_NODE_CLI:
+ description: "Include shell commands for LoRa operations"
+ value: 0