]> begriffs open source - cmsis/blob - CMSIS/CoreValidation/Source/CV_GenTimer.c
CoreValidation: Added test cases for Cortex-M cache functions.
[cmsis] / CMSIS / CoreValidation / Source / CV_GenTimer.c
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
8 #include "CV_Framework.h"
9 #include "cmsis_cv.h"
10
11 /*-----------------------------------------------------------------------------
12  *      Test implementation
13  *----------------------------------------------------------------------------*/
14
15 /*-----------------------------------------------------------------------------
16  *      Test cases
17  *----------------------------------------------------------------------------*/
18
19  
20 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
21 void TC_GenTimer_CNTFRQ(void) {
22   const uint32_t cntfrq1 = __get_CNTFRQ();
23   __set_CNTFRQ(cntfrq1 + 1U);
24   const uint32_t cntfrq2 = __get_CNTFRQ();
25
26   ASSERT_TRUE((cntfrq1 + 1U) == cntfrq2);
27   
28   __set_CNTFRQ(cntfrq1);
29 }
30
31 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
32 void TC_GenTimer_CNTP_TVAL(void) {
33   const uint32_t cntp_tval1 = __get_CNTP_TVAL();
34   __set_CNTP_TVAL(cntp_tval1 + 1U);
35   const uint32_t cntp_tval2 = __get_CNTP_TVAL();
36
37   ASSERT_TRUE((cntp_tval2 - cntp_tval1) >= 1ULL);
38 }
39
40 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
41 void TC_GenTimer_CNTP_CTL(void) {
42   static const uint32_t CNTP_CTL_ENABLE = 0x01U;
43   const uint32_t cntp_ctl = __get_CNTP_CTL();
44   const uint32_t cntp_ctl_toggled = (cntp_ctl & (~CNTP_CTL_ENABLE)) | ((~cntp_ctl) & CNTP_CTL_ENABLE);
45   __set_CNTP_CTL(cntp_ctl_toggled);
46
47   const uint32_t cntp_ctl_new = __get_CNTP_CTL();
48
49   ASSERT_TRUE((cntp_ctl_toggled & CNTP_CTL_ENABLE) == (cntp_ctl_new & CNTP_CTL_ENABLE));
50   
51   __set_CNTP_CTL(cntp_ctl);
52 }
53
54 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
55 void TC_GenTimer_CNTPCT(void) {
56   const uint64_t cntpct1 = __get_CNTPCT();
57   for(int i=0; i<10; i++);
58   const uint64_t cntpct2 = __get_CNTPCT();
59
60   ASSERT_TRUE((cntpct2 - cntpct1) <= 120ULL);
61 }
62
63 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
64 void TC_GenTimer_CNTP_CVAL(void) {
65   const uint64_t cntp_cval1 = __get_CNTP_CVAL();
66   __set_CNTP_CVAL(cntp_cval1 + 1ULL);
67   const uint64_t cntp_cval2 = __get_CNTP_CVAL();
68
69   ASSERT_TRUE((cntp_cval2 - cntp_cval1) >= 1ULL);
70 }