Skip to content

Commit

Permalink
Merge pull request ARMmbed#12485 from artokin/nanostack_for_mbedos_5_…
Browse files Browse the repository at this point in the history
…15_branch

Nanostack release for Mbed OS 5.15
  • Loading branch information
0xc0170 authored Apr 2, 2020
2 parents 41273e3 + 1a5cf1f commit 978db96
Show file tree
Hide file tree
Showing 100 changed files with 2,363 additions and 833 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ static void rf_if_reset_radio(void)
#else
rf->spi.frequency(MBED_CONF_ATMEL_RF_LOW_SPI_SPEED);
#endif
rf->IRQ.rise(0);
rf->IRQ.rise(nullptr);
rf->RST = 1;
ThisThread::sleep_for(2);
rf->RST = 0;
Expand Down
13 changes: 7 additions & 6 deletions components/802.15.4_RF/mcr20a-rf-driver/source/MCR20Drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#if defined(MBED_CONF_NANOSTACK_CONFIGURATION) && DEVICE_SPI && DEVICE_INTERRUPTIN && defined(MBED_CONF_RTOS_PRESENT)

#include "platform/mbed_critical.h"
#include <string.h>

/*****************************************************************************
* PRIVATE VARIABLES *
Expand Down Expand Up @@ -165,7 +166,7 @@ void MCR20Drv_DirectAccessSPIMultiByteWrite
{
uint8_t txData;

if ((numOfBytes == 0) || (byteArray == 0)) {
if ((numOfBytes == 0) || (byteArray == NULL)) {
return;
}

Expand Down Expand Up @@ -230,7 +231,7 @@ void MCR20Drv_PB_SPIBurstWrite
{
uint8_t txData;

if ((numOfBytes == 0) || (byteArray == 0)) {
if ((numOfBytes == 0) || (byteArray == NULL)) {
return;
}

Expand Down Expand Up @@ -301,7 +302,7 @@ uint8_t MCR20Drv_DirectAccessSPIMultiByteRead
uint8_t txData;
uint8_t phyIRQSTS1;

if ((numOfBytes == 0) || (byteArray == 0)) {
if ((numOfBytes == 0) || (byteArray == NULL)) {
return 0;
}

Expand Down Expand Up @@ -338,7 +339,7 @@ uint8_t MCR20Drv_PB_SPIBurstRead
uint8_t txData;
uint8_t phyIRQSTS1;

if ((numOfBytes == 0) || (byteArray == 0)) {
if ((numOfBytes == 0) || (byteArray == NULL)) {
return 0;
}

Expand Down Expand Up @@ -406,7 +407,7 @@ void MCR20Drv_IndirectAccessSPIMultiByteWrite
{
uint16_t txData;

if ((numOfBytes == 0) || (byteArray == 0)) {
if ((numOfBytes == 0) || (byteArray == NULL)) {
return;
}

Expand Down Expand Up @@ -473,7 +474,7 @@ void MCR20Drv_IndirectAccessSPIMultiByteRead
{
uint16_t txData;

if ((numOfBytes == 0) || (byteArray == 0)) {
if ((numOfBytes == 0) || (byteArray == NULL)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ static rf_mode_e rf_mode = RF_MODE_NORMAL;
static bool rf_update_config = false;
static uint16_t cur_packet_len = 0xffff;
static uint32_t receiver_ready_timestamp;

static int16_t rssi_threshold = RSSI_THRESHOLD;
static uint32_t tx_start_time = 0;

/* Channel configurations for sub-GHz */
static phy_rf_channel_configuration_s phy_subghz = {
Expand Down Expand Up @@ -276,6 +276,20 @@ static uint32_t rf_get_timestamp(void)
return (uint32_t)rf->tx_timer.read_us();
}

static void rf_update_tx_active_time(void)
{
if (device_driver.phy_rf_statistics) {
device_driver.phy_rf_statistics->tx_active_time += rf_get_timestamp() - tx_start_time;
}
}

static void rf_update_rx_active_time(void)
{
if (device_driver.phy_rf_statistics) {
device_driver.phy_rf_statistics->rx_active_time += rf_get_timestamp() - rx_time;
}
}

static void rf_lock(void)
{
platform_enter_critical();
Expand Down Expand Up @@ -739,6 +753,7 @@ static void rf_tx_sent_handler(void)
rf_disable_interrupt(TX_DATA_SENT);
if (rf_state != RF_TX_ACK) {
tx_finnish_time = rf_get_timestamp();
rf_update_tx_active_time();
TEST_TX_DONE
rf_state = RF_IDLE;
rf_receive(rf_rx_channel);
Expand Down Expand Up @@ -771,6 +786,7 @@ static void rf_start_tx(void)
rf_disable_all_interrupts();
rf_poll_state_change(S2LP_STATE_READY);
rf_state_change(S2LP_STATE_TX, false);
tx_start_time = rf_get_timestamp();
// More TX data to be written in FIFO when TX threshold interrupt occurs
if (tx_data_ptr) {
rf_enable_interrupt(TX_FIFO_ALMOST_EMPTY);
Expand Down Expand Up @@ -805,6 +821,7 @@ static void rf_cca_timer_interrupt(void)
}
rf_flush_tx_fifo();
tx_finnish_time = rf_get_timestamp();
rf_update_tx_active_time();
if (device_driver.phy_tx_done_cb) {
device_driver.phy_tx_done_cb(rf_radio_driver_id, mac_tx_handle, PHY_LINK_CCA_FAIL, 0, 0);
}
Expand All @@ -825,6 +842,9 @@ static void rf_cca_timer_interrupt(void)
rf_start_tx();
rf_state = RF_TX_STARTED;
TEST_TX_STARTED
if (device_driver.phy_rf_statistics) {
device_driver.phy_rf_statistics->tx_bytes += tx_data_length;
}
}
}
}
Expand All @@ -843,10 +863,12 @@ static void rf_backup_timer_interrupt(void)
{
tx_finnish_time = rf_get_timestamp();
if (rf_state == RF_RX_STARTED) {
rf_update_rx_active_time();
if (device_driver.phy_rf_statistics) {
device_driver.phy_rf_statistics->rx_timeouts++;
}
} else {
rf_update_tx_active_time();
if (device_driver.phy_rf_statistics) {
device_driver.phy_rf_statistics->tx_timeouts++;
}
Expand Down Expand Up @@ -921,13 +943,17 @@ static void rf_send_ack(uint8_t seq)
rf_start_tx();
TEST_ACK_TX_STARTED
rf_backup_timer_start(ACK_SENDING_TIME);
if (device_driver.phy_rf_statistics) {
device_driver.phy_rf_statistics->tx_bytes += sizeof(ack_frame);
}
}

static void rf_handle_ack(uint8_t seq_number, uint8_t pending)
{
phy_link_tx_status_e phy_status;
if (tx_sequence == (uint16_t)seq_number) {
tx_finnish_time = rf_get_timestamp();
rf_update_tx_active_time();
if (pending) {
phy_status = PHY_LINK_TX_DONE_PENDING;
} else {
Expand Down Expand Up @@ -966,6 +992,9 @@ static void rf_rx_ready_handler(void)
rf_send_ack(rx_buffer[2]);
}
}
if (device_driver.phy_rf_statistics) {
device_driver.phy_rf_statistics->rx_bytes += rx_data_length;
}
} else {
rf_state = RF_IDLE;
int8_t rssi = (rf_read_register(RSSI_LEVEL) - RSSI_OFFSET);
Expand Down Expand Up @@ -1072,6 +1101,7 @@ static void rf_irq_task_process_irq(void)
if ((irq_status & (1 << TX_FIFO_UNF_OVF)) && (enabled_interrupts & (1 << TX_FIFO_UNF_OVF))) {
rf_backup_timer_stop();
tx_finnish_time = rf_get_timestamp();
rf_update_tx_active_time();
TEST_TX_DONE
device_driver.phy_tx_done_cb(rf_radio_driver_id, mac_tx_handle, PHY_LINK_CCA_FAIL, 1, 0);
rf_send_command(S2LP_CMD_SABORT);
Expand All @@ -1087,6 +1117,7 @@ static void rf_irq_task_process_irq(void)
}
} else if (rf_state == RF_RX_STARTED) {
if ((irq_status & (1 << RX_DATA_READY)) && (enabled_interrupts & (1 << RX_DATA_READY))) {
rf_update_rx_active_time();
if (!(irq_status & (1 << CRC_ERROR))) {
rf_rx_ready_handler();
} else {
Expand All @@ -1112,6 +1143,7 @@ static void rf_irq_task_process_irq(void)
}
}
if ((irq_status & (1 << RX_FIFO_UNF_OVF)) && (enabled_interrupts & (1 << RX_FIFO_UNF_OVF))) {
rf_update_rx_active_time();
TEST_RX_DONE
rf_backup_timer_stop();
rf_send_command(S2LP_CMD_SABORT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ uint_fast8_t ip6_prefix_tos(const void *prefix, uint_fast8_t prefix_len, char *p
* IPv4 tunneling addresses are not covered.
*
* \param ip6addr IPv6 address in string format.
* \param len Lenght of ipv6 string, maximum of 41.
* \param len Length of ipv6 string, maximum of 41.
* \param dest buffer for address. MUST be 16 bytes. Filled with 0 on error.
* \return boolean set to true if conversion succeed, false if it didn't
*/
Expand Down
10 changes: 5 additions & 5 deletions features/nanostack/coap-service/coap-service/coap_service_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ extern void coap_service_close_secure_connection(int8_t service_id, uint8_t dest
* \param destination_addr_ptr Receiver IPv6 address.
* \param port Receiver port number.
* \param *data_ptr Pointer to the data.
* \param data_len Lenght of the data.
* \param data_len Length of the data.
*
* \return 0 for success / -1 for failure
*/
Expand All @@ -199,7 +199,7 @@ typedef int coap_service_virtual_socket_send_cb(int8_t service_id, uint8_t desti
* \param source_addr_ptr Receiver IPv6 address.
* \param port Receiver port number.
* \param *data_ptr Pointer to the data
* \param data_len Lenght of the data
* \param data_len Length of the data
*
* \return 0 for success / -1 for failure
*/
Expand Down Expand Up @@ -257,7 +257,7 @@ extern int8_t coap_service_unregister_uri(int8_t service_id, const char *uri);
* \param *uri Uri address.
* \param cont_type Content type can be found from sn_coap_header.
* \param payload_ptr Pointer to message content.
* \param payload_len Lenght of the message.
* \param payload_len Length of the message.
* \param *request_response_cb Callback to inform result of the request.
*
* \return msg_id Id number of the current message.
Expand All @@ -276,7 +276,7 @@ extern uint16_t coap_service_request_send(int8_t service_id, uint8_t options, co
* \param message_code Message code can be found from sn_coap_header.
* \param content_type Content type can be found from sn_coap_header.
* \param payload_ptr Pointer to message content.
* \param payload_len Lenght of the message.
* \param payload_len Length of the message.
*
* \return -1 For failure
*- 0 For success
Expand All @@ -295,7 +295,7 @@ extern int8_t coap_service_response_send(int8_t service_id, uint8_t options, sn_
* \param message_code Message code can be found from sn_coap_header.
* \param content_type Content type can be found from sn_coap_header.
* \param payload_ptr Pointer to message content.
* \param payload_len Lenght of the message.
* \param payload_len Length of the message.
*
* \return -1 For failure
*- 0 For success
Expand Down
3 changes: 2 additions & 1 deletion features/nanostack/sal-stack-nanostack/nanostack/fhss_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,10 @@ typedef void fhss_data_tx_done(const fhss_api_t *api, bool waiting_ack, bool tx_
* @param api FHSS instance.
* @param handle Handle of the data request.
* @param frame_type Frame type of packet (Frames types are defined by FHSS api).
* @param channel Channel wanted to black list temporarily.
* @return true if frame has to be queued for retransmission, false otherwise.
*/
typedef bool fhss_data_tx_fail(const fhss_api_t *api, uint8_t handle, int frame_type);
typedef bool fhss_data_tx_fail(const fhss_api_t *api, uint8_t handle, int frame_type, uint8_t channel);

/**
* @brief Change synchronization state.
Expand Down
46 changes: 46 additions & 0 deletions features/nanostack/sal-stack-nanostack/nanostack/fhss_test_api.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2020, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed 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.
*/

/**
* \file fhss_test_api.h
* \brief
*/

#ifndef FHSS_TEST_API_H
#define FHSS_TEST_API_H


#ifdef __cplusplus
extern "C" {
#endif

/**
* \brief Set optimal packet length
*
* \param fhss_api FHSS instance.
* \param packet_length Optimal packet length
*
* \return 0 Success
* \return -1 Failure
*/
int8_t fhss_set_optimal_packet_length(const fhss_api_t *fhss_api, uint16_t packet_length);

#ifdef __cplusplus
}
#endif

#endif // FHSS_TEST_API_H
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ typedef enum {
CHANNEL_PAGE_5 = 5, ///< Page 5
CHANNEL_PAGE_6 = 6, ///< Page 6
CHANNEL_PAGE_9 = 9, ///< Page 9
CHANNEL_PAGE_10 = 10 ///< Page 10
CHANNEL_PAGE_10 = 10, ///< Page 10
CHANNEL_PAGE_UNDEFINED ///< Undefined
} channel_page_e;

/** Modulation index */
Expand Down Expand Up @@ -192,6 +193,10 @@ typedef struct phy_rf_statistics_s {
uint32_t crc_fails; ///< CRC failures
uint32_t tx_timeouts; ///< transmission timeouts
uint32_t rx_timeouts; ///< reception timeouts
uint64_t tx_active_time; ///< transmission active time
uint64_t rx_active_time; ///< reception active time
uint32_t tx_bytes; ///< transmitted bytes
uint32_t rx_bytes; ///< received bytes
} phy_rf_statistics_s;

/** Virtual data request */
Expand Down
7 changes: 7 additions & 0 deletions features/nanostack/sal-stack-nanostack/nanostack/sw_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ extern int8_t ns_sw_mac_virtual_client_unregister(struct mac_api_s *api);
*/
extern int ns_sw_mac_fhss_register(struct mac_api_s *mac_api, struct fhss_api *fhss_api);

/**
* @brief Unregister FHSS API instance from given software MAC instance.
* @param mac_api MAC instance.
* @return 0 on success, -1 on fail.
*/
extern int ns_sw_mac_fhss_unregister(struct mac_api_s *mac_api);

/**
* @brief Request registered FHSS API instance from software MAC instance.
* @param mac_api MAC instance.
Expand Down
12 changes: 4 additions & 8 deletions features/nanostack/sal-stack-nanostack/nanostack/ws_bbr_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,10 @@ int ws_bbr_start(int8_t interface_id, int8_t backbone_interface_id);
/**
* Border router configuration options
*/
#define BBR_ULA_C 0x0001 /**< Static ULA prefix created automatically */
#define BBR_GUA_ROUTE 0x0002 /**< More specific route is added for GUA prefix */
#define BBR_BB_WAIT 0x0004 /**< Wait backbone availability before starting Wi-SUN network */

/*Deprecated configuration values */
#define BBR_GUA_C 0x0000 /**< Routable prefix is learned from the backbone */
#define BBR_GUA_SLAAC 0x0000 /**< Use SLAAC addressing in routable prefix */
#define BBR_GUA_WAIT 0x0000 /**< Wait backbone availability before startingRPL dodag */
#define BBR_ULA_C 0x0001 /**< Static ULA prefix created automatically */
#define BBR_GUA_ROUTE 0x0002 /**< More specific route is added for GUA prefix */
#define BBR_BB_WAIT 0x0004 /**< Wait backbone availability before starting Wi-SUN network */
#define BBR_DEFAULT_ROUTE 0x0008 /**< Add default route parameter to DIO */

/**
* Configure border router features.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1379,6 +1379,8 @@ static int8_t arm_6lowpan_bootstrap_down(protocol_interface_info_entry_t *cur)
}
cur->if_lowpan_security_params->mle_security_frame_counter = mle_service_security_get_frame_counter(cur->id);
mle_service_interface_receiver_handler_update(cur->id, mle_6lowpan_message_handler);
// Reset MAC for safe upper layer memory free
protocol_mac_reset(cur);
return nwk_6lowpan_down(cur);
}
#ifdef HAVE_6LOWPAN_ND
Expand Down Expand Up @@ -1593,7 +1595,7 @@ static void lowpan_neighbor_entry_remove_notify(mac_neighbor_table_entry_t *entr
{

protocol_interface_info_entry_t *cur_interface = user_data;
lowpan_adaptation_remove_free_indirect_table(cur_interface, entry_ptr);
lowpan_adaptation_neigh_remove_free_tx_tables(cur_interface, entry_ptr);
// Sleepy host
if (cur_interface->lowpan_info & INTERFACE_NWK_CONF_MAC_RX_OFF_IDLE) {
mac_data_poll_protocol_poll_mode_decrement(cur_interface);
Expand Down
Loading

0 comments on commit 978db96

Please sign in to comment.