Thông tin tài liệu:
Real-Time Embedded Multithreading Using ThreadX and MIPS- P5: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- P5 78 Chapter 7 need to create a thread entry function to complete the example. Figure 7.6 contains the code necessary to create a thread and its corresponding entry function. In this figure, the line TX_THREAD my_thread; is used to define a thread called my_thread. Recall that TX_THREAD is a data type used to define a TCB. The line UINT status; declares a variable to store the return value from the service call invocation. Each time we invoke a service call, we will check the value of this status variable to determine whether the call was successful. We will use this convention for all invocations to service calls, not just for thread services. The lines beginning with status tx_thread_create ( … ); Parameter Description Pointer to a thread control block (defined by &my_thread TX_THREAD ) Pointer to the name of the thread—a user-defined my_thread name Name of the thread entry function; when the thread my_thread_entry begins execution, control is passed to this function A 32-bit value passed to the thread entry function— 0x1234 this value is reserved for the exclusive use of the application Starting address of the stack’s memory area; we used an actual address for the beginning location of the (VOID *) 0x400000 stack, although we have many choices on how to allocate stack space 1000 Number of bytes in the stack memory area Priority—a value in the range from 0 to 31 (inclusive) 15 must be specified Preemption-threshold—a value equal to the priority 15 disables preemption-threshold Time-slice option—this means we have disabled time- TX_NO_TIME_SLICE slicing for this thread Initial thread status—this means that the thread starts TX_AUTO_START immediately upon creation Figure 7.7: Thread create parameters used in previous figure 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. The Thread—The Essential Component 79 create the thread, where the parameters specify the characteristics of the thread. Figure 7.7 contains descriptions for these parameters. We need to create a thread entry function for this thread. In this case, the lines VOID my_thread_entry (ULONG initial_input) { … } define that function. As noted earlier, the real work of the thread, including calls to other functions, occurs in this function. The initial_input value is passed to the function and is used exclusively by the application. Many entry functions are in a “do forever” loop and never return, but if the function does return, then the thread is placed in a “completed” state. If a thread is placed in this state, it cannot be executed again. Consult the appendices to find thorough descriptions of the parameters for all the service calls, as well as the return values that indicate whether a call was successful, and if not, the exact cause of the problem. For our next thread creation example, we will create a thread of priority 20, also with an entry point of “my_thread_entry.” This thread’s stack area is 1,500 bytes in size, starting at address &my_stack. We will use a preemption-threshold value of 14 and we will disable time-slicing. Note that using preemption-threshold automatically disables time-slicing. TX_THREAD my_thread; UINT status; /* Create a thread of priority 20 whose entry point is my_thread_entry. This thread’s stack area is 1500 bytes in size, starting at address &my_stack. The preemption-threshold is setup to allow preemption at priorities above 14. Time-slicing is disabled. This thread is au ...