1 /*=================================================================
5 // PowerPC VIPER HAL timing tests
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.
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.
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
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.
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.
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.
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####
46 //####DESCRIPTIONEND####
49 #include <pkgconf/system.h>
50 #include <pkgconf/hal.h>
52 #include <cyg/infra/cyg_type.h>
53 #include <cyg/infra/cyg_ass.h>
54 #include <cyg/infra/testcase.h>
58 #include <pkgconf/kernel.h>
60 #ifdef CYGVAR_KERNEL_COUNTERS_CLOCK
62 #include <cyg/hal/hal_arch.h>
63 #include <cyg/hal/hal_intr.h>
64 #include <cyg/hal/hal_diag.h>
66 #include <pkgconf/infra.h>
68 #include <cyg/infra/diag.h>
70 #include <cyg/kernel/thread.hxx>
71 #include <cyg/kernel/thread.inl>
72 #include <cyg/kernel/sched.hxx>
73 #include <cyg/kernel/sched.inl>
75 // ------------------------------------------------------------------------
77 externC void hal_viper_flash_led( int count );
78 externC void hal_viper_set_led( int val );
80 // -------------------------------------------------------------------------
82 static void entry1( CYG_ADDRWORD arg )
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
91 hal_viper_set_led( ((~i) & 7)<<1 );
93 if ( '9' == s[ 6 ]++ ) {
100 CYG_TEST_PASS( "Done measured seconds..." );
102 hal_viper_flash_led( 5 );
107 //---------------------------------------------------------------
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 };
115 char s[] = "0 count 00 loops 00000";
117 static void entry2( CYG_ADDRWORD arg )
119 #if 0 // Do not bother with this on PPC
121 for ( a = 0; a < 10; a++, (*s)++ ) {
122 CYG_TEST_INFO( "------------------------------------------" );
123 HAL_CLOCK_READ( &t1 );
126 HAL_CLOCK_READ( &t1 );
127 } while ( t1 >= t2 );
129 for ( i = 0; i < LOOPS; i++ ) {
133 HAL_CLOCK_READ( &t1 );
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;
147 if ( '9' == s[9]++ ) {
154 CYG_TEST_PASS( "Counted loops per timer tick" );
155 CYG_TEST_EXIT( "All done" );
158 // -------------------------------------------------------------------------
160 static char stack1[ CYGNUM_HAL_STACK_SIZE_TYPICAL ];
161 static char stack2[ CYGNUM_HAL_STACK_SIZE_TYPICAL ];
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 );
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 );
173 // -------------------------------------------------------------------------
175 #ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
177 cyg_hal_invoke_constructors();
181 cyg_user_start( void )
183 #ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
184 cyg_hal_invoke_constructors();
187 CYG_TEST_INFO( "cyg_user_start()" );
191 // -------------------------------------------------------------------------
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
205 CYG_TEST_NA( N_A_MSG );
207 #endif // N_A_MSG defined ie. we are N/A.
209 /* EOF vipertime.cxx */