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

Subversion Repositories openrisc

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

powered by: WebSVN 2.1.0

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