summaryrefslogtreecommitdiff
path: root/firmware/test
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/test')
-rw-r--r--firmware/test/buflib/Makefile67
-rw-r--r--firmware/test/buflib/autoconf.h2
-rw-r--r--firmware/test/buflib/system-hosted.h43
-rw-r--r--firmware/test/buflib/test_main.c88
-rw-r--r--firmware/test/buflib/test_main2.c108
-rw-r--r--firmware/test/buflib/test_max.c75
-rw-r--r--firmware/test/buflib/test_move.c63
-rw-r--r--firmware/test/buflib/test_move2.c132
-rw-r--r--firmware/test/buflib/test_shrink.c56
-rw-r--r--firmware/test/buflib/test_shrink_cb.c108
-rw-r--r--firmware/test/buflib/test_shrink_startchanged.c59
-rw-r--r--firmware/test/buflib/test_shrink_unaligned.c56
-rw-r--r--firmware/test/buflib/util.c61
-rw-r--r--firmware/test/buflib/util.h30
-rw-r--r--firmware/test/fat/Makefile49
-rw-r--r--firmware/test/fat/README32
-rw-r--r--firmware/test/fat/ata-sim.c68
-rw-r--r--firmware/test/fat/autoconf.h9
-rw-r--r--firmware/test/fat/main.c724
-rw-r--r--firmware/test/fat/test.sh146
-rw-r--r--firmware/test/fat/test16.sh135
-rw-r--r--firmware/test/i2c/Makefile53
-rw-r--r--firmware/test/i2c/app.lds36
-rw-r--r--firmware/test/i2c/gendata.c31
-rw-r--r--firmware/test/i2c/main.c1280
-rw-r--r--firmware/test/id3/Makefile13
-rw-r--r--firmware/test/kernel/Makefile52
-rw-r--r--firmware/test/kernel/app.lds36
-rw-r--r--firmware/test/kernel/main.c104
-rw-r--r--firmware/test/snprintf/Makefile16
-rw-r--r--firmware/test/snprintf/test.c16
31 files changed, 0 insertions, 3748 deletions
diff --git a/firmware/test/buflib/Makefile b/firmware/test/buflib/Makefile
deleted file mode 100644
index 33191c6cbe..0000000000
--- a/firmware/test/buflib/Makefile
+++ /dev/null
@@ -1,67 +0,0 @@
1FIRMWARE=../..
2
3CC ?= gcc
4# Note: Don't be fooled by MEMORYSIZE here
5# We have a fixed, predictable buffer in UT_core_allocator_init()
6CFLAGS += -g -O2 -DDEBUG -D__PCTOOL__ -DBUFLIB_UNIT_TEST -DMEMORYSIZE=8 -DBUFLIB_DEBUG_BLOCKS -std=gnu99 -I$(FIRMWARE)/include -I$(FIRMWARE)/export -I.
7LDFLAGS += -L. -lpthread
8
9.PHONY: clean all
10
11TARGETS_OBJ = test_main.o \
12 test_main2.o \
13 test_move.o \
14 test_move2.o \
15 test_max.o \
16 test_shrink.o \
17 test_shrink_unaligned.o \
18 test_shrink_startchanged.o \
19 test_shrink_cb.o
20
21TARGETS = $(TARGETS_OBJ:.o=)
22
23LIB_OBJ = buflib.o \
24 core_alloc.o \
25 crc32.o \
26 strlcpy.o \
27 util.o
28
29LIB_FILE = libbuflib.a
30LIB = buflib
31
32
33ifndef V
34SILENT:=@
35else
36VERBOSEOPT:=-v
37endif
38
39PRINTS=$(SILENT)$(call info,$(1))
40
41all: $(TARGETS)
42
43test_%: test_%.o $(LIB_FILE)
44 $(call PRINTS,LD $@)$(CC) $(LDFLAGS) -o $@ $< -l$(LIB)
45
46$(TARGETS): $(TARGETS_OBJ) $(LIB_FILE)
47
48buflib.o: $(FIRMWARE)/buflib.c
49 $(CC) $(CFLAGS) -c $< -o $@
50
51core_alloc.o: $(FIRMWARE)/core_alloc.c
52 $(CC) $(CFLAGS) -c $< -o $@
53
54crc32.o: $(FIRMWARE)/common/crc32.c
55 $(CC) $(CFLAGS) -c $< -o $@
56
57strlcpy.o: $(FIRMWARE)/common/strlcpy.c
58 $(CC) $(CFLAGS) -c $< -o $@
59
60%.o: %.c
61 $(call PRINTS,CC $<)$(CC) $(CFLAGS) -c $<
62
63$(LIB_FILE): $(LIB_OBJ)
64 $(call PRINTS,AR $@)ar rcs $@ $^
65
66clean:
67 rm *.o $(TARGETS) $(LIB_FILE)
diff --git a/firmware/test/buflib/autoconf.h b/firmware/test/buflib/autoconf.h
deleted file mode 100644
index abfaa482e1..0000000000
--- a/firmware/test/buflib/autoconf.h
+++ /dev/null
@@ -1,2 +0,0 @@
1/* Define endianess for the target or simulator platform */
2#define ROCKBOX_LITTLE_ENDIAN 1
diff --git a/firmware/test/buflib/system-hosted.h b/firmware/test/buflib/system-hosted.h
deleted file mode 100644
index 40b5ea8f9f..0000000000
--- a/firmware/test/buflib/system-hosted.h
+++ /dev/null
@@ -1,43 +0,0 @@
1/***************************************************************************
2* __________ __ ___.
3* Open \______ \ ____ ____ | | _\_ |__ _______ ___
4* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7* \/ \/ \/ \/ \/
8* $Id$
9*
10* Copyright (C) 2015 Thomas Jarosch
11*
12* Loosely based upon rbcodecplatform-unix.h from rbcodec
13*
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.
18*
19* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20* KIND, either express or implied.
21*
22****************************************************************************/
23
24#ifndef _COMMON_UNITTEST_H
25#define _COMMON_UNITTEST_H
26
27/* debugf, logf */
28#define debugf(...) fprintf(stderr, __VA_ARGS__)
29
30#ifndef logf
31#define logf(...) do { fprintf(stderr, __VA_ARGS__); \
32 putc('\n', stderr); \
33 } while (0)
34#endif
35
36#ifndef panicf
37#define panicf(...) do { fprintf(stderr, __VA_ARGS__); \
38 putc('\n', stderr); \
39 exit(-1); \
40 } while (0)
41#endif
42
43#endif /* _COMMON_UNITTEST_H */
diff --git a/firmware/test/buflib/test_main.c b/firmware/test/buflib/test_main.c
deleted file mode 100644
index 83b95e4341..0000000000
--- a/firmware/test/buflib/test_main.c
+++ /dev/null
@@ -1,88 +0,0 @@
1/***************************************************************************
2* __________ __ ___.
3* Open \______ \ ____ ____ | | _\_ |__ _______ ___
4* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7* \/ \/ \/ \/ \/
8* $Id$
9*
10* Copyright (C) 2011 Thomas Martitz
11*
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.
16*
17* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18* KIND, either express or implied.
19*
20****************************************************************************/
21
22#include <stdio.h>
23#include <stdlib.h>
24#include "buflib.h"
25#include "util.h"
26
27#define BUFLIB_BUFFER_SIZE (12<<10)
28static char buflib_buffer[BUFLIB_BUFFER_SIZE];
29static struct buflib_context ctx;
30#define assert(x) do { if (!(x)) exit(1); } while(0)
31
32int move_callback(int handle, void* current, void* new)
33{
34 (void)handle;(void)current;(void)new;
35 printf("Move!\n");
36}
37
38int shrink_callback(int handle, unsigned hints, void* start, size_t old_size)
39{
40 (void)handle;(void)start;(void)old_size;(void)hints;
41 printf("Shrink");
42}
43
44struct buflib_callbacks ops = {
45 .move_callback = move_callback,
46 .shrink_callback = shrink_callback,
47};
48
49int main(int argc, char **argv)
50{
51 buflib_init(&ctx, buflib_buffer, BUFLIB_BUFFER_SIZE);
52
53 int id = buflib_alloc_ex(&ctx, 512, "foo", &ops);
54 int id2 = buflib_alloc_ex(&ctx, 1024, "bar", &ops);
55 int id3 = buflib_alloc_ex(&ctx, 8<<10, "8K", &ops);
56
57 assert(id > 0 && id2 > 0 && id3 > 0);
58
59 #define STR "<TEST>"
60 strncpy(buflib_get_data(&ctx, id3), STR, sizeof STR);
61 if (id > 0)
62 {
63 buflib_print_allocs(&ctx, &print_handle);
64 buflib_free(&ctx, id);
65 buflib_print_allocs(&ctx, &print_handle);
66 buflib_free(&ctx, id2);
67 buflib_print_allocs(&ctx, &print_handle);
68
69 id = buflib_alloc_ex(&ctx, 3<<10, "should compact", &ops);
70 if (id <= 0) printf("compacting alloc failed\n");
71
72 buflib_print_allocs(&ctx, &print_handle);
73
74 printf("id I: %p\n", buflib_get_data(&ctx, id3));
75 id2 = buflib_alloc_ex(&ctx, 3<<10, "should fail", &ops);
76 printf("id II: %p\n", buflib_get_data(&ctx, id3));
77 if (id2 <= 0) printf("failing alloc failed\n");
78 else buflib_free(&ctx, id2);
79
80 if (id > 0)
81 buflib_free(&ctx, id);
82
83 printf("Check string: \"%s\"\n", buflib_get_data(&ctx, id3));
84 buflib_print_allocs(&ctx, &print_handle);
85 }
86
87 return 0;
88}
diff --git a/firmware/test/buflib/test_main2.c b/firmware/test/buflib/test_main2.c
deleted file mode 100644
index da6b1366e7..0000000000
--- a/firmware/test/buflib/test_main2.c
+++ /dev/null
@@ -1,108 +0,0 @@
1/***************************************************************************
2* __________ __ ___.
3* Open \______ \ ____ ____ | | _\_ |__ _______ ___
4* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7* \/ \/ \/ \/ \/
8* $Id$
9*
10* Copyright (C) 2011 Thomas Martitz
11*
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.
16*
17* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18* KIND, either express or implied.
19*
20****************************************************************************/
21#include <stdio.h>
22#include <stdlib.h>
23#include "core_alloc.h"
24#include "util.h"
25
26/*
27 * Expected output (64-bit):
28-------------------
29-------------------
30*/
31
32#define error(...) do { printf(__VA_ARGS__); exit(1); } while(0)
33static int move_callback(int handle, void* old, void* new)
34{
35 printf("MOVED!\n");
36 return BUFLIB_CB_OK;
37}
38
39static int shrink_callback(int handle, unsigned hints, void* start, size_t size)
40{
41 char* buf = start;
42
43 size_t wanted = hints & BUFLIB_SHRINK_SIZE_MASK;
44
45 if (handle == 4)
46 {
47 buf+=1, size-=1;
48 memmove(buf, buf-1, (size < 20) ? size : 20);
49 core_shrink(handle, buf, size);
50 return BUFLIB_CB_OK;
51 }
52 return BUFLIB_CB_CANNOT_SHRINK;
53}
54
55static struct buflib_callbacks ops = {
56 .move_callback = move_callback,
57 .shrink_callback = shrink_callback,
58};
59
60static struct buflib_callbacks ops2 = {
61 .move_callback = NULL,
62 .shrink_callback = shrink_callback,
63};
64
65int main(void)
66{
67 size_t size2, size4;
68 UT_core_allocator_init();
69
70 printf("available: %zu\n", core_available());
71 int first = core_alloc("first, fixed", 4<<10);
72 if (first <= 0) error("first failed\n");
73
74 printf("available: %zu\n", core_available());
75 int second = core_alloc_maximum("second, var", &size2, &ops);
76 if (second <= 0) error("second failed\n");
77 printf("second size: %zu\n", size2);
78
79 strcpy(core_get_data(second), "begin");
80 strcpy(core_get_data(second)+124, "end");
81 printf("%s\n", core_get_name(second));
82 if (!core_shrink(second, core_get_data(second), 128))
83 error("shrink second failed\n");
84
85 int third = core_alloc("third, fixed", 20<<10);
86 if (third <= 0) error("third failed");
87 strcpy(core_get_data(third), "third");
88
89 printf("available: %zu\n", core_available());
90 int fourth = core_alloc_maximum("fourth", &size4, &ops2);
91 if (fourth <= 0) error("fourth failed\n");
92 core_print_blocks(&print_simple);
93 if (!core_shrink(fourth, core_get_data(fourth)+(5<<10), size4-(5<<10)))
94 {
95 error("shrink fourth failed\n");
96 }
97 sprintf(core_get_data(fourth), "fourth size: %zu", size4);
98 core_print_blocks(&print_simple);
99
100 int fifth = core_alloc("fifth, fixed", 6<<10);
101 if (fifth <= 0) error("fifth failed\n");
102
103 printf("%s\n", core_get_data(fourth));
104 core_print_blocks(&print_simple);
105 core_print_allocs(&print_simple);
106
107 return 0;
108}
diff --git a/firmware/test/buflib/test_max.c b/firmware/test/buflib/test_max.c
deleted file mode 100644
index 5378fcf6bd..0000000000
--- a/firmware/test/buflib/test_max.c
+++ /dev/null
@@ -1,75 +0,0 @@
1/***************************************************************************
2* __________ __ ___.
3* Open \______ \ ____ ____ | | _\_ |__ _______ ___
4* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7* \/ \/ \/ \/ \/
8* $Id$
9*
10* Copyright (C) 2011 Thomas Martitz
11*
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.
16*
17* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18* KIND, either express or implied.
19*
20****************************************************************************/
21#include <stdio.h>
22#include "core_alloc.h"
23#include "util.h"
24
25
26/*
27 * Expected output (64bit):
28-------------------
29get_all(1): 0x6027a0
30 0x6027c8
31 6424
32get_all(1): 0x6027a0
33 0x6027c8
34 3232
35get_all(1): 0x6027a0
36 0x6027c8
37 3232
38dont freeze(2): 0x603440
39 0x603470
40 152
410x6027a0: val: 404 (get_all)
420x603440: val: 19 (dont freeze)
43-------------------
44*/
45struct buflib_callbacks ops;
46int main(void)
47{
48 UT_core_allocator_init();
49 size_t size;
50 int handle = core_alloc_maximum("get_all", &size, &ops);
51
52 if (handle <= 0)
53 printf("core_alloc_maximum error\n");
54 int handle2;
55
56 core_print_allocs(&print_simple);
57
58 /* this should freeze */
59 // core_alloc("freeze", 100);
60 core_shrink(handle, core_get_data(handle), size/2);
61
62 core_print_allocs(&print_simple);
63
64 /* this should not freeze anymore */
65 handle2 = core_alloc("dont freeze", 100);
66 if (handle2 <= 0)
67 printf("handle 2 failed!\n");
68
69 core_print_allocs(&print_simple);
70 core_print_blocks(&print_simple);
71
72 core_free(handle);
73 core_free(handle2);
74 return 0;
75}
diff --git a/firmware/test/buflib/test_move.c b/firmware/test/buflib/test_move.c
deleted file mode 100644
index cf6168a311..0000000000
--- a/firmware/test/buflib/test_move.c
+++ /dev/null
@@ -1,63 +0,0 @@
1/***************************************************************************
2* __________ __ ___.
3* Open \______ \ ____ ____ | | _\_ |__ _______ ___
4* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7* \/ \/ \/ \/ \/
8* $Id$
9*
10* Copyright (C) 2011 Thomas Martitz
11*
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.
16*
17* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18* KIND, either express or implied.
19*
20****************************************************************************/
21#include <stdio.h>
22#include "core_alloc.h"
23#include "util.h"
24
25static int move_size;
26int move_callback(int handle, void* old, void* new)
27{
28 move_size = (char*)old-(char*)new;
29 printf("Move! %s, %p, %p, %zu\n", core_get_name(handle), old, new,
30 move_size);
31
32 return BUFLIB_CB_OK;
33}
34
35struct buflib_callbacks ops = {
36 .move_callback = move_callback,
37 .shrink_callback = NULL,
38};
39
40int main(void)
41{
42 UT_core_allocator_init();
43
44 int first = core_alloc("first", 20<<10);
45 int second= core_alloc_ex("second", 20<<10, &ops);
46 strcpy(core_get_data(second), "Here's data");
47
48 core_free(first);
49 /* should not trigger compaction, but replace the just freed one */
50 int third = core_alloc("third", 20<<10);
51 core_free(third);
52 /* should trigger compaction since it's a bit bigger than the just freed one */
53 int fourth = core_alloc("fourth", 21<<10);
54
55 int ret = !(!strcmp(core_get_data(second), "Here's data") && move_size >= 20<<10);
56
57 core_print_blocks(&print_simple);
58
59 core_free(second);
60 core_free(third);
61
62 return ret;
63}
diff --git a/firmware/test/buflib/test_move2.c b/firmware/test/buflib/test_move2.c
deleted file mode 100644
index 2f72850b2b..0000000000
--- a/firmware/test/buflib/test_move2.c
+++ /dev/null
@@ -1,132 +0,0 @@
1/***************************************************************************
2* __________ __ ___.
3* Open \______ \ ____ ____ | | _\_ |__ _______ ___
4* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7* \/ \/ \/ \/ \/
8* $Id$
9*
10* Copyright (C) 2011 Thomas Martitz
11*
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.
16*
17* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18* KIND, either express or implied.
19*
20****************************************************************************/
21#include <stdio.h>
22#include "core_alloc.h"
23#include "util.h"
24/*
25 * Expected output (64bit)
26--------------------
27after freeing first: available: 10040
28after freeing forth: available: 10040
29buflib_compact(): Compacting!
30move_block(): moving "third"(id=3) by -3210(-25680)
31Move! third, 0x608758, 0x602308, 25680
32Cannot move now for handle 3
33fifth failed. Retrying...
34buflib_compact(): Compacting!
35move_block(): moving "third"(id=3) by -3210(-25680)
36Move! third, 0x608758, 0x602308, 25680
37fifth handle: 1
38fifth(1): 0x608730
39 0x608758
40 21544
41second(2): 0x607308
42 0x607330
43 5160
44third(3): 0x6022e0
45 0x602308
46 15400
47sixth(4): 0x605f08
48 0x605f30
49 2088
50seventh(5): 0x606730
51 0x606758
52 552
530x6022e0: val: 1925 (third)
540x605f08: val: 261 (sixth)
550x606730: val: 69 (seventh)
560x606958: val: -310 (<unallocated>)
570x607308: val: 645 (second)
580x608730: val: 2693 (fifth)
59--------------------
60*/
61
62static int move_size, retry;
63int move_callback(int handle, void* old, void* new)
64{
65 move_size = (char*)old-(char*)new;
66 printf("Move! %s, %p, %p, %d\n", core_get_name(handle), old, new,
67 move_size);
68
69 if (!retry)
70 {
71 retry = 1;
72 printf("Cannot move now for handle %d\n", handle);
73 return BUFLIB_CB_CANNOT_MOVE;
74 }
75 return BUFLIB_CB_OK;
76}
77
78struct buflib_callbacks ops = {
79 .move_callback = move_callback,
80 .shrink_callback = NULL,
81};
82
83static struct buflib_callbacks ops_no_move = {
84 .move_callback = NULL,
85 .shrink_callback = NULL,
86};
87
88int main(void)
89{
90 UT_core_allocator_init();
91
92 int first = core_alloc("first", 20<<10);
93 int second= core_alloc_ex("second", 5<<10, &ops_no_move);
94 int third = core_alloc_ex("third", 15<<10, &ops);
95 strcpy(core_get_data(second), "Here's data");
96
97 core_free(first);
98 printf("after freeing first: available: %zu\n", core_available());
99 /* should not trigger compaction, but replace the just freed one */
100 int fourth = core_alloc("forth", 20<<10);
101 core_free(fourth);
102 printf("after freeing forth: available: %zu\n", core_available());
103 /* should trigger compaction since it's a bit bigger than the just freed one */
104 int fifth = core_alloc("fifth", 21<<10);
105 if (fifth <= 0)
106 {
107 printf("fifth failed. Retrying...\n");
108 fifth = core_alloc("fifth", 21<<10);
109 }
110 if (fifth <= 0)
111 {
112 printf("fifth still failed\n");
113 }
114
115 printf("fifth handle: %d\n", fifth);
116 int sixth = core_alloc("sixth", 2<<10);
117 int seventh = core_alloc("seventh", 512);
118
119
120 core_print_allocs(&print_simple);
121 core_print_blocks(&print_simple);
122 int ret = !(!strcmp(core_get_data(second), "Here's data") && move_size >= 20<<10);
123
124 core_free(second);
125 core_free(third);
126 if (fifth > 0)
127 core_free(fifth);
128 core_free(sixth);
129 core_free(seventh);
130
131 return ret;
132}
diff --git a/firmware/test/buflib/test_shrink.c b/firmware/test/buflib/test_shrink.c
deleted file mode 100644
index 7424f56d51..0000000000
--- a/firmware/test/buflib/test_shrink.c
+++ /dev/null
@@ -1,56 +0,0 @@
1/***************************************************************************
2* __________ __ ___.
3* Open \______ \ ____ ____ | | _\_ |__ _______ ___
4* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7* \/ \/ \/ \/ \/
8* $Id$
9*
10* Copyright (C) 2011 Thomas Martitz
11*
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.
16*
17* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18* KIND, either express or implied.
19*
20****************************************************************************/
21#include <stdio.h>
22#include "core_alloc.h"
23#include "util.h"
24
25/*
26 * Expected output:
27-------------------
280x602520: val: 1285 (first)
290x604d48: val: -32 (<unallocated>)
300x604e48: val: 1221 (second)
310x607470: val: -32 (<unallocated>)
320x607570: val: 1285 (third)
33-------------------
34*/
35struct buflib_callbacks ops;
36
37int main(void)
38{
39 UT_core_allocator_init();
40
41 int first = core_alloc("first", 10<<10);
42 int second = core_alloc("second", 10<<10);
43 int third = core_alloc("third", 10<<10);
44
45 strcpy((char*)core_get_data(second)+0x100, "foobar");
46 core_shrink(second, (char*)core_get_data(second)+0x100, (10<<10)-0x200);
47 core_print_blocks(&print_simple);
48
49 int ret = strcmp(core_get_data(second), "foobar");
50
51 core_free(first);
52 core_free(second);
53 core_free(third);
54
55 return ret;
56}
diff --git a/firmware/test/buflib/test_shrink_cb.c b/firmware/test/buflib/test_shrink_cb.c
deleted file mode 100644
index 8c2c02ed1c..0000000000
--- a/firmware/test/buflib/test_shrink_cb.c
+++ /dev/null
@@ -1,108 +0,0 @@
1/***************************************************************************
2* __________ __ ___.
3* Open \______ \ ____ ____ | | _\_ |__ _______ ___
4* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7* \/ \/ \/ \/ \/
8* $Id$
9*
10* Copyright (C) 2011 Thomas Martitz
11*
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.
16*
17* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18* KIND, either express or implied.
19*
20****************************************************************************/
21#include <stdio.h>
22#include <stdlib.h>
23#include "core_alloc.h"
24#include "util.h"
25
26/*
27 * Expected output (64-bit):
28-------------------
29MOVED!
300x6032e0: val: 1285 (first)
310x605b08: val: 1285 (third)
320x608330: val: 1413 (fourth)
330x60af58: val: 2181 (fifth)
34SHRINK! 517
35MOVED!
360x6032e0: val: 1285 (first)
370x605b08: val: 645 (third)
380x606f30: val: 1413 (fourth)
390x609b58: val: 2181 (fifth)
400x60df80: val: 517 (sixth)
41-------------------
42*/
43
44#define error(...) do { printf(__VA_ARGS__); exit(1); } while(0)
45static int move_callback(int handle, void* old, void* new)
46{
47 printf("MOVED!\n");
48 return BUFLIB_CB_OK;
49}
50
51static int shrink_callback(int handle, unsigned hints, void* start, size_t size)
52{
53 char* buf = start;
54 size /= 2;
55
56 printf("SHRINK! %u\n", hints);
57
58 memmove(buf + size/2, buf, size);
59 if (core_shrink(handle, buf + size/2, size))
60 {
61 return BUFLIB_CB_OK;
62 }
63 return BUFLIB_CB_CANNOT_SHRINK;
64}
65
66struct buflib_callbacks ops = {
67 .move_callback = move_callback,
68 .shrink_callback = shrink_callback,
69};
70
71int main(void)
72{
73 UT_core_allocator_init();
74
75 int first = core_alloc("first", 10<<10);
76 int second = core_alloc("second", 10<<10);
77 int third = core_alloc_ex("third", 10<<10, &ops);
78
79 strcpy(core_get_data(third), "third");
80
81 core_free(second);
82 int fourth = core_alloc("fourth", 11<<10);
83 strcpy(core_get_data(fourth), "fourth");
84
85 /* this should cause MOVED! twice */
86 int fifth = core_alloc("fifth", 17<<10);
87 if (fifth <= 0) error("fifth failed\n");
88 strcpy(core_get_data(fifth), "fifth");
89
90 core_print_blocks(&print_simple);
91 int sixth = core_alloc("sixth", 4<<10);
92 if (sixth <= 0) error("sixth failed\n");
93 strcpy(core_get_data(sixth), "sixth");
94
95 core_print_blocks(&print_simple);
96
97 int ret = strcmp(core_get_data(third), "third")
98 || strcmp(core_get_data(fourth), "fourth")
99 || strcmp(core_get_data(fifth), "fifth")
100 || strcmp(core_get_data(sixth), "sixth");
101 core_free(first);
102 core_free(third);
103 core_free(fourth);
104 core_free(fifth);
105 core_free(sixth);
106
107 return ret;
108}
diff --git a/firmware/test/buflib/test_shrink_startchanged.c b/firmware/test/buflib/test_shrink_startchanged.c
deleted file mode 100644
index 63b864db88..0000000000
--- a/firmware/test/buflib/test_shrink_startchanged.c
+++ /dev/null
@@ -1,59 +0,0 @@
1/***************************************************************************
2* __________ __ ___.
3* Open \______ \ ____ ____ | | _\_ |__ _______ ___
4* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7* \/ \/ \/ \/ \/
8* $Id$
9*
10* Copyright (C) 2011 Thomas Martitz
11*
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.
16*
17* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18* KIND, either express or implied.
19*
20****************************************************************************/
21#include <stdio.h>
22#include "core_alloc.h"
23#include "util.h"
24
25/*
26 * Expected output:
27-------------------
280x602620: val: 1285 (first)
290x604e48: val: -32 (<unallocated>)
300x604f48: val: 1253 (second)
310x607670: val: 1285 (third)
32-------------------
33*/
34struct buflib_callbacks ops;
35
36int main(void)
37{
38 UT_core_allocator_init();
39
40 int first = core_alloc("first", 10<<10);
41 int second = core_alloc("second", 10<<10);
42 int third = core_alloc("third", 10<<10);
43
44 strcpy(core_get_data(third), "baz");
45
46 strcpy((char*)core_get_data(second)+0x102, "foobar");
47 core_shrink(second, (char*)core_get_data(second)+0x102, (10<<10)-0x102);
48 memset(core_get_data(second) + sizeof("foobar"), 0, (10<<10)-0x102-sizeof("foobar"));
49 core_print_blocks(&print_simple);
50
51 int ret = strcmp(core_get_data(second), "foobar")
52 || strcmp(core_get_data(third), "baz");
53
54 core_free(first);
55 core_free(second);
56 core_free(third);
57
58 return ret;
59}
diff --git a/firmware/test/buflib/test_shrink_unaligned.c b/firmware/test/buflib/test_shrink_unaligned.c
deleted file mode 100644
index 0f07685f65..0000000000
--- a/firmware/test/buflib/test_shrink_unaligned.c
+++ /dev/null
@@ -1,56 +0,0 @@
1/***************************************************************************
2* __________ __ ___.
3* Open \______ \ ____ ____ | | _\_ |__ _______ ___
4* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7* \/ \/ \/ \/ \/
8* $Id$
9*
10* Copyright (C) 2011 Thomas Martitz
11*
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.
16*
17* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18* KIND, either express or implied.
19*
20****************************************************************************/
21#include <stdio.h>
22#include "core_alloc.h"
23#include "util.h"
24
25/*
26 * Expected output:
27-------------------
280x602520: val: 1285 (first)
290x604d48: val: -32 (<unallocated>)
300x604e48: val: 1222 (second)
310x607470: val: -31 (<unallocated>)
320x607570: val: 1285 (third)
33-------------------
34*/
35struct buflib_callbacks ops;
36
37int main(void)
38{
39 UT_core_allocator_init();
40
41 int first = core_alloc("first", 10<<10);
42 int second = core_alloc("second", 10<<10);
43 int third = core_alloc("third", 10<<10);
44
45 strcpy((char*)core_get_data(second)+0x102, "foobar");
46 core_shrink(second, (char*)core_get_data(second)+0x102, (10<<10)-0x200);
47 core_print_blocks(&print_simple);
48
49 int ret = strcmp(core_get_data(second), "foobar");
50
51 core_free(first);
52 core_free(second);
53 core_free(third);
54
55 return ret;
56}
diff --git a/firmware/test/buflib/util.c b/firmware/test/buflib/util.c
deleted file mode 100644
index 66a02e8a0d..0000000000
--- a/firmware/test/buflib/util.c
+++ /dev/null
@@ -1,61 +0,0 @@
1/***************************************************************************
2* __________ __ ___.
3* Open \______ \ ____ ____ | | _\_ |__ _______ ___
4* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7* \/ \/ \/ \/ \/
8* $Id$
9*
10* Copyright (C) 2015 Thomas Jarosch
11*
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.
16*
17* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18* KIND, either express or implied.
19*
20****************************************************************************/
21#include "util.h"
22#include "stdio.h"
23#include "buflib.h"
24#include "system.h"
25
26void print_simple(const char *str)
27{
28 printf("%s\n", str);
29}
30
31void print_handle(int handle_num, const char *str)
32{
33 (void)handle_num;
34 printf("%s\n", str);
35}
36
37/* fake core_allocator_init() with a fixed 50kb buffer size */
38void UT_core_allocator_init()
39{
40 extern struct buflib_context core_ctx;
41 static char buf[50<<10];
42 unsigned char *raw_start = buf;
43 unsigned char *aligned_start = ALIGN_UP(raw_start, sizeof(intptr_t));
44
45 buflib_init(&core_ctx, aligned_start, sizeof(buf) - (aligned_start - raw_start));
46}
47
48/* TODO: those should be part of core_alloc */
49void core_print_blocks(void (*print)(const char*))
50{
51 (void)print;
52 extern struct buflib_context core_ctx;
53 buflib_print_blocks(&core_ctx, &print_handle);
54}
55
56void core_print_allocs(void (*print)(const char*))
57{
58 (void)print;
59 extern struct buflib_context core_ctx;
60 buflib_print_allocs(&core_ctx, &print_handle);
61}
diff --git a/firmware/test/buflib/util.h b/firmware/test/buflib/util.h
deleted file mode 100644
index 1b03bbbed5..0000000000
--- a/firmware/test/buflib/util.h
+++ /dev/null
@@ -1,30 +0,0 @@
1/***************************************************************************
2* __________ __ ___.
3* Open \______ \ ____ ____ | | _\_ |__ _______ ___
4* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7* \/ \/ \/ \/ \/
8* $Id$
9*
10* Copyright (C) 2015 Thomas Jarosch
11*
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.
16*
17* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18* KIND, either express or implied.
19*
20****************************************************************************/
21
22#ifndef _TEST_UTIL_H
23#define _TEST_UTIL_H
24
25void print_simple(const char *string);
26void print_handle(int handle_num, const char *string);
27
28void UT_core_allocator_init();
29
30#endif
diff --git a/firmware/test/fat/Makefile b/firmware/test/fat/Makefile
deleted file mode 100644
index 38bce0bde1..0000000000
--- a/firmware/test/fat/Makefile
+++ /dev/null
@@ -1,49 +0,0 @@
1SECTOR_SIZE = 512
2FIRMWARE = ../..
3
4DRIVERS = ../../drivers
5EXPORT = ../../export
6
7BUILDDATE=$(shell date -u +'-DYEAR=%Y -DMONTH=%m -DDAY=%d')
8INCLUDE = -I$(EXPORT) -I$(FIRMWARE)/include -I$(FIRMWARE)/target/hosted -I$(FIRMWARE)/target/hosted/sdl
9DEFINES = -DTEST_FAT -DDEBUG -DDISK_WRITE -DHAVE_FAT16SUPPORT -D__PCTOOL__
10
11CFLAGS = -g -Wall -std=gnu99 -Wno-pointer-sign $(DEFINES) $(BUILDDATE) -I. $(INCLUDE) -I$(FIRMWARE)/libc/include -DROCKBOX_DIR='".rockbox"' -DSECTOR_SIZE=$(SECTOR_SIZE)
12SIMFLAGS = -g -Wall -std=gnu99 -Wno-pointer-sign $(DEFINES) -I. $(INCLUDE) -DSECTOR_SIZE=$(SECTOR_SIZE)
13
14TARGET = fat
15
16all: $(TARGET)
17
18$(TARGET): fat.o ata-sim.o main.o disk.o dir.o file.o ctype.o unicode.o strlcpy.o
19 gcc -g -o fat $+
20
21fat.o: $(DRIVERS)/fat.c $(EXPORT)/fat.h $(EXPORT)/ata.h
22 $(CC) $(CFLAGS) -c $< -o $@
23
24ctype.o: $(FIRMWARE)/libc/ctype.c
25 $(CC) $(CFLAGS) -c $< -o $@
26
27disk.o: $(FIRMWARE)/common/disk.c
28 $(CC) $(CFLAGS) -c $< -o $@
29
30dir.o: $(FIRMWARE)/common/dir_uncached.c
31 $(CC) $(CFLAGS) -c $< -o $@
32
33file.o: $(FIRMWARE)/common/file.c
34 $(CC) $(CFLAGS) -c $< -o $@
35
36unicode.o: $(FIRMWARE)/common/unicode.c
37 $(CC) $(CFLAGS) -c $< -o $@
38
39strlcpy.o: $(FIRMWARE)/common/strlcpy.c
40 $(CC) $(CFLAGS) -c $< -o $@
41
42ata-sim.o: ata-sim.c $(EXPORT)/ata.h
43 $(CC) $(SIMFLAGS) -c $< -o $@
44
45main.o: main.c $(EXPORT)/ata.h
46 $(CC) $(SIMFLAGS) -c $< -o $@
47
48clean:
49 rm -f *.o $(TARGET)
diff --git a/firmware/test/fat/README b/firmware/test/fat/README
deleted file mode 100644
index 58ffe7ffa8..0000000000
--- a/firmware/test/fat/README
+++ /dev/null
@@ -1,32 +0,0 @@
1This code is for testing the Rockbox fat code on a dummy drive image file.
2
3Dummy image
4-----------
5Here's how to create a 1 gig dummy drive image in linux:
6
7# dd if=/dev/hda of=disk.img bs=1M count=1024
8
9You can then format disk.img as a FAT32 partition:
10
11# mkdosfs -F 32 disk.img
12
13To mount the image, your linux kernel must include the loopback device:
14
15# mount -o loop disk.img /mnt/image
16
17Now copy some test data to the disk, umount it and start testing.
18
19The test script mounts the disk image in order to initialize it will a number
20of dummy files. Since users are no longer allowed to mount loopback devices,
21you can either run the test script as root (not recommended) or add a line to
22your fstab file:
23
24/path/to/disk.img /mnt/dummy vfat loop,users,noauto 0 0
25
26
27Test code
28---------
29The files in this dir build the 'fat' program. It will read 'disk.img' and
30treat is as a real disk, thanks to the ata-sim.c module.
31
32Modify the main.c source code to make it perform the tests you want.
diff --git a/firmware/test/fat/ata-sim.c b/firmware/test/fat/ata-sim.c
deleted file mode 100644
index 07b772f433..0000000000
--- a/firmware/test/fat/ata-sim.c
+++ /dev/null
@@ -1,68 +0,0 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include "debug.h"
5
6static FILE* file;
7
8void panicf( const char *fmt, ... );
9
10int storage_read_sectors(unsigned long start, int count, void* buf)
11{
12 if ( count > 1 )
13 DEBUGF("[Reading %d blocks: 0x%lx to 0x%lx]\n",
14 count, start, start+count-1);
15 else
16 DEBUGF("[Reading block 0x%lx]\n", start);
17
18 if(fseek(file,start*SECTOR_SIZE,SEEK_SET)) {
19 perror("fseek");
20 return -1;
21 }
22 if(!fread(buf,SECTOR_SIZE,count,file)) {
23 DEBUGF("ata_write_sectors(0x%lx, 0x%x, %p)\n", start, count, buf );
24 perror("fread");
25 panicf("Disk error\n");
26 }
27 return 0;
28}
29
30int storage_write_sectors(unsigned long start, int count, void* buf)
31{
32 if ( count > 1 )
33 DEBUGF("[Writing %d blocks: 0x%lx to 0x%lx]\n",
34 count, start, start+count-1);
35 else
36 DEBUGF("[Writing block 0x%lx]\n", start);
37
38 if (start == 0)
39 panicf("Writing on sector 0!\n");
40
41 if(fseek(file,start*SECTOR_SIZE,SEEK_SET)) {
42 perror("fseek");
43 return -1;
44 }
45 if(!fwrite(buf,SECTOR_SIZE,count,file)) {
46 DEBUGF("ata_write_sectors(0x%lx, 0x%x, %p)\n", start, count, buf );
47 perror("fwrite");
48 panicf("Disk error\n");
49 }
50 return 0;
51}
52
53int ata_init(void)
54{
55 char* filename = "disk.img";
56 /* check disk size */
57 file=fopen(filename,"rb+");
58 if(!file) {
59 fprintf(stderr, "read_disk() - Could not find \"%s\"\n",filename);
60 return -1;
61 }
62 return 0;
63}
64
65void ata_exit(void)
66{
67 fclose(file);
68}
diff --git a/firmware/test/fat/autoconf.h b/firmware/test/fat/autoconf.h
deleted file mode 100644
index e5a91790af..0000000000
--- a/firmware/test/fat/autoconf.h
+++ /dev/null
@@ -1,9 +0,0 @@
1/* fake autoconf for fat testing */
2
3#ifndef __BUILD_AUTOCONF_H
4#define __BUILD_AUTOCONF_H
5
6/* assume little endian for now */
7#define ROCKBOX_LITTLE_ENDIAN 1
8
9#endif
diff --git a/firmware/test/fat/main.c b/firmware/test/fat/main.c
deleted file mode 100644
index e838682b0b..0000000000
--- a/firmware/test/fat/main.c
+++ /dev/null
@@ -1,724 +0,0 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <stdarg.h>
5#include <time.h>
6#include "fat.h"
7#include "debug.h"
8#include "disk.h"
9#include "dir.h"
10#include "file.h"
11#include "ata.h"
12#include "storage.h"
13
14void dbg_dump_sector(int sec);
15void dbg_dump_buffer(unsigned char *buf, int len, int offset);
16void dbg_console(void);
17
18void mutex_init(struct mutex* l) {}
19void mutex_lock(struct mutex* l) {}
20void mutex_unlock(struct mutex* l) {}
21
22void panicf( char *fmt, ...)
23{
24 va_list ap;
25 va_start( ap, fmt );
26 fprintf(stderr,"***PANIC*** ");
27 vfprintf(stderr, fmt, ap );
28 va_end( ap );
29 exit(1);
30}
31
32void debugf(const char *fmt, ...)
33{
34 va_list ap;
35 va_start( ap, fmt );
36 fprintf(stderr,"DEBUGF: ");
37 vfprintf( stderr, fmt, ap );
38 va_end( ap );
39}
40
41void ldebugf(const char* file, int line, const char *fmt, ...)
42{
43 va_list ap;
44 va_start( ap, fmt );
45 fprintf( stderr, "%s:%d ", file, line );
46 vfprintf( stderr, fmt, ap );
47 va_end( ap );
48}
49
50void dbg_dump_sector(int sec)
51{
52 unsigned char buf[SECTOR_SIZE];
53
54 storage_read_sectors(sec,1,buf);
55 DEBUGF("---< Sector %d >-----------------------------------------\n", sec);
56 dbg_dump_buffer(buf, SECTOR_SIZE, 0);
57}
58
59void dbg_dump_buffer(unsigned char *buf, int len, int offset)
60{
61 int i, j;
62 unsigned char c;
63 unsigned char ascii[33];
64
65 for(i = 0;i < len/16;i++)
66 {
67 DEBUGF("%03x: ", i*16 + offset);
68 for(j = 0;j < 16;j++)
69 {
70 c = buf[i*16+j];
71
72 DEBUGF("%02x ", c);
73 if(c < 32 || c > 127)
74 {
75 ascii[j] = '.';
76 }
77 else
78 {
79 ascii[j] = c;
80 }
81 }
82
83 ascii[j] = 0;
84 DEBUGF("%s\n", ascii);
85 }
86}
87
88void dbg_dir(char* currdir)
89{
90 DIR* dir;
91 struct dirent* entry;
92
93 dir = opendir(currdir);
94 if (dir)
95 {
96 while ( (entry = readdir(dir)) ) {
97 DEBUGF("%15s %lx\n", entry->d_name, entry->startcluster);
98 }
99 closedir(dir);
100 }
101 else
102 {
103 DEBUGF( "Could not open dir %s\n", currdir);
104 }
105}
106
107#define CHUNKSIZE 8
108#define BUFSIZE 8192
109
110int dbg_mkfile(char* name, int num)
111{
112 char text[BUFSIZE+1];
113 int i;
114 int fd;
115 int x=0;
116 bool stop = false;
117
118 fd = creat(name,O_WRONLY);
119 if (fd<0) {
120 DEBUGF("Failed creating file\n");
121 return -1;
122 }
123 num *= 1024;
124 while ( num ) {
125 int rc;
126 int len = num > BUFSIZE ? BUFSIZE : num;
127
128 for (i=0; i<len/CHUNKSIZE; i++ )
129 sprintf(text+i*CHUNKSIZE,"%c%06x,",name[1],x++);
130
131 rc = write(fd, text, len);
132 if ( rc < 0 ) {
133 DEBUGF("Failed writing data\n");
134 return -1;
135 }
136 else
137 if ( rc == 0 ) {
138 DEBUGF("No space left\n");
139 return -2;
140 }
141 else
142 DEBUGF("wrote %d bytes\n",rc);
143
144 num -= len;
145
146 if ( !num ) {
147 if ( stop )
148 break;
149
150 /* add a random number of chunks to test byte-copy code */
151 num = ((int) rand() % SECTOR_SIZE) & ~7;
152 LDEBUGF("Adding random size %d\n",num);
153 stop = true;
154 }
155 }
156
157 return close(fd);
158}
159
160
161int dbg_chkfile(char* name, int size)
162{
163 char text[81920];
164 int i;
165 int x=0;
166 int pos = 0;
167 int block=0;
168 int fd = open(name,O_RDONLY);
169 if (fd<0) {
170 DEBUGF("Failed opening file\n");
171 return -1;
172 }
173
174 size = lseek(fd, 0, SEEK_END);
175 DEBUGF("File is %d bytes\n", size);
176 /* random start position */
177 if ( size )
178 pos = ((int)rand() % size) & ~7;
179 lseek(fd, pos, SEEK_SET);
180 x = pos / CHUNKSIZE;
181
182 LDEBUGF("Check base is %x (%d)\n",x,pos);
183
184 while (1) {
185 int rc = read(fd, text, sizeof text);
186 DEBUGF("read %d bytes\n",rc);
187 if (rc < 0) {
188 panicf("Failed reading data\n");
189 }
190 else {
191 char tmp[CHUNKSIZE+1];
192 if (!rc)
193 break;
194 for (i=0; i<rc/CHUNKSIZE; i++ ) {
195 sprintf(tmp,"%c%06x,",name[1],x++);
196 if (strncmp(text+i*CHUNKSIZE,tmp,CHUNKSIZE)) {
197 int idx = pos + block*sizeof(text) + i*CHUNKSIZE;
198 DEBUGF("Mismatch in byte 0x%x (byte 0x%x of sector 0x%x)."
199 "\nExpected %.8s found %.8s\n",
200 idx, idx % SECTOR_SIZE, idx / SECTOR_SIZE,
201 tmp,
202 text+i*CHUNKSIZE);
203 DEBUGF("i=%x, idx=%x\n",i,idx);
204 dbg_dump_buffer(text+i*CHUNKSIZE - 0x20, 0x40, idx - 0x20);
205 return -1;
206 }
207 }
208 }
209 block++;
210 }
211
212 return close(fd);
213}
214
215int dbg_wrtest(char* name)
216{
217 char text[81920];
218 int i;
219 int x=0;
220 int pos = 0;
221 int block=0;
222 int size, fd, rc;
223 char tmp[CHUNKSIZE+1];
224
225 fd = open(name,O_RDWR);
226 if (fd<0) {
227 DEBUGF("Failed opening file\n");
228 return -1;
229 }
230
231 size = lseek(fd, 0, SEEK_END);
232 DEBUGF("File is %d bytes\n", size);
233 /* random start position */
234 if ( size )
235 pos = ((int)rand() % size) & ~7;
236 rc = lseek(fd, pos, SEEK_SET);
237 if ( rc < 0 )
238 panicf("Failed seeking\n");
239 x = pos / CHUNKSIZE;
240 LDEBUGF("Check base is %x (%d)\n",x,pos);
241
242 sprintf(tmp,"%c%06x,",name[1],x++);
243 rc = write(fd, tmp, 8);
244 if ( rc < 0 )
245 panicf("Failed writing data\n");
246
247 if ( size )
248 pos = ((int)rand() % size) & ~7;
249 rc = lseek(fd, pos, SEEK_SET);
250 if ( rc < 0 )
251 panicf("Failed seeking\n");
252 x = pos / CHUNKSIZE;
253 LDEBUGF("Check base 2 is %x (%d)\n",x,pos);
254
255 while (1) {
256 rc = read(fd, text, sizeof text);
257 DEBUGF("read %d bytes\n",rc);
258 if (rc < 0) {
259 panicf("Failed reading data\n");
260 }
261 else {
262 if (!rc)
263 break;
264 for (i=0; i<rc/CHUNKSIZE; i++ ) {
265 sprintf(tmp,"%c%06x,",name[1],x++);
266 if (strncmp(text+i*CHUNKSIZE,tmp,CHUNKSIZE)) {
267 int idx = pos + block*sizeof(text) + i*CHUNKSIZE;
268 DEBUGF("Mismatch in byte 0x%x (byte 0x%x of sector 0x%x)."
269 "\nExpected %.8s found %.8s\n",
270 idx, idx % SECTOR_SIZE, idx / SECTOR_SIZE,
271 tmp,
272 text+i*CHUNKSIZE);
273 DEBUGF("i=%x, idx=%x\n",i,idx);
274 dbg_dump_buffer(text+i*CHUNKSIZE - 0x20, 0x40, idx - 0x20);
275 return -1;
276 }
277 }
278 }
279 block++;
280 }
281
282 return close(fd);
283}
284
285void dbg_type(char* name)
286{
287 const int size = SECTOR_SIZE*5;
288 unsigned char buf[SECTOR_SIZE*5+1];
289 int fd,rc;
290
291 fd = open(name,O_RDONLY);
292 if (fd<0)
293 return;
294 DEBUGF("Got file descriptor %d\n",fd);
295
296 while ( 1 ) {
297 rc = read(fd, buf, size);
298 if( rc > 0 )
299 {
300 buf[size] = 0;
301 printf("%d: %.*s\n", rc, rc, buf);
302 }
303 else if ( rc == 0 ) {
304 DEBUGF("EOF\n");
305 break;
306 }
307 else
308 {
309 DEBUGF("Failed reading file: %d\n",rc);
310 break;
311 }
312 }
313 close(fd);
314}
315
316int dbg_append(char* name)
317{
318 int x=0;
319 int size, fd, rc;
320 char tmp[CHUNKSIZE+1];
321
322 fd = open(name,O_RDONLY);
323 if (fd<0) {
324 DEBUGF("Failed opening file\n");
325 return -1;
326 }
327
328 size = lseek(fd, 0, SEEK_END);
329 DEBUGF("File is %d bytes\n", size);
330 x = size / CHUNKSIZE;
331 LDEBUGF("Check base is %x (%d)\n",x,size);
332
333 if (close(fd) < 0)
334 return -1;
335
336 fd = open(name,O_RDWR|O_APPEND);
337 if (fd<0) {
338 DEBUGF("Failed opening file\n");
339 return -1;
340 }
341
342 sprintf(tmp,"%c%06x,",name[1],x++);
343 rc = write(fd, tmp, 8);
344 if ( rc < 0 )
345 panicf("Failed writing data\n");
346
347 return close(fd);
348}
349
350int dbg_test(char* name)
351{
352 int x=0;
353 int j;
354 int fd;
355 char text[BUFSIZE+1];
356
357 for (j=0; j<5; j++) {
358 int num = 40960;
359
360 fd = open(name,O_WRONLY|O_CREAT|O_APPEND, 0666);
361 if (fd<0) {
362 DEBUGF("Failed opening file\n");
363 return -1;
364 }
365
366 while ( num ) {
367 int rc, i;
368 int len = num > BUFSIZE ? BUFSIZE : num;
369
370 for (i=0; i<len/CHUNKSIZE; i++ )
371 sprintf(text+i*CHUNKSIZE,"%c%06x,",name[1],x++);
372
373 rc = write(fd, text, len);
374 if ( rc < 0 ) {
375 DEBUGF("Failed writing data\n");
376 return -1;
377 }
378 else
379 if ( rc == 0 ) {
380 DEBUGF("No space left\n");
381 return -2;
382 }
383 else
384 DEBUGF("wrote %d bytes\n",rc);
385
386 num -= len;
387 }
388
389 if (close(fd) < 0)
390 return -1;
391 }
392
393 return 0;
394}
395
396int dbg_dump(char* name, int offset)
397{
398 char buf[SECTOR_SIZE];
399
400 int rc;
401 int fd = open(name,O_RDONLY);
402 if (fd<0) {
403 DEBUGF("Failed opening file\n");
404 return -1;
405 }
406 lseek(fd, offset, SEEK_SET);
407 rc = read(fd, buf, sizeof buf);
408
409 if ( rc < 0 )
410 panicf("Error reading data\n");
411
412 if (close(fd) < 0)
413 return -1;
414
415 dbg_dump_buffer(buf, rc, offset);
416
417 return 0;
418}
419
420void dbg_tail(char* name)
421{
422 unsigned char buf[SECTOR_SIZE*5];
423 int fd,rc;
424
425 fd = open(name,O_RDONLY);
426 if (fd<0)
427 return;
428 DEBUGF("Got file descriptor %d\n",fd);
429
430 rc = lseek(fd,-SECTOR_SIZE,SEEK_END);
431 if ( rc >= 0 ) {
432 rc = read(fd, buf, SECTOR_SIZE);
433 if( rc > 0 )
434 {
435 buf[rc]=0;
436 printf("%d:\n%s\n", (int)strlen(buf), buf);
437 }
438 else if ( rc == 0 ) {
439 DEBUGF("EOF\n");
440 }
441 else
442 {
443 DEBUGF("Failed reading file: %d\n",rc);
444 }
445 }
446 else {
447 perror("lseek");
448 }
449
450 close(fd);
451}
452
453int dbg_head(char* name)
454{
455 unsigned char buf[SECTOR_SIZE*5];
456 int fd,rc;
457
458 fd = open(name,O_RDONLY);
459 if (fd<0)
460 return -1;
461 DEBUGF("Got file descriptor %d\n",fd);
462
463 rc = read(fd, buf, SECTOR_SIZE*3);
464 if( rc > 0 )
465 {
466 buf[rc]=0;
467 printf("%d:\n%s\n", (int)strlen(buf), buf);
468 }
469 else if ( rc == 0 ) {
470 DEBUGF("EOF\n");
471 }
472 else
473 {
474 DEBUGF("Failed reading file: %d\n",rc);
475 }
476
477 return close(fd);
478}
479
480int dbg_trunc(char* name, int size)
481{
482 int fd,rc;
483
484#if 1
485 fd = open(name,O_RDWR);
486 if (fd<0)
487 return -1;
488
489 rc = ftruncate(fd, size);
490 if (rc<0) {
491 DEBUGF("ftruncate(%d) failed\n", size);
492 return -2;
493 }
494
495#else
496 fd = open(name,O_RDWR|O_TRUNC);
497 if (fd<0)
498 return -1;
499
500 rc = lseek(fd, size, SEEK_SET);
501 if (fd<0)
502 return -2;
503#endif
504
505 return close(fd);
506}
507
508int dbg_mkdir(char* name)
509{
510 int fd;
511
512 fd = mkdir(name);
513 if (fd<0) {
514 DEBUGF("Failed creating directory\n");
515 return -1;
516 }
517 return 0;
518}
519
520int dbg_cmd(int argc, char *argv[])
521{
522 char* cmd = NULL;
523 char* arg1 = NULL;
524 char* arg2 = NULL;
525
526 if (argc > 1) {
527 cmd = argv[1];
528 if ( argc > 2 ) {
529 arg1 = argv[2];
530 if ( argc > 3 ) {
531 arg2 = argv[3];
532 }
533 }
534 }
535 else {
536 DEBUGF("usage: fat command [options]\n"
537 "commands:\n"
538 " dir <dir>\n"
539 " ds <sector> - display sector\n"
540 " type <file>\n"
541 " head <file>\n"
542 " tail <file>\n"
543 " mkfile <file> <size (KB)>\n"
544 " chkfile <file>\n"
545 " del <file>\n"
546 " rmdir <dir>\n"
547 " dump <file> <offset>\n"
548 " mkdir <dir>\n"
549 " trunc <file> <size>\n"
550 " wrtest <file>\n"
551 " append <file>\n"
552 " test <file>\n"
553 " ren <file> <newname>\n"
554 );
555 return -1;
556 }
557
558 if (!strcasecmp(cmd, "dir"))
559 {
560 if ( arg1 )
561 dbg_dir(arg1);
562 else
563 dbg_dir("/");
564 }
565
566 if (!strcasecmp(cmd, "ds"))
567 {
568 if ( arg1 ) {
569 DEBUGF("secnum: %ld\n", strtol(arg1, NULL, 0));
570 dbg_dump_sector(strtol(arg1, NULL, 0));
571 }
572 }
573
574 if (!strcasecmp(cmd, "type"))
575 {
576 if (arg1)
577 dbg_type(arg1);
578 }
579
580 if (!strcasecmp(cmd, "head"))
581 {
582 if (arg1)
583 return dbg_head(arg1);
584 }
585
586 if (!strcasecmp(cmd, "tail"))
587 {
588 if (arg1)
589 dbg_tail(arg1);
590 }
591
592 if (!strcasecmp(cmd, "mkfile"))
593 {
594 if (arg1) {
595 if (arg2)
596 return dbg_mkfile(arg1,strtol(arg2, NULL, 0));
597 else
598 return dbg_mkfile(arg1,1);
599 }
600 }
601
602 if (!strcasecmp(cmd, "chkfile"))
603 {
604 if (arg1) {
605 if (arg2)
606 return dbg_chkfile(arg1, strtol(arg2, NULL, 0));
607 else
608 return dbg_chkfile(arg1, 0);
609 }
610 }
611
612 if (!strcasecmp(cmd, "mkdir"))
613 {
614 if (arg1) {
615 return dbg_mkdir(arg1);
616 }
617 }
618
619 if (!strcasecmp(cmd, "del"))
620 {
621 if (arg1)
622 return remove(arg1);
623 }
624
625 if (!strcasecmp(cmd, "rmdir"))
626 {
627 if (arg1)
628 return rmdir(arg1);
629 }
630
631 if (!strcasecmp(cmd, "dump"))
632 {
633 if (arg1) {
634 if (arg2)
635 return dbg_dump(arg1, strtol(arg2, NULL, 0));
636 else
637 return dbg_dump(arg1, 0);
638 }
639 }
640
641 if (!strcasecmp(cmd, "wrtest"))
642 {
643 if (arg1)
644 return dbg_wrtest(arg1);
645 }
646
647 if (!strcasecmp(cmd, "append"))
648 {
649 if (arg1)
650 return dbg_append(arg1);
651 }
652
653 if (!strcasecmp(cmd, "test"))
654 {
655 if (arg1)
656 return dbg_test(arg1);
657 }
658
659 if (!strcasecmp(cmd, "trunc"))
660 {
661 if (arg1 && arg2)
662 return dbg_trunc(arg1, strtol(arg2, NULL, 0));
663 }
664
665 if (!strcasecmp(cmd, "ren"))
666 {
667 if (arg1 && arg2)
668 return rename(arg1, arg2);
669 }
670
671 return 0;
672}
673
674extern void ata_exit(void);
675
676int main(int argc, char *argv[])
677{
678 int rc,i;
679 struct partinfo* pinfo;
680
681 srand(clock());
682
683 if(ata_init()) {
684 DEBUGF("*** Warning! The disk is uninitialized\n");
685 return -1;
686 }
687 pinfo = disk_init();
688 if (!pinfo) {
689 DEBUGF("*** Failed reading partitions\n");
690 return -1;
691 }
692
693 for ( i=0; i<4; i++ ) {
694 if ( pinfo[i].type == PARTITION_TYPE_FAT32
695#ifdef HAVE_FAT16SUPPORT
696 || pinfo[i].type == PARTITION_TYPE_FAT16
697#endif
698 ) {
699 DEBUGF("*** Mounting at block %ld\n",pinfo[i].start);
700 rc = fat_mount(IF_MV(0,) IF_MD(0,) pinfo[i].start);
701 if(rc) {
702 DEBUGF("mount: %d",rc);
703 return -1;
704 }
705 break;
706 }
707 }
708 if ( i==4 ) {
709 if(fat_mount(IF_MV(0,) IF_MD(0,) 0)) {
710 DEBUGF("No FAT32 partition!");
711 return -1;
712 }
713 }
714
715 rc = dbg_cmd(argc, argv);
716
717 ata_exit();
718
719 if (rc)
720 DEBUGF("Return code: %d\n", rc);
721
722 return rc;
723}
724
diff --git a/firmware/test/fat/test.sh b/firmware/test/fat/test.sh
deleted file mode 100644
index ca0a1db067..0000000000
--- a/firmware/test/fat/test.sh
+++ /dev/null
@@ -1,146 +0,0 @@
1#!/bin/sh
2
3IMAGE=disk.img
4MOUNT=/mnt/dummy
5RESULT=result.txt
6
7fail() {
8 echo "!! Test failed. Look in $RESULT for test logs."
9 chmod a+rw $RESULT
10 exit
11}
12
13check() {
14 /sbin/dosfsck -r $IMAGE | tee -a $RESULT
15 [ $RETVAL -ne 0 ] && fail
16}
17
18try() {
19 echo COMMAND: fat $1 "$2" "$3"
20 echo COMMAND: fat $1 "$2" "$3" >> $RESULT
21 ./fat $1 "$2" "$3" 2>> $RESULT
22 RETVAL=$?
23 [ $RETVAL -ne 0 ] && fail
24}
25
26buildimage() {
27 /sbin/mkdosfs -F 32 -s $1 $IMAGE > /dev/null
28 #mount -o loop $IMAGE $MOUNT
29 mount $MOUNT
30 echo "Filling it with /etc files"
31 find /etc -maxdepth 1 -type f -readable -exec cp {} $MOUNT \;
32 for i in `seq 1 120`;
33 do
34 echo apa > "$MOUNT/very $i long test filename so we can make sure they.work"
35 done
36 umount $MOUNT
37}
38
39runtests() {
40 rm $RESULT
41
42 echo ---Test: create a long name directory in the root
43 try mkdir "/very long subdir name"
44 check
45 try mkdir "/very long subdir name/apa.monkey.me.now"
46 check
47
48 echo ---Test: create a directory called "dir"
49 try mkdir "/dir"
50 check
51
52 echo ---Test: create a 10K file
53 try mkfile "/really long filenames rock" 10
54 check
55
56 try mkfile /dir/apa.monkey.me.now 10
57 check
58 try chkfile "/really long filenames rock" 10
59 try chkfile /dir/apa.monkey.me.now 8
60
61 echo ---Test: create a 1K file
62 try mkfile /bpa.rock 1
63 check
64 try chkfile /bpa.rock 1
65
66 echo ---Test: create a 40K file
67 try mkfile /cpa.rock 40
68 check
69 try chkfile /cpa.rock 40
70
71 echo ---Test: create a 400K file
72 try mkfile /dpa.rock 400
73 check
74 try chkfile /dpa.rock 400
75
76 echo ---Test: create a 1200K file
77 try mkfile /epa.rock 1200
78 check
79 try chkfile /epa.rock 1200
80
81 echo ---Test: rewrite first 20K of a 40K file
82 try mkfile /cpa.rock 20
83 check
84 try chkfile /cpa.rock 20
85
86 echo ---Test: rewrite first sector of 40K file
87 try mkfile /cpa.rock 0
88 check
89 try chkfile /cpa.rock
90 try chkfile /bpa.rock
91
92 LOOP=50
93 SIZE=700
94
95 try del "/really long filenames rock"
96
97 echo ---Test: create $LOOP $SIZE k files
98 for i in `seq 1 $LOOP`;
99 do
100 echo ---Test: $i/$LOOP ---
101 try mkfile "/rockbox rocks.$i" $SIZE
102 check
103 try chkfile "/rockbox rocks.$i" $SIZE
104 check
105 try del "/rockbox rocks.$i"
106 check
107 try mkfile "/rockbox rocks.$i" $SIZE
108 check
109 try ren "/rockbox rocks.$i" "/$i is a new long filename!"
110 check
111 done
112
113}
114
115echo "--------------------------------------"
116echo "Building test image (4 sector/cluster)"
117echo "--------------------------------------"
118buildimage 4
119runtests
120
121echo "---------------------------------------"
122echo "Building test image (32 sectors/cluster)"
123echo "---------------------------------------"
124buildimage 32
125runtests
126
127echo "--------------------------------------"
128echo "Building test image (1 sector/cluster)"
129echo "--------------------------------------"
130buildimage 1
131runtests
132
133echo "--------------------------------------"
134echo "Building test image (8 sectors/cluster)"
135echo "--------------------------------------"
136buildimage 8
137runtests
138
139echo "----------------------------------------"
140echo "Building test image (128 sectors/cluster)"
141echo "----------------------------------------"
142buildimage 128
143runtests
144
145echo "== Test completed successfully =="
146chmod a+rw $RESULT
diff --git a/firmware/test/fat/test16.sh b/firmware/test/fat/test16.sh
deleted file mode 100644
index 5a1c13150c..0000000000
--- a/firmware/test/fat/test16.sh
+++ /dev/null
@@ -1,135 +0,0 @@
1#!/bin/sh
2
3IMAGE=disk.img
4MOUNT=/mnt/dummy
5DIR=$MOUNT/q
6RESULT=result.txt
7
8fail() {
9 echo "!! Test failed $RETVAL. Look in $RESULT for test logs."
10 chmod a+rw $RESULT
11 exit
12}
13
14check() {
15 /sbin/dosfsck -r $IMAGE | tee -a $RESULT
16 [ $RETVAL -ne 0 ] && fail
17}
18
19try() {
20 echo COMMAND: fat $1 "$2" "$3"
21 echo COMMAND: fat $1 "$2" "$3" >> $RESULT
22 ./fat $1 "$2" "$3" 2>> $RESULT
23 RETVAL=$?
24 [ $RETVAL -ne 0 ] && fail
25}
26
27buildimage() {
28 /sbin/mkdosfs -F 16 -s $1 $IMAGE > /dev/null;
29 mount -o loop,fat=16 $IMAGE $MOUNT;
30 echo "Filling it with /etc files";
31 mkdir $DIR;
32 find /etc -type f -maxdepth 1 -exec cp {} $DIR \;
33 for i in `seq 1 120`;
34 do
35 echo apa > "$DIR/very $i long test filename so we can make sure they.work";
36 done;
37 umount $MOUNT;
38}
39
40runtests() {
41 rm $RESULT
42
43 echo ---Test: create a long name directory in the root
44 try mkdir "/very long subdir name"
45 check
46 try mkdir "/very long subdir name/apa.monkey.me.now"
47 check
48
49 echo ---Test: create a directory called "dir"
50 try mkdir "/dir"
51 check
52
53 echo ---Test: create a 10K file
54 try mkfile "/really long filenames rock" 10
55 check
56
57 try mkfile /dir/apa.monkey.me.now 10
58 check
59 try chkfile "/really long filenames rock" 10
60 try chkfile /dir/apa.monkey.me.now 8
61
62 echo ---Test: create a 1K file
63 try mkfile /bpa.rock 1
64 check
65 try chkfile /bpa.rock 1
66
67 echo ---Test: create a 40K file
68 try mkfile /cpa.rock 40
69 check
70 try chkfile /cpa.rock 40
71
72 echo ---Test: create a 400K file
73 try mkfile /dpa.rock 400
74 check
75 try chkfile /dpa.rock 400
76
77 echo ---Test: create a 1200K file
78 try mkfile /epa.rock 1200
79 check
80 try chkfile /epa.rock 1200
81
82 echo ---Test: rewrite first 20K of a 40K file
83 try mkfile /cpa.rock 20
84 check
85 try chkfile /cpa.rock 20
86
87 echo ---Test: rewrite first sector of 40K file
88 try mkfile /cpa.rock 0
89 check
90 try chkfile /cpa.rock
91 try chkfile /bpa.rock
92
93 LOOP=25
94 SIZE=700
95
96 try del "/really long filenames rock"
97
98 echo ---Test: create $LOOP $SIZE k files
99 for i in `seq 1 $LOOP`;
100 do
101 echo ---Test: $i/$LOOP ---
102 try mkfile "/q/rockbox rocks.$i" $SIZE
103 check
104 try chkfile "/q/rockbox rocks.$i" $SIZE
105 check
106 try del "/q/rockbox rocks.$i"
107 check
108 try mkfile "/q/rockbox rocks.$i" $SIZE
109 check
110 try ren "/q/rockbox rocks.$i" "/q/$i is a new long filename!"
111 check
112 done
113
114}
115
116echo "--------------------------------------"
117echo "Building test image (4 sector/cluster)"
118echo "--------------------------------------"
119buildimage 4
120runtests
121
122echo "--------------------------------------"
123echo "Building test image (8 sectors/cluster)"
124echo "--------------------------------------"
125buildimage 8
126runtests
127
128echo "----------------------------------------"
129echo "Building test image (64 sectors/cluster)"
130echo "----------------------------------------"
131buildimage 64
132runtests
133
134echo "== Test completed successfully =="
135chmod a+rw $RESULT
diff --git a/firmware/test/i2c/Makefile b/firmware/test/i2c/Makefile
deleted file mode 100644
index 51e72b859b..0000000000
--- a/firmware/test/i2c/Makefile
+++ /dev/null
@@ -1,53 +0,0 @@
1CC = sh-elf-gcc
2LD = sh-elf-ld
3AR = sh-elf-ar
4AS = sh-elf-as
5OC = sh-elf-objcopy
6
7FIRMWARE=../..
8
9INCLUDES=-I$(FIRMWARE) -I$(FIRMWARE)/common -I$(FIRMWARE)/drivers
10
11TARGET = -DARCHOS_PLAYER_OLD=1
12
13CFLAGS = -g -W -Wall -m1 -save-temps -nostdlib -Wstrict-prototypes -fschedule-insns -fno-builtin $(INCLUDES) $(TARGET) -DDEBUG
14AFLAGS += -small -relax
15
16SRC := $(wildcard *.c)
17OBJS := $(SRC:%.c=%.o) $(FIRMWARE)/crt0.o
18DEPS:=.deps
19DEPDIRS:=$(DEPS)
20
21all : archos.mod
22
23archos.elf : $(OBJS) app.lds
24 $(CC) -nostartfiles -o archos.elf $(OBJS) -lgcc -lrockbox -L$(FIRMWARE) -Tapp.lds -Wl,-Map,archos.map
25
26archos.bin : archos.elf
27 $(OC) -O binary archos.elf archos.bin
28
29archos.asm: archos.bin
30 sh2d -sh1 archos.bin > archos.asm
31
32archos.mod : archos.bin
33 scramble archos.bin archos.mod
34
35archos.mod.gz : archos.mod
36 gzip -f archos.mod
37
38dist:
39 tar czvf dist.tar.gz Makefile main.c start.s app.lds
40
41clean:
42 -rm -f $(OBJS) *.x *.i *.o *.s *.elf *.bin *.map *.mod *.bak *~
43 -$(RM) -r $(DEPS)
44
45$(DEPS)/%.d: %.c
46 @$(SHELL) -c 'for d in $(DEPDIRS); do { if [ ! -d $$d ]; then mkdir $$d; fi; }; done'
47 @echo "Updating dependencies for $<"
48 @$(SHELL) -ec '$(CC) -MM $(CFLAGS) $< \
49 |sed '\''s|\($*\)\.o[ :]*|\1.o $(<:%.c=%.d) : |g'\'' > $@; \
50 [ -s $@ ] || rm -f $@'
51
52-include $(SRC:%.c=$(DEPS)/%.d)
53
diff --git a/firmware/test/i2c/app.lds b/firmware/test/i2c/app.lds
deleted file mode 100644
index b8a341a8ae..0000000000
--- a/firmware/test/i2c/app.lds
+++ /dev/null
@@ -1,36 +0,0 @@
1ENTRY(start)
2OUTPUT_FORMAT(elf32-sh)
3SECTIONS
4{
5 .text 0x09010000 :
6 {
7 KEEP(*(.vectors))
8 . = ALIGN(0x200);
9 *(.init.text)
10 }
11
12 .text :
13 {
14 *(.text)
15 }
16
17 .data :
18 {
19 *(.rodata)
20 *(.data)
21 }
22
23 .rodata :
24 {
25 *(.rodata)
26 }
27
28 .bss :
29 {
30 _edata = .;
31 *(.bss)
32 *(COMMON)
33 _end = .;
34 _stack = . + 0x80000;
35 }
36}
diff --git a/firmware/test/i2c/gendata.c b/firmware/test/i2c/gendata.c
deleted file mode 100644
index dc5989ee66..0000000000
--- a/firmware/test/i2c/gendata.c
+++ /dev/null
@@ -1,31 +0,0 @@
1#include <stdio.h>
2
3int main(int argc, char *argv[])
4{
5 FILE *f;
6 int i;
7 unsigned char buf[128000];
8
9 f = fopen("mp.mp3", "r");
10
11 if(f)
12 {
13 if(fread(buf, 1, 128000, f) < 128000)
14 {
15 fprintf(stderr, "FAN!\n");
16 exit(1);
17 }
18
19 printf("int mp3datalen = 128000;\n");
20 printf("unsigned char mp3data[128000] =\n{");
21 for(i = 0;i < 128000;i++)
22 {
23 if(i % 8 == 0)
24 {
25 printf("\n");
26 }
27 printf("0x%02x, ", buf[i]);
28 }
29 printf("};\n");
30 }
31}
diff --git a/firmware/test/i2c/main.c b/firmware/test/i2c/main.c
deleted file mode 100644
index 990369eae8..0000000000
--- a/firmware/test/i2c/main.c
+++ /dev/null
@@ -1,1280 +0,0 @@
1/***************************************************************************
2
3 * __________ __ ___.
4
5 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
6
7 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
8
9 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
10
11 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
12
13 * \/ \/ \/ \/ \/
14
15 * $Id$
16
17 *
18
19 * Copyright (C) 2002 by Linus Nielsen Feltzing
20
21 *
22
23
24 * This program is free software; you can redistribute it and/or
25 * modify it under the terms of the GNU General Public License
26 * as published by the Free Software Foundation; either version 2
27 * of the License, or (at your option) any later version.
28
29 *
30
31 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
32
33 * KIND, either express or implied.
34
35 *
36
37 ****************************************************************************/
38
39#include <stdio.h>
40
41#include <stdlib.h>
42
43#include <stdbool.h>
44
45#include <string.h>
46
47#include "i2c.h"
48
49#include "mas35xx.h"
50
51#include "dac3550a.h"
52
53#include "sh7034.h"
54
55#include "system.h"
56
57#include "debug.h"
58
59#include "kernel.h"
60
61#include "thread.h"
62
63#include "ata.h"
64
65#include "disk.h"
66
67#include "fat.h"
68
69#include "file.h"
70
71#include "dir.h"
72
73#include "panic.h"
74
75
76
77#ifndef MIN
78
79#define MIN(a, b) (((a)<(b))?(a):(b))
80
81#endif
82
83
84
85#define MPEG_PLAY 1
86
87#define MPEG_STOP 2
88
89#define MPEG_PAUSE 3
90
91#define MPEG_RESUME 4
92
93#define MPEG_NEED_DATA 100
94
95
96
97#define MP3_LOW_WATER 0x30000
98
99#define MP3_CHUNK_SIZE 0x20000
100
101
102
103unsigned int bass_table[] =
104
105{
106
107 0,
108
109 0x800, /* 1dB */
110
111 0x10000, /* 2dB */
112
113 0x17c00, /* 3dB */
114
115 0x1f800, /* 4dB */
116
117 0x27000, /* 5dB */
118
119 0x2e400, /* 6dB */
120
121 0x35800, /* 7dB */
122
123 0x3c000, /* 8dB */
124
125 0x42800, /* 9dB */
126
127 0x48800, /* 10dB */
128
129 0x4e400, /* 11dB */
130
131 0x53800, /* 12dB */
132
133 0x58800, /* 13dB */
134
135 0x5d400, /* 14dB */
136
137 0x61800 /* 15dB */
138
139};
140
141
142
143unsigned int treble_table[] =
144
145{
146
147 0,
148
149 0x5400, /* 1dB */
150
151 0xac00, /* 2dB */
152
153 0x10400, /* 3dB */
154
155 0x16000, /* 4dB */
156
157 0x1c000, /* 5dB */
158
159 0x22400, /* 6dB */
160
161 0x28400, /* 7dB */
162
163 0x2ec00, /* 8dB */
164
165 0x35400, /* 9dB */
166
167 0x3c000, /* 10dB */
168
169 0x42c00, /* 11dB */
170
171 0x49c00, /* 12dB */
172
173 0x51800, /* 13dB */
174
175 0x58400, /* 14dB */
176
177 0x5f800 /* 15dB */
178
179};
180
181
182
183unsigned char fliptable[] =
184
185{
186
187 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
188
189 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
190
191 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,
192
193 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,
194
195 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4,
196
197 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
198
199 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec,
200
201 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,
202
203 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,
204
205 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,
206
207 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea,
208
209 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
210
211 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6,
212
213 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6,
214
215 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,
216
217 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe,
218
219 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1,
220
221 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,
222
223 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9,
224
225 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9,
226
227 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5,
228
229 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5,
230
231 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed,
232
233 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,
234
235 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3,
236
237 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3,
238
239 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb,
240
241 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb,
242
243 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7,
244
245 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,
246
247 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef,
248
249 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff
250
251};
252
253
254
255extern unsigned int stack[];
256
257/* Place the MP3 data right after the stack */
258
259
260
261#define MP3BUF_LEN 0x100000 /* 1 Mbyte */
262
263
264
265unsigned char *mp3buf = (unsigned char *)stack;
266
267
268
269char *tracks[100];
270
271int num_tracks;
272
273
274
275int mp3buf_write;
276
277int mp3buf_read;
278
279int last_dma_chunk_size;
280
281
282
283bool dma_on; /* The DMA is active */
284
285bool playing; /* We are playing an MP3 stream */
286
287bool filling; /* We are filling the buffer with data from disk */
288
289
290
291struct event_queue mpeg_queue SHAREDBSS_ATTR;
292
293
294
295static void mas_poll_start(unsigned int interval_in_ms);
296
297void mpeg_thread(void);
298
299
300
301void reset_mp3_buffer(void)
302
303{
304
305 mp3buf_read = 0;
306
307 mp3buf_write = 0;
308
309}
310
311
312
313void setup_sci0(void)
314
315{
316
317 /* PB15 is I/O, PB14 is IRQ6, PB12 is SCK0 */
318
319 PBCR1 = (PBCR1 & 0x0cff) | 0x1200;
320
321
322
323 /* Set PB12 to output */
324
325 PBIOR |= 0x1000;
326
327
328
329 /* Disable serial port */
330
331 SCR0 = 0x00;
332
333
334
335 /* Synchronous, no prescale */
336
337 SMR0 = 0x80;
338
339
340
341 /* Set baudrate 1Mbit/s */
342
343 BRR0 = 0x03;
344
345
346
347 /* use SCK as serial clock output */
348
349 SCR0 = 0x01;
350
351
352
353 /* Clear FER and PER */
354
355 SSR0 &= 0xe7;
356
357
358
359 /* Set interrupt ITU2 and SCI0 priority to 0 */
360
361 IPRD &= 0x0ff0;
362
363
364
365 /* set IRQ6 and IRQ7 to edge detect */
366
367 ICR |= 0x03;
368
369
370
371 /* set PB15 and PB14 to inputs */
372
373 PBIOR &= 0x7fff;
374
375 PBIOR &= 0xbfff;
376
377
378
379 /* set IRQ6 prio 8 and IRQ7 prio 0 */
380
381 IPRB = ( IPRB & 0xff00 ) | 0x0080;
382
383
384
385 /* Enable End of DMA interrupt at prio 8 */
386
387 IPRC = (IPRC & 0xf0ff) | 0x0800;
388
389
390
391 /* Enable Tx (only!) */
392
393 SCR0 |= 0x20;
394
395}
396
397
398
399
400
401void init_dma(void)
402
403{
404
405 SAR3 = (unsigned int) mp3buf + mp3buf_read;
406
407 DAR3 = 0x5FFFEC3;
408
409 CHCR3 &= ~0x0002; /* Clear interrupt */
410
411 CHCR3 = 0x1504; /* Single address destination, TXI0, IE=1 */
412
413 last_dma_chunk_size = MIN(65536, mp3buf_write - mp3buf_read);
414
415 DTCR3 = last_dma_chunk_size & 0xffff;
416
417 DMAOR = 0x0001; /* Enable DMA */
418
419 CHCR3 |= 0x0001; /* Enable DMA IRQ */
420
421}
422
423
424
425void start_dma(void)
426
427{
428
429 SCR0 |= 0x80;
430
431 dma_on = true;
432
433}
434
435
436
437void stop_dma(void)
438
439{
440
441 SCR0 &= 0x7f;
442
443 dma_on = false;
444
445}
446
447
448
449void dma_tick(void)
450
451{
452
453 /* Start DMA if it isn't running */
454
455 if(playing && !dma_on)
456
457 {
458
459 if(PBDR & 0x4000)
460
461 {
462
463 if(!(SCR0 & 0x80))
464
465 start_dma();
466
467 }
468
469 }
470
471}
472
473
474
475void bitswap(unsigned char *data, int length)
476
477{
478
479 int i;
480
481 for(i = 0;i < length;i++)
482
483 {
484
485 data[i] = fliptable[data[i]];
486
487 }
488
489}
490
491
492
493int main(void)
494
495{
496
497 char buf[40];
498
499 char str[32];
500
501 int i=0;
502
503 DIR *d;
504
505 struct dirent *dent;
506
507 char *tmp;
508
509 int volume, bass, treble;
510
511 unsigned short frame_count;
512
513
514
515 /* Clear it all! */
516
517 SSR1 &= ~(SCI_RDRF | SCI_ORER | SCI_PER | SCI_FER);
518
519
520
521 /* This enables the serial Rx interrupt, to be able to exit into the
522
523 debugger when you hit CTRL-C */
524
525 SCR1 |= 0x40;
526
527 SCR1 &= ~0x80;
528
529
530
531 IPRE |= 0xf000; /* Highest priority */
532
533
534
535 i2c_init();
536
537
538
539 dma_on = true;
540
541
542
543 kernel_init();
544
545
546
547 enable_irq();
548
549
550
551 setup_sci0();
552
553
554
555 i=mas_readmem(MAS_BANK_D1,0xff6,(unsigned long*)buf,2);
556
557 if (i) {
558
559 debugf("Error - mas_readmem() returned %d\n", i);
560
561 while(1);
562
563 }
564
565
566
567 i = buf[0] | buf[1] << 8;
568
569 debugf("MAS version: %x\n", i);
570
571 i = buf[4] | buf[5] << 8;
572
573 debugf("MAS revision: %x\n", i);
574
575
576
577 i=mas_readmem(MAS_BANK_D1,0xff9,(unsigned long*)buf,7);
578
579 if (i) {
580
581 debugf("Error - mas_readmem() returned %d\n", i);
582
583 while(1);
584
585 }
586
587
588
589 for(i = 0;i < 7;i++)
590
591 {
592
593 str[i*2+1] = buf[i*4];
594
595 str[i*2] = buf[i*4+1];
596
597 }
598
599 str[i*2] = 0;
600
601 debugf("Description: %s\n", str);
602
603
604
605 i=mas_writereg(0x3b, 0x20);
606
607 if (i < 0) {
608
609 debugf("Error - mas_writereg() returned %d\n", i);
610
611 while(1);
612
613 }
614
615
616
617 i = mas_run(1);
618
619 if (i < 0) {
620
621 debugf("Error - mas_run() returned %d\n", i);
622
623 while(1);
624
625 }
626
627
628
629 i = ata_init();
630
631 debugf("ata_init() returned %d\n", i);
632
633
634
635 i = disk_init();
636
637 debugf("disk_init() returned %d\n", i);
638
639
640
641 debugf("part[0] starts at sector %d\n", part[0].start);
642
643
644
645 i = fat_mount(IF_MV(0,) IF_MD(0,) part[0].start);
646
647 debugf("fat_mount() returned %d\n", i);
648
649
650
651 num_tracks = 0;
652
653 if((d = opendir("/")))
654
655 {
656
657 while((dent = readdir(d)))
658
659 {
660
661 debugf("%s\n", dent->d_name);
662
663 i = strlen(dent->d_name);
664
665 tmp = dent->d_name + i - 4;
666
667 debugf("%s\n", tmp);
668
669 if(!stricmp(tmp, ".mp3"))
670
671 {
672
673 tmp = malloc(i+1);
674
675 if(tmp)
676
677 {
678
679 debugf("Adding track %s\n", dent->d_name);
680
681 snprintf(tmp, i+1, "/%s", dent->d_name);
682
683 tracks[num_tracks++] = tmp;
684
685 }
686
687 else
688
689 {
690
691 panicf("Out of memory\n");
692
693 }
694
695 }
696
697 }
698
699 closedir(d);
700
701 }
702
703
704
705 debugf("Number of tracks: %d\n");
706
707
708
709 queue_init(&mpeg_queue);
710
711
712
713 create_thread(mpeg_thread, stack - 0x2000, 0x4000, 0);
714
715
716
717 mas_poll_start(2);
718
719
720
721 debugf("let's play...\n");
722
723
724
725 queue_post(&mpeg_queue, MPEG_PLAY, 0);
726
727
728
729 volume = 0x2c;
730
731
732
733 if(dac_config(0x04) < 0)
734
735 debugf("DAC write failed\n");
736
737
738
739 if(dac_volume(volume) < 0)
740
741 debugf("DAC write failed\n");
742
743
744
745 bass = 12;
746
747 treble = 8;
748
749
750
751 mas_writereg(MAS_REG_KPRESCALE, 0xe9400);
752
753 mas_writereg(MAS_REG_KBASS, bass_table[bass]);
754
755 mas_writereg(MAS_REG_KTREBLE, treble_table[treble]);
756
757
758
759 while(1)
760
761 {
762
763 sleep(HZ*4);
764
765 }
766
767}
768
769
770
771void IRQ6(void) __attribute__((interrupt_handler));
772
773void IRQ6(void)
774
775{
776
777 stop_dma();
778
779}
780
781
782
783void DEI3(void) __attribute__((interrupt_handler));
784
785void DEI3(void)
786
787{
788
789 int unplayed_space_left;
790
791 int space_until_end_of_buffer;
792
793
794
795 if(playing)
796
797 {
798
799 mp3buf_read += last_dma_chunk_size;
800
801 if(mp3buf_read >= MP3BUF_LEN)
802
803 mp3buf_read = 0;
804
805
806
807 unplayed_space_left = mp3buf_write - mp3buf_read;
808
809 if(unplayed_space_left < 0)
810
811 unplayed_space_left = MP3BUF_LEN + unplayed_space_left;
812
813
814
815 space_until_end_of_buffer = MP3BUF_LEN - mp3buf_read;
816
817
818
819 if(!filling && unplayed_space_left < MP3_LOW_WATER)
820
821 {
822
823 queue_post(&mpeg_queue, MPEG_NEED_DATA, 0);
824
825 }
826
827
828
829 if(unplayed_space_left)
830
831 {
832
833 last_dma_chunk_size = MIN(65536, unplayed_space_left);
834
835 last_dma_chunk_size = MIN(last_dma_chunk_size, space_until_end_of_buffer);
836
837 DTCR3 = last_dma_chunk_size & 0xffff;
838
839 SAR3 = (unsigned int)mp3buf + mp3buf_read;
840
841 }
842
843 else
844
845 {
846
847 debugf("No more MP3 data. Stopping.\n");
848
849 CHCR3 = 0; /* Stop DMA interrupt */
850
851 }
852
853 }
854
855
856
857 CHCR3 &= ~0x0002; /* Clear DMA interrupt */
858
859}
860
861
862
863static void mas_poll_start(unsigned int interval_in_ms)
864
865{
866
867 unsigned int count;
868
869
870
871 count = FREQ / 1000 / 8 * interval_in_ms;
872
873
874
875 if(count > 0xffff)
876
877 {
878
879 panicf("Error! The MAS poll interval is too long (%d ms)\n",
880
881 interval_in_ms);
882
883 return;
884
885 }
886
887
888
889 /* We are using timer 1 */
890
891
892
893 TSTR &= ~0x02; /* Stop the timer */
894
895 TSNC &= ~0x02; /* No synchronization */
896
897 TMDR &= ~0x02; /* Operate normally */
898
899
900
901 TCNT1 = 0; /* Start counting at 0 */
902
903 GRA1 = count;
904
905 TCR1 = 0x23; /* Clear at GRA match, sysclock/8 */
906
907
908
909 /* Enable interrupt on level 2 */
910
911 IPRC = (IPRC & ~0x000f) | 0x0002;
912
913
914
915 TSR1 &= ~0x02;
916
917 TIER1 = 0xf9; /* Enable GRA match interrupt */
918
919
920
921 TSTR |= 0x02; /* Start timer 2 */
922
923}
924
925
926
927void IMIA1(void) __attribute__((interrupt_handler));
928
929void IMIA1(void)
930
931{
932
933 dma_tick();
934
935 TSR1 &= ~0x01;
936
937}
938
939
940
941int track_index = 0;
942
943char *peek_next_track(int index)
944
945{
946
947 if(track_index < num_tracks)
948
949 return tracks[track_index+index];
950
951 else
952
953 return NULL;
954
955}
956
957
958
959void next_track(void)
960
961{
962
963 track_index++;
964
965}
966
967
968
969int mpeg_file = -1;
970
971
972
973int new_file(void)
974
975{
976
977 char *trackname;
978
979
980
981 trackname = peek_next_track(0);
982
983
984
985 debugf("playing %s\n", trackname);
986
987 mpeg_file = open(trackname, O_RDONLY);
988
989 if(mpeg_file < 0)
990
991 {
992
993 debugf("Couldn't open file\n");
994
995 return -1;
996
997 }
998
999 return 0;
1000
1001}
1002
1003
1004
1005void mpeg_thread(void)
1006
1007{
1008
1009 struct queue_event ev;
1010
1011 int len;
1012
1013 int free_space_left;
1014
1015 int amount_to_read;
1016
1017 bool play_pending;
1018
1019
1020
1021 play_pending = false;
1022
1023 playing = false;
1024
1025
1026
1027 while(1)
1028
1029 {
1030
1031 debugf("S\n");
1032
1033 queue_wait(&mpeg_queue, &ev);
1034
1035 switch(ev.id)
1036
1037 {
1038
1039 case MPEG_PLAY:
1040
1041 /* Stop the current stream */
1042
1043 play_pending = false;
1044
1045 playing = false;
1046
1047 stop_dma();
1048
1049
1050
1051 reset_mp3_buffer();
1052
1053
1054
1055 new_file();
1056
1057
1058
1059 /* Make it read more data */
1060
1061 filling = true;
1062
1063 queue_post(&mpeg_queue, MPEG_NEED_DATA, 0);
1064
1065
1066
1067 /* Tell the file loading code that we want to start playing
1068
1069 as soon as we have some data */
1070
1071 play_pending = true;
1072
1073 break;
1074
1075
1076
1077 case MPEG_STOP:
1078
1079 /* Stop the current stream */
1080
1081 playing = false;
1082
1083 stop_dma();
1084
1085 break;
1086
1087
1088
1089 case MPEG_PAUSE:
1090
1091 /* Stop the current stream */
1092
1093 playing = false;
1094
1095 stop_dma();
1096
1097 break;
1098
1099
1100
1101 case MPEG_RESUME:
1102
1103 /* Stop the current stream */
1104
1105 playing = true;
1106
1107 start_dma();
1108
1109 break;
1110
1111
1112
1113 case MPEG_NEED_DATA:
1114
1115 free_space_left = mp3buf_read - mp3buf_write;
1116
1117
1118
1119 /* We interpret 0 as "empty buffer" */
1120
1121 if(free_space_left <= 0)
1122
1123 free_space_left = MP3BUF_LEN + free_space_left;
1124
1125
1126
1127 if(free_space_left <= MP3_CHUNK_SIZE)
1128
1129 {
1130
1131 debugf("0\n");
1132
1133 ata_spindown(-1);
1134
1135 filling = false;
1136
1137 break;
1138
1139 }
1140
1141
1142
1143 amount_to_read = MIN(MP3_CHUNK_SIZE, free_space_left);
1144
1145 amount_to_read = MIN(MP3BUF_LEN - mp3buf_write, amount_to_read);
1146
1147
1148
1149 /* Read in a few seconds worth of MP3 data. We don't want to
1150
1151 read too large chunks because the bitswapping will take
1152
1153 too much time. We must keep the DMA happy and also give
1154
1155 the other threads a chance to run. */
1156
1157 debugf("R\n");
1158
1159 len = read(mpeg_file, mp3buf+mp3buf_write, amount_to_read);
1160
1161 if(len)
1162
1163 {
1164
1165 debugf("B\n");
1166
1167 bitswap(mp3buf + mp3buf_write, len);
1168
1169
1170
1171 mp3buf_write += len;
1172
1173 if(mp3buf_write >= MP3BUF_LEN)
1174
1175 {
1176
1177 mp3buf_write = 0;
1178
1179 debugf("W\n");
1180
1181 }
1182
1183
1184
1185 /* Tell ourselves that we want more data */
1186
1187 queue_post(&mpeg_queue, MPEG_NEED_DATA, 0);
1188
1189
1190
1191 /* And while we're at it, see if we have startet playing
1192
1193 yet. If not, do it. */
1194
1195 if(play_pending)
1196
1197 {
1198
1199 play_pending = false;
1200
1201 playing = true;
1202
1203
1204
1205 init_dma();
1206
1207 start_dma();
1208
1209 }
1210
1211 }
1212
1213 else
1214
1215 {
1216
1217 close(mpeg_file);
1218
1219
1220
1221 /* Make sure that the write pointer is at a word
1222
1223 boundary */
1224
1225 mp3buf_write &= 0xfffffffe;
1226
1227
1228
1229 next_track();
1230
1231 if(new_file() < 0)
1232
1233 {
1234
1235 /* No more data to play */
1236
1237 debugf("Finished playing\n");
1238
1239 playing = false;
1240
1241 ata_spindown(-1);
1242
1243 filling = false;
1244
1245 }
1246
1247 else
1248
1249 {
1250
1251 /* Tell ourselves that we want more data */
1252
1253 queue_post(&mpeg_queue, MPEG_NEED_DATA, 0);
1254
1255 }
1256
1257 }
1258
1259 break;
1260
1261 }
1262
1263 }
1264
1265}
1266
1267
1268
1269/* Newlib trap honeypot */
1270
1271void __trap34(void)
1272
1273{
1274
1275 debugf("newlib trap34\n");
1276
1277 while(1);
1278
1279}
1280
diff --git a/firmware/test/id3/Makefile b/firmware/test/id3/Makefile
deleted file mode 100644
index 8b9cd230b2..0000000000
--- a/firmware/test/id3/Makefile
+++ /dev/null
@@ -1,13 +0,0 @@
1TARGET = id3test
2
3OBJS = id3.o
4CFLAGS = -g -W -Wall -DDEBUG_STANDALONE -DSIMULATOR -c -o
5
6$(TARGET) : $(OBJS)
7 $(CC) -o $(TARGET) $(OBJS)
8
9id3.o:../../id3.c
10 $(CC) $(CFLAGS) $@ $<
11
12clean:
13 rm -f $(OBJS) $(TARGET) *~
diff --git a/firmware/test/kernel/Makefile b/firmware/test/kernel/Makefile
deleted file mode 100644
index 94171767c6..0000000000
--- a/firmware/test/kernel/Makefile
+++ /dev/null
@@ -1,52 +0,0 @@
1CC = sh-elf-gcc
2LD = sh-elf-ld
3AR = sh-elf-ar
4AS = sh-elf-as
5OC = sh-elf-objcopy
6
7INCLUDES=-I../../ -I../../drivers
8
9# Pick a target to build for
10#TARGET = -DARCHOS_PLAYER=1
11TARGET = -DARCHOS_PLAYER_OLD=1
12#TARGET = -DARCHOS_RECORDER=1
13
14CFLAGS = -g -Wall -m1 -save-temps -nostdlib -Wstrict-prototypes -fschedule-insns -fno-builtin $(INCLUDES) $(TARGET) -DDEBUG
15AFLAGS += -small -relax
16
17OBJS= ../../crt0.o ../../system.o main.o ../../panic.o ../../drivers/lcd.o \
18 thread.o ../../kernel.o ../../drivers/led.o \
19 ../../debug.o ../../common/sprintf.o
20
21%.o: %.S
22 $(CC) -o $@ $(CFLAGS) $(INCLUDES) $(DEFS) $(ASMFLAGS) -c $<
23
24
25all : archos.mod
26
27archos.elf : $(OBJS) app.lds
28 $(CC) -nostartfiles -o archos.elf $(OBJS) -lgcc -Tapp.lds -Wl,-Map,archos.map
29
30archos.bin : archos.elf
31 $(OC) -O binary archos.elf archos.bin
32
33archos.asm: archos.bin
34 sh2d -sh1 archos.bin > archos.asm
35
36archos.mod : archos.bin
37 scramble archos.bin archos.mod
38
39archos.mod.gz : archos.mod
40 gzip -f archos.mod
41
42dist:
43 tar czvf dist.tar.gz Makefile main.c start.s app.lds
44
45clean:
46 -rm -f $(OBJS) *.s *.x *.i *.o *.elf *.bin *.map *.mod *.bak *~
47
48install:
49 mount /mnt/archos; cp archos.mod /mnt/archos; umount /mnt/archos
50
51thread.o: ../../thread.c
52 $(CC) -O -fomit-frame-pointer -c $(CFLAGS) $<
diff --git a/firmware/test/kernel/app.lds b/firmware/test/kernel/app.lds
deleted file mode 100644
index b8a341a8ae..0000000000
--- a/firmware/test/kernel/app.lds
+++ /dev/null
@@ -1,36 +0,0 @@
1ENTRY(start)
2OUTPUT_FORMAT(elf32-sh)
3SECTIONS
4{
5 .text 0x09010000 :
6 {
7 KEEP(*(.vectors))
8 . = ALIGN(0x200);
9 *(.init.text)
10 }
11
12 .text :
13 {
14 *(.text)
15 }
16
17 .data :
18 {
19 *(.rodata)
20 *(.data)
21 }
22
23 .rodata :
24 {
25 *(.rodata)
26 }
27
28 .bss :
29 {
30 _edata = .;
31 *(.bss)
32 *(COMMON)
33 _end = .;
34 _stack = . + 0x80000;
35 }
36}
diff --git a/firmware/test/kernel/main.c b/firmware/test/kernel/main.c
deleted file mode 100644
index df0e72156a..0000000000
--- a/firmware/test/kernel/main.c
+++ /dev/null
@@ -1,104 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Linus Nielsen Feltzing
11 *
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.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#include "thread.h"
22#include "kernel.h"
23#include "sh7034.h"
24#include "debug.h"
25
26void tick_start(unsigned int interval);
27
28unsigned int s1[256];
29unsigned int s2[256];
30
31void t1(void);
32void t2(void);
33
34struct event_queue main_q SHAREDBSS_ATTR;
35
36int tick_add_task(void (*f)(void));
37
38void testfunc(void)
39{
40 if(current_tick == 5000)
41 debugf("Yippie!\n");
42}
43
44int main(void)
45{
46 char buf[40];
47 char str[32];
48 int i=0;
49 struct queue_event *ev;
50
51 /* Clear it all! */
52 SSR1 &= ~(SCI_RDRF | SCI_ORER | SCI_PER | SCI_FER);
53
54 /* This enables the serial Rx interrupt, to be able to exit into the
55 debugger when you hit CTRL-C */
56 SCR1 |= 0x40;
57 SCR1 &= ~0x80;
58 IPRE |= 0xf000; /* Set to highest priority */
59
60 debugf("OK. Let's go\n");
61
62 kernel_init();
63
64 enable_irq();
65
66 tick_add_task(testfunc);
67
68 debugf("sleeping 10s...\n");
69 sleep(HZ*10);
70 debugf("woke up\n");
71
72 queue_init(&main_q);
73
74 create_thread(t1, s1, 1024, 0);
75 create_thread(t2, s2, 1024, 0);
76
77 while(1)
78 {
79 ev = queue_wait(&main_q);
80 debugf("Thread 0 got an event. ID: %d\n", ev->id);
81 }
82}
83
84void t1(void)
85{
86 debugf("Thread 1 started\n");
87 while(1)
88 {
89 sleep(HZ);
90 debugf("Thread 1 posting an event\n");
91 queue_post(&main_q, 1234, 0);
92 queue_post(&main_q, 5678, 0);
93 }
94}
95
96void t2(void)
97{
98 debugf("Thread 2 started\n");
99 while(1)
100 {
101 sleep(HZ*3);
102 debugf("Thread 2 awakened\n");
103 }
104}
diff --git a/firmware/test/snprintf/Makefile b/firmware/test/snprintf/Makefile
deleted file mode 100644
index 39f128ed8a..0000000000
--- a/firmware/test/snprintf/Makefile
+++ /dev/null
@@ -1,16 +0,0 @@
1
2TARGET = snprintf
3
4OBJS = snprintf.o test.o
5
6CFLAGS = -I../../include
7
8$(TARGET): $(OBJS)
9
10snprintf.o: ../../common/sprintf.c
11 $(CC) -c $< -o $@
12
13test.o: test.c
14
15clean:
16 rm -f $(OBJS) \ No newline at end of file
diff --git a/firmware/test/snprintf/test.c b/firmware/test/snprintf/test.c
deleted file mode 100644
index 049be4d257..0000000000
--- a/firmware/test/snprintf/test.c
+++ /dev/null
@@ -1,16 +0,0 @@
1
2#include <stdio.h>
3
4
5int main(int argc, char **argv)
6{
7 char buffer[256];
8 snprintf(buffer, 5, "123456789");
9 printf("%s\n", buffer);
10 snprintf(buffer, 6, "123456789");
11 printf("%s\n", buffer);
12 snprintf(buffer, 7, "123456789");
13 printf("%s\n", buffer);
14 snprintf(buffer, 7, "123%s", "mooooooooooo");
15 printf("%s\n", buffer);
16}