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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [kernel/] [v2_0/] [tests/] [clock0.cxx] - Blame information for rev 475

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

Line No. Rev Author Line
1 27 unneback
//==========================================================================
2
//
3
//        clock0.cxx
4
//
5
//        Clock test 0
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-13
46
// Description:   Tests some basic clock functions.
47
// Omissions:     Doesn't test likely boundary conditions for
48
//                CYGNUM_KERNEL_COUNTERS_MULTI_LIST_SIZE
49
//                Real Time Clock Testing is limited
50
// Options:
51
//     CYGIMP_KERNEL_COUNTERS_SINGLE_LIST
52
//     CYGIMP_KERNEL_COUNTERS_MULTI_LIST
53
//     CYGVAR_KERNEL_COUNTERS_CLOCK
54
//     CYGNUM_KERNEL_COUNTERS_MULTI_LIST_SIZE
55
// Assumptions:   This assumes we have long long support and
56
//                that counters are 64 bits.
57
//####DESCRIPTIONEND####
58
 
59
#include <pkgconf/kernel.h>
60
 
61
#include <cyg/kernel/clock.hxx>
62
 
63
#include <cyg/infra/testcase.h>
64
 
65
#include <cyg/kernel/clock.inl>
66
 
67
#include "testaux.hxx"
68
 
69
#ifdef CYGVAR_KERNEL_COUNTERS_CLOCK
70
 
71
cyg_alarm_fn call_me;
72
 
73
bool flash( void )
74
{
75
    Cyg_Counter counter0 = Cyg_Counter();
76
    Cyg_Counter counter1 = Cyg_Counter(723);
77
 
78
    CYG_ASSERTCLASSO( counter0, "error" );
79
    CYG_ASSERTCLASSO( counter1, "error" );
80
 
81
    Cyg_Alarm alarm0 = Cyg_Alarm(&counter0, call_me, 12);
82
 
83
    CYG_ASSERTCLASSO( alarm0, "error" );
84
 
85
    Cyg_Clock::cyg_resolution res = {1,2};
86
 
87
    Cyg_Clock clock0(res);
88
 
89
    CYG_ASSERTCLASSO( clock0, "error" );
90
 
91
    return true;
92
}
93
 
94
// Testing alarms
95
//
96
// call_me is a function that will be called when an alarm is
97
// triggered.  It updates a global variable called which is CHECKed
98
// explicitly to see if the approriate alarms have been called.
99
 
100
cyg_uint16 called = 0x0;
101
 
102
void call_me(Cyg_Alarm *alarm, CYG_ADDRWORD data)
103
{
104
    called ^= data;
105
}
106
 
107
void call_me2(Cyg_Alarm *alarm, CYG_ADDRWORD data)
108
{
109
    call_me(alarm, data^0x10);
110
}
111
 
112
 
113
void clock0_main(void)
114
{
115
    CYG_TEST_INIT();
116
 
117
    CHECK(flash());
118
    CHECK(flash());
119
 
120
    const cyg_uint32 big_number = 3333222111u;
121
    Cyg_Counter counter0 = Cyg_Counter();
122
 
123
    CHECK( 0 == counter0.current_value() );
124
    CHECK( 0 == counter0.current_value_lo() );
125
    CHECK( 0 == counter0.current_value_hi() );
126
 
127
    counter0.tick();
128
 
129
    CHECK( 1 == counter0.current_value() );
130
    CHECK( 1 == counter0.current_value_lo() );
131
    CHECK( 0 == counter0.current_value_hi() );
132
 
133
    counter0.tick(6);
134
 
135
    CHECK( 7 == counter0.current_value() );
136
    CHECK( 7 == counter0.current_value_lo() );
137
    CHECK( 0 == counter0.current_value_hi() );
138
 
139
    counter0.set_value( 0xfffffffc );
140
 
141
    CHECK( 0xfffffffc == counter0.current_value() );
142
    CHECK( 0xfffffffc == counter0.current_value_lo() );
143
    CHECK( 0 == counter0.current_value_hi() );
144
 
145
    counter0.tick( 0x13 );      // Overflows 32 bits
146
 
147
    CHECK( 0x10000000fULL == counter0.current_value() );
148
    CHECK( 0xf == counter0.current_value_lo() );
149
    CHECK( 0x1 == counter0.current_value_hi() );
150
 
151
 
152
    Cyg_Counter counter1 = Cyg_Counter(big_number);
153
 
154
    CHECK( 0 == counter1.current_value() );
155
    CHECK( 0 == counter1.current_value_lo() );
156
    CHECK( 0 == counter1.current_value_hi() );
157
 
158
    counter1.tick(2);
159
 
160
    CHECK( 2ll*big_number == counter1.current_value() );
161
    CHECK( ((2ll*big_number) & 0xffffffff) ==
162
                counter1.current_value_lo() );
163
    CHECK( ((2ll*big_number) >> 32) == counter1.current_value_hi() );
164
 
165
    counter1.tick();
166
 
167
    CHECK( 3ll*big_number == counter1.current_value() );
168
    CHECK( ((3ll*big_number) & 0xffffffff) ==
169
                counter1.current_value_lo() );
170
    CHECK( ((3ll*big_number) >> 32) == counter1.current_value_hi() );
171
 
172
    counter1.tick();
173
 
174
    CHECK( 4ll*big_number == counter1.current_value() );
175
    CHECK( ((4ll*big_number) & 0xffffffff) ==
176
                counter1.current_value_lo() );
177
    CHECK( ((4ll*big_number) >> 32) == counter1.current_value_hi() );
178
 
179
    counter1.set_value(1222333444555ll);
180
    CHECK( 1222333444555ll == counter1.current_value() );
181
 
182
    counter0.set_value(11);
183
    CHECK( 11 == counter0.current_value() );
184
 
185
    // the call_me functions cause the "called" bits to toggle
186
    // CHECKing the value of called TEST_CHECKs the parity of # of calls
187
    // made by each alarm.
188
 
189
    Cyg_Alarm alarm0 = Cyg_Alarm(&counter0, call_me, 0x1);
190
    Cyg_Alarm alarm1 = Cyg_Alarm(&counter0, call_me, 0x2);
191
    Cyg_Alarm alarm2 = Cyg_Alarm(&counter0, call_me2, 0x4);
192
 
193
    CHECK( 0x00 == called );
194
    alarm0.initialize(12,3);
195
    alarm2.initialize(21,2);
196
    CHECK( 0x00 == called );
197
 
198
    counter0.tick();            // 12 a0
199
    CHECK( 0x01 == called );
200
 
201
    alarm1.initialize(13,0);
202
    counter0.tick();            // 13 a1
203
    CHECK( 0x03 == called );
204
 
205
    alarm1.initialize(17,0);
206
    counter0.tick();            // 14
207
    CHECK( 0x03 == called );
208
 
209
    counter0.tick();            // 15 a0
210
    CHECK( 0x02 == called );
211
 
212
    counter0.tick(2);           // 17 a1
213
    CHECK( 0x00 == called );
214
 
215
    counter0.tick();            // 18 a0
216
    CHECK( 0x01 == called );
217
 
218
    counter0.tick(3);           // 21 a0 a2
219
    CHECK( 0x14 == called );
220
 
221
    counter0.tick(2);           // 23 a2
222
    CHECK( 0x00 == called );
223
 
224
    alarm2.disable();
225
 
226
    counter0.tick(2);           // 25 a0(24)
227
    CHECK( 0x01 == called );
228
 
229
    alarm2.enable();            // a2 (enabled at 25)
230
    CHECK( 0x15 == called );
231
 
232
    counter0.tick();            // 26
233
    CHECK( 0x15 == called );
234
 
235
    counter0.tick(2);           // 28 a0(27) a2(27)
236
    CHECK( 0x00 == called );
237
 
238
    counter0.tick(3);           // 31 a0(30) a2(29 31)
239
    CHECK( 0x01 == called );
240
 
241
    Cyg_Clock::cyg_resolution res0;
242
 
243
    res0.dividend = 100;
244
    res0.divisor = 3;
245
 
246
    Cyg_Clock::cyg_resolution res1;
247
 
248
    Cyg_Clock clock0 = Cyg_Clock(res0);
249
 
250
    res1 = clock0.get_resolution();
251
    CHECK( res0.dividend == res1.dividend );
252
    CHECK( res0.divisor == res1.divisor );
253
 
254
    res1.dividend = 12;
255
    res1.divisor = 25;
256
 
257
    clock0.set_resolution(res1);
258
    res0 = clock0.get_resolution();
259
    CHECK( res0.dividend == res1.dividend );
260
    CHECK( res0.divisor == res1.divisor );
261
 
262
    res0 = Cyg_Clock::real_time_clock->get_resolution();
263
 
264
    CYG_TEST_PASS_FINISH("Clock 0 OK");
265
}
266
 
267
externC void
268
cyg_start( void )
269
{
270
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
271
    cyg_hal_invoke_constructors();
272
#endif
273
    clock0_main();
274
}
275
 
276
#else // def CYGVAR_KERNEL_COUNTERS_CLOCK
277
 
278
externC void
279
cyg_start( void )
280
{
281
    CYG_TEST_INIT();
282
    CYG_TEST_NA( "Kernel real-time clock disabled");
283
}
284
 
285
#endif // def CYGVAR_KERNEL_COUNTERS_CLOCK
286
// EOF clock0.cxx

powered by: WebSVN 2.1.0

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