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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [hal/] [arm/] [sa11x0/] [ipaq/] [v2_0/] [src/] [redboot_cmds.c] - Blame information for rev 616

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
//==========================================================================
2
//
3
//      redboot_cmds.c
4
//
5
//      iPAQ [platform] specific RedBoot commands
6
//
7
//==========================================================================
8
//####ECOSGPLCOPYRIGHTBEGIN####
9
// -------------------------------------------
10
// This file is part of eCos, the Embedded Configurable Operating System.
11
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
12
//
13
// eCos is free software; you can redistribute it and/or modify it under
14
// the terms of the GNU General Public License as published by the Free
15
// Software Foundation; either version 2 or (at your option) any later version.
16
//
17
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
19
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20
// for more details.
21
//
22
// You should have received a copy of the GNU General Public License along
23
// with eCos; if not, write to the Free Software Foundation, Inc.,
24
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25
//
26
// As a special exception, if other files instantiate templates or use macros
27
// or inline functions from this file, or you compile this file and link it
28
// with other works to produce a work based on this file, this file does not
29
// by itself cause the resulting work to be covered by the GNU General Public
30
// License. However the source code for this file must still be made available
31
// in accordance with section (3) of the GNU General Public License.
32
//
33
// This exception does not invalidate any other reasons why a work based on
34
// this file might be covered by the GNU General Public License.
35
//
36
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37
// at http://sources.redhat.com/ecos/ecos-license/
38
// -------------------------------------------
39
//####ECOSGPLCOPYRIGHTEND####
40
//==========================================================================
41
//#####DESCRIPTIONBEGIN####
42
//
43
// Author(s):    gthomas
44
// Contributors: gthomas
45
//               Richard Panton <richard.panton@3glab.com>
46
// Date:         2001-02-24
47
// Purpose:      
48
// Description:  
49
//              
50
// This code is part of RedBoot (tm).
51
//
52
//####DESCRIPTIONEND####
53
//
54
//==========================================================================
55
 
56
#include <redboot.h>
57
 
58
#include <cyg/hal/hal_sa11x0.h>   // Board definitions
59
#include <cyg/hal/ipaq.h>
60
#include <cyg/hal/hal_intr.h>
61
#include <cyg/hal/hal_cache.h>
62
 
63
// Exported CLI function(s)
64
static void do_gpio(int argc, char *argv[]);
65
RedBoot_cmd("gpio",
66
            "Query and/or set the GPIO status",
67
            "[-s bits] [-c bits]",
68
            do_gpio
69
    );
70
 
71
static void do_egpio(int argc, char *argv[]);
72
RedBoot_cmd("egpio",
73
            "Query and/or set the EGPIO status",
74
            "[-s bits] [-c bits]",
75
            do_egpio
76
    );
77
 
78
static void do_mem(int argc, char *argv[]);
79
RedBoot_cmd("mem",
80
            "Set a memory location",
81
            "[-h|-b] [-a <address>] <data>",
82
            do_mem
83
    );
84
 
85
static void do_physaddr(int argc, char *argv[]);
86
RedBoot_cmd("physaddr",
87
            "Converts a virtual to a physical address",
88
            "<address>",
89
            do_physaddr
90
    );
91
 
92
static void
93
do_gpio(int argc,char *argv[]) {
94
    struct option_info opts[2];
95
    bool set_bits_set, clr_bits_set;
96
    int set_bits, clr_bits;
97
    init_opts(&opts[0], 's', true, OPTION_ARG_TYPE_NUM,
98
              (void **)&set_bits, (bool *)&set_bits_set, "bits to set");
99
    init_opts(&opts[1], 'c', true, OPTION_ARG_TYPE_NUM,
100
              (void **)&clr_bits, (bool *)&clr_bits_set, "bits to clear");
101
    if (!scan_opts(argc, argv, 1, opts, 2, NULL, 0, NULL))
102
    {
103
        return;
104
    }
105
    if ( !set_bits_set && !clr_bits_set ) {
106
        // display only
107
        diag_printf("  gpio = 0x%08lX\n", *SA11X0_GPIO_PIN_LEVEL);
108
        diag_printf("         0x%08lX are output\n", *SA11X0_GPIO_PIN_DIRECTION);
109
        diag_printf("         0x%08lX rising edge detect\n", *SA11X0_GPIO_RISING_EDGE_DETECT);
110
        diag_printf("         0x%08lX falling edge detect\n", *SA11X0_GPIO_FALLING_EDGE_DETECT);
111
        diag_printf("         0x%08lX edge detect status\n", *SA11X0_GPIO_EDGE_DETECT_STATUS);
112
        diag_printf("         0x%08lX alternate function\n", *SA11X0_GPIO_ALTERNATE_FUNCTION);
113
        return;
114
    }
115
    diag_printf( "  gpio 0x%08lX, ", *SA11X0_GPIO_PIN_LEVEL);
116
    if ( set_bits_set ) {
117
        diag_printf("set(0x%08X) ",set_bits);
118
        *SA11X0_GPIO_PIN_OUTPUT_SET = set_bits;
119
    }
120
    if ( clr_bits_set ) {
121
        diag_printf("clear(0x%08X) ",clr_bits);
122
        *SA11X0_GPIO_PIN_OUTPUT_CLEAR = clr_bits;
123
    }
124
    diag_printf( "gives 0x%08lX\n", *SA11X0_GPIO_PIN_LEVEL);
125
}
126
 
127
static void
128
do_egpio(int argc,char *argv[]) {
129
    struct option_info opts[2];
130
    bool set_bits_set, clr_bits_set;
131
    int set_bits, clr_bits;
132
    init_opts(&opts[0], 's', true, OPTION_ARG_TYPE_NUM,
133
              (void **)&set_bits, (bool *)&set_bits_set, "bits to set");
134
    init_opts(&opts[1], 'c', true, OPTION_ARG_TYPE_NUM,
135
              (void **)&clr_bits, (bool *)&clr_bits_set, "bits to clear");
136
    if (!scan_opts(argc, argv, 1, opts, 2, NULL, 0, NULL)) return;
137
    if ( !set_bits_set && !clr_bits_set ) {
138
        // display only
139
        diag_printf("  egpio = 0x%04X\n", (int)(_ipaq_EGPIO & 0xffff));
140
        return;
141
    }
142
    diag_printf( "  egpio 0x%04X, ", (int)(_ipaq_EGPIO & 0xffff));
143
    if ( set_bits_set ) {
144
        diag_printf("set(0x%08X) ",set_bits);
145
        ipaq_EGPIO( set_bits, set_bits );
146
    }
147
    if ( clr_bits_set ) {
148
        diag_printf("clear(0x%08X) ",clr_bits);
149
        ipaq_EGPIO( clr_bits, 0x0000 );
150
    }
151
    diag_printf( "gives 0x%04X\n", (int)(_ipaq_EGPIO & 0xffff));
152
}
153
 
154
static void
155
do_mem(int argc, char *argv[]) {
156
    struct option_info opts[3];
157
    bool mem_half_word, mem_byte;
158
    static int address = 0x00000000;
159
    int value;
160
    init_opts(&opts[0], 'b', false, OPTION_ARG_TYPE_FLG,
161
              (void**)&mem_byte, 0, "write a byte");
162
    init_opts(&opts[1], 'h', false, OPTION_ARG_TYPE_FLG,
163
              (void**)&mem_half_word, 0, "write a half-word");
164
    init_opts(&opts[2], 'a', true, OPTION_ARG_TYPE_NUM,
165
              (void**)&address, NULL, "address to write at");
166
    if (!scan_opts(argc, argv, 1, opts, 3, (void*)&value, OPTION_ARG_TYPE_NUM, "address to set"))
167
        return;
168
    if ( mem_byte && mem_half_word ) {
169
        diag_printf("*ERR: Should not specify both byte and half-word access\n");
170
    } else if ( mem_byte ) {
171
        *(cyg_uint8*)address = (cyg_uint8)(value & 255);
172
        diag_printf("  Set 0x%08X to 0x%02X (result 0x%02X)\n", address, value & 255, (int)*(cyg_uint8*)address );
173
    } else if ( mem_half_word ) {
174
        if ( address & 1 ) {
175
            diag_printf( "*ERR: Badly aligned address 0x%08X for half-word store\n", address );
176
        } else {
177
            *(cyg_uint16*)address = (cyg_uint16)(value & 0xffff);
178
            diag_printf("  Set 0x%08X to 0x%04X (result 0x%04X)\n", address, value & 0xffff, (int)*(cyg_uint16*)address );
179
        }
180
    } else {
181
        if ( address & 3 ) {
182
            diag_printf( "*ERR: Badly aligned address 0x%08X for word store\n", address );
183
        } else {
184
            *(cyg_uint32*)address = (cyg_uint32)value;
185
            diag_printf("  Set 0x%08X to 0x%08X (result 0x%08X)\n", address, value, (int)*(cyg_uint32*)address );
186
        }
187
    }
188
}
189
 
190
static void
191
do_physaddr(int argc, char *argv[]) {
192
    unsigned long phys_addr, virt_addr;
193
 
194
    if ( !scan_opts(argc,argv,1,0,0,(void*)&virt_addr, OPTION_ARG_TYPE_NUM, "virtual address") )
195
        return;
196
    phys_addr = hal_virt_to_phys_address(virt_addr);
197
    diag_printf("Virtual addr %p = physical addr %p\n", virt_addr, phys_addr);
198
}
199
 
200
// Get here when RedBoot is idle.  If it's been long enough, then
201
// dim the LCD.  The problem is - how to determine other activities
202
// so at this doesn't get in the way.  In the default case, this will
203
// be called from RedBoot every 10ms (CYGNUM_REDBOOT_CLI_IDLE_TIMEOUT)
204
 
205
#define MAX_IDLE_TIME (30*100)
206
#ifdef CYGSEM_IPAQ_LCD_COMM
207
extern void lcd_on(bool);
208
#endif
209
 
210
static void
211
idle(bool is_idle)
212
{
213
    static int idle_time = 0;
214
    static bool was_idled = false;
215
 
216
    if (is_idle) {
217
        if (!was_idled) {
218
            if (++idle_time == MAX_IDLE_TIME) {
219
                was_idled = true;
220
#ifdef CYGSEM_IPAQ_LCD_COMM
221
                lcd_on(false);
222
#endif
223
            }
224
        }
225
    } else {
226
        idle_time = 0;
227
        if (was_idled) {
228
            was_idled = false;
229
#ifdef CYGSEM_IPAQ_LCD_COMM
230
                lcd_on(true);
231
#endif
232
        }
233
    }
234
}
235
 
236
RedBoot_idle(idle, RedBoot_AFTER_NETIO);

powered by: WebSVN 2.1.0

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