OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [hal/] [arm/] [xscale/] [iq80321/] [v2_0/] [src/] [diag/] [test_menu.c] - Blame information for rev 174

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
//=============================================================================
2
//
3
//      test_menu.c - Cyclone Diagnostics
4
//
5
//=============================================================================
6
//####ECOSGPLCOPYRIGHTBEGIN####
7
// -------------------------------------------
8
// This file is part of eCos, the Embedded Configurable Operating System.
9
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
10
//
11
// eCos is free software; you can redistribute it and/or modify it under
12
// the terms of the GNU General Public License as published by the Free
13
// Software Foundation; either version 2 or (at your option) any later version.
14
//
15
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
16
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
17
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
18
// for more details.
19
//
20
// You should have received a copy of the GNU General Public License along
21
// with eCos; if not, write to the Free Software Foundation, Inc.,
22
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
23
//
24
// As a special exception, if other files instantiate templates or use macros
25
// or inline functions from this file, or you compile this file and link it
26
// with other works to produce a work based on this file, this file does not
27
// by itself cause the resulting work to be covered by the GNU General Public
28
// License. However the source code for this file must still be made available
29
// in accordance with section (3) of the GNU General Public License.
30
//
31
// This exception does not invalidate any other reasons why a work based on
32
// this file might be covered by the GNU General Public License.
33
//
34
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
35
// at http://sources.redhat.com/ecos/ecos-license/
36
// -------------------------------------------
37
//####ECOSGPLCOPYRIGHTEND####
38
//=============================================================================
39
//#####DESCRIPTIONBEGIN####
40
//
41
// Author(s):   Scott Coulter, Jeff Frazier, Eric Breeden
42
// Contributors:
43
// Date:        2001-01-25
44
// Purpose:     
45
// Description: 
46
//
47
//####DESCRIPTIONEND####
48
//
49
//===========================================================================*/
50
 
51
/*****************************************************************************
52
* test_menu.c - Menu dispatching routine
53
*
54
* modification history
55
* --------------------
56
* 30aug00 ejb Ported to IQ80310 Cygmon
57
*/
58
 
59
/*
60
DESCRIPTION:
61
 
62
A table-driven menu dispatcher
63
*/
64
 
65
 
66
#include <pkgconf/hal.h>
67
#include <pkgconf/system.h>
68
#include CYGBLD_HAL_PLATFORM_H
69
 
70
#include <cyg/infra/cyg_type.h>         // base types
71
#include <cyg/infra/cyg_trac.h>         // tracing macros
72
#include <cyg/infra/cyg_ass.h>          // assertion macros
73
 
74
#include <cyg/hal/hal_io.h>             // IO macros
75
#include <cyg/hal/hal_arch.h>           // Register state info
76
#include <cyg/hal/hal_diag.h>
77
#include <cyg/hal/hal_intr.h>           // Interrupt names
78
#include <cyg/hal/hal_cache.h>
79
#include <cyg/hal/hal_verde.h>          // Hardware definitions
80
#include <cyg/hal/iq80321.h>            // Platform specifics
81
 
82
#include <cyg/infra/diag.h>             // diag_printf
83
#include "test_menu.h"
84
 
85
#define QUIT                    -1
86
#define MAX_INPUT_LINE_SIZE     80
87
 
88
extern long decIn(void);
89
 
90
/*
91
 * Internal routines
92
 */
93
static int menuGetChoice (MENU_ITEM     menuTable[],
94
                          int           numMenuItems,
95
                          char          *title,
96
                          unsigned long options);
97
static void printMenu (MENU_ITEM        menuTable[],
98
                       int              numMenuItems,
99
                       char             *title);
100
 
101
 
102
/***************************************************************************
103
*
104
* menu - a table-driven menu dispatcher
105
*
106
* RETURNS:
107
*
108
*       The menu item argument, or NULL if the item chosen is QUIT.
109
*/
110
MENU_ARG menu (
111
      MENU_ITEM menuTable[],
112
      int               numMenuItems,
113
      char              *title,
114
      unsigned long     options
115
      )
116
{
117
int     item;           /* User's menu item choice */
118
 
119
    /*
120
     * Get the user's first choice.  Always display the menu the first time.
121
     */
122
    item = menuGetChoice (menuTable, numMenuItems, title, MENU_OPT_NONE);
123
    if (item == QUIT)
124
        return (MENU_ARG)0;
125
 
126
    /*
127
     * If the user just wants a value returned, return the argument.  If the
128
     * argument is null, return the item number itself.
129
     */
130
    if (options & MENU_OPT_VALUE)
131
    {
132
        if (menuTable[item].arg)
133
            return (menuTable[item].arg);
134
        else
135
            return ((void *)item);
136
    }
137
 
138
    /*
139
     * Process menu items until the user selects QUIT
140
     */
141
    while (1)
142
    {
143
        /*
144
         * Call the action routine for the chosen item.  If the argument is
145
         * NULL, pass the item number itself.
146
         */
147
        if (menuTable[item].actionRoutine != NULL) {
148
            if (menuTable[item].arg == NULL) {
149
                diag_printf("\n");
150
                (*menuTable[item].actionRoutine) ((void *)item);
151
            } else {
152
                diag_printf("\n");
153
                (*menuTable[item].actionRoutine) (menuTable[item].arg);
154
            }
155
        }
156
 
157
        /*
158
         * Get the next choice, using any display options the user specified.
159
         */
160
        item = menuGetChoice (menuTable, numMenuItems, title, options);
161
        if (item == QUIT)
162
            return (NULL);
163
    }
164
 
165
} /* end menu () */
166
 
167
 
168
/***************************************************************************
169
*
170
* menuGetChoice - Get the user's menu choice.
171
*
172
* If display is not suppressed, display the menu, then prompt the user for
173
* a choice.  If the choice is out of range or invalid, display the menu and
174
* prompt again.  Continue to display and prompt until a valid choice is made.
175
*
176
* RETURNS:
177
*       The item number of the user's menu choice. (-1 if they chose QUIT)
178
*/
179
 
180
static int
181
menuGetChoice (
182
               MENU_ITEM        menuTable[],
183
               int              numMenuItems,
184
               char             *title,
185
               unsigned long    options
186
               )
187
{
188
/*char  inputLine[MAX_INPUT_LINE_SIZE];*/
189
 
190
int     choice;
191
 
192
    /*
193
     * Suppress display of the menu the first time if we're asked
194
     */
195
    if (!(options & MENU_OPT_SUPPRESS_DISP))
196
                printMenu (menuTable, numMenuItems, title);
197
 
198
    /*
199
     * Prompt for a selection.  Redisplay the menu and prompt again
200
     * if there's an error in the selection.
201
     */
202
    choice = -1;
203
 
204
    while (choice < 0 || choice > numMenuItems)
205
    {
206
 
207
                diag_printf ("\nEnter the menu item number (0 to quit): ");
208
 
209
                choice = decIn ();
210
 
211
                if (choice < 0 || choice > numMenuItems)
212
 
213
                        printMenu (menuTable, numMenuItems, title);
214
 
215
    }
216
 
217
    if (choice == 0)
218
 
219
                return (QUIT);
220
 
221
    return (choice - 1);
222
 
223
} /* end menuGetChoice () */
224
 
225
 
226
/***************************************************************************
227
*
228
* printMenu - Print the menu
229
*
230
*
231
*/
232
 
233
static void
234
printMenu (
235
           MENU_ITEM    menuTable[],
236
           int          numMenuItems,
237
           char         *title
238
           )
239
{
240
    int         i;
241
 
242
 
243
    diag_printf("\n%s\n\n", title);
244
 
245
    for (i = 0; i < numMenuItems; i++)
246
    {
247
                diag_printf ("%2d - %s\n", i+1, menuTable[i].itemName);
248
    }
249
 
250
    diag_printf(" 0 - quit");
251
 
252
} /* end printMenu () */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.