|
0
|
1 /*================================================================= |
|
|
2 // |
|
|
3 // kclock0.c |
|
|
4 // |
|
|
5 // Kernel C API Clock test 0 |
|
|
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 some basic clock functions. |
|
|
36 //####DESCRIPTIONEND#### |
|
|
37 */ |
|
|
38 |
|
|
39 #include <cyg/kernel/kapi.h> |
|
|
40 |
|
|
41 #include <cyg/infra/testcase.h> |
|
|
42 |
|
|
43 #ifdef CYGVAR_KERNEL_COUNTERS_CLOCK |
|
|
44 |
|
|
45 #ifdef CYGFUN_KERNEL_API_C |
|
|
46 |
|
|
47 #include "testaux.h" |
|
|
48 |
|
|
49 cyg_alarm_t call_me; |
|
|
50 |
|
|
51 cyg_counter counter0o, counter1o; |
|
|
52 cyg_handle_t counter0, counter1; |
|
|
53 |
|
|
54 cyg_alarm alarmo[3]; |
|
|
55 cyg_handle_t alarm0, alarm1, alarm2; |
|
|
56 |
|
|
57 cyg_resolution_t res, res0, res1; |
|
|
58 |
|
|
59 cyg_clock clock0o; |
|
|
60 cyg_handle_t clock0; |
|
|
61 |
|
|
62 const cyg_uint32 big_number = 3333222111u; |
|
|
63 |
|
|
64 cyg_bool_t flash( void ) |
|
|
65 { |
|
|
66 cyg_counter_create( &counter0, &counter0o ); |
|
|
67 cyg_counter_create( &counter1, &counter1o ); |
|
|
68 |
|
|
69 cyg_alarm_create( counter0, |
|
|
70 call_me, |
|
|
71 (cyg_addrword_t)12, |
|
|
72 &alarm0, |
|
|
73 &alarmo[0]); |
|
|
74 |
|
|
75 res.dividend = 1; |
|
|
76 res.divisor = 2; |
|
|
77 |
|
|
78 cyg_clock_create( res, &clock0, &clock0o ); |
|
|
79 cyg_clock_delete( clock0 ); |
|
|
80 |
|
|
81 cyg_alarm_delete( alarm0 ); |
|
|
82 |
|
|
83 cyg_counter_delete( counter0 ); |
|
|
84 cyg_counter_delete( counter1 ); |
|
|
85 |
|
|
86 return true; |
|
|
87 } |
|
|
88 |
|
|
89 /* Testing alarms |
|
|
90 // |
|
|
91 // call_me is a function that will be called when an alarm is |
|
|
92 // triggered. It updates a global variable called which is CHECKed |
|
|
93 // explicitly to see if the approriate alarms have been called. |
|
|
94 */ |
|
|
95 |
|
|
96 cyg_uint16 called = 0x0; |
|
|
97 |
|
|
98 void call_me(cyg_handle_t alarm, cyg_addrword_t data) |
|
|
99 { |
|
|
100 called ^= (int)data; |
|
|
101 } |
|
|
102 |
|
|
103 void call_me2(cyg_handle_t alarm, cyg_addrword_t data) |
|
|
104 { |
|
|
105 call_me(alarm, (cyg_addrword_t)((int)data^0x10)); |
|
|
106 } |
|
|
107 |
|
|
108 |
|
|
109 void kclock0_main(void) |
|
|
110 { |
|
|
111 CYG_TEST_INIT(); |
|
|
112 |
|
|
113 CHECK(flash()); |
|
|
114 CHECK(flash()); |
|
|
115 |
|
|
116 cyg_counter_create( &counter0, &counter0o); |
|
|
117 |
|
|
118 CHECK( 0 == cyg_counter_current_value( counter0 ) ); |
|
|
119 |
|
|
120 cyg_counter_tick(counter0); |
|
|
121 |
|
|
122 CHECK( 1 == cyg_counter_current_value(counter0) ); |
|
|
123 |
|
|
124 cyg_counter_tick(counter0); |
|
|
125 |
|
|
126 CHECK( 2 == cyg_counter_current_value(counter0) ); |
|
|
127 |
|
|
128 cyg_counter_set_value( counter0, 0xffffffff ); |
|
|
129 |
|
|
130 CHECK( 0xffffffff == cyg_counter_current_value(counter0) ); |
|
|
131 |
|
2
|
132 cyg_counter_tick(counter0); // Overflows 32 bits |
|
0
|
133 |
|
|
134 CHECK( 0x100000000ULL == cyg_counter_current_value(counter0) ); |
|
|
135 |
|
|
136 cyg_counter_set_value(counter0, 11); |
|
|
137 CHECK( 11 == cyg_counter_current_value(counter0) ); |
|
|
138 |
|
|
139 /* the call_me functions cause the "called" bits to toggle |
|
|
140 // checking the value of called checks the parity of # of calls |
|
|
141 // made by each alarm. |
|
|
142 */ |
|
|
143 |
|
|
144 cyg_alarm_create(counter0, |
|
|
145 call_me, (cyg_addrword_t)0x1, &alarm0, &alarmo[0]); |
|
|
146 cyg_alarm_create(counter0, |
|
|
147 call_me, (cyg_addrword_t)0x2, &alarm1, &alarmo[1]); |
|
|
148 cyg_alarm_create(counter0, |
|
|
149 call_me2, (cyg_addrword_t)0x4, &alarm2, &alarmo[2]); |
|
|
150 |
|
|
151 CHECK( 0x00 == called ); |
|
|
152 cyg_alarm_initialize(alarm0, 12,3); |
|
|
153 cyg_alarm_initialize(alarm2, 21,2); |
|
|
154 CHECK( 0x00 == called ); |
|
|
155 |
|
2
|
156 cyg_counter_tick(counter0); /* 12 a0 */ |
|
0
|
157 CHECK( 0x01 == called ); |
|
|
158 |
|
|
159 cyg_alarm_initialize(alarm1, 13,0); |
|
2
|
160 cyg_counter_tick(counter0); /* 13 a1 */ |
|
0
|
161 CHECK( 0x03 == called ); |
|
|
162 |
|
|
163 cyg_alarm_initialize(alarm1, 17,0); |
|
2
|
164 cyg_counter_tick(counter0); /* 14 */ |
|
0
|
165 CHECK( 0x03 == called ); |
|
|
166 |
|
2
|
167 cyg_counter_tick(counter0); /* 15 a0 */ |
|
0
|
168 CHECK( 0x02 == called ); |
|
|
169 |
|
2
|
170 cyg_counter_tick(counter0); /* 16 */ |
|
|
171 cyg_counter_tick(counter0); /* 17 a1 */ |
|
0
|
172 CHECK( 0x00 == called ); |
|
|
173 |
|
2
|
174 cyg_counter_tick(counter0); /* 18 a0 */ |
|
0
|
175 CHECK( 0x01 == called ); |
|
|
176 |
|
2
|
177 cyg_counter_tick(counter0); /* 19 */ |
|
|
178 cyg_counter_tick(counter0); /* 20 */ |
|
|
179 cyg_counter_tick(counter0); /* 21 a0 a2 */ |
|
0
|
180 CHECK( 0x14 == called ); |
|
|
181 |
|
2
|
182 cyg_counter_tick(counter0); /* 22 */ |
|
|
183 cyg_counter_tick(counter0); /* 23 a2 */ |
|
0
|
184 CHECK( 0x00 == called ); |
|
|
185 |
|
|
186 cyg_alarm_disable(alarm2); |
|
|
187 |
|
2
|
188 cyg_counter_tick(counter0); /* 24 a0 */ |
|
|
189 cyg_counter_tick(counter0); /* 25 */ |
|
0
|
190 CHECK( 0x01 == called ); |
|
|
191 |
|
|
192 cyg_alarm_enable(alarm2); /* a2 (enabled at 25) */ |
|
|
193 CHECK( 0x15 == called ); |
|
|
194 |
|
2
|
195 cyg_counter_tick(counter0); /* 26 */ |
|
0
|
196 CHECK( 0x15 == called ); |
|
|
197 |
|
2
|
198 cyg_counter_tick(counter0); /* 27 a0 a2 */ |
|
|
199 cyg_counter_tick(counter0); /* 28 */ |
|
0
|
200 CHECK( 0x00 == called ); |
|
|
201 |
|
2
|
202 cyg_counter_tick(counter0); /* 29 a2 */ |
|
|
203 cyg_counter_tick(counter0); /* 30 a0 */ |
|
|
204 cyg_counter_tick(counter0); /* 31 a2 */ |
|
0
|
205 CHECK( 0x01 == called ); |
|
|
206 |
|
|
207 res0.dividend = 100; |
|
|
208 res0.divisor = 3; |
|
|
209 |
|
|
210 cyg_clock_create( res0, &clock0, &clock0o ); |
|
|
211 |
|
|
212 res1 = cyg_clock_get_resolution(clock0); |
|
|
213 CHECK( res0.dividend == res1.dividend ); |
|
|
214 CHECK( res0.divisor == res1.divisor ); |
|
|
215 |
|
|
216 res1.dividend = 12; |
|
|
217 res1.divisor = 25; |
|
|
218 |
|
|
219 cyg_clock_set_resolution(clock0, res1); |
|
|
220 res0 = cyg_clock_get_resolution(clock0); |
|
|
221 CHECK( res0.dividend == res1.dividend ); |
|
|
222 CHECK( res0.divisor == res1.divisor ); |
|
|
223 |
|
|
224 cyg_clock_to_counter(clock0, &counter1); |
|
|
225 |
|
|
226 CHECK( 0 == cyg_counter_current_value( counter1 ) ); |
|
|
227 CHECK( 0 == cyg_current_time() ); |
|
|
228 |
|
|
229 cyg_counter_tick(counter1); |
|
|
230 |
|
|
231 CHECK( 1 == cyg_counter_current_value(counter1) ); |
|
|
232 |
|
|
233 res0 = cyg_clock_get_resolution(cyg_real_time_clock()); |
|
|
234 |
|
|
235 /* Current time should be 0 as interrupts will still be disabled */ |
|
|
236 CHECK( 0 == cyg_current_time() ); |
|
|
237 |
|
|
238 CYG_TEST_PASS_FINISH("Kernel C API Clock 0 OK"); |
|
|
239 } |
|
|
240 |
|
|
241 externC void |
|
|
242 cyg_start( void ) |
|
|
243 { |
|
|
244 kclock0_main(); |
|
|
245 } |
|
|
246 |
|
|
247 #else // def CYGFUN_KERNEL_API_C |
|
|
248 #define N_A_MSG "Kernel C API layer disabled" |
|
|
249 #endif // def CYGFUN_KERNEL_API_C |
|
|
250 #else // def CYGVAR_KERNEL_COUNTERS_CLOCK |
|
|
251 #define N_A_MSG "Kernel real-time clock disabled" |
|
|
252 #endif // def CYGVAR_KERNEL_COUNTERS_CLOCK |
|
|
253 |
|
|
254 #ifdef N_A_MSG |
|
|
255 externC void |
|
|
256 cyg_start( void ) |
|
|
257 { |
|
|
258 CYG_TEST_INIT(); |
|
2
|
259 CYG_TEST_NA( N_A_MSG ); |
|
0
|
260 } |
|
|
261 #endif // N_A_MSG |
|
|
262 |
|
|
263 // EOF kclock0.c |