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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [kernel/] [current/] [tests/] [kalarm0.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
//        kalarm0
4
//
5
//        Alarm functionality test
6
//
7
//==========================================================================
8
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
9
// -------------------------------------------                              
10
// This file is part of eCos, the Embedded Configurable Operating System.   
11
// Copyright (C) 2003 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):     nickg
43
// Contributors:  nickg
44
// Date:          2003-06-25
45
// Description:   Tests the ability of alarms to be added and removed by the
46
//                alarm functions of other alarms.
47
//
48
//####DESCRIPTIONEND####
49
//==========================================================================
50
 
51
#include <cyg/kernel/kapi.h>
52
 
53
#include <cyg/infra/testcase.h>
54
 
55
//==========================================================================
56
 
57
#if defined(CYGVAR_KERNEL_COUNTERS_CLOCK) && \
58
    defined(CYGFUN_KERNEL_API_C)
59
 
60
#include "testaux.h"
61
 
62
//==========================================================================
63
 
64
//#define db_printf diag_printf
65
#define db_printf( fmt, ... )
66
 
67
//==========================================================================
68
 
69
static cyg_counter counter_obj;
70
static cyg_handle_t counter;
71
static cyg_alarm alarm_obj[3];
72
static cyg_handle_t alarm[3];
73
 
74
static cyg_uint32 alarmfn_called[3];
75
 
76
//==========================================================================
77
 
78
void alarmfn0(cyg_handle_t alarmh, cyg_addrword_t data)
79
{
80
    db_printf("%s: %d\n",__PRETTY_FUNCTION__,cyg_counter_current_value( counter ));
81
 
82
    // alarmfn0 just counts how many times it has been called
83
 
84
    alarmfn_called[0]++;
85
}
86
 
87
//==========================================================================
88
 
89
void alarmfn1(cyg_handle_t alarmh, cyg_addrword_t data)
90
{
91
    db_printf("%s: %d\n",__PRETTY_FUNCTION__,cyg_counter_current_value( counter ));
92
 
93
    alarmfn_called[1]++;
94
 
95
    // Reschedule alarm[0] to run every tick until alarm[2] next runs.
96
 
97
    cyg_alarm_initialize( alarm[0], cyg_counter_current_value( counter )+1, 1 );
98
 
99
}
100
 
101
//==========================================================================
102
 
103
void alarmfn2(cyg_handle_t alarmh, cyg_addrword_t data)
104
{
105
    db_printf("%s: %d\n",__PRETTY_FUNCTION__,cyg_counter_current_value( counter ));
106
 
107
    alarmfn_called[2]++;
108
 
109
    // Reschedule alarm[0] to run every 2 ticks until alarm[1] next runs.
110
 
111
    cyg_alarm_initialize( alarm[0], cyg_counter_current_value( counter )+1, 2 );
112
 
113
    // Reschedule alarm[1] to run every 3 ticks starting in 6 ticks time.
114
 
115
    cyg_alarm_initialize( alarm[1], cyg_counter_current_value( counter )+6, 3 );
116
}
117
 
118
//==========================================================================
119
 
120
void alarm0_main(void)
121
{
122
    int i;
123
 
124
    CYG_TEST_INIT();
125
 
126
    // Create the counter
127
    cyg_counter_create( &counter, &counter_obj );
128
 
129
    // Create the alarms
130
    cyg_alarm_create( counter,
131
                      alarmfn0,
132
                      0,
133
                      &alarm[0],
134
                      &alarm_obj[0]);
135
 
136
 
137
    cyg_alarm_create( counter,
138
                      alarmfn1,
139
                      1,
140
                      &alarm[1],
141
                      &alarm_obj[1]);
142
 
143
    cyg_alarm_create( counter,
144
                      alarmfn2,
145
                      2,
146
                      &alarm[2],
147
                      &alarm_obj[2]);
148
 
149
 
150
    // Kick it all off by starting alarm[2]
151
    cyg_alarm_initialize( alarm[2], 0, 10 );
152
 
153
    // Run the whole thing for 10000 ticks
154
    for( i = 0; i < 10000; i++ )
155
        cyg_counter_tick( counter );
156
 
157
    db_printf("alarmfn_called: %d %d %d\n",
158
                alarmfn_called[0],alarmfn_called[1],alarmfn_called[2]);
159
 
160
    CYG_TEST_CHECK( alarmfn_called[0]==5000, "alarmfn0 not called 5000 times\n");
161
    CYG_TEST_CHECK( alarmfn_called[1]==2000, "alarmfn1 not called 2000 times\n");
162
    CYG_TEST_CHECK( alarmfn_called[2]==1001, "alarmfn2 not called 1001 times\n");
163
 
164
    CYG_TEST_PASS_FINISH("KAlarm0");
165
}
166
 
167
//==========================================================================
168
 
169
externC void
170
cyg_start( void )
171
{
172
    alarm0_main();
173
}
174
 
175
//==========================================================================
176
 
177
#else
178
 
179
externC void
180
cyg_start( void )
181
{
182
    CYG_TEST_INIT();
183
    CYG_TEST_NA( "This test needs CYGVAR_KERNEL_COUNTERS_CLOCK "
184
                 "and CYGFUN_KERNEL_API_C" );
185
}
186
 
187
#endif
188
 
189
//==========================================================================
190
// End of kalarm0.c

powered by: WebSVN 2.1.0

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