1 //=============================================================================
5 //=============================================================================
6 //####ECOSGPLCOPYRIGHTBEGIN####
7 // -------------------------------------------
8 // This file is part of eCos, the Embedded Configurable Operating System.
9 // Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Red Hat, Inc.
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.
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
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.
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.
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.
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####
41 // Author(s): Scott Coulter, Jeff Frazier, Eric Breeden
42 // Contributors: Mark Salter
47 //####DESCRIPTIONEND####
49 //===========================================================================*/
52 #include <cyg/hal/hal_io.h>
53 #include "test_menu.h"
55 extern void diag_wait(void);
57 #define TEST_PATTERN 0x55555555
59 // test battery status
61 battery_status(MENU_ARG arg)
63 unsigned short status;
65 // read battery status port
66 status = *IQ80321_BATTERY_STATUS;
68 // examine bit b0 BATT_PRES#
69 if (status & IQ80321_BATTERY_NOT_PRESENT) {
70 diag_printf("No battery installed.\n");
74 diag_printf("A battery is installed.\n");
76 if (status & IQ80321_BATTERY_CHARGE)
77 diag_printf("Battery is fully charged.\n");
79 diag_printf("Battery is charging.\n");
81 if (status & IQ80321_BATTERY_DISCHARGE)
82 diag_printf("Battery is fully discharged.\n");
84 diag_printf("Battery voltage measures within normal operating range.\n");
86 if (status & IQ80321_BATTERY_ENABLE)
87 diag_printf("Battery Backup is enabled.\n");
89 diag_printf("Battery Backup is disabled.\n");
95 #ifdef CYGSEM_HAL_ARM_IQ80321_BATTERY_TEST
96 // Data to be written to address and read after the board has
97 // been powered off and powered back on
100 battery_test_write (MENU_ARG arg)
102 *IQ80321_BATTERY_STATUS |= IQ80321_BATTERY_ENABLE;
103 if (*IQ80321_BATTERY_STATUS & IQ80321_BATTERY_ENABLE)
104 diag_printf("The battery backup has now been enabled.\n");
106 diag_printf("Unable to enable battery backup.\n");
108 *(volatile unsigned *)SDRAM_BATTERY_TEST_ADDR = TEST_PATTERN;
110 diag_printf("The value '%p' is now written to DRAM at address %p.\n",
111 TEST_PATTERN, SDRAM_BATTERY_TEST_ADDR);
112 diag_printf("\nYou may now power the board off, wait 60 seconds and power it back on.\n");
113 diag_printf("Then come back into the battery test menu and check data in DRAM.\n");
119 battery_test_read (MENU_ARG arg)
123 *IQ80321_BATTERY_STATUS &= ~IQ80321_BATTERY_ENABLE;
124 if (*IQ80321_BATTERY_STATUS & IQ80321_BATTERY_ENABLE)
125 diag_printf("Unable to disable battery backup.\n");
127 diag_printf("The battery backup has now been disabled.\n");
129 value = *(volatile unsigned *)SDRAM_BATTERY_TEST_ADDR;
131 diag_printf ("Value written at address %p: %p\n",
132 SDRAM_BATTERY_TEST_ADDR, TEST_PATTERN);
133 diag_printf ("Value read: %p\n", value);
135 if (value == TEST_PATTERN)
136 diag_printf ("\nThe battery test is a success !");
138 diag_printf ("\n****************************\n");
139 diag_printf ("* The battery test failed. *\n");
140 diag_printf ("****************************\n");
148 battery_test_menu (MENU_ARG arg)
151 static MENU_ITEM batteryMenu[] = {
152 {"Write data to SDRAM", battery_test_write, NULL},
153 {"Check data from SDRAM", battery_test_read, NULL},
156 unsigned int num_menu_items = (sizeof (batteryMenu) / sizeof (batteryMenu[0]));
158 char *menu_title = "\n Battery Backup SDRAM memory test.";
160 diag_printf ("\n*************************************************************************\n");
161 diag_printf ("* This test will enable you to perform a battery test in 4 steps: *\n");
162 diag_printf ("* 1/ Select option 1 to write test pattern, *\n");
163 diag_printf ("* 2/ Power the board off and wait 60 seconds, *\n");
164 diag_printf ("* 3/ Power the board back on, *\n");
165 diag_printf ("* 4/ Select option 2 to read back and compare test pattern *\n");
166 diag_printf ("*************************************************************************");
168 menu (batteryMenu, num_menu_items, menu_title, MENU_OPT_NONE);
171 #endif // CYGSEM_HAL_ARM_IQ80321_BATTERY_TEST