Mercurial > ecos
annotate packages/kernel/current/tests/kclock0.c @ 3132:80f232caf539
* tests/except1.cxx (cause_exception): Fix compiler warning about
variable that is set but not used. Enter CYGBLD_ATTRIB_UNUSED.
* tests/kexcept1.c (cause_exception): Ditto.
* tests/kmbox1.c (entry1): Fix compiler warning about variable that
is set but not used. Use by a conditional CYGMTH_MBOX_PUT_CAN_WAIT.
* tests/mbox1.cxx (entry1): Ditto.
* tests/tm_basic.cxx (run_thread_tests, run_mbox_tests,
run_flag_tests): Remove unused variables.
| author | sergeig |
|---|---|
| date | Tue, 20 Mar 2012 15:39:58 +0000 |
| parents | 74dbf4c3f2e1 |
| children |
| rev | line source |
|---|---|
| 0 | 1 /*================================================================= |
| 2 // | |
| 3 // kclock0.c | |
| 4 // | |
| 5 // Kernel C API Clock test 0 | |
| 6 // | |
| 7 //========================================================================== | |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
8 // ####ECOSGPLCOPYRIGHTBEGIN#### |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
9 // ------------------------------------------- |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
10 // This file is part of eCos, the Embedded Configurable Operating System. |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
12 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
13 // eCos is free software; you can redistribute it and/or modify it under |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
14 // the terms of the GNU General Public License as published by the Free |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
15 // Software Foundation; either version 2 or (at your option) any later |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
16 // version. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
17 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
18 // eCos is distributed in the hope that it will be useful, but WITHOUT |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
19 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
20 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
21 // for more details. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
22 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
23 // You should have received a copy of the GNU General Public License |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
24 // along with eCos; if not, write to the Free Software Foundation, Inc., |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
25 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
26 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
27 // As a special exception, if other files instantiate templates or use |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
28 // macros or inline functions from this file, or you compile this file |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
29 // and link it with other works to produce a work based on this file, |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
30 // this file does not by itself cause the resulting work to be covered by |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
31 // the GNU General Public License. However the source code for this file |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
32 // must still be made available in accordance with section (3) of the GNU |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
33 // General Public License v2. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
34 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
35 // This exception does not invalidate any other reasons why a work based |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
36 // on this file might be covered by the GNU General Public License. |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
37 // ------------------------------------------- |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
38 // ####ECOSGPLCOPYRIGHTEND#### |
| 0 | 39 //========================================================================== |
| 40 //#####DESCRIPTIONBEGIN#### | |
| 41 // | |
| 42 // Author(s): dsm | |
| 43 // Contributors: dsm | |
| 44 // Date: 1998-03-20 | |
| 45 // Description: Tests some basic clock functions. | |
| 46 //####DESCRIPTIONEND#### | |
| 47 */ | |
| 48 | |
| 49 #include <cyg/kernel/kapi.h> | |
| 50 | |
| 51 #include <cyg/infra/testcase.h> | |
| 52 | |
| 53 #ifdef CYGVAR_KERNEL_COUNTERS_CLOCK | |
| 54 | |
| 55 #ifdef CYGFUN_KERNEL_API_C | |
| 56 | |
| 57 #include "testaux.h" | |
| 58 | |
| 59 cyg_alarm_t call_me; | |
| 60 | |
| 61 cyg_counter counter0o, counter1o; | |
| 62 cyg_handle_t counter0, counter1; | |
| 63 | |
| 64 cyg_alarm alarmo[3]; | |
| 65 cyg_handle_t alarm0, alarm1, alarm2; | |
| 66 | |
| 67 cyg_resolution_t res, res0, res1; | |
| 68 | |
| 69 cyg_clock clock0o; | |
| 70 cyg_handle_t clock0; | |
| 71 | |
| 72 const cyg_uint32 big_number = 3333222111u; | |
| 73 | |
| 74 cyg_bool_t flash( void ) | |
| 75 { | |
| 76 cyg_counter_create( &counter0, &counter0o ); | |
| 77 cyg_counter_create( &counter1, &counter1o ); | |
| 78 | |
| 79 cyg_alarm_create( counter0, | |
| 80 call_me, | |
| 81 (cyg_addrword_t)12, | |
| 82 &alarm0, | |
| 83 &alarmo[0]); | |
| 84 | |
| 85 res.dividend = 1; | |
| 86 res.divisor = 2; | |
| 87 | |
| 88 cyg_clock_create( res, &clock0, &clock0o ); | |
| 89 cyg_clock_delete( clock0 ); | |
| 90 | |
| 91 cyg_alarm_delete( alarm0 ); | |
| 92 | |
| 93 cyg_counter_delete( counter0 ); | |
| 94 cyg_counter_delete( counter1 ); | |
| 95 | |
| 96 return true; | |
| 97 } | |
| 98 | |
| 99 /* Testing alarms | |
| 100 // | |
| 101 // call_me is a function that will be called when an alarm is | |
| 102 // triggered. It updates a global variable called which is CHECKed | |
| 103 // explicitly to see if the approriate alarms have been called. | |
| 104 */ | |
| 105 | |
| 106 cyg_uint16 called = 0x0; | |
| 107 | |
| 108 void call_me(cyg_handle_t alarm, cyg_addrword_t data) | |
| 109 { | |
| 110 called ^= (int)data; | |
| 111 } | |
| 112 | |
| 113 void call_me2(cyg_handle_t alarm, cyg_addrword_t data) | |
| 114 { | |
| 115 call_me(alarm, (cyg_addrword_t)((int)data^0x10)); | |
| 116 } | |
| 117 | |
| 118 | |
| 119 void kclock0_main(void) | |
| 120 { | |
| 121 CYG_TEST_INIT(); | |
| 122 | |
| 123 CHECK(flash()); | |
| 124 CHECK(flash()); | |
| 125 | |
| 126 cyg_counter_create( &counter0, &counter0o); | |
| 127 | |
| 128 CHECK( 0 == cyg_counter_current_value( counter0 ) ); | |
| 129 | |
| 130 cyg_counter_tick(counter0); | |
| 131 | |
| 132 CHECK( 1 == cyg_counter_current_value(counter0) ); | |
| 133 | |
| 134 cyg_counter_tick(counter0); | |
| 135 | |
| 136 CHECK( 2 == cyg_counter_current_value(counter0) ); | |
| 137 | |
| 138 cyg_counter_set_value( counter0, 0xffffffff ); | |
| 139 | |
| 140 CHECK( 0xffffffff == cyg_counter_current_value(counter0) ); | |
| 141 | |
| 2 | 142 cyg_counter_tick(counter0); // Overflows 32 bits |
| 0 | 143 |
| 144 CHECK( 0x100000000ULL == cyg_counter_current_value(counter0) ); | |
| 145 | |
| 146 cyg_counter_set_value(counter0, 11); | |
| 147 CHECK( 11 == cyg_counter_current_value(counter0) ); | |
| 148 | |
| 149 /* the call_me functions cause the "called" bits to toggle | |
| 150 // checking the value of called checks the parity of # of calls | |
| 151 // made by each alarm. | |
| 152 */ | |
| 153 | |
| 154 cyg_alarm_create(counter0, | |
| 155 call_me, (cyg_addrword_t)0x1, &alarm0, &alarmo[0]); | |
| 156 cyg_alarm_create(counter0, | |
| 157 call_me, (cyg_addrword_t)0x2, &alarm1, &alarmo[1]); | |
| 158 cyg_alarm_create(counter0, | |
| 159 call_me2, (cyg_addrword_t)0x4, &alarm2, &alarmo[2]); | |
| 160 | |
| 161 CHECK( 0x00 == called ); | |
| 162 cyg_alarm_initialize(alarm0, 12,3); | |
| 163 cyg_alarm_initialize(alarm2, 21,2); | |
| 164 CHECK( 0x00 == called ); | |
| 165 | |
| 2 | 166 cyg_counter_tick(counter0); /* 12 a0 */ |
| 0 | 167 CHECK( 0x01 == called ); |
| 168 | |
| 169 cyg_alarm_initialize(alarm1, 13,0); | |
| 2 | 170 cyg_counter_tick(counter0); /* 13 a1 */ |
| 0 | 171 CHECK( 0x03 == called ); |
| 172 | |
| 173 cyg_alarm_initialize(alarm1, 17,0); | |
| 2 | 174 cyg_counter_tick(counter0); /* 14 */ |
| 0 | 175 CHECK( 0x03 == called ); |
| 176 | |
| 2 | 177 cyg_counter_tick(counter0); /* 15 a0 */ |
| 0 | 178 CHECK( 0x02 == called ); |
| 179 | |
| 2 | 180 cyg_counter_tick(counter0); /* 16 */ |
| 181 cyg_counter_tick(counter0); /* 17 a1 */ | |
| 0 | 182 CHECK( 0x00 == called ); |
| 183 | |
| 2 | 184 cyg_counter_tick(counter0); /* 18 a0 */ |
| 0 | 185 CHECK( 0x01 == called ); |
| 186 | |
| 2 | 187 cyg_counter_tick(counter0); /* 19 */ |
| 188 cyg_counter_tick(counter0); /* 20 */ | |
| 189 cyg_counter_tick(counter0); /* 21 a0 a2 */ | |
| 0 | 190 CHECK( 0x14 == called ); |
| 191 | |
| 2 | 192 cyg_counter_tick(counter0); /* 22 */ |
| 193 cyg_counter_tick(counter0); /* 23 a2 */ | |
| 0 | 194 CHECK( 0x00 == called ); |
| 195 | |
| 196 cyg_alarm_disable(alarm2); | |
| 197 | |
| 2 | 198 cyg_counter_tick(counter0); /* 24 a0 */ |
| 199 cyg_counter_tick(counter0); /* 25 */ | |
| 0 | 200 CHECK( 0x01 == called ); |
| 201 | |
| 202 cyg_alarm_enable(alarm2); /* a2 (enabled at 25) */ | |
| 203 CHECK( 0x15 == called ); | |
| 204 | |
| 2 | 205 cyg_counter_tick(counter0); /* 26 */ |
| 0 | 206 CHECK( 0x15 == called ); |
| 207 | |
| 2 | 208 cyg_counter_tick(counter0); /* 27 a0 a2 */ |
| 209 cyg_counter_tick(counter0); /* 28 */ | |
| 0 | 210 CHECK( 0x00 == called ); |
| 211 | |
| 2 | 212 cyg_counter_tick(counter0); /* 29 a2 */ |
| 213 cyg_counter_tick(counter0); /* 30 a0 */ | |
| 214 cyg_counter_tick(counter0); /* 31 a2 */ | |
| 0 | 215 CHECK( 0x01 == called ); |
| 216 | |
| 217 res0.dividend = 100; | |
| 218 res0.divisor = 3; | |
| 219 | |
| 220 cyg_clock_create( res0, &clock0, &clock0o ); | |
| 221 | |
| 222 res1 = cyg_clock_get_resolution(clock0); | |
| 223 CHECK( res0.dividend == res1.dividend ); | |
| 224 CHECK( res0.divisor == res1.divisor ); | |
| 225 | |
| 226 res1.dividend = 12; | |
| 227 res1.divisor = 25; | |
| 228 | |
| 229 cyg_clock_set_resolution(clock0, res1); | |
| 230 res0 = cyg_clock_get_resolution(clock0); | |
| 231 CHECK( res0.dividend == res1.dividend ); | |
| 232 CHECK( res0.divisor == res1.divisor ); | |
| 233 | |
| 234 cyg_clock_to_counter(clock0, &counter1); | |
| 235 | |
| 236 CHECK( 0 == cyg_counter_current_value( counter1 ) ); | |
| 237 CHECK( 0 == cyg_current_time() ); | |
| 238 | |
| 239 cyg_counter_tick(counter1); | |
| 240 | |
| 241 CHECK( 1 == cyg_counter_current_value(counter1) ); | |
| 242 | |
| 243 res0 = cyg_clock_get_resolution(cyg_real_time_clock()); | |
| 244 | |
| 245 /* Current time should be 0 as interrupts will still be disabled */ | |
| 246 CHECK( 0 == cyg_current_time() ); | |
| 247 | |
| 248 CYG_TEST_PASS_FINISH("Kernel C API Clock 0 OK"); | |
| 249 } | |
| 250 | |
| 251 externC void | |
| 252 cyg_start( void ) | |
| 253 { | |
| 254 kclock0_main(); | |
| 255 } | |
| 256 | |
| 257 #else // def CYGFUN_KERNEL_API_C | |
| 258 #define N_A_MSG "Kernel C API layer disabled" | |
| 259 #endif // def CYGFUN_KERNEL_API_C | |
| 260 #else // def CYGVAR_KERNEL_COUNTERS_CLOCK | |
| 261 #define N_A_MSG "Kernel real-time clock disabled" | |
| 262 #endif // def CYGVAR_KERNEL_COUNTERS_CLOCK | |
| 263 | |
| 264 #ifdef N_A_MSG | |
| 265 externC void | |
| 266 cyg_start( void ) | |
| 267 { | |
| 268 CYG_TEST_INIT(); | |
| 2 | 269 CYG_TEST_NA( N_A_MSG ); |
| 0 | 270 } |
| 271 #endif // N_A_MSG | |
| 272 | |
| 273 // EOF kclock0.c |
