fix building on w32.
[Rockbox.git] / bootloader / telechips.c
blobd5239d18639370a2dfa6f3474b5f8933d3813c55
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 * All files in this archive are subject to the GNU General Public License.
15 * See the file COPYING in the source tree root for full license agreement.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #include "config.h"
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <string.h>
26 #include "cpu.h"
27 #include "system.h"
28 #include "lcd.h"
29 #include "kernel.h"
30 #include "thread.h"
31 #include "ata.h"
32 #include "fat.h"
33 #include "disk.h"
34 #include "font.h"
35 #include "button.h"
36 #include "adc.h"
37 #include "adc-target.h"
38 #include "backlight.h"
39 #include "backlight-target.h"
40 #include "panic.h"
41 #include "power.h"
42 #include "file.h"
43 #include "common.h"
45 #if defined(COWON_D2)
46 #include "pcf50606.h"
47 #define LOAD_ADDRESS 0x20000000 /* DRAM_START */
48 #endif
50 char version[] = APPSVERSION;
52 extern int line;
54 #define MAX_LOAD_SIZE (8*1024*1024) /* Arbitrary, but plenty. */
56 /* The following function is just test/development code */
57 #ifdef CPU_TCC77X
58 void show_debug_screen(void)
60 int button;
61 int power_count = 0;
62 int count = 0;
63 bool do_power_off = false;
65 /*lcd_puts_scroll(0,0,"this is a very long line to test scrolling");*/
66 while(!do_power_off) {
68 line = 1;
69 button = button_get(false);
71 /* Power-off if POWER button has been held for a long time
72 This loop is currently running at about 100 iterations/second
74 if (button & POWEROFF_BUTTON) {
75 power_count++;
76 if (power_count > 200)
77 do_power_off = true;
78 } else {
79 power_count = 0;
82 if (button & BUTTON_SELECT){
83 _backlight_off();
85 else{
86 _backlight_on();
89 /*printf("Btn: 0x%08x",button);
90 printf("Tick: %d",current_tick);
91 printf("GPIOA: 0x%08x",GPIOA);
92 printf("GPIOB: 0x%08x",GPIOB);
93 printf("GPIOC: 0x%08x",GPIOC);
94 printf("GPIOD: 0x%08x",GPIOD);
95 printf("GPIOE: 0x%08x",GPIOE);*/
97 #if 0
98 int i;
99 for (i = 1; i<4; i++)
101 printf("ADC%d: 0x%04x",i,adc_read(i));
103 #endif
104 count++;
105 printf("Count: %d",count);
106 sleep(HZ/10);
110 lcd_clear_display();
111 line = 0;
112 printf("POWER-OFF");
114 /* Power-off */
115 power_off();
117 printf("(NOT) POWERED OFF");
118 while (true);
121 #else /* !CPU_TCC77X */
122 void show_debug_screen(void)
124 int button;
125 int power_count = 0;
126 int count = 0;
127 bool do_power_off = false;
128 #ifdef HAVE_BUTTON_DATA
129 unsigned int data;
130 #endif
132 while(!do_power_off) {
133 line = 0;
134 printf("Hello World!");
136 #ifdef HAVE_BUTTON_DATA
137 button = button_read_device(&data);
138 #else
139 button = button_read_device();
140 #endif
142 /* Power-off if POWER button has been held for a long time
143 This loop is currently running at about 100 iterations/second
145 if (button & POWEROFF_BUTTON) {
146 power_count++;
147 if (power_count > 200)
148 do_power_off = true;
149 } else {
150 power_count = 0;
153 printf("Btn: 0x%08x",button);
155 count++;
156 printf("Count: %d",count);
159 lcd_clear_display();
160 line = 0;
161 printf("POWER-OFF");
163 /* Power-off */
164 power_off();
166 printf("(NOT) POWERED OFF");
167 while (true);
169 #endif
171 void* main(void)
173 #if defined(COWON_D2) && defined(TCCBOOT)
174 int rc;
175 unsigned char* loadbuffer = (unsigned char*)LOAD_ADDRESS;
176 #endif
178 power_init();
179 system_init();
180 #ifndef COWON_D2
181 /* The D2 doesn't enable threading or interrupts */
182 kernel_init();
183 enable_irq();
184 #endif
185 lcd_init();
187 adc_init();
188 button_init();
189 backlight_init();
191 font_init();
192 lcd_setfont(FONT_SYSFIXED);
194 _backlight_on();
196 /* Only load the firmware if TCCBOOT is defined - this ensures SDRAM_START is
197 available for loading the firmware. Otherwise display the debug screen. */
198 #if defined(COWON_D2) && defined(TCCBOOT)
199 printf("Rockbox boot loader");
200 printf("Version %s", version);
202 printf("ATA");
203 rc = ata_init();
204 if(rc)
206 reset_screen();
207 error(EATA, rc);
210 printf("mount");
211 rc = disk_mount_all();
212 if (rc<=0)
214 error(EDISK,rc);
217 rc = load_firmware(loadbuffer, BOOTFILE, MAX_LOAD_SIZE);
219 if (rc < 0)
221 error(EBOOTFILE,rc);
223 else if (rc == EOK)
225 int(*kernel_entry)(void);
227 kernel_entry = (void*) loadbuffer;
228 rc = kernel_entry();
230 #else
231 show_debug_screen();
232 #endif
234 return 0;
237 /* These functions are present in the firmware library, but we reimplement
238 them here because the originals do a lot more than we want */
239 void usb_acknowledge(void)
243 void usb_wait_for_disconnect(void)