nv_counter_test.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright (c) 2023, Arm Limited. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <stdint.h>
  7. #include <stdio.h>
  8. #include <drivers/arm/rse_comms.h>
  9. #include <plat/common/platform.h>
  10. #include "rse_platform_api.h"
  11. #include <platform_def.h>
  12. int nv_counter_test(void)
  13. {
  14. psa_status_t status;
  15. uint32_t old_val;
  16. uint32_t new_val;
  17. uint32_t id;
  18. status = rse_comms_init(PLAT_RSE_AP_SND_MHU_BASE, PLAT_RSE_AP_RCV_MHU_BASE);
  19. if (status != PSA_SUCCESS) {
  20. printf("Failed to initialize RSE communication channel - psa_status = %d\n", status);
  21. return -1;
  22. }
  23. for (id = 0; id < 3; id++) {
  24. status = rse_platform_nv_counter_read(id, sizeof(old_val), (uint8_t *)&old_val);
  25. if (status != PSA_SUCCESS) {
  26. printf("Failed during first id=(%d) rse_platform_nv_counter_read - psa_status = %d\n",
  27. id, status);
  28. return -1;
  29. }
  30. status = rse_platform_nv_counter_increment(id);
  31. if (status != PSA_SUCCESS) {
  32. printf("Failed during id=(%d) rse_platform_nv_counter_increment - psa_status = %d\n",
  33. id, status);
  34. return -1;
  35. }
  36. status = rse_platform_nv_counter_read(id, sizeof(new_val), (uint8_t *)&new_val);
  37. if (status != PSA_SUCCESS) {
  38. printf("Failed during second id=(%d) rse_platform_nv_counter_read - psa_status = %d\n",
  39. id, status);
  40. return -1;
  41. }
  42. if (old_val + 1 != new_val) {
  43. printf("Failed nv_counter_test: old_val (%d) + 1 != new_val (%d)\n",
  44. old_val, new_val);
  45. return -1;
  46. }
  47. }
  48. printf("Passed nv_counter_test\n");
  49. return 0;
  50. }