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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [kernel/] [current/] [tests/] [clocktruth.cxx] - Blame information for rev 851

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//        clocktruth.cxx
4
//
5
//        Clock accuracy test
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, 2003 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):     hmt
43
// Contributors:  hmt
44
// Date:          2001-06-05
45
// Description:   Tests the Kernel Real Time Clock for accuracy using a human
46
// 
47
//####DESCRIPTIONEND####
48
 
49
 
50
// This is for a human to watch to sanity check the clock rate.
51
// It's easier to see what's happening if you enable this:
52
#define nRUNFOREVER
53
 
54
 
55
#include <pkgconf/kernel.h>
56
 
57
#include <cyg/kernel/clock.hxx>
58
#include <cyg/kernel/sema.hxx>
59
#include <cyg/kernel/thread.hxx>
60
 
61
#include <cyg/infra/testcase.h>
62
 
63
#include <cyg/kernel/clock.inl>
64
#include <cyg/kernel/thread.inl>
65
 
66
#ifdef CYGVAR_KERNEL_COUNTERS_CLOCK
67
 
68
#include <cyg/infra/diag.h>
69
 
70
#define NTHREADS 1
71
#include "testaux.hxx"
72
 
73
#ifdef RUNFOREVER
74
#define ENDPOINT 8192
75
#else
76
#define ENDPOINT 20
77
#endif
78
 
79
static cyg_alarm_fn alarmfunc;
80
static void alarmfunc( Cyg_Alarm *alarm, CYG_ADDRWORD data )
81
{
82
    Cyg_Binary_Semaphore *sp = (Cyg_Binary_Semaphore *)data;
83
    sp->post();
84
}
85
 
86
 
87
static void entry0( CYG_ADDRWORD data )
88
{
89
    cyg_uint32 now, then;
90
    int i;
91
 
92
    Cyg_Clock *rtc = Cyg_Clock::real_time_clock;
93
 
94
    Cyg_Binary_Semaphore sema;
95
 
96
    Cyg_Alarm alarm( rtc, &alarmfunc, (CYG_ADDRWORD)&sema );
97
 
98
    // First, print 100 lines as fast as you can, of distinct ticks.
99
    for ( i = 0; i < 100; i++ ) {
100
        now = rtc->current_value_lo();
101
        then = now;
102
        while ( then == now )
103
            now = rtc->current_value_lo();
104
 
105
        diag_printf( "INFO<time now %8d>\n", now );
106
    }
107
 
108
    diag_printf( "INFO<per-second times are: %8d>\n", rtc->current_value_lo() );
109
    for ( i = 0; i < 20; i++ ) {
110
        Cyg_Thread::counted_sleep( 100 );
111
        diag_printf( "INFO<per-second time %2d is %8d>\n",
112
                     i, rtc->current_value_lo() );
113
    }
114
 
115
    alarm.initialize( rtc->current_value() + 100, 100 );
116
    alarm.enable();
117
    for ( i = 0; i < ENDPOINT; i++ ) {
118
        sema.wait();
119
        diag_printf( "INFO<alarm time %2d is %8d>\n",
120
                     i, rtc->current_value_lo() );
121
    }
122
 
123
    CYG_TEST_PASS_FINISH("Clock truth OK");
124
}
125
 
126
void clocktruth_main( void )
127
{
128
    CYG_TEST_INIT();
129
    new_thread(entry0, (CYG_ADDRWORD)&thread_obj[0]);
130
    Cyg_Scheduler::start();
131
}
132
 
133
externC void
134
cyg_start( void )
135
{
136
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
137
    cyg_hal_invoke_constructors();
138
#endif
139
    clocktruth_main();
140
}
141
 
142
#else // def CYGVAR_KERNEL_COUNTERS_CLOCK
143
 
144
externC void
145
cyg_start( void )
146
{
147
    CYG_TEST_INIT();
148
    CYG_TEST_NA( "Kernel real-time clock disabled");
149
}
150
 
151
#endif // def CYGVAR_KERNEL_COUNTERS_CLOCK
152
 
153
// EOF clocktruth.cxx

powered by: WebSVN 2.1.0

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