Mercurial > flash_v2
annotate packages/language/c/libc/current/src/time/clock.cxx @ 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 |
| rev | line source |
|---|---|
| 0 | 1 //=========================================================================== |
| 2 // | |
| 3 // clock.cxx | |
| 4 // | |
| 2 | 5 // ISO C date and time implementation for clock() |
| 0 | 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 // | |
| 2 | 34 // Author(s): jlarmour |
| 35 // Contributors: jlarmour | |
| 36 // Date: 1999-03-05 | |
| 37 // Purpose: Provides an implementation of the ISO C function clock() | |
| 38 // from ISO C section 7.12.2.1 | |
| 39 // Description: This file uses the kernel real time clock to determine | |
| 40 // the complete running time of the system - since we only | |
| 41 // have one task, even though there are perhaps multiple threads | |
| 42 // that is still the running time of the "program" | |
| 0 | 43 // Usage: |
| 44 // | |
| 45 //####DESCRIPTIONEND#### | |
| 46 // | |
| 47 //=========================================================================== | |
| 48 | |
| 49 // CONFIGURATION | |
| 50 | |
| 51 #include <pkgconf/libc.h> // Configuration header | |
| 52 | |
| 2 | 53 #ifdef CYGSEM_LIBC_TIME_CLOCK_WORKING |
| 0 | 54 # include <pkgconf/kernel.h> // Kernel config header |
| 55 #endif | |
| 56 | |
| 57 // INCLUDES | |
| 58 | |
| 2 | 59 #include <cyg/infra/cyg_type.h> // Common type definitions and support |
| 60 #include <cyg/infra/cyg_ass.h> // Assertion infrastructure | |
| 61 #include <cyg/infra/cyg_trac.h> // Tracing infrastructure | |
| 0 | 62 |
| 2 | 63 #include <time.h> // Header for all time-related functions |
| 0 | 64 |
| 2 | 65 #ifdef CYGSEM_LIBC_TIME_CLOCK_WORKING |
| 66 # include <cyg/kernel/clock.hxx> // Kernel clock definitions | |
| 67 # include <cyg/kernel/clock.inl> // Kernel clock inline functions | |
| 0 | 68 #endif |
| 69 | |
| 70 | |
| 71 // TRACE | |
| 72 | |
| 2 | 73 # if defined(CYGDBG_USE_TRACING) && defined(CYGNUM_LIBC_TIME_CLOCK_TRACE_LEVEL) |
| 74 static int clock_trace = CYGNUM_LIBC_TIME_CLOCK_TRACE_LEVEL; | |
| 0 | 75 # define TL1 (0 < clock_trace) |
| 76 # else | |
| 77 # define TL1 (0) | |
| 78 # endif | |
| 79 | |
| 80 // FUNCTIONS | |
| 81 | |
| 2 | 82 externC clock_t |
| 83 __clock( void ) | |
| 0 | 84 { |
| 2 | 85 CYG_REPORT_FUNCNAMETYPE( "__clock", "returning clock tick %d" ); |
| 0 | 86 CYG_REPORT_FUNCARGVOID(); |
| 87 | |
| 2 | 88 #ifdef CYGSEM_LIBC_TIME_CLOCK_WORKING |
| 0 | 89 cyg_tick_count curr_clock; // kernel clock value |
| 90 Cyg_Clock::cyg_resolution resolution; // kernel clock resolution | |
| 91 clock_t clocks; | |
| 92 | |
| 93 CYG_TRACE0( TL1, "getting clock resolution" ); | |
| 94 | |
| 95 // get the resolution | |
| 96 resolution = Cyg_Clock::real_time_clock->get_resolution(); | |
| 97 | |
| 98 CYG_TRACE2( TL1, "got resolution dividend %d divisor %d. Getting " | |
| 99 "clock value", resolution.dividend, resolution.divisor ); | |
| 100 | |
| 101 // get the value | |
| 102 curr_clock = Cyg_Clock::real_time_clock->current_value(); | |
| 103 | |
| 104 CYG_TRACE1( TL1, "got clock value %d", curr_clock ); | |
| 105 | |
| 106 // scale the value so that clock()/CLOCKS_PER_SEC works - clock_t | |
| 107 // should be big enough to cope | |
| 108 clocks = ((clock_t)curr_clock * resolution.dividend) / | |
| 109 (resolution.divisor * (1000000000 / CLOCKS_PER_SEC)); | |
| 110 | |
| 111 CYG_REPORT_RETVAL( clocks ); | |
| 112 return clocks; | |
| 113 | |
| 2 | 114 #else // i.e. ifndef CYGSEM_LIBC_TIME_CLOCK_WORKING |
| 0 | 115 CYG_REPORT_RETVAL( -1 ); |
| 116 return (clock_t) -1; | |
| 117 #endif | |
| 118 | |
| 2 | 119 } // __clock() |
| 120 | |
| 0 | 121 |
| 2 | 122 // SYMBOL DEFINITIONS |
| 123 | |
| 124 externC clock_t | |
| 125 clock( void ) CYGBLD_ATTRIB_WEAK_ALIAS(__clock); | |
| 0 | 126 |
| 127 // EOF clock.cxx |
