uart-echo/uart-echo.c

Date:
18.06.2004
Author:
Martin Hinz <btnode@hinz.ch>
This application echos the application uart and signals a received byte with an led pattern

00001 /*
00002  * Copyright (C) 2000-2005 by ETH Zurich
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions
00006  * are met:
00007  *
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the copyright holders nor the names of
00014  *    contributors may be used to endorse or promote products derived
00015  *    from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY ETH ZURICH AND CONTRIBUTORS
00018  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00019  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00020  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ETH ZURICH
00021  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00022  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00023  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
00024  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
00025  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00026  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
00027  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00028  * SUCH DAMAGE.
00029  *
00030  * For additional information see http://www.btnode.ethz.ch
00031  *
00032  * $Id: uart-echo.c,v 1.10 2006/03/23 07:22:22 dyerm Exp $
00033  * 
00034  */
00035 
00066 #include <string.h>
00067 #include <stdio.h>
00068 #include <io.h>
00069 #include <hardware/btn-hardware.h>
00070 #include <dev/usartavr.h>
00071 #include <led/btn-led.h>
00072 #include <sys/thread.h>
00073 FILE *uart;
00074 
00075 
00076 /*
00077  * listen on uart and write to uart
00078  */
00079 void listen_to_uart(void)
00080 {
00081     int got;
00082     char inbuf[20]; 
00083     for(;;){
00084         got = _read(_fileno(uart), inbuf, 20);
00085         btn_led_clear_pattern_queue();
00086         btn_led_add_pattern(BTN_LED_PATTERN_UP, 0,1, 1);
00087         btn_led_add_pattern(BTN_LED_PATTERN_KNIGHT, 0, 4, BTN_LED_INFINITE);
00088         _write(_fileno(uart), inbuf, got);        
00089     }
00090 } 
00091 
00092 int main(void){   
00093     u_long baud = 57600;
00094     btn_hardware_init();
00095     //initialize application UART
00096     //speed of uart set default to 576200
00097     NutRegisterDevice(&APP_UART, 0, 0);
00098     uart = fopen(APP_UART.dev_name, "r+");
00099     _ioctl(_fileno(uart), UART_SETSPEED, &baud);
00100 
00101     fputs("UART-echo application!\n",uart); 
00102     btn_led_init(1);
00103     btn_led_add_pattern(BTN_LED_PATTERN_KNIGHT, 0, 4, BTN_LED_INFINITE);
00104     
00105     listen_to_uart();
00106     return 1;
00107 }

Generated on Wed Apr 29 11:12:28 2009 for BTnut System Software by doxygen 1.5.1
!!! Dieses Dokument stammt aus dem ETH Web-Archiv und wird nicht mehr gepflegt !!!
!!! This document is stored in the ETH Web archive and is no longer maintained !!!