Skip to content

Commit dc40c47

Browse files
authored
Merge pull request #14169 from artokin/nanostack_release_12_8_0_to_master
Nanostack release v12.8.0
2 parents d2b6797 + 4d13419 commit dc40c47

File tree

79 files changed

+2793
-584
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+2793
-584
lines changed

connectivity/drivers/802.15.4_RF/atmel-rf-driver/source/AT86RF215Reg.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ extern "C" {
9696

9797
// RF_PAC
9898
#define TXPWR 0x1F
99+
#define TXPWR_7 (7 << 0)
99100
#define TXPWR_11 (11 << 0)
100101
#define TXPWR_0 (0 << 0)
101102
#define TXPWR_31 (31 << 0)

connectivity/drivers/802.15.4_RF/atmel-rf-driver/source/NanostackRfPhyAT86RF215.cpp

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,24 @@
3030
#include <Timer.h>
3131
#include "Timeout.h"
3232
#include "SPI.h"
33+
#include "platform/mbed_version.h"
3334

3435
#define TRACE_GROUP "AtRF"
3536

37+
#if (MBED_VERSION > MBED_ENCODE_VERSION(6, 0, 0))
38+
/* Mbed OS 6.0 introduces support for chrono time management */
39+
using namespace std::chrono_literals;
40+
#define ATMEL_RF_TIME_65MS 65ms
41+
#define ATMEL_RF_TIME_1US 1us
42+
#define ATMEL_RF_ATTACH(timer_ref, signal_ref, timeout_ref) timer_ref.attach(signal_ref, timeout_ref)
43+
#define ATMEL_RF_DRIVER_CHRONO_SUPPORTED
44+
#else
45+
#define ATMEL_RF_TIME_65MS 65000
46+
#define ATMEL_RF_TIME_1US 1
47+
48+
#define ATMEL_RF_ATTACH(timer_ref, signal_ref, timeout_ref) timer_ref.attach_us(signal_ref, timeout_ref)
49+
#endif
50+
3651
#define RF_MTU_15_4_2011 127
3752
#define RF_MTU_15_4G_2012 2047
3853

@@ -164,8 +179,6 @@ static const phy_device_channel_page_s phy_channel_pages[] = {
164179
{ CHANNEL_PAGE_0, NULL}
165180
};
166181

167-
using namespace std::chrono_literals;
168-
169182
using namespace mbed;
170183
using namespace rtos;
171184

@@ -198,7 +211,11 @@ static Se2435Pins *se2435_pa_pins = NULL;
198211

199212
static uint32_t rf_get_timestamp(void)
200213
{
214+
#ifdef ATMEL_RF_DRIVER_CHRONO_SUPPORTED
201215
return (uint32_t)rf->tx_timer.elapsed_time().count();
216+
#else
217+
return (uint32_t)rf->tx_timer.read_us();
218+
#endif
202219
}
203220

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

568585
if (tx_time) {
586+
#ifdef ATMEL_RF_DRIVER_CHRONO_SUPPORTED
569587
std::chrono::microseconds backoff_time(tx_time - rf_get_timestamp());
588+
#else
589+
uint32_t backoff_time = tx_time - rf_get_timestamp();
590+
#endif
570591
// Max. time to TX can be 65ms, otherwise time has passed already -> send immediately
571-
if (backoff_time <= 65ms) {
572-
rf->cca_timer.attach(rf_csma_ca_timer_signal, backoff_time);
592+
if (backoff_time <= ATMEL_RF_TIME_65MS) {
593+
ATMEL_RF_ATTACH(rf->cca_timer, rf_csma_ca_timer_signal, backoff_time);
573594
TEST_CSMA_STARTED
574595
rf_unlock();
575596
return 0;
576597
}
577598
}
578599
// Short timeout to start CCA immediately.
579-
rf->cca_timer.attach(rf_csma_ca_timer_signal, 1us);
600+
ATMEL_RF_ATTACH(rf->cca_timer, rf_csma_ca_timer_signal, ATMEL_RF_TIME_1US);
580601
TEST_CSMA_STARTED
581602
rf_unlock();
582603
return 0;
@@ -609,12 +630,16 @@ static void rf_handle_cca_ed_done(void)
609630
if (cca_prepare_status == PHY_RESTART_CSMA) {
610631
device_driver.phy_tx_done_cb(rf_radio_driver_id, mac_tx_handle, PHY_LINK_CCA_OK, 0, 0);
611632
if (tx_time) {
633+
#ifdef ATMEL_RF_DRIVER_CHRONO_SUPPORTED
612634
std::chrono::microseconds backoff_time(tx_time - rf_get_timestamp());
635+
#else
636+
uint32_t backoff_time = tx_time - rf_get_timestamp();
637+
#endif
613638
// Max. time to TX can be 65ms, otherwise time has passed already -> send immediately
614-
if (backoff_time > 65ms) {
615-
backoff_time = 1us;
639+
if (backoff_time > ATMEL_RF_TIME_65MS) {
640+
backoff_time = ATMEL_RF_TIME_1US;
616641
}
617-
rf->cca_timer.attach(rf_csma_ca_timer_signal, backoff_time);
642+
ATMEL_RF_ATTACH(rf->cca_timer, rf_csma_ca_timer_signal, backoff_time);
618643
TEST_CSMA_STARTED
619644
}
620645
return;
@@ -996,7 +1021,11 @@ static uint32_t rf_backup_timer_start(uint16_t bytes, uint32_t time_us)
9961021
time_us = (uint32_t)(8000000 / phy_current_config.datarate) * bytes + PACKET_PROCESSING_TIME;
9971022
}
9981023
// Using cal_timer as backup timer
1024+
#ifdef ATMEL_RF_DRIVER_CHRONO_SUPPORTED
9991025
rf->cal_timer.attach(rf_backup_timer_signal, std::chrono::microseconds(time_us));
1026+
#else
1027+
rf->cal_timer.attach_us(rf_backup_timer_signal, time_us);
1028+
#endif
10001029

10011030
return (rf_get_timestamp() + time_us);
10021031
}

connectivity/libraries/nanostack-libservice/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ target_sources(mbed-nanostack-libservice
1616
source/libip4string/stoip4.c
1717
source/libip6string/stoip6.c
1818
source/nsdynmemLIB/nsdynmemLIB.c
19+
source/nsdynmemtracker/nsdynmem_tracker_lib.c
1920
source/nvmHelper/ns_nvm_helper.c
2021
)
2122

connectivity/libraries/nanostack-libservice/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ source/libip6string/ip6tos.c \
55
source/libip6string/stoip6.c \
66
source/libList/ns_list.c \
77
source/nsdynmemLIB/nsdynmemLIB.c \
8+
source/nsdynmemtracker/nsdynmem_tracker_lib.c \
89
source/nvmHelper/ns_nvm_helper.c \
910

1011
LIB := libservice.a

connectivity/libraries/nanostack-libservice/mbed-client-libservice/nsdynmemLIB.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ extern "C" {
3737
typedef size_t ns_mem_block_size_t; //external interface unsigned heap block size type
3838
typedef size_t ns_mem_heap_size_t; //total heap size type.
3939

40+
// Can be used to enable tracking of dynamic memory allocations
41+
#include "nsdynmem_tracker.h"
42+
4043
/*!
4144
* \enum heap_fail_t
4245
* \brief Dynamically heap system failure call back event types.
@@ -64,7 +67,6 @@ typedef struct mem_stat_t {
6467
uint32_t heap_alloc_fail_cnt; /**< Counter for Heap allocation fail. */
6568
} mem_stat_t;
6669

67-
6870
typedef struct ns_mem_book ns_mem_book_t;
6971

7072
/**
@@ -99,7 +101,9 @@ extern int ns_dyn_mem_region_add(void *region_ptr, ns_mem_heap_size_t region_siz
99101
* \return 0, Free OK
100102
* \return <0, Free Fail
101103
*/
104+
#if NSDYNMEM_TRACKER_ENABLED!=1
102105
extern void ns_dyn_mem_free(void *heap_ptr);
106+
#endif
103107

104108
/**
105109
* \brief Allocate temporary data.
@@ -111,7 +115,9 @@ extern void ns_dyn_mem_free(void *heap_ptr);
111115
* \return 0, Allocate Fail
112116
* \return >0, Pointer to allocated data sector.
113117
*/
118+
#if NSDYNMEM_TRACKER_ENABLED!=1
114119
extern void *ns_dyn_mem_temporary_alloc(ns_mem_block_size_t alloc_size);
120+
#endif
115121

116122
/**
117123
* \brief Allocate long period data.
@@ -123,7 +129,9 @@ extern void *ns_dyn_mem_temporary_alloc(ns_mem_block_size_t alloc_size);
123129
* \return 0, Allocate Fail
124130
* \return >0, Pointer to allocated data sector.
125131
*/
132+
#if NSDYNMEM_TRACKER_ENABLED!=1
126133
extern void *ns_dyn_mem_alloc(ns_mem_block_size_t alloc_size);
134+
#endif
127135

128136
/**
129137
* \brief Get pointer to the current mem_stat_t set via ns_dyn_mem_init.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright (c) 2020 ARM Limited. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
* Licensed under the Apache License, Version 2.0 (the License); you may
5+
* not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
* \file nsdynmem_tracker.h
19+
* \brief Dynamical Memory Tracker definitions to override the default NS dynamic memory functionality
20+
* Provides tracking and tracing of dynamic memory blocks
21+
*/
22+
23+
#ifndef NSDYNMEM_TRACKER_H_
24+
#define NSDYNMEM_TRACKER_H_
25+
#ifdef __cplusplus
26+
extern "C" {
27+
#endif
28+
29+
#if NSDYNMEM_TRACKER_ENABLED==1
30+
31+
#define ns_dyn_mem_free(block) ns_dyn_mem_tracker_dyn_mem_free(block, __func__, __LINE__)
32+
#define ns_dyn_mem_temporary_alloc(alloc_size) ns_dyn_mem_tracker_dyn_mem_temporary_alloc(alloc_size, __func__, __LINE__)
33+
#define ns_dyn_mem_alloc(alloc_size) ns_dyn_mem_tracker_dyn_mem_alloc(alloc_size, __func__, __LINE__)
34+
35+
void *ns_dyn_mem_tracker_dyn_mem_alloc(ns_mem_heap_size_t alloc_size, const char *function, uint32_t line);
36+
void *ns_dyn_mem_tracker_dyn_mem_temporary_alloc(ns_mem_heap_size_t alloc_size, const char *function, uint32_t line);
37+
void ns_dyn_mem_tracker_dyn_mem_free(void *block, const char *function, uint32_t line);
38+
39+
#endif
40+
41+
#ifdef __cplusplus
42+
}
43+
#endif
44+
#endif /* NSDYNMEM_TRACKER_H_ */
45+
46+
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
* Copyright (c) 2020 ARM Limited. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
* Licensed under the Apache License, Version 2.0 (the License); you may
5+
* not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
18+
/**
19+
* \file nsdynmem_tracker_lib.h
20+
* \brief Dynamical Memory Tracker library API
21+
* Provides tracking and tracing of dynamic memory blocks
22+
*/
23+
24+
#ifndef NSDYNMEM_TRACKER_LIB_H_
25+
#define NSDYNMEM_TRACKER_LIB_H_
26+
#ifdef __cplusplus
27+
extern "C" {
28+
#endif
29+
30+
#if NSDYNMEM_TRACKER_ENABLED==1
31+
32+
// Memory block structure with caller information
33+
typedef struct ns_dyn_mem_tracker_lib_mem_blocks_s {
34+
void *block; /**< Allocated memory block */
35+
void *caller_addr; /**< Caller address */
36+
uint32_t size; /**< Allocation size */
37+
uint32_t total_size; /**< Total allocation size for all allocations */
38+
uint32_t lifetime; /**< Memory block lifetime in steps (e.g. seconds) */
39+
uint32_t ref_count; /**< Reference count */
40+
const char *function; /**< Caller function */
41+
uint16_t line; /**< Caller line in module */
42+
bool permanent : 1; /**< Permanent memory block */
43+
bool permanent_printed : 1; /**< Permanent memory block printed */
44+
} ns_dyn_mem_tracker_lib_mem_blocks_t;
45+
46+
// Extended memory block structure that is used if same caller allocates multiple memory blocks
47+
typedef struct ns_dyn_mem_tracker_lib_mem_blocks_ext_s {
48+
void *block; /**< Allocated memory block */
49+
void *caller_addr; /**< Caller address */
50+
uint32_t size; /**< Allocation size */
51+
} ns_dyn_mem_tracker_lib_mem_blocks_ext_t;
52+
53+
// Allocator information structure
54+
typedef struct ns_dyn_mem_tracker_lib_allocators_s {
55+
void *caller_addr; /**< Caller address */
56+
uint32_t alloc_count; /**< Number of allocations */
57+
uint32_t total_memory; /**< Total memory used by allocations */
58+
uint32_t min_lifetime; /**< Shortest lifetime among the allocations */
59+
const char *function; /**< Function name string */
60+
uint16_t line; /**< Module line */
61+
} ns_dyn_mem_tracker_lib_allocators_t;
62+
63+
// Memory block array allocator / array size increase allocator
64+
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);
65+
// Extended memory block array allocator / array size increase allocator
66+
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);
67+
// Extended memory block array index hash function to get memory block (allocation/search start) index from block address
68+
typedef uint32_t ns_dyn_mem_tracker_lib_mem_block_index_hash(void *block, uint32_t ext_mem_blocks_count);
69+
70+
typedef struct ns_dyn_mem_tracker_lib_conf_s {
71+
ns_dyn_mem_tracker_lib_mem_blocks_t *mem_blocks; /**< Memory blocks array, if NULL calls allocator on init */
72+
ns_dyn_mem_tracker_lib_mem_blocks_ext_t *ext_mem_blocks; /**< Extended memory blocks array, if NULL calls allocator on init */
73+
ns_dyn_mem_tracker_lib_allocators_t *top_allocators; /**< Top allocators array */
74+
ns_dyn_mem_tracker_lib_allocators_t *permanent_allocators; /**< Permanent allocators */
75+
ns_dyn_mem_tracker_lib_allocators_t *to_permanent_allocators; /**< To permanent allocators */
76+
ns_dyn_mem_tracker_lib_allocators_t *max_snap_shot_allocators; /**< Snap shot of maximum memory used by allocators */
77+
ns_dyn_mem_tracker_lib_alloc_mem_blocks *alloc_mem_blocks; /**< Memory block array allocator / array size increase allocator */
78+
ns_dyn_mem_tracker_lib_alloc_mem_blocks_ext *ext_alloc_mem_blocks; /**< Extended memory block array allocator / array size increase allocator */
79+
ns_dyn_mem_tracker_lib_mem_block_index_hash *block_index_hash; /**< Hash function to get memory block index from block address */
80+
uint32_t allocated_memory; /**< Currently allocated memory */
81+
uint16_t mem_blocks_count; /**< Number of entries in memory blocks array */
82+
uint32_t ext_mem_blocks_count; /**< Number of entries in extended memory blocks array */
83+
uint16_t last_mem_block_index; /**< Last memory block in memory blocks array */
84+
uint16_t top_allocators_count; /**< Top allocators array count */
85+
uint16_t permanent_allocators_count; /**< Permanent allocators array count */
86+
uint16_t to_permanent_allocators_count; /**< To permanent allocators array count */
87+
uint16_t max_snap_shot_allocators_count; /**< Snap shot of maximum memory used by allocators array count */
88+
uint16_t to_permanent_steps_count; /**< How many steps before moving block to permanent allocators list */
89+
} ns_dyn_mem_tracker_lib_conf_t;
90+
91+
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);
92+
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);
93+
void ns_dyn_mem_tracker_lib_step(ns_dyn_mem_tracker_lib_conf_t *conf);
94+
int8_t ns_dyn_mem_tracker_lib_allocator_lists_update(ns_dyn_mem_tracker_lib_conf_t *conf);
95+
void ns_dyn_mem_tracker_lib_max_snap_shot_update(ns_dyn_mem_tracker_lib_conf_t *conf);
96+
97+
#endif
98+
99+
#ifdef __cplusplus
100+
}
101+
#endif
102+
#endif /* NSDYNMEM_TRACKER_LIB_H_ */
103+
104+
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
{
22
"name": "nanostack-libservice",
3+
"macros": ["NSDYNMEM_TRACKER_ENABLED=MBED_CONF_NANOSTACK_LIBSERVICE_NSDYNMEM_TRACKER_ENABLED"],
34
"config": {
4-
"present": 1
5+
"present": 1,
6+
"nsdynmem-tracker-enabled": {
7+
"help": "Use to enable dynamic memory tracker",
8+
"value": 0
9+
}
510
}
611
}

0 commit comments

Comments
 (0)