Skip to content

Commit bdab10d

Browse files
authored
Merge pull request #2590 from ARMmbed/release
Release mbed-os-5.1.3 and mbed lib v125
2 parents d220204 + 5e38a9c commit bdab10d

File tree

270 files changed

+30063
-2409
lines changed

Some content is hidden

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

270 files changed

+30063
-2409
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ mbed OS accelerates the process of creating a connected product by providing a p
88

99
Our current release series is mbed OS 5.1:
1010

11-
- [Release Note](https://docs.mbed.com/docs/mbed-os-release-notes/en/latest/5_1/release)
11+
- [Release Note](https://docs.mbed.com/docs/mbed-os-release-notes/en/latest/5_1/release/)
1212

1313
## Getting Started for Developers
1414

@@ -20,4 +20,4 @@ We have a getting started guide for developers using mbed OS in applications:
2020

2121
We have a getting started guide for contributors working on mbed OS:
2222

23-
- Have a look in the docs directory
23+
- Have a look in the docs directory
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2016 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may 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,
12+
* WITHOUT 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+
#if !DEVICE_LOWPOWERTIMER
18+
#error [NOT_SUPPORTED] Low power timer not supported for this target
19+
#endif
20+
21+
#include "utest/utest.h"
22+
#include "unity/unity.h"
23+
#include "greentea-client/test_env.h"
24+
25+
#include "mbed.h"
26+
#include "us_ticker_api.h"
27+
28+
using namespace utest::v1;
29+
30+
volatile static bool complete;
31+
static LowPowerTimeout lpt;
32+
33+
/* Timeouts are quite arbitrary due to large number of boards with varying level of accuracy */
34+
#define LONG_TIMEOUT (100000)
35+
#define SHORT_TIMEOUT (600)
36+
37+
void cb_done() {
38+
complete = true;
39+
}
40+
41+
#if DEVICE_SLEEP
42+
void lp_timeout_1s_deepsleep(void)
43+
{
44+
complete = false;
45+
46+
timestamp_t start = us_ticker_read();
47+
lpt.attach(&cb_done, 1);
48+
deepsleep();
49+
while (!complete);
50+
timestamp_t end = us_ticker_read();
51+
52+
/* It takes longer to wake up from deep sleep */
53+
TEST_ASSERT_UINT32_WITHIN(LONG_TIMEOUT, 1000000, end - start);
54+
TEST_ASSERT_TRUE(complete);
55+
}
56+
57+
void lp_timeout_1s_sleep(void)
58+
{
59+
complete = false;
60+
61+
timestamp_t start = us_ticker_read();
62+
lpt.attach(&cb_done, 1);
63+
sleep();
64+
while (!complete);
65+
timestamp_t end = us_ticker_read();
66+
67+
TEST_ASSERT_UINT32_WITHIN(LONG_TIMEOUT, 1000000, end - start);
68+
TEST_ASSERT_TRUE(complete);
69+
}
70+
#endif /* DEVICE_SLEEP */
71+
72+
void lp_timeout_us(uint32_t delay_us, uint32_t tolerance)
73+
{
74+
complete = false;
75+
76+
timestamp_t start = us_ticker_read();
77+
lpt.attach_us(&cb_done, delay_us);
78+
while (!complete);
79+
timestamp_t end = us_ticker_read();
80+
81+
/* Using RTC which is less accurate */
82+
TEST_ASSERT_UINT32_WITHIN(tolerance, delay_us, end - start);
83+
TEST_ASSERT_TRUE(complete);
84+
}
85+
86+
void lp_timeout_5s(void)
87+
{
88+
lp_timeout_us(5000000, LONG_TIMEOUT);
89+
}
90+
91+
void lp_timeout_1s(void)
92+
{
93+
lp_timeout_us(1000000, LONG_TIMEOUT);
94+
}
95+
96+
void lp_timeout_1ms(void)
97+
{
98+
lp_timeout_us(1000, SHORT_TIMEOUT);
99+
}
100+
101+
void lp_timeout_500us(void)
102+
{
103+
lp_timeout_us(500, SHORT_TIMEOUT);
104+
105+
}
106+
107+
status_t greentea_failure_handler(const Case *const source, const failure_t reason) {
108+
greentea_case_failure_abort_handler(source, reason);
109+
return STATUS_CONTINUE;
110+
}
111+
112+
Case cases[] = {
113+
Case("500us LowPowerTimeout", lp_timeout_500us, greentea_failure_handler),
114+
Case("1ms LowPowerTimeout", lp_timeout_1ms, greentea_failure_handler),
115+
Case("1sec LowPowerTimeout", lp_timeout_1s, greentea_failure_handler),
116+
Case("5sec LowPowerTimeout", lp_timeout_5s, greentea_failure_handler),
117+
#if DEVICE_SLEEP
118+
Case("1sec LowPowerTimeout from sleep", lp_timeout_1s_sleep, greentea_failure_handler),
119+
Case("1sec LowPowerTimeout from deepsleep", lp_timeout_1s_deepsleep, greentea_failure_handler),
120+
#endif /* DEVICE_SLEEP */
121+
};
122+
123+
status_t greentea_test_setup(const size_t number_of_cases) {
124+
GREENTEA_SETUP(20, "default_auto");
125+
return greentea_test_setup_handler(number_of_cases);
126+
}
127+
128+
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
129+
130+
int main() {
131+
Harness::run(specification);
132+
}

TESTS/mbed_hal/lp_ticker/main.cpp

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2016 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may 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,
12+
* WITHOUT 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+
#if !DEVICE_LOWPOWERTIMER
18+
#error [NOT_SUPPORTED] Low power timer not supported for this target
19+
#endif
20+
21+
#include "utest/utest.h"
22+
#include "unity/unity.h"
23+
#include "greentea-client/test_env.h"
24+
25+
#include "mbed.h"
26+
#include "us_ticker_api.h"
27+
#include "lp_ticker_api.h"
28+
29+
using namespace utest::v1;
30+
31+
volatile static bool complete;
32+
static ticker_event_t delay_event;
33+
static const ticker_data_t *lp_ticker_data = get_lp_ticker_data();
34+
35+
36+
/* Timeouts are quite arbitrary due to large number of boards with varying level of accuracy */
37+
#define LONG_TIMEOUT (100000)
38+
#define SHORT_TIMEOUT (600)
39+
40+
void cb_done(uint32_t id) {
41+
complete = true;
42+
}
43+
44+
void lp_ticker_delay_us(uint32_t delay_us, uint32_t tolerance)
45+
{
46+
complete = false;
47+
uint32_t delay_ts;
48+
49+
ticker_set_handler(lp_ticker_data, cb_done);
50+
ticker_remove_event(lp_ticker_data, &delay_event);
51+
delay_ts = lp_ticker_read() + delay_us;
52+
53+
timestamp_t start = us_ticker_read();
54+
ticker_insert_event(lp_ticker_data, &delay_event, delay_ts, (uint32_t)&delay_event);
55+
while (!complete);
56+
timestamp_t end = us_ticker_read();
57+
58+
TEST_ASSERT_UINT32_WITHIN(tolerance, delay_us, end - start);
59+
TEST_ASSERT_TRUE(complete);
60+
}
61+
62+
#if DEVICE_SLEEP
63+
void lp_ticker_1s_deepsleep()
64+
{
65+
complete = false;
66+
uint32_t delay_ts;
67+
68+
ticker_set_handler(lp_ticker_data, cb_done);
69+
ticker_remove_event(lp_ticker_data, &delay_event);
70+
delay_ts = lp_ticker_read() + 1000000;
71+
72+
timestamp_t start = us_ticker_read();
73+
ticker_insert_event(lp_ticker_data, &delay_event, delay_ts, (uint32_t)&delay_event);
74+
deepsleep();
75+
while (!complete);
76+
timestamp_t end = us_ticker_read();
77+
78+
TEST_ASSERT_UINT32_WITHIN(LONG_TIMEOUT, 1000000, end - start);
79+
TEST_ASSERT_TRUE(complete);
80+
}
81+
82+
void lp_ticker_1s_sleep()
83+
{
84+
complete = false;
85+
uint32_t delay_ts;
86+
87+
ticker_set_handler(lp_ticker_data, cb_done);
88+
ticker_remove_event(lp_ticker_data, &delay_event);
89+
delay_ts = lp_ticker_read() + 1000000;
90+
91+
timestamp_t start = us_ticker_read();
92+
ticker_insert_event(lp_ticker_data, &delay_event, delay_ts, (uint32_t)&delay_event);
93+
sleep();
94+
while (!complete);
95+
timestamp_t end = us_ticker_read();
96+
97+
TEST_ASSERT_UINT32_WITHIN(LONG_TIMEOUT, 1000000, end - start);
98+
TEST_ASSERT_TRUE(complete);
99+
}
100+
#endif /* DEVICE_SLEEP */
101+
102+
void lp_ticker_500us(void)
103+
{
104+
lp_ticker_delay_us(500, SHORT_TIMEOUT);
105+
}
106+
107+
void lp_ticker_1ms(void)
108+
{
109+
lp_ticker_delay_us(1000, SHORT_TIMEOUT);
110+
}
111+
112+
void lp_ticker_1s(void)
113+
{
114+
lp_ticker_delay_us(1000000, LONG_TIMEOUT);
115+
}
116+
117+
void lp_ticker_5s(void)
118+
{
119+
lp_ticker_delay_us(5000000, LONG_TIMEOUT);
120+
}
121+
122+
status_t greentea_failure_handler(const Case *const source, const failure_t reason) {
123+
greentea_case_failure_abort_handler(source, reason);
124+
return STATUS_CONTINUE;
125+
}
126+
127+
Case cases[] = {
128+
Case("500us lp_ticker", lp_ticker_500us, greentea_failure_handler),
129+
Case("1ms lp_ticker", lp_ticker_1ms, greentea_failure_handler),
130+
Case("1s lp_ticker", lp_ticker_1s, greentea_failure_handler),
131+
Case("5s lp_ticker", lp_ticker_5s, greentea_failure_handler),
132+
#if DEVICE_SLEEP
133+
Case("1s lp_ticker sleep", lp_ticker_1s_sleep, greentea_failure_handler),
134+
Case("1s lp_ticker deepsleep", lp_ticker_1s_deepsleep, greentea_failure_handler),
135+
#endif /* DEVICE_SLEEP */
136+
};
137+
138+
status_t greentea_test_setup(const size_t number_of_cases) {
139+
GREENTEA_SETUP(20, "default_auto");
140+
lp_ticker_data->interface->init();
141+
return greentea_test_setup_handler(number_of_cases);
142+
}
143+
144+
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
145+
146+
int main() {
147+
Harness::run(specification);
148+
}

features/FEATURE_CLIENT/mbed-client-classic/source/m2mconnectionhandlerpimpl.cpp

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,16 @@
3131

3232
#define TRACE_GROUP "mClt"
3333

34+
#ifdef MBED_CONF_MBED_CLIENT_EVENT_LOOP_SIZE
35+
#define MBED_CLIENT_EVENT_LOOP_SIZE MBED_CONF_MBED_CLIENT_EVENT_LOOP_SIZE
36+
#else
37+
#define MBED_CLIENT_EVENT_LOOP_SIZE 1024
38+
#endif
39+
3440
int8_t M2MConnectionHandlerPimpl::_tasklet_id = -1;
3541

42+
static MemoryPool<M2MConnectionHandlerPimpl::TaskIdentifier, MBED_CLIENT_EVENT_LOOP_SIZE/64> memory_pool;
43+
3644
extern "C" void connection_tasklet_event_handler(arm_event_s *event)
3745
{
3846
tr_debug("M2MConnectionHandlerPimpl::connection_tasklet_event_handler");
@@ -74,7 +82,7 @@ extern "C" void connection_tasklet_event_handler(arm_event_s *event)
7482
break;
7583
}
7684
if (task_id) {
77-
free(task_id);
85+
memory_pool.free(task_id);
7886
}
7987
}
8088

@@ -103,7 +111,7 @@ M2MConnectionHandlerPimpl::M2MConnectionHandlerPimpl(M2MConnectionHandler* base,
103111
_address._address = _address_buffer;
104112

105113
if (_network_stack != M2MInterface::LwIP_IPv4) {
106-
error("ConnectionHandler: Unsupported network stack, only IPv4 is currently supported");
114+
tr_error("ConnectionHandler: Unsupported network stack, only IPv4 is currently supported");
107115
}
108116
_running = true;
109117
tr_debug("M2MConnectionHandlerPimpl::M2MConnectionHandlerPimpl() - Initializing thread");
@@ -117,6 +125,10 @@ M2MConnectionHandlerPimpl::M2MConnectionHandlerPimpl(M2MConnectionHandler* base,
117125
M2MConnectionHandlerPimpl::~M2MConnectionHandlerPimpl()
118126
{
119127
tr_debug("M2MConnectionHandlerPimpl::~M2MConnectionHandlerPimpl()");
128+
if(_socket_address) {
129+
delete _socket_address;
130+
_socket_address = NULL;
131+
}
120132
if (_socket) {
121133
delete _socket;
122134
_socket = 0;
@@ -145,7 +157,7 @@ bool M2MConnectionHandlerPimpl::resolve_server_address(const String& server_addr
145157
_server_port = server_port;
146158
_server_type = server_type;
147159
_server_address = server_address;
148-
TaskIdentifier* task = (TaskIdentifier*)malloc(sizeof(TaskIdentifier));
160+
TaskIdentifier* task = memory_pool.alloc();
149161
if (!task) {
150162
return false;
151163
}
@@ -163,6 +175,10 @@ bool M2MConnectionHandlerPimpl::resolve_server_address(const String& server_addr
163175
void M2MConnectionHandlerPimpl::dns_handler()
164176
{
165177
tr_debug("M2MConnectionHandlerPimpl::dns_handler()");
178+
if(_socket_address) {
179+
delete _socket_address;
180+
_socket_address = NULL;
181+
}
166182
_socket_address = new SocketAddress(_net_iface,_server_address.c_str(), _server_port);
167183
if(*_socket_address) {
168184
_address._address = (void*)_socket_address->get_ip_address();
@@ -248,7 +264,7 @@ bool M2MConnectionHandlerPimpl::send_data(uint8_t *data,
248264
return false;
249265
}
250266

251-
TaskIdentifier* task = (TaskIdentifier*)malloc(sizeof(TaskIdentifier));
267+
TaskIdentifier* task = memory_pool.alloc();
252268
if (!task) {
253269
free(buffer);
254270
return false;
@@ -310,9 +326,7 @@ int8_t M2MConnectionHandlerPimpl::connection_tasklet_handler()
310326

311327
void M2MConnectionHandlerPimpl::socket_event()
312328
{
313-
tr_debug("M2MConnectionHandlerPimpl::socket_event()");
314-
315-
TaskIdentifier* task = (TaskIdentifier*)malloc(sizeof(TaskIdentifier));
329+
TaskIdentifier* task = memory_pool.alloc();
316330
if (!task) {
317331
_observer.socket_error(M2MConnectionHandler::SOCKET_READ_ERROR, true);
318332
return;

0 commit comments

Comments
 (0)