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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [arm/] [sa11x0/] [ipaq/] [current/] [src/] [redboot_cmds.c] - Blame information for rev 856

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

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