Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lorawan upstream downlink #2

Open
wants to merge 27 commits into
base: lorawan-upstream
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7f0e077
drivers: lora: Prepare the SX1276 driver for LoRaWAN
Mani-Sadhasivam Mar 4, 2020
1ca7059
drivers: lora: Add CheckRfFrequency callback to SX1276 driver
KubaFYI Mar 4, 2020
08e0235
include: Add LoRaWAN API
Mani-Sadhasivam Mar 4, 2020
010f460
lorawan: Add initial support for LoRaWAN
Mani-Sadhasivam Mar 4, 2020
7f040e4
samples: lorawan: Add Class-A LoRaWAN sample application
Mani-Sadhasivam Mar 4, 2020
303e759
lorawan: Add support for system_max_rs_error
KubaFYI Mar 4, 2020
7bb80fa
lorawan: Rework error handling code
KubaFYI Mar 12, 2020
f425e69
CODEOWNERS: Add entry for LoRaWAN
Mani-Sadhasivam Mar 4, 2020
768a688
west: Update loramac-node repo
Mani-Sadhasivam Mar 22, 2020
076a769
drivers: lora: Prepare the SX1276 driver for LoRaWAN
Mani-Sadhasivam Mar 4, 2020
1acab10
drivers: lora: Add CheckRfFrequency callback to SX1276 driver
KubaFYI Mar 4, 2020
393d076
include: Add LoRaWAN API
Mani-Sadhasivam Mar 4, 2020
1c7ca9f
lorawan: Add initial support for LoRaWAN
Mani-Sadhasivam Mar 4, 2020
2b27ea8
samples: lorawan: Add Class-A LoRaWAN sample application
Mani-Sadhasivam Mar 4, 2020
6706335
lorawan: Add support for system_max_rs_error
KubaFYI Mar 4, 2020
87c79d6
lorawan: Rework error handling code
KubaFYI Mar 12, 2020
cbbc043
CODEOWNERS: Add entry for LoRaWAN
Mani-Sadhasivam Mar 4, 2020
2b2d81e
west: Update loramac-node repo
Mani-Sadhasivam Mar 22, 2020
067e4d5
Merge branch 'lorawan-upstream' of github.com:Mani-Sadhasivam/zephyr …
KubaFYI Jun 9, 2020
d1a2b8e
Add downlink latest message read functionality.
KubaFYI May 12, 2020
2c91d4c
Reshuffled Kconfig to make usage of ring buffer optional (as it causes
KubaFYI Jun 3, 2020
2f677e7
Get rid of warnings.
KubaFYI Jun 3, 2020
65903c1
Update with main lorawan-upstream branch
KubaFYI Jun 9, 2020
7083925
Revert "boards: arm: adafruit_feather_m0_basic_proto: Set flash offset"
KubaFYI May 15, 2020
1fae38a
Make the Feather M0 overlay work with new device referencing style
KubaFYI Jun 11, 2020
4b2d7f3
Fix problems with ring buffer use.
KubaFYI Jun 11, 2020
078ff36
Fix build warnings.
KubaFYI Jun 11, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@
/include/logging/ @nordic-krch
/include/net/ @jukkar @tbursztyka @pfalcon
/include/net/buf.h @jukkar @jhedberg @tbursztyka @pfalcon
/include/net/lorawan.h @Mani-Sadhasivam
/include/posix/ @pfalcon
/include/power/power.h @wentongwu @nashif
/include/ptp_clock.h @jukkar
Expand Down Expand Up @@ -379,6 +380,7 @@
/samples/drivers/ht16k33/ @henrikbrixandersen
/samples/drivers/lora/ @Mani-Sadhasivam
/samples/drivers/counter/maxim_ds3231/ @pabigot
/samples/lorawan/ @Mani-Sadhasivam
/samples/net/ @jukkar @tbursztyka @pfalcon
/samples/net/dns_resolve/ @jukkar @tbursztyka @pfalcon
/samples/net/lwm2m_client/ @rlubos
Expand Down Expand Up @@ -442,6 +444,7 @@
/subsys/fs/nvs/ @Laczen
/subsys/logging/ @nordic-krch
/subsys/logging/log_backend_net.c @nordic-krch @jukkar
/subsys/lorawan/ @Mani-Sadhasivam
/subsys/mgmt/ @carlescufi @nvlsianpu
/subsys/mgmt/smp_udp.c @aunsbjerg
/subsys/net/buf.c @jukkar @jhedberg @tbursztyka @pfalcon
Expand Down
2 changes: 0 additions & 2 deletions boards/arm/adafruit_feather_m0_basic_proto/board.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@
#
# SPDX-License-Identifier: Apache-2.0

board_runner_args(bossac "--offset=0x2000")

include(${ZEPHYR_BASE}/boards/common/bossac.board.cmake)
9 changes: 8 additions & 1 deletion drivers/lora/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# SPDX-License-Identifier: Apache-2.0

zephyr_library_named(loramac-node)
# LoRa drivers depend on the include directories exposed by the loramac-node
# library. Hence, if it exists then the source files are added to that otherwise
# a library with same name is created.
if(TARGET loramac-node)
set(ZEPHYR_CURRENT_LIBRARY loramac-node)
else()
zephyr_library_named(loramac-node)
endif()

zephyr_library_sources_ifdef(CONFIG_LORA_SHELL shell.c)
zephyr_library_sources_ifdef(CONFIG_LORA_SX1276 sx1276.c)
41 changes: 38 additions & 3 deletions drivers/lora/sx1276.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ LOG_MODULE_REGISTER(sx1276);
#define SX1276_REG_PA_DAC 0x4d
#define SX1276_REG_VERSION 0x42

#define BOARD_TCXO_WAKEUP_TIME 5

static u32_t saved_time;
extern DioIrqHandler *DioIrq[];

Expand Down Expand Up @@ -60,13 +62,15 @@ struct sx1276_data {
struct k_sem data_sem;
struct k_timer timer;
RadioEvents_t sx1276_event;
/* TODO: Use Non-volatile memory for backup */
volatile u32_t backup_reg[2];
u8_t *rx_buf;
u8_t rx_len;
s8_t snr;
s16_t rssi;
} dev_data;

bool SX1276CheckRfFrequency(uint32_t frequency)
bool SX1276CheckRfFrequency(u32_t frequency)
{
/* TODO */
return true;
Expand All @@ -82,6 +86,11 @@ void SX1276SetBoardTcxo(u8_t state)
/* TODO */
}

u32_t SX1276GetBoardTcxoWakeupTime(void)
{
return BOARD_TCXO_WAKEUP_TIME;
}

void SX1276SetAntSw(u8_t opMode)
{
/* TODO */
Expand All @@ -99,12 +108,12 @@ void SX1276Reset(void)
k_sleep(K_MSEC(6));
}

void BoardCriticalSectionBegin(uint32_t *mask)
void BoardCriticalSectionBegin(u32_t *mask)
{
*mask = irq_lock();
}

void BoardCriticalSectionEnd(uint32_t *mask)
void BoardCriticalSectionEnd(u32_t *mask)
{
irq_unlock(*mask);
}
Expand Down Expand Up @@ -176,6 +185,28 @@ static void sx1276_dio_work_handle(struct k_work *work)
(*DioIrq[dio])(NULL);
}

u32_t RtcGetCalendarTime(uint16_t *milliseconds)
{
u32_t now = k_uptime_get_32();

*milliseconds = now;

/* Return in seconds */
return now / MSEC_PER_SEC;
}

void RtcBkupWrite(u32_t data0, uint32_t data1)
{
dev_data.backup_reg[0] = data0;
dev_data.backup_reg[1] = data1;
}

void RtcBkupRead(u32_t *data0, uint32_t *data1)
{
*data0 = dev_data.backup_reg[0];
*data1 = dev_data.backup_reg[1];
}

static void sx1276_irq_callback(struct device *dev,
struct gpio_callback *cb, u32_t pins)
{
Expand Down Expand Up @@ -463,6 +494,8 @@ const struct Radio_s Radio = {
.Random = SX1276Random,
.SetRxConfig = SX1276SetRxConfig,
.SetTxConfig = SX1276SetTxConfig,
.CheckRfFrequency = SX1276CheckRfFrequency,
.TimeOnAir = SX1276GetTimeOnAir,
.Send = SX1276Send,
.Sleep = SX1276SetSleep,
.Standby = SX1276SetStby,
Expand All @@ -472,6 +505,8 @@ const struct Radio_s Radio = {
.WriteBuffer = SX1276WriteBuffer,
.ReadBuffer = SX1276ReadBuffer,
.SetMaxPayloadLength = SX1276SetMaxPayloadLength,
.SetPublicNetwork = SX1276SetPublicNetwork,
.GetWakeupTime = SX1276GetWakeupTime,
.IrqProcess = NULL,
.RxBoosted = NULL,
.SetRxDutyCycle = NULL,
Expand Down
149 changes: 149 additions & 0 deletions include/net/lorawan.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/*
* Copyright (c) 2019 Manivannan Sadhasivam <mani@kernel.org>
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef ZEPHYR_INCLUDE_NET_LORAWAN_H_
#define ZEPHYR_INCLUDE_NET_LORAWAN_H_

/**
* @file
* @brief Public LoRaWAN APIs
*/

#include <zephyr/types.h>
#include <device.h>

/**
* @brief LoRaWAN class types.
*/
enum lorawan_class {
LORAWAN_CLASS_A = 0x00,
LORAWAN_CLASS_B = 0x01,
LORAWAN_CLASS_C = 0x02,
};

/**
* @brief LoRaWAN activation types.
*/
enum lorawan_act_type {
LORAWAN_ACT_OTAA = 0,
LORAWAN_ACT_ABP,
};

/**
* @brief LoRaWAN datarate types.
*/
enum lorawan_datarate {
LORAWAN_DR_0 = 0,
LORAWAN_DR_1,
LORAWAN_DR_2,
LORAWAN_DR_3,
LORAWAN_DR_4,
LORAWAN_DR_5,
LORAWAN_DR_6,
LORAWAN_DR_7,
LORAWAN_DR_8,
LORAWAN_DR_9,
LORAWAN_DR_10,
LORAWAN_DR_11,
LORAWAN_DR_12,
LORAWAN_DR_13,
LORAWAN_DR_14,
LORAWAN_DR_15,
};

struct lorawan_mib_config {
enum lorawan_class lw_class;
u8_t *dev_eui;
u8_t *join_eui;
u8_t *app_eui;
u8_t *app_key;
u8_t *nwk_key;
u32_t system_max_rs_error;
bool pub_nw;
bool adr_enable;
};

/**
* @brief Configure the LoRaWAN stack
*
* Configure the LoRaWAN stack using MIB (Mac Information Base) parameters.
*
* @param mib_config MIB configuration
*
* @return 0 if successful, negative errno code if failure
*/
int lorawan_config(struct lorawan_mib_config *mib_config);

/**
* @brief Join the LoRaWAN network
*
* Join the LoRaWAN network using either OTAA or AWB.
*
* @param datarate Datarate to be used for network join
* @param mode Activation mode
*
* @return 0 if successful, negative errno code if failure
*/
int lorawan_join_network(enum lorawan_datarate datarate,
enum lorawan_act_type mode);

/**
* @brief Send data to the LoRaWAN network
*
* Send data to the connected LoRaWAN network.
*
* @param port Port to be used for sending data. Must be set if the
* payload is not empty.
* @param datarate Datarate to be used for sending data
* @param data Data buffer to be sent
* @param len Length of the buffer to be sent. Maximum length of this
* buffer is 255 bytes but the actual payload size varies with
* region and datarate.
* @param confirm Use confirmed messages
* @param tries Number of tries needed for sending the data in case the Ack
* from server is not received
*
* @return 0 if successful, negative errno code if failure
*/
int lorawan_send(u8_t port, enum lorawan_datarate datarate,
u8_t *data, u8_t len, bool confirm, u8_t tries);
/**
* @brief Check if there is uncollected received data from the LoRaWAN network
*
* Check if there is uncolllected received data from the LoRaWAN network
*
* @return 0 or positive number indicating the number of received messages
* waiting to be read from the buffer, or negative errno code if failure
*/
int lorawan_receive_available();

/**
* @brief Check if any uncollected received incoming data was discarded
*
* Check if any uncollected received incoming data was discarded due to
* insufficient free space in the RX buffer.
*
* @return 0 or positive number indicating the number of discarded messages
*/
int lorawan_receive_discarded();

/**
* @brief Read uncollected received data from the LoRaWAN network
*
* Read uncollected received data from the LoRaWAN network. This function will
* return each received message only once - each read opration removes the
* oldest downlink measage from the buffer of received unread messages.
*
* @param port Port at which the message arrived
* @param data Data buffer where received data shall be placed
* @param len Size of the \p data buffer available. Messages with
* payloads larger than the buffer will be truncated
*
* @return 0 if successful, negative errno code if failure
*/
int lorawan_receive_read(u8_t *port, u8_t *data, u8_t len);

#endif /* ZEPHYR_INCLUDE_NET_LORAWAN_H_ */
6 changes: 6 additions & 0 deletions modules/Kconfig.loramac-node
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ config HAS_SEMTECH_LORAMAC
help
This option enables the use of Semtech's LoRaMac stack

config HAS_SEMTECH_SOFT_SE
bool "Semtech Secure Element software implementation"
help
This option enables the use of Semtech's Secure Element
software implementation

config HAS_SEMTECH_RADIO_DRIVERS
bool "Semtech LoRa Radio Drivers"
help
Expand Down
9 changes: 9 additions & 0 deletions samples/lorawan/class_a/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.13.1)

include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project(lorawan)

FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources})
1 change: 1 addition & 0 deletions samples/lorawan/class_a/boards/96b_wistrio.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CONFIG_SPI_1=y
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* This overlay suits Adafrut Feather M0 LoRa edition.
*
* Copyritght (c) 2020: R3-IoT Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*/

&sercom4 {
status = "okay";
compatible = "atmel,sam0-spi";

cs-gpios = <&porta 6 0>;

dipo = <0>;
dopo = <1>;

lora: sx1276@0 {
compatible = "semtech,sx1276";
reg = <0>;
label = "sx1276";
reset-gpios = <&portb 13 0>;
dio-gpios = <&porta 9 0>;

spi-max-frequency = <1000000>;
};
};

/ {

aliases {
lora0 = &lora;
};
};
11 changes: 11 additions & 0 deletions samples/lorawan/class_a/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CONFIG_LOG=y
CONFIG_SPI=y
CONFIG_GPIO=y
CONFIG_NEWLIB_LIBC=y
CONFIG_LORA=y
CONFIG_LORA_SX1276=y
CONFIG_LORAWAN=y
CONFIG_LORAWAN_USE_RX_RING_BUFFER=n

CONFIG_MAIN_STACK_SIZE=2048
CONFIG_LORAWAN_USE_RX_RING_BUFFER=y
8 changes: 8 additions & 0 deletions samples/lorawan/class_a/sample.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
common:
tags: lorawan
sample:
description: Demonstration of Class-A LoRaWAN functionality
name: LoRaWAN Class-A
tests:
samples.lorawan.class_a:
platform_whitelist: 96b_wistrio
Loading