Mercurial > ecos
annotate packages/kernel/current/tests/kclock1.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 // kclock1.c | |
| 4 // | |
| 5 // Kernel C API Clock test 1 - Real Time Clock | |
| 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 the Kernel Real Time Clock | |
| 38 // This test creates a thread, starts the scheduler and | |
| 39 // delays for a time of about 5 seconds. This test should | |
| 40 // be expected to run for about this length of time. | |
| 41 // Omissions: | |
| 42 // Doesn't test alarms attached to RTC. | |
| 43 // Assumptions: | |
| 44 // CYGVAR_KERNEL_COUNTERS_CLOCK must be set. | |
| 45 // Resolution of clock small compared with 5s. | |
| 46 // Overhead small compared with 5s. | |
| 47 // Options: | |
| 48 // CYGIMP_KERNEL_COUNTERS_SINGLE_LIST | |
| 49 // CYGIMP_KERNEL_COUNTERS_MULTI_LIST | |
| 50 // CYGVAR_KERNEL_COUNTERS_CLOCK | |
| 51 // CYGNUM_KERNEL_COUNTERS_MULTI_LIST_SIZE | |
| 52 //####DESCRIPTIONEND#### | |
| 53 */ | |
| 54 | |
| 2 | 55 #include <cyg/hal/hal_arch.h> // CYGNUM_HAL_STACK_SIZE_TYPICAL |
| 56 | |
| 0 | 57 #include <cyg/kernel/kapi.h> |
| 58 | |
| 59 #include <cyg/infra/testcase.h> | |
| 60 | |
| 61 | |
| 2 | 62 static cyg_uint64 TEST_DELAY; |
| 0 | 63 |
| 2 | 64 #ifdef CYGFUN_KERNEL_THREADS_TIMER |
| 0 | 65 |
| 66 #ifdef CYGFUN_KERNEL_API_C | |
| 67 | |
| 68 #include "testaux.h" | |
| 69 | |
| 70 #define NTHREADS 1 | |
| 2 | 71 #define STACKSIZE CYGNUM_HAL_STACK_SIZE_TYPICAL |
| 0 | 72 |
| 73 static cyg_handle_t thread[NTHREADS]; | |
| 74 | |
| 75 static cyg_thread thread_obj[NTHREADS]; | |
| 76 static char stack[NTHREADS][STACKSIZE]; | |
| 77 | |
| 78 static void entry0( cyg_addrword_t data ) | |
| 79 { | |
| 80 cyg_resolution_t res; | |
| 81 cyg_uint32 ticks; | |
| 82 cyg_tick_count_t count0, count1; | |
| 83 cyg_handle_t rtclock, rtcounter; | |
| 84 | |
| 85 rtclock = cyg_real_time_clock(); | |
| 86 cyg_clock_to_counter(rtclock, &rtcounter); | |
| 87 | |
| 88 res = cyg_clock_get_resolution (rtclock); | |
| 89 | |
| 90 /* RTC takes res.dividend/res.divisor ns/tick */ | |
| 91 ticks = ((cyg_uint64)TEST_DELAY * res.divisor) / res.dividend; | |
| 92 | |
| 93 count0 = cyg_counter_current_value(rtcounter); | |
| 94 cyg_thread_delay(ticks); | |
| 95 count1 = cyg_counter_current_value(rtcounter); | |
| 96 | |
| 97 CYG_TEST_CHECK(count0+ticks <= count1, | |
| 98 "real time clock's counter not counting"); | |
| 99 | |
| 100 CYG_TEST_CHECK(count1 <= cyg_current_time(),"cyg_current_time()"); | |
| 101 | |
| 102 CYG_TEST_PASS_FINISH("Kernel C API Clock 1 OK"); | |
| 103 } | |
| 104 | |
| 105 void kclock1_main( void ) | |
| 106 { | |
| 107 CYG_TEST_INIT(); | |
| 108 | |
| 2 | 109 if (cyg_test_is_simulator) { |
| 110 TEST_DELAY = 100000000ll; | |
| 111 } else { | |
| 112 TEST_DELAY = 3000000000ll; | |
| 113 } | |
| 114 | |
| 0 | 115 cyg_thread_create(4, entry0 , (cyg_addrword_t)0, "kclock1", |
| 2 | 116 (void *)stack[0], STACKSIZE, &thread[0], &thread_obj[0]); |
| 0 | 117 cyg_thread_resume(thread[0]); |
| 118 | |
| 119 cyg_scheduler_start(); | |
| 120 } | |
| 121 | |
| 122 externC void | |
| 123 cyg_start( void ) | |
| 124 { | |
| 125 kclock1_main(); | |
| 126 } | |
| 127 | |
| 2 | 128 #else // def CYGFUN_KERNEL_API_C |
| 0 | 129 #define N_A_MSG "Kernel C API layer disabled" |
| 130 #endif // def CYGFUN_KERNEL_API_C | |
| 2 | 131 #else // def CYGFUN_KERNEL_THREADS_TIMER |
| 132 #define N_A_MSG "Kernel threads timer disabled" | |
| 133 #endif // def CYGFUN_KERNEL_THREADS_TIMER | |
| 0 | 134 |
| 135 #ifdef N_A_MSG | |
| 136 externC void | |
| 137 cyg_start( void ) | |
| 138 { | |
| 139 CYG_TEST_INIT(); | |
| 2 | 140 CYG_TEST_NA( N_A_MSG ); |
| 0 | 141 } |
| 142 #endif // N_A_MSG | |
| 143 | |
| 144 // EOF kclock1.c |
