1
0
mirror of git://projects.qi-hardware.com/ben-blinkenlights.git synced 2024-07-05 02:39:49 +03:00
ben-blinkenlights/swuart/test.c
Werner Almesberger 2e749f901c swuart/: split general UART functions from application
... in preparation for making it a library.
2012-12-17 18:43:51 -03:00

58 lines
1.1 KiB
C

/*
* 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 <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <ubb/ubb.h>
#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);
}
}