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