Mercurial > ecos
comparison packages/kernel/current/tests/kclock1.c @ 0:3111d98ba7b3 ecos-v1_1-release
Initial commit of eCos version 1.1
| author | jlarmour |
|---|---|
| date | Tue, 11 May 1999 11:16:07 +0000 |
| parents | |
| children | 443894e2e912 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:3111d98ba7b3 |
|---|---|
| 1 /*================================================================= | |
| 2 // | |
| 3 // kclock1.c | |
| 4 // | |
| 5 // Kernel C API Clock test 1 - Real Time Clock | |
| 6 // | |
| 7 //========================================================================== | |
| 8 //####COPYRIGHTBEGIN#### | |
| 9 // | |
| 10 // ------------------------------------------- | |
| 11 // The contents of this file are subject to the Cygnus eCos Public License | |
| 12 // Version 1.0 (the "License"); you may not use this file except in | |
| 13 // compliance with the License. You may obtain a copy of the License at | |
| 14 // http://sourceware.cygnus.com/ecos | |
| 15 // | |
| 16 // Software distributed under the License is distributed on an "AS IS" | |
| 17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the | |
| 18 // License for the specific language governing rights and limitations under | |
| 19 // the License. | |
| 20 // | |
| 21 // The Original Code is eCos - Embedded Cygnus Operating System, released | |
| 22 // September 30, 1998. | |
| 23 // | |
| 24 // The Initial Developer of the Original Code is Cygnus. Portions created | |
| 25 // by Cygnus are Copyright (C) 1998 Cygnus Solutions. All Rights Reserved. | |
| 26 // ------------------------------------------- | |
| 27 // | |
| 28 //####COPYRIGHTEND#### | |
| 29 //========================================================================== | |
| 30 //#####DESCRIPTIONBEGIN#### | |
| 31 // | |
| 32 // Author(s): dsm | |
| 33 // Contributors: dsm | |
| 34 // Date: 1998-03-20 | |
| 35 // Description: Tests the Kernel Real Time Clock | |
| 36 // This test creates a thread, starts the scheduler and | |
| 37 // delays for a time of about 5 seconds. This test should | |
| 38 // be expected to run for about this length of time. | |
| 39 // Omissions: | |
| 40 // Doesn't test alarms attached to RTC. | |
| 41 // Assumptions: | |
| 42 // CYGVAR_KERNEL_COUNTERS_CLOCK must be set. | |
| 43 // Resolution of clock small compared with 5s. | |
| 44 // Overhead small compared with 5s. | |
| 45 // Options: | |
| 46 // CYGIMP_KERNEL_COUNTERS_SINGLE_LIST | |
| 47 // CYGIMP_KERNEL_COUNTERS_MULTI_LIST | |
| 48 // CYGVAR_KERNEL_COUNTERS_CLOCK | |
| 49 // CYGNUM_KERNEL_COUNTERS_MULTI_LIST_SIZE | |
| 50 //####DESCRIPTIONEND#### | |
| 51 */ | |
| 52 | |
| 53 #include <cyg/kernel/kapi.h> | |
| 54 | |
| 55 #include <cyg/infra/testcase.h> | |
| 56 | |
| 57 #if defined(CYG_HAL_MIPS_SIM) | |
| 58 | |
| 59 // Reduce time in simulated TX39 so that | |
| 60 // it runs within the timeout. | |
| 61 | |
| 62 #define TEST_DELAY 1000000000ll | |
| 63 | |
| 64 #else | |
| 65 | |
| 66 #define TEST_DELAY 5000000000ll | |
| 67 | |
| 68 #endif | |
| 69 | |
| 70 #if defined(CYGVAR_KERNEL_COUNTERS_CLOCK) \ | |
| 71 && defined(CYGFUN_KERNEL_THREADS_TIMER) | |
| 72 | |
| 73 #ifdef CYGFUN_KERNEL_API_C | |
| 74 | |
| 75 #include "testaux.h" | |
| 76 | |
| 77 #define NTHREADS 1 | |
| 78 #define STACKSIZE 4096 | |
| 79 | |
| 80 static cyg_handle_t thread[NTHREADS]; | |
| 81 | |
| 82 static cyg_thread thread_obj[NTHREADS]; | |
| 83 static char stack[NTHREADS][STACKSIZE]; | |
| 84 | |
| 85 static void entry0( cyg_addrword_t data ) | |
| 86 { | |
| 87 cyg_resolution_t res; | |
| 88 cyg_uint32 ticks; | |
| 89 cyg_tick_count_t count0, count1; | |
| 90 cyg_handle_t rtclock, rtcounter; | |
| 91 | |
| 92 rtclock = cyg_real_time_clock(); | |
| 93 cyg_clock_to_counter(rtclock, &rtcounter); | |
| 94 | |
| 95 res = cyg_clock_get_resolution (rtclock); | |
| 96 | |
| 97 /* RTC takes res.dividend/res.divisor ns/tick */ | |
| 98 ticks = ((cyg_uint64)TEST_DELAY * res.divisor) / res.dividend; | |
| 99 | |
| 100 count0 = cyg_counter_current_value(rtcounter); | |
| 101 cyg_thread_delay(ticks); | |
| 102 count1 = cyg_counter_current_value(rtcounter); | |
| 103 | |
| 104 CYG_TEST_CHECK(count0+ticks <= count1, | |
| 105 "real time clock's counter not counting"); | |
| 106 | |
| 107 CYG_TEST_CHECK(count1 <= cyg_current_time(),"cyg_current_time()"); | |
| 108 | |
| 109 CYG_TEST_PASS_FINISH("Kernel C API Clock 1 OK"); | |
| 110 } | |
| 111 | |
| 112 void kclock1_main( void ) | |
| 113 { | |
| 114 CYG_TEST_INIT(); | |
| 115 | |
| 116 cyg_thread_create(4, entry0 , (cyg_addrword_t)0, "kclock1", | |
| 117 (void *)stack[0], STACKSIZE, &thread[0], &thread_obj[0]); | |
| 118 cyg_thread_resume(thread[0]); | |
| 119 | |
| 120 cyg_scheduler_start(); | |
| 121 } | |
| 122 | |
| 123 externC void | |
| 124 cyg_start( void ) | |
| 125 { | |
| 126 kclock1_main(); | |
| 127 } | |
| 128 | |
| 129 #else // def CYGFUN_KERNEL_API_C | |
| 130 #define N_A_MSG "Kernel C API layer disabled" | |
| 131 #endif // def CYGFUN_KERNEL_API_C | |
| 132 #else // def CYGVAR_KERNEL_COUNTERS_CLOCK && CYGFUN_KERNEL_THREADS_TIMER | |
| 133 #define N_A_MSG "Kernel real-time clock/threads timer disabled" | |
| 134 #endif // def CYGVAR_KERNEL_COUNTERS_CLOCK && CYGFUN_KERNEL_THREADS_TIMER | |
| 135 | |
| 136 #ifdef N_A_MSG | |
| 137 externC void | |
| 138 cyg_start( void ) | |
| 139 { | |
| 140 CYG_TEST_INIT(); | |
| 141 CYG_TEST_PASS_FINISH("N/A: " N_A_MSG); | |
| 142 } | |
| 143 #endif // N_A_MSG | |
| 144 | |
| 145 // EOF kclock1.c |
