blob: f9e001ea87271fb76f6e879c8996608fe6fe5a02 [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
Sandrine Bailleuxe1da6c42023-05-05 13:59:07 +020016int nv_counter_test(void)
laurenw-arm2ce1e352023-02-07 13:40:05 -060017{
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");
Sandrine Bailleuxe1da6c42023-05-05 13:59:07 +020026 return -1;
laurenw-arm2ce1e352023-02-07 13:40:05 -060027 }
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);
Sandrine Bailleuxe1da6c42023-05-05 13:59:07 +020034 return -1;
laurenw-arm2ce1e352023-02-07 13:40:05 -060035 }
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);
Sandrine Bailleuxe1da6c42023-05-05 13:59:07 +020041 return -1;
laurenw-arm2ce1e352023-02-07 13:40:05 -060042 }
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);
Sandrine Bailleuxe1da6c42023-05-05 13:59:07 +020048 return -1;
laurenw-arm2ce1e352023-02-07 13:40:05 -060049 }
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);
Sandrine Bailleuxe1da6c42023-05-05 13:59:07 +020054 return -1;
laurenw-arm2ce1e352023-02-07 13:40:05 -060055 }
56 }
57 printf("Passed nv_counter_test\n");
Sandrine Bailleuxe1da6c42023-05-05 13:59:07 +020058
59 return 0;
laurenw-arm2ce1e352023-02-07 13:40:05 -060060}