aboutsummaryrefslogtreecommitdiff
path: root/lib/chibios-contrib/testhal/STM32/STM32F4xx/FSMC_SDRAM/membench.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chibios-contrib/testhal/STM32/STM32F4xx/FSMC_SDRAM/membench.c')
-rw-r--r--lib/chibios-contrib/testhal/STM32/STM32F4xx/FSMC_SDRAM/membench.c133
1 files changed, 133 insertions, 0 deletions
diff --git a/lib/chibios-contrib/testhal/STM32/STM32F4xx/FSMC_SDRAM/membench.c b/lib/chibios-contrib/testhal/STM32/STM32F4xx/FSMC_SDRAM/membench.c
new file mode 100644
index 000000000..91b9aee6f
--- /dev/null
+++ b/lib/chibios-contrib/testhal/STM32/STM32F4xx/FSMC_SDRAM/membench.c
@@ -0,0 +1,133 @@
1/*
2 ChibiOS/RT - Copyright (C) 2013-2014 Uladzimir Pylinsky aka barthess
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17#include <string.h>
18
19#include "ch.h"
20#include "hal.h"
21
22#include "membench.h"
23#include "memcpy_dma.h"
24
25/*
26 ******************************************************************************
27 * DEFINES
28 ******************************************************************************
29 */
30
31/*
32 ******************************************************************************
33 * EXTERNS
34 ******************************************************************************
35 */
36
37/*
38 ******************************************************************************
39 * PROTOTYPES
40 ******************************************************************************
41 */
42
43/*
44 ******************************************************************************
45 * GLOBAL VARIABLES
46 ******************************************************************************
47 */
48volatile int warning_suppressor;
49
50/*
51 ******************************************************************************
52 ******************************************************************************
53 * LOCAL FUNCTIONS
54 ******************************************************************************
55 ******************************************************************************
56 */
57/*
58 * Calculates memory access time in MiB/s.
59 */
60double speed_mibps(const time_measurement_t *tmu, size_t len) {
61 double size; // MiB
62 double time; // sec
63
64 size = len;
65 size /= 1024 * 1024;
66
67 time = tmu->last;
68 time /= STM32_SYSCLK;
69
70 return size / time;
71}
72
73/*
74 * Calculates memory access time in B/s.
75 */
76uint32_t speed_bps(const time_measurement_t *tmu, size_t len) {
77
78 uint64_t tmp = len;
79 tmp *= STM32_SYSCLK;
80
81 return tmp / tmu->last;
82}
83
84/*
85 ******************************************************************************
86 * EXPORTED FUNCTIONS
87 ******************************************************************************
88 */
89
90/*
91 *
92 */
93void membench_run(membench_t *dest, const membench_t *src,
94 membench_result_t *result) {
95 time_measurement_t mem_tmu;
96 size_t len;
97
98 if (src->size < dest->size)
99 len = src->size;
100 else
101 len = dest->size;
102
103 /* memset */
104 chTMObjectInit(&mem_tmu);
105 chTMStartMeasurementX(&mem_tmu);
106 memset(dest->start, 0x55, dest->size);
107 chTMStopMeasurementX(&mem_tmu);
108 result->memset = speed_bps(&mem_tmu, dest->size);
109
110 /* memcpy */
111 chTMObjectInit(&mem_tmu);
112 chTMStartMeasurementX(&mem_tmu);
113 memcpy(dest->start, src->start, len);
114 chTMStopMeasurementX(&mem_tmu);
115 result->memcpy = speed_bps(&mem_tmu, len);
116
117 /* memcmp */
118 chTMObjectInit(&mem_tmu);
119 chTMStartMeasurementX(&mem_tmu);
120 warning_suppressor = memcmp(dest->start, src->start, len);
121 chTMStopMeasurementX(&mem_tmu);
122 result->memcmp = speed_bps(&mem_tmu, len);
123
124 /* memcpy DMA */
125 memcpy_dma_start();
126 chTMObjectInit(&mem_tmu);
127 chTMStartMeasurementX(&mem_tmu);
128 memcpy_dma(dest->start, src->start, len);
129 chTMStopMeasurementX(&mem_tmu);
130 result->memcpy_dma = speed_bps(&mem_tmu, len);
131 memcpy_dma_stop();
132}
133