]> git.karo-electronics.de Git - karo-tx-redboot.git/blob - packages/hal/powerpc/viper/v2_0/tests/vipertime.cxx
Initial revision
[karo-tx-redboot.git] / packages / hal / powerpc / viper / v2_0 / tests / vipertime.cxx
1 /*=================================================================
2 //
3 //        vipertime.cxx
4 //
5 //        PowerPC VIPER HAL timing tests
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):     hmt
44 // Contributors:  hmt
45 // Date:          1999-06-01
46 //####DESCRIPTIONEND####
47 */
48
49 #include <pkgconf/system.h>
50 #include <pkgconf/hal.h>
51
52 #include <cyg/infra/cyg_type.h>
53 #include <cyg/infra/cyg_ass.h>
54 #include <cyg/infra/testcase.h>
55
56 #ifdef CYGPKG_KERNEL
57
58 #include <pkgconf/kernel.h>
59
60 #ifdef CYGVAR_KERNEL_COUNTERS_CLOCK
61
62 #include <cyg/hal/hal_arch.h>
63 #include <cyg/hal/hal_intr.h>
64 #include <cyg/hal/hal_diag.h>
65
66 #include <pkgconf/infra.h>
67
68 #include <cyg/infra/diag.h>
69
70 #include <cyg/kernel/thread.hxx>
71 #include <cyg/kernel/thread.inl>
72 #include <cyg/kernel/sched.hxx>
73 #include <cyg/kernel/sched.inl>
74
75 // ------------------------------------------------------------------------
76
77 externC void hal_viper_flash_led( int count );
78 externC void hal_viper_set_led( int val );
79
80 // -------------------------------------------------------------------------
81
82 static void entry1( CYG_ADDRWORD arg )
83 {
84     int i;
85     char *s = "tick 00";
86     extern Cyg_Thread thread2;
87     CYG_TEST_INFO( "Starting measured seconds..." );
88     for ( i = 0; i < 20 ; i++ ) {
89         Cyg_Thread::self()->delay( 100 ); // units should be centiSeconds
90
91         hal_viper_set_led( ((~i) & 7)<<1 );
92
93         if ( '9' == s[ 6 ]++ ) {
94             s[ 6 ] = '0';
95             s[ 5 ] ++;
96         }
97         CYG_TEST_INFO( s );
98     }
99
100     CYG_TEST_PASS( "Done measured seconds..." );
101
102     hal_viper_flash_led( 5 );
103
104     thread2.resume();
105 }
106
107 //---------------------------------------------------------------
108
109 #define LOOPS 30
110
111 int loops[ LOOPS ] = { 0,0,0,0,0 , 0,0,0,0,0 ,
112                        0,0,0,0,0 , 0,0,0,0,0 ,
113                        0,0,0,0,0 , 0,0,0,0,0 };
114
115 char s[] = "0 count 00 loops 00000";
116
117 static void entry2( CYG_ADDRWORD arg )
118 {
119 #if 0 // Do not bother with this on PPC
120     int i, t1, t2, a;
121     for ( a = 0; a < 10; a++, (*s)++ ) {
122         CYG_TEST_INFO( "------------------------------------------" );
123         HAL_CLOCK_READ( &t1 );
124         do {
125             t2 = t1;
126             HAL_CLOCK_READ( &t1 );
127         } while ( t1 >= t2 );
128
129         for ( i = 0; i < LOOPS; i++ ) {
130             register int z = 0;
131             while ( t1 <= i ) {
132                 z++;
133                 HAL_CLOCK_READ( &t1 );
134             }
135             loops[ i ] = z;
136         }
137
138         s[9] = '0';
139         s[8] = '0';
140         for ( i = 0; i < LOOPS; i++ ) {
141             s[ sizeof( s ) - 2 ] = '0' + loops[ i ] / 1       % 10;
142             s[ sizeof( s ) - 3 ] = '0' + loops[ i ] / 10      % 10;
143             s[ sizeof( s ) - 4 ] = '0' + loops[ i ] / 100     % 10;
144             s[ sizeof( s ) - 5 ] = '0' + loops[ i ] / 1000    % 10;
145             s[ sizeof( s ) - 6 ] = '0' + loops[ i ] / 10000   % 10;
146             CYG_TEST_INFO( s );
147             if ( '9' == s[9]++ ) {
148                 s[9] = '0';
149                 s[8]++;
150             }        
151         }
152     }
153 #endif
154     CYG_TEST_PASS( "Counted loops per timer tick" );
155     CYG_TEST_EXIT( "All done" );
156 }
157
158 // -------------------------------------------------------------------------
159
160 static char stack1[ CYGNUM_HAL_STACK_SIZE_TYPICAL ];
161 static char stack2[ CYGNUM_HAL_STACK_SIZE_TYPICAL ];
162
163 static Cyg_Thread thread1     CYG_INIT_PRIORITY( APPLICATION )
164  = Cyg_Thread( 2u, entry1, 0u, "timed minute thread",
165                (CYG_ADDRWORD)stack1,
166                (CYG_ADDRWORD)CYGNUM_HAL_STACK_SIZE_TYPICAL );
167
168 static Cyg_Thread thread2     CYG_INIT_PRIORITY( APPLICATION )
169  = Cyg_Thread( 4u, entry2, 0u, "uS clock loops timing thread",
170                (CYG_ADDRWORD)stack2,
171                (CYG_ADDRWORD)CYGNUM_HAL_STACK_SIZE_TYPICAL );
172
173 // -------------------------------------------------------------------------
174
175 #ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
176 externC void
177 cyg_hal_invoke_constructors();
178 #endif
179
180 externC void
181 cyg_user_start( void )
182 {
183 #ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
184     cyg_hal_invoke_constructors();
185 #endif
186     CYG_TEST_INIT();
187     CYG_TEST_INFO( "cyg_user_start()" );
188     thread1.resume();
189 }
190
191 // -------------------------------------------------------------------------
192
193 #else  // ! CYGVAR_KERNEL_COUNTERS_CLOCK
194 #define N_A_MSG "no kernel clock"
195 #endif // CYGVAR_KERNEL_COUNTERS_CLOCK
196 #else  // ! CYGPKG_KERNEL
197 #define N_A_MSG "no kernel"
198 #endif // CYGPKG_KERNEL
199
200 #ifdef N_A_MSG
201 externC void
202 cyg_start( void )
203 {
204     CYG_TEST_INIT();
205     CYG_TEST_NA( N_A_MSG );
206 }
207 #endif // N_A_MSG defined ie. we are N/A.
208
209 /* EOF vipertime.cxx */