1 /*
2 * Copyright (c) 2020, Teslabs Engineering S.L.
3 * Copyright (c) 2022, Basalte bv
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
8 #include <zephyr/linker/devicetree_regions.h>
9 #include <zephyr/kernel.h>
10 #include <zephyr/ztest.h>
11
12 /** Buffer size. */
13 #define BUF_SIZE 64U
14 #define BUF_DEF(label) static uint32_t buf_##label[BUF_SIZE] \
15 Z_GENERIC_SECTION(LINKER_DT_NODE_REGION_NAME(DT_NODELABEL(label)))
16
17 /**
18 * @brief Helper function to test RAM r/w.
19 *
20 * @param mem RAM memory location to be tested.
21 */
test_ram_rw(uint32_t * mem,size_t size)22 static void test_ram_rw(uint32_t *mem, size_t size)
23 {
24 /* fill memory with number range (0, BUF_SIZE - 1) */
25 for (size_t i = 0U; i < size / sizeof(uint32_t); i++) {
26 mem[i] = i;
27 }
28
29 /* check that memory contains written range */
30 for (size_t i = 0U; i < size / sizeof(uint32_t); i++) {
31 zassert_equal(mem[i], i, "Unexpected content on byte %ld", i);
32 }
33 }
34
35 #if DT_NODE_HAS_STATUS(DT_NODELABEL(sdram1), okay)
36 BUF_DEF(sdram1);
37 #endif
38 #if DT_NODE_HAS_STATUS(DT_NODELABEL(sdram2), okay)
39 BUF_DEF(sdram2);
40 #endif
41 #if DT_NODE_HAS_STATUS(DT_NODELABEL(sram1), okay)
42 BUF_DEF(sram1);
43 #endif
44 #if DT_NODE_HAS_STATUS(DT_NODELABEL(sram2), okay)
45 BUF_DEF(sram2);
46 #endif
47
48 #if DT_NODE_HAS_STATUS(DT_NODELABEL(ram0), okay)
49 #define RAM_SIZE DT_REG_SIZE(DT_NODELABEL(ram0))
50 static uint32_t *buf_ram0 = (uint32_t *)DT_REG_ADDR(DT_NODELABEL(ram0));
51 #endif
52
53 ZTEST_SUITE(test_ram, NULL, NULL, NULL, NULL, NULL);
54
ZTEST(test_ram,test_sdram1)55 ZTEST(test_ram, test_sdram1)
56 {
57 #if DT_NODE_HAS_STATUS(DT_NODELABEL(sdram1), okay)
58 test_ram_rw(buf_sdram1, BUF_SIZE);
59 #else
60 ztest_test_skip();
61 #endif
62 }
63
ZTEST(test_ram,test_ram0)64 ZTEST(test_ram, test_ram0)
65 {
66 #if DT_NODE_HAS_STATUS(DT_NODELABEL(ram0), okay)
67 test_ram_rw(buf_ram0, RAM_SIZE);
68 #else
69 ztest_test_skip();
70 #endif
71 }
72
ZTEST(test_ram,test_sdram2)73 ZTEST(test_ram, test_sdram2)
74 {
75 #if DT_NODE_HAS_STATUS(DT_NODELABEL(sdram2), okay)
76 test_ram_rw(buf_sdram2, BUF_SIZE);
77 #else
78 ztest_test_skip();
79 #endif
80 }
81
ZTEST(test_ram,test_sram1)82 ZTEST(test_ram, test_sram1)
83 {
84 #if DT_NODE_HAS_STATUS(DT_NODELABEL(sram1), okay)
85 test_ram_rw(buf_sram1, BUF_SIZE);
86 #else
87 ztest_test_skip();
88 #endif
89 }
90
ZTEST(test_ram,test_sram2)91 ZTEST(test_ram, test_sram2)
92 {
93 #if DT_NODE_HAS_STATUS(DT_NODELABEL(sram2), okay)
94 test_ram_rw(buf_sram2, BUF_SIZE);
95 #else
96 ztest_test_skip();
97 #endif
98 }
99