1 //==========================================================================
5 // TRITON [platform] specific RedBoot commands
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.
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.
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.
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.
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.
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.
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####
44 // Contributors: gthomas
45 // Richard Panton <richard.panton@3glab.com>
50 // This code is part of RedBoot (tm).
52 //####DESCRIPTIONEND####
54 //==========================================================================
58 #include <cyg/hal/hal_triton.h>
59 #include <cyg/hal/hal_intr.h>
60 #include <cyg/hal/hal_cache.h>
62 // Exported CLI function(s)
66 #define CCCR_MEMCLK_99 0x00000001
67 #define CCCR_MEMCLK_117 0x00000002
68 #define CCCR_MEMCLK_132 0x00000003
69 #define CCCR_MEMCLK_147 0x00000004
70 #define CCCR_MEMCLK_165 0x00000005
72 #define CCCR_RUN_EQ_MEM 0x00000020
73 #define CCCR_RUN_2T_MEM 0x00000040
75 #define CCCR_TURBO_10 0x00000100
76 #define CCCR_TURBO_15 0x00000180
77 #define CCCR_TURBO_20 0x00000200
78 #define CCCR_TURBO_30 0x00000300
83 "Set a memory location",
84 "[-h|-b] [-a <address>] <data>",
88 void do_mem(int argc, char *argv[])
90 struct option_info opts[3];
91 bool mem_half_word, mem_byte;
92 volatile cyg_uint32 *address = NULL;
95 init_opts(&opts[0], 'b', false, OPTION_ARG_TYPE_FLG,
96 (void *)&mem_byte, 0, "write a byte");
97 init_opts(&opts[1], 'h', false, OPTION_ARG_TYPE_FLG,
98 (void *)&mem_half_word, 0, "write a half-word");
99 init_opts(&opts[2], 'a', true, OPTION_ARG_TYPE_NUM,
100 (void *)&address, NULL, "address to write at");
101 if (!scan_opts(argc, argv, 1, opts, 3, (void *)&value, OPTION_ARG_TYPE_NUM, "address to set"))
103 if (mem_byte && mem_half_word) {
104 diag_printf("*ERR: Should not specify both byte and half-word access\n");
105 } else if (mem_byte) {
106 *(cyg_uint8*)address = (cyg_uint8)(value & 255);
107 diag_printf(" Set 0x%08X to 0x%02X (result 0x%02X)\n", address, value & 255, (int)*(cyg_uint8*)address);
108 } else if (mem_half_word) {
109 if ((unsigned long)address & 1) {
110 diag_printf("*ERR: Badly aligned address 0x%08X for half-word store\n", address);
112 *(cyg_uint16*)address = (cyg_uint16)(value & 0xffff);
113 diag_printf(" Set 0x%08X to 0x%04X (result 0x%04X)\n", address, value & 0xffff, (int)*(cyg_uint16*)address);
116 if ((unsigned long)address & 3) {
117 diag_printf("*ERR: Badly aligned address 0x%08X for word store\n", address);
120 diag_printf(" Set 0x%08X to 0x%08X (result 0x%08X)\n", address, value,
127 "Set/Query the system clock speed",
132 int get_clock_rate(void) {
134 unsigned long CCCR_reg, CCLKCFG_reg;
138 "ldr r1, =0x41300000;" // Core Clock Config Reg
140 "mrc p14, 0, %1, c6, c0, 0;" // read CCLKCFG register
141 : "=r"(CCCR_reg), "=r"(CCLKCFG_reg)
146 CCCR_reg &= 0x3ff; // blank reserved bits
148 if (!(CCLKCFG_reg & 1)) { // we do not stay in turbo mode
149 CCCR_reg &= 0x7f; // delete turbo information
151 case (CCCR_MEMCLK_99 | CCCR_RUN_EQ_MEM):
154 case (CCCR_MEMCLK_99 | CCCR_RUN_2T_MEM):
160 } else { // we stay in turbo mode
162 case (CCCR_MEMCLK_99 | CCCR_RUN_2T_MEM | CCCR_TURBO_15):
165 case (CCCR_MEMCLK_99 | CCCR_RUN_2T_MEM | CCCR_TURBO_20):
173 void do_clock(int argc, char *argv[])
176 bool new_clock_set, clock_ok;
177 struct option_info opts[1];
178 //#ifdef CYGSEM_REDBOOT_FLASH_CONFIG
179 // struct config_option opt;
183 init_opts(&opts[0], 's', true, OPTION_ARG_TYPE_NUM,
184 (void *)&new_clock, (bool *)&new_clock_set, "new clock speed");
185 if (!scan_opts(argc, argv, 1, opts, 1, 0, 0, "")) {
190 diag_printf("Clock speed will be changed to %d MHz\n", new_clock);
196 reg = CCCR_MEMCLK_99 | CCCR_RUN_EQ_MEM | CCCR_TURBO_10;
199 "ldr r2, =0x41300000;" // Core Clock Config Reg
200 "str r1, [r2];" // set speed
201 "mov r1, #0x2;" // no turbo mode
202 "mcr p14, 0, r1, c6, c0, 0;" // frequency change sequence
209 reg = CCCR_MEMCLK_99 | CCCR_RUN_2T_MEM | CCCR_TURBO_10;
212 "ldr r2, =0x41300000;" // Core Clock Config Reg
213 "str r1, [r2];" // set speed
214 "mov r1, #0x2;" // no turbo mode
215 "mcr p14, 0, r1, c6, c0, 0;" // frequency change sequence
222 reg = CCCR_MEMCLK_99 | CCCR_RUN_2T_MEM | CCCR_TURBO_15;
225 "ldr r2, =0x41300000;" // Core Clock Config Reg
226 "str r1, [r2];" // set speed
227 "mov r1, #0x3;" // set turbo mode
228 "mcr p14, 0, r1, c6, c0, 0;" // frequency change sequence
235 reg = CCCR_MEMCLK_99 | CCCR_RUN_2T_MEM | CCCR_TURBO_20;
238 "ldr r2, =0x41300000;" // Core Clock Config Reg
239 "str r1, [r2];" // set speed
240 "mov r1, #0x3;" // set turbo mode
241 "mcr p14, 0, r1, c6, c0, 0;" // frequency change sequence
249 diag_printf("\ndon't know how to install %d MHz, keeping clock speed at %d MHz\n\n", new_clock, get_clock_rate());
252 diag_printf("\nclock speed set to %d MHz ...\n", new_clock);
255 //#ifdef CYGSEM_REDBOOT_FLASH_CONFIG
256 // opt.type = CONFIG_INT;
257 // opt.enable = (char *)0;
258 // opt.enable_sense = 1;
259 // opt.key = "console_baud_rate";
260 // opt.dflt = new_rate;
261 // flash_add_config(&opt, true);
264 ret = get_clock_rate();
265 diag_printf("Clock = ");
267 diag_printf("unknown\n");
269 diag_printf("%d\n", ret);
275 "Execute code at a location",
276 "[-w <timeout>] [entry]",
280 void do_run(int argc, char *argv[])
282 typedef void code_fun(void);
284 unsigned long oldints;
288 struct option_info opts[1];
291 entry = entry_address; // Default from last 'load' operation
292 init_opts(&opts[0], 'w', true, OPTION_ARG_TYPE_NUM,
293 (void *)&wait_time, (bool *)&wait_time_set, "wait timeout");
294 if (!scan_opts(argc, argv, 1, opts, 1, (void *)&entry, OPTION_ARG_TYPE_NUM,
295 "starting address")) {
297 diag_printf("starting run at address 0x%08X ...\n", entry);
300 int script_timeout_ms = wait_time * 1000;
301 #ifdef CYGSEM_REDBOOT_FLASH_CONFIG
302 unsigned char *hold_script = script;
303 script = (unsigned char *)0;
305 diag_printf("About to start execution at %p - abort with ^C within %d seconds\n",
306 (void *)entry, wait_time);
307 while (script_timeout_ms >= CYGNUM_REDBOOT_CLI_IDLE_TIMEOUT) {
308 res = _rb_gets(line, sizeof(line), CYGNUM_REDBOOT_CLI_IDLE_TIMEOUT);
309 if (res == _GETS_CTRLC) {
310 #ifdef CYGSEM_REDBOOT_FLASH_CONFIG
311 script = hold_script; // Re-enable script
315 script_timeout_ms -= CYGNUM_REDBOOT_CLI_IDLE_TIMEOUT;
318 fun = (code_fun *)entry;
319 HAL_DISABLE_INTERRUPTS(oldints);
321 HAL_ICACHE_DISABLE();
322 HAL_DCACHE_DISABLE();
324 HAL_ICACHE_INVALIDATE_ALL();
325 HAL_DCACHE_INVALIDATE_ALL();
326 #ifdef HAL_ARCH_PROGRAM_NEW_STACK
327 HAL_ARCH_PROGRAM_NEW_STACK(fun);
333 HAL_RESTORE_INTERRUPTS(oldints);