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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [kernel/] [current/] [tests/] [thread1.cxx] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//        thread1.cxx
4
//
5
//        Thread test 1
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 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):     dsm
43
// Contributors:    dsm
44
// Date:          1998-02-11
45
// Description:   Tests some basic thread functions.
46
// Omissions:     Cyg_ThreadTimer
47
//                Cyg_Thread
48
//                  exit -- not necessarily called
49
//                  yield
50
//                  set_priority
51
//                  get_priority
52
//                  get/set_sleep_reason
53
//                  get/set_wake_reason
54
//                  set/clear_timer
55
//                Cyg_ThreadQueue
56
//               
57
//####DESCRIPTIONEND####
58
 
59
#include <pkgconf/kernel.h>
60
 
61
#include <cyg/kernel/sched.hxx>
62
#include <cyg/kernel/thread.hxx>
63
 
64
#include <cyg/infra/testcase.h>
65
 
66
#ifdef CYGFUN_KERNEL_THREADS_TIMER
67
 
68
#include <cyg/kernel/sched.inl>
69
#include <cyg/kernel/thread.inl>
70
 
71
#include "testaux.hxx"
72
 
73
#ifdef CYGNUM_HAL_STACK_SIZE_TYPICAL
74
#define STACKSIZE CYGNUM_HAL_STACK_SIZE_TYPICAL
75
#else
76
#define STACKSIZE 2000
77
#endif
78
 
79
static char stack[2][STACKSIZE];
80
 
81
static char thread[2][sizeof(Cyg_Thread)];
82
 
83
static Cyg_Thread *pt0,*pt1;
84
static cyg_uint16 uid0,uid1;
85
 
86
 
87
static void entry0( CYG_ADDRWORD data )
88
{
89
    CHECK( 222 == data );
90
 
91
    uid0 = pt0->get_unique_id();
92
 
93
    pt1->suspend();
94
    pt1->resume();
95
 
96
    do {
97
        pt0->delay(1);
98
    } while( Cyg_Thread::RUNNING == pt1->get_state() );
99
 
100
    CHECK( Cyg_Thread::SLEEPING == pt1->get_state() );
101
 
102
    pt1->wake();
103
 
104
    CHECK( uid0 != uid1 );
105
 
106
    CYG_TEST_PASS_FINISH("Thread 1 OK");
107
}
108
 
109
static void entry1( CYG_ADDRWORD data )
110
{
111
    CHECK( 333 == data );
112
 
113
    uid1 = pt1->get_unique_id();
114
 
115
    Cyg_Thread *self = Cyg_Thread::self();
116
 
117
    CHECK( self == pt1 );
118
 
119
    pt1->sleep();
120
    pt1->suspend();
121
 
122
    Cyg_Thread::exit();         // no guarantee this will be called
123
}
124
 
125
void thread1_main( void )
126
{
127
    CYG_TEST_INIT();
128
 
129
    pt0 = new((void *)&thread[0])
130
            Cyg_Thread(CYG_SCHED_DEFAULT_INFO,
131
                       entry0, 222,
132
                       "thread 0",
133
                       (CYG_ADDRESS)stack[0], STACKSIZE );
134
    pt1 = new((void *)&thread[1])
135
            Cyg_Thread(CYG_SCHED_DEFAULT_INFO,
136
                       entry1, 333,
137
                       "thread 1",
138
                       (CYG_ADDRESS)stack[1], STACKSIZE );
139
 
140
    CYG_ASSERTCLASS( pt0, "error" );
141
    CYG_ASSERTCLASS( pt1, "error" );
142
 
143
    pt0->resume();
144
    pt1->resume();
145
 
146
    Cyg_Scheduler::start();
147
 
148
    CYG_TEST_FAIL_FINISH("Not reached");
149
}
150
 
151
externC void
152
cyg_start( void )
153
{
154
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
155
    cyg_hal_invoke_constructors();
156
#endif
157
    thread1_main();
158
}
159
 
160
#else // ifdef CYGFUN_KERNEL_THREADS_TIMER
161
 
162
externC void
163
cyg_start( void )
164
{
165
    CYG_TEST_INIT();
166
    CYG_TEST_NA("Kernel threads timer disabled");
167
}
168
 
169
#endif // ifdef CYGFUN_KERNEL_THREADS_TIMER
170
 
171
// EOF thread1.cxx

powered by: WebSVN 2.1.0

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