4 * This file is part of BeRTOS.
6 * Bertos is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * As a special exception, you may use this file as part of a free software
21 * library without restriction. Specifically, if other files instantiate
22 * templates or use macros or inline functions from this file, or you compile
23 * this file and link it with other files to produce an executable, this
24 * file does not by itself cause the resulting executable to be covered by
25 * the GNU General Public License. This exception does not however
26 * invalidate any other reasons why the executable file might be covered by
27 * the GNU General Public License.
29 * Copyright 2003, 2004, 2006, 2012 Develer S.r.l. (http://www.develer.com/)
30 * Copyright 2000 Bernie Innocenti <bernie@codewiz.org>
34 * \brief Implementation of the command protocol between the board and the host
37 * \author Giovanni Bajo <rasky@develer.com>
38 * \author Marco Benelli <marco@develer.com>
39 * \author Bernie Innocenti <bernie@codewiz.org>
40 * \author Daniele Basile <asterix@develer.com>
46 #include "hw/hw_input.h"
47 #include "cfg/cfg_parser.h"
48 #include <cfg/compiler.h>
49 #include <cfg/debug.h>
51 #include <mware/parser.h>
53 #include <drv/timer.h>
56 #include <drv/buzzer.h>
60 // Define the format string for ADC
61 #define ADC_FORMAT_STR "dddd"
62 #define ADC_CHANNEL_NUM 4
64 static Sipo *local_sipo;
65 static uint8_t reg_status_dout;
68 MAKE_CMD(ver, "", "ddd",
70 args[1].l = VERS_MAJOR;
71 args[2].l = VERS_MINOR;
76 /* Sleep. Example of declaring function body directly in macro call. */
77 MAKE_CMD(sleep, "d", "",
79 timer_delay((mtime_t)args[1].l);
84 MAKE_CMD(ping, "", "",
86 //Silence "args not used" warning.
92 MAKE_CMD(dout, "d", "",
94 kfile_putc((uint8_t)args[1].l, &local_sipo->fd);
96 //Store status of dout ports.
97 reg_status_dout = (uint8_t)args[1].l;
101 /* rdout read the status of out ports.*/
102 MAKE_CMD(rdout, "", "d",
104 args[1].l = reg_status_dout;
110 MAKE_CMD(reset, "", "",
112 //Silence "args not used" warning.
116 /*We want to have an infinite loop that lock access on watchdog timer.
117 This piece of code it's equivalent to a while(true), but we have done this because
118 gcc generate a warning message that suggest to use "noreturn" parameter in function reset.*/
126 MAKE_CMD(din, "", "d",
128 args[1].l = INPUT_GET();
134 MAKE_CMD(ain, "", ADC_FORMAT_STR,
136 STATIC_ASSERT((sizeof(ADC_FORMAT_STR) - 1) == ADC_CHANNEL_NUM);
137 for(int i = 0; i < ADC_CHANNEL_NUM; i++)
138 args[i+1].l = adc_read(i);
144 MAKE_CMD(beep, "d", "",
150 /* Register commands. */
151 void cmd_register(void)
164 void cmd_init(Sipo *sipo)