-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdwtest.c
More file actions
65 lines (54 loc) · 1.45 KB
/
dwtest.c
File metadata and controls
65 lines (54 loc) · 1.45 KB
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
#include "dwtime.h"
#include "log.h"
#include <deca_device_api.h>
#if defined(__ZEPHYR__)
#include <zephyr/timing/timing.h>
#endif
static int sizes[] = {10, 12, 14, 15, 16, 18, 20, 50, 100, 200, 512};
static unsigned char buf[1024] = {1};
#define DWTEST_REPETITIONS 1000
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
#endif
#ifndef __ZEPHYR__
static const char* LOG_TAG = "DECA";
#endif
#if defined(__ZEPHYR__) && CONFIG_TIMING_FUNCTIONS
void dwtest_spi(void)
{
timing_t start_time, end_time;
uint64_t total_cycles;
uint64_t total_ns;
timing_init();
timing_start();
for (size_t i = 0; i < ARRAY_SIZE(sizes); i++) {
start_time = timing_counter_get();
for (int j = 0; j < DWTEST_REPETITIONS; j++) {
dwt_writetxdata(sizes[i], buf, 0);
}
end_time = timing_counter_get();
total_cycles = timing_cycles_get(&start_time, &end_time);
total_ns = timing_cycles_to_ns_avg(total_cycles, DWTEST_REPETITIONS);
LOG_INF("SPI %d %f usec /byte %f", sizes[i], total_ns / 1000.0,
total_ns / sizes[i] / 1000.0);
}
timing_stop();
}
#else
void dwtest_spi(void)
{
uint64_t start;
uint64_t end;
uint32_t diff;
for (size_t i = 0; i < ARRAY_SIZE(sizes); i++) {
start = dw_get_systime();
for (int j = 0; j < 1000; j++) {
dwt_writetxdata(sizes[i], buf, 0);
}
end = dw_get_systime();
diff = (end - start) / 1000;
LOG_INF("SPI %d %f usec /byte %f", sizes[i], DTU_TO_US(diff),
DTU_TO_US(diff / sizes[i]));
}
}
#endif