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

Nanostack release v12.8.0 #14169

Merged
merged 12 commits into from
Jan 20, 2021
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ extern "C" {

// RF_PAC
#define TXPWR 0x1F
#define TXPWR_7 (7 << 0)
#define TXPWR_11 (11 << 0)
#define TXPWR_0 (0 << 0)
#define TXPWR_31 (31 << 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,24 @@
#include <Timer.h>
#include "Timeout.h"
#include "SPI.h"
#include "platform/mbed_version.h"

#define TRACE_GROUP "AtRF"

#if (MBED_VERSION > MBED_ENCODE_VERSION(6, 0, 0))
/* Mbed OS 6.0 introduces support for chrono time management */
using namespace std::chrono_literals;
#define ATMEL_RF_TIME_65MS 65ms
#define ATMEL_RF_TIME_1US 1us
#define ATMEL_RF_ATTACH(timer_ref, signal_ref, timeout_ref) timer_ref.attach(signal_ref, timeout_ref)
#define ATMEL_RF_DRIVER_CHRONO_SUPPORTED
#else
#define ATMEL_RF_TIME_65MS 65000
#define ATMEL_RF_TIME_1US 1

#define ATMEL_RF_ATTACH(timer_ref, signal_ref, timeout_ref) timer_ref.attach_us(signal_ref, timeout_ref)
#endif

#define RF_MTU_15_4_2011 127
#define RF_MTU_15_4G_2012 2047

Expand Down Expand Up @@ -164,8 +179,6 @@ static const phy_device_channel_page_s phy_channel_pages[] = {
{ CHANNEL_PAGE_0, NULL}
};

using namespace std::chrono_literals;

using namespace mbed;
using namespace rtos;

Expand Down Expand Up @@ -198,7 +211,11 @@ static Se2435Pins *se2435_pa_pins = NULL;

static uint32_t rf_get_timestamp(void)
{
#ifdef ATMEL_RF_DRIVER_CHRONO_SUPPORTED
return (uint32_t)rf->tx_timer.elapsed_time().count();
#else
return (uint32_t)rf->tx_timer.read_us();
#endif
}

static void rf_lock(void)
Expand Down Expand Up @@ -487,7 +504,7 @@ static void rf_init_registers(rf_modules_e module)
// Set low frequency offset bit
rf_write_bbc_register_field(BBC_OFDMC, module, LFO, 0);
// Configure using bandwidth option
rf_configure_by_ofdm_bandwidth_option(4, 300000, module);
rf_configure_by_ofdm_bandwidth_option(phy_current_config.ofdm_option, phy_current_config.datarate, module);
// Set Gain control settings
rf_write_rf_register_field(RF_AGCC, module, AVGS, AVGS_8_SAMPLES);
rf_write_rf_register_field(RF_AGCC, module, AGCI, 0);
Expand All @@ -501,8 +518,8 @@ static void rf_init_registers(rf_modules_e module)
se2435_pa_pins->ANT_SEL = 0;
// Enable external front end with configuration 3
rf_write_rf_register_field(RF_PADFE, module, PADFE, RF_FEMODE3);
// Output power at 900MHz: 0 dBm with FSK/QPSK, less than -5 dBm with OFDM
rf_tx_power = TXPWR_11;
// Output power at 900MHz: -4 dBm with FSK/QPSK, less than -10 dBm with OFDM
rf_tx_power = TXPWR_7;
}
// Set TX output power
rf_write_rf_register_field(RF_PAC, module, TXPWR, rf_tx_power);
Expand Down Expand Up @@ -566,17 +583,21 @@ static int8_t rf_start_csma_ca(uint8_t *data_ptr, uint16_t data_length, uint8_t
mac_tx_handle = tx_handle;

if (tx_time) {
#ifdef ATMEL_RF_DRIVER_CHRONO_SUPPORTED
std::chrono::microseconds backoff_time(tx_time - rf_get_timestamp());
#else
uint32_t backoff_time = tx_time - rf_get_timestamp();
#endif
// Max. time to TX can be 65ms, otherwise time has passed already -> send immediately
if (backoff_time <= 65ms) {
rf->cca_timer.attach(rf_csma_ca_timer_signal, backoff_time);
if (backoff_time <= ATMEL_RF_TIME_65MS) {
ATMEL_RF_ATTACH(rf->cca_timer, rf_csma_ca_timer_signal, backoff_time);
TEST_CSMA_STARTED
rf_unlock();
return 0;
}
}
// Short timeout to start CCA immediately.
rf->cca_timer.attach(rf_csma_ca_timer_signal, 1us);
ATMEL_RF_ATTACH(rf->cca_timer, rf_csma_ca_timer_signal, ATMEL_RF_TIME_1US);
TEST_CSMA_STARTED
rf_unlock();
return 0;
Expand Down Expand Up @@ -609,12 +630,16 @@ static void rf_handle_cca_ed_done(void)
if (cca_prepare_status == PHY_RESTART_CSMA) {
device_driver.phy_tx_done_cb(rf_radio_driver_id, mac_tx_handle, PHY_LINK_CCA_OK, 0, 0);
if (tx_time) {
#ifdef ATMEL_RF_DRIVER_CHRONO_SUPPORTED
std::chrono::microseconds backoff_time(tx_time - rf_get_timestamp());
#else
uint32_t backoff_time = tx_time - rf_get_timestamp();
#endif
// Max. time to TX can be 65ms, otherwise time has passed already -> send immediately
if (backoff_time > 65ms) {
backoff_time = 1us;
if (backoff_time > ATMEL_RF_TIME_65MS) {
backoff_time = ATMEL_RF_TIME_1US;
}
rf->cca_timer.attach(rf_csma_ca_timer_signal, backoff_time);
ATMEL_RF_ATTACH(rf->cca_timer, rf_csma_ca_timer_signal, backoff_time);
TEST_CSMA_STARTED
}
return;
Expand Down Expand Up @@ -996,7 +1021,11 @@ static uint32_t rf_backup_timer_start(uint16_t bytes, uint32_t time_us)
time_us = (uint32_t)(8000000 / phy_current_config.datarate) * bytes + PACKET_PROCESSING_TIME;
}
// Using cal_timer as backup timer
#ifdef ATMEL_RF_DRIVER_CHRONO_SUPPORTED
rf->cal_timer.attach(rf_backup_timer_signal, std::chrono::microseconds(time_us));
#else
rf->cal_timer.attach_us(rf_backup_timer_signal, time_us);
#endif

return (rf_get_timestamp() + time_us);
}
Expand Down
1 change: 1 addition & 0 deletions connectivity/libraries/nanostack-libservice/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ source/libip6string/ip6tos.c \
source/libip6string/stoip6.c \
source/libList/ns_list.c \
source/nsdynmemLIB/nsdynmemLIB.c \
source/nsdynmemtracker/nsdynmem_tracker_lib.c \
source/nvmHelper/ns_nvm_helper.c \

LIB := libservice.a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ extern "C" {
typedef size_t ns_mem_block_size_t; //external interface unsigned heap block size type
typedef size_t ns_mem_heap_size_t; //total heap size type.

// Can be used to enable tracking of dynamic memory allocations
#include "nsdynmem_tracker.h"

/*!
* \enum heap_fail_t
* \brief Dynamically heap system failure call back event types.
Expand Down Expand Up @@ -64,7 +67,6 @@ typedef struct mem_stat_t {
uint32_t heap_alloc_fail_cnt; /**< Counter for Heap allocation fail. */
} mem_stat_t;


typedef struct ns_mem_book ns_mem_book_t;

/**
Expand Down Expand Up @@ -99,7 +101,9 @@ extern int ns_dyn_mem_region_add(void *region_ptr, ns_mem_heap_size_t region_siz
* \return 0, Free OK
* \return <0, Free Fail
*/
#if NSDYNMEM_TRACKER_ENABLED!=1
extern void ns_dyn_mem_free(void *heap_ptr);
#endif

/**
* \brief Allocate temporary data.
Expand All @@ -111,7 +115,9 @@ extern void ns_dyn_mem_free(void *heap_ptr);
* \return 0, Allocate Fail
* \return >0, Pointer to allocated data sector.
*/
#if NSDYNMEM_TRACKER_ENABLED!=1
extern void *ns_dyn_mem_temporary_alloc(ns_mem_block_size_t alloc_size);
#endif

/**
* \brief Allocate long period data.
Expand All @@ -123,7 +129,9 @@ extern void *ns_dyn_mem_temporary_alloc(ns_mem_block_size_t alloc_size);
* \return 0, Allocate Fail
* \return >0, Pointer to allocated data sector.
*/
#if NSDYNMEM_TRACKER_ENABLED!=1
extern void *ns_dyn_mem_alloc(ns_mem_block_size_t alloc_size);
#endif

/**
* \brief Get pointer to the current mem_stat_t set via ns_dyn_mem_init.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2020 ARM Limited. All rights reserved.
* 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 nsdynmem_tracker.h
* \brief Dynamical Memory Tracker definitions to override the default NS dynamic memory functionality
* Provides tracking and tracing of dynamic memory blocks
*/

#ifndef NSDYNMEM_TRACKER_H_
#define NSDYNMEM_TRACKER_H_
#ifdef __cplusplus
extern "C" {
#endif

#if NSDYNMEM_TRACKER_ENABLED==1

#define ns_dyn_mem_free(block) ns_dyn_mem_tracker_dyn_mem_free(block, __func__, __LINE__)
#define ns_dyn_mem_temporary_alloc(alloc_size) ns_dyn_mem_tracker_dyn_mem_temporary_alloc(alloc_size, __func__, __LINE__)
#define ns_dyn_mem_alloc(alloc_size) ns_dyn_mem_tracker_dyn_mem_alloc(alloc_size, __func__, __LINE__)

void *ns_dyn_mem_tracker_dyn_mem_alloc(ns_mem_heap_size_t alloc_size, const char *function, uint32_t line);
void *ns_dyn_mem_tracker_dyn_mem_temporary_alloc(ns_mem_heap_size_t alloc_size, const char *function, uint32_t line);
void ns_dyn_mem_tracker_dyn_mem_free(void *block, const char *function, uint32_t line);

#endif

#ifdef __cplusplus
}
#endif
#endif /* NSDYNMEM_TRACKER_H_ */


Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* Copyright (c) 2020 ARM Limited. All rights reserved.
* 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 nsdynmem_tracker_lib.h
* \brief Dynamical Memory Tracker library API
* Provides tracking and tracing of dynamic memory blocks
*/

#ifndef NSDYNMEM_TRACKER_LIB_H_
#define NSDYNMEM_TRACKER_LIB_H_
#ifdef __cplusplus
extern "C" {
#endif

#if NSDYNMEM_TRACKER_ENABLED==1

// Memory block structure with caller information
typedef struct ns_dyn_mem_tracker_lib_mem_blocks_s {
void *block; /**< Allocated memory block */
void *caller_addr; /**< Caller address */
uint32_t size; /**< Allocation size */
uint32_t total_size; /**< Total allocation size for all allocations */
uint32_t lifetime; /**< Memory block lifetime in steps (e.g. seconds) */
uint32_t ref_count; /**< Reference count */
const char *function; /**< Caller function */
uint16_t line; /**< Caller line in module */
bool permanent : 1; /**< Permanent memory block */
bool permanent_printed : 1; /**< Permanent memory block printed */
} ns_dyn_mem_tracker_lib_mem_blocks_t;

// Extended memory block structure that is used if same caller allocates multiple memory blocks
typedef struct ns_dyn_mem_tracker_lib_mem_blocks_ext_s {
void *block; /**< Allocated memory block */
void *caller_addr; /**< Caller address */
uint32_t size; /**< Allocation size */
} ns_dyn_mem_tracker_lib_mem_blocks_ext_t;

// Allocator information structure
typedef struct ns_dyn_mem_tracker_lib_allocators_s {
void *caller_addr; /**< Caller address */
uint32_t alloc_count; /**< Number of allocations */
uint32_t total_memory; /**< Total memory used by allocations */
uint32_t min_lifetime; /**< Shortest lifetime among the allocations */
const char *function; /**< Function name string */
uint16_t line; /**< Module line */
} ns_dyn_mem_tracker_lib_allocators_t;

// Memory block array allocator / array size increase allocator
typedef ns_dyn_mem_tracker_lib_mem_blocks_t *ns_dyn_mem_tracker_lib_alloc_mem_blocks(ns_dyn_mem_tracker_lib_mem_blocks_t *blocks, uint16_t *mem_blocks_count);
// Extended memory block array allocator / array size increase allocator
typedef ns_dyn_mem_tracker_lib_mem_blocks_ext_t *ns_dyn_mem_tracker_lib_alloc_mem_blocks_ext(ns_dyn_mem_tracker_lib_mem_blocks_ext_t *blocks, uint32_t *mem_blocks_count);
// Extended memory block array index hash function to get memory block (allocation/search start) index from block address
typedef uint32_t ns_dyn_mem_tracker_lib_mem_block_index_hash(void *block, uint32_t ext_mem_blocks_count);

typedef struct ns_dyn_mem_tracker_lib_conf_s {
ns_dyn_mem_tracker_lib_mem_blocks_t *mem_blocks; /**< Memory blocks array, if NULL calls allocator on init */
ns_dyn_mem_tracker_lib_mem_blocks_ext_t *ext_mem_blocks; /**< Extended memory blocks array, if NULL calls allocator on init */
ns_dyn_mem_tracker_lib_allocators_t *top_allocators; /**< Top allocators array */
ns_dyn_mem_tracker_lib_allocators_t *permanent_allocators; /**< Permanent allocators */
ns_dyn_mem_tracker_lib_allocators_t *to_permanent_allocators; /**< To permanent allocators */
ns_dyn_mem_tracker_lib_allocators_t *max_snap_shot_allocators; /**< Snap shot of maximum memory used by allocators */
ns_dyn_mem_tracker_lib_alloc_mem_blocks *alloc_mem_blocks; /**< Memory block array allocator / array size increase allocator */
ns_dyn_mem_tracker_lib_alloc_mem_blocks_ext *ext_alloc_mem_blocks; /**< Extended memory block array allocator / array size increase allocator */
ns_dyn_mem_tracker_lib_mem_block_index_hash *block_index_hash; /**< Hash function to get memory block index from block address */
uint32_t allocated_memory; /**< Currently allocated memory */
uint16_t mem_blocks_count; /**< Number of entries in memory blocks array */
uint32_t ext_mem_blocks_count; /**< Number of entries in extended memory blocks array */
uint16_t last_mem_block_index; /**< Last memory block in memory blocks array */
uint16_t top_allocators_count; /**< Top allocators array count */
uint16_t permanent_allocators_count; /**< Permanent allocators array count */
uint16_t to_permanent_allocators_count; /**< To permanent allocators array count */
uint16_t max_snap_shot_allocators_count; /**< Snap shot of maximum memory used by allocators array count */
uint16_t to_permanent_steps_count; /**< How many steps before moving block to permanent allocators list */
} ns_dyn_mem_tracker_lib_conf_t;

int8_t ns_dyn_mem_tracker_lib_alloc(ns_dyn_mem_tracker_lib_conf_t *conf, void *caller_addr, const char *function, uint32_t line, void *block, uint32_t alloc_size);
int8_t ns_dyn_mem_tracker_lib_free(ns_dyn_mem_tracker_lib_conf_t *conf, void *caller_addr, const char *function, uint32_t line, void *block);
void ns_dyn_mem_tracker_lib_step(ns_dyn_mem_tracker_lib_conf_t *conf);
int8_t ns_dyn_mem_tracker_lib_allocator_lists_update(ns_dyn_mem_tracker_lib_conf_t *conf);
void ns_dyn_mem_tracker_lib_max_snap_shot_update(ns_dyn_mem_tracker_lib_conf_t *conf);

#endif

#ifdef __cplusplus
}
#endif
#endif /* NSDYNMEM_TRACKER_LIB_H_ */


7 changes: 6 additions & 1 deletion connectivity/libraries/nanostack-libservice/mbed_lib.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
{
"name": "nanostack-libservice",
"macros": ["NSDYNMEM_TRACKER_ENABLED=MBED_CONF_NANOSTACK_LIBSERVICE_NSDYNMEM_TRACKER_ENABLED"],
"config": {
"present": 1
"present": 1,
"nsdynmem-tracker-enabled": {
"help": "Use to enable dynamic memory tracker",
"value": 0
}
}
}