Mercurial > flash_v2
annotate packages/kernel/current/tests/kclock0.c @ 1717:faaea4243d52
* cdl/redboot.cdl: Fixed the type of CYGNUM_REDBOOT_FLASH_BASE
* src/flash.c (fis_[un]lock): Fix compiler warnings
* src/flash.c (do_flash_init): Removed the MIPS br0ken condition
which i wrongly added. My problem was actually a / 0. This roundup
is needed otherwise the workspace goes off the end of the RAM.
| author | asl |
|---|---|
| date | Mon, 16 Aug 2004 08:35:33 +0000 |
| parents | d2c90368aeef |
| children |
| rev | line source |
|---|---|
| 0 | 1 /*================================================================= |
| 2 // | |
| 3 // kclock0.c | |
| 4 // | |
| 5 // Kernel C API Clock test 0 | |
| 6 // | |
| 7 //========================================================================== | |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
8 //####ECOSGPLCOPYRIGHTBEGIN#### |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
9 // ------------------------------------------- |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
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:
66
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:
66
diff
changeset
|
12 // |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
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:
66
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:
66
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:
66
diff
changeset
|
16 // |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
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:
66
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:
66
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:
66
diff
changeset
|
20 // for more details. |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
21 // |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
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:
66
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:
66
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:
66
diff
changeset
|
25 // |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
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:
66
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:
66
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:
66
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:
66
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:
66
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:
66
diff
changeset
|
32 // |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
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:
66
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:
66
diff
changeset
|
35 // |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
36 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. |
|
210
d2c90368aeef
Merge from eCos master repository on 2002-05-23-21:39:14-BST
jlarmour
parents:
208
diff
changeset
|
37 // at http://sources.redhat.com/ecos/ecos-license/ |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
38 // ------------------------------------------- |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
39 //####ECOSGPLCOPYRIGHTEND#### |
| 0 | 40 //========================================================================== |
| 41 //#####DESCRIPTIONBEGIN#### | |
| 42 // | |
| 43 // Author(s): dsm | |
| 44 // Contributors: dsm | |
| 45 // Date: 1998-03-20 | |
| 46 // Description: Tests some basic clock functions. | |
| 47 //####DESCRIPTIONEND#### | |
| 48 */ | |
| 49 | |
| 50 #include <cyg/kernel/kapi.h> | |
| 51 | |
| 52 #include <cyg/infra/testcase.h> | |
| 53 | |
| 54 #ifdef CYGVAR_KERNEL_COUNTERS_CLOCK | |
| 55 | |
| 56 #ifdef CYGFUN_KERNEL_API_C | |
| 57 | |
| 58 #include "testaux.h" | |
| 59 | |
| 60 cyg_alarm_t call_me; | |
| 61 | |
| 62 cyg_counter counter0o, counter1o; | |
| 63 cyg_handle_t counter0, counter1; | |
| 64 | |
| 65 cyg_alarm alarmo[3]; | |
| 66 cyg_handle_t alarm0, alarm1, alarm2; | |
| 67 | |
| 68 cyg_resolution_t res, res0, res1; | |
| 69 | |
| 70 cyg_clock clock0o; | |
| 71 cyg_handle_t clock0; | |
| 72 | |
| 73 const cyg_uint32 big_number = 3333222111u; | |
| 74 | |
| 75 cyg_bool_t flash( void ) | |
| 76 { | |
| 77 cyg_counter_create( &counter0, &counter0o ); | |
| 78 cyg_counter_create( &counter1, &counter1o ); | |
| 79 | |
| 80 cyg_alarm_create( counter0, | |
| 81 call_me, | |
| 82 (cyg_addrword_t)12, | |
| 83 &alarm0, | |
| 84 &alarmo[0]); | |
| 85 | |
| 86 res.dividend = 1; | |
| 87 res.divisor = 2; | |
| 88 | |
| 89 cyg_clock_create( res, &clock0, &clock0o ); | |
| 90 cyg_clock_delete( clock0 ); | |
| 91 | |
| 92 cyg_alarm_delete( alarm0 ); | |
| 93 | |
| 94 cyg_counter_delete( counter0 ); | |
| 95 cyg_counter_delete( counter1 ); | |
| 96 | |
| 97 return true; | |
| 98 } | |
| 99 | |
| 100 /* Testing alarms | |
| 101 // | |
| 102 // call_me is a function that will be called when an alarm is | |
| 103 // triggered. It updates a global variable called which is CHECKed | |
| 104 // explicitly to see if the approriate alarms have been called. | |
| 105 */ | |
| 106 | |
| 107 cyg_uint16 called = 0x0; | |
| 108 | |
| 109 void call_me(cyg_handle_t alarm, cyg_addrword_t data) | |
| 110 { | |
| 111 called ^= (int)data; | |
| 112 } | |
| 113 | |
| 114 void call_me2(cyg_handle_t alarm, cyg_addrword_t data) | |
| 115 { | |
| 116 call_me(alarm, (cyg_addrword_t)((int)data^0x10)); | |
| 117 } | |
| 118 | |
| 119 | |
| 120 void kclock0_main(void) | |
| 121 { | |
| 122 CYG_TEST_INIT(); | |
| 123 | |
| 124 CHECK(flash()); | |
| 125 CHECK(flash()); | |
| 126 | |
| 127 cyg_counter_create( &counter0, &counter0o); | |
| 128 | |
| 129 CHECK( 0 == cyg_counter_current_value( counter0 ) ); | |
| 130 | |
| 131 cyg_counter_tick(counter0); | |
| 132 | |
| 133 CHECK( 1 == cyg_counter_current_value(counter0) ); | |
| 134 | |
| 135 cyg_counter_tick(counter0); | |
| 136 | |
| 137 CHECK( 2 == cyg_counter_current_value(counter0) ); | |
| 138 | |
| 139 cyg_counter_set_value( counter0, 0xffffffff ); | |
| 140 | |
| 141 CHECK( 0xffffffff == cyg_counter_current_value(counter0) ); | |
| 142 | |
| 2 | 143 cyg_counter_tick(counter0); // Overflows 32 bits |
| 0 | 144 |
| 145 CHECK( 0x100000000ULL == cyg_counter_current_value(counter0) ); | |
| 146 | |
| 147 cyg_counter_set_value(counter0, 11); | |
| 148 CHECK( 11 == cyg_counter_current_value(counter0) ); | |
| 149 | |
| 150 /* the call_me functions cause the "called" bits to toggle | |
| 151 // checking the value of called checks the parity of # of calls | |
| 152 // made by each alarm. | |
| 153 */ | |
| 154 | |
| 155 cyg_alarm_create(counter0, | |
| 156 call_me, (cyg_addrword_t)0x1, &alarm0, &alarmo[0]); | |
| 157 cyg_alarm_create(counter0, | |
| 158 call_me, (cyg_addrword_t)0x2, &alarm1, &alarmo[1]); | |
| 159 cyg_alarm_create(counter0, | |
| 160 call_me2, (cyg_addrword_t)0x4, &alarm2, &alarmo[2]); | |
| 161 | |
| 162 CHECK( 0x00 == called ); | |
| 163 cyg_alarm_initialize(alarm0, 12,3); | |
| 164 cyg_alarm_initialize(alarm2, 21,2); | |
| 165 CHECK( 0x00 == called ); | |
| 166 | |
| 2 | 167 cyg_counter_tick(counter0); /* 12 a0 */ |
| 0 | 168 CHECK( 0x01 == called ); |
| 169 | |
| 170 cyg_alarm_initialize(alarm1, 13,0); | |
| 2 | 171 cyg_counter_tick(counter0); /* 13 a1 */ |
| 0 | 172 CHECK( 0x03 == called ); |
| 173 | |
| 174 cyg_alarm_initialize(alarm1, 17,0); | |
| 2 | 175 cyg_counter_tick(counter0); /* 14 */ |
| 0 | 176 CHECK( 0x03 == called ); |
| 177 | |
| 2 | 178 cyg_counter_tick(counter0); /* 15 a0 */ |
| 0 | 179 CHECK( 0x02 == called ); |
| 180 | |
| 2 | 181 cyg_counter_tick(counter0); /* 16 */ |
| 182 cyg_counter_tick(counter0); /* 17 a1 */ | |
| 0 | 183 CHECK( 0x00 == called ); |
| 184 | |
| 2 | 185 cyg_counter_tick(counter0); /* 18 a0 */ |
| 0 | 186 CHECK( 0x01 == called ); |
| 187 | |
| 2 | 188 cyg_counter_tick(counter0); /* 19 */ |
| 189 cyg_counter_tick(counter0); /* 20 */ | |
| 190 cyg_counter_tick(counter0); /* 21 a0 a2 */ | |
| 0 | 191 CHECK( 0x14 == called ); |
| 192 | |
| 2 | 193 cyg_counter_tick(counter0); /* 22 */ |
| 194 cyg_counter_tick(counter0); /* 23 a2 */ | |
| 0 | 195 CHECK( 0x00 == called ); |
| 196 | |
| 197 cyg_alarm_disable(alarm2); | |
| 198 | |
| 2 | 199 cyg_counter_tick(counter0); /* 24 a0 */ |
| 200 cyg_counter_tick(counter0); /* 25 */ | |
| 0 | 201 CHECK( 0x01 == called ); |
| 202 | |
| 203 cyg_alarm_enable(alarm2); /* a2 (enabled at 25) */ | |
| 204 CHECK( 0x15 == called ); | |
| 205 | |
| 2 | 206 cyg_counter_tick(counter0); /* 26 */ |
| 0 | 207 CHECK( 0x15 == called ); |
| 208 | |
| 2 | 209 cyg_counter_tick(counter0); /* 27 a0 a2 */ |
| 210 cyg_counter_tick(counter0); /* 28 */ | |
| 0 | 211 CHECK( 0x00 == called ); |
| 212 | |
| 2 | 213 cyg_counter_tick(counter0); /* 29 a2 */ |
| 214 cyg_counter_tick(counter0); /* 30 a0 */ | |
| 215 cyg_counter_tick(counter0); /* 31 a2 */ | |
| 0 | 216 CHECK( 0x01 == called ); |
| 217 | |
| 218 res0.dividend = 100; | |
| 219 res0.divisor = 3; | |
| 220 | |
| 221 cyg_clock_create( res0, &clock0, &clock0o ); | |
| 222 | |
| 223 res1 = cyg_clock_get_resolution(clock0); | |
| 224 CHECK( res0.dividend == res1.dividend ); | |
| 225 CHECK( res0.divisor == res1.divisor ); | |
| 226 | |
| 227 res1.dividend = 12; | |
| 228 res1.divisor = 25; | |
| 229 | |
| 230 cyg_clock_set_resolution(clock0, res1); | |
| 231 res0 = cyg_clock_get_resolution(clock0); | |
| 232 CHECK( res0.dividend == res1.dividend ); | |
| 233 CHECK( res0.divisor == res1.divisor ); | |
| 234 | |
| 235 cyg_clock_to_counter(clock0, &counter1); | |
| 236 | |
| 237 CHECK( 0 == cyg_counter_current_value( counter1 ) ); | |
| 238 CHECK( 0 == cyg_current_time() ); | |
| 239 | |
| 240 cyg_counter_tick(counter1); | |
| 241 | |
| 242 CHECK( 1 == cyg_counter_current_value(counter1) ); | |
| 243 | |
| 244 res0 = cyg_clock_get_resolution(cyg_real_time_clock()); | |
| 245 | |
| 246 /* Current time should be 0 as interrupts will still be disabled */ | |
| 247 CHECK( 0 == cyg_current_time() ); | |
| 248 | |
| 249 CYG_TEST_PASS_FINISH("Kernel C API Clock 0 OK"); | |
| 250 } | |
| 251 | |
| 252 externC void | |
| 253 cyg_start( void ) | |
| 254 { | |
| 255 kclock0_main(); | |
| 256 } | |
| 257 | |
| 258 #else // def CYGFUN_KERNEL_API_C | |
| 259 #define N_A_MSG "Kernel C API layer disabled" | |
| 260 #endif // def CYGFUN_KERNEL_API_C | |
| 261 #else // def CYGVAR_KERNEL_COUNTERS_CLOCK | |
| 262 #define N_A_MSG "Kernel real-time clock disabled" | |
| 263 #endif // def CYGVAR_KERNEL_COUNTERS_CLOCK | |
| 264 | |
| 265 #ifdef N_A_MSG | |
| 266 externC void | |
| 267 cyg_start( void ) | |
| 268 { | |
| 269 CYG_TEST_INIT(); | |
| 2 | 270 CYG_TEST_NA( N_A_MSG ); |
| 0 | 271 } |
| 272 #endif // N_A_MSG | |
| 273 | |
| 274 // EOF kclock0.c |
