|
0
|
1 /*================================================================= |
|
|
2 // |
|
|
3 // kclock1.c |
|
|
4 // |
|
|
5 // Kernel C API Clock test 1 - Real Time Clock |
|
|
6 // |
|
|
7 //========================================================================== |
|
|
8 //####COPYRIGHTBEGIN#### |
|
|
9 // |
|
|
10 // ------------------------------------------- |
|
|
11 // The contents of this file are subject to the Cygnus eCos Public License |
|
|
12 // Version 1.0 (the "License"); you may not use this file except in |
|
|
13 // compliance with the License. You may obtain a copy of the License at |
|
|
14 // http://sourceware.cygnus.com/ecos |
|
|
15 // |
|
|
16 // Software distributed under the License is distributed on an "AS IS" |
|
|
17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the |
|
|
18 // License for the specific language governing rights and limitations under |
|
|
19 // the License. |
|
|
20 // |
|
|
21 // The Original Code is eCos - Embedded Cygnus Operating System, released |
|
|
22 // September 30, 1998. |
|
|
23 // |
|
|
24 // The Initial Developer of the Original Code is Cygnus. Portions created |
|
2
|
25 // by Cygnus are Copyright (C) 1998,1999 Cygnus Solutions. All Rights Reserved. |
|
0
|
26 // ------------------------------------------- |
|
|
27 // |
|
|
28 //####COPYRIGHTEND#### |
|
|
29 //========================================================================== |
|
|
30 //#####DESCRIPTIONBEGIN#### |
|
|
31 // |
|
|
32 // Author(s): dsm |
|
|
33 // Contributors: dsm |
|
|
34 // Date: 1998-03-20 |
|
|
35 // Description: Tests the Kernel Real Time Clock |
|
|
36 // This test creates a thread, starts the scheduler and |
|
|
37 // delays for a time of about 5 seconds. This test should |
|
|
38 // be expected to run for about this length of time. |
|
|
39 // Omissions: |
|
|
40 // Doesn't test alarms attached to RTC. |
|
|
41 // Assumptions: |
|
|
42 // CYGVAR_KERNEL_COUNTERS_CLOCK must be set. |
|
|
43 // Resolution of clock small compared with 5s. |
|
|
44 // Overhead small compared with 5s. |
|
|
45 // Options: |
|
|
46 // CYGIMP_KERNEL_COUNTERS_SINGLE_LIST |
|
|
47 // CYGIMP_KERNEL_COUNTERS_MULTI_LIST |
|
|
48 // CYGVAR_KERNEL_COUNTERS_CLOCK |
|
|
49 // CYGNUM_KERNEL_COUNTERS_MULTI_LIST_SIZE |
|
|
50 //####DESCRIPTIONEND#### |
|
|
51 */ |
|
|
52 |
|
2
|
53 #include <cyg/hal/hal_arch.h> // CYGNUM_HAL_STACK_SIZE_TYPICAL |
|
|
54 |
|
0
|
55 #include <cyg/kernel/kapi.h> |
|
|
56 |
|
|
57 #include <cyg/infra/testcase.h> |
|
|
58 |
|
|
59 |
|
2
|
60 static cyg_uint64 TEST_DELAY; |
|
0
|
61 |
|
2
|
62 #ifdef CYGFUN_KERNEL_THREADS_TIMER |
|
0
|
63 |
|
|
64 #ifdef CYGFUN_KERNEL_API_C |
|
|
65 |
|
|
66 #include "testaux.h" |
|
|
67 |
|
|
68 #define NTHREADS 1 |
|
2
|
69 #define STACKSIZE CYGNUM_HAL_STACK_SIZE_TYPICAL |
|
0
|
70 |
|
|
71 static cyg_handle_t thread[NTHREADS]; |
|
|
72 |
|
|
73 static cyg_thread thread_obj[NTHREADS]; |
|
|
74 static char stack[NTHREADS][STACKSIZE]; |
|
|
75 |
|
|
76 static void entry0( cyg_addrword_t data ) |
|
|
77 { |
|
|
78 cyg_resolution_t res; |
|
|
79 cyg_uint32 ticks; |
|
|
80 cyg_tick_count_t count0, count1; |
|
|
81 cyg_handle_t rtclock, rtcounter; |
|
|
82 |
|
|
83 rtclock = cyg_real_time_clock(); |
|
|
84 cyg_clock_to_counter(rtclock, &rtcounter); |
|
|
85 |
|
|
86 res = cyg_clock_get_resolution (rtclock); |
|
|
87 |
|
|
88 /* RTC takes res.dividend/res.divisor ns/tick */ |
|
|
89 ticks = ((cyg_uint64)TEST_DELAY * res.divisor) / res.dividend; |
|
|
90 |
|
|
91 count0 = cyg_counter_current_value(rtcounter); |
|
|
92 cyg_thread_delay(ticks); |
|
|
93 count1 = cyg_counter_current_value(rtcounter); |
|
|
94 |
|
|
95 CYG_TEST_CHECK(count0+ticks <= count1, |
|
|
96 "real time clock's counter not counting"); |
|
|
97 |
|
|
98 CYG_TEST_CHECK(count1 <= cyg_current_time(),"cyg_current_time()"); |
|
|
99 |
|
|
100 CYG_TEST_PASS_FINISH("Kernel C API Clock 1 OK"); |
|
|
101 } |
|
|
102 |
|
|
103 void kclock1_main( void ) |
|
|
104 { |
|
|
105 CYG_TEST_INIT(); |
|
|
106 |
|
2
|
107 if (cyg_test_is_simulator) { |
|
|
108 TEST_DELAY = 100000000ll; |
|
|
109 } else { |
|
|
110 TEST_DELAY = 3000000000ll; |
|
|
111 } |
|
|
112 |
|
0
|
113 cyg_thread_create(4, entry0 , (cyg_addrword_t)0, "kclock1", |
|
2
|
114 (void *)stack[0], STACKSIZE, &thread[0], &thread_obj[0]); |
|
0
|
115 cyg_thread_resume(thread[0]); |
|
|
116 |
|
|
117 cyg_scheduler_start(); |
|
|
118 } |
|
|
119 |
|
|
120 externC void |
|
|
121 cyg_start( void ) |
|
|
122 { |
|
|
123 kclock1_main(); |
|
|
124 } |
|
|
125 |
|
2
|
126 #else // def CYGFUN_KERNEL_API_C |
|
0
|
127 #define N_A_MSG "Kernel C API layer disabled" |
|
|
128 #endif // def CYGFUN_KERNEL_API_C |
|
2
|
129 #else // def CYGFUN_KERNEL_THREADS_TIMER |
|
|
130 #define N_A_MSG "Kernel threads timer disabled" |
|
|
131 #endif // def CYGFUN_KERNEL_THREADS_TIMER |
|
0
|
132 |
|
|
133 #ifdef N_A_MSG |
|
|
134 externC void |
|
|
135 cyg_start( void ) |
|
|
136 { |
|
|
137 CYG_TEST_INIT(); |
|
2
|
138 CYG_TEST_NA( N_A_MSG ); |
|
0
|
139 } |
|
|
140 #endif // N_A_MSG |
|
|
141 |
|
|
142 // EOF kclock1.c |