blob: 179ec4b0e5c7d36c3fe05c9a8cdfb4c7cf93cd28 [file] [log] [blame]
laurenw-arm2ce1e352023-02-07 13:40:05 -06001/*
laurenw-arm116f10c2023-06-13 16:43:39 -05002 * Copyright (c) 2023, Arm Limited. All rights reserved.
laurenw-arm2ce1e352023-02-07 13:40:05 -06003 *
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) {
laurenw-arm5f939a92023-07-14 14:24:55 -050025 printf("Failed to initialize RSS communication channel - psa_status = %d\n", status);
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) {
laurenw-arm5f939a92023-07-14 14:24:55 -050032 printf("Failed during first id=(%d) rss_platform_nv_counter_read - psa_status = %d\n",
33 id, status);
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) {
laurenw-arm5f939a92023-07-14 14:24:55 -050039 printf("Failed during id=(%d) rss_platform_nv_counter_increment - psa_status = %d\n",
40 id, status);
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) {
laurenw-arm5f939a92023-07-14 14:24:55 -050046 printf("Failed during second id=(%d) rss_platform_nv_counter_read - psa_status = %d\n",
47 id, status);
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}