Dave Chapman | 28f6ae4 | 2007-10-28 11:08:10 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2007 by Dave Chapman |
| 11 | * |
| 12 | * Based on Rockbox iriver bootloader by Linus Nielsen Feltzing |
| 13 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame] | 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. |
Dave Chapman | 28f6ae4 | 2007-10-28 11:08:10 +0000 | [diff] [blame] | 18 | * |
| 19 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 20 | * KIND, either express or implied. |
| 21 | * |
| 22 | ****************************************************************************/ |
| 23 | #include "config.h" |
| 24 | |
| 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 "ata.h" |
| 34 | #include "fat.h" |
| 35 | #include "disk.h" |
| 36 | #include "font.h" |
Dave Chapman | a4d48d0 | 2007-11-01 23:38:57 +0000 | [diff] [blame] | 37 | #include "button.h" |
Dave Chapman | 28f6ae4 | 2007-10-28 11:08:10 +0000 | [diff] [blame] | 38 | #include "adc.h" |
| 39 | #include "adc-target.h" |
Rob Purchase | 3b46671 | 2008-03-29 17:26:16 +0000 | [diff] [blame] | 40 | #include "backlight.h" |
Dave Chapman | 28f6ae4 | 2007-10-28 11:08:10 +0000 | [diff] [blame] | 41 | #include "backlight-target.h" |
| 42 | #include "panic.h" |
| 43 | #include "power.h" |
| 44 | #include "file.h" |
| 45 | #include "common.h" |
| 46 | |
Rob Purchase | 47ea030 | 2008-01-14 22:04:48 +0000 | [diff] [blame] | 47 | #if defined(COWON_D2) |
Rob Purchase | f4deea6 | 2008-04-08 08:01:18 +0000 | [diff] [blame] | 48 | #include "pcf50606.h" |
Rob Purchase | c883611 | 2008-03-12 20:57:19 +0000 | [diff] [blame] | 49 | #define LOAD_ADDRESS 0x20000000 /* DRAM_START */ |
Rob Purchase | 47ea030 | 2008-01-14 22:04:48 +0000 | [diff] [blame] | 50 | #endif |
| 51 | |
Dave Chapman | 28f6ae4 | 2007-10-28 11:08:10 +0000 | [diff] [blame] | 52 | char version[] = APPSVERSION; |
| 53 | |
| 54 | extern int line; |
| 55 | |
Rob Purchase | c883611 | 2008-03-12 20:57:19 +0000 | [diff] [blame] | 56 | #define MAX_LOAD_SIZE (8*1024*1024) /* Arbitrary, but plenty. */ |
| 57 | |
Dave Chapman | f204298 | 2008-05-02 19:12:09 +0000 | [diff] [blame] | 58 | /* The following function is just test/development code */ |
| 59 | #ifdef CPU_TCC77X |
| 60 | void show_debug_screen(void) |
| 61 | { |
| 62 | int button; |
| 63 | int power_count = 0; |
| 64 | int count = 0; |
| 65 | bool do_power_off = false; |
Marc Guay | b93667b | 2008-06-21 15:18:36 +0000 | [diff] [blame] | 66 | |
| 67 | /*lcd_puts_scroll(0,0,"this is a very long line to test scrolling");*/ |
Dave Chapman | f204298 | 2008-05-02 19:12:09 +0000 | [diff] [blame] | 68 | while(!do_power_off) { |
Marc Guay | b93667b | 2008-06-21 15:18:36 +0000 | [diff] [blame] | 69 | |
Dave Chapman | f204298 | 2008-05-02 19:12:09 +0000 | [diff] [blame] | 70 | line = 1; |
| 71 | button = button_get(false); |
Marc Guay | b93667b | 2008-06-21 15:18:36 +0000 | [diff] [blame] | 72 | |
Marc Guay | f6cde72 | 2008-07-06 21:32:59 +0000 | [diff] [blame] | 73 | /* Power-off if POWER button has been held for a time |
Dave Chapman | f204298 | 2008-05-02 19:12:09 +0000 | [diff] [blame] | 74 | This loop is currently running at about 100 iterations/second |
| 75 | */ |
| 76 | if (button & POWEROFF_BUTTON) { |
| 77 | power_count++; |
Marc Guay | f6cde72 | 2008-07-06 21:32:59 +0000 | [diff] [blame] | 78 | if (power_count > 100) |
Dave Chapman | f204298 | 2008-05-02 19:12:09 +0000 | [diff] [blame] | 79 | do_power_off = true; |
| 80 | } else { |
| 81 | power_count = 0; |
| 82 | } |
Marc Guay | b93667b | 2008-06-21 15:18:36 +0000 | [diff] [blame] | 83 | |
| 84 | if (button & BUTTON_SELECT){ |
| 85 | _backlight_off(); |
| 86 | } |
| 87 | else{ |
| 88 | _backlight_on(); |
| 89 | } |
| 90 | |
| 91 | /*printf("Btn: 0x%08x",button); |
Dave Chapman | f204298 | 2008-05-02 19:12:09 +0000 | [diff] [blame] | 92 | printf("Tick: %d",current_tick); |
Dave Chapman | f204298 | 2008-05-02 19:12:09 +0000 | [diff] [blame] | 93 | printf("GPIOA: 0x%08x",GPIOA); |
| 94 | printf("GPIOB: 0x%08x",GPIOB); |
| 95 | printf("GPIOC: 0x%08x",GPIOC); |
| 96 | printf("GPIOD: 0x%08x",GPIOD); |
Marc Guay | b93667b | 2008-06-21 15:18:36 +0000 | [diff] [blame] | 97 | printf("GPIOE: 0x%08x",GPIOE);*/ |
Dave Chapman | f204298 | 2008-05-02 19:12:09 +0000 | [diff] [blame] | 98 | |
| 99 | #if 0 |
| 100 | int i; |
Marc Guay | b93667b | 2008-06-21 15:18:36 +0000 | [diff] [blame] | 101 | for (i = 1; i<4; i++) |
Dave Chapman | f204298 | 2008-05-02 19:12:09 +0000 | [diff] [blame] | 102 | { |
| 103 | printf("ADC%d: 0x%04x",i,adc_read(i)); |
| 104 | } |
| 105 | #endif |
| 106 | count++; |
| 107 | printf("Count: %d",count); |
| 108 | sleep(HZ/10); |
| 109 | |
| 110 | } |
| 111 | |
| 112 | lcd_clear_display(); |
| 113 | line = 0; |
| 114 | printf("POWER-OFF"); |
| 115 | |
| 116 | /* Power-off */ |
| 117 | power_off(); |
| 118 | |
| 119 | printf("(NOT) POWERED OFF"); |
| 120 | while (true); |
Marc Guay | b93667b | 2008-06-21 15:18:36 +0000 | [diff] [blame] | 121 | |
Dave Chapman | f204298 | 2008-05-02 19:12:09 +0000 | [diff] [blame] | 122 | } |
| 123 | #else /* !CPU_TCC77X */ |
Rob Purchase | 3b46671 | 2008-03-29 17:26:16 +0000 | [diff] [blame] | 124 | void show_debug_screen(void) |
Dave Chapman | 28f6ae4 | 2007-10-28 11:08:10 +0000 | [diff] [blame] | 125 | { |
Dave Chapman | a4d48d0 | 2007-11-01 23:38:57 +0000 | [diff] [blame] | 126 | int button; |
| 127 | int power_count = 0; |
| 128 | int count = 0; |
| 129 | bool do_power_off = false; |
Rob Purchase | 18b004b | 2008-04-27 13:30:11 +0000 | [diff] [blame] | 130 | #ifdef HAVE_BUTTON_DATA |
| 131 | unsigned int data; |
| 132 | #endif |
Rob Purchase | 3b46671 | 2008-03-29 17:26:16 +0000 | [diff] [blame] | 133 | |
| 134 | while(!do_power_off) { |
| 135 | line = 0; |
| 136 | printf("Hello World!"); |
| 137 | |
Rob Purchase | 18b004b | 2008-04-27 13:30:11 +0000 | [diff] [blame] | 138 | #ifdef HAVE_BUTTON_DATA |
| 139 | button = button_read_device(&data); |
| 140 | #else |
Rob Purchase | 3b46671 | 2008-03-29 17:26:16 +0000 | [diff] [blame] | 141 | button = button_read_device(); |
Rob Purchase | 18b004b | 2008-04-27 13:30:11 +0000 | [diff] [blame] | 142 | #endif |
Rob Purchase | 3b46671 | 2008-03-29 17:26:16 +0000 | [diff] [blame] | 143 | |
| 144 | /* Power-off if POWER button has been held for a long time |
| 145 | This loop is currently running at about 100 iterations/second |
| 146 | */ |
| 147 | if (button & POWEROFF_BUTTON) { |
| 148 | power_count++; |
| 149 | if (power_count > 200) |
| 150 | do_power_off = true; |
| 151 | } else { |
| 152 | power_count = 0; |
| 153 | } |
| 154 | |
| 155 | printf("Btn: 0x%08x",button); |
| 156 | |
Rob Purchase | 3b46671 | 2008-03-29 17:26:16 +0000 | [diff] [blame] | 157 | count++; |
| 158 | printf("Count: %d",count); |
| 159 | } |
| 160 | |
| 161 | lcd_clear_display(); |
| 162 | line = 0; |
| 163 | printf("POWER-OFF"); |
| 164 | |
| 165 | /* Power-off */ |
| 166 | power_off(); |
| 167 | |
| 168 | printf("(NOT) POWERED OFF"); |
| 169 | while (true); |
| 170 | } |
Dave Chapman | f204298 | 2008-05-02 19:12:09 +0000 | [diff] [blame] | 171 | #endif |
Rob Purchase | 3b46671 | 2008-03-29 17:26:16 +0000 | [diff] [blame] | 172 | |
| 173 | void* main(void) |
| 174 | { |
Rob Purchase | c883611 | 2008-03-12 20:57:19 +0000 | [diff] [blame] | 175 | #if defined(COWON_D2) && defined(TCCBOOT) |
| 176 | int rc; |
| 177 | unsigned char* loadbuffer = (unsigned char*)LOAD_ADDRESS; |
Rob Purchase | addb522 | 2008-02-13 23:50:44 +0000 | [diff] [blame] | 178 | #endif |
Dave Chapman | 28f6ae4 | 2007-10-28 11:08:10 +0000 | [diff] [blame] | 179 | |
Rob Purchase | addb522 | 2008-02-13 23:50:44 +0000 | [diff] [blame] | 180 | power_init(); |
Rob Purchase | addb522 | 2008-02-13 23:50:44 +0000 | [diff] [blame] | 181 | system_init(); |
Dave Chapman | f204298 | 2008-05-02 19:12:09 +0000 | [diff] [blame] | 182 | #ifndef COWON_D2 |
| 183 | /* The D2 doesn't enable threading or interrupts */ |
| 184 | kernel_init(); |
| 185 | enable_irq(); |
| 186 | #endif |
Rob Purchase | 562b9de | 2008-03-05 00:21:56 +0000 | [diff] [blame] | 187 | lcd_init(); |
Rob Purchase | addb522 | 2008-02-13 23:50:44 +0000 | [diff] [blame] | 188 | |
| 189 | adc_init(); |
| 190 | button_init(); |
| 191 | backlight_init(); |
| 192 | |
Dave Chapman | 28f6ae4 | 2007-10-28 11:08:10 +0000 | [diff] [blame] | 193 | font_init(); |
Rob Purchase | addb522 | 2008-02-13 23:50:44 +0000 | [diff] [blame] | 194 | lcd_setfont(FONT_SYSFIXED); |
| 195 | |
Jens Arnold | ef12b3b | 2007-11-12 18:49:53 +0000 | [diff] [blame] | 196 | _backlight_on(); |
Dave Chapman | 28f6ae4 | 2007-10-28 11:08:10 +0000 | [diff] [blame] | 197 | |
Rob Purchase | c883611 | 2008-03-12 20:57:19 +0000 | [diff] [blame] | 198 | /* Only load the firmware if TCCBOOT is defined - this ensures SDRAM_START is |
| 199 | available for loading the firmware. Otherwise display the debug screen. */ |
| 200 | #if defined(COWON_D2) && defined(TCCBOOT) |
| 201 | printf("Rockbox boot loader"); |
| 202 | printf("Version %s", version); |
| 203 | |
Rob Purchase | addb522 | 2008-02-13 23:50:44 +0000 | [diff] [blame] | 204 | printf("ATA"); |
| 205 | rc = ata_init(); |
| 206 | if(rc) |
| 207 | { |
| 208 | reset_screen(); |
| 209 | error(EATA, rc); |
| 210 | } |
| 211 | |
| 212 | printf("mount"); |
| 213 | rc = disk_mount_all(); |
| 214 | if (rc<=0) |
| 215 | { |
| 216 | error(EDISK,rc); |
| 217 | } |
| 218 | |
Rob Purchase | c883611 | 2008-03-12 20:57:19 +0000 | [diff] [blame] | 219 | rc = load_firmware(loadbuffer, BOOTFILE, MAX_LOAD_SIZE); |
Rob Purchase | addb522 | 2008-02-13 23:50:44 +0000 | [diff] [blame] | 220 | |
Rob Purchase | c883611 | 2008-03-12 20:57:19 +0000 | [diff] [blame] | 221 | if (rc < 0) |
Rob Purchase | addb522 | 2008-02-13 23:50:44 +0000 | [diff] [blame] | 222 | { |
Rob Purchase | c883611 | 2008-03-12 20:57:19 +0000 | [diff] [blame] | 223 | error(EBOOTFILE,rc); |
Rob Purchase | addb522 | 2008-02-13 23:50:44 +0000 | [diff] [blame] | 224 | } |
Rob Purchase | c883611 | 2008-03-12 20:57:19 +0000 | [diff] [blame] | 225 | else if (rc == EOK) |
Rob Purchase | addb522 | 2008-02-13 23:50:44 +0000 | [diff] [blame] | 226 | { |
Rob Purchase | c883611 | 2008-03-12 20:57:19 +0000 | [diff] [blame] | 227 | int(*kernel_entry)(void); |
| 228 | |
| 229 | kernel_entry = (void*) loadbuffer; |
Rob Purchase | 18b004b | 2008-04-27 13:30:11 +0000 | [diff] [blame] | 230 | rc = kernel_entry(); |
Dave Chapman | 28f6ae4 | 2007-10-28 11:08:10 +0000 | [diff] [blame] | 231 | } |
Rob Purchase | 18b004b | 2008-04-27 13:30:11 +0000 | [diff] [blame] | 232 | #else |
Rob Purchase | 3b46671 | 2008-03-29 17:26:16 +0000 | [diff] [blame] | 233 | show_debug_screen(); |
Rob Purchase | 18b004b | 2008-04-27 13:30:11 +0000 | [diff] [blame] | 234 | #endif |
Rob Purchase | c883611 | 2008-03-12 20:57:19 +0000 | [diff] [blame] | 235 | |
Dave Chapman | 28f6ae4 | 2007-10-28 11:08:10 +0000 | [diff] [blame] | 236 | return 0; |
| 237 | } |
| 238 | |
| 239 | /* These functions are present in the firmware library, but we reimplement |
| 240 | them here because the originals do a lot more than we want */ |
| 241 | void usb_acknowledge(void) |
| 242 | { |
| 243 | } |
| 244 | |
| 245 | void usb_wait_for_disconnect(void) |
| 246 | { |
| 247 | } |