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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
/*
ChibiOS/GFX - Copyright (C) 2012, 2013
Joel Bodenmann aka Tectu <joel@unormal.org>
This file is part of ChibiOS/GFX.
ChibiOS/GFX 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 3 of the License, or
(at your option) any later version.
ChibiOS/GFX is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ch.h"
#include "hal.h"
#include "chprintf.h"
#include "stdlib.h"
#include "string.h"
#include "gfx.h"
#define SCB_DEMCR (*(volatile unsigned *)0xE000EDFC)
#define CPU_RESET_CYCLECOUNTER do { SCB_DEMCR = SCB_DEMCR | 0x01000000; \
DWT_CYCCNT = 0; \
DWT_CTRL = DWT_CTRL | 1 ; } while(0)
static int uitoa(unsigned int value, char * buf, int max) {
int n = 0;
int i = 0;
unsigned int tmp = 0;
if (NULL == buf)
return -3;
if (2 > max)
return -4;
i=1;
tmp = value;
if (0 > tmp) {
tmp *= -1;
i++;
}
for (;;) {
tmp /= 10;
if (0 >= tmp)
break;
i++;
}
if (i >= max) {
buf[0] = '?';
buf[1] = 0x0;
return 2;
}
n = i;
tmp = value;
if (0 > tmp) {
tmp *= -1;
}
buf[i--] = 0x0;
for (;;) {
buf[i--] = (tmp % 10) + '0';
tmp /= 10;
if (0 >= tmp) {
break;
}
}
if (-1 != i) {
buf[i--] = '-';
}
return n;
}
void benchmark(void) {
uint32_t i, pixels, ms, pps;
char pps_str[25];
coord_t height, width, rx, ry, rcx, rcy;
color_t random_color;
font_t font;
gdispSetOrientation(GDISP_ROTATE_90);
gdispClear(Black);
width = gdispGetWidth();
height = gdispGetHeight();
font = gdispOpenFont("UI2 Double");
gdispDrawStringBox(0, 0, width, 30, "ChibiOS/GFX - Benchmark", font, White, justifyCenter);
font = gdispOpenFont("UI2");
gdispDrawStringBox(0, height/2, width, 30, "5000 random rectangles", font, White, justifyCenter);
chThdSleepMilliseconds(3000);
/* seed for the rand() */
srand(DWT_CYCCNT);
pixels = 0;
CPU_RESET_CYCLECOUNTER;
for (i = 0; i < 5000; i++) {
random_color = (rand() % 65535);
rx = (rand() % (width-10));
ry = (rand() % (height-10));
rcx = (rand() % ((width-rx)-10))+10;
rcy = (rand() % ((height-ry)-10))+10;
gdispFillArea(rx, ry, rcx, rcy, random_color);
pixels += (rcx+1)*(rcy+1);
}
ms = DWT_CYCCNT / 168000;
pps = (float)pixels/((float)ms/1000.0f);
memset (pps_str, 0, sizeof(pps_str));
uitoa(pps, pps_str, sizeof(pps_str));
strcat(pps_str, " Pixels/s");
font = gdispOpenFont("UI2 Double");
gdispClear(Black);
gdispDrawStringBox(0, 0, width, 30, "ChibiOS/GFX - Benchmark", font, White, justifyCenter);
gdispDrawStringBox(0, height/2, width, 30, pps_str, font, White, justifyCenter);
//gdispDrawString(20, height/2, pps_str, font, White);
}
int main(void) {
halInit();
chSysInit();
gdispInit();
benchmark();
while(TRUE) {
chThdSleepMilliseconds(500);
}
return 0;
}
|