2 * Copyright Droids Corporation (2008)
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Revision : $Id: commands.c,v 1.1 2009-01-30 20:42:17 zer0 Exp $
20 * Olivier MATZ <zer0@droids-corp.org>
27 #include <aversive/pgmspace.h>
28 #include <aversive/wait.h>
31 #include <parse_num.h>
32 #include <parse_string.h>
39 /**********************************************************/
42 /* this structure is filled when cmd_reset is parsed successfully */
43 struct cmd_reset_result {
47 /* function called when cmd_reset is parsed successfully */
48 static void cmd_reset_parsed(void * parsed_result, void * data)
53 prog_char str_reset_arg0[] = "reset";
54 parse_pgm_token_string_t cmd_reset_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_reset_result, arg0, str_reset_arg0);
56 prog_char help_reset[] = "Reset the board";
57 parse_pgm_inst_t cmd_reset = {
58 .f = cmd_reset_parsed, /* function to call */
59 .data = NULL, /* 2nd arg of func */
60 .help_str = help_reset,
61 .tokens = { /* token list, NULL terminated */
62 (prog_void *)&cmd_reset_arg0,
67 /**********************************************************/
70 /* this structure is filled when cmd_spi_test is parsed successfully */
71 struct cmd_spi_test_result {
75 /* function called when cmd_spi_test is parsed successfully */
76 static void cmd_spi_test_parsed(void * parsed_result, void * data)
83 ret = spi_send_and_receive_byte(i);
84 spi_slave_deselect(0);
85 printf_P(PSTR("Sent %d, received %d\r\n"), i, ret);
88 printf_P(PSTR("disabled\r\n"));
92 prog_char str_spi_test_arg0[] = "spi_test";
93 parse_pgm_token_string_t cmd_spi_test_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_spi_test_result, arg0, str_spi_test_arg0);
95 prog_char help_spi_test[] = "Test the SPI";
96 parse_pgm_inst_t cmd_spi_test = {
97 .f = cmd_spi_test_parsed, /* function to call */
98 .data = NULL, /* 2nd arg of func */
99 .help_str = help_spi_test,
100 .tokens = { /* token list, NULL terminated */
101 (prog_void *)&cmd_spi_test_arg0,
106 /**********************************************************/
109 /* this structure is filled when cmd_bootloader is parsed successfully */
110 struct cmd_bootloader_result {
114 /* function called when cmd_bootloader is parsed successfully */
115 static void cmd_bootloader_parsed(void * parsed_result, void * data)
117 #define BOOTLOADER_ADDR 0x1e000
118 if (pgm_read_byte_far(BOOTLOADER_ADDR) == 0xff) {
119 printf_P(PSTR("Bootloader is not present\r\n"));
123 /* ... very specific :( */
124 #ifdef __AVR_ATmega128__
138 __asm__ __volatile__ ("ldi r30,0x00\n");
139 __asm__ __volatile__ ("ldi r31,0xf0\n");
140 __asm__ __volatile__ ("ijmp\n");
143 prog_char str_bootloader_arg0[] = "bootloader";
144 parse_pgm_token_string_t cmd_bootloader_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_bootloader_result, arg0, str_bootloader_arg0);
146 prog_char help_bootloader[] = "Bootloader the board";
147 parse_pgm_inst_t cmd_bootloader = {
148 .f = cmd_bootloader_parsed, /* function to call */
149 .data = NULL, /* 2nd arg of func */
150 .help_str = help_bootloader,
151 .tokens = { /* token list, NULL terminated */
152 (prog_void *)&cmd_bootloader_arg0,
158 /**********************************************************/
161 /* this structure is filled when cmd_encoders is parsed successfully */
162 struct cmd_encoders_result {
167 /* function called when cmd_encoders is parsed successfully */
168 static void cmd_encoders_parsed(void * parsed_result, void * data)
170 while(uart_recv_nowait(0) == -1) {
171 printf_P(PSTR("% .8ld % .8ld % .8ld % .8ld\r\n"),
172 encoders_microb_get_value((void *)0),
173 encoders_microb_get_value((void *)1),
174 encoders_microb_get_value((void *)2),
175 encoders_microb_get_value((void *)3));
180 prog_char str_encoders_arg0[] = "encoders";
181 parse_pgm_token_string_t cmd_encoders_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_encoders_result, arg0, str_encoders_arg0);
182 prog_char str_encoders_arg1[] = "show";
183 parse_pgm_token_string_t cmd_encoders_arg1 = TOKEN_STRING_INITIALIZER(struct cmd_encoders_result, arg1, str_encoders_arg1);
185 prog_char help_encoders[] = "Show encoders values";
186 parse_pgm_inst_t cmd_encoders = {
187 .f = cmd_encoders_parsed, /* function to call */
188 .data = NULL, /* 2nd arg of func */
189 .help_str = help_encoders,
190 .tokens = { /* token list, NULL terminated */
191 (prog_void *)&cmd_encoders_arg0,
192 (prog_void *)&cmd_encoders_arg1,
198 /**********************************************************/
202 parse_pgm_ctx_t main_ctx[] = {
203 (parse_pgm_inst_t *)&cmd_reset,
204 (parse_pgm_inst_t *)&cmd_spi_test,
205 (parse_pgm_inst_t *)&cmd_bootloader,
207 (parse_pgm_inst_t *)&cmd_encoders,