Skip to content

Commit

Permalink
Merge pull request ARMmbed#9 from yennster/uart-new
Browse files Browse the repository at this point in the history
Added peripherals & updated Mbed OS
  • Loading branch information
Jenny Plunkett authored Jun 25, 2018
2 parents 674fabb + 420bec9 commit 4fa2b21
Show file tree
Hide file tree
Showing 639 changed files with 16,990 additions and 5,516 deletions.
6 changes: 1 addition & 5 deletions .astyleignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@ BUILD
cmsis
features/cryptocell
features/mbedtls
features/FEATURE_LWIP/lwip
features/lwipstack/lwip
rtos/TARGET_CORTEX/rtx4
features/filesystem/littlefs/littlefs
features/filesystem/fat/ChaN
features/frameworks
features/FEATURE_BLE/targets
features/FEATURE_LWIP/lwip-interface/lwip
features/unsupported/
features/FEATURE_COMMON_PAL/
FEATURE_NANOSTACK/coap-service
FEATURE_NANOSTACK/sal-stack-nanostack
rtos/TARGET_CORTEX/rtx5
targets
tools
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ before_install:
# Setup ppa to make sure arm-none-eabi-gcc is correct version
- sudo add-apt-repository -y ppa:team-gcc-arm-embedded/ppa
- sudo add-apt-repository -y ppa:deadsnakes/ppa
# Fix for "The following signatures were invalid: KEYEXPIRED 1515625755" failed". See https://github.com/travis-ci/travis-ci/issues/9037
- sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
# Loop until update succeeds (timeouts can occur)
- travis_retry $(! sudo apt-get update 2>&1 |grep Failed)

Expand Down Expand Up @@ -160,7 +162,7 @@ matrix:
- python tools/make.py -t GCC_ARM -m K64F --source=. --build=BUILD/K64F/GCC_ARM -j0
# Check that example compiles without rtos
- sed -n '/``` cpp/,/```/{/```$/Q;/```/d;p;}' $EVENTS/README.md > main.cpp
- rm -r rtos features/cellular features/netsocket features/nanostack features/frameworks/greentea-client features/frameworks/utest features/frameworks/unity BUILD
- rm -r rtos features/cellular features/netsocket features/nanostack features/lwipstack features/frameworks/greentea-client features/frameworks/utest features/frameworks/unity BUILD
- python tools/make.py -t GCC_ARM -m DISCO_F401VC --source=. --build=BUILD/DISCO_F401VC/GCC_ARM -j0
# Run local equeue tests
- make -C $EVENTS/equeue test
Expand Down
20 changes: 18 additions & 2 deletions TESTS/mbed_hal/sleep/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@

#define US_PER_S 1000000

/* Flush serial buffer before deep sleep
*
* Since deepsleep() may shut down the UART peripheral, we wait for some time
* to allow for hardware serial buffers to completely flush.
*
* Take NUMAKER_PFM_NUC472 as an example:
* Its UART peripheral has 16-byte Tx FIFO. With baud rate set to 9600, flush
* Tx FIFO would take: 16 * 8 * 1000 / 9600 = 13.3 (ms). So set wait time to
* 20ms here for safe.
*
* This should be replaced with a better function that checks if the
* hardware buffers are empty. However, such an API does not exist now,
* so we'll use the wait_ms() function for now.
*/
#define SERIAL_FLUSH_TIME_MS 20

using namespace utest::v1;

/* The following ticker frequencies are possible:
Expand Down Expand Up @@ -167,7 +183,7 @@ void deepsleep_lpticker_test()
/* Give some time Green Tea to finish UART transmission before entering
* deep-sleep mode.
*/
wait_ms(10);
wait_ms(SERIAL_FLUSH_TIME_MS);

TEST_ASSERT_TRUE_MESSAGE(sleep_manager_can_deep_sleep(), "deep sleep should not be locked");

Expand Down Expand Up @@ -202,7 +218,7 @@ void deepsleep_high_speed_clocks_turned_off_test()
/* Give some time Green Tea to finish UART transmission before entering
* deep-sleep mode.
*/
wait_ms(10);
wait_ms(SERIAL_FLUSH_TIME_MS);

TEST_ASSERT_TRUE_MESSAGE(sleep_manager_can_deep_sleep(), "deep sleep should not be locked");

Expand Down
10 changes: 5 additions & 5 deletions TESTS/mbed_platform/error_handling/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ void test_error_context_capture()
TEST_ASSERT_EQUAL_UINT((uint32_t)current_thread->thread_addr, error_ctx.thread_entry_address);
TEST_ASSERT_EQUAL_UINT((uint32_t)current_thread->stack_size, error_ctx.thread_stack_size);
TEST_ASSERT_EQUAL_UINT((uint32_t)current_thread->stack_mem, error_ctx.thread_stack_mem);
#ifdef MBED_CONF_ERROR_FILENAME_CAPTURE_ENABLED
#if MBED_CONF_PLATFORM_ERROR_FILENAME_CAPTURE_ENABLED
TEST_ASSERT_EQUAL_STRING(MBED_FILENAME, error_ctx.error_filename);
#endif
}

#ifndef MBED_CONF_ERROR_HIST_DISABLED
#if MBED_CONF_PLATFORM_ERROR_HIST_ENABLED
/** Test error logging functionality
*/
void test_error_logging()
Expand Down Expand Up @@ -261,7 +261,7 @@ void test_error_hook()
TEST_ASSERT(sem_status > 0);
}

#ifdef MBED_TEST_SIM_BLOCKDEVICE
#if MBED_CONF_PLATFORM_ERROR_HIST_ENABLED && defined(MBED_TEST_SIM_BLOCKDEVICE)

// test configuration
#ifndef MBED_TEST_FILESYSTEM
Expand Down Expand Up @@ -351,12 +351,12 @@ Case cases[] = {
Case("Test error context capture", test_error_context_capture),
#endif //MBED_CONF_RTOS_PRESENT
Case("Test error hook", test_error_hook),
#ifndef MBED_CONF_ERROR_HIST_DISABLED
#if MBED_CONF_PLATFORM_ERROR_HIST_ENABLED
Case("Test error logging", test_error_logging),
#if MBED_CONF_RTOS_PRESENT
Case("Test error handling multi-threaded", test_error_logging_multithread),
#endif //MBED_CONF_RTOS_PRESENT
#ifdef MBED_TEST_SIM_BLOCKDEVICE
#if MBED_CONF_PLATFORM_ERROR_HIST_ENABLED && defined(MBED_TEST_SIM_BLOCKDEVICE)
Case("Test error save log", test_save_error_log),
#endif //MBED_TEST_SIM_BLOCKDEVICE
#endif //MBED_CONF_ERROR_HIST_DISABLED
Expand Down
41 changes: 41 additions & 0 deletions TESTS/netsocket/dns/asynchronous_dns.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2018, 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.
*/

#include "mbed.h"
#include "greentea-client/test_env.h"
#include "unity.h"
#include "utest.h"
#include "dns_tests.h"

using namespace utest::v1;

namespace {
int result_ok;
int result_no_mem;
int result_dns_failure;
int result_exp_timeout;
}

void ASYNCHRONOUS_DNS()
{
do_asynchronous_gethostbyname(dns_test_hosts, 1, &result_ok, &result_no_mem, &result_dns_failure, &result_exp_timeout);

TEST_ASSERT(result_ok == 1);
TEST_ASSERT(result_no_mem == 0);
TEST_ASSERT(result_dns_failure == 0);
TEST_ASSERT(result_exp_timeout == 0);
}
65 changes: 65 additions & 0 deletions TESTS/netsocket/dns/asynchronous_dns_cache.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright (c) 2018, 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.
*/

#include "mbed.h"
#include "greentea-client/test_env.h"
#include "unity.h"
#include "utest.h"
#include "dns_tests.h"

using namespace utest::v1;

namespace {
int ticker_us = 0;
}

static void test_dns_query_ticker(void)
{
ticker_us += 100;
}

void ASYNCHRONOUS_DNS_CACHE()
{
rtos::Semaphore semaphore;
dns_application_data data;
data.semaphore = &semaphore;

Ticker ticker;
ticker.attach_us(&test_dns_query_ticker, 100);

for (unsigned int i = 0; i < 5; i++) {
int started_us = ticker_us;

nsapi_error_t err = get_interface()->gethostbyname_async(dns_test_hosts[0],
mbed::Callback<void(nsapi_error_t, SocketAddress *)>(hostbyname_cb, (void *) &data));
TEST_ASSERT(err >= 0);

semaphore.wait();

TEST_ASSERT(data.result == NSAPI_ERROR_OK);
TEST_ASSERT(strlen(data.addr.get_ip_address()) > 1);

int delay_ms = (ticker_us - started_us) / 1000;

static int delay_first = delay_ms / 2;
// Check that cached accesses are at least twice as fast as the first one
TEST_ASSERT_FALSE(i != 0 && delay_ms > delay_first);

printf("DNS: query \"%s\" => \"%s\", time %i ms\n",
dns_test_hosts[0], data.addr.get_ip_address(), delay_ms);
}
}
84 changes: 84 additions & 0 deletions TESTS/netsocket/dns/asynchronous_dns_cancel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright (c) 2018, 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.
*/

#include "mbed.h"
#include "greentea-client/test_env.h"
#include "unity.h"
#include "utest.h"
#include "dns_tests.h"

using namespace utest::v1;

void ASYNCHRONOUS_DNS_CANCEL()
{
rtos::Semaphore semaphore;
dns_application_data *data = new dns_application_data[MBED_CONF_APP_DNS_TEST_HOSTS_NUM];

int count = 0;

for (unsigned int i = 0; i < MBED_CONF_APP_DNS_TEST_HOSTS_NUM; i++) {
data[i].value_set = false;
data[i].semaphore = &semaphore;
data[i].req_result = get_interface()->gethostbyname_async(dns_test_hosts[i],
mbed::Callback<void(nsapi_error_t, SocketAddress *)>(hostbyname_cb, (void *) &data[i]));
TEST_ASSERT(data[i].req_result >= 0 || data[i].req_result == NSAPI_ERROR_NO_MEMORY);

if (data[i].req_result >= 0) {
// Callback will be called
count++;
} else {
// No memory to initiate DNS query, callback will not be called
data[i].result = NSAPI_ERROR_NO_MEMORY;
data[i].value_set = true;
}
}

for (unsigned int i = 0; i < MBED_CONF_APP_DNS_TEST_HOSTS_NUM; i++) {
if (data[i].req_result > 0) {
if (get_interface()->gethostbyname_async_cancel(data[i].req_result) == NSAPI_ERROR_OK) {
count--;
}
}
}

// Wait for callback(s) to complete
for (int i = 0; i < count; i++) {
semaphore.wait();
}

for (unsigned int i = 0; i < MBED_CONF_APP_DNS_TEST_HOSTS_NUM; i++) {
if (!data[i].value_set) {
printf("DNS: query \"%s\" => cancel\n", dns_test_hosts[i]);
continue;
}
TEST_ASSERT(data[i].result == NSAPI_ERROR_OK || data[i].result == NSAPI_ERROR_NO_MEMORY || data[i].result == NSAPI_ERROR_DNS_FAILURE || data[i].result == NSAPI_ERROR_TIMEOUT);
if (data[i].result == NSAPI_ERROR_OK) {
printf("DNS: query \"%s\" => \"%s\"\n",
dns_test_hosts[i], data[i].addr.get_ip_address());
} else if (data[i].result == NSAPI_ERROR_DNS_FAILURE) {
printf("DNS: query \"%s\" => DNS failure\n", dns_test_hosts[i]);
} else if (data[i].result == NSAPI_ERROR_TIMEOUT) {
printf("DNS: query \"%s\" => timeout\n", dns_test_hosts[i]);
} else if (data[i].result == NSAPI_ERROR_NO_MEMORY) {
printf("DNS: query \"%s\" => no memory\n", dns_test_hosts[i]);
}
}

delete[] data;

wait(5.0);
}
85 changes: 85 additions & 0 deletions TESTS/netsocket/dns/asynchronous_dns_external_event_queue.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Copyright (c) 2018, 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.
*/

#include "mbed.h"
#include "greentea-client/test_env.h"
#include "unity.h"
#include "utest.h"
#include "dns_tests.h"

#include "nsapi_dns.h"

using namespace utest::v1;

namespace {
int result_ok;
int result_no_mem;
int result_dns_failure;
int result_exp_timeout;

const int EXTERNAL_THREAD_SIZE = 2048;
const int EVENT_QUEUE_SIZE = 10;

events::EventQueue *event_queue;
}

static nsapi_error_t event_queue_call(int delay, mbed::Callback<void()> func)
{
if (delay) {
if (event_queue->call_in(delay, func) == 0) {
return NSAPI_ERROR_NO_MEMORY;
}
} else {
if (event_queue->call(func) == 0) {
return NSAPI_ERROR_NO_MEMORY;
}
}
return NSAPI_ERROR_OK;
}

void ASYNCHRONOUS_DNS_EXTERNAL_EVENT_QUEUE()
{
// Ensures that cache does not contain entries
do_asynchronous_gethostbyname(dns_test_hosts, MBED_CONF_NSAPI_DNS_CACHE_SIZE, &result_ok, &result_no_mem,
&result_dns_failure, &result_exp_timeout);

TEST_ASSERT(result_ok == MBED_CONF_NSAPI_DNS_CACHE_SIZE);
TEST_ASSERT(result_no_mem == 0);
TEST_ASSERT(result_dns_failure == 0);
TEST_ASSERT(result_exp_timeout == 0);

// Dispatch event queue
Thread eventThread(osPriorityNormal, EXTERNAL_THREAD_SIZE);
EventQueue queue(EVENT_QUEUE_SIZE * EVENTS_EVENT_SIZE);
eventThread.start(callback(&queue, &EventQueue::dispatch_forever));
event_queue = &queue;

nsapi_dns_call_in_set(event_queue_call);

do_asynchronous_gethostbyname(dns_test_hosts_second, MBED_CONF_APP_DNS_SIMULT_QUERIES + 1, &result_ok, &result_no_mem,
&result_dns_failure, &result_exp_timeout);

TEST_ASSERT(result_ok == MBED_CONF_APP_DNS_SIMULT_QUERIES);
TEST_ASSERT(result_no_mem == 1); // last query fails for no memory as expected
TEST_ASSERT(result_dns_failure == 0);
TEST_ASSERT(result_exp_timeout == 0);

// Give event queue time to finalise before destructors
wait(2.0);

nsapi_dns_call_in_set(0);
}
Loading

0 comments on commit 4fa2b21

Please sign in to comment.