/////////////////////////////////////////////////////////////////////////////// // // Filename: basic1.c // // Description: Basic example application from Chapter 12: An Example // Application Using eCos. This program creates two // threads and uses a semaphore to signal from one thread // to the other. // // Embedded Software Development With eCos // by Anthony J. Massa // // Copyright (c) 2002, 2003 by Anthony J. Massa. // This software is placed into the public domain // and may be used for any purpose. No warranty is // either expressed or implied by its // publication or distribution. // //////////////////////////////////////////////////////////////////////////////// #include // Kernel API. #include // For diagnostic printing. #define THREAD_STACK_SIZE ( 8192 / sizeof(int) ) #define THREAD_PRIORITY 12 // // Declare the thread variables. // /* int thread_a_stack[ THREAD_STACK_SIZE ]; int thread_b_stack[ THREAD_STACK_SIZE ]; cyg_thread thread_a_obj; cyg_thread thread_b_obj; cyg_handle_t thread_a_hdl; cyg_handle_t thread_b_hdl; cyg_sem_t sem_signal_thread; int thread_a_count; // // Thread A - signals thread B via semaphore. // void thread_a( cyg_addrword_t data ) { // Store the data value passed in for this thread. int msg = (int)data; while( 1 ) { // Increment the thread a count. thread_a_count++; // Send out a message to the diagnostic port. diag_printf( "Thread A, count: %d message: %d\n", thread_a_count, msg ); // Delay for 1 second. cyg_thread_delay( 100 ); // Signal thread B using the semaphore. cyg_semaphore_post( &sem_signal_thread ); } } // // Thread B - waits for semaphore signal from thread A. // void thread_b( cyg_addrword_t data ) { // Store the data value passed in for this thread. int msg = (int)data; while( 1 ) { // Signal thread B using the semaphore. cyg_semaphore_wait( &sem_signal_thread ); // Send out a message to the diagnostic port. diag_printf( "Thread B, message: %d\n", msg ); } } */ // // This is the main starting point for our // example application. // void cyg_user_start( void ) { // Initialize the count for thread a. //thread_a_count = 0; // It wouldn't be much of a basic example if some // kind of hello message wasn't output. diag_printf( "Hello eCos World!!!\n\n" ); printf( "Hello eCos World!!!\n\n" ); /* // Initialize the semaphore with a count of zero, // prior to creating the threads. cyg_semaphore_init( &sem_signal_thread, 0 ); // // Create our two threads. // cyg_thread_create( THREAD_PRIORITY, thread_a, (cyg_addrword_t) 75, "Thread A", (void *)thread_a_stack, THREAD_STACK_SIZE, &thread_a_hdl, &thread_a_obj ); cyg_thread_create( THREAD_PRIORITY, thread_b, (cyg_addrword_t) 68, "Thread B", (void *)thread_b_stack, THREAD_STACK_SIZE, &thread_b_hdl, &thread_b_obj ); // Resume the threads so they start when the scheduler // begins. cyg_thread_resume( thread_a_hdl ); cyg_thread_resume( thread_b_hdl ); */ }