]> git.karo-electronics.de Git - karo-tx-redboot.git/blob - packages/services/objloader/v2_0/tests/library/hello.c
8c96122e860f323d29d7d05afb95500ed2a9d155
[karo-tx-redboot.git] / packages / services / objloader / v2_0 / tests / library / hello.c
1 /* =================================================================
2  *
3  *      hello.c
4  *
5  *      Sample library to test the object loader
6  *
7  * ================================================================= 
8  * ####ECOSGPLCOPYRIGHTBEGIN####
9  * -------------------------------------------
10  * This file is part of eCos, the Embedded Configurable Operating
11  * System.
12  * Copyright (C) 2005 eCosCentric Ltd.
13  * 
14  * eCos is free software; you can redistribute it and/or modify it
15  * under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 2 or (at your option)
17  * any later version.
18  * 
19  * eCos is distributed in the hope that it will be useful, but
20  * WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22  * General Public License for more details.
23  * 
24  * You should have received a copy of the GNU General Public License
25  * along with eCos; if not, write to the Free Software Foundation,
26  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
27  * 
28  * As a special exception, if other files instantiate templates or
29  * use macros or inline functions from this file, or you compile this
30  * file and link it with other works to produce a work based on this
31  * file, this file does not by itself cause the resulting work to be
32  * covered by the GNU General Public License. However the source code
33  * for this file must still be made available in accordance with
34  * section (3) of the GNU General Public License.
35  * 
36  * This exception does not invalidate any other reasons why a work
37  * based on this file might be covered by the GNU General Public
38  * License.
39  *
40  * -------------------------------------------
41  * ####ECOSGPLCOPYRIGHTEND####
42  * =================================================================
43  * #####DESCRIPTIONBEGIN####
44  * 
45  *  Author(s):    atonizzo@lycos.com
46  *  Date:         2005-05-13
47  *  Purpose:      
48  *  Description:  
49  *               
50  * ####DESCRIPTIONEND####
51  * 
52  * =================================================================
53  */
54
55 #include <cyg/kernel/kapi.h>    // Kernel API.
56 #include <cyg/infra/diag.h>     // For diagnostic printing.
57 #include <cyg/infra/testcase.h>
58
59 cyg_sem_t sem_signal_thread;
60 int thread_a_count;
61
62 extern int weak_fn_called;
63
64 void weak_function( void ) CYGBLD_ATTRIB_WEAK;
65 void weak_function( void )
66 {
67     // Store the data value passed in for this thread.
68     diag_printf( "INFO:< This is the library weak function>" );
69     CYG_TEST_FAIL ( "Libraries weak function called when apps should be called" );
70 }
71
72 void library_open( void )
73 {
74     // Initialize the count for thread a.
75     thread_a_count = 0;
76
77     // Initialize the semaphore with a count of zero,
78     // prior to creating the threads.
79     cyg_semaphore_init( &sem_signal_thread, 0 );
80     CYG_TEST_INFO( "Library initialized" );
81 }
82
83 void library_close( void )
84 {
85     CYG_TEST_INFO( "Library closed" );
86 }
87
88 void print_message( void )
89 {
90     diag_printf( "INFO:<Printing a silly message...>\n" );
91 }
92
93 // Thread A - signals thread B via semaphore.
94 void thread_a( cyg_addrword_t data )
95 {
96     // Store the data value passed in for this thread.
97     int msg = (int)data;
98
99     weak_function ();
100     
101     while( thread_a_count < 5 )
102     {
103         // Increment the thread a count.
104         thread_a_count++;
105
106
107         // Send out a message to the diagnostic port.
108         diag_printf( "INFO:<Thread A, count: %d  message: %d>\n", thread_a_count, msg );
109
110         // Delay for 1 second.
111         cyg_thread_delay( 100 );
112
113         // Signal thread B using the semaphore.
114         cyg_semaphore_post( &sem_signal_thread );
115     }
116     
117     CYG_TEST_CHECK( weak_fn_called == 2 , "Application week function not called" );
118     CYG_TEST_FINISH( "Object loader test finished" );
119 }
120
121 // Thread B - waits for semaphore signal from thread A.
122 void thread_b( cyg_addrword_t data )
123 {
124     // Store the data value passed in for this thread.
125     int msg = (int)data;
126
127     while( 1 )
128     {
129
130         // Signal thread B using the semaphore.
131         cyg_semaphore_wait( &sem_signal_thread );
132
133         // Send out a message to the diagnostic port.
134         diag_printf( "INFO:< Thread B, message: %d>\n", msg );
135     }
136 }