Mercurial > ecos
annotate packages/kernel/current/tests/clock0.cxx @ 3292:7f8e529b4d82 default tip
Fix FREESCALE_EDMA_NBYTES_MLOFFYES_MLOFF() so it works with negative offsets.
| author | vae |
|---|---|
| date | Wed, 29 Apr 2015 23:31:48 +0000 |
| parents | 74dbf4c3f2e1 |
| children |
| rev | line source |
|---|---|
| 0 | 1 //========================================================================== |
| 2 // | |
| 3 // clock0.cxx | |
| 4 // | |
| 5 // 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:
130
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:
130
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:
130
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:
130
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:
130
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-02-13 | |
| 45 // Description: Tests some basic clock functions. | |
| 46 // Omissions: Doesn't test likely boundary conditions for | |
| 47 // CYGNUM_KERNEL_COUNTERS_MULTI_LIST_SIZE | |
| 48 // Real Time Clock Testing is limited | |
| 49 // Options: | |
| 50 // CYGIMP_KERNEL_COUNTERS_SINGLE_LIST | |
| 51 // CYGIMP_KERNEL_COUNTERS_MULTI_LIST | |
| 52 // CYGVAR_KERNEL_COUNTERS_CLOCK | |
| 53 // CYGNUM_KERNEL_COUNTERS_MULTI_LIST_SIZE | |
| 54 // Assumptions: This assumes we have long long support and | |
| 55 // that counters are 64 bits. | |
| 56 //####DESCRIPTIONEND#### | |
| 57 | |
| 58 #include <pkgconf/kernel.h> | |
| 59 | |
| 60 #include <cyg/kernel/clock.hxx> | |
| 61 | |
| 62 #include <cyg/infra/testcase.h> | |
| 63 | |
| 64 #include <cyg/kernel/clock.inl> | |
| 65 | |
| 66 #include "testaux.hxx" | |
| 67 | |
| 68 #ifdef CYGVAR_KERNEL_COUNTERS_CLOCK | |
| 69 | |
| 70 cyg_alarm_fn call_me; | |
| 71 | |
| 72 bool flash( void ) | |
| 73 { | |
| 74 Cyg_Counter counter0 = Cyg_Counter(); | |
| 75 Cyg_Counter counter1 = Cyg_Counter(723); | |
| 76 | |
| 77 CYG_ASSERTCLASSO( counter0, "error" ); | |
| 78 CYG_ASSERTCLASSO( counter1, "error" ); | |
| 79 | |
| 80 Cyg_Alarm alarm0 = Cyg_Alarm(&counter0, call_me, 12); | |
| 81 | |
| 82 CYG_ASSERTCLASSO( alarm0, "error" ); | |
| 83 | |
| 84 Cyg_Clock::cyg_resolution res = {1,2}; | |
| 85 | |
| 86 Cyg_Clock clock0(res); | |
| 87 | |
| 88 CYG_ASSERTCLASSO( clock0, "error" ); | |
| 89 | |
| 90 return true; | |
| 91 } | |
| 92 | |
| 93 // Testing alarms | |
| 94 // | |
| 95 // call_me is a function that will be called when an alarm is | |
| 96 // triggered. It updates a global variable called which is CHECKed | |
| 97 // explicitly to see if the approriate alarms have been called. | |
| 98 | |
| 99 cyg_uint16 called = 0x0; | |
| 100 | |
| 101 void call_me(Cyg_Alarm *alarm, CYG_ADDRWORD data) | |
| 102 { | |
| 103 called ^= data; | |
| 104 } | |
| 105 | |
| 106 void call_me2(Cyg_Alarm *alarm, CYG_ADDRWORD data) | |
| 107 { | |
| 108 call_me(alarm, data^0x10); | |
| 109 } | |
| 110 | |
| 111 | |
| 112 void clock0_main(void) | |
| 113 { | |
| 114 CYG_TEST_INIT(); | |
| 115 | |
| 116 CHECK(flash()); | |
| 117 CHECK(flash()); | |
| 118 | |
| 119 const cyg_uint32 big_number = 3333222111u; | |
| 120 Cyg_Counter counter0 = Cyg_Counter(); | |
| 121 | |
| 122 CHECK( 0 == counter0.current_value() ); | |
| 123 CHECK( 0 == counter0.current_value_lo() ); | |
| 124 CHECK( 0 == counter0.current_value_hi() ); | |
| 125 | |
| 126 counter0.tick(); | |
| 127 | |
| 128 CHECK( 1 == counter0.current_value() ); | |
| 129 CHECK( 1 == counter0.current_value_lo() ); | |
| 130 CHECK( 0 == counter0.current_value_hi() ); | |
| 131 | |
| 132 counter0.tick(6); | |
| 133 | |
| 134 CHECK( 7 == counter0.current_value() ); | |
| 135 CHECK( 7 == counter0.current_value_lo() ); | |
| 136 CHECK( 0 == counter0.current_value_hi() ); | |
| 137 | |
| 138 counter0.set_value( 0xfffffffc ); | |
| 139 | |
| 140 CHECK( 0xfffffffc == counter0.current_value() ); | |
| 141 CHECK( 0xfffffffc == counter0.current_value_lo() ); | |
| 142 CHECK( 0 == counter0.current_value_hi() ); | |
| 143 | |
| 2 | 144 counter0.tick( 0x13 ); // Overflows 32 bits |
| 0 | 145 |
| 146 CHECK( 0x10000000fULL == counter0.current_value() ); | |
| 147 CHECK( 0xf == counter0.current_value_lo() ); | |
| 148 CHECK( 0x1 == counter0.current_value_hi() ); | |
| 149 | |
| 150 | |
| 151 Cyg_Counter counter1 = Cyg_Counter(big_number); | |
| 152 | |
| 153 CHECK( 0 == counter1.current_value() ); | |
| 154 CHECK( 0 == counter1.current_value_lo() ); | |
| 155 CHECK( 0 == counter1.current_value_hi() ); | |
| 156 | |
| 157 counter1.tick(2); | |
| 158 | |
| 159 CHECK( 2ll*big_number == counter1.current_value() ); | |
| 160 CHECK( ((2ll*big_number) & 0xffffffff) == | |
| 161 counter1.current_value_lo() ); | |
| 162 CHECK( ((2ll*big_number) >> 32) == counter1.current_value_hi() ); | |
| 163 | |
| 164 counter1.tick(); | |
| 165 | |
| 166 CHECK( 3ll*big_number == counter1.current_value() ); | |
| 167 CHECK( ((3ll*big_number) & 0xffffffff) == | |
| 168 counter1.current_value_lo() ); | |
| 169 CHECK( ((3ll*big_number) >> 32) == counter1.current_value_hi() ); | |
| 170 | |
| 171 counter1.tick(); | |
| 172 | |
| 173 CHECK( 4ll*big_number == counter1.current_value() ); | |
| 174 CHECK( ((4ll*big_number) & 0xffffffff) == | |
| 175 counter1.current_value_lo() ); | |
| 176 CHECK( ((4ll*big_number) >> 32) == counter1.current_value_hi() ); | |
| 177 | |
| 178 counter1.set_value(1222333444555ll); | |
| 179 CHECK( 1222333444555ll == counter1.current_value() ); | |
| 180 | |
| 181 counter0.set_value(11); | |
| 182 CHECK( 11 == counter0.current_value() ); | |
| 183 | |
| 184 // the call_me functions cause the "called" bits to toggle | |
| 185 // CHECKing the value of called TEST_CHECKs the parity of # of calls | |
| 186 // made by each alarm. | |
| 187 | |
| 188 Cyg_Alarm alarm0 = Cyg_Alarm(&counter0, call_me, 0x1); | |
| 189 Cyg_Alarm alarm1 = Cyg_Alarm(&counter0, call_me, 0x2); | |
| 190 Cyg_Alarm alarm2 = Cyg_Alarm(&counter0, call_me2, 0x4); | |
| 191 | |
| 192 CHECK( 0x00 == called ); | |
| 193 alarm0.initialize(12,3); | |
| 194 alarm2.initialize(21,2); | |
| 195 CHECK( 0x00 == called ); | |
| 196 | |
| 2 | 197 counter0.tick(); // 12 a0 |
| 0 | 198 CHECK( 0x01 == called ); |
| 199 | |
| 200 alarm1.initialize(13,0); | |
| 2 | 201 counter0.tick(); // 13 a1 |
| 0 | 202 CHECK( 0x03 == called ); |
| 203 | |
| 204 alarm1.initialize(17,0); | |
| 2 | 205 counter0.tick(); // 14 |
| 0 | 206 CHECK( 0x03 == called ); |
| 207 | |
| 2 | 208 counter0.tick(); // 15 a0 |
| 0 | 209 CHECK( 0x02 == called ); |
| 210 | |
| 2 | 211 counter0.tick(2); // 17 a1 |
| 0 | 212 CHECK( 0x00 == called ); |
| 213 | |
| 2 | 214 counter0.tick(); // 18 a0 |
| 0 | 215 CHECK( 0x01 == called ); |
| 216 | |
| 2 | 217 counter0.tick(3); // 21 a0 a2 |
| 0 | 218 CHECK( 0x14 == called ); |
| 219 | |
| 2 | 220 counter0.tick(2); // 23 a2 |
| 0 | 221 CHECK( 0x00 == called ); |
| 222 | |
| 223 alarm2.disable(); | |
| 224 | |
| 2 | 225 counter0.tick(2); // 25 a0(24) |
| 0 | 226 CHECK( 0x01 == called ); |
| 227 | |
| 228 alarm2.enable(); // a2 (enabled at 25) | |
| 229 CHECK( 0x15 == called ); | |
| 230 | |
| 2 | 231 counter0.tick(); // 26 |
| 0 | 232 CHECK( 0x15 == called ); |
| 233 | |
| 2 | 234 counter0.tick(2); // 28 a0(27) a2(27) |
| 0 | 235 CHECK( 0x00 == called ); |
| 236 | |
| 2 | 237 counter0.tick(3); // 31 a0(30) a2(29 31) |
| 0 | 238 CHECK( 0x01 == called ); |
| 239 | |
| 240 Cyg_Clock::cyg_resolution res0; | |
| 241 | |
| 242 res0.dividend = 100; | |
| 243 res0.divisor = 3; | |
| 244 | |
| 245 Cyg_Clock::cyg_resolution res1; | |
| 246 | |
| 247 Cyg_Clock clock0 = Cyg_Clock(res0); | |
| 248 | |
| 249 res1 = clock0.get_resolution(); | |
| 250 CHECK( res0.dividend == res1.dividend ); | |
| 251 CHECK( res0.divisor == res1.divisor ); | |
| 252 | |
| 253 res1.dividend = 12; | |
| 254 res1.divisor = 25; | |
| 255 | |
| 256 clock0.set_resolution(res1); | |
| 257 res0 = clock0.get_resolution(); | |
| 258 CHECK( res0.dividend == res1.dividend ); | |
| 259 CHECK( res0.divisor == res1.divisor ); | |
| 260 | |
| 261 res0 = Cyg_Clock::real_time_clock->get_resolution(); | |
| 262 | |
| 263 CYG_TEST_PASS_FINISH("Clock 0 OK"); | |
| 264 } | |
| 265 | |
| 266 externC void | |
| 267 cyg_start( void ) | |
| 268 { | |
|
130
eb9fd8c04db3
Merge from eCos master repository on 2000-10-23-17:01:37-BST
jlarmour
parents:
66
diff
changeset
|
269 #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
|
270 cyg_hal_invoke_constructors(); |
|
eb9fd8c04db3
Merge from eCos master repository on 2000-10-23-17:01:37-BST
jlarmour
parents:
66
diff
changeset
|
271 #endif |
| 0 | 272 clock0_main(); |
| 273 } | |
| 274 | |
| 275 #else // def CYGVAR_KERNEL_COUNTERS_CLOCK | |
| 276 | |
| 277 externC void | |
| 278 cyg_start( void ) | |
| 279 { | |
| 280 CYG_TEST_INIT(); | |
| 2 | 281 CYG_TEST_NA( "Kernel real-time clock disabled"); |
| 0 | 282 } |
| 283 | |
| 284 #endif // def CYGVAR_KERNEL_COUNTERS_CLOCK | |
| 285 // EOF clock0.cxx |
