the high-performance embedded kernel
User Guide
Express Logic, Inc.
858.613.6640
Toll Free 888.THREADX
FAX 858.521.4259
http://www.expresslogic.com
®
Express Logic, Inc.
©1997-2003 by Express Logic, Inc.
All rights reserved. This document and the associated ThreadX software are the sole property of
Express Logic, Inc. Each contains proprietary information of Express Logic, Inc. Reproduction or
duplication by any means of any portion of this document without the prior written consent of Express
Logic, Inc. is expressly forbidden.
Express Logic, Inc. reserves the right to make changes to the specifications described herein at any
time and without notice in order to improve design or reliability of ThreadX. The information in this
document has been carefully checked for accuracy; however, Express Logic, Inc. makes no warranty
pertaining to the correctness of this document.
Trademarks
ThreadX is a registered trademark of Express Logic, Inc., and picokernel, and preemption-threshold
are trademarks of Express Logic, Inc.
All other product and company names are trademarks or registered trademarks of their respective
holders.
Warranty Limitations
Express Logic, Inc. makes no warranty of any kind that the ThreadX products will meet the USER’s
requirements, or will operate in the manner specified by the USER, or that the operation of the
ThreadX products will operate uninterrupted or error free, or that any defects that may exist in the
ThreadX products will be corrected after the warranty period. Express Logic, Inc. makes no warranties
of any kind, either expressed or implied, including but not limited to the implied warranties of
merchantability and fitness for a particular purpose, with respect to the ThreadX products. No oral or
written information or advice given by Express Logic, Inc., its dealers, distributors, agents, or
employees shall create any other warranty or in any way increase the scope of this warranty, and
licensee may not rely on any such information or advice.
Part Number: 000-1001
Revision 4.0c
User Guide
Contents
Figures 15
About This Guide 17
1 Organization 17
1 Guide Conventions 18
1 ThreadX Data Types 19
1 Customer Support Center 20
Where to Send Comments 20
1 Introduction to ThreadX 21
1 ThreadX Unique Features 22
picokernel™ Architecture 22
ANSI C Source Code 22
Not A Black Box 22
A Potential Standard 23
1 Embedded Applications 23
Real-time Software 23
Multitasking 24
Tasks vs. Threads 24
1 ThreadX Benefits 25
Improved Responsiveness 25
Software Maintenance 26
Increased Throughput 26
Processor Isolation 26
Dividing the Application 27
Ease of Use 27
Improve
4 ThreadX
User Guide
Time-to-market 27
Protecting the Software Investment 27
2 Installation and Use of ThreadX 29
1 Host Considerations 30
1 Target Considerations 30
1 Product Distribution 31
1 ThreadX Installation 32
1 Using ThreadX 33
1 Small Example System 34
1 Troubleshooting 36
1 Configuration Options 36
1 ThreadX Version ID 37
3 Functional Components of ThreadX 39
1 Execution Overview 42
Initialization 42
Thread Execution 42
Interrupt Service Routines (ISR) 42
Initialization 43
Application Timers 44
1 Memory Usage 44
Static Memory Usage 44
Dynamic Memory Usage 46
1 Initialization 46
System Reset 47
Development Tool Initialization 47
main 47
tx_kernel_enter 47
Application Definition Function 48
Interrupts 48
1 Thread Execution 48
Thread Execution States 50
Thread Priorities 52
Contents 5
Express Logic, Inc.
Thread Scheduling 52
Round-Robin Scheduling 52
Time-Slicing 53
Preemption 53
Preemption- Threshold™ 54
Priority Inheritance 55
Thread Creation 55
Thread Control Block TX_THREAD 55
Currently Executing Thread 57
Thread Stack Area 57
Memory Pitfalls 59
Reentrancy 60
Thread Priority Pitfalls 60
Priority Overhead 62
Debugging Pitfalls 63
1 Message Queues 63
Creating Message Queues 64
Message Size 64
Message Queue Capacity 64
Queue Memory Area 64
Thread Suspension 65
Queue Control Block TX_QUEUE 65
Message Destination Pitfall 66
1 Counting Semaphores 66
Mutual Exclusion 66
Event Notification 67
Creating Counting Semaphores 67
Thread Suspension 67
Semaphore Control Block TX_SEMAPHORE 68
Deadly Embrace 68
Priority Inversion 70
1 Mutexes 70
Mutex Mutual Exclusion 71
Creating Mutexes 71
Thread Suspension 71
Mutex Control Block TX_MUTEX 72
Deadly Embrace 72
Priority Inversion 72
1 Event Flags 73
Creating Event Flag Groups 74