X-Git-Url: http://git.droids-corp.org/?p=aversive.git;a=blobdiff_plain;f=modules%2Fcomm%2Fuart%2Ftest%2Fmain.c;h=23ed2f012fd012b1bd10623a7d142fbaa6cf1f79;hp=b5ef729dfe1f4e52dd5088293d4654090f710a3d;hb=3b7b449237422537c8cdf124b0f4dde827787e14;hpb=92b0749bee9fba8b5105590bf2c2f15786c55cee diff --git a/modules/comm/uart/test/main.c b/modules/comm/uart/test/main.c index b5ef729..23ed2f0 100644 --- a/modules/comm/uart/test/main.c +++ b/modules/comm/uart/test/main.c @@ -1,6 +1,6 @@ -/* +/* * Copyright Droids Corporation, Microb Technology, Eirbot (2005) - * + * * 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 @@ -18,25 +18,51 @@ * Revision : $Id: main.c,v 1.15.10.5 2008-12-27 16:29:08 zer0 Exp $ * */ -#include #include +#include + +#include #include -#include -#include +/* sending "pop" on cmdline uart resets the robot */ +void emergency(char c) +{ + static uint8_t i = 0; + + printf("%c\n", c); + + if ((i == 0 && c == 'p') || + (i == 1 && c == 'o') || + (i == 2 && c == 'p')) + i++; + else if ( !(i == 1 && c == 'p') ) + i = 0; + if (i == 3) { +#ifdef HOST_VERSION + hostsim_uart_exit(); +#endif + reset(); + } +} /* * This code sends a counter value to uart. */ int main(void) -{ +{ int i; +#ifdef HOST_VERSION + hostsim_uart_init(); + hostsim_ittimer_enable(100000); +#endif + /* initialize uart with the default parameters ( see * uart_config.h ) */ - uart_init(); - + uart_init(); + uart_register_rx_event(0, emergency); + /* enable interrupts */ sei(); @@ -47,24 +73,26 @@ int main(void) wait_ms(100); } uart_send(0, '\n'); - + +#ifndef HOST_VERSION /* now we want to do a printf : we must register the * uart0_send as stdout. Here no receive function is * specified. */ fdevopen(uart0_dev_send, NULL); - +#endif + /** ready to do a nice printf on the uart */ printf("Uart is cool !!\n"); - - /* one drawback of the previous printf is that the format - * chain is srored in RAM and this can take a huge size if + + /* one drawback of the previous printf is that the format + * chain is stored in RAM and this can take a huge size if * there are many printf. To avoid this problem, please use - * printf_P together with PSTR, like in the next example. */ + * printf_P together with PSTR, like in the next example. */ while (1) { printf_P(PSTR("This format string takes no RAM " "space. %i\n"), i++); wait_ms(1000); } - + return 0; }