|
0
|
1 //========================================================================== |
|
|
2 // |
|
|
3 // wallclock.cxx |
|
|
4 // |
|
|
5 // WallClock test |
|
|
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): nickg |
|
|
33 // Contributors: nickg |
|
|
34 // Date: 1998-07-20 |
|
|
35 // Description: Tests the Kernel Wall Clock |
|
|
36 // This test exercises the WallClock class and checks that it |
|
|
37 // keeps time correctly. |
|
|
38 //####DESCRIPTIONEND#### |
|
|
39 // ------------------------------------------------------------------------- |
|
|
40 |
|
|
41 #include <pkgconf/kernel.h> |
|
|
42 |
|
|
43 #include <cyg/kernel/thread.hxx> |
|
|
44 #include <cyg/kernel/thread.inl> |
|
|
45 #include <cyg/kernel/sched.hxx> |
|
|
46 #include <cyg/kernel/mutex.hxx> |
|
|
47 #include <cyg/kernel/sema.hxx> |
|
|
48 #include <cyg/kernel/clock.hxx> |
|
|
49 |
|
|
50 #include <cyg/kernel/diag.h> |
|
|
51 |
|
|
52 #include <cyg/devs/wallclock.hxx> |
|
|
53 |
|
|
54 #include <cyg/infra/testcase.h> |
|
|
55 |
|
2
|
56 #if defined(CYGFUN_KERNEL_THREADS_TIMER) && \ |
|
|
57 defined(CYGVAR_KERNEL_COUNTERS_CLOCK) |
|
|
58 |
|
0
|
59 #include <cyg/kernel/sched.inl> |
|
|
60 |
|
|
61 // ------------------------------------------------------------------------- |
|
|
62 // Data for the test |
|
|
63 |
|
2
|
64 #ifdef CYGNUM_HAL_STACK_SIZE_TYPICAL |
|
|
65 #define STACKSIZE CYGNUM_HAL_STACK_SIZE_TYPICAL |
|
|
66 #else |
|
0
|
67 #define STACKSIZE (2*1024) // size of thread stack |
|
2
|
68 #endif |
|
0
|
69 |
|
|
70 char thread_stack[STACKSIZE]; |
|
|
71 |
|
|
72 inline void *operator new(size_t size, void *ptr) { return ptr; }; |
|
|
73 |
|
|
74 // array of threads. |
|
|
75 char thread[sizeof(Cyg_Thread)]; |
|
|
76 |
|
|
77 Cyg_Thread *th; |
|
|
78 |
|
|
79 #define EPOCH 900000000U |
|
|
80 |
|
2
|
81 // MN10300 sim takes 1min15secs to do one loop on 300MHz PII. |
|
|
82 #define LOOPS_SIM 2 |
|
|
83 #define LOOPS_HW 20 |
|
0
|
84 |
|
2
|
85 cyg_int32 loops = LOOPS_HW; |
|
0
|
86 cyg_tick_count one_sec; |
|
|
87 |
|
|
88 // ------------------------------------------------------------------------- |
|
|
89 // Thread body |
|
|
90 |
|
|
91 |
|
|
92 void wallclock_thread( CYG_ADDRWORD id ) |
|
|
93 { |
|
|
94 cyg_uint32 wtime; |
|
|
95 |
|
|
96 Cyg_WallClock::wallclock->set_current_time( EPOCH ); |
|
|
97 |
|
2
|
98 for( int i = 0; i < loops; i++ ) |
|
0
|
99 { |
|
2
|
100 CYG_TEST_STILL_ALIVE(i, "tick..."); |
|
|
101 |
|
0
|
102 wtime = Cyg_WallClock::wallclock->get_current_time(); |
|
|
103 |
|
|
104 if(wtime != EPOCH+i) |
|
|
105 { |
|
|
106 CYG_TEST_FAIL_FINISH( "Clock out of sync" ); |
|
|
107 } |
|
|
108 |
|
|
109 th->delay( one_sec ); |
|
|
110 } |
|
|
111 |
|
|
112 CYG_TEST_PASS_FINISH("Wallclock OK"); |
|
|
113 |
|
|
114 } |
|
|
115 |
|
|
116 // ------------------------------------------------------------------------- |
|
|
117 |
|
|
118 |
|
|
119 externC void |
|
|
120 cyg_start( void ) |
|
|
121 { |
|
|
122 CYG_TEST_INIT(); |
|
2
|
123 |
|
|
124 CYG_TEST_INFO("Starting wallclock test"); |
|
|
125 |
|
|
126 if( cyg_test_is_simulator ) loops = LOOPS_SIM; |
|
0
|
127 |
|
|
128 Cyg_Clock::cyg_resolution res = Cyg_Clock::real_time_clock->get_resolution(); |
|
|
129 |
|
|
130 one_sec = ( res.divisor * 1000000000LL ) / res.dividend ; |
|
|
131 |
|
2
|
132 th = new((void *)&thread) Cyg_Thread(CYG_SCHED_DEFAULT_INFO, |
|
|
133 wallclock_thread, |
|
0
|
134 0, |
|
2
|
135 "wallclock_thread", |
|
|
136 (CYG_ADDRESS)thread_stack, |
|
|
137 STACKSIZE |
|
0
|
138 ); |
|
|
139 |
|
|
140 th->resume(); |
|
|
141 |
|
|
142 // Get the world going |
|
|
143 Cyg_Scheduler::scheduler.start(); |
|
|
144 |
|
|
145 } |
|
|
146 |
|
2
|
147 #else // if defined(CYGFUN_KERNEL_THREADS_TIMER) etc... |
|
|
148 |
|
|
149 externC void |
|
|
150 cyg_start( void ) |
|
|
151 { |
|
|
152 CYG_TEST_INIT(); |
|
|
153 CYG_TEST_PASS_FINISH("N/A: Kernel real-time clock/threads timer disabled"); |
|
|
154 } |
|
|
155 |
|
|
156 #endif // if defined(CYGFUN_KERNEL_THREADS_TIMER) etc... |
|
|
157 |
|
0
|
158 // ------------------------------------------------------------------------- |
|
|
159 // EOF wallclock.cxx |