Changes in test_mem plugin: Use correct formula to calculate KB/s, reasonable unrolli...
[kugel-rb.git] / apps / plugins / test_mem.c
blob2ad0e044363d7d18ee717c73705c1002f000a630
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2010 Thomas Martitz
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 ****************************************************************************/
22 #include "plugin.h"
24 PLUGIN_HEADER
26 #define BUF_SIZE ((PLUGIN_BUFFER_SIZE-(10<<10)) / (sizeof(int)))
27 #define LOOP_REPEAT 8
28 static volatile int buf[BUF_SIZE];
30 /* (Byte per loop * loops * 100 ticks per s / ticks)>>10 = KB per s */
31 #define KB_PER_SEC(delta) (((BUF_SIZE*sizeof(buf[0])*LOOP_REPEAT*100)/delta) >> 10)
33 enum plugin_status plugin_start(const void* parameter)
35 (void)parameter;
36 bool done = false;
37 bool boost = false;
38 int count = 0;
39 int last_tick = 0;
41 rb->lcd_setfont(FONT_SYSFIXED);
43 while (!done)
45 unsigned i, j;
46 int line = 0;
47 volatile int x;
48 int delta;
49 last_tick = *rb->current_tick;
51 for(i = 0; i < LOOP_REPEAT; i++)
53 for (j = 0; j < BUF_SIZE; j+=4)
55 buf[j ] = j;
56 buf[j+1] = j+1;
57 buf[j+2] = j+2;
58 buf[j+3] = j+3;
61 delta = *rb->current_tick - last_tick;
62 rb->screens[0]->clear_display();
63 rb->screens[0]->putsf(0, line++, "%s", boost?"boosted":"unboosted");
64 rb->screens[0]->putsf(0, line++, "bufsize: %u", BUF_SIZE*sizeof(buf[0]));
65 rb->screens[0]->putsf(0, line++, "loop#: %d", ++count);
66 rb->screens[0]->putsf(0, line++, "write ticks: %2d (%5d KB/s)", delta,
67 KB_PER_SEC(delta));
68 last_tick = *rb->current_tick;
69 for(i = 0; i < LOOP_REPEAT; i++)
71 for(j = 0; j < BUF_SIZE; j+=4)
73 x = buf[j ];
74 x = buf[j+2];
75 x = buf[j+3];
76 x = buf[j+4];
79 delta = *rb->current_tick - last_tick;
80 rb->screens[0]->putsf(0, line++, "read ticks : %2d (%5d KB/s)", delta,
81 KB_PER_SEC(delta));
82 rb->screens[0]->update();
84 switch (rb->get_action(CONTEXT_STD, TIMEOUT_NOBLOCK))
86 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
87 case ACTION_STD_PREV:
88 if (!boost)
90 rb->cpu_boost(true);
91 boost = true;
93 break;
95 case ACTION_STD_NEXT:
96 if (boost)
98 rb->cpu_boost(false);
99 boost = false;
101 break;
102 #endif
103 case ACTION_STD_CANCEL:
104 done = true;
105 break;
109 return PLUGIN_OK;