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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [kernel/] [v2_0/] [tests/] [kclock0.c] - Blame information for rev 27

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

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

powered by: WebSVN 2.1.0

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