]> rtime.felk.cvut.cz Git - pes-rpp/rpp-test-sw.git/blob - rpp-test-sw/commands/cmd.c
Change license to MIT
[pes-rpp/rpp-test-sw.git] / rpp-test-sw / commands / cmd.c
1 /*
2  * Copyright (C) 2012-2016 Czech Technical University in Prague
3  *
4  * Created on: 31.7.2012
5  *
6  * Authors:
7  *     - Michal Horn
8  *
9  * Permission is hereby granted, free of charge, to any person
10  * obtaining a copy of this software and associated documentation
11  * files (the "Software"), to deal in the Software without
12  * restriction, including without limitation the rights to use,
13  * copy, modify, merge, publish, distribute, sublicense, and/or sell
14  * copies of the Software, and to permit persons to whom the
15  * Software is furnished to do so, subject to the following
16  * conditions:
17  *
18  * The above copyright notice and this permission notice shall be
19  * included in all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
23  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
25  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
26  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28  * OTHER DEALINGS IN THE SOFTWARE.
29  *
30  * File : cmd.c
31  *
32  * Abstract:
33  *      This file contains root of the list of the commands.
34  *
35  */
36
37 /* Include files */
38 #include "cmdproc.h"
39 #include "cmd.h"
40 #include "cmd_adc.h"
41 #include "cmd_can.h"
42 #include "cmd_pin.h"
43 #include "cmd_port.h"
44 #include "cmd_nc.h"
45 #include "cmd_netstats.h"
46 #include "cmd_emac.h"
47 #include "cmd_echoserver.h"
48 #include "cmd_ping.h"
49 #include "cmd_iperf.h"
50
51 #ifdef TARGET_TMS570_RPP
52 #include "cmd_dac.h"
53 #include "cmd_fray.h"
54 #include "cmd_din.h"
55 #include "cmd_hbr.h"
56 #include "cmd_hout.h"
57 #include "cmd_lin.h"
58 #include "cmd_lout.h"
59 #include "cmd_mout.h"
60 #include "cmd_sdram.h"
61 #include "cmd_spi.h"
62 #include "cmd_vbat.h"
63 #include "cmd_motor_example.h"
64 #include "cmd_fr_basic_test.h"
65 #endif
66
67 #ifndef DOCGEN
68
69 #include "rpp/rpp.h"
70
71 #include <version.h>
72
73 int cmd_do_version(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
74 {
75         rpp_sci_printf("version=%s\n", GIT_VERSION);
76         return 0;
77 }
78
79 #endif  /* DOCGEN */
80
81 /** Root list in which commands are stored */
82 cmd_des_t const **cmd_list;
83
84 #ifdef TARGET_TMS570_RPP
85 int cmd_do_sleep(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
86 {
87 #ifndef DOCGEN
88         if (rpp_gio_set(PIN_CANNSTB, 1) == FAILURE) return -CMDERR_BADDIO;
89         if (rpp_gio_set(PIN_CANEN, 1) == FAILURE) return -CMDERR_BADDIO;
90         if (rpp_gio_set(PIN_LIN2NSLP, 1) == FAILURE) return -CMDERR_BADDIO;
91         if (rpp_gio_set(PIN_LIN1NSLP, 1) == FAILURE) return -CMDERR_BADDIO;
92         vTaskDelay(10/portTICK_RATE_MS);
93         if (rpp_gio_set(PIN_LIN2NSLP, 0) == FAILURE) return -CMDERR_BADDIO;
94         if (rpp_gio_set(PIN_LIN1NSLP, 0) == FAILURE) return -CMDERR_BADDIO;
95         if (rpp_gio_set(PIN_CANNSTB, 0) == FAILURE) return -CMDERR_BADDIO;
96 #endif
97         return 0;
98 }
99
100 /** Command descriptor for sleep command */
101 cmd_des_t const cmd_des_sleep = {
102                 0, 0,
103                 "sleep","Sleep the board",
104                 "### Syntax ###\n"
105                 "\n"
106                 " sleep\n"
107                 "\n"
108                 "### Description ###\n"
109                 "\n"
110                 "This command configures the LIN and CAN peripherals to enter sleep mode\n"
111                 "and turn the whole device into sleep mode. External signal on CAN or\n"
112                 "LIN will wake the device up.\n",
113                 CMD_HANDLER(cmd_do_sleep), (void *)&cmd_list
114 };
115 #endif
116
117 /** Command descriptor for show help command */
118 cmd_des_t const cmd_des_help = {
119         0, 0,
120         "help","Print help for commands",
121         "### Syntax ###\n"
122         "\n"
123         " help [command]\n"
124         "\n"
125         "### Description ###\n"
126         "\n"
127         "This command without parameter prints the list of all available\n"
128         "commands with short help text for each of them. If a parameter is\n"
129         "provided, the command prints a long description for given command.\n",
130         CMD_HANDLER(cmd_do_help), (void *)&cmd_list
131 };
132
133 cmd_des_t const cmd_des_version = {
134         0, 0,
135         "version","Print version of the software",
136         "### Syntax ###\n"
137         "\n"
138         " version\n"
139         "\n"
140         "### Description ###\n"
141         "\n"
142         "This command prints the version of the test software. The version\n"
143         "number is the output of 'git describe' command, i.e. it is composed\n"
144         "from the last tag in the git repository, the number of commits since\n"
145         "the tag and the abbreviated commit hash.\n"
146         "\n"
147         "### Example ###\n"
148         "\n"
149         "    --> version\n"
150         "    version=v0.2-109-ga81a9dd\n",
151         CMD_HANDLER(cmd_do_version),
152 };
153
154 /*  ------------------------
155  *  Command lists definitons
156  *  ------------------------
157  */
158
159 /** @brief Main list of commands */
160 cmd_des_t const *cmd_list_main[] = {
161         &cmd_des_help,
162 #ifdef TARGET_TMS570_RPP
163         &cmd_des_sleep,
164 #endif
165         &cmd_des_version,
166         CMD_DES_INCLUDE_SUBLIST(cmd_list_adc),
167         CMD_DES_INCLUDE_SUBLIST(cmd_list_can),
168         CMD_DES_INCLUDE_SUBLIST(cmd_list_emac),
169         CMD_DES_INCLUDE_SUBLIST(cmd_list_nc),
170         CMD_DES_INCLUDE_SUBLIST(cmd_list_es),
171         CMD_DES_INCLUDE_SUBLIST(cmd_list_netstats),
172         CMD_DES_INCLUDE_SUBLIST(cmd_list_ping),
173         CMD_DES_INCLUDE_SUBLIST(cmd_list_iperf),
174 #ifdef TARGET_TMS570_RPP
175         CMD_DES_INCLUDE_SUBLIST(cmd_list_dac),
176         CMD_DES_INCLUDE_SUBLIST(cmd_list_din),
177         CMD_DES_INCLUDE_SUBLIST(cmd_list_fr_basic_test),
178         CMD_DES_INCLUDE_SUBLIST(cmd_list_fray),
179         CMD_DES_INCLUDE_SUBLIST(cmd_list_hbr),
180         CMD_DES_INCLUDE_SUBLIST(cmd_list_hout),
181         CMD_DES_INCLUDE_SUBLIST(cmd_list_lin),
182         CMD_DES_INCLUDE_SUBLIST(cmd_list_lout),
183         CMD_DES_INCLUDE_SUBLIST(cmd_list_mout),
184         CMD_DES_INCLUDE_SUBLIST(cmd_list_motor_example),
185 #endif
186         CMD_DES_INCLUDE_SUBLIST(cmd_list_pin),
187         CMD_DES_INCLUDE_SUBLIST(cmd_list_port),
188 #ifdef TARGET_TMS570_RPP
189         CMD_DES_INCLUDE_SUBLIST(cmd_list_sdram),
190         CMD_DES_INCLUDE_SUBLIST(cmd_list_spi),
191         CMD_DES_INCLUDE_SUBLIST(cmd_list_vbat),
192 #endif
193         NULL
194 };
195
196 /** Pointer to the root list */
197 cmd_des_t const **cmd_list = cmd_list_main;