Thông tin tài liệu:
Real-Time Embedded Multithreading Using ThreadX and MIPS- P15:Although the history of embedded systems is relatively short, 1 the advances andsuccesses of this fi eld have been profound. Embedded systems are found in a vast array ofapplications such as consumer electronics, “ smart ” devices, communication equipment,automobiles, desktop computers, and medical equipment.
Nội dung trích xuất từ tài liệu:
Real-Time Embedded Multithreading Using ThreadX and MIPS- P15 Case Study: Designing a Multithreaded System 285 a. Get the mutex. b. Store the event time and priority in the next available position in protected memory. c. Store the 24 seconds of frame data from temporary memory to protected memory. d. Increment the event counter. e. Release the mutex. /************************************************************/ /**** Entry function definition of thread event_recorder ****/ /************************************************************/ void event_recorder_process(ULONG thread_input) { ULONG frame, event_priority, event_time, index, frame_data[2]; while (1) { /* Copy an event from temporary memory to protected memory. */ /* Get frame_index from event message queue and copy 24 frames */ /* from temp_memory to protected_memory. */ tx_queue_receive (&event_notice, frame_data, TX_NO_WAIT); /* Store event time and event priority in protected memory */ frame = frame_data[0]; event_priority = frame_data[1]; event_time = temp_memory[frame][0]; printf(**Event** Time: %5lu Count: %2lu Pri: %lu, event_time, event_count, event_priority); if (event_count < MAX_EVENTS) { tx_mutex_get (&memory_mutex, TX_WAIT_FOREVER); protected_memory[event_count][0] = event_time; protected_memory[event_count][1] = event_priority; if (frame < 11) frame = (MAX_TEMP_MEMORY-1) - (frame_index+1); for (index=0; index 286 Chapter 14 We will not implement the overwrite rules in the case when protected memory is full. These rules depend on the actual file system used, and are left as an exercise for the reader. When protected memory is full, we will display a message to that effect, but will not copy the event. Figure 14.29 contains the definition for the print_stats expiration function, which is part of the timer called stats_timer. This timer expires every 1,000 timer-ticks and the function displays a statistical summary of the system. We have now discussed most of the components of the VAM system. The next section contains a complete listing of the system, which also appears on the CD at the back of the book. /************************************************************/ /*********** print statistics at specified times ************/ /************************************************************/ void print_stats (ULONG invalue) { UINT row, col; printf(
**** VAM System Periodic Event Summary
); printf( Current Time: %lu
, tx_time_get()); printf( Number of Crashes: %lu
, num_crashes); printf( Number of Unsafe Events: %lu
, num_unsafe); printf( Number of Warnings: %lu
, num_warning); printf( Number of Manual Events: %lu
, num_manual); if (event_count > 0) { printf(
**** Portion of Protected Memory Contents
); printf(%6s%6s%6s
, Time, Pri, Data); for (row = 0; row < event_count; row++) { for (col = 0; col < 8; col++) printf(%6lu, protected_memory[row][col]); printf( (etc.)
); } } if (event_count >= MAX_EVENTS) printf( Warning: Protected Memory is full...
); } Figure 14.29: Function definitions Part 5—print_stats expiration function w ww. n e w n e s p r e s s .c o mPlease purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Case Study: Designing a Multithreaded System 287 14.6 Listing of VAM System 001 /* 14_case_study.c 002 003 Implement a simplified version of a real-time, video/audio/ motion (VAM) 004 recording system. 005 006 Create three threads named: initializer, data_capture, event_recorder 007 Create one byte pool for thread stacks and message queue: my_byte_pool 008 Create one mutex to guard protected memory: memory_mutex 009 Create one message queue to store event notices: event_notice 010 Create nine application timers named: crash_interrupt, unsafe_interrupt, 011 warning_interrupt, manual_interrupt, crash_copy_scheduler, 012 unsafe_copy_scheduler, manual_copy_sche ...