/*
 * Copyright(C) Paul und Scherer (mct.de/mct.net)
 *
 * This example demonstrates how to...
 *
 *  ... redirect stdin/stdout/stderr to UART1.
 */

#include <stdio.h>
#include <sys/io.h>

/*
 * The array _iodev[] holds the file descriptors for
 *
 *  stdin  =&_iodev[0]: 0 =UART0 in
 *  stdout =&_iodev[1]: 1 =UART0 out
 *  stderr =&_iodev[2]: 2 =UART0 out
 *  auxin  =&_iodev[3]: 3 =UART1 in
 *  auxout =&_iodev[4]: 4 =UART1 out
 *
 * when main is called.
 *
 * Each stream can be dynamically re-assigned any fd
 * by the user program.
 */
int
main(void)
{
	/*
	 * Initialize UART1.
	 *
	 * If the baudrate cannot be set within +/-3%,
	 * _sio_init() returns non-zero and sets errno
	 * appropriately.
	 */
	if (_sio_init(19200, 1)) return perror("_sio_init"), 1;

	*stdin  = 3;				// stdin  -> UART1 in
	*stdout = 4;				// stdout -> UART1 out
	*stderr = 4;				// stderr -> UART1 out

	/*
	 * All following std I/O is now via UART1.
	 */
	while (1) puts("hello..."), getchar();
}
