1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 by Alan Korr
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
32 long cpu_frequency NOCACHEBSS_ATTR
= CPU_FREQ
;
35 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
36 static int boost_counter NOCACHEBSS_ATTR
= 0;
37 static bool cpu_idle NOCACHEBSS_ATTR
= false;
39 int get_cpu_boost_counter(void)
43 #ifdef CPU_BOOST_LOGGING
44 #define MAX_BOOST_LOG 64
45 static char cpu_boost_calls
[MAX_BOOST_LOG
][MAX_PATH
];
46 static int cpu_boost_first
= 0;
47 static int cpu_boost_calls_count
= 0;
48 static int cpu_boost_track_message
= 0;
49 int cpu_boost_log_getcount(void)
51 return cpu_boost_calls_count
;
53 char * cpu_boost_log_getlog_first(void)
55 if (cpu_boost_calls_count
)
57 cpu_boost_track_message
= 1;
58 return cpu_boost_calls
[cpu_boost_first
];
62 char * cpu_boost_log_getlog_next(void)
64 int message
= (cpu_boost_track_message
+cpu_boost_first
)%MAX_BOOST_LOG
;
65 if (cpu_boost_track_message
< cpu_boost_calls_count
)
67 cpu_boost_track_message
++;
68 return cpu_boost_calls
[message
];
72 void cpu_boost_(bool on_off
, char* location
, int line
)
74 if (cpu_boost_calls_count
== MAX_BOOST_LOG
)
76 cpu_boost_first
= (cpu_boost_first
+1)%MAX_BOOST_LOG
;
77 cpu_boost_calls_count
--;
78 if (cpu_boost_calls_count
< 0)
79 cpu_boost_calls_count
= 0;
81 if (cpu_boost_calls_count
< MAX_BOOST_LOG
)
83 int message
= (cpu_boost_first
+cpu_boost_calls_count
)%MAX_BOOST_LOG
;
84 snprintf(cpu_boost_calls
[message
], MAX_PATH
,
85 "%c %s:%d",on_off
==true?'B':'U',location
,line
);
86 cpu_boost_calls_count
++;
89 void cpu_boost(bool on_off
)
94 /* Boost the frequency if not already boosted */
95 if(boost_counter
++ == 0)
96 set_cpu_frequency(CPUFREQ_MAX
);
100 /* Lower the frequency if the counter reaches 0 */
101 if(--boost_counter
== 0)
104 set_cpu_frequency(CPUFREQ_DEFAULT
);
106 set_cpu_frequency(CPUFREQ_NORMAL
);
110 if(boost_counter
< 0)
115 void cpu_idle_mode(bool on_off
)
119 /* We need to adjust the frequency immediately if the CPU
121 if(boost_counter
== 0)
124 set_cpu_frequency(CPUFREQ_DEFAULT
);
126 set_cpu_frequency(CPUFREQ_NORMAL
);
129 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
132 #ifdef HAVE_FLASHED_ROCKBOX
133 static bool detect_flash_header(uint8_t *addr
)
136 int oldmode
= system_memory_guard(MEMGUARD_NONE
);
138 struct flash_header hdr
;
139 memcpy(&hdr
, addr
, sizeof(struct flash_header
));
141 system_memory_guard(oldmode
);
143 return hdr
.magic
== FLASH_MAGIC
;
147 bool detect_flashed_romimage(void)
149 #ifdef HAVE_FLASHED_ROCKBOX
150 return detect_flash_header((uint8_t *)FLASH_ROMIMAGE_ENTRY
);
153 #endif /* HAVE_FLASHED_ROCKBOX */
156 bool detect_flashed_ramimage(void)
158 #ifdef HAVE_FLASHED_ROCKBOX
159 return detect_flash_header((uint8_t *)FLASH_RAMIMAGE_ENTRY
);
162 #endif /* HAVE_FLASHED_ROCKBOX */
165 bool detect_original_firmware(void)
167 return !(detect_flashed_ramimage() || detect_flashed_romimage());
172 static const char* const uiename
[] = {
173 "Undefined instruction", "Prefetch abort", "Data abort"
176 /* Unexpected Interrupt or Exception handler. Currently only deals with
177 exceptions, but will deal with interrupts later.
179 void UIE(unsigned int pc
, unsigned int num
)
184 #ifdef HAVE_LCD_BITMAP
185 lcd_setfont(FONT_SYSFIXED
);
187 lcd_puts(0, 0, uiename
[num
]);
188 snprintf(str
, sizeof(str
), "at %08x", pc
);
194 /* TODO: perhaps add button handling in here when we get a polling