Thông tin tài liệu:
Real-Time Embedded Multithreading Using ThreadX and MIPS- P2: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- P2 16 Chapter 2 042 043 /* Enter the ThreadX kernel. */ 044 tx_kernel_enter(); 045 } 046 047 048 049 /****************************************************/ 050 /* Application Definitions */ 051 /****************************************************/ 052 053 054 /* Define what the initial system looks like. */ 055 056 void tx_application_define(void *first_unused_memory) 057 { 058 059 CHAR *pool_pointer; 060 061 062 /* Create a byte memory pool from which to allocate 063 the thread stacks. */ 064 tx_byte_pool_create(&my_byte_pool, “my_byte_pool”, 065 first_unused_memory, 066 DEMO_BYTE_POOL_SIZE); 067 068 /* Put system definition stuff in here, e.g., thread 069 creates and other assorted create information. */ 070 071 /* Allocate the stack for the Speedy_Thread. */ 072 tx_byte_allocate(&my_byte_pool, (VOID **) &pool_pointer, 073 DEMO_STACK_SIZE, TX_NO_WAIT); 074 075 /* Create the Speedy_Thread. */ 076 tx_thread_create(&Speedy_Thread, “Speedy_Thread”, 077 Speedy_Thread_entry, 0, 078 pool_pointer, DEMO_STACK_SIZE, 5, 5, 079 TX_NO_TIME_SLICE, TX_AUTO_START); 080 081 /* Allocate the stack for the Slow_Thread. */ 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. First Look at a System Using an RTOS 17 082 tx_byte_allocate(&my_byte_pool, (VOID **) &pool_pointer, 083 DEMO_STACK_SIZE, TX_NO_WAIT); 084 085 /* Create the Slow_Thread. */ 086 tx_thread_create(&Slow_Thread, “Slow_Thread”, 087 Slow_Thread_entry, 1, pool_pointer, 088 DEMO_STACK_SIZE, 15, 15, 089 TX_NO_TIME_SLICE, TX_AUTO_START); 090 091 /* Create the mutex used by both threads */ 092 tx_mutex_create(&my_mutex, “my_mutex”, TX_NO_INHERIT); 093 094 095 } 096 097 098 /****************************************************/ 099 /* Function Definitions */ 100 /****************************************************/ 101 102 103 /* Entry function definition of the “Speedy_Thread” 104 it has a higher priority than the “Slow_Thread” */ 105 106 void Speedy_Thread_entry(ULONG thread_input) 107 { 108 109 ULONG current_time; 110 111 while (1) 112 { 113 /* Activity 1: 2 timer-ticks */ 114 tx_thread_sleep(2); 115 116 /* Get the mutex with suspension */ 117 tx_mutex_get(&my_mutex, TX_WAIT_FOREVER); 118 119 /* Activity 2: 5 timer-ticks *** critical section *** */ 120 tx_thread_sleep(5); 121 w w w.ne w nespress.comPlease purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 18 Chapter 2 122 /* Release the mutex */ 123 tx_mutex_put(&my_mutex); 124 125 /* Activity 3: 4 timer-ticks */ 126 tx_thread_sleep(4); 127 128 /* Get the mutex with suspension */ 129 tx_mutex_get(&my_mutex, TX_WAIT_FOREVER); 130 131 /* Activity 4: 3 timer-ticks *** critical section *** */ 132 tx_thread_sleep(3); 133 134 /* Release the mutex */ 135 tx_mutex_put(&my_mutex); 136 137 current_time tx_time_get(); 138 printf(“Current Time: %5lu Speedy_Thread finished a cycle…
”, 139 current_time); 140 141 } 142 } 143 144 /****************************************************/ 145 146 /* Entry function definition of the “Slow_Thread” 147 it has a lower priority than the “Speedy_Thread” */ 148 149 void Slow_Thread_entry(ULONG thread_input) 150 { 151 152 153 ULONG current_time; 154 155 while(1) 156 { 157 /* Activity 5 - 12 timer-ticks *** critical section *** */ 158 159 /* Get the mutex with suspension */ 160 tx_mutex_get(&my_mutex, TX_WAIT_FOREVER); 161 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. First Look at a System Using an RTOS 19 162 ...