comparison packages/language/c/libc/current/src/time/clock.cxx @ 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 // clock.cxx
4 //
5 // ANSI standard clock() routine defined in section 7.12.2.1
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): jlarmour
33 // Contributors: jlarmour@cygnus.co.uk
34 // Date: 1998-02-13
35 // Purpose:
36 // Description:
37 // Usage:
38 //
39 //####DESCRIPTIONEND####
40 //
41 //===========================================================================
42
43 // CONFIGURATION
44
45 #include <pkgconf/libc.h> // Configuration header
46
47 #ifdef CYGPKG_KERNEL
48 # include <pkgconf/kernel.h> // Kernel config header
49 #endif
50
51 // Include the C library?
52 #ifdef CYGPKG_LIBC
53
54 // INCLUDES
55
56 #include <cyg/infra/cyg_type.h> // Common type definitions and support
57 #include <cyg/infra/cyg_trac.h> // Tracing support
58 #include <cyg/infra/cyg_ass.h> // Assertion support
59 #include <stddef.h> // NULL and size_t from compiler
60
61 #include <time.h> // Header for all time-related functions
62 #include "clibincl/timesupp.hxx" // Support for time functions
63
64 #if defined(CYGFUN_KERNEL_THREADS_TIMER) && \
65 defined(CYGVAR_KERNEL_COUNTERS_CLOCK)
66 # include <cyg/kernel/clock.hxx> // Kernel clock definitions
67 # include <cyg/kernel/clock.inl> // Kernel clock inline functions
68 #endif
69
70
71 // TRACE
72
73 # if defined(CYGDBG_USE_TRACING) && defined(CYGNUM_LIBC_CLOCK_TRACE_LEVEL)
74 static int clock_trace = CYGNUM_LIBC_CLOCK_TRACE_LEVEL;
75 # define TL1 (0 < clock_trace)
76 # else
77 # define TL1 (0)
78 # endif
79
80
81 // EXPORTED SYMBOLS
82
83 externC clock_t
84 clock( void ) CYGPRI_LIBC_WEAK_ALIAS("_clock");
85
86 // FUNCTIONS
87
88 clock_t
89 _clock( void )
90 {
91 CYG_REPORT_FUNCNAMETYPE( "_clock", "returning clock tick %d" );
92 CYG_REPORT_FUNCARGVOID();
93
94 // Only if the kernel has clock device support
95 #if defined(CYGFUN_KERNEL_THREADS_TIMER) && defined(CYGVAR_KERNEL_COUNTERS_CLOCK)
96 cyg_tick_count curr_clock; // kernel clock value
97 Cyg_Clock::cyg_resolution resolution; // kernel clock resolution
98 clock_t clocks;
99
100 CYG_TRACE0( TL1, "getting clock resolution" );
101
102 // get the resolution
103 resolution = Cyg_Clock::real_time_clock->get_resolution();
104
105 CYG_TRACE2( TL1, "got resolution dividend %d divisor %d. Getting "
106 "clock value", resolution.dividend, resolution.divisor );
107
108 // get the value
109 curr_clock = Cyg_Clock::real_time_clock->current_value();
110
111 CYG_TRACE1( TL1, "got clock value %d", curr_clock );
112
113 // scale the value so that clock()/CLOCKS_PER_SEC works - clock_t
114 // should be big enough to cope
115 clocks = ((clock_t)curr_clock * resolution.dividend) /
116 (resolution.divisor * (1000000000 / CLOCKS_PER_SEC));
117
118 CYG_REPORT_RETVAL( clocks );
119 return clocks;
120
121 #else
122 CYG_REPORT_RETVAL( -1 );
123 return (clock_t) -1;
124 #endif
125
126 } // _clock()
127
128 #endif // ifdef CYGPKG_LIBC
129
130 // EOF clock.cxx