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/] [battery.c] - Blame information for rev 174

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
//=============================================================================
2
//
3
//      battery.c
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, 2003 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: Mark Salter
43
// Date:        2001-01-25
44
// Purpose:     
45
// Description: 
46
//
47
//####DESCRIPTIONEND####
48
//
49
//===========================================================================*/
50
 
51
#include <redboot.h>
52
#include <cyg/hal/hal_io.h>
53
#include "test_menu.h"
54
 
55
extern void diag_wait(void);
56
 
57
#define TEST_PATTERN 0x55555555
58
 
59
// test battery status
60
void
61
battery_status(MENU_ARG arg)
62
{
63
    unsigned short status;
64
 
65
    // read battery status port
66
    status = *IQ80321_BATTERY_STATUS;
67
 
68
    // examine bit b0 BATT_PRES#
69
    if (status & IQ80321_BATTERY_NOT_PRESENT) {
70
        diag_printf("No battery installed.\n");
71
        diag_wait();
72
        return;
73
    }
74
    diag_printf("A battery is installed.\n");
75
 
76
    if (status & IQ80321_BATTERY_CHARGE)
77
        diag_printf("Battery is fully charged.\n");
78
    else
79
        diag_printf("Battery is charging.\n");
80
 
81
    if (status & IQ80321_BATTERY_DISCHARGE)
82
        diag_printf("Battery is fully discharged.\n");
83
    else
84
        diag_printf("Battery voltage measures within normal operating range.\n");
85
 
86
    if (status & IQ80321_BATTERY_ENABLE)
87
        diag_printf("Battery Backup is enabled.\n");
88
    else
89
        diag_printf("Battery Backup is disabled.\n");
90
 
91
    diag_wait();
92
}
93
 
94
 
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
98
 
99
static void
100
battery_test_write (MENU_ARG arg)
101
{
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");
105
    else
106
        diag_printf("Unable to enable battery backup.\n");
107
 
108
    *(volatile unsigned *)SDRAM_BATTERY_TEST_ADDR = TEST_PATTERN;
109
 
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");
114
    diag_wait();
115
}
116
 
117
 
118
static void
119
battery_test_read (MENU_ARG arg)
120
{
121
    cyg_uint32 value;
122
 
123
    *IQ80321_BATTERY_STATUS &= ~IQ80321_BATTERY_ENABLE;
124
    if (*IQ80321_BATTERY_STATUS & IQ80321_BATTERY_ENABLE)
125
        diag_printf("Unable to disable battery backup.\n");
126
    else
127
        diag_printf("The battery backup has now been disabled.\n");
128
 
129
    value = *(volatile unsigned *)SDRAM_BATTERY_TEST_ADDR;
130
 
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);
134
 
135
    if (value == TEST_PATTERN)
136
        diag_printf ("\nThe battery test is a success !");
137
    else {
138
        diag_printf ("\n****************************\n");
139
        diag_printf ("* The battery test failed. *\n");
140
        diag_printf ("****************************\n");
141
    }
142
 
143
    diag_wait();
144
}
145
 
146
 
147
void
148
battery_test_menu (MENU_ARG arg)
149
{
150
    // Test Menu Table
151
    static MENU_ITEM batteryMenu[] = {
152
        {"Write data to SDRAM", battery_test_write, NULL},
153
        {"Check data from SDRAM", battery_test_read, NULL},
154
    };
155
 
156
    unsigned int num_menu_items = (sizeof (batteryMenu) / sizeof (batteryMenu[0]));
157
 
158
    char *menu_title = "\n Battery Backup SDRAM memory test.";
159
 
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 ("*************************************************************************");
167
 
168
    menu (batteryMenu, num_menu_items, menu_title, MENU_OPT_NONE);
169
    diag_printf ("\n");
170
}
171
#endif // CYGSEM_HAL_ARM_IQ80321_BATTERY_TEST
172
 

powered by: WebSVN 2.1.0

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