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