micro_delay.c 639 B

12345678910111213141516171819202122232425262728293031
  1. /*
  2. * Copyright (c) 2018-2020, Renesas Electronics Corporation. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <arch.h>
  7. #include <arch_helpers.h>
  8. #include "micro_delay.h"
  9. #define RCAR_CONV_MICROSEC 1000000U
  10. void
  11. #if IMAGE_BL31
  12. __attribute__ ((section(".system_ram")))
  13. #endif
  14. rcar_micro_delay(uint64_t micro_sec)
  15. {
  16. uint64_t freq;
  17. uint64_t base_count;
  18. uint64_t get_count;
  19. uint64_t wait_time = 0U;
  20. freq = read_cntfrq_el0();
  21. base_count = read_cntpct_el0();
  22. while (micro_sec > wait_time) {
  23. get_count = read_cntpct_el0();
  24. wait_time = ((get_count - base_count) * RCAR_CONV_MICROSEC) / freq;
  25. }
  26. }