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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [kernel/] [current/] [tests/] [kclock0.c] - 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
//        kclock0.c
4
//
5
//        Kernel C API 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-03-20
45
// Description:   Tests some basic clock functions.
46
//####DESCRIPTIONEND####
47
*/
48
 
49
#include <cyg/kernel/kapi.h>
50
 
51
#include <cyg/infra/testcase.h>
52
 
53
#ifdef CYGVAR_KERNEL_COUNTERS_CLOCK
54
 
55
#ifdef CYGFUN_KERNEL_API_C
56
 
57
#include "testaux.h"
58
 
59
cyg_alarm_t call_me;
60
 
61
cyg_counter counter0o, counter1o;
62
cyg_handle_t counter0, counter1;
63
 
64
cyg_alarm alarmo[3];
65
cyg_handle_t alarm0, alarm1, alarm2;
66
 
67
cyg_resolution_t res, res0, res1;
68
 
69
cyg_clock clock0o;
70
cyg_handle_t clock0;
71
 
72
const cyg_uint32 big_number = 3333222111u;
73
 
74
cyg_bool_t flash( void )
75
{
76
    cyg_counter_create( &counter0, &counter0o );
77
    cyg_counter_create( &counter1, &counter1o );
78
 
79
    cyg_alarm_create( counter0,
80
                      call_me,
81
                      (cyg_addrword_t)12,
82
                      &alarm0,
83
                      &alarmo[0]);
84
 
85
    res.dividend = 1;
86
    res.divisor = 2;
87
 
88
    cyg_clock_create( res, &clock0, &clock0o );
89
    cyg_clock_delete( clock0 );
90
 
91
    cyg_alarm_delete( alarm0 );
92
 
93
    cyg_counter_delete( counter0 );
94
    cyg_counter_delete( counter1 );
95
 
96
    return true;
97
}
98
 
99
/* Testing alarms
100
//
101
// call_me is a function that will be called when an alarm is
102
// triggered.  It updates a global variable called which is CHECKed
103
// explicitly to see if the approriate alarms have been called.
104
*/
105
 
106
cyg_uint16 called = 0x0;
107
 
108
void call_me(cyg_handle_t alarm, cyg_addrword_t data)
109
{
110
    called ^= (int)data;
111
}
112
 
113
void call_me2(cyg_handle_t alarm, cyg_addrword_t data)
114
{
115
    call_me(alarm, (cyg_addrword_t)((int)data^0x10));
116
}
117
 
118
 
119
void kclock0_main(void)
120
{
121
    CYG_TEST_INIT();
122
 
123
    CHECK(flash());
124
    CHECK(flash());
125
 
126
    cyg_counter_create( &counter0, &counter0o);
127
 
128
    CHECK( 0 == cyg_counter_current_value( counter0 ) );
129
 
130
    cyg_counter_tick(counter0);
131
 
132
    CHECK( 1 == cyg_counter_current_value(counter0) );
133
 
134
    cyg_counter_tick(counter0);
135
 
136
    CHECK( 2 == cyg_counter_current_value(counter0) );
137
 
138
    cyg_counter_set_value( counter0, 0xffffffff );
139
 
140
    CHECK( 0xffffffff == cyg_counter_current_value(counter0) );
141
 
142
    cyg_counter_tick(counter0); // Overflows 32 bits
143
 
144
    CHECK( 0x100000000ULL == cyg_counter_current_value(counter0) );
145
 
146
    cyg_counter_set_value(counter0, 11);
147
    CHECK( 11 == cyg_counter_current_value(counter0) );
148
 
149
    /* the call_me functions cause the "called" bits to toggle
150
    // checking the value of called checks the parity of # of calls
151
    // made by each alarm.
152
    */
153
 
154
    cyg_alarm_create(counter0,
155
                     call_me,  (cyg_addrword_t)0x1, &alarm0, &alarmo[0]);
156
    cyg_alarm_create(counter0,
157
                     call_me,  (cyg_addrword_t)0x2, &alarm1, &alarmo[1]);
158
    cyg_alarm_create(counter0,
159
                     call_me2, (cyg_addrword_t)0x4, &alarm2, &alarmo[2]);
160
 
161
    CHECK( 0x00 == called );
162
    cyg_alarm_initialize(alarm0, 12,3);
163
    cyg_alarm_initialize(alarm2, 21,2);
164
    CHECK( 0x00 == called );
165
 
166
    cyg_counter_tick(counter0);         /* 12 a0 */
167
    CHECK( 0x01 == called );
168
 
169
    cyg_alarm_initialize(alarm1, 13,0);
170
    cyg_counter_tick(counter0);         /* 13 a1 */
171
    CHECK( 0x03 == called );
172
 
173
    cyg_alarm_initialize(alarm1, 17,0);
174
    cyg_counter_tick(counter0);         /* 14 */
175
    CHECK( 0x03 == called );
176
 
177
    cyg_counter_tick(counter0);         /* 15 a0 */
178
    CHECK( 0x02 == called );
179
 
180
    cyg_counter_tick(counter0);         /* 16 */
181
    cyg_counter_tick(counter0);         /* 17 a1 */
182
    CHECK( 0x00 == called );
183
 
184
    cyg_counter_tick(counter0);         /* 18 a0 */
185
    CHECK( 0x01 == called );
186
 
187
    cyg_counter_tick(counter0);         /* 19 */
188
    cyg_counter_tick(counter0);         /* 20 */
189
    cyg_counter_tick(counter0);         /* 21 a0 a2 */
190
    CHECK( 0x14 == called );
191
 
192
    cyg_counter_tick(counter0);         /* 22 */
193
    cyg_counter_tick(counter0);         /* 23 a2 */
194
    CHECK( 0x00 == called );
195
 
196
    cyg_alarm_disable(alarm2);
197
 
198
    cyg_counter_tick(counter0);         /* 24 a0 */
199
    cyg_counter_tick(counter0);         /* 25 */
200
    CHECK( 0x01 == called );
201
 
202
    cyg_alarm_enable(alarm2);           /* a2 (enabled at 25) */
203
    CHECK( 0x15 == called );
204
 
205
    cyg_counter_tick(counter0);         /* 26 */
206
    CHECK( 0x15 == called );
207
 
208
    cyg_counter_tick(counter0);         /* 27 a0 a2 */
209
    cyg_counter_tick(counter0);         /* 28 */
210
    CHECK( 0x00 == called );
211
 
212
    cyg_counter_tick(counter0);         /* 29 a2 */
213
    cyg_counter_tick(counter0);         /* 30 a0 */
214
    cyg_counter_tick(counter0);         /* 31 a2 */
215
    CHECK( 0x01 == called );
216
 
217
    res0.dividend = 100;
218
    res0.divisor   = 3;
219
 
220
    cyg_clock_create( res0, &clock0, &clock0o );
221
 
222
    res1 = cyg_clock_get_resolution(clock0);
223
    CHECK( res0.dividend == res1.dividend );
224
    CHECK( res0.divisor == res1.divisor );
225
 
226
    res1.dividend = 12;
227
    res1.divisor = 25;
228
 
229
    cyg_clock_set_resolution(clock0, res1);
230
    res0 = cyg_clock_get_resolution(clock0);
231
    CHECK( res0.dividend == res1.dividend );
232
    CHECK( res0.divisor == res1.divisor );
233
 
234
    cyg_clock_to_counter(clock0, &counter1);
235
 
236
    CHECK( 0 == cyg_counter_current_value( counter1 ) );
237
    CHECK( 0 == cyg_current_time() );
238
 
239
    cyg_counter_tick(counter1);
240
 
241
    CHECK( 1 == cyg_counter_current_value(counter1) );
242
 
243
    res0 = cyg_clock_get_resolution(cyg_real_time_clock());
244
 
245
    /* Current time should be 0 as interrupts will still be disabled */
246
    CHECK( 0 == cyg_current_time() );
247
 
248
    CYG_TEST_PASS_FINISH("Kernel C API Clock 0 OK");
249
}
250
 
251
externC void
252
cyg_start( void )
253
{
254
    kclock0_main();
255
}
256
 
257
#else // def CYGFUN_KERNEL_API_C
258
#define N_A_MSG "Kernel C API layer disabled"
259
#endif // def CYGFUN_KERNEL_API_C
260
#else // def CYGVAR_KERNEL_COUNTERS_CLOCK
261
#define N_A_MSG "Kernel real-time clock disabled"
262
#endif // def CYGVAR_KERNEL_COUNTERS_CLOCK
263
 
264
#ifdef N_A_MSG
265
externC void
266
cyg_start( void )
267
{
268
    CYG_TEST_INIT();
269
    CYG_TEST_NA( N_A_MSG );
270
}
271
#endif // N_A_MSG
272
 
273
// EOF kclock0.c

powered by: WebSVN 2.1.0

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