1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2010 Thomas Martitz, Andree Buschmann
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
26 #if PLUGIN_BUFFER_SIZE <= 0x8000
27 #define BUF_SIZE (1<<12) /* 16 KB = (1<<12)*sizeof(int) */
29 #define BUF_SIZE (1<<13) /* 32 KB = (1<<13)*sizeof(int) */
32 #define LOOP_REPEAT_DRAM 256
33 static volatile int buf_dram
[BUF_SIZE
];
35 #if defined(PLUGIN_USE_IRAM)
36 #define LOOP_REPEAT_IRAM 1024
37 static volatile int buf_iram
[BUF_SIZE
] IBSS_ATTR
;
40 /* (Byte per loop * loops)>>20 * ticks per s * 10 / ticks = dMB per s */
41 #define dMB_PER_SEC(cnt, delta) ((((BUF_SIZE*sizeof(int)*cnt)>>20)*HZ*10)/delta)
43 void memset_test(volatile int *buf
, int buf_size
, int loop_cnt
,
44 int line
, char *ramtype
)
47 int last_tick
= *rb
->current_tick
;
49 for(i
=0; i
< loop_cnt
; i
++)
51 memset((void *)buf
, 0xff, buf_size
*sizeof(int));
54 delta
= *rb
->current_tick
- last_tick
;
55 delta
= delta
>0 ? delta
: delta
+1;
56 dMB
= dMB_PER_SEC(loop_cnt
, delta
);
57 rb
->screens
[0]->putsf(0, line
, "%s st: %3d.%d MB/s (%3d ticks for %d MB)",
58 ramtype
, dMB
/10, dMB
%10, delta
,
59 (loop_cnt
*BUF_SIZE
*4)>>20);
62 void memcpy_test(volatile int *buf
, int buf_size
, int loop_cnt
,
63 int line
, char *ramtype
)
66 int last_tick
= *rb
->current_tick
;
68 /* double loop count to compensate for half size memcpy */
69 for(i
=0; i
< loop_cnt
*2; i
++)
71 memcpy((void *)buf
+(buf_size
*sizeof(int)/2),
72 (void *)buf
, buf_size
*sizeof(int)/2);
75 delta
= *rb
->current_tick
- last_tick
;
76 delta
= delta
>0 ? delta
: delta
+1;
77 dMB
= dMB_PER_SEC(loop_cnt
, delta
);
78 rb
->screens
[0]->putsf(0, line
, "%s cp: %3d.%d MB/s (%3d ticks for %d MB)",
79 ramtype
, dMB
/10, dMB
%10, delta
,
80 (loop_cnt
*BUF_SIZE
*4)>>21);
83 void write_test(volatile int *buf
, int buf_size
, int loop_cnt
,
84 int line
, char *ramtype
)
87 int last_tick
= *rb
->current_tick
;
96 ".outer_loop_read: \n"
99 ".inner_loop_read: \n"
100 "stmia r4!, {r0-r3} \n"
101 "stmia r4!, {r0-r3} \n"
103 "bgt .inner_loop_read \n"
105 "bgt .outer_loop_read \n"
107 : [loops
] "r" (loop_cnt
), [size
] "r" (buf_size
), [buf_p
] "r" (buf
)
108 : "r0", "r1", "r2", "r3", "r4", "r5", "r6", "memory", "cc"
112 for(i
= 0; i
< loop_cnt
; i
++)
114 for (j
= 0; j
< buf_size
; j
+=4)
123 delta
= *rb
->current_tick
- last_tick
;
124 delta
= delta
>0 ? delta
: delta
+1;
125 dMB
= dMB_PER_SEC(loop_cnt
, delta
);
126 rb
->screens
[0]->putsf(0, line
, "%s wr: %3d.%d MB/s (%3d ticks for %d MB)",
127 ramtype
, dMB
/10, dMB
%10, delta
,
128 (loop_cnt
*BUF_SIZE
*4)>>20);
131 void read_test(volatile int *buf
, int buf_size
, int loop_cnt
,
132 int line
, char *ramtype
)
135 int last_tick
= *rb
->current_tick
;
139 "mov r6, %[loops] \n"
140 ".outer_loop_write: \n"
141 "mov r4, %[buf_p] \n"
143 ".inner_loop_write: \n"
144 "ldmia r4!, {r0-r3} \n"
145 "ldmia r4!, {r0-r3} \n"
147 "bgt .inner_loop_write \n"
149 "bgt .outer_loop_write \n"
151 : [loops
] "r" (loop_cnt
), [size
] "r" (buf_size
), [buf_p
] "r" (buf
)
152 : "r0", "r1", "r2", "r3", "r4", "r5", "r6", "memory", "cc"
156 for(i
= 0; i
< loop_cnt
; i
++)
158 for(j
= 0; j
< buf_size
; j
+=4)
167 delta
= *rb
->current_tick
- last_tick
;
168 delta
= delta
>0 ? delta
: delta
+1;
169 dMB
= dMB_PER_SEC(loop_cnt
, delta
);
170 rb
->screens
[0]->putsf(0, line
, "%s rd: %3d.%d MB/s (%3d ticks for %d MB)",
171 ramtype
, dMB
/10, dMB
%10, delta
,
172 (loop_cnt
*BUF_SIZE
*4)>>20);
176 enum plugin_status
plugin_start(const void* parameter
)
183 #ifdef HAVE_LCD_BITMAP
184 rb
->lcd_setfont(FONT_SYSFIXED
);
187 rb
->screens
[0]->clear_display();
188 rb
->screens
[0]->putsf(0, 0, "patience, may take some seconds...");
189 rb
->screens
[0]->update();
195 rb
->screens
[0]->clear_display();
196 rb
->screens
[0]->putsf(0, line
++, "%s", boost
?"boosted":"unboosted");
197 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
198 rb
->screens
[0]->putsf(0, line
++, "clock: %d Hz", *rb
->cpu_frequency
);
200 rb
->screens
[0]->putsf(0, line
++, "loop#: %d", ++count
);
202 read_test (buf_dram
, BUF_SIZE
, LOOP_REPEAT_DRAM
, line
++, "DRAM");
203 write_test (buf_dram
, BUF_SIZE
, LOOP_REPEAT_DRAM
, line
++, "DRAM");
204 memset_test(buf_dram
, BUF_SIZE
, LOOP_REPEAT_DRAM
, line
++, "DRAM");
205 memcpy_test(buf_dram
, BUF_SIZE
, LOOP_REPEAT_DRAM
, line
++, "DRAM");
206 #if defined(PLUGIN_USE_IRAM)
207 read_test (buf_iram
, BUF_SIZE
, LOOP_REPEAT_IRAM
, line
++, "IRAM");
208 write_test (buf_iram
, BUF_SIZE
, LOOP_REPEAT_IRAM
, line
++, "IRAM");
209 memset_test(buf_iram
, BUF_SIZE
, LOOP_REPEAT_DRAM
, line
++, "IRAM");
210 memcpy_test(buf_iram
, BUF_SIZE
, LOOP_REPEAT_DRAM
, line
++, "IRAM");
213 rb
->screens
[0]->update();
215 switch (rb
->get_action(CONTEXT_STD
, HZ
/5))
217 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
218 case ACTION_STD_PREV
:
226 case ACTION_STD_NEXT
:
229 rb
->cpu_boost(false);
234 case ACTION_STD_CANCEL
: