diff --git a/testing/drivers/ser/CMakeLists.txt b/testing/drivers/ser/CMakeLists.txt new file mode 100644 index 000000000..1e17c7a3e --- /dev/null +++ b/testing/drivers/ser/CMakeLists.txt @@ -0,0 +1,33 @@ +# ############################################################################## +# apps/testing/drivers/ser/CMakeLists.txt +# +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed to the Apache Software Foundation (ASF) under one or more contributor +# license agreements. See the NOTICE file distributed with this work for +# additional information regarding copyright ownership. The ASF licenses this +# file to you 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. +# +# ############################################################################## + +if(CONFIG_TESTING_SERIAL) + nuttx_add_application( + NAME + ${CONFIG_TESTING_SERIAL_PROGNAME} + PRIORITY + ${CONFIG_TESTING_SERIAL_PRIORITY} + STACKSIZE + ${CONFIG_TESTING_SERIAL_STACKSIZE} + SRCS + ser.c) +endif() diff --git a/testing/drivers/ser/Kconfig b/testing/drivers/ser/Kconfig new file mode 100644 index 000000000..484df2843 --- /dev/null +++ b/testing/drivers/ser/Kconfig @@ -0,0 +1,38 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +config TESTING_SERIAL + bool "Serial Error Report (ser)" + default n + depends on SERIAL_TIOCGICOUNT + ---help--- + Enable the serial error reporting test. This test + could report U[S]ART erros like frame, overrun, parity, etc + +if TESTING_SERIAL + +config TESTING_SERIAL_PORT + string "Serial Port to Use" + default "/dev/ttyS1" + ---help--- + This is the name of serial port to use. Please avoid using + the ttyS0 because it is used as console. + +config TESTING_SERIAL_PROGNAME + string "Program name" + default "ser" + ---help--- + This is the name of the program that will be used when the NSH ELF + program is installed. + +config TESTING_SERIAL_PRIORITY + int "ser utility task priority" + default 100 + +config TESTING_SERIAL_STACKSIZE + int "ser utility stack size" + default DEFAULT_TASK_STACKSIZE + +endif diff --git a/testing/drivers/ser/Make.defs b/testing/drivers/ser/Make.defs new file mode 100644 index 000000000..cc03f2146 --- /dev/null +++ b/testing/drivers/ser/Make.defs @@ -0,0 +1,25 @@ +############################################################################ +# apps/testing/drivers/ser/Make.defs +# +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you 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. +# +############################################################################ + +ifneq ($(CONFIG_TESTING_SERIAL),) +CONFIGURED_APPS += $(APPDIR)/testing/drivers/ser +endif diff --git a/testing/drivers/ser/Makefile b/testing/drivers/ser/Makefile new file mode 100644 index 000000000..f1fcea625 --- /dev/null +++ b/testing/drivers/ser/Makefile @@ -0,0 +1,35 @@ +############################################################################ +# apps/testing/drivers/ser/Makefile +# +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you 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 $(APPDIR)/Make.defs + +# ser built-in application info + +PROGNAME = $(CONFIG_TESTING_SERIAL_PROGNAME) +PRIORITY = $(CONFIG_TESTING_SERIAL_PRIORITY) +STACKSIZE = $(CONFIG_TESTING_SERIAL_STACKSIZE) + +# ser main source + +MAINSRC = ser.c + +include $(APPDIR)/Application.mk diff --git a/testing/drivers/ser/ser.c b/testing/drivers/ser/ser.c new file mode 100644 index 000000000..ca5820c74 --- /dev/null +++ b/testing/drivers/ser/ser.c @@ -0,0 +1,99 @@ +/**************************************************************************** + * apps/testing/drivers/ser/ser.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +int main(int argc, FAR char *argv[]) +{ + struct serial_icounter_s rcount; + struct serial_icounter_s scount; + + int fd; + int ret; + + fd = open(CONFIG_TESTING_SERIAL_PORT, O_RDONLY); + if (fd < 0) + { + ret = -ENODEV; + goto out; + } + + ret = ioctl(fd, TIOCGICOUNT, &scount); + if (ret < 0) + { + goto out_close; + } + + while (1) + { + ret = ioctl(fd, TIOCGICOUNT, &rcount); + + if (rcount.frame > scount.frame) + { + printf("ERROR: framing %d\n", rcount.frame - scount.frame); + } + + if (rcount.overrun > scount.overrun) + { + printf("ERROR: overrun %d\n", rcount.overrun - scount.overrun); + } + + if (rcount.parity > scount.parity) + { + printf("ERROR: parity %d\n", rcount.parity - scount.parity); + } + + if (rcount.brk > scount.brk) + { + printf("ERROR: break %d\n", rcount.brk - scount.brk); + } + + if (rcount.buf_overrun > scount.buf_overrun) + { + printf("ERROR: buffer overrun %d\n", + rcount.buf_overrun - scount.buf_overrun); + } + + scount = rcount; + usleep(1000000); + } + +out_close: + close(fd); +out: + + return ret; +}