blob: 76c99159ad2db96e611fcd468957f8cea479ef37 [file] [log] [blame]
laurenw-arm2ce1e352023-02-07 13:40:05 -06001/*
2 * Copyright (c) 2023, ARM Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <stdint.h>
8#include <stdio.h>
9
10#include <drivers/arm/rss_comms.h>
11#include <plat/common/platform.h>
12#include "rss_platform_api.h"
13
14#include <platform_def.h>
15
16void nv_counter_test(void)
17{
18 psa_status_t status;
19 uint32_t old_val;
20 uint32_t new_val;
21 uint32_t id;
22
23 status = rss_comms_init(PLAT_RSS_AP_SND_MHU_BASE, PLAT_RSS_AP_RCV_MHU_BASE);
24 if (status != PSA_SUCCESS) {
25 printf("Failed to initialize RSS communication channel\n");
26 plat_error_handler(-1);
27 }
28
29 for (id = 0; id < 3; id++) {
30 status = rss_platform_nv_counter_read(id, sizeof(old_val), (uint8_t *)&old_val);
31 if (status != PSA_SUCCESS) {
32 printf("Failed during first id=(%d) rss_platform_nv_counter_read\n",
33 id);
34 plat_error_handler(-1);
35 }
36
37 status = rss_platform_nv_counter_increment(id);
38 if (status != PSA_SUCCESS) {
39 printf("Failed during id=(%d) rss_platform_nv_counter_increment\n",
40 id);
41 plat_error_handler(-1);
42 }
43
44 status = rss_platform_nv_counter_read(id, sizeof(new_val), (uint8_t *)&new_val);
45 if (status != PSA_SUCCESS) {
46 printf("Failed during second id=(%d) rss_platform_nv_counter_read\n",
47 id);
48 plat_error_handler(-1);
49 }
50
51 if (old_val + 1 != new_val) {
52 printf("Failed nv_counter_test: old_val (%d) + 1 != new_val (%d)\n",
53 old_val, new_val);
54 plat_error_handler(-1);
55 }
56 }
57 printf("Passed nv_counter_test\n");
58}