CV_GenTimer.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*-----------------------------------------------------------------------------
  2. * Name: CV_GenTimer.c
  3. * Purpose: CMSIS CORE validation tests implementation
  4. *-----------------------------------------------------------------------------
  5. * Copyright (c) 2017 ARM Limited. All rights reserved.
  6. *----------------------------------------------------------------------------*/
  7. #include "CV_Framework.h"
  8. #include "cmsis_cv.h"
  9. /*-----------------------------------------------------------------------------
  10. * Test implementation
  11. *----------------------------------------------------------------------------*/
  12. /*-----------------------------------------------------------------------------
  13. * Test cases
  14. *----------------------------------------------------------------------------*/
  15. /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
  16. void TC_GenTimer_CNTFRQ(void) {
  17. const uint32_t cntfrq1 = __get_CNTFRQ();
  18. __set_CNTFRQ(cntfrq1 + 1U);
  19. const uint32_t cntfrq2 = __get_CNTFRQ();
  20. ASSERT_TRUE((cntfrq1 + 1U) == cntfrq2);
  21. __set_CNTFRQ(cntfrq1);
  22. }
  23. /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
  24. void TC_GenTimer_CNTP_TVAL(void) {
  25. const uint32_t cntp_tval1 = __get_CNTP_TVAL();
  26. __set_CNTP_TVAL(cntp_tval1 + 1U);
  27. const uint32_t cntp_tval2 = __get_CNTP_TVAL();
  28. ASSERT_TRUE((cntp_tval2 - cntp_tval1) >= 1ULL);
  29. }
  30. /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
  31. void TC_GenTimer_CNTP_CTL(void) {
  32. static const uint32_t CNTP_CTL_ENABLE = 0x01U;
  33. const uint32_t cntp_ctl = __get_CNTP_CTL();
  34. const uint32_t cntp_ctl_toggled = (cntp_ctl & (~CNTP_CTL_ENABLE)) | ((~cntp_ctl) & CNTP_CTL_ENABLE);
  35. __set_CNTP_CTL(cntp_ctl_toggled);
  36. const uint32_t cntp_ctl_new = __get_CNTP_CTL();
  37. ASSERT_TRUE((cntp_ctl_toggled & CNTP_CTL_ENABLE) == (cntp_ctl_new & CNTP_CTL_ENABLE));
  38. __set_CNTP_CTL(cntp_ctl);
  39. }
  40. /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
  41. void TC_GenTimer_CNTPCT(void) {
  42. const uint64_t cntpct1 = __get_CNTPCT();
  43. for(int i=0; i<10; i++);
  44. const uint64_t cntpct2 = __get_CNTPCT();
  45. ASSERT_TRUE((cntpct2 - cntpct1) <= 120ULL);
  46. }
  47. /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
  48. void TC_GenTimer_CNTP_CVAL(void) {
  49. const uint64_t cntp_cval1 = __get_CNTP_CVAL();
  50. __set_CNTP_CVAL(cntp_cval1 + 1ULL);
  51. const uint64_t cntp_cval2 = __get_CNTP_CVAL();
  52. ASSERT_TRUE((cntp_cval2 - cntp_cval1) >= 1ULL);
  53. }