Skip to content

Commit 90e0f26

Browse files
committed
testing: Add Serial Error Reporting testing app
This commit adds support to Serial Error Reporting using the ioctl TIOCGICOUNT. Signed-off-by: Alan C. Assis <[email protected]>
1 parent 5d7ff30 commit 90e0f26

File tree

5 files changed

+239
-0
lines changed

5 files changed

+239
-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

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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_PROGNAME
17+
string "Program name"
18+
default "ser"
19+
---help---
20+
This is the name of the program that will be used when the NSH ELF
21+
program is installed.
22+
23+
config TESTING_SERIAL_PRIORITY
24+
int "ser utility task priority"
25+
default 100
26+
27+
config TESTING_SERIAL_STACKSIZE
28+
int "ser utility stack size"
29+
default DEFAULT_TASK_STACKSIZE
30+
31+
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

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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+
* Pre-processor Definitions
37+
****************************************************************************/
38+
39+
/****************************************************************************
40+
* Private Types
41+
****************************************************************************/
42+
43+
/****************************************************************************
44+
* Private Data
45+
****************************************************************************/
46+
47+
/****************************************************************************
48+
* Private Functions
49+
****************************************************************************/
50+
51+
/****************************************************************************
52+
* Public Functions
53+
****************************************************************************/
54+
55+
int main(int argc, FAR char *argv[])
56+
{
57+
struct serial_icounter_s rcount;
58+
struct serial_icounter_s scount;
59+
60+
int fd;
61+
int ret;
62+
63+
fd = open("/dev/ttyS1", O_RDONLY);
64+
if (fd < 0)
65+
{
66+
ret = -ENODEV;
67+
goto out;
68+
}
69+
70+
ret = ioctl(fd, TIOCGICOUNT, &scount);
71+
if (ret < 0)
72+
{
73+
goto out_close;
74+
}
75+
76+
while (1)
77+
{
78+
ret = ioctl(fd, TIOCGICOUNT, &rcount);
79+
80+
if (rcount.frame > scount.frame)
81+
{
82+
printf("ERROR: framing %d\n", rcount.frame - scount.frame);
83+
}
84+
85+
if (rcount.overrun > scount.overrun)
86+
{
87+
printf("ERROR: overrun %d\n", rcount.overrun - scount.overrun);
88+
}
89+
90+
if (rcount.parity > scount.parity)
91+
{
92+
printf("ERROR: parity %d\n", rcount.parity - scount.parity);
93+
}
94+
95+
if (rcount.brk > scount.brk)
96+
{
97+
printf("ERROR: break %d\n", rcount.brk - scount.brk);
98+
}
99+
100+
if (rcount.buf_overrun > scount.buf_overrun)
101+
{
102+
printf("ERROR: buffer overrun %d\n",
103+
rcount.buf_overrun - scount.buf_overrun);
104+
}
105+
106+
scount = rcount;
107+
usleep(1000000);
108+
}
109+
110+
out_close:
111+
close(fd);
112+
out:
113+
114+
return ret;
115+
}

0 commit comments

Comments
 (0)