/* * swuart/test.c - Software-implemented UART for UBB * * Written 2012 by Werner Almesberger * Copyright 2012 Werner Almesberger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. */ #include #include #include #include #include #include "swuart.h" #define RX UBB_DAT0 #define TX UBB_DAT1 static void at_exit(void) { swuart_close(); } int main(int argc, char **argv) { uint8_t buf[40]; struct swuart_err err; int got, i; swuart_open(TX, RX, atoi(argv[1])); atexit(at_exit); while (1) { got = swuart_trx(argv[2], strlen(argv[2]), buf, sizeof(buf), 10000, 100); swuart_get_errors(&err); printf("%d (%d %d %d): ", got, err.glitch, err.framing, err.overflow); for (i = 0; i != got; i++) if (buf[i] >= ' ' && buf[i] <= '~') printf("%c", buf[i]); else printf("\\%02o", buf[i]); printf("\n"); usleep(100); } }