|
| 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/zephyr.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 | + */ |
| 22 | +static void test_ram_rw(uint32_t *mem) |
| 23 | +{ |
| 24 | + /* fill memory with number range (0, BUF_SIZE - 1) */ |
| 25 | + for (size_t i = 0U; i < BUF_SIZE; i++) { |
| 26 | + mem[i] = i; |
| 27 | + } |
| 28 | + |
| 29 | + /* check that memory contains written range */ |
| 30 | + for (size_t i = 0U; i < BUF_SIZE; i++) { |
| 31 | + zassert_equal(mem[i], i, "Unexpected content"); |
| 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 | +ZTEST_SUITE(test_ram, NULL, NULL, NULL, NULL, NULL); |
| 49 | + |
| 50 | +ZTEST(test_ram, test_sdram1) |
| 51 | +{ |
| 52 | +#if DT_NODE_HAS_STATUS(DT_NODELABEL(sdram1), okay) |
| 53 | + test_ram_rw(buf_sdram1); |
| 54 | +#else |
| 55 | + ztest_test_skip(); |
| 56 | +#endif |
| 57 | +} |
| 58 | + |
| 59 | +ZTEST(test_ram, test_sdram2) |
| 60 | +{ |
| 61 | +#if DT_NODE_HAS_STATUS(DT_NODELABEL(sdram2), okay) |
| 62 | + test_ram_rw(buf_sdram2); |
| 63 | +#else |
| 64 | + ztest_test_skip(); |
| 65 | +#endif |
| 66 | +} |
| 67 | + |
| 68 | +ZTEST(test_ram, test_sram1) |
| 69 | +{ |
| 70 | +#if DT_NODE_HAS_STATUS(DT_NODELABEL(sram1), okay) |
| 71 | + test_ram_rw(buf_sram1); |
| 72 | +#else |
| 73 | + ztest_test_skip(); |
| 74 | +#endif |
| 75 | +} |
| 76 | + |
| 77 | +ZTEST(test_ram, test_sram2) |
| 78 | +{ |
| 79 | +#if DT_NODE_HAS_STATUS(DT_NODELABEL(sram2), okay) |
| 80 | + test_ram_rw(buf_sram2); |
| 81 | +#else |
| 82 | + ztest_test_skip(); |
| 83 | +#endif |
| 84 | +} |
0 commit comments