OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [language/] [c/] [libc/] [time/] [current/] [src/] [clock.cxx] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//===========================================================================
2
//
3
//      clock.cxx
4
//
5
//      ISO C date and time implementation for clock()
6
//
7
//===========================================================================
8
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
9
// -------------------------------------------                              
10
// This file is part of eCos, the Embedded Configurable Operating System.   
11
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
12
//
13
// eCos is free software; you can redistribute it and/or modify it under    
14
// the terms of the GNU General Public License as published by the Free     
15
// Software Foundation; either version 2 or (at your option) any later      
16
// version.                                                                 
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT      
19
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
21
// for more details.                                                        
22
//
23
// You should have received a copy of the GNU General Public License        
24
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
25
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
26
//
27
// As a special exception, if other files instantiate templates or use      
28
// macros or inline functions from this file, or you compile this file      
29
// and link it with other works to produce a work based on this file,       
30
// this file does not by itself cause the resulting work to be covered by   
31
// the GNU General Public License. However the source code for this file    
32
// must still be made available in accordance with section (3) of the GNU   
33
// General Public License v2.                                               
34
//
35
// This exception does not invalidate any other reasons why a work based    
36
// on this file might be covered by the GNU General Public License.         
37
// -------------------------------------------                              
38
// ####ECOSGPLCOPYRIGHTEND####                                              
39
//===========================================================================
40
//#####DESCRIPTIONBEGIN####
41
//
42
// Author(s):    jlarmour
43
// Contributors: jlarmour
44
// Date:         1999-03-05
45
// Purpose:      Provides an implementation of the ISO C function clock()
46
//               from ISO C section 7.12.2.1
47
// Description:  This file uses the kernel real time clock to determine
48
//               the complete running time of the system - since we only
49
//               have one task, even though there are perhaps multiple threads
50
//               that is still the running time of the "program"
51
// Usage:       
52
//
53
//####DESCRIPTIONEND####
54
//
55
//===========================================================================
56
 
57
// CONFIGURATION
58
 
59
#include <pkgconf/libc_time.h>    // Configuration header
60
 
61
#ifdef CYGSEM_LIBC_TIME_CLOCK_WORKING
62
# include <pkgconf/kernel.h> // Kernel config header
63
#endif
64
 
65
// INCLUDES
66
 
67
#include <cyg/infra/cyg_type.h>    // Common type definitions and support
68
#include <cyg/infra/cyg_ass.h>     // Assertion infrastructure
69
#include <cyg/infra/cyg_trac.h>    // Tracing infrastructure
70
 
71
#include <time.h>                  // Header for all time-related functions
72
 
73
#ifdef CYGSEM_LIBC_TIME_CLOCK_WORKING
74
# include <cyg/kernel/clock.hxx>   // Kernel clock definitions
75
# include <cyg/kernel/clock.inl>   // Kernel clock inline functions
76
#endif
77
 
78
 
79
// TRACE
80
 
81
# if defined(CYGDBG_USE_TRACING) && defined(CYGNUM_LIBC_TIME_CLOCK_TRACE_LEVEL)
82
static int clock_trace = CYGNUM_LIBC_TIME_CLOCK_TRACE_LEVEL;
83
#  define TL1 (0 < clock_trace)
84
# else
85
#  define TL1 (0)
86
# endif
87
 
88
// FUNCTIONS
89
 
90
externC clock_t
91
clock( void )
92
{
93
    CYG_REPORT_FUNCNAMETYPE( "clock", "returning clock tick %d" );
94
    CYG_REPORT_FUNCARGVOID();
95
 
96
#ifdef CYGSEM_LIBC_TIME_CLOCK_WORKING
97
    cyg_tick_count curr_clock;            // kernel clock value
98
    Cyg_Clock::cyg_resolution resolution; // kernel clock resolution
99
    clock_t clocks;
100
    unsigned long long temp;
101
 
102
    CYG_TRACE0( TL1, "getting clock resolution" );
103
 
104
    // get the resolution
105
    resolution = Cyg_Clock::real_time_clock->get_resolution();
106
 
107
    CYG_TRACE2( TL1, "got resolution dividend %d divisor %d. Getting "
108
                "clock value", resolution.dividend, resolution.divisor );
109
 
110
    // get the value
111
    curr_clock = Cyg_Clock::real_time_clock->current_value();
112
 
113
    CYG_TRACE1( TL1, "got clock value %d", curr_clock );
114
 
115
    // scale the value so that clock()/CLOCKS_PER_SEC works
116
    // We use an unsigned long long to avoid overflow as the dividend
117
    // and divisors tend to be huge
118
    temp = (1000000000 / CLOCKS_PER_SEC);
119
    temp *= resolution.divisor;
120
    temp = (unsigned long long)curr_clock * resolution.dividend / temp;
121
    clocks = (clock_t)temp;
122
 
123
    CYG_REPORT_RETVAL( clocks );
124
    return clocks;
125
 
126
#else // i.e. ifndef CYGSEM_LIBC_TIME_CLOCK_WORKING
127
    CYG_REPORT_RETVAL( -1 );
128
    return (clock_t) -1;
129
#endif
130
 
131
} // clock()
132
 
133
 
134
// EOF clock.cxx

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.