1 /* =================================================================
5 * Sample library to test the object loader
7 * =================================================================
8 * ####ECOSGPLCOPYRIGHTBEGIN####
9 * -------------------------------------------
10 * This file is part of eCos, the Embedded Configurable Operating
12 * Copyright (C) 2005 eCosCentric Ltd.
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)
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.
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.
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.
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
40 * -------------------------------------------
41 * ####ECOSGPLCOPYRIGHTEND####
42 * =================================================================
43 * #####DESCRIPTIONBEGIN####
45 * Author(s): Anthony Tonizzo (atonizzo@gmail.com)
50 * ####DESCRIPTIONEND####
52 * =================================================================
55 #include <cyg/kernel/kapi.h> // Kernel API.
56 #include <cyg/infra/diag.h> // For diagnostic printing.
57 #include <cyg/infra/testcase.h>
59 cyg_sem_t sem_signal_thread;
62 extern int weak_fn_called;
64 void weak_function(void) CYGBLD_ATTRIB_WEAK;
65 void weak_function(void)
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");
72 void library_open(void)
74 // Initialize the count for thread a.
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");
83 void library_close(void)
85 CYG_TEST_INFO("Library closed");
88 void print_message(void)
90 diag_printf("INFO:<Printing a silly message...>\n");
93 // Thread A - signals thread B via semaphore.
94 void thread_a(cyg_addrword_t data)
96 // Store the data value passed in for this thread.
101 while(thread_a_count < 5)
103 // Increment the thread a count.
107 // Send out a message to the diagnostic port.
108 diag_printf("INFO:<Thread A, count: %d message: %d>\n", thread_a_count, msg);
110 // Delay for 1 second.
111 cyg_thread_delay(100);
113 // Signal thread B using the semaphore.
114 cyg_semaphore_post(&sem_signal_thread);
117 CYG_TEST_CHECK(weak_fn_called == 2 , "Application week function not called");
118 CYG_TEST_FINISH("Object loader test finished");
121 // Thread B - waits for semaphore signal from thread A.
122 void thread_b(cyg_addrword_t data)
124 // Store the data value passed in for this thread.
130 // Signal thread B using the semaphore.
131 cyg_semaphore_wait(&sem_signal_thread);
133 // Send out a message to the diagnostic port.
134 diag_printf("INFO:< Thread B, message: %d>\n", msg);