sd.h : avoid namespace collision by prefixing defines with SD_
[kugel-rb.git] / bootloader / telechips.c
blob4d6453244922847816c46c1cb31154982c0b5f98
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2007 by Dave Chapman
12 * Based on Rockbox iriver bootloader by Linus Nielsen Feltzing
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
22 ****************************************************************************/
23 #include "config.h"
25 #include <stdlib.h>
26 #include <stdio.h>
27 #include <string.h>
28 #include "cpu.h"
29 #include "system.h"
30 #include "lcd.h"
31 #include "kernel.h"
32 #include "thread.h"
33 #include "storage.h"
34 #include "fat.h"
35 #include "disk.h"
36 #include "font.h"
37 #include "button.h"
38 #include "adc.h"
39 #include "adc-target.h"
40 #include "backlight.h"
41 #include "backlight-target.h"
42 #include "panic.h"
43 #include "power.h"
44 #include "file.h"
45 #include "common.h"
47 #if defined(COWON_D2) || defined(IAUDIO_7)
48 #include "pcf50606.h"
49 #endif
51 /* Address to load main Rockbox image to */
52 #define LOAD_ADDRESS 0x20000000 /* DRAM_START */
54 char version[] = APPSVERSION;
56 extern int line;
58 #define MAX_LOAD_SIZE (8*1024*1024) /* Arbitrary, but plenty. */
60 /* The following function is just test/development code */
61 #ifdef CPU_TCC77X
62 void show_debug_screen(void)
64 int button;
65 int power_count = 0;
66 int count = 0;
67 bool do_power_off = false;
69 lcd_puts_scroll(0,0,"this is a very long line to test scrolling");
70 while (!do_power_off) {
71 line = 1;
72 button = button_get(false);
74 /* Power-off if POWER button has been held for a time
75 This loop is currently running at about 100 iterations/second
77 if (button & POWEROFF_BUTTON) {
78 power_count++;
79 if (power_count > 100)
80 do_power_off = true;
81 } else {
82 power_count = 0;
84 #if 0
85 if (button & BUTTON_SELECT){
86 _backlight_off();
88 else{
89 _backlight_on();
91 #endif
92 printf("Btn: 0x%08x",button);
93 #if 0
94 printf("Tick: %d",current_tick);
95 printf("GPIOA: 0x%08x",GPIOA);
96 printf("GPIOB: 0x%08x",GPIOB);
97 printf("GPIOC: 0x%08x",GPIOC);
98 printf("GPIOD: 0x%08x",GPIOD);
99 printf("GPIOE: 0x%08x",GPIOE);
100 #endif
102 #if 0
103 int i;
104 for (i = 0; i<4; i++)
106 printf("ADC%d: 0x%04x",i,adc_read(i));
108 #endif
109 count++;
110 printf("Count: %d",count);
111 sleep(HZ/10);
115 lcd_clear_display();
116 line = 0;
117 printf("POWER-OFF");
119 /* Power-off */
120 power_off();
122 printf("(NOT) POWERED OFF");
123 while (true);
126 #else /* !CPU_TCC77X */
128 void show_debug_screen(void)
130 int button;
131 int power_count = 0;
132 int count = 0;
133 bool do_power_off = false;
134 #ifdef HAVE_BUTTON_DATA
135 unsigned int data;
136 #endif
138 while(!do_power_off) {
139 line = 0;
140 printf("Hello World!");
142 #ifdef HAVE_BUTTON_DATA
143 button = button_read_device(&data);
144 #else
145 button = button_read_device();
146 #endif
148 /* Power-off if POWER button has been held for a long time
149 This loop is currently running at about 100 iterations/second
151 if (button & POWEROFF_BUTTON) {
152 power_count++;
153 if (power_count > 200)
154 do_power_off = true;
155 } else {
156 power_count = 0;
159 printf("Btn: 0x%08x",button);
161 count++;
162 printf("Count: %d",count);
165 lcd_clear_display();
166 line = 0;
167 printf("POWER-OFF");
169 /* Power-off */
170 power_off();
172 printf("(NOT) POWERED OFF");
173 while (true);
175 #endif
177 void* main(void)
179 #ifdef TCCBOOT
180 int rc;
181 unsigned char* loadbuffer = (unsigned char*)LOAD_ADDRESS;
182 #endif
184 system_init();
185 power_init();
186 #ifndef COWON_D2
187 /* The D2 doesn't enable threading or interrupts */
188 kernel_init();
189 enable_irq();
190 #endif
191 lcd_init();
193 adc_init();
194 button_init();
195 backlight_init();
197 font_init();
198 lcd_setfont(FONT_SYSFIXED);
200 _backlight_on();
202 /* Only load the firmware if TCCBOOT is defined - this ensures SDRAM_START is
203 available for loading the firmware. Otherwise display the debug screen. */
204 #ifdef TCCBOOT
205 printf("Rockbox boot loader");
206 printf("Version %s", version);
208 printf("ATA");
209 rc = storage_init();
210 if(rc)
212 reset_screen();
213 error(EATA, rc);
216 printf("mount");
217 rc = disk_mount_all();
218 if (rc<=0)
220 error(EDISK,rc);
223 rc = load_firmware(loadbuffer, BOOTFILE, MAX_LOAD_SIZE);
225 if (rc < 0)
227 error(EBOOTFILE,rc);
229 else if (rc == EOK)
231 int(*kernel_entry)(void);
233 kernel_entry = (void*) loadbuffer;
234 rc = kernel_entry();
236 #else
237 show_debug_screen();
238 #endif
240 return 0;
243 #ifndef HAVE_USBSTACK
244 /* These functions are present in the firmware library, but we reimplement
245 them here because the originals do a lot more than we want */
246 void usb_acknowledge(void)
250 void usb_wait_for_disconnect(void)
253 #endif