1 |
1254 |
phoenix |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// clock1.cxx
|
4 |
|
|
//
|
5 |
|
|
// Clock test 1 - Real Time 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 Red Hat, 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 version.
|
16 |
|
|
//
|
17 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
|
18 |
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
19 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
20 |
|
|
// for more details.
|
21 |
|
|
//
|
22 |
|
|
// You should have received a copy of the GNU General Public License along
|
23 |
|
|
// with eCos; if not, write to the Free Software Foundation, Inc.,
|
24 |
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
25 |
|
|
//
|
26 |
|
|
// As a special exception, if other files instantiate templates or use macros
|
27 |
|
|
// or inline functions from this file, or you compile this file and link it
|
28 |
|
|
// with other works to produce a work based on this file, this file does not
|
29 |
|
|
// by itself cause the resulting work to be covered by the GNU General Public
|
30 |
|
|
// License. However the source code for this file must still be made available
|
31 |
|
|
// in accordance with section (3) of the GNU General Public License.
|
32 |
|
|
//
|
33 |
|
|
// This exception does not invalidate any other reasons why a work based on
|
34 |
|
|
// this file might be covered by the GNU General Public License.
|
35 |
|
|
//
|
36 |
|
|
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
|
37 |
|
|
// at http://sources.redhat.com/ecos/ecos-license/
|
38 |
|
|
// -------------------------------------------
|
39 |
|
|
//####ECOSGPLCOPYRIGHTEND####
|
40 |
|
|
//==========================================================================
|
41 |
|
|
//#####DESCRIPTIONBEGIN####
|
42 |
|
|
//
|
43 |
|
|
// Author(s): dsm
|
44 |
|
|
// Contributors: dsm
|
45 |
|
|
// Date: 1998-02-16
|
46 |
|
|
// Description: Tests the Kernel Real Time Clock
|
47 |
|
|
// This test creates a thread, starts the scheduler and
|
48 |
|
|
// delays for a time of about 5 seconds. This test should
|
49 |
|
|
// be expected to run for about this length of time.
|
50 |
|
|
// Omissions:
|
51 |
|
|
// Doesn't test alarms attached to RTC.
|
52 |
|
|
// Assumptions:
|
53 |
|
|
// CYGVAR_KERNEL_COUNTERS_CLOCK must be set.
|
54 |
|
|
// Resolution of clock small compared with 5s.
|
55 |
|
|
// Overhead small compared with 5s.
|
56 |
|
|
// Options:
|
57 |
|
|
// CYGIMP_KERNEL_COUNTERS_SINGLE_LIST
|
58 |
|
|
// CYGIMP_KERNEL_COUNTERS_MULTI_LIST
|
59 |
|
|
// CYGVAR_KERNEL_COUNTERS_CLOCK
|
60 |
|
|
// CYGNUM_KERNEL_COUNTERS_MULTI_LIST_SIZE
|
61 |
|
|
//####DESCRIPTIONEND####
|
62 |
|
|
|
63 |
|
|
#include <pkgconf/kernel.h>
|
64 |
|
|
|
65 |
|
|
#include <cyg/kernel/clock.hxx>
|
66 |
|
|
#include <cyg/kernel/thread.hxx>
|
67 |
|
|
|
68 |
|
|
#include <cyg/infra/testcase.h>
|
69 |
|
|
|
70 |
|
|
#include <cyg/kernel/clock.inl>
|
71 |
|
|
#include <cyg/kernel/thread.inl>
|
72 |
|
|
|
73 |
|
|
#ifdef CYGVAR_KERNEL_COUNTERS_CLOCK
|
74 |
|
|
|
75 |
|
|
|
76 |
|
|
#define NTHREADS 1
|
77 |
|
|
#include "testaux.hxx"
|
78 |
|
|
|
79 |
|
|
static cyg_uint32 ticks; // Number of ticks thread[0] will delay for
|
80 |
|
|
|
81 |
|
|
static cyg_uint64 TEST_DELAY;
|
82 |
|
|
|
83 |
|
|
static void entry0( CYG_ADDRWORD data )
|
84 |
|
|
{
|
85 |
|
|
((Cyg_Thread *)data)->delay(ticks);
|
86 |
|
|
|
87 |
|
|
CYG_TEST_PASS_FINISH("Clock 1 OK");
|
88 |
|
|
}
|
89 |
|
|
|
90 |
|
|
void clock1_main( void )
|
91 |
|
|
{
|
92 |
|
|
CYG_TEST_INIT();
|
93 |
|
|
|
94 |
|
|
if (cyg_test_is_simulator) {
|
95 |
|
|
TEST_DELAY = 100000000ll;
|
96 |
|
|
} else {
|
97 |
|
|
TEST_DELAY = 3000000000ll;
|
98 |
|
|
}
|
99 |
|
|
|
100 |
|
|
new_thread(entry0, (CYG_ADDRWORD)&thread_obj[0]);
|
101 |
|
|
|
102 |
|
|
Cyg_Clock::cyg_resolution res;
|
103 |
|
|
|
104 |
|
|
res = Cyg_Clock::real_time_clock->get_resolution ();
|
105 |
|
|
|
106 |
|
|
// RTC takes res.dividend/res.divisor ns/tick
|
107 |
|
|
ticks = ((cyg_uint64)TEST_DELAY * res.divisor) / res.dividend;
|
108 |
|
|
|
109 |
|
|
Cyg_Scheduler::start();
|
110 |
|
|
}
|
111 |
|
|
|
112 |
|
|
externC void
|
113 |
|
|
cyg_start( void )
|
114 |
|
|
{
|
115 |
|
|
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
|
116 |
|
|
cyg_hal_invoke_constructors();
|
117 |
|
|
#endif
|
118 |
|
|
clock1_main();
|
119 |
|
|
}
|
120 |
|
|
|
121 |
|
|
#else // def CYGVAR_KERNEL_COUNTERS_CLOCK
|
122 |
|
|
|
123 |
|
|
externC void
|
124 |
|
|
cyg_start( void )
|
125 |
|
|
{
|
126 |
|
|
CYG_TEST_INIT();
|
127 |
|
|
CYG_TEST_NA( "Kernel real-time clock disabled");
|
128 |
|
|
}
|
129 |
|
|
|
130 |
|
|
#endif // def CYGVAR_KERNEL_COUNTERS_CLOCK
|
131 |
|
|
|
132 |
|
|
// EOF clock1.cxx
|