Skip to content

Commit 5d900e1

Browse files
author
Jenny Plunkett
authored
Merge pull request ARMmbed#5 from yennster/cc3220sf-uart
Added initial stubs for Serial/UART API
2 parents 554b36e + 6ba96d7 commit 5d900e1

File tree

82 files changed

+2610
-475
lines changed

Some content is hidden

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

82 files changed

+2610
-475
lines changed

TESTS/mbed_drivers/timeout/timeout_tests.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,14 +305,19 @@ void test_deepsleep(void)
305305
LowPowerTimer timer;
306306

307307
/*
308-
* Since deepsleep() may shut down the UART peripheral, we wait for 10ms
308+
* Since deepsleep() may shut down the UART peripheral, we wait for 20ms
309309
* to allow for hardware serial buffers to completely flush.
310+
*
311+
* Take NUMAKER_PFM_NUC472 as an example:
312+
* Its UART peripheral has 16-byte Tx FIFO. With baud rate set to 9600, flush
313+
* Tx FIFO would take: 16 * 8 * 1000 / 9600 = 13.3 (ms). So set wait time to
314+
* 20ms here for safe.
310315
311316
* This should be replaced with a better function that checks if the
312317
* hardware buffers are empty. However, such an API does not exist now,
313318
* so we'll use the wait_ms() function for now.
314319
*/
315-
wait_ms(10);
320+
wait_ms(20);
316321

317322
timer.start();
318323
timeout.attach_callback(mbed::callback(sem_callback, &sem), delay_us);
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/*
2+
* Copyright (c) 2018, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
19+
#if !defined(MBED_CONF_NSAPI_PRESENT)
20+
#error [NOT_SUPPORTED] A json configuration file is needed. Skipping this build.
21+
#endif
22+
23+
#include "CellularUtil.h" // for CELLULAR_ helper macros
24+
#include "CellularTargets.h"
25+
26+
#ifndef CELLULAR_DEVICE
27+
#error [NOT_SUPPORTED] CELLULAR_DEVICE must be defined
28+
#endif
29+
30+
#ifndef MBED_CONF_APP_CELLULAR_SIM_PIN
31+
#error [NOT_SUPPORTED] SIM pin code is needed. Skipping this build.
32+
#endif
33+
34+
#include "greentea-client/test_env.h"
35+
#include "unity.h"
36+
#include "utest.h"
37+
38+
#include "mbed.h"
39+
40+
#include "CellularDevice.h"
41+
#include "../../cellular_tests_common.h"
42+
#include CELLULAR_STRINGIFY(CELLULAR_DEVICE.h)
43+
44+
#define NETWORK_TIMEOUT (180*1000)
45+
46+
static UARTSerial cellular_serial(MDMTXD, MDMRXD, MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE);
47+
static CELLULAR_DEVICE* cellular_device;
48+
static EventQueue queue(2 * EVENTS_EVENT_SIZE);
49+
50+
static void urc_callback()
51+
{
52+
}
53+
54+
static void wait_for_power(CellularPower* pwr)
55+
{
56+
nsapi_error_t err = pwr->set_device_ready_urc_cb(&urc_callback);
57+
MBED_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED);
58+
59+
int sanity_count = 0;
60+
while (pwr->is_device_ready() != NSAPI_ERROR_OK) {
61+
sanity_count++;
62+
wait(1);
63+
MBED_ASSERT(sanity_count < 20);
64+
}
65+
66+
err = pwr->set_at_mode();
67+
MBED_ASSERT(err == NSAPI_ERROR_OK);
68+
69+
pwr->remove_device_ready_urc_cb(&urc_callback);
70+
}
71+
72+
static void test_power_interface()
73+
{
74+
cellular_device = new CELLULAR_DEVICE(queue);
75+
CellularPower* pwr = cellular_device->open_power(&cellular_serial);
76+
77+
nsapi_error_t err = pwr->on();
78+
MBED_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED);
79+
wait_for_power(pwr);
80+
81+
MBED_ASSERT(pwr->set_power_level(1,0) == NSAPI_ERROR_OK);
82+
83+
err = pwr->reset();
84+
MBED_ASSERT(err == NSAPI_ERROR_OK);
85+
wait_for_power(pwr);
86+
87+
err = pwr->off();
88+
MBED_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED);
89+
}
90+
91+
using namespace utest::v1;
92+
93+
static utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason)
94+
{
95+
greentea_case_failure_abort_handler(source, reason);
96+
return STATUS_ABORT;
97+
}
98+
99+
static Case cases[] = {
100+
Case("CellularPower test interface", test_power_interface, greentea_failure_handler)
101+
};
102+
103+
static utest::v1::status_t test_setup(const size_t number_of_cases)
104+
{
105+
GREENTEA_SETUP(10*60, "default_auto");
106+
return verbose_test_setup_handler(number_of_cases);
107+
}
108+
109+
static Specification specification(test_setup, cases);
110+
111+
int main()
112+
{
113+
#if MBED_CONF_MBED_TRACE_ENABLE
114+
trace_open();
115+
#endif
116+
int ret = Harness::run(specification);
117+
#if MBED_CONF_MBED_TRACE_ENABLE
118+
trace_close();
119+
#endif
120+
return ret;
121+
}
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
/*
2+
* Copyright (c) 2018, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
19+
#if !defined(MBED_CONF_NSAPI_PRESENT)
20+
#error [NOT_SUPPORTED] A json configuration file is needed. Skipping this build.
21+
#endif
22+
23+
#include "CellularUtil.h" // for CELLULAR_ helper macros
24+
#include "CellularTargets.h"
25+
26+
#ifndef CELLULAR_DEVICE
27+
#error [NOT_SUPPORTED] CELLULAR_DEVICE must be defined
28+
#endif
29+
30+
#ifndef MBED_CONF_APP_CELLULAR_SIM_PIN
31+
#error [NOT_SUPPORTED] SIM pin code is needed. Skipping this build.
32+
#endif
33+
34+
#include "greentea-client/test_env.h"
35+
#include "unity.h"
36+
#include "utest.h"
37+
38+
#include "mbed.h"
39+
40+
#include "CellularConnectionFSM.h"
41+
#include "CellularDevice.h"
42+
#include "../../cellular_tests_common.h"
43+
#include CELLULAR_STRINGIFY(CELLULAR_DEVICE.h)
44+
45+
#define NETWORK_TIMEOUT (180*1000)
46+
47+
static UARTSerial cellular_serial(MDMTXD, MDMRXD, MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE);
48+
static EventQueue queue(8 * EVENTS_EVENT_SIZE);
49+
static rtos::Semaphore network_semaphore(0);
50+
static CellularConnectionFSM cellular;
51+
static CellularConnectionFSM::CellularState cellular_target_state;
52+
53+
static char *get_rand_string(char *str, size_t size)
54+
{
55+
const char charset[] = "0123456789";
56+
if (size) {
57+
--size;
58+
for (size_t n = 0; n < size; n++) {
59+
int key = rand() % (int) (sizeof charset - 1);
60+
str[n] = charset[key];
61+
}
62+
str[size] = '\0';
63+
}
64+
return str;
65+
}
66+
67+
static bool fsm_callback(int state, int next_state)
68+
{
69+
if (next_state == CellularConnectionFSM::STATE_SIM_PIN) {
70+
MBED_ASSERT(network_semaphore.release() == osOK);
71+
return false;
72+
}
73+
return true;
74+
}
75+
76+
static void init_to_sim_state()
77+
{
78+
cellular.set_serial(&cellular_serial);
79+
TEST_ASSERT(cellular.init() == NSAPI_ERROR_OK);
80+
#if defined (MDMRTS) && defined (MDMCTS)
81+
cellular_serial.set_flow_control(SerialBase::RTSCTS, MDMRTS, MDMCTS);
82+
#endif
83+
cellular.set_callback(&fsm_callback);
84+
TEST_ASSERT(cellular.start_dispatch() == NSAPI_ERROR_OK);
85+
cellular_target_state = CellularConnectionFSM::STATE_SIM_PIN;
86+
TEST_ASSERT(cellular.continue_to_state(cellular_target_state) == NSAPI_ERROR_OK);
87+
TEST_ASSERT(network_semaphore.wait(NETWORK_TIMEOUT) == 1);
88+
}
89+
90+
static void test_sim_interface()
91+
{
92+
CellularSIM *sim = cellular.get_sim();
93+
TEST_ASSERT(sim != NULL);
94+
95+
// 1. test set_pin
96+
nsapi_error_t err = sim->set_pin(MBED_CONF_APP_CELLULAR_SIM_PIN);
97+
MBED_ASSERT(err == NSAPI_ERROR_OK);
98+
99+
// 2. test change pin
100+
char pin[5];
101+
int sanity_count = 0;
102+
while (strcmp(get_rand_string(pin, 5), MBED_CONF_APP_CELLULAR_SIM_PIN) == 0) {
103+
sanity_count++;
104+
TEST_ASSERT(sanity_count < 50);
105+
};
106+
107+
// change pin and change it back
108+
err = sim->change_pin(MBED_CONF_APP_CELLULAR_SIM_PIN, pin);
109+
MBED_ASSERT(err == NSAPI_ERROR_OK);
110+
err = sim->change_pin(pin, MBED_CONF_APP_CELLULAR_SIM_PIN);
111+
MBED_ASSERT(err == NSAPI_ERROR_OK);
112+
113+
// 3. test set_pin_query
114+
err = sim->set_pin_query(MBED_CONF_APP_CELLULAR_SIM_PIN, false);
115+
MBED_ASSERT(err == NSAPI_ERROR_OK);
116+
err = sim->set_pin_query(MBED_CONF_APP_CELLULAR_SIM_PIN, true);
117+
MBED_ASSERT(err == NSAPI_ERROR_OK);
118+
119+
// 4. test get_sim_state
120+
CellularSIM::SimState state;
121+
err = sim->get_sim_state(state);
122+
MBED_ASSERT(err == NSAPI_ERROR_OK);
123+
MBED_ASSERT(state == CellularSIM::SimStateReady);
124+
125+
// 5. test get_imsi
126+
char imsi[16] = {0};
127+
err = sim->get_imsi(imsi);
128+
MBED_ASSERT(err == NSAPI_ERROR_OK);
129+
MBED_ASSERT(strlen(imsi) > 0);
130+
}
131+
132+
using namespace utest::v1;
133+
134+
static utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason)
135+
{
136+
greentea_case_failure_abort_handler(source, reason);
137+
return STATUS_ABORT;
138+
}
139+
140+
static Case cases[] = {
141+
Case("CellularSIM init", init_to_sim_state, greentea_failure_handler),
142+
Case("CellularSIM test interface", test_sim_interface, greentea_failure_handler)
143+
};
144+
145+
static utest::v1::status_t test_setup(const size_t number_of_cases)
146+
{
147+
GREENTEA_SETUP(10*60, "default_auto");
148+
return verbose_test_setup_handler(number_of_cases);
149+
}
150+
151+
static Specification specification(test_setup, cases);
152+
153+
int main()
154+
{
155+
#if MBED_CONF_MBED_TRACE_ENABLE
156+
trace_open();
157+
#endif
158+
int ret = Harness::run(specification);
159+
#if MBED_CONF_MBED_TRACE_ENABLE
160+
trace_close();
161+
#endif
162+
return ret;
163+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright (c) 2018, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
#ifndef CELLULAR_TESTS_COMMON_H_
18+
#define CELLULAR_TESTS_COMMON_H_
19+
20+
#include "CellularLog.h"
21+
22+
#if MBED_CONF_MBED_TRACE_ENABLE
23+
24+
static rtos::Mutex trace_mutex;
25+
26+
void trace_wait()
27+
{
28+
trace_mutex.lock();
29+
}
30+
31+
void trace_release()
32+
{
33+
trace_mutex.unlock();
34+
}
35+
36+
static char time_st[sizeof("[12345678]") + 1];
37+
38+
static char *trace_time(size_t ss)
39+
{
40+
snprintf(time_st, sizeof("[12345678]"), "[%08llu]", rtos::Kernel::get_ms_count());
41+
return time_st;
42+
}
43+
44+
static void trace_open()
45+
{
46+
mbed_trace_init();
47+
mbed_trace_prefix_function_set(&trace_time);
48+
mbed_trace_mutex_wait_function_set(trace_wait);
49+
mbed_trace_mutex_release_function_set(trace_release);
50+
51+
mbed_cellular_trace::mutex_wait_function_set(trace_wait);
52+
mbed_cellular_trace::mutex_release_function_set(trace_release);
53+
}
54+
55+
static void trace_close()
56+
{
57+
mbed_cellular_trace::mutex_wait_function_set(NULL);
58+
mbed_cellular_trace::mutex_release_function_set(NULL);
59+
60+
mbed_trace_free();
61+
}
62+
63+
#endif // MBED_CONF_MBED_TRACE_ENABLE
64+
65+
66+
#endif /* CELLULAR_TESTS_COMMON_H_ */

0 commit comments

Comments
 (0)