summaryrefslogtreecommitdiffstats
path: root/apps/plugins/test_mem.c
blob: 2ad0e044363d7d18ee717c73705c1002f000a630 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/***************************************************************************
*             __________               __   ___.
*   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
*   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
*   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
*   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
*                     \/            \/     \/    \/            \/
* $Id$
*
* Copyright (C) 2010 Thomas Martitz
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/

#include "plugin.h"

PLUGIN_HEADER

#define BUF_SIZE ((PLUGIN_BUFFER_SIZE-(10<<10)) / (sizeof(int)))
#define LOOP_REPEAT 8
static volatile int buf[BUF_SIZE];

/* (Byte per loop * loops * 100 ticks per s / ticks)>>10 = KB per s */
#define KB_PER_SEC(delta) (((BUF_SIZE*sizeof(buf[0])*LOOP_REPEAT*100)/delta) >> 10)

enum plugin_status plugin_start(const void* parameter)
{
    (void)parameter;
    bool done = false;
    bool boost = false;
    int count = 0;
    int last_tick = 0;

    rb->lcd_setfont(FONT_SYSFIXED);

    while (!done)
    {
        unsigned i, j;
        int line = 0;
        volatile int x;
        int delta;
        last_tick = *rb->current_tick;

        for(i = 0; i < LOOP_REPEAT; i++)
        {
            for (j = 0; j < BUF_SIZE; j+=4)
            {
                buf[j  ] = j;
                buf[j+1] = j+1;
                buf[j+2] = j+2;
                buf[j+3] = j+3;
            }
        }
        delta = *rb->current_tick - last_tick;
        rb->screens[0]->clear_display();
        rb->screens[0]->putsf(0, line++, "%s", boost?"boosted":"unboosted");
        rb->screens[0]->putsf(0, line++, "bufsize: %u", BUF_SIZE*sizeof(buf[0]));
        rb->screens[0]->putsf(0, line++, "loop#: %d", ++count);
        rb->screens[0]->putsf(0, line++, "write ticks: %2d (%5d KB/s)", delta,
                              KB_PER_SEC(delta));
        last_tick = *rb->current_tick;
        for(i = 0; i < LOOP_REPEAT; i++)
        {
            for(j = 0; j < BUF_SIZE; j+=4)
            {
                x = buf[j  ];
                x = buf[j+2];
                x = buf[j+3];
                x = buf[j+4];
            }
        }
        delta = *rb->current_tick - last_tick;
        rb->screens[0]->putsf(0, line++, "read ticks : %2d (%5d KB/s)", delta,
                              KB_PER_SEC(delta));
        rb->screens[0]->update();

        switch (rb->get_action(CONTEXT_STD, TIMEOUT_NOBLOCK))
        {
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
            case ACTION_STD_PREV:
                if (!boost)
                {
                    rb->cpu_boost(true);
                    boost = true;
                }
                break;

            case ACTION_STD_NEXT:
                if (boost)
                {
                    rb->cpu_boost(false);
                    boost = false;
                }
                break;
#endif
            case ACTION_STD_CANCEL:
                done = true;
                break;
        }
    }

    return PLUGIN_OK;
}