1 /* 2 * Copyright (c) 2023-2026, Arm Limited and Contributors. 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/sfcp.h> 11 #include <plat/common/platform.h> 12 #include "rse_platform_api.h" 13 14 #include <platform_def.h> 15 16 int nv_counter_test(void) 17 { 18 enum sfcp_error_t sfcp_err; 19 psa_status_t status; 20 uint32_t old_val; 21 uint32_t new_val; 22 uint32_t id; 23 24 sfcp_err = sfcp_init(); 25 if (sfcp_err != SFCP_ERROR_SUCCESS) { 26 printf("Failed to initialize RSE communication channel - sfcp_error = %d\n", 27 sfcp_err); 28 return -1; 29 } 30 31 for (id = 0; id < 3; id++) { 32 status = rse_platform_nv_counter_read(id, sizeof(old_val), (uint8_t *)&old_val); 33 if (status != PSA_SUCCESS) { 34 printf("Failed during first id=(%d) rse_platform_nv_counter_read - psa_status = %d\n", 35 id, status); 36 return -1; 37 } 38 39 status = rse_platform_nv_counter_increment(id); 40 if (status != PSA_SUCCESS) { 41 printf("Failed during id=(%d) rse_platform_nv_counter_increment - psa_status = %d\n", 42 id, status); 43 return -1; 44 } 45 46 status = rse_platform_nv_counter_read(id, sizeof(new_val), (uint8_t *)&new_val); 47 if (status != PSA_SUCCESS) { 48 printf("Failed during second id=(%d) rse_platform_nv_counter_read - psa_status = %d\n", 49 id, status); 50 return -1; 51 } 52 53 if (old_val + 1 != new_val) { 54 printf("Failed nv_counter_test: old_val (%d) + 1 != new_val (%d)\n", 55 old_val, new_val); 56 return -1; 57 } 58 } 59 printf("Passed nv_counter_test\n"); 60 61 return 0; 62 } 63