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