Mercurial > flash_v2
annotate packages/kernel/current/tests/clock0.cxx @ 208:e0c0827131d1 ecos
Merge from eCos master repository on 2002-05-20-20:11:54-BST
| author | jlarmour |
|---|---|
| date | Mon, 20 May 2002 22:19:26 +0000 |
| parents | eb9fd8c04db3 |
| children | d2c90368aeef |
| rev | line source |
|---|---|
| 0 | 1 //========================================================================== |
| 2 // | |
| 3 // clock0.cxx | |
| 4 // | |
| 5 // Clock test 0 | |
| 6 // | |
| 7 //========================================================================== | |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
130
diff
changeset
|
8 //####ECOSGPLCOPYRIGHTBEGIN#### |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
130
diff
changeset
|
9 // ------------------------------------------- |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
130
diff
changeset
|
10 // This file is part of eCos, the Embedded Configurable Operating System. |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
130
diff
changeset
|
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
130
diff
changeset
|
12 // |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
130
diff
changeset
|
13 // eCos is free software; you can redistribute it and/or modify it under |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
130
diff
changeset
|
14 // the terms of the GNU General Public License as published by the Free |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
130
diff
changeset
|
15 // Software Foundation; either version 2 or (at your option) any later version. |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
130
diff
changeset
|
16 // |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
130
diff
changeset
|
17 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
130
diff
changeset
|
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
130
diff
changeset
|
19 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
130
diff
changeset
|
20 // for more details. |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
130
diff
changeset
|
21 // |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
130
diff
changeset
|
22 // You should have received a copy of the GNU General Public License along |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
130
diff
changeset
|
23 // with eCos; if not, write to the Free Software Foundation, Inc., |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
130
diff
changeset
|
24 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
130
diff
changeset
|
25 // |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
130
diff
changeset
|
26 // As a special exception, if other files instantiate templates or use macros |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
130
diff
changeset
|
27 // or inline functions from this file, or you compile this file and link it |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
130
diff
changeset
|
28 // with other works to produce a work based on this file, this file does not |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
130
diff
changeset
|
29 // by itself cause the resulting work to be covered by the GNU General Public |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
130
diff
changeset
|
30 // License. However the source code for this file must still be made available |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
130
diff
changeset
|
31 // in accordance with section (3) of the GNU General Public License. |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
130
diff
changeset
|
32 // |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
130
diff
changeset
|
33 // This exception does not invalidate any other reasons why a work based on |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
130
diff
changeset
|
34 // this file might be covered by the GNU General Public License. |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
130
diff
changeset
|
35 // |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
130
diff
changeset
|
36 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
130
diff
changeset
|
37 // at http://sources.redhat.com/ecos/ecos-license |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
130
diff
changeset
|
38 // ------------------------------------------- |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
130
diff
changeset
|
39 //####ECOSGPLCOPYRIGHTEND#### |
| 0 | 40 //========================================================================== |
| 41 //#####DESCRIPTIONBEGIN#### | |
| 42 // | |
| 43 // Author(s): dsm | |
| 44 // Contributors: dsm | |
| 45 // Date: 1998-02-13 | |
| 46 // Description: Tests some basic clock functions. | |
| 47 // Omissions: Doesn't test likely boundary conditions for | |
| 48 // CYGNUM_KERNEL_COUNTERS_MULTI_LIST_SIZE | |
| 49 // Real Time Clock Testing is limited | |
| 50 // Options: | |
| 51 // CYGIMP_KERNEL_COUNTERS_SINGLE_LIST | |
| 52 // CYGIMP_KERNEL_COUNTERS_MULTI_LIST | |
| 53 // CYGVAR_KERNEL_COUNTERS_CLOCK | |
| 54 // CYGNUM_KERNEL_COUNTERS_MULTI_LIST_SIZE | |
| 55 // Assumptions: This assumes we have long long support and | |
| 56 // that counters are 64 bits. | |
| 57 //####DESCRIPTIONEND#### | |
| 58 | |
| 59 #include <pkgconf/kernel.h> | |
| 60 | |
| 61 #include <cyg/kernel/clock.hxx> | |
| 62 | |
| 63 #include <cyg/infra/testcase.h> | |
| 64 | |
| 65 #include <cyg/kernel/clock.inl> | |
| 66 | |
| 67 #include "testaux.hxx" | |
| 68 | |
| 69 #ifdef CYGVAR_KERNEL_COUNTERS_CLOCK | |
| 70 | |
| 71 cyg_alarm_fn call_me; | |
| 72 | |
| 73 bool flash( void ) | |
| 74 { | |
| 75 Cyg_Counter counter0 = Cyg_Counter(); | |
| 76 Cyg_Counter counter1 = Cyg_Counter(723); | |
| 77 | |
| 78 CYG_ASSERTCLASSO( counter0, "error" ); | |
| 79 CYG_ASSERTCLASSO( counter1, "error" ); | |
| 80 | |
| 81 Cyg_Alarm alarm0 = Cyg_Alarm(&counter0, call_me, 12); | |
| 82 | |
| 83 CYG_ASSERTCLASSO( alarm0, "error" ); | |
| 84 | |
| 85 Cyg_Clock::cyg_resolution res = {1,2}; | |
| 86 | |
| 87 Cyg_Clock clock0(res); | |
| 88 | |
| 89 CYG_ASSERTCLASSO( clock0, "error" ); | |
| 90 | |
| 91 return true; | |
| 92 } | |
| 93 | |
| 94 // Testing alarms | |
| 95 // | |
| 96 // call_me is a function that will be called when an alarm is | |
| 97 // triggered. It updates a global variable called which is CHECKed | |
| 98 // explicitly to see if the approriate alarms have been called. | |
| 99 | |
| 100 cyg_uint16 called = 0x0; | |
| 101 | |
| 102 void call_me(Cyg_Alarm *alarm, CYG_ADDRWORD data) | |
| 103 { | |
| 104 called ^= data; | |
| 105 } | |
| 106 | |
| 107 void call_me2(Cyg_Alarm *alarm, CYG_ADDRWORD data) | |
| 108 { | |
| 109 call_me(alarm, data^0x10); | |
| 110 } | |
| 111 | |
| 112 | |
| 113 void clock0_main(void) | |
| 114 { | |
| 115 CYG_TEST_INIT(); | |
| 116 | |
| 117 CHECK(flash()); | |
| 118 CHECK(flash()); | |
| 119 | |
| 120 const cyg_uint32 big_number = 3333222111u; | |
| 121 Cyg_Counter counter0 = Cyg_Counter(); | |
| 122 | |
| 123 CHECK( 0 == counter0.current_value() ); | |
| 124 CHECK( 0 == counter0.current_value_lo() ); | |
| 125 CHECK( 0 == counter0.current_value_hi() ); | |
| 126 | |
| 127 counter0.tick(); | |
| 128 | |
| 129 CHECK( 1 == counter0.current_value() ); | |
| 130 CHECK( 1 == counter0.current_value_lo() ); | |
| 131 CHECK( 0 == counter0.current_value_hi() ); | |
| 132 | |
| 133 counter0.tick(6); | |
| 134 | |
| 135 CHECK( 7 == counter0.current_value() ); | |
| 136 CHECK( 7 == counter0.current_value_lo() ); | |
| 137 CHECK( 0 == counter0.current_value_hi() ); | |
| 138 | |
| 139 counter0.set_value( 0xfffffffc ); | |
| 140 | |
| 141 CHECK( 0xfffffffc == counter0.current_value() ); | |
| 142 CHECK( 0xfffffffc == counter0.current_value_lo() ); | |
| 143 CHECK( 0 == counter0.current_value_hi() ); | |
| 144 | |
| 2 | 145 counter0.tick( 0x13 ); // Overflows 32 bits |
| 0 | 146 |
| 147 CHECK( 0x10000000fULL == counter0.current_value() ); | |
| 148 CHECK( 0xf == counter0.current_value_lo() ); | |
| 149 CHECK( 0x1 == counter0.current_value_hi() ); | |
| 150 | |
| 151 | |
| 152 Cyg_Counter counter1 = Cyg_Counter(big_number); | |
| 153 | |
| 154 CHECK( 0 == counter1.current_value() ); | |
| 155 CHECK( 0 == counter1.current_value_lo() ); | |
| 156 CHECK( 0 == counter1.current_value_hi() ); | |
| 157 | |
| 158 counter1.tick(2); | |
| 159 | |
| 160 CHECK( 2ll*big_number == counter1.current_value() ); | |
| 161 CHECK( ((2ll*big_number) & 0xffffffff) == | |
| 162 counter1.current_value_lo() ); | |
| 163 CHECK( ((2ll*big_number) >> 32) == counter1.current_value_hi() ); | |
| 164 | |
| 165 counter1.tick(); | |
| 166 | |
| 167 CHECK( 3ll*big_number == counter1.current_value() ); | |
| 168 CHECK( ((3ll*big_number) & 0xffffffff) == | |
| 169 counter1.current_value_lo() ); | |
| 170 CHECK( ((3ll*big_number) >> 32) == counter1.current_value_hi() ); | |
| 171 | |
| 172 counter1.tick(); | |
| 173 | |
| 174 CHECK( 4ll*big_number == counter1.current_value() ); | |
| 175 CHECK( ((4ll*big_number) & 0xffffffff) == | |
| 176 counter1.current_value_lo() ); | |
| 177 CHECK( ((4ll*big_number) >> 32) == counter1.current_value_hi() ); | |
| 178 | |
| 179 counter1.set_value(1222333444555ll); | |
| 180 CHECK( 1222333444555ll == counter1.current_value() ); | |
| 181 | |
| 182 counter0.set_value(11); | |
| 183 CHECK( 11 == counter0.current_value() ); | |
| 184 | |
| 185 // the call_me functions cause the "called" bits to toggle | |
| 186 // CHECKing the value of called TEST_CHECKs the parity of # of calls | |
| 187 // made by each alarm. | |
| 188 | |
| 189 Cyg_Alarm alarm0 = Cyg_Alarm(&counter0, call_me, 0x1); | |
| 190 Cyg_Alarm alarm1 = Cyg_Alarm(&counter0, call_me, 0x2); | |
| 191 Cyg_Alarm alarm2 = Cyg_Alarm(&counter0, call_me2, 0x4); | |
| 192 | |
| 193 CHECK( 0x00 == called ); | |
| 194 alarm0.initialize(12,3); | |
| 195 alarm2.initialize(21,2); | |
| 196 CHECK( 0x00 == called ); | |
| 197 | |
| 2 | 198 counter0.tick(); // 12 a0 |
| 0 | 199 CHECK( 0x01 == called ); |
| 200 | |
| 201 alarm1.initialize(13,0); | |
| 2 | 202 counter0.tick(); // 13 a1 |
| 0 | 203 CHECK( 0x03 == called ); |
| 204 | |
| 205 alarm1.initialize(17,0); | |
| 2 | 206 counter0.tick(); // 14 |
| 0 | 207 CHECK( 0x03 == called ); |
| 208 | |
| 2 | 209 counter0.tick(); // 15 a0 |
| 0 | 210 CHECK( 0x02 == called ); |
| 211 | |
| 2 | 212 counter0.tick(2); // 17 a1 |
| 0 | 213 CHECK( 0x00 == called ); |
| 214 | |
| 2 | 215 counter0.tick(); // 18 a0 |
| 0 | 216 CHECK( 0x01 == called ); |
| 217 | |
| 2 | 218 counter0.tick(3); // 21 a0 a2 |
| 0 | 219 CHECK( 0x14 == called ); |
| 220 | |
| 2 | 221 counter0.tick(2); // 23 a2 |
| 0 | 222 CHECK( 0x00 == called ); |
| 223 | |
| 224 alarm2.disable(); | |
| 225 | |
| 2 | 226 counter0.tick(2); // 25 a0(24) |
| 0 | 227 CHECK( 0x01 == called ); |
| 228 | |
| 229 alarm2.enable(); // a2 (enabled at 25) | |
| 230 CHECK( 0x15 == called ); | |
| 231 | |
| 2 | 232 counter0.tick(); // 26 |
| 0 | 233 CHECK( 0x15 == called ); |
| 234 | |
| 2 | 235 counter0.tick(2); // 28 a0(27) a2(27) |
| 0 | 236 CHECK( 0x00 == called ); |
| 237 | |
| 2 | 238 counter0.tick(3); // 31 a0(30) a2(29 31) |
| 0 | 239 CHECK( 0x01 == called ); |
| 240 | |
| 241 Cyg_Clock::cyg_resolution res0; | |
| 242 | |
| 243 res0.dividend = 100; | |
| 244 res0.divisor = 3; | |
| 245 | |
| 246 Cyg_Clock::cyg_resolution res1; | |
| 247 | |
| 248 Cyg_Clock clock0 = Cyg_Clock(res0); | |
| 249 | |
| 250 res1 = clock0.get_resolution(); | |
| 251 CHECK( res0.dividend == res1.dividend ); | |
| 252 CHECK( res0.divisor == res1.divisor ); | |
| 253 | |
| 254 res1.dividend = 12; | |
| 255 res1.divisor = 25; | |
| 256 | |
| 257 clock0.set_resolution(res1); | |
| 258 res0 = clock0.get_resolution(); | |
| 259 CHECK( res0.dividend == res1.dividend ); | |
| 260 CHECK( res0.divisor == res1.divisor ); | |
| 261 | |
| 262 res0 = Cyg_Clock::real_time_clock->get_resolution(); | |
| 263 | |
| 264 CYG_TEST_PASS_FINISH("Clock 0 OK"); | |
| 265 } | |
| 266 | |
| 267 externC void | |
| 268 cyg_start( void ) | |
| 269 { | |
|
130
eb9fd8c04db3
Merge from eCos master repository on 2000-10-23-17:01:37-BST
jlarmour
parents:
66
diff
changeset
|
270 #ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG |
|
eb9fd8c04db3
Merge from eCos master repository on 2000-10-23-17:01:37-BST
jlarmour
parents:
66
diff
changeset
|
271 cyg_hal_invoke_constructors(); |
|
eb9fd8c04db3
Merge from eCos master repository on 2000-10-23-17:01:37-BST
jlarmour
parents:
66
diff
changeset
|
272 #endif |
| 0 | 273 clock0_main(); |
| 274 } | |
| 275 | |
| 276 #else // def CYGVAR_KERNEL_COUNTERS_CLOCK | |
| 277 | |
| 278 externC void | |
| 279 cyg_start( void ) | |
| 280 { | |
| 281 CYG_TEST_INIT(); | |
| 2 | 282 CYG_TEST_NA( "Kernel real-time clock disabled"); |
| 0 | 283 } |
| 284 | |
| 285 #endif // def CYGVAR_KERNEL_COUNTERS_CLOCK | |
| 286 // EOF clock0.cxx |
