2 * Copyright Droids Corporation
3 * Olivier Matz <zer0@droids-corp.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * Revision : $Id: main.c,v 1.1 2009-01-30 20:42:17 zer0 Exp $
27 #include <aversive/pgmspace.h>
28 #include <aversive/wait.h>
34 #include <scheduler.h>
39 /* for cmdline interface */
41 char prompt[RDLINE_PROMPT_SIZE];
42 extern parse_pgm_ctx_t main_ctx[];
44 /******** For cmdline. See in commands.c for the list of commands. */
45 static void write_char(char c)
51 valid_buffer(const char * buf, uint8_t size)
54 ret = parse(main_ctx, buf);
55 if (ret == PARSE_AMBIGUOUS)
56 printf_P(PSTR("Ambiguous command\r\n"));
57 else if (ret == PARSE_NOMATCH)
58 printf_P(PSTR("Command not found\r\n"));
59 else if (ret == PARSE_BAD_ARGS)
60 printf_P(PSTR("Bad arguments\r\n"));
64 complete_buffer(const char * buf, char * dstbuf, uint8_t dstsize,
67 return complete(main_ctx, buf, state, dstbuf, dstsize);
70 /***********************/
72 void do_led_blink(void * dummy)
74 #if 1 /* simple blink */
86 static void main_timer_interrupt(void)
88 static uint8_t cpt = 0;
94 scheduler_interrupt();
97 /* sending "pop" on uart0 resets the robot */
98 static void emergency(char c) {
101 if( (i == 0 && c == 'p') ||
102 (i == 1 && c == 'o') ||
103 (i == 2 && c == 'p') )
105 else if ( !(i == 1 && c == 'p') )
114 const char * history;
118 spi_init(SPI_MODE_MASTER, SPI_FORMAT_2, SPI_CLK_RATE_16);
119 spi_set_data_order(SPI_MSB_FIRST);
120 spi_register_ss_line(&SS_PORT, SS_BIT);
124 fdevopen(uart0_dev_send, uart0_dev_recv);
125 uart_register_rx_event(0, emergency);
129 timer0_register_OV_intr(main_timer_interrupt);
133 scheduler_add_periodical_event_priority(do_led_blink, NULL,
134 100000L / SCHEDULER_UNIT,
138 printf_P(PSTR("Coucou\r\n"));
140 rdline_init(&rdl, write_char, valid_buffer, complete_buffer);
141 snprintf(prompt, sizeof(prompt), "ax12 > ");
142 rdline_newline(&rdl, prompt);
145 c = uart_recv_nowait(0);
148 ret = rdline_char_in(&rdl, c);
149 if (ret != 2 && ret != 0) {
150 history = rdline_get_buffer(&rdl);
151 if (strlen(history) > 1)
152 rdline_add_history(&rdl, history);
153 rdline_newline(&rdl, prompt);