Mercurial > flash_v2
annotate packages/kernel/current/tests/kclock0.c @ 66:bf00f99aec69 ecos-sw-2000-02-02
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
| author | jlarmour |
|---|---|
| date | Wed, 02 Feb 2000 19:57:02 +0000 |
| parents | c38311975d4f |
| children | e0c0827131d1 |
| rev | line source |
|---|---|
| 0 | 1 /*================================================================= |
| 2 // | |
| 3 // kclock0.c | |
| 4 // | |
| 5 // Kernel C API Clock test 0 | |
| 6 // | |
| 7 //========================================================================== | |
| 8 //####COPYRIGHTBEGIN#### | |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
9 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
10 // ------------------------------------------- |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
11 // The contents of this file are subject to the Red Hat eCos Public License |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
12 // Version 1.1 (the "License"); you may not use this file except in |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
13 // compliance with the License. You may obtain a copy of the License at |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
14 // http://www.redhat.com/ |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
15 // |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
16 // Software distributed under the License is distributed on an "AS IS" |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
18 // License for the specific language governing rights and limitations under |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
19 // the License. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
20 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
21 // The Original Code is eCos - Embedded Configurable Operating System, |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
22 // released September 30, 1998. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
23 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
24 // The Initial Developer of the Original Code is Red Hat. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
25 // Portions created by Red Hat are |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
26 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
27 // All Rights Reserved. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
28 // ------------------------------------------- |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
29 // |
| 0 | 30 //####COPYRIGHTEND#### |
| 31 //========================================================================== | |
| 32 //#####DESCRIPTIONBEGIN#### | |
| 33 // | |
| 34 // Author(s): dsm | |
| 35 // Contributors: dsm | |
| 36 // Date: 1998-03-20 | |
| 37 // Description: Tests some basic clock functions. | |
| 38 //####DESCRIPTIONEND#### | |
| 39 */ | |
| 40 | |
| 41 #include <cyg/kernel/kapi.h> | |
| 42 | |
| 43 #include <cyg/infra/testcase.h> | |
| 44 | |
| 45 #ifdef CYGVAR_KERNEL_COUNTERS_CLOCK | |
| 46 | |
| 47 #ifdef CYGFUN_KERNEL_API_C | |
| 48 | |
| 49 #include "testaux.h" | |
| 50 | |
| 51 cyg_alarm_t call_me; | |
| 52 | |
| 53 cyg_counter counter0o, counter1o; | |
| 54 cyg_handle_t counter0, counter1; | |
| 55 | |
| 56 cyg_alarm alarmo[3]; | |
| 57 cyg_handle_t alarm0, alarm1, alarm2; | |
| 58 | |
| 59 cyg_resolution_t res, res0, res1; | |
| 60 | |
| 61 cyg_clock clock0o; | |
| 62 cyg_handle_t clock0; | |
| 63 | |
| 64 const cyg_uint32 big_number = 3333222111u; | |
| 65 | |
| 66 cyg_bool_t flash( void ) | |
| 67 { | |
| 68 cyg_counter_create( &counter0, &counter0o ); | |
| 69 cyg_counter_create( &counter1, &counter1o ); | |
| 70 | |
| 71 cyg_alarm_create( counter0, | |
| 72 call_me, | |
| 73 (cyg_addrword_t)12, | |
| 74 &alarm0, | |
| 75 &alarmo[0]); | |
| 76 | |
| 77 res.dividend = 1; | |
| 78 res.divisor = 2; | |
| 79 | |
| 80 cyg_clock_create( res, &clock0, &clock0o ); | |
| 81 cyg_clock_delete( clock0 ); | |
| 82 | |
| 83 cyg_alarm_delete( alarm0 ); | |
| 84 | |
| 85 cyg_counter_delete( counter0 ); | |
| 86 cyg_counter_delete( counter1 ); | |
| 87 | |
| 88 return true; | |
| 89 } | |
| 90 | |
| 91 /* Testing alarms | |
| 92 // | |
| 93 // call_me is a function that will be called when an alarm is | |
| 94 // triggered. It updates a global variable called which is CHECKed | |
| 95 // explicitly to see if the approriate alarms have been called. | |
| 96 */ | |
| 97 | |
| 98 cyg_uint16 called = 0x0; | |
| 99 | |
| 100 void call_me(cyg_handle_t alarm, cyg_addrword_t data) | |
| 101 { | |
| 102 called ^= (int)data; | |
| 103 } | |
| 104 | |
| 105 void call_me2(cyg_handle_t alarm, cyg_addrword_t data) | |
| 106 { | |
| 107 call_me(alarm, (cyg_addrword_t)((int)data^0x10)); | |
| 108 } | |
| 109 | |
| 110 | |
| 111 void kclock0_main(void) | |
| 112 { | |
| 113 CYG_TEST_INIT(); | |
| 114 | |
| 115 CHECK(flash()); | |
| 116 CHECK(flash()); | |
| 117 | |
| 118 cyg_counter_create( &counter0, &counter0o); | |
| 119 | |
| 120 CHECK( 0 == cyg_counter_current_value( counter0 ) ); | |
| 121 | |
| 122 cyg_counter_tick(counter0); | |
| 123 | |
| 124 CHECK( 1 == cyg_counter_current_value(counter0) ); | |
| 125 | |
| 126 cyg_counter_tick(counter0); | |
| 127 | |
| 128 CHECK( 2 == cyg_counter_current_value(counter0) ); | |
| 129 | |
| 130 cyg_counter_set_value( counter0, 0xffffffff ); | |
| 131 | |
| 132 CHECK( 0xffffffff == cyg_counter_current_value(counter0) ); | |
| 133 | |
| 2 | 134 cyg_counter_tick(counter0); // Overflows 32 bits |
| 0 | 135 |
| 136 CHECK( 0x100000000ULL == cyg_counter_current_value(counter0) ); | |
| 137 | |
| 138 cyg_counter_set_value(counter0, 11); | |
| 139 CHECK( 11 == cyg_counter_current_value(counter0) ); | |
| 140 | |
| 141 /* the call_me functions cause the "called" bits to toggle | |
| 142 // checking the value of called checks the parity of # of calls | |
| 143 // made by each alarm. | |
| 144 */ | |
| 145 | |
| 146 cyg_alarm_create(counter0, | |
| 147 call_me, (cyg_addrword_t)0x1, &alarm0, &alarmo[0]); | |
| 148 cyg_alarm_create(counter0, | |
| 149 call_me, (cyg_addrword_t)0x2, &alarm1, &alarmo[1]); | |
| 150 cyg_alarm_create(counter0, | |
| 151 call_me2, (cyg_addrword_t)0x4, &alarm2, &alarmo[2]); | |
| 152 | |
| 153 CHECK( 0x00 == called ); | |
| 154 cyg_alarm_initialize(alarm0, 12,3); | |
| 155 cyg_alarm_initialize(alarm2, 21,2); | |
| 156 CHECK( 0x00 == called ); | |
| 157 | |
| 2 | 158 cyg_counter_tick(counter0); /* 12 a0 */ |
| 0 | 159 CHECK( 0x01 == called ); |
| 160 | |
| 161 cyg_alarm_initialize(alarm1, 13,0); | |
| 2 | 162 cyg_counter_tick(counter0); /* 13 a1 */ |
| 0 | 163 CHECK( 0x03 == called ); |
| 164 | |
| 165 cyg_alarm_initialize(alarm1, 17,0); | |
| 2 | 166 cyg_counter_tick(counter0); /* 14 */ |
| 0 | 167 CHECK( 0x03 == called ); |
| 168 | |
| 2 | 169 cyg_counter_tick(counter0); /* 15 a0 */ |
| 0 | 170 CHECK( 0x02 == called ); |
| 171 | |
| 2 | 172 cyg_counter_tick(counter0); /* 16 */ |
| 173 cyg_counter_tick(counter0); /* 17 a1 */ | |
| 0 | 174 CHECK( 0x00 == called ); |
| 175 | |
| 2 | 176 cyg_counter_tick(counter0); /* 18 a0 */ |
| 0 | 177 CHECK( 0x01 == called ); |
| 178 | |
| 2 | 179 cyg_counter_tick(counter0); /* 19 */ |
| 180 cyg_counter_tick(counter0); /* 20 */ | |
| 181 cyg_counter_tick(counter0); /* 21 a0 a2 */ | |
| 0 | 182 CHECK( 0x14 == called ); |
| 183 | |
| 2 | 184 cyg_counter_tick(counter0); /* 22 */ |
| 185 cyg_counter_tick(counter0); /* 23 a2 */ | |
| 0 | 186 CHECK( 0x00 == called ); |
| 187 | |
| 188 cyg_alarm_disable(alarm2); | |
| 189 | |
| 2 | 190 cyg_counter_tick(counter0); /* 24 a0 */ |
| 191 cyg_counter_tick(counter0); /* 25 */ | |
| 0 | 192 CHECK( 0x01 == called ); |
| 193 | |
| 194 cyg_alarm_enable(alarm2); /* a2 (enabled at 25) */ | |
| 195 CHECK( 0x15 == called ); | |
| 196 | |
| 2 | 197 cyg_counter_tick(counter0); /* 26 */ |
| 0 | 198 CHECK( 0x15 == called ); |
| 199 | |
| 2 | 200 cyg_counter_tick(counter0); /* 27 a0 a2 */ |
| 201 cyg_counter_tick(counter0); /* 28 */ | |
| 0 | 202 CHECK( 0x00 == called ); |
| 203 | |
| 2 | 204 cyg_counter_tick(counter0); /* 29 a2 */ |
| 205 cyg_counter_tick(counter0); /* 30 a0 */ | |
| 206 cyg_counter_tick(counter0); /* 31 a2 */ | |
| 0 | 207 CHECK( 0x01 == called ); |
| 208 | |
| 209 res0.dividend = 100; | |
| 210 res0.divisor = 3; | |
| 211 | |
| 212 cyg_clock_create( res0, &clock0, &clock0o ); | |
| 213 | |
| 214 res1 = cyg_clock_get_resolution(clock0); | |
| 215 CHECK( res0.dividend == res1.dividend ); | |
| 216 CHECK( res0.divisor == res1.divisor ); | |
| 217 | |
| 218 res1.dividend = 12; | |
| 219 res1.divisor = 25; | |
| 220 | |
| 221 cyg_clock_set_resolution(clock0, res1); | |
| 222 res0 = cyg_clock_get_resolution(clock0); | |
| 223 CHECK( res0.dividend == res1.dividend ); | |
| 224 CHECK( res0.divisor == res1.divisor ); | |
| 225 | |
| 226 cyg_clock_to_counter(clock0, &counter1); | |
| 227 | |
| 228 CHECK( 0 == cyg_counter_current_value( counter1 ) ); | |
| 229 CHECK( 0 == cyg_current_time() ); | |
| 230 | |
| 231 cyg_counter_tick(counter1); | |
| 232 | |
| 233 CHECK( 1 == cyg_counter_current_value(counter1) ); | |
| 234 | |
| 235 res0 = cyg_clock_get_resolution(cyg_real_time_clock()); | |
| 236 | |
| 237 /* Current time should be 0 as interrupts will still be disabled */ | |
| 238 CHECK( 0 == cyg_current_time() ); | |
| 239 | |
| 240 CYG_TEST_PASS_FINISH("Kernel C API Clock 0 OK"); | |
| 241 } | |
| 242 | |
| 243 externC void | |
| 244 cyg_start( void ) | |
| 245 { | |
| 246 kclock0_main(); | |
| 247 } | |
| 248 | |
| 249 #else // def CYGFUN_KERNEL_API_C | |
| 250 #define N_A_MSG "Kernel C API layer disabled" | |
| 251 #endif // def CYGFUN_KERNEL_API_C | |
| 252 #else // def CYGVAR_KERNEL_COUNTERS_CLOCK | |
| 253 #define N_A_MSG "Kernel real-time clock disabled" | |
| 254 #endif // def CYGVAR_KERNEL_COUNTERS_CLOCK | |
| 255 | |
| 256 #ifdef N_A_MSG | |
| 257 externC void | |
| 258 cyg_start( void ) | |
| 259 { | |
| 260 CYG_TEST_INIT(); | |
| 2 | 261 CYG_TEST_NA( N_A_MSG ); |
| 0 | 262 } |
| 263 #endif // N_A_MSG | |
| 264 | |
| 265 // EOF kclock0.c |
