Stuart Martin | 614acaa | 2002-04-30 19:23:44 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2002 by wavey@wavey.org |
Dominik Riebeling | 551319c | 2008-05-18 16:21:52 +0000 | [diff] [blame] | 11 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame^] | 12 | * This program is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU General Public License |
| 14 | * as published by the Free Software Foundation; either version 2 |
| 15 | * of the License, or (at your option) any later version. |
Stuart Martin | 614acaa | 2002-04-30 19:23:44 +0000 | [diff] [blame] | 16 | * |
| 17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 18 | * KIND, either express or implied. |
| 19 | * |
| 20 | ****************************************************************************/ |
| 21 | |
Linus Nielsen Feltzing | e6c6d22 | 2005-09-12 10:34:27 +0000 | [diff] [blame] | 22 | #include "config.h" |
Stuart Martin | 614acaa | 2002-04-30 19:23:44 +0000 | [diff] [blame] | 23 | #include <stdio.h> |
| 24 | #include <stdarg.h> |
Björn Stenberg | 42510d9 | 2002-11-12 09:04:06 +0000 | [diff] [blame] | 25 | #include <string.h> |
Stuart Martin | 614acaa | 2002-04-30 19:23:44 +0000 | [diff] [blame] | 26 | #include "panic.h" |
Björn Stenberg | 697dd70 | 2002-05-02 14:05:51 +0000 | [diff] [blame] | 27 | #include "lcd.h" |
Daniel Stenberg | 93b231c | 2002-09-12 13:33:59 +0000 | [diff] [blame] | 28 | #include "font.h" |
Stuart Martin | 614acaa | 2002-04-30 19:23:44 +0000 | [diff] [blame] | 29 | #include "debug.h" |
Björn Stenberg | 42510d9 | 2002-11-12 09:04:06 +0000 | [diff] [blame] | 30 | #include "led.h" |
Linus Nielsen Feltzing | e6c6d22 | 2005-09-12 10:34:27 +0000 | [diff] [blame] | 31 | #include "power.h" |
| 32 | #include "system.h" |
Stuart Martin | 614acaa | 2002-04-30 19:23:44 +0000 | [diff] [blame] | 33 | |
Björn Stenberg | 6b25f79 | 2002-07-15 11:02:12 +0000 | [diff] [blame] | 34 | static char panic_buf[128]; |
Stuart Martin | 614acaa | 2002-04-30 19:23:44 +0000 | [diff] [blame] | 35 | |
| 36 | /* |
| 37 | * "Dude. This is pretty fucked-up, right here." |
| 38 | */ |
Jens Arnold | c76c568 | 2004-08-16 23:37:23 +0000 | [diff] [blame] | 39 | void panicf( const char *fmt, ...) |
Stuart Martin | 614acaa | 2002-04-30 19:23:44 +0000 | [diff] [blame] | 40 | { |
| 41 | va_list ap; |
Linus Nielsen Feltzing | 6c2accf | 2002-05-05 17:51:23 +0000 | [diff] [blame] | 42 | |
Linus Nielsen Feltzing | 011f1d3 | 2002-05-05 17:52:59 +0000 | [diff] [blame] | 43 | #ifndef SIMULATOR |
Jonathan Gordon | bd47d48 | 2007-02-18 05:07:19 +0000 | [diff] [blame] | 44 | #if (CONFIG_LED == LED_REAL) |
Jens Arnold | f4e7759 | 2006-10-08 21:34:26 +0000 | [diff] [blame] | 45 | bool state = false; |
| 46 | int i = 0; |
Jens Arnold | 5690f78 | 2005-06-04 23:15:52 +0000 | [diff] [blame] | 47 | #endif |
Björn Stenberg | 42510d9 | 2002-11-12 09:04:06 +0000 | [diff] [blame] | 48 | |
Linus Nielsen Feltzing | 6c2accf | 2002-05-05 17:51:23 +0000 | [diff] [blame] | 49 | /* Disable interrupts */ |
Michael Sevakis | bfb281f | 2007-05-12 05:20:04 +0000 | [diff] [blame] | 50 | #ifdef CPU_ARM |
| 51 | disable_fiq(); |
Linus Nielsen Feltzing | 011f1d3 | 2002-05-05 17:52:59 +0000 | [diff] [blame] | 52 | #endif |
Michael Sevakis | bfb281f | 2007-05-12 05:20:04 +0000 | [diff] [blame] | 53 | |
| 54 | set_irq_level(DISABLE_INTERRUPTS); |
| 55 | #endif /* SIMULATOR */ |
Linus Nielsen Feltzing | b2ffaa9 | 2004-11-02 21:43:37 +0000 | [diff] [blame] | 56 | |
Stuart Martin | 614acaa | 2002-04-30 19:23:44 +0000 | [diff] [blame] | 57 | va_start( ap, fmt ); |
Björn Stenberg | 824a003 | 2002-05-02 11:44:15 +0000 | [diff] [blame] | 58 | vsnprintf( panic_buf, sizeof(panic_buf), fmt, ap ); |
Stuart Martin | 614acaa | 2002-04-30 19:23:44 +0000 | [diff] [blame] | 59 | va_end( ap ); |
| 60 | |
Daniel Stenberg | 7a186cb | 2002-05-05 11:17:10 +0000 | [diff] [blame] | 61 | #ifdef HAVE_LCD_CHARCELLS |
Björn Stenberg | b3745a0 | 2002-08-08 15:32:15 +0000 | [diff] [blame] | 62 | lcd_double_height(false); |
Daniel Stenberg | 1a29cfb | 2005-11-25 00:10:12 +0000 | [diff] [blame] | 63 | lcd_puts(0, 0, "*PANIC*"); |
| 64 | lcd_puts(0, 1, panic_buf); |
Daniel Stenberg | 7a186cb | 2002-05-05 11:17:10 +0000 | [diff] [blame] | 65 | #elif defined(HAVE_LCD_BITMAP) |
| 66 | lcd_clear_display(); |
Björn Stenberg | a4c3b03 | 2002-09-24 18:04:15 +0000 | [diff] [blame] | 67 | lcd_setfont(FONT_SYSFIXED); |
Daniel Stenberg | 1a29cfb | 2005-11-25 00:10:12 +0000 | [diff] [blame] | 68 | lcd_puts(0, 0, (unsigned char *)"*PANIC*"); |
Björn Stenberg | 42510d9 | 2002-11-12 09:04:06 +0000 | [diff] [blame] | 69 | { |
| 70 | /* wrap panic line */ |
| 71 | int i, y=1, len = strlen(panic_buf); |
| 72 | for (i=0; i<len; i+=18) { |
| 73 | unsigned char c = panic_buf[i+18]; |
| 74 | panic_buf[i+18] = 0; |
Daniel Stenberg | 1a29cfb | 2005-11-25 00:10:12 +0000 | [diff] [blame] | 75 | lcd_puts(0, y++, (unsigned char *)panic_buf+i); |
Björn Stenberg | 42510d9 | 2002-11-12 09:04:06 +0000 | [diff] [blame] | 76 | panic_buf[i+18] = c; |
| 77 | } |
| 78 | } |
Daniel Stenberg | 7a186cb | 2002-05-05 11:17:10 +0000 | [diff] [blame] | 79 | #else |
| 80 | /* no LCD */ |
| 81 | #endif |
Jens Arnold | f9b90e9 | 2007-04-06 22:55:00 +0000 | [diff] [blame] | 82 | lcd_update(); |
Björn Stenberg | 697dd70 | 2002-05-02 14:05:51 +0000 | [diff] [blame] | 83 | DEBUGF(panic_buf); |
Linus Nielsen Feltzing | e6c6d22 | 2005-09-12 10:34:27 +0000 | [diff] [blame] | 84 | |
| 85 | set_cpu_frequency(0); |
| 86 | |
| 87 | #ifdef HAVE_ATA_POWER_OFF |
| 88 | ide_power_enable(false); |
| 89 | #endif |
| 90 | |
Björn Stenberg | 42510d9 | 2002-11-12 09:04:06 +0000 | [diff] [blame] | 91 | while (1) |
| 92 | { |
Jens Arnold | 0b00108 | 2005-11-09 00:54:43 +0000 | [diff] [blame] | 93 | #ifndef SIMULATOR |
Jonathan Gordon | bd47d48 | 2007-02-18 05:07:19 +0000 | [diff] [blame] | 94 | #if (CONFIG_LED == LED_REAL) |
Jens Arnold | f4e7759 | 2006-10-08 21:34:26 +0000 | [diff] [blame] | 95 | if (--i <= 0) |
| 96 | { |
| 97 | state = !state; |
| 98 | led(state); |
| 99 | i = 240000; |
| 100 | } |
Linus Nielsen Feltzing | e6c6d22 | 2005-09-12 10:34:27 +0000 | [diff] [blame] | 101 | #endif |
Jens Arnold | 0b00108 | 2005-11-09 00:54:43 +0000 | [diff] [blame] | 102 | |
Linus Nielsen Feltzing | e6c6d22 | 2005-09-12 10:34:27 +0000 | [diff] [blame] | 103 | /* try to restart firmware if ON is pressed */ |
Michael Sevakis | bfb281f | 2007-05-12 05:20:04 +0000 | [diff] [blame] | 104 | #if defined (CPU_PP) |
| 105 | /* For now, just sleep the core */ |
Jens Arnold | cea07eb | 2008-04-20 17:53:05 +0000 | [diff] [blame] | 106 | sleep_core(CURRENT_CORE); |
Michael Sevakis | bfb281f | 2007-05-12 05:20:04 +0000 | [diff] [blame] | 107 | #define system_reboot() nop |
| 108 | #elif defined (TOSHIBA_GIGABEAT_F) |
| 109 | if ((GPGDAT & (1 << 0)) != 0) |
Jens Arnold | c6b6bad | 2008-03-17 00:19:23 +0000 | [diff] [blame] | 110 | #elif defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES) |
Jens Arnold | 0b00108 | 2005-11-09 00:54:43 +0000 | [diff] [blame] | 111 | if ((GPIO1_READ & 0x22) == 0) /* check for ON button and !hold */ |
Jens Arnold | c6b6bad | 2008-03-17 00:19:23 +0000 | [diff] [blame] | 112 | #elif defined(IAUDIO_X5) || defined(IAUDIO_M5) |
| 113 | if ((GPIO_READ & 0x0c000000) == 0x08000000) /* check for ON button and !hold */ |
| 114 | #elif defined(IAUDIO_M3) |
| 115 | if ((GPIO1_READ & 0x202) == 0x200) /* check for ON button and !hold */ |
Rob Purchase | 3f7f5d7 | 2008-05-31 11:30:24 +0000 | [diff] [blame] | 116 | #elif defined(COWON_D2) |
| 117 | if (GPIOA & 0x10) /* check for power button */ |
Jens Arnold | 0b00108 | 2005-11-09 00:54:43 +0000 | [diff] [blame] | 118 | #elif CONFIG_CPU == SH7034 |
Linus Nielsen Feltzing | e6c6d22 | 2005-09-12 10:34:27 +0000 | [diff] [blame] | 119 | #if CONFIG_KEYPAD == PLAYER_PAD |
Jens Arnold | 0b00108 | 2005-11-09 00:54:43 +0000 | [diff] [blame] | 120 | if (!(PADRL & 0x20)) |
Linus Nielsen Feltzing | e6c6d22 | 2005-09-12 10:34:27 +0000 | [diff] [blame] | 121 | #elif CONFIG_KEYPAD == RECORDER_PAD |
| 122 | #ifdef HAVE_FMADC |
| 123 | if (!(PCDR & 0x0008)) |
| 124 | #else |
Jens Arnold | 0b00108 | 2005-11-09 00:54:43 +0000 | [diff] [blame] | 125 | if (!(PBDRH & 0x01)) |
Linus Nielsen Feltzing | e6c6d22 | 2005-09-12 10:34:27 +0000 | [diff] [blame] | 126 | #endif |
Jens Arnold | 0b00108 | 2005-11-09 00:54:43 +0000 | [diff] [blame] | 127 | #elif CONFIG_KEYPAD == ONDIO_PAD |
| 128 | if (!(PCDR & 0x0008)) |
| 129 | #endif /* CONFIG_KEYPAD */ |
Maurus Cuelenaere | e031db4 | 2008-05-14 18:55:19 +0000 | [diff] [blame] | 130 | #elif defined(CREATIVE_ZVx) |
Maurus Cuelenaere | 95167e0 | 2008-04-24 20:08:28 +0000 | [diff] [blame] | 131 | if(false) |
Jens Arnold | 0b00108 | 2005-11-09 00:54:43 +0000 | [diff] [blame] | 132 | #endif /* CPU */ |
Linus Nielsen Feltzing | e6c6d22 | 2005-09-12 10:34:27 +0000 | [diff] [blame] | 133 | system_reboot(); |
Jens Arnold | 0b00108 | 2005-11-09 00:54:43 +0000 | [diff] [blame] | 134 | #endif /* !SIMULATOR */ |
Björn Stenberg | 42510d9 | 2002-11-12 09:04:06 +0000 | [diff] [blame] | 135 | } |
Stuart Martin | 614acaa | 2002-04-30 19:23:44 +0000 | [diff] [blame] | 136 | } |