Real-Time Embedded Multithreading Using ThreadX and MIPS- P15

Chia sẻ: Cong Thanh | Ngày: | Loại File: PDF | Số trang:20

0
44
lượt xem
6
download

Real-Time Embedded Multithreading Using ThreadX and MIPS- P15

Mô tả tài liệu
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

Real-Time Embedded Multithreading Using ThreadX and MIPS- P15:Although the history of embedded systems is relatively short, 1 the advances and successes of this fi eld have been profound. Embedded systems are found in a vast array of applications such as consumer electronics, “ smart ” devices, communication equipment, automobiles, desktop computers, and medical equipment.

Chủ đề:
Lưu

Nội dung Text: Real-Time Embedded Multithreading Using ThreadX and MIPS- P15

  1. 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
  2. 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("\n\n**** VAM System Periodic Event Summary\n\n"); printf(" Current Time: %lu\n", tx_time_get()); printf(" Number of Crashes: %lu\n", num_crashes); printf(" Number of Unsafe Events: %lu\n", num_unsafe); printf(" Number of Warnings: %lu\n", num_warning); printf(" Number of Manual Events: %lu\n", num_manual); if (event_count > 0) { printf("\n\n**** Portion of Protected Memory Contents\n\n"); printf("%6s%6s%6s\n", "Time", "Pri", "Data"); for (row = 0; row < event_count; row++) { for (col = 0; col < 8; col++) printf("%6lu", protected_memory[row][col]); printf(" (etc.)\n"); } } if (event_count >= MAX_EVENTS) printf(" Warning: Protected Memory is full...\n\n"); } 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 m Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  3. 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_scheduler, stats_timer 013 014 For this system, assume that each timer-tick represents one second */ 015 016 /****************************************************/ 017 /* Declarations, Definitions, and Prototypes */ 018 /****************************************************/ 019 020 #include “tx_api.h” 021 #include stdio.h 022 023 #define STACK_SIZE 1024 024 #define BYTE_POOL_SIZE 9120 025 #define MAX_EVENTS 16 026 #define MAX_TEMP_MEMORY 200 027 028 029 /* Define the ThreadX object control blocks */ 030 031 TX_THREAD initializer; 032 TX_THREAD data_capture; w w w.ne w nespress.com Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  4. 288 Chapter 14 033 TX_THREAD event_recorder; 034 035 TX_QUEUE event_notice; 036 037 TX_MUTEX memory_mutex; 038 TX_BYTE_POOL my_byte_pool; 039 040 TX_TIMER crash_interrupt; 041 TX_TIMER unsafe_interrupt; 042 TX_TIMER warning_interrupt; 043 TX_TIMER manual_interrupt; 044 045 TX_TIMER crash_copy_scheduler; 046 TX_TIMER unsafe_copy_scheduler; 047 TX_TIMER warning_copy_scheduler; 048 TX_TIMER manual_copy_scheduler; 049 TX_TIMER stats_timer; 050 051 052 /* Define the counters and variables used in the VAM system */ 053 054 ULONG num_crashes 0, num_unsafe 0, num_warning 0, num_manual 0; 055 ULONG frame_index, event_count, frame_data[2]; 056 057 /* Define the arrays used to represent temporary memory */ 058 /* and protected memory. temp_memory contains pair of data */ 059 /* in the form time-data and protected_memory contains rows */ 060 /* of 26 elements in the form time-priority-data-data-data… */ 061 /* The working index to temp_memory is frame_index and the */ 062 /* working index to protected_memory is event_count. */ 063 064 ULONG temp_memory[MAX_TEMP_MEMORY][2], 065 protected_memory[MAX_EVENTS][26]; 066 067 /* Define thread and function prototypes. */ 068 069 void initializer_process(ULONG); 070 void data_capture_process(ULONG); 071 void event_recorder_process(ULONG); w ww. n e w n e s p r e s s .c o m Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  5. Case Study: Designing a Multithreaded System 289 072 void crash_ISR(ULONG); 073 void unsafe_ISR(ULONG); 074 void warning_ISR(ULONG); 075 void manual_ISR(ULONG); 076 void crash_copy_activate(ULONG); 077 void unsafe_copy_activate(ULONG); 078 void warning_copy_activate(ULONG); 079 void manual_copy_activate(ULONG); 080 void print_stats(ULONG); 081 082 083 /****************************************************/ 084 /* Main Entry Point */ 085 /****************************************************/ 086 087 /* Define main entry point. */ 088 089 int main() 090 { 091 092 /* Enter the ThreadX kernel. */ 093 tx_kernel_enter(); 094 } 095 096 097 098 /****************************************************/ 099 /* Application Definitions */ 100 /****************************************************/ 101 102 103 /* Define what the initial system looks like. */ 104 105 void tx_application_define(void *first_unused_memory) 106 { 107 108 CHAR *byte_pointer; 109 110 /* Put system definition stuff in here, e.g., thread creates 111 and other assorted create information. */ w w w.ne w nespress.com Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  6. 290 Chapter 14 112 113 /* Create a memory byte pool from which to allocate 114 the thread stacks. */ 115 tx_byte_pool_create(&my_byte_pool, “my_byte_pool”, 116 first_unused_memory, BYTE_POOL_SIZE); 117 118 /* Allocate the stack for the initializer thread. */ 119 tx_byte_allocate(&my_byte_pool, (VOID **) &byte_pointer, 120 STACK_SIZE, TX_NO_WAIT); 121 122 /* Create the initializer thread. */ 123 tx_thread_create(&initializer, “initializer”, 124 initializer_process, 0, 125 byte_pointer, STACK_SIZE, 11, 11, 126 TX_NO_TIME_SLICE, TX_AUTO_START); 127 128 /* Allocate the stack for the data_capture thread. */ 129 tx_byte_allocate(&my_byte_pool, (VOID **) &byte_pointer, 130 STACK_SIZE, TX_NO_WAIT); 131 132 /* Create the data_capture thread. */ 133 tx_thread_create(&data_capture, “data_capture”, 134 data_capture_process, 0, 135 byte_pointer, STACK_SIZE, 15, 15, 136 TX_NO_TIME_SLICE, TX_AUTO_START); 137 138 /* Allocate the stack for the event_recorder thread. */ 139 tx_byte_allocate(&my_byte_pool, (VOID **) &byte_pointer, 140 STACK_SIZE, TX_NO_WAIT); 141 142 /* Create the event_recorder thread. */ 143 tx_thread_create(&event_recorder, “event_recorder”, 144 event_recorder_process, 0, 145 byte_pointer, STACK_SIZE, 12, 12, 146 TX_NO_TIME_SLICE, TX_DONT_START); 147 148 /* Create and activate the 4 timers to simulate interrupts */ 149 tx_timer_create (&crash_interrupt, “crash_interrupt”, crash_ISR, 150 0 1234, 1444, 1444, TX_AUTO_ACTIVATE); w ww. n e w n e s p r e s s .c o m Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  7. Case Study: Designing a Multithreaded System 291 151 tx_timer_create (&unsafe_interrupt, “unsafe_interrupt”, unsafe_ISR, 152 0 1234, 760, 760, TX_AUTO_ACTIVATE); 153 tx_timer_create (&warning_interrupt, “warning_interrupt”, warning_ISR, 154 0 1234, 410, 410, TX_AUTO_ACTIVATE); 155 tx_timer_create (&manual_interrupt, “manual_interrupt”, manual_ISR, 156 0 1234, 888, 888, TX_AUTO_ACTIVATE); 157 158 /* Create and activate the 4 timers to initiate data copying */ 159 tx_timer_create (&crash_copy_scheduler, “crash_copy_scheduler”, 160 crash_copy_activate, 0 1234, 12, 12, TX_NO_ACTIVATE); 161 tx_timer_create (&unsafe_copy_scheduler, “unsafe_copy_scheduler”, 162 unsafe_copy_activate, 0 1234, 12, 12, TX_NO_ACTIVATE); 163 tx_timer_create (&warning_copy_scheduler, “warning_copy_scheduler”, 164 warning_copy_activate, 0 1234, 12, 12, TX_NO_ACTIVATE); 165 tx_timer_create (&manual_copy_scheduler, “manual_copy_scheduler”, 166 manual_copy_activate, 0 1234, 12, 12, TX_NO_ACTIVATE); 167 168 /* Create and activate the timer to print statistics periodically */ 169 tx_timer_create (&stats_timer, “stats_timer”, print_stats, 170 0 1234, 1000, 1000, TX_AUTO_ACTIVATE); 171 172 /* Create the message queue that holds the frame_indexes for all events. */ 173 /* The frame_index is a position marker for the temp_memory array. */ 174 /* Whenever an event occurs, the event ISR sends the current frame_index */ w w w.ne w nespress.com Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  8. 292 Chapter 14 175 /* and event priority to the queue for storing crash event information. */ 176 /* First, allocate memory space for the queue, then create the queue. */ 177 tx_byte_allocate(&my_byte_pool, (VOID **) &byte_pointer, 178 MAX_EVENTS*2*sizeof(ULONG), TX_NO_WAIT); 179 tx_queue_create (&event_notice, “event_notice”, TX_2_ULONG, 180 byte_pointer, MAX_EVENTS*2*sizeof(ULONG)); 181 182 } 183 184 185 /**********************************************************/ 186 /* Function Definitions */ 187 /**********************************************************/ 188 189 190 /* Entry function definition of the initializer thread */ 191 192 void initializer_process(ULONG thread_input) 193 { 194 /* Perform initialization tasks */ 195 /* Because we are using arrays to represent files, there is */ 196 /* very little initialization to perform. We initialize two */ 197 /* global variables that represent starting array indexes. */ 198 printf(“VAM System-Trace of Event Activities Begins…\n\n”); 199 frame_index 0; 200 event_count 0; 201 } 202 203 /***********************************************************/ 204 /* Entry function definition of the data_capture thread */ 205 206 void data_capture_process(ULONG thread_input) 207 { 208 /* Perform data capture from the VAM system to temporary memory */ 209 /* This function simulates the data capture operation by writing */ 210 /* to an array, which represents a temporary memory file. For */ w ww. n e w n e s p r e s s .c o m Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  9. Case Study: Designing a Multithreaded System 293 211 /* simplicity, we will write to the array once every timer- tick */ 212 while (1) { 213 temp_memory[frame_index][0] tx_time_get(); 214 temp_memory[frame_index][1] 0 1234; 215 frame_index (frame_index 1) % MAX_TEMP_MEMORY; 216 tx_thread_sleep(1); 217 } 218 } 219 220 221 /***********************************************************/ 222 /********** crash event detection and processing ***********/ 223 /***********************************************************/ 224 225 /* Timer function definition for simulated crash interrupt */ 226 /* This is a simulated ISR -- an actual ISR would probably begin */ 227 /* with a context save and would end with a context restore. */ 228 229 void crash_ISR (ULONG timer_input) 230 { 231 ULONG frame_data[2]; 232 frame_data[0] frame_index; 233 frame_data[1] 1; 234 num_crashes ; 235 /* Activates timer to expire in 12 seconds-end of event */ 236 /* Put frame_index and priority on queue for crash events */ 237 tx_queue_send (&event_notice, frame_data, TX_NO_WAIT); 238 tx_timer_activate (&crash_copy_scheduler); 239 } 240 /***********************************************************/ 241 /* Timer function definition for timer crash_copy_scheduler, */ 242 /* which resumes thread that performs recording of crash data */ 243 244 void crash_copy_activate (ULONG timer_input) 245 { 246 /* resume recorder thread to initiate data recording */ 247 tx_thread_resume(&event_recorder); 248 tx_timer_deactivate (&crash_copy_scheduler); 249 } w w w.ne w nespress.com Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  10. 294 Chapter 14 250 251 /***********************************************************/ 252 /**** Entry function definition of thread event_recorder ****/ 253 /***********************************************************/ 254 255 void event_recorder_process(ULONG thread_input) 256 { 257 ULONG frame, event_priority, event_time, index, frame_data[2]; 258 while (1) 259 { 260 /* Copy an event from temporary memory to protected memory. */ 261 /* Get frame_index from event message queue and copy 24 frames */ 262 /* from temp_memory to protected_memory. */ 263 tx_queue_receive (&event_notice, frame_data, TX_NO_WAIT); 264 /* Store event time and event priority in protected memory */ 265 frame frame_data[0]; 266 event_priority frame_data[1]; 267 event_time temp_memory[frame][0]; 268 printf(“**Event** Time: %5lu Count: %2lu Pri: %lu”, 269 event_time, event_count, event_priority); 270 if (event_count MAX_EVENTS) 271 { 272 tx_mutex_get (&memory_mutex, TX_WAIT_FOREVER); 273 protected_memory[event_count][0] event_time; 274 protected_memory[event_count][1] event_priority; 275 if (frame 11) 276 frame (MAX_TEMP_MEMORY-1)-(frame_index 1); 277 for (index 0; index 24; index ) 278 { 279 protected_memory[event_count][index 2] temp_ memory[frame][1]; 280 frame (frame 1) % MAX_TEMP_MEMORY; 281 } 282 tx_mutex_put (&memory_mutex); 283 event_count ; 284 } 285 else printf(“ **not processed**”); w ww. n e w n e s p r e s s .c o m Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  11. Case Study: Designing a Multithreaded System 295 286 printf (“\n”); 287 tx_thread_suspend(&event_recorder); 288 } 289 } 290 291 /***********************************************************/ 292 /********** unsafe event detection and processing **********/ 293 /***********************************************************/ 294 295 /* Timer function definition for simulated unsafe interrupt */ 296 /* This is a simulated ISR -- an actual ISR would probably begin */ 297 /* with a context save and would end with a context restore. */ 298 299 void unsafe_ISR (ULONG timer_input) 300 { 301 ULONG frame_data[2]; 302 frame_data[0] frame_index; 303 frame_data[1] 2; 304 num_unsafe ; 305 /* Activates timer to expire in 12 seconds-end of event */ 306 /* Put frame_index and priority on queue for unsafe events */ 307 tx_queue_send (&event_notice, frame_data, TX_NO_WAIT); 308 tx_timer_activate (&unsafe_copy_scheduler); 309 } 310 /***********************************************************/ 311 /* Timer function definition for timer unsafe_copy_scheduler, */ 312 /* which resumes thread that performs recording of unsafe data */ 313 314 void unsafe_copy_activate (ULONG timer_input) 315 { 316 /* resume event_recorder thread to initiate data recording */ 317 tx_thread_resume(&event_recorder); 318 tx_timer_deactivate (&unsafe_copy_scheduler); 319 } 320 321 w w w.ne w nespress.com Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  12. 296 Chapter 14 322 /***********************************************************/ 323 /********* warning event detection and processing **********/ 324 /***********************************************************/ 325 326 /* Timer function definition for simulated warning interrupt */ 327 /* This is a simulated ISR -- an actual ISR would probably begin */ 328 /* with a context save and would end with a context restore. */ 329 330 void warning_ISR (ULONG timer_input) 331 { 332 ULONG frame_data[2]; 333 frame_data[0] frame_index; 334 frame_data[1] 3; 335 num_warning ; 336 /* Activates timer to expire in 12 seconds-end of event */ 337 /* Put frame_index and priority on queue for warning events */ 338 tx_queue_send (&event_notice, frame_data, TX_NO_WAIT); 339 tx_timer_activate (&warning_copy_scheduler); 340 } 341 /***********************************************************/ 342 /* Timer function definition for timer warning_copy_scheduler, */ 343 /* which resumes thread that performs recording of warning data */ 344 345 void warning_copy_activate (ULONG timer_input) 346 { 347 /* resume event_recorder thread to initiate data recording */ 348 tx_thread_resume(&event_recorder); 349 tx_timer_deactivate (&warning_copy_scheduler); 350 } 351 352 353 /***********************************************************/ 354 /********** manual event detection and processing **********/ 355 /***********************************************************/ 356 357 /* Timer function definition for simulated manual interrupt */ 358 /* This is a simulated ISR -- an actual ISR would probably begin */ w ww. n e w n e s p r e s s .c o m Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  13. Case Study: Designing a Multithreaded System 297 359 /* with a context save and would end with a context restore. */ 360 361 void manual_ISR (ULONG timer_input) 362 { 363 ULONG frame_data[2]; 364 frame_data[0] frame_index; 365 frame_data[1] 4; 366 num_manual ; 367 /* Activates timer to expire in 12 seconds-end of event */ 368 /* Put frame_index and priority on queue for manual events */ 369 tx_queue_send (&event_notice, frame_data, TX_NO_WAIT); 370 tx_timer_activate (&manual_copy_scheduler); 371 } 372 /***********************************************************/ 373 /* Timer function definition for timer manual_copy_scheduler, */ 374 /* which resumes thread that performs recording of manual data */ 375 376 void manual_copy_activate (ULONG timer_input) 377 { 378 /* resume event_recorder thread to initiate data recording */ 379 tx_thread_resume(&event_recorder); 380 tx_timer_deactivate (&manual_copy_scheduler); 381 } 382 383 384 /***********************************************************/ 385 /*********** print statistics at specified times ************/ 386 /***********************************************************/ 387 388 void print_stats (ULONG invalue) 389 { 390 UINT row, col; 391 printf(“\n\n**** VAM System Periodic Event Summary\n\n”); 392 printf(“ Current Time: %lu\n”, tx_time_get()); 393 printf(“ Number of Crashes: %lu\n”, num_crashes); 394 printf(“ Number of Unsafe Events: %lu\n”, num_unsafe); 395 printf(“ Number of Warnings: %lu\n”, num_warning); 396 printf(“ Number of Manual Events: %lu\n”, num_manual); w w w.ne w nespress.com Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  14. 298 Chapter 14 397 398 if (event_count 0) 399 { 400 printf(“\n\n**** Portion of Protected Memory Contents\n\n”); 401 printf(“%6s%6s%6s\n”, “Time”, “Pri”, “Data”); 402 for (row 0; row event_count; row ) 403 { 404 for (col 0; col 8; col ) 405 printf(“%6lu”, protected_memory[row][col]); 406 printf(“ (etc.)\n”); 407 } 408 } 409 if (event_count MAX_EVENTS) 410 printf(“ Warning: Protected Memory is full…\n\n”); 411 } 14.7 Overview This case study provides an excellent overview of developing a system with ThreadX. We used a variety of ThreadX services, including the following: ● application timers ● threads ● message queue ● mutex ● memory byte pool This case study depends heavily on the use of application timers. One reason for using so many timers is because we need to schedule the copying of data from the temporary memory to the protected memory whenever any one of four events occurs. Our design provides the ability to record several events within each 24-second time frame, rather than just one. Application timers play a major role in providing this feature. We also used application timers to simulate interrupts that signify the occurrence of events, and we used one timer to display periodic system statistics. w ww. n e w n e s p r e s s .c o m Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  15. Case Study: Designing a Multithreaded System 299 We used only three threads for this case study. The initializer thread initializes the system, the data_capture thread coordinates the capture of data from the VAM unit to temporary memory, and the event_recorder thread copies event data from temporary memory to protected memory. We created the data_capture thread with the TX_AUTO_START option, so it would become ready immediately after initialization. We created the event_ recorder thread with the TX_DON’T_START option, which means it cannot start until it is resumed by an application timer. When the event_recorder thread completes its data copying operation, it suspends itself and remains suspended until it is resumed by a timer. We used one message queue to store information about events that had occurred. When the event_recorder thread is resumed, it takes the first message from the front of the message queue. This message contains information about the event data being copied from temporary memory to protected memory. Although we used only one message queue in this case study, typical applications tend to use a number of message queues. We used one mutex to ensure that the event_recorder thread had exclusive access to protected memory before beginning the copying operation. We used one memory byte pool to provide space for the thread stacks and for the message queue. This application is an excellent use of a memory byte pool because we need memory space of different sizes for the thread stacks and the message queue. Furthermore, these entities remain in existence for the life of the system, so there is no possibility of the fragmentation problems that can occur when bytes are repeatedly allocated and released. We also demonstrated several examples of communication between resources. For example, timers send data to the message queue, a thread receives data from the message queue, a timer activates another timer, a timer resumes a thread, and a thread obtains ownership of a mutex. All these entities interact to form an efficient and effective system. w w w.ne w nespress.com Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  16. Appendices This series of appendices comprises a reference manual for ThreadX.1 Every service is described here, including purpose, parameters, return values, and examples. Following is a list of the services discussed in the appendices. Appendix K contains the ThreadX API, which summarizes all the service calls. A Memory Block Pool Services B Memory Byte Pool Services C Event Flags Group Services D Interrupt Control Service E Mutex Services F Message Queue Services G Counting Semaphore Services H Thread Services I Internal System Clock Services J Application Timer Services K ThreadX API 1 ThreadX is a registered trademark of Express Logic, Inc. The ThreadX API, associated data structures, and data types are copyrights of Express Logic, Inc. w w w.ne w nespress.com Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  17. 302 Appendices Appendices A through J follow a common format, as follows: Service Service name and brief description Prototype Prototype showing service name, parameter order, and data types Description Detailed information about the service Input Parameters Name and description of parameters that provide data to the service (Note that the parameters may not be presented in the same order as the prototype, which specifies the correct order.) Output Parameters Name and description of parameters whose values are returned by the service Return Values Description of status values returned after invoking the service Allowed From List of objects that can call this service Preemption Possible Determination (Yes or No) of whether a preemption condition can arise as a result of calling this service, e.g., if “Yes,” the thread executing this service may be preempted by a higher-priority thread because that service may resume a higher-priority thread Example Complete example using this service See Also List of related services w ww. n e w n e s p r e s s .c o m Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  18. APPE NDIX A Memory Block Pool Services The memory block pool services described in this appendix are: tx_block_allocate Allocate a fixed-size block of memory tx_block_pool_create Create a pool of fixed-size memory blocks tx_block_pool_delete Delete pool of fixed-size memory blocks tx_block_pool_info_get Retrieve information about block pool tx_block_pool_performance_info_get Get block pool performance information tx_block_pool_performance_system_ Get block pool system performance information info_get tx_block_pool_prioritize Prioritize block pool suspension list tx_block_release Release a fixed-size block of memory tx_block_allocate Allocate a fixed-size block of memory Prototype UINT tx_block_allocate (TX_BLOCK_POOL *pool_ptr, VOID **block_ptr, ULONG wait_option) Description This service allocates a fixed-size memory block from the specified memory pool. The actual size of the memory block is determined during memory pool creation. This service modifies the Memory Block Pool Control Block through the parameter pool_ptr. w w w.ne w nespress.com Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  19. A-2 Appendix A Input Parameter pool_ptr Pointer to a previously created pool’s memory Control Block. Output Parameters block_ptr Pointer to a destination block pointer. On successful allocation, the address of the allocated memory block is placed where this parameter points to. wait_option Defines how the service behaves if no memory blocks are available. The wait options are defined as follows: TX_NO_WAIT (0x00000000) TX_WAIT_FOREVER (0xFFFFFFFF) timeout value (0x00000001 to 0xFFFFFFFE, inclusive) Selecting TX_NO_WAIT results in an immediate return from this service regardless of whether or not it was successful. This is the only valid option if the service is called from a non-thread; e.g., initialization, timer, or ISR. Selecting TX_WAIT_FOREVER causes the calling thread to suspend indefinitely until a memory block becomes available. Selecting a numeric value (1-0xFFFFFFFE) specifies the maximum number of timer-ticks to stay suspended while waiting for a memory block. Return Values TX_SUCCESS1 (0x00) Successful memory block allocation. TX_DELETED (0x01) Memory block pool was deleted while thread was suspended. TX_NO_MEMORY1 (0x10) Service was unable to allocate a block of memory. 1 This value is not affected by the TX_DISABLE_ERROR_CHECKING define that is used to disable API error checking. w ww. n e w n e s p r e s s .c o m Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  20. Memory Block Pool Services A-3 TX_WAIT_ABORTED1 (0x1A) Suspension was aborted by another thread, timer, or ISR. TX_POOL_ERROR (0x02) Invalid memory block pool pointer. TX_PTR_ERROR (0x03) Invalid pointer to destination pointer. TX_WAIT_ERROR (0x04) A wait option other than TX_NO_WAIT was specified on a call from a non-thread. Allowed From Initialization, threads, timers, and ISRs Preemption Possible Yes Example TX_BLOCK_POOL my_pool; unsigned char *memory_ptr; UINT status; … /* Allocate a memory block from my_pool. Assume that the pool has already been created with a call to tx_block_pool_create. */ status tx_block_allocate (&my_pool, (VOID **) &memory_ptr, TX_NO_WAIT); /* If status equals TX_SUCCESS, memory_ptr contains the address of the allocated block of memory. */ tx_block_pool_create Create a pool of fixed-size memory blocks Prototype UINT tx_block_pool_create (TX_BLOCK_POOL *pool_ptr, CHAR *name_ptr, ULONG block_size, VOID *pool_start, ULONG pool_size) w w w.ne w nespress.com Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
Đồng bộ tài khoản