Skip to content

Commit 1109e5d

Browse files
committed
testing: Add Serial Error Reporting testing app
This commit adds support to Serial Error Reporting using the ioctl TIOCGICOUNT. This examples was inspired on this sample code: https://stackoverflow.com/questions/78796301/c-serial-communication-why-does-read-lose-some-data-bytes-at-high-baud-rates/78800245#78800245 Signed-off-by: Alan C. Assis <[email protected]>
1 parent 5d7ff30 commit 1109e5d

File tree

5 files changed

+230
-0
lines changed

5 files changed

+230
-0
lines changed

testing/drivers/ser/CMakeLists.txt

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# ##############################################################################
2+
# apps/testing/drivers/ser/CMakeLists.txt
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
7+
# license agreements. See the NOTICE file distributed with this work for
8+
# additional information regarding copyright ownership. The ASF licenses this
9+
# file to you under the Apache License, Version 2.0 (the "License"); you may not
10+
# use this file except in compliance with the License. You may obtain a copy of
11+
# the License at
12+
#
13+
# http://www.apache.org/licenses/LICENSE-2.0
14+
#
15+
# Unless required by applicable law or agreed to in writing, software
16+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
# License for the specific language governing permissions and limitations under
19+
# the License.
20+
#
21+
# ##############################################################################
22+
23+
if(CONFIG_TESTING_SERIAL)
24+
nuttx_add_application(
25+
NAME
26+
${CONFIG_TESTING_SERIAL_PROGNAME}
27+
PRIORITY
28+
${CONFIG_TESTING_SERIAL_PRIORITY}
29+
STACKSIZE
30+
${CONFIG_TESTING_SERIAL_STACKSIZE}
31+
SRCS
32+
ser.c)
33+
endif()

testing/drivers/ser/Kconfig

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#
2+
# For a description of the syntax of this configuration file,
3+
# see the file kconfig-language.txt in the NuttX tools repository.
4+
#
5+
6+
config TESTING_SERIAL
7+
bool "Serial Error Report (ser)"
8+
default n
9+
depends on SERIAL_TIOCGICOUNT
10+
---help---
11+
Enable the serial error reporting test. This test
12+
could report U[S]ART erros like frame, overrun, parity, etc
13+
14+
if TESTING_SERIAL
15+
16+
config TESTING_SERIAL_PORT
17+
string "Serial Port to Use"
18+
default "/dev/ttyS1"
19+
---help---
20+
This is the name of serial port to use. Please avoid using
21+
the ttyS0 because it is used as console.
22+
23+
config TESTING_SERIAL_PROGNAME
24+
string "Program name"
25+
default "ser"
26+
---help---
27+
This is the name of the program that will be used when the NSH ELF
28+
program is installed.
29+
30+
config TESTING_SERIAL_PRIORITY
31+
int "ser utility task priority"
32+
default 100
33+
34+
config TESTING_SERIAL_STACKSIZE
35+
int "ser utility stack size"
36+
default DEFAULT_TASK_STACKSIZE
37+
38+
endif

testing/drivers/ser/Make.defs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
############################################################################
2+
# apps/testing/drivers/ser/Make.defs
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# Licensed to the Apache Software Foundation (ASF) under one or more
7+
# contributor license agreements. See the NOTICE file distributed with
8+
# this work for additional information regarding copyright ownership. The
9+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
10+
# "License"); you may not use this file except in compliance with the
11+
# License. You may obtain a copy of the License at
12+
#
13+
# http://www.apache.org/licenses/LICENSE-2.0
14+
#
15+
# Unless required by applicable law or agreed to in writing, software
16+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
# License for the specific language governing permissions and limitations
19+
# under the License.
20+
#
21+
############################################################################
22+
23+
ifneq ($(CONFIG_TESTING_SERIAL),)
24+
CONFIGURED_APPS += $(APPDIR)/testing/drivers/ser
25+
endif

testing/drivers/ser/Makefile

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
############################################################################
2+
# apps/testing/drivers/ser/Makefile
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# Licensed to the Apache Software Foundation (ASF) under one or more
7+
# contributor license agreements. See the NOTICE file distributed with
8+
# this work for additional information regarding copyright ownership. The
9+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
10+
# "License"); you may not use this file except in compliance with the
11+
# License. You may obtain a copy of the License at
12+
#
13+
# http://www.apache.org/licenses/LICENSE-2.0
14+
#
15+
# Unless required by applicable law or agreed to in writing, software
16+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
# License for the specific language governing permissions and limitations
19+
# under the License.
20+
#
21+
############################################################################
22+
23+
include $(APPDIR)/Make.defs
24+
25+
# ser built-in application info
26+
27+
PROGNAME = $(CONFIG_TESTING_SERIAL_PROGNAME)
28+
PRIORITY = $(CONFIG_TESTING_SERIAL_PRIORITY)
29+
STACKSIZE = $(CONFIG_TESTING_SERIAL_STACKSIZE)
30+
31+
# ser main source
32+
33+
MAINSRC = ser.c
34+
35+
include $(APPDIR)/Application.mk

testing/drivers/ser/ser.c

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/****************************************************************************
2+
* apps/testing/drivers/ser/ser.c
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed to the Apache Software Foundation (ASF) under one or more
7+
* contributor license agreements. See the NOTICE file distributed with
8+
* this work for additional information regarding copyright ownership. The
9+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
10+
* "License"); you may not use this file except in compliance with the
11+
* License. You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
* License for the specific language governing permissions and limitations
19+
* under the License.
20+
*
21+
****************************************************************************/
22+
23+
/****************************************************************************
24+
* Included Files
25+
****************************************************************************/
26+
27+
#include <fcntl.h>
28+
#include <libgen.h>
29+
#include <stdio.h>
30+
#include <stdlib.h>
31+
#include <string.h>
32+
#include <sys/ioctl.h>
33+
#include <nuttx/serial/serial.h>
34+
35+
/****************************************************************************
36+
* Public Functions
37+
****************************************************************************/
38+
39+
int main(int argc, FAR char *argv[])
40+
{
41+
struct serial_icounter_s rcount;
42+
struct serial_icounter_s scount;
43+
44+
int fd;
45+
int ret;
46+
47+
fd = open(CONFIG_TESTING_SERIAL_PORT, O_RDONLY);
48+
if (fd < 0)
49+
{
50+
ret = -ENODEV;
51+
goto out;
52+
}
53+
54+
ret = ioctl(fd, TIOCGICOUNT, &scount);
55+
if (ret < 0)
56+
{
57+
goto out_close;
58+
}
59+
60+
while (1)
61+
{
62+
ret = ioctl(fd, TIOCGICOUNT, &rcount);
63+
64+
if (rcount.frame > scount.frame)
65+
{
66+
printf("ERROR: framing %d\n", rcount.frame - scount.frame);
67+
}
68+
69+
if (rcount.overrun > scount.overrun)
70+
{
71+
printf("ERROR: overrun %d\n", rcount.overrun - scount.overrun);
72+
}
73+
74+
if (rcount.parity > scount.parity)
75+
{
76+
printf("ERROR: parity %d\n", rcount.parity - scount.parity);
77+
}
78+
79+
if (rcount.brk > scount.brk)
80+
{
81+
printf("ERROR: break %d\n", rcount.brk - scount.brk);
82+
}
83+
84+
if (rcount.buf_overrun > scount.buf_overrun)
85+
{
86+
printf("ERROR: buffer overrun %d\n",
87+
rcount.buf_overrun - scount.buf_overrun);
88+
}
89+
90+
scount = rcount;
91+
usleep(1000000);
92+
}
93+
94+
out_close:
95+
close(fd);
96+
out:
97+
98+
return ret;
99+
}

0 commit comments

Comments
 (0)