comparison packages/hal/common/current/tests/context.c @ 0:3111d98ba7b3 ecos-v1_1-release

Initial commit of eCos version 1.1
author jlarmour
date Tue, 11 May 1999 11:16:07 +0000
parents
children 443894e2e912
comparison
equal deleted inserted replaced
-1:000000000000 0:3111d98ba7b3
1 /*=================================================================
2 //
3 // context.c
4 //
5 // HAL Thread context handling test
6 //
7 //==========================================================================
8 //####COPYRIGHTBEGIN####
9 //
10 // -------------------------------------------
11 // The contents of this file are subject to the Cygnus eCos Public License
12 // Version 1.0 (the "License"); you may not use this file except in
13 // compliance with the License. You may obtain a copy of the License at
14 // http://sourceware.cygnus.com/ecos
15 //
16 // Software distributed under the License is distributed on an "AS IS"
17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
18 // License for the specific language governing rights and limitations under
19 // the License.
20 //
21 // The Original Code is eCos - Embedded Cygnus Operating System, released
22 // September 30, 1998.
23 //
24 // The Initial Developer of the Original Code is Cygnus. Portions created
25 // by Cygnus are Copyright (C) 1998 Cygnus Solutions. All Rights Reserved.
26 // -------------------------------------------
27 //
28 //####COPYRIGHTEND####
29 //==========================================================================
30 //#####DESCRIPTIONBEGIN####
31 //
32 // Author(s): nickg
33 // Contributors: nickg
34 // Date: 1998-10-07
35 //####DESCRIPTIONEND####
36 */
37
38 #include <pkgconf/hal.h>
39
40 #include <pkgconf/infra.h>
41
42 #include <cyg/infra/testcase.h>
43
44 #include <cyg/infra/cyg_trac.h>
45 #include <cyg/hal/hal_arch.h>
46
47 #define CYG_TRACE_USER_BOOL 1
48
49 // -------------------------------------------------------------------------
50
51 #define THREADS 4
52 #define STACKSIZE (2*1024)
53
54 char stack[THREADS][STACKSIZE];
55
56 CYG_ADDRWORD sp[THREADS];
57
58 cyg_count32 switches = 0;
59
60 // -------------------------------------------------------------------------
61
62 void entry0( CYG_ADDRWORD arg )
63 {
64 CYG_TRACE1B("Thread %d started\n", arg );
65
66 while( switches < 1000 )
67 {
68 HAL_THREAD_SWITCH_CONTEXT( &sp[arg], &sp[(arg+1) % THREADS] );
69
70 CYG_TRACE1B("Thread %d resumed\n", arg );
71
72 switches++;
73 }
74
75 CYG_TEST_PASS_FINISH("HAL Context test");
76
77 }
78
79 // -------------------------------------------------------------------------
80
81 void context_main(void)
82 {
83 int i;
84
85 CYG_TEST_INIT();
86
87 // Init all thread contexts:
88
89 for( i = 0 ; i < THREADS; i++ )
90 {
91 sp[i] = (CYG_ADDRWORD)stack[i]+STACKSIZE;
92
93 HAL_THREAD_INIT_CONTEXT( sp[i], i, entry0, i*0x01010000 );
94 }
95
96 // Load the first thread.
97
98 HAL_THREAD_LOAD_CONTEXT( &sp[0] );
99 }
100
101 // -------------------------------------------------------------------------
102
103 externC void
104 cyg_start( void )
105 {
106 context_main();
107 }
108
109 // -------------------------------------------------------------------------
110 /* EOF context.c */