Skip to content

Commit d0b2fb6

Browse files
author
Bogdan Marinescu
committed
Added flow control test
Since this requires a separate serial port connection, added this as a new attribute of the MUTs.
1 parent 2ac6c4c commit d0b2fb6

File tree

5 files changed

+108
-6
lines changed

5 files changed

+108
-6
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include "mbed.h"
2+
3+
#if defined(TARGET_LPC1768)
4+
#define UART_TX p9
5+
#define UART_RX p10
6+
#define FLOW_CONTROL_RTS p11
7+
#define FLOW_CONTROL_CTS p12
8+
#define RTS_CHECK_PIN p13
9+
#else
10+
#error This test is not supported on this target
11+
#endif
12+
13+
Serial pc(UART_TX, UART_RX);
14+
15+
#ifdef RTS_CHECK_PIN
16+
InterruptIn in(RTS_CHECK_PIN);
17+
DigitalOut led(LED1);
18+
static void checker(void) {
19+
led = !led;
20+
}
21+
#endif
22+
23+
int main() {
24+
char buf[256];
25+
26+
pc.set_flow_control(Serial::RTSCTS, FLOW_CONTROL_RTS, FLOW_CONTROL_CTS);
27+
#ifdef RTS_CHECK_PIN
28+
in.fall(checker);
29+
#endif
30+
while (1) {
31+
pc.gets(buf, 256);
32+
pc.printf("%s", buf);
33+
}
34+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"""
2+
mbed SDK
3+
Copyright (c) 2011-2013 ARM Limited
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+
from host_test import Test
18+
19+
20+
class EchoTest(Test):
21+
def __init__(self):
22+
Test.__init__(self)
23+
self.mbed.init_serial()
24+
self.mbed.extra_serial.rtscts = True
25+
self.mbed.reset()
26+
27+
def test(self):
28+
self.mbed.flush()
29+
self.notify("Starting the ECHO test")
30+
TEST="longer serial test"
31+
check = True
32+
for i in range(1, 100):
33+
self.mbed.extra_serial.write(TEST + "\n")
34+
l = self.mbed.extra_serial.readline().strip()
35+
if not l: continue
36+
37+
if l != TEST:
38+
check = False
39+
self.notify('"%s" != "%s"' % (l, TEST))
40+
else:
41+
if (i % 10) == 0:
42+
self.notify('.')
43+
44+
return check
45+
46+
47+
if __name__ == '__main__':
48+
EchoTest().run()

workspace_tools/host_tests/host_test.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ def __init__(self):
3838

3939
parser.add_option("-t", "--timeout", dest="timeout",
4040
help="Timeout", metavar="TIMEOUT")
41+
42+
parser.add_option("-e", "--extra", dest="extra",
43+
help="Extra serial port (used by some tests)", metavar="EXTRA")
4144

4245
(self.options, _) = parser.parse_args()
4346

@@ -46,14 +49,19 @@ def __init__(self):
4649

4750
self.port = self.options.port
4851
self.disk = self.options.disk
52+
self.extra_port = self.options.extra
53+
self.extra_serial = None
4954
self.serial = None
5055
self.timeout = 10 if self.options.timeout is None else self.options.timeout
5156

5257
print 'Mbed: "%s" "%s"' % (self.port, self.disk)
5358

54-
def init_serial(self, baud=9600):
59+
def init_serial(self, baud=9600, extra_baud=9600):
5560
self.serial = Serial(self.port, timeout = 1)
5661
self.serial.setBaudrate(baud)
62+
if self.extra_port:
63+
self.extra_serial = Serial(self.extra_port, timeout = 1)
64+
self.extra_serial.setBaudrate(extra_baud)
5765
self.flush()
5866

5967
def reset(self):
@@ -64,7 +72,9 @@ def reset(self):
6472
def flush(self):
6573
self.serial.flushInput()
6674
self.serial.flushOutput()
67-
75+
if self.extra_serial:
76+
self.extra_serial.flushInput()
77+
self.extra_serial.flushOutput()
6878

6979
class Test:
7080
def __init__(self):

workspace_tools/server.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ def stop(self):
5757
pass
5858

5959

60-
def run_host_test(client, name, disk, port, duration):
60+
def run_host_test(client, name, disk, port, duration, extra_serial):
6161
print "{%s}" % name,
62-
cmd = ["python", "%s.py" % name, '-p', port, '-d', disk, '-t', str(duration)]
62+
cmd = ["python", "%s.py" % name, '-p', port, '-d', disk, '-t', str(duration), "-e", extra_serial]
6363
proc = Popen(cmd, stdout=PIPE, cwd=HOST_TESTS)
6464
obs = ProcessObserver(proc)
6565
start = time()
@@ -144,6 +144,7 @@ def handle(self):
144144

145145
disk = mut['disk']
146146
port = mut['port']
147+
extra_serial = mut.get('extra_serial', "")
147148
target = TARGET_MAP[mut['mcu']]
148149

149150
# Program
@@ -169,7 +170,7 @@ def handle(self):
169170

170171
# Host test
171172
self.request.setblocking(0)
172-
result = run_host_test(self.request, test.host_test, disk, port, duration)
173+
result = run_host_test(self.request, test.host_test, disk, port, duration, extra_serial)
173174
self.send_result(result)
174175

175176

workspace_tools/tests.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,15 @@
203203
"dependencies": [MBED_LIBRARIES, TEST_MBED_LIB],
204204
"automated": True,
205205
},
206+
{
207+
"id": "MBED_A22", "description": "Serial echo with RTS/CTS flow control",
208+
"source_dir": join(TEST_DIR, "mbed", "echo_flow_control"),
209+
"dependencies": [MBED_LIBRARIES],
210+
"automated": "True",
211+
"host_test": "echo_flow_control",
212+
"mcu": ["LPC1768"],
213+
"peripherals": ["extra_serial"]
214+
},
206215

207216
# Size benchmarks
208217
{
@@ -392,7 +401,7 @@
392401
"dependencies": [MBED_LIBRARIES],
393402
"mcu": ["LPC1768", "LPC4088"]
394403
},
395-
404+
396405
# CMSIS RTOS tests
397406
{
398407
"id": "CMSIS_RTOS_1", "description": "Basic",

0 commit comments

Comments
 (0)