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 struct spinlock boostctrl_spin NOCACHEBSS_ATTR
;
40 void cpu_boost_init(void)
42 spinlock_init(&boostctrl_spin
);
46 int get_cpu_boost_counter(void)
50 #ifdef CPU_BOOST_LOGGING
51 #define MAX_BOOST_LOG 64
52 static char cpu_boost_calls
[MAX_BOOST_LOG
][MAX_PATH
];
53 static int cpu_boost_first
= 0;
54 static int cpu_boost_calls_count
= 0;
55 static int cpu_boost_track_message
= 0;
56 int cpu_boost_log_getcount(void)
58 return cpu_boost_calls_count
;
60 char * cpu_boost_log_getlog_first(void)
64 spinlock_lock(&boostctrl_spin
);
69 if (cpu_boost_calls_count
)
71 cpu_boost_track_message
= 1;
72 first
= cpu_boost_calls
[cpu_boost_first
];
76 spinlock_unlock(&boostctrl_spin
);
82 char * cpu_boost_log_getlog_next(void)
88 spinlock_lock(&boostctrl_spin
);
91 message
= (cpu_boost_track_message
+cpu_boost_first
)%MAX_BOOST_LOG
;
94 if (cpu_boost_track_message
< cpu_boost_calls_count
)
96 cpu_boost_track_message
++;
97 next
= cpu_boost_calls
[message
];
101 spinlock_unlock(&boostctrl_spin
);
107 void cpu_boost_(bool on_off
, char* location
, int line
)
110 spinlock_lock(&boostctrl_spin
);
113 if (cpu_boost_calls_count
== MAX_BOOST_LOG
)
115 cpu_boost_first
= (cpu_boost_first
+1)%MAX_BOOST_LOG
;
116 cpu_boost_calls_count
--;
117 if (cpu_boost_calls_count
< 0)
118 cpu_boost_calls_count
= 0;
120 if (cpu_boost_calls_count
< MAX_BOOST_LOG
)
122 int message
= (cpu_boost_first
+cpu_boost_calls_count
)%MAX_BOOST_LOG
;
123 snprintf(cpu_boost_calls
[message
], MAX_PATH
,
124 "%c %s:%d",on_off
==true?'B':'U',location
,line
);
125 cpu_boost_calls_count
++;
128 void cpu_boost(bool on_off
)
131 spinlock_lock(&boostctrl_spin
);
134 #endif /* CPU_BOOST_LOGGING */
137 /* Boost the frequency if not already boosted */
138 if(++boost_counter
== 1)
139 set_cpu_frequency(CPUFREQ_MAX
);
143 /* Lower the frequency if the counter reaches 0 */
144 if(--boost_counter
<= 0)
147 set_cpu_frequency(CPUFREQ_DEFAULT
);
149 set_cpu_frequency(CPUFREQ_NORMAL
);
152 if (boost_counter
< 0)
160 spinlock_unlock(&boostctrl_spin
);
164 void cpu_idle_mode(bool on_off
)
167 spinlock_lock(&boostctrl_spin
);
172 /* We need to adjust the frequency immediately if the CPU
174 if(boost_counter
== 0)
177 set_cpu_frequency(CPUFREQ_DEFAULT
);
179 set_cpu_frequency(CPUFREQ_NORMAL
);
183 spinlock_unlock(&boostctrl_spin
);
186 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
189 #ifdef HAVE_FLASHED_ROCKBOX
190 static bool detect_flash_header(uint8_t *addr
)
193 int oldmode
= system_memory_guard(MEMGUARD_NONE
);
195 struct flash_header hdr
;
196 memcpy(&hdr
, addr
, sizeof(struct flash_header
));
198 system_memory_guard(oldmode
);
200 return hdr
.magic
== FLASH_MAGIC
;
204 bool detect_flashed_romimage(void)
206 #ifdef HAVE_FLASHED_ROCKBOX
207 return detect_flash_header((uint8_t *)FLASH_ROMIMAGE_ENTRY
);
210 #endif /* HAVE_FLASHED_ROCKBOX */
213 bool detect_flashed_ramimage(void)
215 #ifdef HAVE_FLASHED_ROCKBOX
216 return detect_flash_header((uint8_t *)FLASH_RAMIMAGE_ENTRY
);
219 #endif /* HAVE_FLASHED_ROCKBOX */
222 bool detect_original_firmware(void)
224 return !(detect_flashed_ramimage() || detect_flashed_romimage());
229 static const char* const uiename
[] = {
230 "Undefined instruction",
236 /* Unexpected Interrupt or Exception handler. Currently only deals with
237 exceptions, but will deal with interrupts later.
239 void UIE(unsigned int pc
, unsigned int num
) __attribute__((noreturn
));
240 void UIE(unsigned int pc
, unsigned int num
)
245 #ifdef HAVE_LCD_BITMAP
246 lcd_setfont(FONT_SYSFIXED
);
248 lcd_puts(0, 0, uiename
[num
]);
249 snprintf(str
, sizeof(str
), "at %08x" IF_COP(" (%d)"), pc
250 IF_COP(, CURRENT_CORE
));
256 /* TODO: perhaps add button handling in here when we get a polling
264 /* Needs to be here or gcc won't find it */
265 void __div0(void) __attribute__((naked
));
277 void reference_system_c(void)