summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--firmware/Makefile8
-rw-r--r--firmware/app.lds20
-rw-r--r--firmware/debug.c12
-rw-r--r--firmware/debug.h20
-rw-r--r--firmware/disk.c4
-rw-r--r--firmware/drivers/fat.c92
-rw-r--r--firmware/panic.c18
-rw-r--r--firmware/panic.h1
-rw-r--r--firmware/playlist.c35
-rw-r--r--firmware/settings.c40
10 files changed, 122 insertions, 128 deletions
diff --git a/firmware/Makefile b/firmware/Makefile
index 90ce900cc9..91cb19955e 100644
--- a/firmware/Makefile
+++ b/firmware/Makefile
@@ -20,15 +20,11 @@ TARGET = -DARCHOS_PLAYER=1
20#TARGET = -DARCHOS_PLAYER_OLD=1 20#TARGET = -DARCHOS_PLAYER_OLD=1
21#TARGET = -DARCHOS_RECORDER=1 21#TARGET = -DARCHOS_RECORDER=1
22 22
23CFLAGS = -Os -Wall -m1 -nostdlib -Wstrict-prototypes -fomit-frame-pointer -fschedule-insns $(INCLUDES) $(TARGET) 23CFLAGS = -Os -Wall -m1 -nostdlib -Wstrict-prototypes -fomit-frame-pointer -fschedule-insns $(INCLUDES) $(TARGET) -DDEBUG
24AFLAGS += -small -relax 24AFLAGS += -small -relax
25 25
26SRC := $(wildcard drivers/*.c common/*.c *.c) 26SRC := $(wildcard drivers/*.c common/*.c *.c)
27OBJS := $(SRC:%.c=%.o) 27OBJS := $(SRC:%.c=%.o) crt0.o
28
29%.o: %.s
30 $(CC) -o $@ $(CFLAGS) $(INCLUDES) $(DEFS) -c $<
31
32 28
33all : archos.mod # archos.asm 29all : archos.mod # archos.asm
34 30
diff --git a/firmware/app.lds b/firmware/app.lds
index 03bd1b2b54..246c528b65 100644
--- a/firmware/app.lds
+++ b/firmware/app.lds
@@ -1,4 +1,4 @@
1ENTRY(_start) 1ENTRY(start)
2OUTPUT_FORMAT(elf32-sh) 2OUTPUT_FORMAT(elf32-sh)
3SECTIONS 3SECTIONS
4{ 4{
@@ -6,14 +6,28 @@ SECTIONS
6 { 6 {
7 *(.vectors); 7 *(.vectors);
8 . = ALIGN(0x200); 8 . = ALIGN(0x200);
9 *(.text.start) 9 *(.init.text)
10 }
11
12 .text :
13 {
10 *(.text) 14 *(.text)
11 *(.rodata)
12 } 15 }
13 16
17 .data :
18 {
19 *(.data)
20 }
21
22 .rodata :
23 {
24 *(.rodata)
25 }
14 .bss : 26 .bss :
15 { 27 {
28 _end = .;
16 _stack = . + 0x1000; 29 _stack = . + 0x1000;
30 _edata = .;
17 } 31 }
18 32
19 .pad 0x0900C800 : 33 .pad 0x0900C800 :
diff --git a/firmware/debug.c b/firmware/debug.c
index 9d2a6997a0..ae0fbe72c6 100644
--- a/firmware/debug.c
+++ b/firmware/debug.c
@@ -167,7 +167,7 @@ static char *mem2hex (char *mem, char *buf, int count)
167 return (buf); 167 return (buf);
168} 168}
169 169
170void debug(char *msg) 170static void debug(char *msg)
171{ 171{
172 debugbuf[0] = 'O'; 172 debugbuf[0] = 'O';
173 173
@@ -177,29 +177,27 @@ void debug(char *msg)
177 177
178void debugf(char *fmt, ...) 178void debugf(char *fmt, ...)
179{ 179{
180#ifdef DEBUG
180 va_list ap; 181 va_list ap;
181 182
182 va_start(ap, fmt); 183 va_start(ap, fmt);
183 vsnprintf(debugmembuf, sizeof(debugmembuf), fmt, ap); 184 vsnprintf(debugmembuf, sizeof(debugmembuf), fmt, ap);
184 va_end(ap); 185 va_end(ap);
185 debug(debugmembuf); 186 debug(debugmembuf);
187#endif
186} 188}
187 189
188#else 190#else
189 191
190void debug( const char *message )
191{
192 printf( message );
193}
194
195void debugf(char *fmt, ...) 192void debugf(char *fmt, ...)
196{ 193{
194#ifdef DEBUG
197 va_list ap; 195 va_list ap;
198 196
199 va_start( ap, fmt ); 197 va_start( ap, fmt );
200 vsnprintf( debugmembuf, sizeof(debugmembuf), fmt, ap ); 198 vsnprintf( debugmembuf, sizeof(debugmembuf), fmt, ap );
201 va_end( ap ); 199 va_end( ap );
202 printf( debugmembuf ); 200 printf( debugmembuf );
201#endif
203} 202}
204#endif 203#endif
205
diff --git a/firmware/debug.h b/firmware/debug.h
index dc3053cb32..adedfd9546 100644
--- a/firmware/debug.h
+++ b/firmware/debug.h
@@ -19,7 +19,23 @@
19#ifndef DEBUG_H 19#ifndef DEBUG_H
20#define DEBUG_H 20#define DEBUG_H
21 21
22void debug(char *msg); 22extern void debugf(char* fmt,...);
23void debugf(char *fmt, ...); 23
24#ifdef __GNUC__
25
26/* GCC handles ellipses in macros, which
27 means we can avoid the call completely */
28#ifdef DEBUG
29#define DEBUGF(fmt,args...) debugf(fmt, ## args)
30#else
31#define DEBUGF(fmt,args...)
32#endif
33
34#else
35
36void DEBUGF debugf
37
38#endif /* GCC */
39
24 40
25#endif 41#endif
diff --git a/firmware/disk.c b/firmware/disk.c
index 9d131f0421..c32a39be41 100644
--- a/firmware/disk.c
+++ b/firmware/disk.c
@@ -25,13 +25,11 @@
25 25
26void read_file_into_buffer( char **buf, const char *filename ) 26void read_file_into_buffer( char **buf, const char *filename )
27{ 27{
28 /*char debug_message[128]; */
29 int i; 28 int i;
30 FILE *fp; 29 FILE *fp;
31 int count = 0; 30 int count = 0;
32 31
33 /*sprintf( debug_message, "read_file_into_buffer( %s, %s )\n", *buf, filename ); 32 /*DEBUG( "read_file_into_buffer( %s, %s )\n", *buf, filename ); */
34 debug( debug_message );*/
35 33
36 fp = fopen( filename, "r" ); 34 fp = fopen( filename, "r" );
37 35
diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c
index 35e79789b0..6192d4619f 100644
--- a/firmware/drivers/fat.c
+++ b/firmware/drivers/fat.c
@@ -27,6 +27,7 @@
27 27
28#include "fat.h" 28#include "fat.h"
29#include "ata.h" 29#include "ata.h"
30#include "debug.h"
30 31
31#define BYTES2INT16(array,pos) \ 32#define BYTES2INT16(array,pos) \
32 (array[pos] | (array[pos+1] << 8 )) 33 (array[pos] | (array[pos+1] << 8 ))
@@ -134,12 +135,6 @@ static unsigned char lastsector2[SECTOR_SIZE];
134 135
135#ifdef TEST_FAT 136#ifdef TEST_FAT
136 137
137#include "debug.h"
138#define DEBUG(x) printf(x)
139#define DEBUG1(x,y) printf(x,y)
140#define DEBUG2(x,y1,y2) printf(x,y1,y2)
141#define DEBUG3(x,y1,y2,y3) printf(x,y1,y2,y3)
142
143int main(int argc, char *argv[]) 138int main(int argc, char *argv[])
144{ 139{
145 struct bpb bpb; 140 struct bpb bpb;
@@ -148,25 +143,20 @@ int main(int argc, char *argv[])
148 memset(fat_cache_dirty, 0, sizeof(fat_cache_dirty)); 143 memset(fat_cache_dirty, 0, sizeof(fat_cache_dirty));
149 144
150 if(ata_init()) 145 if(ata_init())
151 DEBUG("*** Warning! The disk is uninitialized\n"); 146 DEBUGF("*** Warning! The disk is uninitialized\n");
152 else 147 else
153 fat_mount(&bpb); 148 fat_mount(&bpb);
154 149
155 dbg_console(&bpb); 150 dbg_console(&bpb);
156 return 0; 151 return 0;
157} 152}
158#else
159#define DEBUG(x);
160#define DEBUG1(x,y);
161#define DEBUG2(x,y1,y2);
162#define DEBUG3(x,y1,y2,y3);
163#endif 153#endif
164 154
165static int sec2cluster(struct bpb *bpb, unsigned int sec) 155static int sec2cluster(struct bpb *bpb, unsigned int sec)
166{ 156{
167 if ( sec < bpb->firstdatasector ) 157 if ( sec < bpb->firstdatasector )
168 { 158 {
169 DEBUG1( "sec2cluster() - Bad sector number (%d)\n", sec); 159 DEBUGF( "sec2cluster() - Bad sector number (%d)\n", sec);
170 return -1; 160 return -1;
171 } 161 }
172 162
@@ -180,7 +170,7 @@ static int cluster2sec(struct bpb *bpb, unsigned int cluster)
180 170
181 if(cluster > max_cluster) 171 if(cluster > max_cluster)
182 { 172 {
183 DEBUG1( "cluster2sec() - Bad cluster number (%d)\n", 173 DEBUGF( "cluster2sec() - Bad cluster number (%d)\n",
184 cluster); 174 cluster);
185 return -1; 175 return -1;
186 } 176 }
@@ -204,7 +194,7 @@ int fat_mount(struct bpb *bpb)
204 err = ata_read_sectors(0,1,buf); 194 err = ata_read_sectors(0,1,buf);
205 if(err) 195 if(err)
206 { 196 {
207 DEBUG1( "fat_mount() - Couldn't read BPB (error code %i)\n", 197 DEBUGF( "fat_mount() - Couldn't read BPB (error code %i)\n",
208 err); 198 err);
209 return -1; 199 return -1;
210 } 200 }
@@ -256,7 +246,7 @@ int fat_mount(struct bpb *bpb)
256 if ( countofclusters < 65525 ) 246 if ( countofclusters < 65525 )
257#endif 247#endif
258 { 248 {
259 DEBUG("This is not FAT32. Go away!\n"); 249 DEBUGF("This is not FAT32. Go away!\n");
260 return -1; 250 return -1;
261 } 251 }
262 252
@@ -277,7 +267,7 @@ int fat_mount(struct bpb *bpb)
277 267
278 if (bpb_is_sane(bpb) < 0) 268 if (bpb_is_sane(bpb) < 0)
279 { 269 {
280 DEBUG( "fat_mount() - BPB is not sane\n"); 270 DEBUGF( "fat_mount() - BPB is not sane\n");
281 return -1; 271 return -1;
282 } 272 }
283 273
@@ -290,55 +280,55 @@ static int bpb_is_sane(struct bpb *bpb)
290{ 280{
291 if(bpb->bpb_bytspersec != 512) 281 if(bpb->bpb_bytspersec != 512)
292 { 282 {
293 DEBUG1( "bpb_is_sane() - Error: sector size is not 512 (%i)\n", 283 DEBUGF( "bpb_is_sane() - Error: sector size is not 512 (%i)\n",
294 bpb->bpb_bytspersec); 284 bpb->bpb_bytspersec);
295 return -1; 285 return -1;
296 } 286 }
297 if(bpb->bpb_secperclus * bpb->bpb_bytspersec > 32768) 287 if(bpb->bpb_secperclus * bpb->bpb_bytspersec > 32768)
298 { 288 {
299 DEBUG3( "bpb_is_sane() - Warning: cluster size is larger than 32K " 289 DEBUGF( "bpb_is_sane() - Warning: cluster size is larger than 32K "
300 "(%i * %i = %i)\n", 290 "(%i * %i = %i)\n",
301 bpb->bpb_bytspersec, bpb->bpb_secperclus, 291 bpb->bpb_bytspersec, bpb->bpb_secperclus,
302 bpb->bpb_bytspersec * bpb->bpb_secperclus); 292 bpb->bpb_bytspersec * bpb->bpb_secperclus);
303 } 293 }
304 if(bpb->bpb_rsvdseccnt != 1) 294 if(bpb->bpb_rsvdseccnt != 1)
305 { 295 {
306 DEBUG1( "bpb_is_sane() - Warning: Reserved sectors is not 1 (%i)\n", 296 DEBUGF( "bpb_is_sane() - Warning: Reserved sectors is not 1 (%i)\n",
307 bpb->bpb_rsvdseccnt); 297 bpb->bpb_rsvdseccnt);
308 } 298 }
309 if(bpb->bpb_numfats != 2) 299 if(bpb->bpb_numfats != 2)
310 { 300 {
311 DEBUG1( "bpb_is_sane() - Warning: NumFATS is not 2 (%i)\n", 301 DEBUGF( "bpb_is_sane() - Warning: NumFATS is not 2 (%i)\n",
312 bpb->bpb_numfats); 302 bpb->bpb_numfats);
313 } 303 }
314 if(bpb->bpb_rootentcnt != 512) 304 if(bpb->bpb_rootentcnt != 512)
315 { 305 {
316 DEBUG1( "bpb_is_sane() - Warning: RootEntCnt is not 512 (%i)\n", 306 DEBUGF( "bpb_is_sane() - Warning: RootEntCnt is not 512 (%i)\n",
317 bpb->bpb_rootentcnt); 307 bpb->bpb_rootentcnt);
318 } 308 }
319 if(bpb->bpb_totsec16 < 200) 309 if(bpb->bpb_totsec16 < 200)
320 { 310 {
321 if(bpb->bpb_totsec16 == 0) 311 if(bpb->bpb_totsec16 == 0)
322 { 312 {
323 DEBUG( "bpb_is_sane() - Error: TotSec16 is 0\n"); 313 DEBUGF( "bpb_is_sane() - Error: TotSec16 is 0\n");
324 return -1; 314 return -1;
325 } 315 }
326 else 316 else
327 { 317 {
328 DEBUG1( "bpb_is_sane() - Warning: TotSec16 " 318 DEBUGF( "bpb_is_sane() - Warning: TotSec16 "
329 "is quite small (%i)\n", 319 "is quite small (%i)\n",
330 bpb->bpb_totsec16); 320 bpb->bpb_totsec16);
331 } 321 }
332 } 322 }
333 if(bpb->bpb_media != 0xf0 && bpb->bpb_media < 0xf8) 323 if(bpb->bpb_media != 0xf0 && bpb->bpb_media < 0xf8)
334 { 324 {
335 DEBUG1( "bpb_is_sane() - Warning: Non-standard " 325 DEBUGF( "bpb_is_sane() - Warning: Non-standard "
336 "media type (0x%02x)\n", 326 "media type (0x%02x)\n",
337 bpb->bpb_media); 327 bpb->bpb_media);
338 } 328 }
339 if(bpb->last_word != 0xaa55) 329 if(bpb->last_word != 0xaa55)
340 { 330 {
341 DEBUG1( "bpb_is_sane() - Error: Last word is not " 331 DEBUGF( "bpb_is_sane() - Error: Last word is not "
342 "0xaa55 (0x%04x)\n", bpb->last_word); 332 "0xaa55 (0x%04x)\n", bpb->last_word);
343 return -1; 333 return -1;
344 } 334 }
@@ -356,12 +346,12 @@ static void *cache_fat_sector(struct bpb *bpb, int secnum)
356 sec = malloc(bpb->bpb_bytspersec); 346 sec = malloc(bpb->bpb_bytspersec);
357 if(!sec) 347 if(!sec)
358 { 348 {
359 DEBUG( "cache_fat_sector() - Out of memory\n"); 349 DEBUGF( "cache_fat_sector() - Out of memory\n");
360 return NULL; 350 return NULL;
361 } 351 }
362 if(ata_read_sectors(secnum,1,sec)) 352 if(ata_read_sectors(secnum,1,sec))
363 { 353 {
364 DEBUG1( "cache_fat_sector() - Could" 354 DEBUGF( "cache_fat_sector() - Could"
365 " not read sector %d\n", 355 " not read sector %d\n",
366 secnum); 356 secnum);
367 free(sec); 357 free(sec);
@@ -388,7 +378,7 @@ static int update_entry(struct bpb *bpb, int entry, unsigned int val)
388 sec = cache_fat_sector(bpb, thisfatsecnum); 378 sec = cache_fat_sector(bpb, thisfatsecnum);
389 if(!sec) 379 if(!sec)
390 { 380 {
391 DEBUG1( "update_entry() - Could not cache sector %d\n", 381 DEBUGF( "update_entry() - Could not cache sector %d\n",
392 thisfatsecnum); 382 thisfatsecnum);
393 return -1; 383 return -1;
394 } 384 }
@@ -419,7 +409,7 @@ static int read_entry(struct bpb *bpb, int entry)
419 sec = cache_fat_sector(bpb, thisfatsecnum); 409 sec = cache_fat_sector(bpb, thisfatsecnum);
420 if(!sec) 410 if(!sec)
421 { 411 {
422 DEBUG1( "update_entry() - Could not cache sector %d\n", 412 DEBUGF( "update_entry() - Could not cache sector %d\n",
423 thisfatsecnum); 413 thisfatsecnum);
424 return -1; 414 return -1;
425 } 415 }
@@ -455,19 +445,19 @@ static int flush_fat(struct bpb *bpb)
455 { 445 {
456 if(fat_cache[i] && fat_cache_dirty[i]) 446 if(fat_cache[i] && fat_cache_dirty[i])
457 { 447 {
458 DEBUG1("Flushing FAT sector %d\n", i); 448 DEBUGF("Flushing FAT sector %d\n", i);
459 sec = fat_cache[i]; 449 sec = fat_cache[i];
460 err = ata_write_sectors(i + bpb->bpb_rsvdseccnt,1,sec); 450 err = ata_write_sectors(i + bpb->bpb_rsvdseccnt,1,sec);
461 if(err) 451 if(err)
462 { 452 {
463 DEBUG1( "flush_fat() - Couldn't write" 453 DEBUGF( "flush_fat() - Couldn't write"
464 " sector (%d)\n", i + bpb->bpb_rsvdseccnt); 454 " sector (%d)\n", i + bpb->bpb_rsvdseccnt);
465 return -1; 455 return -1;
466 } 456 }
467 err = ata_write_sectors(i + bpb->bpb_rsvdseccnt + fatsz,1,sec); 457 err = ata_write_sectors(i + bpb->bpb_rsvdseccnt + fatsz,1,sec);
468 if(err) 458 if(err)
469 { 459 {
470 DEBUG1( "flush_fat() - Couldn't write" 460 DEBUGF( "flush_fat() - Couldn't write"
471 " sector (%d)\n", i + bpb->bpb_rsvdseccnt + fatsz); 461 " sector (%d)\n", i + bpb->bpb_rsvdseccnt + fatsz);
472 return -1; 462 return -1;
473 } 463 }
@@ -543,7 +533,7 @@ static int add_dir_entry(struct bpb *bpb,
543 } 533 }
544 else 534 else
545 { 535 {
546 DEBUG( "add_dir_entry() -" 536 DEBUGF( "add_dir_entry() -"
547 " Root dir is full\n"); 537 " Root dir is full\n");
548 return -1; 538 return -1;
549 } 539 }
@@ -554,9 +544,9 @@ static int add_dir_entry(struct bpb *bpb,
554 if(sec_cnt >= bpb->bpb_secperclus) 544 if(sec_cnt >= bpb->bpb_secperclus)
555 { 545 {
556 /* We have reached the end of this cluster */ 546 /* We have reached the end of this cluster */
557 DEBUG("Moving to the next cluster..."); 547 DEBUGF("Moving to the next cluster...");
558 currdir = get_next_cluster(bpb, currdir); 548 currdir = get_next_cluster(bpb, currdir);
559 DEBUG1("new cluster is %d\n", currdir); 549 DEBUGF("new cluster is %d\n", currdir);
560 550
561 if(!currdir) 551 if(!currdir)
562 { 552 {
@@ -567,12 +557,12 @@ static int add_dir_entry(struct bpb *bpb,
567 } 557 }
568 } 558 }
569 559
570 DEBUG1("Reading sector %d...\n", sec); 560 DEBUGF("Reading sector %d...\n", sec);
571 /* Read the next sector in the current dir */ 561 /* Read the next sector in the current dir */
572 err = ata_read_sectors(sec,1,buf); 562 err = ata_read_sectors(sec,1,buf);
573 if(err) 563 if(err)
574 { 564 {
575 DEBUG1( "add_dir_entry() - Couldn't read dir sector" 565 DEBUGF( "add_dir_entry() - Couldn't read dir sector"
576 " (error code %i)\n", err); 566 " (error code %i)\n", err);
577 return -1; 567 return -1;
578 } 568 }
@@ -580,7 +570,7 @@ static int add_dir_entry(struct bpb *bpb,
580 if(need_to_update_last_empty_marker) 570 if(need_to_update_last_empty_marker)
581 { 571 {
582 /* All we need to do is to set the first entry to 0 */ 572 /* All we need to do is to set the first entry to 0 */
583 DEBUG1("Clearing the first entry in sector %d\n", sec); 573 DEBUGF("Clearing the first entry in sector %d\n", sec);
584 buf[0] = 0; 574 buf[0] = 0;
585 done = 1; 575 done = 1;
586 } 576 }
@@ -592,7 +582,7 @@ static int add_dir_entry(struct bpb *bpb,
592 firstbyte = buf[i]; 582 firstbyte = buf[i];
593 if(firstbyte == 0xe5 || firstbyte == 0) 583 if(firstbyte == 0xe5 || firstbyte == 0)
594 { 584 {
595 DEBUG2("Found free slot at entry %d in sector %d\n", 585 DEBUGF("Found free slot at entry %d in sector %d\n",
596 i/32, sec); 586 i/32, sec);
597 eptr = &buf[i]; 587 eptr = &buf[i];
598 memset(eptr, 0, 32); 588 memset(eptr, 0, 32);
@@ -637,7 +627,7 @@ static int add_dir_entry(struct bpb *bpb,
637 err = ata_write_sectors(sec,1,buf); 627 err = ata_write_sectors(sec,1,buf);
638 if(err) 628 if(err)
639 { 629 {
640 DEBUG1( "add_dir_entry() - " 630 DEBUGF( "add_dir_entry() - "
641 " Couldn't write dir" 631 " Couldn't write dir"
642 " sector (error code %i)\n", err); 632 " sector (error code %i)\n", err);
643 return -1; 633 return -1;
@@ -752,11 +742,11 @@ int fat_create_dir(struct bpb *bpb, unsigned int currdir, char *name)
752 struct fat_direntry de; 742 struct fat_direntry de;
753 int err; 743 int err;
754 744
755 DEBUG("fat_create_file()\n"); 745 DEBUGF("fat_create_file()\n");
756 memset(&de, 0, sizeof(struct fat_direntry)); 746 memset(&de, 0, sizeof(struct fat_direntry));
757 if(create_dos_name(name, de.name) < 0) 747 if(create_dos_name(name, de.name) < 0)
758 { 748 {
759 DEBUG1( "fat_create_file() - Illegal file name (%s)\n", name); 749 DEBUGF( "fat_create_file() - Illegal file name (%s)\n", name);
760 return -1; 750 return -1;
761 } 751 }
762 752
@@ -775,11 +765,11 @@ int fat_create_file(struct bpb *bpb, unsigned int currdir, char *name)
775 struct fat_direntry de; 765 struct fat_direntry de;
776 int err; 766 int err;
777 767
778 DEBUG("fat_create_file()\n"); 768 DEBUGF("fat_create_file()\n");
779 memset(&de, 0, sizeof(struct fat_direntry)); 769 memset(&de, 0, sizeof(struct fat_direntry));
780 if(create_dos_name(name, de.name) < 0) 770 if(create_dos_name(name, de.name) < 0)
781 { 771 {
782 DEBUG1( "fat_create_file() - Illegal file name (%s)\n", name); 772 DEBUGF( "fat_create_file() - Illegal file name (%s)\n", name);
783 return -1; 773 return -1;
784 } 774 }
785 getcurrdostime(&de.crtdate, &de.crttime, &de.crttimetenth); 775 getcurrdostime(&de.crtdate, &de.crttime, &de.crttimetenth);
@@ -833,7 +823,7 @@ int fat_read(struct bpb *bpb,
833 for ( i=0; i<sectorcount; i++ ) { 823 for ( i=0; i<sectorcount; i++ ) {
834 err = ata_read_sectors(sector,1,(char*)buf+(i*SECTOR_SIZE)); 824 err = ata_read_sectors(sector,1,(char*)buf+(i*SECTOR_SIZE));
835 if(err) { 825 if(err) {
836 DEBUG2( "fat_read() - Couldn't read sector %d" 826 DEBUGF( "fat_read() - Couldn't read sector %d"
837 " (error code %i)\n", sector,err); 827 " (error code %i)\n", sector,err);
838 return -1; 828 return -1;
839 } 829 }
@@ -911,7 +901,7 @@ int fat_opendir(struct bpb *bpb,
911 err = ata_read_sectors(sec,1,ent->cached_buf); 901 err = ata_read_sectors(sec,1,ent->cached_buf);
912 if(err) 902 if(err)
913 { 903 {
914 DEBUG1( "fat_getfirst() - Couldn't read dir sector" 904 DEBUGF( "fat_getfirst() - Couldn't read dir sector"
915 " (error code %i)\n", err); 905 " (error code %i)\n", err);
916 return -1; 906 return -1;
917 } 907 }
@@ -1027,20 +1017,20 @@ int fat_getnext(struct bpb *bpb,
1027 { 1017 {
1028 int cluster = sec2cluster(bpb, ent->cached_sec); 1018 int cluster = sec2cluster(bpb, ent->cached_sec);
1029 if ( cluster < 0 ) { 1019 if ( cluster < 0 ) {
1030 DEBUG("sec2cluster failed\n"); 1020 DEBUGF("sec2cluster failed\n");
1031 return -1; 1021 return -1;
1032 } 1022 }
1033 ent->num_sec = 0; 1023 ent->num_sec = 0;
1034 cluster = get_next_cluster( bpb, cluster ); 1024 cluster = get_next_cluster( bpb, cluster );
1035 if(!cluster) 1025 if(!cluster)
1036 { 1026 {
1037 DEBUG("End of cluster chain.\n"); 1027 DEBUGF("End of cluster chain.\n");
1038 return -1; 1028 return -1;
1039 } 1029 }
1040 ent->cached_sec = cluster2sec(bpb,cluster); 1030 ent->cached_sec = cluster2sec(bpb,cluster);
1041 if ( ent->cached_sec < 0 ) 1031 if ( ent->cached_sec < 0 )
1042 { 1032 {
1043 DEBUG1("Invalid cluster: %d\n",cluster); 1033 DEBUGF("Invalid cluster: %d\n",cluster);
1044 return -1; 1034 return -1;
1045 } 1035 }
1046 1036
@@ -1050,7 +1040,7 @@ int fat_getnext(struct bpb *bpb,
1050 err = ata_read_sectors(ent->cached_sec,1,ent->cached_buf); 1040 err = ata_read_sectors(ent->cached_sec,1,ent->cached_buf);
1051 if(err) 1041 if(err)
1052 { 1042 {
1053 DEBUG1( "fat_getnext() - Couldn't read dir sector" 1043 DEBUGF( "fat_getnext() - Couldn't read dir sector"
1054 " (error code %i)\n", err); 1044 " (error code %i)\n", err);
1055 return -1; 1045 return -1;
1056 } 1046 }
diff --git a/firmware/panic.c b/firmware/panic.c
index 7f8a08889e..2cb79b1e0c 100644
--- a/firmware/panic.c
+++ b/firmware/panic.c
@@ -20,7 +20,7 @@
20#include <stdio.h> 20#include <stdio.h>
21#include <stdarg.h> 21#include <stdarg.h>
22#include "panic.h" 22#include "panic.h"
23#include "drivers/lcd.h" 23#include "lcd.h"
24#include "debug.h" 24#include "debug.h"
25 25
26char panic_buf[128]; 26char panic_buf[128];
@@ -28,18 +28,6 @@ char panic_buf[128];
28/* 28/*
29 * "Dude. This is pretty fucked-up, right here." 29 * "Dude. This is pretty fucked-up, right here."
30 */ 30 */
31void panic( char *message )
32{
33 debug( message );
34
35 /*lcd_string( message ); */
36
37 while( 1 );
38}
39
40/*
41 * "Dude. This is pretty fucked-up, right here."
42 */
43void panicf( char *fmt, ...) 31void panicf( char *fmt, ...)
44{ 32{
45 va_list ap; 33 va_list ap;
@@ -48,5 +36,7 @@ void panicf( char *fmt, ...)
48 vsnprintf( panic_buf, sizeof(panic_buf), fmt, ap ); 36 vsnprintf( panic_buf, sizeof(panic_buf), fmt, ap );
49 va_end( ap ); 37 va_end( ap );
50 38
51 panic( panic_buf ); 39 lcd_puts(0,0,panic_buf);
40 DEBUGF(panic_buf);
41 while(1);
52} 42}
diff --git a/firmware/panic.h b/firmware/panic.h
index 31542c1edf..585f827927 100644
--- a/firmware/panic.h
+++ b/firmware/panic.h
@@ -20,7 +20,6 @@
20#ifndef __PANIC_H__ 20#ifndef __PANIC_H__
21#define __PANIC_H__ 21#define __PANIC_H__
22 22
23void panic( char *message );
24void panicf( char *fmt, ... ); 23void panicf( char *fmt, ... );
25 24
26#endif /* __PANIC_H__ */ 25#endif /* __PANIC_H__ */
diff --git a/firmware/playlist.c b/firmware/playlist.c
index 67b7834449..50d7313136 100644
--- a/firmware/playlist.c
+++ b/firmware/playlist.c
@@ -31,7 +31,7 @@
31 */ 31 */
32int reload_playlist_info( playlist_info_t *playlist ) 32int reload_playlist_info( playlist_info_t *playlist )
33{ 33{
34 debug( "reload_playlist_info()\n" ); 34 DEBUGF( "reload_playlist_info()\n" );
35 35
36 /* this is a TEMP stub version */ 36 /* this is a TEMP stub version */
37 37
@@ -60,22 +60,16 @@ int reload_playlist_info( playlist_info_t *playlist )
60void load_playlist( playlist_info_t *playlist, const char *filename ) { 60void load_playlist( playlist_info_t *playlist, const char *filename ) {
61 61
62 char *m3u_buf = NULL; 62 char *m3u_buf = NULL;
63 char debug_message[128];
64 63
65 snprintf( debug_message, sizeof(debug_message), 64 DEBUGF( "load_playlist( %s )\n", filename );
66 "load_playlist( %s )\n", filename );
67 debug( debug_message );
68 65
69 /* read file */ 66 /* read file */
70
71 read_file_into_buffer( &m3u_buf, filename ); 67 read_file_into_buffer( &m3u_buf, filename );
72 68
73 /* store playlist filename */ 69 /* store playlist filename */
74
75 strncpy( playlist->filename, filename, sizeof(playlist->filename) ); 70 strncpy( playlist->filename, filename, sizeof(playlist->filename) );
76 71
77 /* add track indices to playlist data structure */ 72 /* add track indices to playlist data structure */
78
79 add_indices_to_playlist( m3u_buf, playlist ); 73 add_indices_to_playlist( m3u_buf, playlist );
80} 74}
81 75
@@ -84,7 +78,7 @@ void load_playlist( playlist_info_t *playlist, const char *filename ) {
84 */ 78 */
85void empty_playlist( playlist_info_t *playlist ) { 79void empty_playlist( playlist_info_t *playlist ) {
86 80
87 debug( "empty_playlist()\n" ); 81 DEBUGF( "empty_playlist()\n" );
88 82
89 playlist->filename[0] = '\0'; 83 playlist->filename[0] = '\0';
90 playlist->indices_count = 0; 84 playlist->indices_count = 0;
@@ -101,7 +95,7 @@ void add_indices_to_playlist( char *buf, playlist_info_t *playlist )
101 char *p; 95 char *p;
102 int i = 0; 96 int i = 0;
103 97
104 /*debug( "add_indices_to_playlist()\n" ); */ 98 /*DEBUGF( "add_indices_to_playlist()\n" ); */
105 99
106 p = buf; 100 p = buf;
107 101
@@ -141,8 +135,7 @@ void add_indices_to_playlist( char *buf, playlist_info_t *playlist )
141 */ 135 */
142void extend_indices( playlist_info_t *playlist, int new_index ) 136void extend_indices( playlist_info_t *playlist, int new_index )
143{ 137{
144 /*sprintf( debug_message, "extend_indices(%d)\n", new_index ); 138 /*DEBUGF( "extend_indices(%d)\n", new_index ); */
145 debug( debug_message );*/
146 139
147 /* increase array size count */ 140 /* increase array size count */
148 141
@@ -157,8 +150,8 @@ void extend_indices( playlist_info_t *playlist, int new_index )
157 playlist->indices[ playlist->indices_count - 1 ] = new_index; 150 playlist->indices[ playlist->indices_count - 1 ] = new_index;
158} 151}
159 152
160track_t next_playlist_track( playlist_info_t *playlist ) { 153track_t next_playlist_track( playlist_info_t *playlist )
161 154{
162 track_t track; 155 track_t track;
163 strncpy( track.filename, "boogie", sizeof(track.filename) ); 156 strncpy( track.filename, "boogie", sizeof(track.filename) );
164 return track; 157 return track;
@@ -167,8 +160,8 @@ track_t next_playlist_track( playlist_info_t *playlist ) {
167/* 160/*
168 * randomly rearrange the array of indices for the playlist 161 * randomly rearrange the array of indices for the playlist
169 */ 162 */
170void randomise_playlist( playlist_info_t *playlist ) { 163void randomise_playlist( playlist_info_t *playlist )
171 164{
172 unsigned seed; 165 unsigned seed;
173 int count = 0; 166 int count = 0;
174 int candidate; 167 int candidate;
@@ -178,7 +171,7 @@ void randomise_playlist( playlist_info_t *playlist ) {
178 int *randomised_list; 171 int *randomised_list;
179 int i; 172 int i;
180 173
181 debug( "randomise_playlist()\n" ); 174 DEBUGF( "randomise_playlist()\n" );
182 175
183 /* create dynamic storage for randomised list so it can be freed later */ 176 /* create dynamic storage for randomised list so it can be freed later */
184 177
@@ -279,7 +272,7 @@ int is_unused_random_in_list( int number, int *new_list, int count )
279 */ 272 */
280void display_playlist_track( track_t *track ) 273void display_playlist_track( track_t *track )
281{ 274{
282 debugf( "track: %s\n", track->filename ); 275 DEBUGF( "track: %s\n", track->filename );
283} 276}
284 277
285/* 278/*
@@ -290,14 +283,14 @@ void display_current_playlist( playlist_info_t *playlist )
290 char indices[2048]; 283 char indices[2048];
291 indices[0]='\0'; 284 indices[0]='\0';
292 285
293 /*debug( "\ndisplay_current_playlist()\n" ); */ 286 /*DEBUGF( "\ndisplay_current_playlist()\n" ); */
294 287
295 if( playlist->indices_count != 0 ) 288 if( playlist->indices_count != 0 )
296 { 289 {
297 get_indices_as_string( indices, playlist ); 290 get_indices_as_string( indices, playlist );
298 } 291 }
299 292
300 debugf( "\nfilename:\t%s\ntotal:\t\t%d\nindices:\t%s\ncurrent index:\t%d\n\n", 293 DEBUGF( "\nfilename:\t%s\ntotal:\t\t%d\nindices:\t%s\ncurrent index:\t%d\n\n",
301 playlist->filename, 294 playlist->filename,
302 playlist->indices_count, 295 playlist->indices_count,
303 indices, 296 indices,
@@ -313,7 +306,7 @@ void get_indices_as_string( char *string, playlist_info_t *playlist )
313 int count = 0; 306 int count = 0;
314 int *p = playlist->indices; 307 int *p = playlist->indices;
315 308
316 /*debug( "get_indices_as_string()\n" ); */ 309 /*DEBUGF( "get_indices_as_string()\n" ); */
317 310
318 while( count < playlist->indices_count ) { 311 while( count < playlist->indices_count ) {
319 312
diff --git a/firmware/settings.c b/firmware/settings.c
index 03a802b543..d2f72e759f 100644
--- a/firmware/settings.c
+++ b/firmware/settings.c
@@ -31,57 +31,57 @@ int persist_all_settings( void )
31{ 31{
32 if( ! persist_volume_setting() ) 32 if( ! persist_volume_setting() )
33 { 33 {
34 panic( "failed to persist volume setting" ); 34 panicf( "failed to persist volume setting" );
35 } 35 }
36 36
37 if( ! persist_balance_setting() ) 37 if( ! persist_balance_setting() )
38 { 38 {
39 panic( "failed to persist balance setting" ); 39 panicf( "failed to persist balance setting" );
40 } 40 }
41 41
42 if( ! persist_bass_setting() ) 42 if( ! persist_bass_setting() )
43 { 43 {
44 panic( "failed to persist bass setting" ); 44 panicf( "failed to persist bass setting" );
45 } 45 }
46 46
47 if( ! persist_treble_setting() ) 47 if( ! persist_treble_setting() )
48 { 48 {
49 panic( "failed to persist treble setting" ); 49 panicf( "failed to persist treble setting" );
50 } 50 }
51 51
52 if( ! persist_loudness_setting() ) 52 if( ! persist_loudness_setting() )
53 { 53 {
54 panic( "failed to persist loudness setting" ); 54 panicf( "failed to persist loudness setting" );
55 } 55 }
56 56
57 if( ! persist_bass_boost_setting() ) 57 if( ! persist_bass_boost_setting() )
58 { 58 {
59 panic( "failed to persist bass boost setting" ); 59 panicf( "failed to persist bass boost setting" );
60 } 60 }
61 61
62 if( ! persist_contrast_setting() ) 62 if( ! persist_contrast_setting() )
63 { 63 {
64 panic( "failed to persist contrast setting" ); 64 panicf( "failed to persist contrast setting" );
65 } 65 }
66 66
67 if( ! persist_poweroff_setting() ) 67 if( ! persist_poweroff_setting() )
68 { 68 {
69 panic( "failed to persist poweroff setting" ); 69 panicf( "failed to persist poweroff setting" );
70 } 70 }
71 71
72 if( ! persist_backlight_setting() ) 72 if( ! persist_backlight_setting() )
73 { 73 {
74 panic( "failed to persist backlight setting" ); 74 panicf( "failed to persist backlight setting" );
75 } 75 }
76 76
77 if( ! persist_poweroff_setting() ) 77 if( ! persist_poweroff_setting() )
78 { 78 {
79 panic( "failed to persist poweroff setting" ); 79 panicf( "failed to persist poweroff setting" );
80 } 80 }
81 81
82 if( ! persist_resume_setting() ) 82 if( ! persist_resume_setting() )
83 { 83 {
84 panic( "failed to persist resume setting" ); 84 panicf( "failed to persist resume setting" );
85 } 85 }
86 86
87 /* by getting here, we had no problems */ 87 /* by getting here, we had no problems */
@@ -96,22 +96,22 @@ int persist_all_playlist_info( void )
96{ 96{
97 if( ! persist_playlist_filename() ) 97 if( ! persist_playlist_filename() )
98 { 98 {
99 panic( "failed to persist playlist filename" ); 99 panicf( "failed to persist playlist filename" );
100 } 100 }
101 101
102 if( ! persist_playlist_indices() ) 102 if( ! persist_playlist_indices() )
103 { 103 {
104 panic( "failed to persist playlist indices" ); 104 panicf( "failed to persist playlist indices" );
105 } 105 }
106 106
107 if( ! persist_playlist_index() ) 107 if( ! persist_playlist_index() )
108 { 108 {
109 panic( "failed to persist playlist index" ); 109 panicf( "failed to persist playlist index" );
110 } 110 }
111 111
112 if( ! persist_resume_track_time() ) 112 if( ! persist_resume_track_time() )
113 { 113 {
114 panic( "failed to persist resume track time" ); 114 panicf( "failed to persist resume track time" );
115 } 115 }
116 116
117 /* by getting here, we had no problems */ 117 /* by getting here, we had no problems */
@@ -124,7 +124,7 @@ int persist_all_playlist_info( void )
124 */ 124 */
125void reload_all_settings( user_settings_t *settings ) 125void reload_all_settings( user_settings_t *settings )
126{ 126{
127 debug( "reload_all_settings()\n" ); 127 DEBUGF( "reload_all_settings()\n" );
128 128
129 /* this is a TEMP stub version */ 129 /* this is a TEMP stub version */
130 130
@@ -138,7 +138,7 @@ void reload_all_settings( user_settings_t *settings )
138 */ 138 */
139void reset_settings( user_settings_t *settings ) { 139void reset_settings( user_settings_t *settings ) {
140 140
141 debug( "reset_settings()\n" ); 141 DEBUGF( "reset_settings()\n" );
142 142
143 settings->volume = DEFAULT_VOLUME_SETTING; 143 settings->volume = DEFAULT_VOLUME_SETTING;
144 settings->balance = DEFAULT_BALANCE_SETTING; 144 settings->balance = DEFAULT_BALANCE_SETTING;
@@ -156,9 +156,9 @@ void reset_settings( user_settings_t *settings ) {
156 */ 156 */
157void display_current_settings( user_settings_t *settings ) 157void display_current_settings( user_settings_t *settings )
158{ 158{
159 debug( "\ndisplay_current_settings()\n" ); 159 DEBUGF( "\ndisplay_current_settings()\n" );
160 160
161 debugf( "\nvolume:\t\t%d\nbalance:\t%d\nbass:\t\t%d\ntreble:\t\t%d\nloudness:\t%d\nbass boost:\t%d\n", 161 DEBUGF( "\nvolume:\t\t%d\nbalance:\t%d\nbass:\t\t%d\ntreble:\t\t%d\nloudness:\t%d\nbass boost:\t%d\n",
162 settings->volume, 162 settings->volume,
163 settings->balance, 163 settings->balance,
164 settings->bass, 164 settings->bass,
@@ -166,7 +166,7 @@ void display_current_settings( user_settings_t *settings )
166 settings->loudness, 166 settings->loudness,
167 settings->bass_boost ); 167 settings->bass_boost );
168 168
169 debugf( "contrast:\t%d\npoweroff:\t%d\nbacklight:\t%d\n", 169 DEBUGF( "contrast:\t%d\npoweroff:\t%d\nbacklight:\t%d\n",
170 settings->contrast, 170 settings->contrast,
171 settings->poweroff, 171 settings->poweroff,
172 settings->backlight ); 172 settings->backlight );