RT-AC66 3.0.0.4.374.130 core
[tomato.git] / release / src-rt-6.x / cfe / cfe / arch / mips / board / carmel / src / ui_carmel.c
blob33dd6878ede5102d7acddc8c7531ca97fb76a35d
1 /* *********************************************************************
2 * Broadcom Common Firmware Environment (CFE)
3 *
4 * carmel-specific commands File: ui_carmel.c
5 *
6 * A temporary sandbox for misc test routines and commands.
7 *
8 * Author: Mitch Lichtenberg (mpl@broadcom.com)
9 *
10 *********************************************************************
12 * Copyright 2000,2001,2002,2003
13 * Broadcom Corporation. All rights reserved.
15 * This software is furnished under license and may be used and
16 * copied only in accordance with the following terms and
17 * conditions. Subject to these conditions, you may download,
18 * copy, install, use, modify and distribute modified or unmodified
19 * copies of this software in source and/or binary form. No title
20 * or ownership is transferred hereby.
22 * 1) Any source code used, modified or distributed must reproduce
23 * and retain this copyright notice and list of conditions
24 * as they appear in the source file.
26 * 2) No right is granted to use any trade name, trademark, or
27 * logo of Broadcom Corporation. The "Broadcom Corporation"
28 * name may not be used to endorse or promote products derived
29 * from this software without the prior written permission of
30 * Broadcom Corporation.
32 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
33 * IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
34 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
35 * PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
36 * SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
37 * PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
38 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
39 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
40 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
41 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
42 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
43 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
44 * THE POSSIBILITY OF SUCH DAMAGE.
45 ********************************************************************* */
48 #include "lib_types.h"
49 #include "lib_string.h"
50 #include "lib_queue.h"
51 #include "lib_malloc.h"
52 #include "lib_printf.h"
54 #include "lib_physio.h"
56 #include "cfe_timer.h"
58 #include "cfe_error.h"
59 #include "cfe_console.h"
61 #include "ui_command.h"
62 #include "cfe.h"
64 #include "bsp_config.h"
66 #include "sbmips.h"
67 #include "sb1250_regs.h"
68 #include "sb1250_scd.h"
70 #include "carmel.h"
72 #include "env_subr.h"
73 #include "carmel_env.h"
75 /* *********************************************************************
76 * Configuration
77 ********************************************************************* */
79 /* *********************************************************************
80 * prototypes
81 ********************************************************************* */
83 int ui_init_carmelcmds(void);
85 static int ui_cmd_mreset(ui_cmdline_t *cmd,int argc,char *argv[]);
86 static int ui_cmd_msetup(ui_cmdline_t *cmd,int argc,char *argv[]);
87 static int ui_cmd_msetenv(ui_cmdline_t *cmd,int argc,char *argv[]);
88 static int ui_cmd_mprintenv(ui_cmdline_t *cmd,int argc,char *argv[]);
89 static int ui_cmd_munsetenv(ui_cmdline_t *cmd,int argc,char *argv[]);
91 /* *********************************************************************
92 * Data
93 ********************************************************************* */
96 /* *********************************************************************
97 * ui_init_carmelcmds()
99 * Add carmel-specific commands to the command table
101 * Input parameters:
102 * nothing
104 * Return value:
106 ********************************************************************* */
109 int ui_init_carmelcmds(void)
111 cmd_addcmd("monterey reset",
112 ui_cmd_mreset,
113 NULL,
114 "Reset the Monterey Subsystem",
115 "monterey reset [0|1]\n\n"
116 "This command resets the board that the Carmel is attached to. For\n"
117 "example, if Carmel is attached to a Monterey board, the Monterey\n"
118 "FPGA is reset. You can specify an absolute value for the reset pin\n"
119 "or type 'monterey reset' without a parameter to pulse the reset line.",
120 "");
122 cmd_addcmd("monterey setenv",
123 ui_cmd_msetenv,
124 NULL,
125 "Set a Monterey environment variable.",
126 "monterey setenv [-p] varname value\n\n"
127 "This command sets an environment variable. By default, an environment variable\n"
128 "is stored only in memory and will not be retained across system restart.",
129 "-p;Store environment variable permanently in the NVRAM device, if present");
131 cmd_addcmd("monterey printenv",
132 ui_cmd_mprintenv,
133 NULL,
134 "Display the Monterey environment variables",
135 "monterey printenv\n\n"
136 "This command prints a table of the Monterey environment variables and their\n"
137 "current values.",
138 "");
140 cmd_addcmd("monterey unsetenv",
141 ui_cmd_munsetenv,
142 NULL,
143 "Delete a Monterey environment variable.",
144 "monterey unsetenv varname\n\n"
145 "This command deletes a Monterey environment variable from memory and also \n"
146 "removes it from the NVRAM device (if present).",
147 "");
149 cmd_addcmd("monterey setup",
150 ui_cmd_msetup,
151 NULL,
152 "Interactive setup for Monterey variables.",
153 "monterey setup\n\n"
154 "This command prompts for the important Monterey environment variables and\n"
155 "stores them in the ID EEPROM\n",
156 "");
158 return 0;
164 static int ui_cmd_mreset(ui_cmdline_t *cmd,int argc,char *argv[])
166 char *x;
167 int val;
169 if ((x = cmd_getarg(cmd,0))) {
170 val = atoi(x);
171 if (val) {
172 SBWRITECSR(A_GPIO_PIN_SET,M_GPIO_MONTEREY_RESET);
174 else {
175 SBWRITECSR(A_GPIO_PIN_CLR,M_GPIO_MONTEREY_RESET);
177 printf("Monterey reset pin set to %d\n",val ? 1 : 0);
179 else {
180 SBWRITECSR(A_GPIO_PIN_CLR,M_GPIO_MONTEREY_RESET);
181 cfe_sleep(2);
182 SBWRITECSR(A_GPIO_PIN_SET,M_GPIO_MONTEREY_RESET);
183 printf("Monterey has been reset.\n");
186 return 0;
194 static int ui_cmd_mprintenv(ui_cmdline_t *cmd,int argc,char *argv[])
196 char varname[80];
197 char value[256];
198 int varlen,vallen;
199 int idx;
201 xprintf("Variable Name Value\n");
202 xprintf("-------------------- --------------------------------------------------\n");
204 idx = 0;
205 for (;;) {
206 varlen = sizeof(varname);
207 vallen = sizeof(value);
208 if (carmel_enumenv(idx,varname,&varlen,value,&vallen) < 0) break;
209 xprintf("%20s %s\n",varname,value);
210 idx++;
213 return 0;
217 static int ui_cmd_msetenv(ui_cmdline_t *cmd,int argc,char *argv[])
219 char *varname;
220 char *value;
221 int roflag = ENV_FLG_NORMAL;
222 int res;
224 varname = cmd_getarg(cmd,0);
226 if (!varname) {
227 return ui_showusage(cmd);
230 value = cmd_getarg(cmd,1);
231 if (!value) {
232 return ui_showusage(cmd);
235 if (!cmd_sw_isset(cmd,"-p")) {
236 roflag = ENV_FLG_BUILTIN; /* just in memory, not NVRAM */
239 if ((res = carmel_setenv(varname,value,roflag)) == 0) {
240 if (roflag != ENV_FLG_BUILTIN) carmel_saveenv();
242 else {
243 return ui_showerror(res,"Could not set Monterey environment variable '%s'",
244 varname);
247 return 0;
251 static int ui_cmd_munsetenv(ui_cmdline_t *cmd,int argc,char *argv[])
253 char *varname;
254 int res;
255 int type;
257 varname = cmd_getarg(cmd,0);
259 if (!varname) {
260 return ui_showusage(cmd);
263 type = carmel_envtype(varname);
265 if ((res = carmel_delenv(varname)) == 0) {
266 if ((type >= 0) && (type != ENV_FLG_BUILTIN)) carmel_saveenv();
268 else {
269 return ui_showerror(res,"Could not delete Monterey environment variable '%s'",
270 varname);
273 return 0;
277 #define MSETUP_UCASE 1
278 #define MSETUP_YESNO 2
280 static int msetup_getone(char *prompt,char *envvar,char *defval,int flg)
282 char buffer[100];
283 char pbuf[100];
284 char *curval;
286 curval = carmel_getenv(envvar);
287 if (!curval) curval = defval;
289 sprintf(pbuf,"%s [%s]: ",prompt,curval);
291 for (;;) {
292 console_readline(pbuf,buffer,sizeof(buffer));
293 if (buffer[0] == 0) break; /* default */
294 if (flg & (MSETUP_UCASE|MSETUP_YESNO)) strupr(buffer);
295 if (flg & MSETUP_YESNO) {
296 if (strcmp(buffer,"YES") == 0) break;
297 if (strcmp(buffer,"NO") == 0) break;
298 printf("You must enter 'YES' or 'NO'.\n");
299 continue;
301 break;
305 if (buffer[0] == 0) {
306 carmel_setenv(envvar,defval,0);
308 else {
309 carmel_setenv(envvar,buffer,0);
312 return 0;
316 static int ui_cmd_msetup(ui_cmdline_t *cmd,int argc,char *argv[])
319 msetup_getone("Board type (MONTEREY,LITTLESUR,BIGSUR)","M_BOARDTYPE","MONTEREY",MSETUP_UCASE);
320 msetup_getone("FPGA Autoload (YES,NO)","M_FPGALOAD","YES",MSETUP_YESNO);
321 msetup_getone("FPGA GPIO bits convoluted (YES,NO)","M_FPGACONVOLUTED","NO",
322 MSETUP_YESNO);
324 carmel_saveenv();
325 return 0;