ThreadX User Guide PDF
ThreadX User Guide PDF
User Guide
Version 5.0
http://www.expresslogic.com
©1997-2006 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, preemption-threshold, and
event-chaining 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.
1 Introduction to ThreadX 19
1 ThreadX Unique Features 20
picokernel™ Architecture 20
ANSI C Source Code 20
Advanced Technology 20
Not A Black Box 21
The RTOS Standard 22
1 Embedded Applications 22
Real-time Software 22
Multitasking 22
Tasks vs. Threads 23
1 ThreadX Benefits 23
Improved Responsiveness 24
Software Maintenance 24
Increased Throughput 24
Processor Isolation 25
Dividing the Application 25
Ease of Use 26
Improve
User Guide
4 ThreadX
Time-to-market 26
Protecting the Software Investment 26
User Guide
Contents 5
Thread Priorities 54
Thread Scheduling 55
Round-robin Scheduling 55
Time-Slicing 55
Preemption 56
Preemption-Threshold™ 56
Priority Inheritance 57
Thread Creation 57
Thread Control Block TX_THREAD 57
Currently Executing Thread 59
Thread Stack Area 59
Memory Pitfalls 62
Optional Run-time Stack Checking 62
Reentrancy 62
Thread Priority Pitfalls 63
Priority Overhead 64
Run-time Thread Performance Information 65
Debugging Pitfalls 66
1 Message Queues 67
Creating Message Queues 68
Message Size 68
Message Queue Capacity 68
Queue Memory Area 69
Thread Suspension 69
Queue Send Notification 70
Queue Event-chaining™ 70
Run-time Queue Performance Information 71
Queue Control Block TX_QUEUE 72
Message Destination Pitfall 72
1 Counting Semaphores 72
Mutual Exclusion 73
Event Notification 73
Creating Counting Semaphores 74
Thread Suspension 74
Semaphore Put Notification 74
Semaphore Event-chaining™ 75
Run-time Semaphore Performance Information 75
Semaphore Control Block TX_SEMAPHORE 76
Deadly Embrace 76
Priority Inversion 78
1 Mutexes 78
Mutex Mutual Exclusion 79
Creating Mutexes 79
Thread Suspension 79
Run-time Mutex Performance Information 80
Mutex Control Block TX_MUTEX 81
Deadly Embrace 81
Priority Inversion 81
1 Event Flags 82
Creating Event Flags Groups 83
Thread Suspension 83
Event Flags Set Notification 83
Event Flags Event-chaining™ 84
Run-time Event Flags Performance Information 84
Event Flags Group Control Block
TX_EVENT_FLAGS_GROUP 85
1 Memory Block Pools 85
Creating Memory Block Pools 86
Memory Block Size 86
Pool Capacity 86
Pool’s Memory Area 87
Thread Suspension 87
Run-time Block Pool Performance Information 87
Memory Block Pool Control Block TX_BLOCK_POOL 88
Overwriting Memory Blocks 89
1 Memory Byte Pools 89
Creating Memory Byte Pools 89
Pool Capacity 90
Pool’s Memory Area 90
Thread Suspension 90
Run-time Byte Pool Performance Information 91
Memory Byte Pool Control Block TX_BYTE_POOL 92
Un-deterministic Behavior 92
Overwriting Memory Blocks 93
1 Application Timers 93
Timer Intervals 93
Timer Accuracy 94
Timer Execution 94
Creating Application Timers 94
Run-time Application Timer Performance Information 95
User Guide
Contents 7
User Guide
Contents 9
Index 345
User Guide
Figures
Figure 1 Template for Application Development 33
Figure 2 Types of Program Execution 45
Figure 3 Memory Area Example 47
Figure 4 Initialization Process 51
Figure 5 Thread State Transition 52
Figure 6 Typical Thread Stack 60
Figure 7 Stack Preset to 0xEFEF 61
Figure 8 Example of Suspended Threads 77
Figure 9 Simple Driver Initialization 300
Figure 10 Simple Driver Input 301
Figure 11 Simple Driver Output 302
Figure 12 Logic for Circular Input Buffer 304
Figure 13 Logic for Circular Output Buffer 305
Figure 14 I/O Buffer 306
Figure 15 Input-Output Lists 308
User Guide
12 ThreadX
User Guide
About This Guide
This guide provides comprehensive information
about ThreadX, the high-performance real-time
kernel from Express Logic, Inc.
Organization
Chapter 1 Provides a basic overview of
ThreadX and its relationship to
real-time embedded
development.
Chapter 2 Gives the basic steps to install
and use ThreadX in your
application right out of the box.
Chapter 3 Describes in detail the functional
operation of ThreadX, the high-
performance real-time kernel.
Chapter 4 Details the application’s
interface to ThreadX.
Chapter 5 Describes writing I/O drivers for
ThreadX applications.
Chapter 6 Describes the demonstration
application that is supplied with
every ThreadX processor
support package.
User Guide
14 ThreadX
Guide Conventions
Italics typeface denotes book titles,
emphasizes important words,
and indicates variables.
i attention to important or
additional information that could
affect performance or function.
User Guide
About This Guide 15
Latest Product Visit the Express Logic web site and select the
Information “Support” menu option to find the latest online
support information, including information about the
latest ThreadX product releases.
User Guide
About This Guide 17
User Guide
CHAPTER 1
Introduction to ThreadX
User Guide
20 Introduction to ThreadX
User Guide
ThreadX Unique Features 21
Embedded Applications
Embedded applications execute on microprocessors
buried within products such as wireless
communication devices, automobile engines, laser
printers, medical devices, etc. Another distinction of
embedded applications is that their software and
hardware have a dedicated purpose.
User Guide
ThreadX Benefits 23
Tasks vs. Threads Another distinction about tasks must be made. The
term task is used in a variety of ways. It sometimes
means a separately loadable program. In other
instances, it may refer to an internal program
segment.
ThreadX Benefits
Using ThreadX provides many benefits to embedded
applications. Of course, the primary benefit rests in
how embedded application threads are allocated
processing time.
User Guide
ThreadX Benefits 25
User Guide
CHAPTER 2
User Guide
28 Installation and Use of ThreadX
Host Considerations
Embedded software is usually developed on
Windows or Linux (Unix) host computers. After the
application is compiled, linked, and located on the
host, it is downloaded to the target hardware for
execution.
Target Considerations
ThreadX requires between 2 KBytes and 20 KBytes
of Read Only Memory (ROM) on the target. Another
1 to 2 KBytes of the target’s Random Access
Memory (RAM) are required for the ThreadX system
stack and other global data structures.
User Guide
Product Distribution 29
Product Distribution
ThreadX is shipped on a single CD-ROM. Two types
of ThreadX packages are available—standard and
premium. The standard package includes minimal
source code; while the premium package contains
complete ThreadX source code.
readme_threadx.txt
Text file containing specific
information about the ThreadX
port, including information about
the target processor and the
development tools.
ThreadX Installation
Installation of ThreadX is straightforward. The
following instructions apply to virtually any
installation. However, examine the
readme_threadx.txt file for changes specific to the
actual development tool environment.
Backup the ThreadX distribution disk and store it in a
Step 1:
safe location.
On the host hard drive, make a directory called
Step 2: “threadx” or something similar. The ThreadX kernel
files will reside in this directory.
Copy all files from the ThreadX distribution CD-ROM
Step 3: into the directory created in step 2.
If the standard package was purchased, installation
Step 4: of ThreadX is now complete.
User Guide
Using ThreadX 31
Using ThreadX
Using ThreadX is easy. Basically, the application
code must include tx_api.h during compilation and
link with the ThreadX run-time library tx.a (or tx.lib).
User Guide
Small Example System 33
#include "tx_api.h"
main( )
{
/* Enter the ThreadX kernel. */
tx_kernel_enter( );
}
/* Create my_thread! */
tx_thread_create(&my_thread, "My Thread",
my_thread_entry, 0x1234, first_unused_memory, 1024,
3, 3, TX_NO_TIME_SLICE, TX_AUTO_START);
}
Troubleshooting
Each ThreadX port is delivered with a demonstration
application. It is always a good idea to first get the
demonstration system running—either on actual
target hardware or simulated environment.
Configuration Options
There are several configuration options when
building the ThreadX library and the application using
ThreadX. The options below can be defined in the
application source, on the command line, or within
the tx_user.h include file.
User Guide
Configuration Options 35
Define Meaning
TX_DISABLE_ERROR_CHECKING Bypasses basic service call error
checking. When defined in the
application source, all basic
parameter error checking is
disabled. This may improve
performance by as much as 30%
and may also reduce the image
size. Of course, this option
should only be used after the
application is thoroughly
debugged. By default, this option
is not defined.
ThreadX API return
values not affected
i by disabling error
checking are listed in
bold in the “Return
Values” section of each API
description in Chapter 4. The
non-bold return values are void if
error checking is disabled by
using the
TX_DISABLE_ERROR_CHECKING
option.
TX_MAX_PRIORITIES Defines the priority levels for
ThreadX. Legal values range
from 32 through 1024 (inclusive)
and must be evenly divisible by
32. Increasing the number of
priority levels supported
increases the RAM usage by 128
bytes for every group of 32
priorities. However, there is only
a negligible effect on
performance. By default, this
value is set to 32 priority levels.
User Guide
Configuration Options 37
Define Meaning
TX_MINIMUM_STACK Defines the minimum stack size
(in bytes). It is used for error
checking when threads are
created. The default value is
port-specific and is found in
tx_port.h.
TX_TIMER_THREAD_STACK_SIZE Defines the stack size (in bytes)
of the internal ThreadX system
timer thread. This thread
processes all thread sleep
requests as well as all service
call timeouts. In addition, all
application timer callback
routines are invoked from this
context. The default value is port-
specific and is found in
tx_port.h.
TX_TIMER_THREAD_PRIORITY Defines the priority of the internal
ThreadX system timer thread.
The default value is priority 0—
the highest priority in ThreadX.
The default value is defined in
tx_port.h.
TX_TIMER_PROCESS_IN_ISR When defined, eliminates the
internal system timer thread for
ThreadX. This results in
improved performance on timer
events and smaller RAM
requirements because the timer
stack and control block are no
longer needed. However, using
this option moves all the timer
expiration processing to the timer
ISR level. By default, this option
is not defined.
TX_REACTIVATE_INLINE When defined, performs
reactivation of ThreadX timers in-
line instead of using a function
call. This improves performance
but slightly increases code size.
By default, this option is not
defined.
Define Meaning
TX_DISABLE_STACK_FILLING When defined, disables placing
the 0xEF value in each byte of
each thread’s stack when
created. By default, this option is
not defined.
TX_ENABLE_STACK_CHECKING When defined, enables ThreadX
run-time stack checking, which
includes analysis of how much
stack has been used and
examination of data pattern
“fences” before and after the
stack area. If a stack error is
detected, the registered
application stack error handler is
called. This option does result in
slightly increased overhead and
code size. Review the
tx_thread_stack_error_notify
API for more information. By
default, this option is not defined.
TX_DISABLE_PREEMPTION_THRESHOLD When defined, disables the
preemption-threshold feature
and slightly reduces code size
and improves performance. Of
course, the preemption-threshold
capabilities are no longer
available. By default, this option
is not defined.
TX_DISABLE_REDUNDANT_CLEARING When defined, removes the logic
for initializing ThreadX global C
data structures to zero. This
should only be used if the
compiler’s initialization code sets
all un-initialized C global data to
zero. Using this option slightly
reduces code size and improves
performance during initialization.
By default, this option is not
defined.
User Guide
Configuration Options 39
Define Meaning
TX_DISABLE_NOTIFY_CALLBACKS When defined, disables the notify
callbacks for various ThreadX
objects. Using this option slightly
reduces code size and improves
performance. By default, this
option is not defined.
TX_BLOCK_POOL_ENABLE_PERFORMANCE_INFO When defined, enables the
gathering of performance
information on block pools. By
default, this option is not defined.
TX_BYTE_POOL_ENABLE_PERFORMANCE_INFO When defined, enables the
gathering of performance
information on byte pools. By
default, this option is not defined.
TX_EVENT_FLAGS_ENABLE_PERFORMANCE_INFO When defined, enables the
gathering of performance
information on event flags
groups. By default, this option is
not defined.
TX_MUTEX_ENABLE_PERFORMANCE_INFO When defined, enables the
gathering of performance
information on mutexes. By
default, this option is not defined.
TX_QUEUE_ENABLE_PERFORMANCE_INFO When defined, enables the
gathering of performance
information on queues. By
default, this option is not defined.
TX_SEMAPHORE_ENABLE_PERFORMANCE_INFO When defined, enables the
gathering of performance
information on semaphores. By
default, this option is not defined.
TX_THREAD_ENABLE_PERFORMANCE_INFO Defined, enables the gathering of
performance information on
threads. By default, this option is
not defined.
TX_TIMER_ENABLE_PERFORMANCE_INFO Defined, enables the gathering of
performance information on
timers. By default, this option is
not defined.
ThreadX Version ID
The ThreadX version ID can be found in the
readme_threadx.txt file. This file also contains a
version history of the corresponding port. Application
software can obtain the ThreadX version by
examining the global string _tx_version_id.
User Guide
CHAPTER 3
Functional Components of
ThreadX
User Guide
42 Functional Components of ThreadX
User Guide
43
Execution Overview
There are four types of program execution within a
ThreadX application: Initialization, Thread Execution,
Interrupt Service Routines (ISRs), and Application
Timers.
User Guide
Execution Overview 45
Execution Overview
Hardware
Reset
Initialization
Thread
Execution
Interrupt Application
Service
Routines Timers
Memory Usage
ThreadX resides along with the application program.
As a result, the static memory (or fixed memory)
usage of ThreadX is determined by the development
tools; e.g., the compiler, linker, and locator. Dynamic
memory (or run-time memory) usage is under direct
control of the application.
User Guide
Memory Usage 47
0x00000000
Instruction Area
ROM
Constant Area
ROM
Indicates ThreadX
Usage
Initialization
Understanding the initialization process is important.
The initial hardware environment is set up here. In
addition, this is where the application is given its
initial personality.
User Guide
Initialization 49
Thread Execution
Scheduling and executing application threads is the
most important activity of ThreadX. A thread is
typically defined as a semi-independent program
segment with a dedicated purpose. The combined
processing of all threads makes an application.
User Guide
Thread Execution 51
entry point*
main( )
tx_kernel_enter( )
tx_application_define(mem_ptr)
Enter thread
scheduling loop
* denotes functions that are
development-tool specific
tx_thread_create
TX_AUTO_START TX_DONT_START
Services
Ready with Suspension Suspended
State State
Thread
Scheduling
Self
Suspend Terminate
Service
Executing
State
Self
Terminate
Return
From Thread
Entry Function
Completed Terminated
State State
User Guide
Thread Execution 53
User Guide
Thread Execution 55
User Guide
Thread Execution 57
tx_thread_run_count
contains a counter of the
number of many times the
thread has been scheduled. An
increasing counter indicates the
thread is being scheduled and
executed.
TX_READY (0x00)
TX_COMPLETED (0x01)
TX_TERMINATED (0x02)
TX_SUSPENDED (0x03)
TX_SLEEP (0x04)
TX_QUEUE_SUSP (0x05)
TX_SEMAPHORE_SUSP (0x06)
TX_EVENT_FLAG (0x07)
TX_BLOCK_MEMORY (0x08)
TX_BYTE_MEMORY (0x09)
TX_MUTEX_SUSP (0x0D)
User Guide
Thread Execution 59
Thread Stack Area Each thread must have its own stack for saving the
context of its last execution and compiler use. Most C
compilers use the stack for making function calls and
for temporarily allocating local variables. Figure 6 on
page 60 shows a typical thread’s stack.
Typical
run-time
stack
growth
tx_stack_ptr
Thread’s last
execution context
User Guide
Thread Execution 61
Thread’s last
execution context
User Guide
Thread Execution 63
User Guide
Thread Execution 65
• priority inversions
• time-slices
• relinquishes
• thread timeouts
• suspension aborts
• idle system returns
• non-idle system returns
User Guide
Message Queues 67
Message Queues
Message queues are the primary means of inter-
thread communication in ThreadX. One or more
messages can reside in a message queue. A
message queue that holds a single message is
commonly called a mailbox.
User Guide
Message Queues 69
User Guide
Message Queues 71
Counting Semaphores
ThreadX provides 32-bit counting semaphores that
range in value between 0 and 4,294,967,295. There
are two operations for counting semaphores:
tx_semaphore_get and tx_semaphore_put. The get
operation decreases the semaphore by one. If the
semaphore is 0, the get operation is not successful.
The inverse of the get operation is the put operation.
It increases the semaphore by one.
User Guide
Counting Semaphores 73
User Guide
Counting Semaphores 75
User Guide
Counting Semaphores 77
Deadly Embrace
(example)
First Second
Semaphore Semaphore
owned by owned by
first thread second thread
attempt to attempt to
get second get first
semaphore semaphore
Mutexes
In addition to semaphores, ThreadX also provides a
mutex object. A mutex is basically a binary
semaphore, which means that only one thread can
own a mutex at a time. In addition, the same thread
may perform a successful mutex get operation on an
owned mutex multiple times, 4,294,967,295 to be
exact. There are two operations on the mutex object:
tx_mutex_get and tx_mutex_put. The get
operation obtains a mutex not owned by another
thread, while the put operation releases a previously
obtained mutex. For a thread to release a mutex, the
number of put operations must equal the number of
prior get operations.
User Guide
Mutexes 79
User Guide
Mutexes 81
Event Flags
Event flags provide a powerful tool for thread
synchronization. Each event flag is represented by a
single bit. Event flags are arranged in groups of 32.
User Guide
Event Flags 83
User Guide
Memory Block Pools 85
Event Flags Group The characteristics of each event flags group are
Control Block found in its control block. It contains information such
TX_EVENT_FLAGS_GROUP as the current event flags settings and the number of
threads suspended for events. This structure is
defined in the tx_api.h file.
User Guide
Memory Block Pools 87
Pool’s Memory As mentioned before, the memory area for the block
Area pool is specified during creation. Like other memory
areas in ThreadX, it can be located anywhere in the
target’s address space.
User Guide
Memory Byte Pools 89
Pool’s Memory The memory area for a memory byte pool is specified
Area during creation. Like other memory areas in
ThreadX, it can be located anywhere in the target’s
address space.
User Guide
Memory Byte Pools 91
Memory Byte Pool The characteristics of each memory byte pool are
Control Block found in its control block. It contains useful
TX_BYTE_POOL information such as the number of available bytes in
the pool. This structure is defined in the tx_api.h file.
User Guide
Application Timers 93
Application Timers
Fast response to asynchronous external events is
the most important function of real-time, embedded
applications. However, many of these applications
must also perform certain activities at pre-determined
intervals of time.
User Guide
Application Timers 95
Relative Time
In addition to the application timers mentioned
previously, ThreadX provides a single continuously
incrementing 32-bit tick counter. The tick counter or
time is increased by one on each timer interrupt.
Interrupts
Fast response to asynchronous events is the
principal function of real-time, embedded
applications. The application knows such an event is
present through hardware interrupts.
User Guide
Interrupts 97
tx_event_flags_info_get
tx_event_flags_get
tx_event_flags_set
tx_event_flags_performance_info_get
tx_event_flags_performance_system_info_get
tx_event_flags_set_notify
tx_interrupt_control
tx_mutex_performance_info_get
tx_mutex_performance_system_info_get
tx_queue_front_send
tx_queue_info_get
tx_queue_performance_info_get
tx_queue_performance_system_info_get
tx_queue_prioritize
tx_queue_receive
tx_queue_send
tx_semaphore_get
tx_queue_send_notify
tx_semaphore_ceiling_put
tx_semaphore_info_get
tx_semaphore_performance_info_get
tx_semaphore_performance_system_info_get
tx_semaphore_prioritize
tx_semaphore_put
tx_thread_identify
tx_semaphore_put_notify
tx_thread_entry_exit_notify
tx_thread_info_get
tx_thread_resume
tx_thread_performance_info_get
tx_thread_performance_system_info_get
tx_thread_stack_error_notify
tx_thread_wait_abort
tx_time_get
tx_time_set
tx_timer_activate
tx_timer_change
tx_timer_deactivate
tx_timer_info_get
tx_timer_performance_info_get
tx_timer_performance_system_info_get
User Guide
Interrupts 99
_application_ISR_vector_entry:
; Save context and prepare for
; ThreadX use by calling the ISR
; entry function.
CALL __tx_thread_context_save
User Guide
CHAPTER 4
User Guide
102 Description of ThreadX Services
tx_byte_pool_create
Create memory pool of bytes 130
tx_byte_pool_delete
Delete memory byte pool 132
tx_byte_pool_info_get
Retrieve information about byte pool 134
tx_byte_pool_performance_info_get
Get byte pool performance information 136
tx_byte_pool_performance_system_info_get
Get byte pool system performance information 138
tx_byte_pool_prioritize
Prioritize byte pool suspension list 140
tx_byte_release
Release bytes back to memory pool 142
tx_event_flags_create
Create event flags group 144
tx_event_flags_delete
Delete event flags group 146
tx_event_flags_get
Get event flags from event flags group 148
tx_event_flags_info_get
Retrieve information about event flags group 152
tx_event_flags_performance info_get
Get event flags group performance information 154
tx_event_flags_performance_system_info_get
Retrieve performance system information 156
tx_event_flags_set
Set event flags in an event flags group 158
tx_event_flags_set_notify
Notify application when event flags are set 160
tx_interrupt_control
Enable and disable interrupts 162
User Guide
103
tx_mutex_create
Create mutual exclusion mutex 164
tx_mutex_delete
Delete mutual exclusion mutex 166
tx_mutex_get
Obtain ownership of mutex 168
tx_mutex_info_get
Retrieve information about mutex 170
tx_mutex_performance_info_get
Get mutex performance information 172
tx_mutex_performance_system_info_get
Get mutex system performance information 174
tx_mutex_prioritize
Prioritize mutex suspension list 176
tx_mutex_put
Release ownership of mutex 178
tx_queue_create
Create message queue 180
tx_queue_delete
Delete message queue 182
tx_queue_flush
Empty messages in message queue 184
tx_queue_front_send
Send message to the front of queue 186
tx_queue_info_get
Retrieve information about queue 190
tx_queue_performance_info_get
Get queue performance information 192
tx_queue_performance_system_info_get
Get queue system performance information 194
tx_queue_prioritize
Prioritize queue suspension list 196
tx_queue_receive
Get message from message queue 198
tx_queue_send
Send message to message queue 202
tx_queue_send_notify
Notify application when message is sent to queue 206
tx_semaphore_ceiling_put
Place an instance in counting semaphore with ceiling 208
tx_semaphore_create
Create counting semaphore 210
tx_semaphore_delete
Delete counting semaphore 212
tx_semaphore_get
Get instance from counting semaphore 214
tx_semaphore_info_get
Retrieve information about semaphore 218
tx_semaphore_performance_info_get
Get semaphore performance information 220
tx_semaphore_performance_system_info_get
Get semaphore system performance information 222
tx_semaphore_prioritize
Prioritize semaphore suspension list 224
tx_semaphore_put
Place an instance in counting semaphore 226
tx_semaphore_put_notify
Notify application when semaphore is put 228
tx_thread_create
Create application thread 230
tx_thread_delete
Delete application thread 234
tx_thread_entry_exit_notify
Notify application upon thread entry and exit 236
User Guide
105
tx_thread_identify
Retrieves pointer to currently executing thread 238
tx_thread_info_get
Retrieve information about thread 240
tx_thread_performance_info_get
Get thread performance information 244
tx_thread_performance_system_info_get
Get thread system performance information 248
tx_thread_preemption_change
Change preemption-threshold of application thread 252
tx_thread_priority_change
Change priority of application thread 254
tx_thread_relinquish
Relinquish control to other application threads 256
tx_thread_reset
Reset thread 258
tx_thread_resume
Resume suspended application thread 260
tx_thread_sleep
Suspend current thread for specified time 262
tx_thread_stack_error_notify
Register thread stack error notification callback 264
tx_thread_suspend
Suspend application thread 266
tx_thread_terminate
Terminates application thread 268
tx_thread_time_slice_change
Changes time-slice of application thread 270
tx_thread_wait_abort
Abort suspension of specified thread 272
tx_time_get
Retrieves the current time 274
tx_time_set
Sets the current time 276
tx_timer_activate
Activate application timer 278
tx_timer_change
Change application timer 280
tx_timer_create
Create application timer 282
tx_timer_deactivate
Deactivate application timer 284
tx_timer_delete
Delete application timer 286
tx_timer_info_get
Retrieve information about an application timer 288
tx_timer_performance_info_get
Get timer performance information 290
tx_timer_performance_system_info_get
Get timer system performance information 292
User Guide
107
tx_block_allocate
Allocate fixed-size block of memory
Mem ory Blocks
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.
Input Parameters
pool_ptr Pointer to a previously created memory block
pool.
block_ptr Pointer to a destination block pointer. On
successful allocation, the address of the
allocated memory block is placed where this
parameter points.
wait_option Defines how the service behaves if there are no
memory blocks available. The wait options are
defined as follows:
TX_NO_WAIT (0x00000000)
TX_WAIT_FOREVER (0xFFFFFFFF)
timeout value (0x00000001 through
0xFFFFFFFE)
Selecting TX_NO_WAIT results in an immediate
return from this service regardless if it was
successful or not. 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 is available.
Selecting a numeric value (1-0xFFFFFFFE)
specifies the maximum number of timer-ticks to
User Guide
Memory Blocks 109
Return Values
TX_SUCCESS (0x00) Successful memory block allocation.
TX_DELETED (0x01) Memory block pool was deleted while
thread was suspended.
TX_NO_MEMORY (0x10) Service was unable to allocate a block
of memory within the specified time to
wait.
TX_WAIT_ABORTED (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;
See Also
tx_block_pool_create, tx_block_pool_delete, tx_block_pool_info_get,
tx_block_pool_performance_info_get,
tx_block_pool_performance_system_info_get, tx_block_pool_prioritize,
tx_block_release
User Guide
Memory Blocks 111
tx_block_pool_create
Create 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)
Description
This service creates a pool of fixed-size memory blocks. The memory
area specified is divided into as many fixed-size memory blocks as
possible using the formula:
total blocks = (total bytes) / (block size + sizeof(void *))
Input Parameters
pool_ptr Pointer to a memory block pool control block.
name_ptr Pointer to the name of the memory block pool.
block_size Number of bytes in each memory block.
pool_start Starting address of the memory block pool.
pool_size Total number of bytes available for the memory
block pool.
User Guide
Memory Blocks 113
Return Values
TX_SUCCESS (0x00) Successful memory block pool
creation.
TX_POOL_ERROR (0x02) Invalid memory block pool pointer.
Either the pointer is NULL or the pool
is already created.
TX_PTR_ERROR (0x03) Invalid starting address of the pool.
TX_SIZE_ERROR (0x05) Size of pool is invalid.
TX_CALLER_ERROR (0x13) Invalid caller of this service.
Allowed From
Initialization and threads
Preemption Possible
No
Example
TX_BLOCK_POOL my_pool;
UINT status;
See Also
tx_block_allocate, tx_block_pool_delete, tx_block_pool_info_get,
tx_block_pool_performance_info_get,
tx_block_pool_performance_system_info_get, tx_block_pool_prioritize,
tx_block_release
tx_block_pool_delete
Delete memory block pool
Prototype
UINT tx_block_pool_delete(TX_BLOCK_POOL *pool_ptr)
Description
This service deletes the specified block-memory pool. All threads
suspended waiting for a memory block from this pool are resumed and
given a TX_DELETED return status.
Input Parameters
pool_ptr Pointer to a previously created memory block
pool.
Return Values
TX_SUCCESS (0x00) Successful memory block pool
deletion.
TX_POOL_ERROR (0x02) Invalid memory block pool pointer.
TX_CALLER_ERROR (0x13) Invalid caller of this service.
Allowed From
Threads
Preemption Possible
Yes
User Guide
Memory Blocks 115
Example
TX_BLOCK_POOL my_pool;
UINT status;
See Also
tx_block_allocate, tx_block_pool_create, tx_block_pool_info_get,
tx_block_pool_performance_info_get,
tx_block_pool_performance_system_info_get, tx_block_pool_prioritize,
tx_block_release
tx_block_pool_info_get
Retrieve information about block pool
Mem ory Blocks
Prototype
UINT tx_block_pool_info_get(TX_BLOCK_POOL *pool_ptr, CHAR **name,
ULONG *available, ULONG *total_blocks,
TX_THREAD **first_suspended,
ULONG *suspended_count,
TX_BLOCK_POOL **next_pool)
Description
This service retrieves information about the specified block memory pool.
Input Parameters
pool_ptr Pointer to previously created memory block pool.
name Pointer to destination for the pointer to the block
pool’s name.
available Pointer to destination for the number of available
blocks in the block pool.
total_blocks Pointer to destination for the total number of
blocks in the block pool.
first_suspended Pointer to destination for the pointer to the thread
that is first on the suspension list of this block
pool.
suspended_count Pointer to destination for the number of threads
currently suspended on this block pool.
next_pool Pointer to destination for the pointer of the next
created block pool.
User Guide
Memory Blocks 117
Return Values
TX_SUCCESS (0x00) Successful block pool information retrieve.
TX_POOL_ERROR (0x02) Invalid memory block pool pointer.
Allowed From
Initialization, threads, timers, and ISRs
Example
TX_BLOCK_POOL my_pool;
CHAR *name;
ULONG available;
ULONG total_blocks;
TX_THREAD *first_suspended;
ULONG suspended_count;
TX_BLOCK_POOL *next_pool;
UINT status;
See Also
tx_block_allocate, tx_block_pool_create, tx_block_pool_delete,
tx_block_pool_info_get, tx_block_pool_performance_info_get,
tx_block_pool_performance_system_info_get, tx_block_pool_prioritize,
tx_block_release
tx_block_pool_performance_info_get
Get block pool performance information
Prototype
UINT tx_block_pool_performance_info_get(TX_BLOCK_POOL *pool_ptr,
ULONG *allocates, ULONG *releases,
ULONG *suspensions, ULONG *timeouts))
Description
This service retrieves performance information about the specified
memory block pool.
Input Parameters
pool_ptr Pointer to previously created memory block pool.
allocates Pointer to destination for the number of allocate
requests performed on this pool.
releases Pointer to destination for the number of release
requests performed on this pool.
suspensions Pointer to destination for the number of thread
allocation suspensions on this pool.
timeouts Pointer to destination for the number of allocate
suspension timeouts on this pool.
i not required.
User Guide
Memory Blocks 119
Return Values
TX_SUCCESS (0x00) Successful block pool
performance get.
TX_PTR_ERROR (0x03) Invalid block pool pointer.
TX_FEATURE_NOT_ENABLED (0xFF) The system was not
compiled with performance
information enabled.
Allowed From
Initialization, threads, timers, and ISRs
Example
TX_BLOCK_POOL my_pool;
ULONG allocates;
ULONG releases;
ULONG suspensions;
ULONG timeouts;
See Also
tx_block_allocate, tx_block_pool_create, tx_block_pool_delete,
tx_block_pool_info_get, tx_block_pool_performance_info_get,
tx_block_pool_performance_system_info_get, tx_block_release
tx_block_pool_performance_system_info_get
Get block pool system performance information
Prototype
UINT tx_block_pool_performance_system_info_get(ULONG *allocates,
ULONG *releases, ULONG *suspensions, ULONG *timeouts);
Description
This service retrieves performance information about all memory block
pools in the application.
Input Parameters
allocates Pointer to destination for the total number of
allocate requests performed on all block pools.
releases Pointer to destination for the total number of
release requests performed on all block pools.
suspensions Pointer to destination for the total number of
thread allocation suspensions on all block pools.
timeouts Pointer to destination for the total number of
allocate suspension timeouts on all block pools..
i not required.
Return Values
TX_SUCCESS (0x00) Successful block pool
system performance get.
TX_FEATURE_NOT_ENABLED (0xFF) The system was not
compiled with performance
information enabled.
User Guide
Memory Blocks 121
Allowed From
Initialization, threads, timers, and ISRs
Example
ULONG allocates;
ULONG releases;
ULONG suspensions;
ULONG timeouts;
See Also
tx_block_allocate, tx_block_pool_create, tx_block_pool_delete,
tx_block_pool_info_get, tx_block_pool_performance_info_get,
tx_block_pool_prioritize, tx_block_release
tx_block_pool_prioritize
Prioritize block pool suspension list
Prototype
UINT tx_block_pool_prioritize(TX_BLOCK_POOL *pool_ptr)
Description
This service places the highest priority thread suspended for a block of
memory on this pool at the front of the suspension list. All other threads
remain in the same FIFO order they were suspended in.
Input Parameters
pool_ptr Pointer to a memory block pool control block.
Return Values
TX_SUCCESS (0x00) Successful block pool prioritize.
TX_POOL_ERROR (0x02) Invalid memory block pool pointer.
Allowed From
Initialization, threads, timers, and ISRs
Preemption Possible
No
User Guide
Memory Blocks 123
Example
TX_BLOCK_POOL my_pool;
UINT status;
See Also
tx_block_allocate, tx_block_pool_create, tx_block_pool_delete,
tx_block_pool_info_get, tx_block_pool_performance_info_get,
tx_block_pool_performance_system_info_get, tx_block_release
tx_block_release
Release fixed-size block of memory
Prototype
UINT tx_block_release(VOID *block_ptr)
Description
This service releases a previously allocated block back to its associated
memory pool. If there are one or more threads suspended waiting for
memory blocks from this pool, the first thread suspended is given this
memory block and resumed.
The application must prevent using a memory block area after it has been
i released back to the pool.
Input Parameters
block_ptr Pointer to the previously allocated memory
block.
Return Values
TX_SUCCESS (0x00) Successful memory block release.
TX_PTR_ERROR (0x03) Invalid pointer to memory block.
Allowed From
Initialization, threads, timers, and ISRs
Preemption Possible
Yes
User Guide
Memory Blocks 125
Example
TX_BLOCK_POOL my_pool;
unsigned char *memory_ptr;
UINT status;
See Also
tx_block_allocate, tx_block_pool_create, tx_block_pool_delete,
tx_block_pool_info_get, tx_block_pool_performance_info_get,
tx_block_pool_performance_system_info_get, tx_block_pool_prioritize
tx_byte_allocate
Allocate bytes of memory
Mem ory Bytes
Prototype
UINT tx_byte_allocate(TX_BYTE_POOL *pool_ptr,
VOID **memory_ptr, ULONG memory_size,
ULONG wait_option)
Description
This service allocates the specified number of bytes from the specified
memory byte pool.
The performance of this service is a function of the block size and the
i amount of fragmentation in the pool. Hence, this service should not be
used during time-critical threads of execution.
Input Parameters
pool_ptr Pointer to a previously created memory pool.
memory_ptr Pointer to a destination memory pointer. On
successful allocation, the address of the
allocated memory area is placed where this
parameter points to.
memory_size Number of bytes requested.
wait_option Defines how the service behaves if there is not
enough memory available. The wait options are
defined as follows:
TX_NO_WAIT (0x00000000)
TX_WAIT_FOREVER (0xFFFFFFFF)
timeout value (0x00000001 through
0xFFFFFFFE)
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 initialization.
Selecting TX_WAIT_FOREVER causes the
calling thread to suspend indefinitely until
enough memory is available.
User Guide
Memory Bytes 127
Return Values
TX_SUCCESS (0x00) Successful memory allocation.
TX_DELETED (0x01) Memory pool was deleted while thread
was suspended.
TX_NO_MEMORY (0x10) Service was unable to allocate the
memory within the specified time to
wait.
TX_WAIT_ABORTED (0x1A) Suspension was aborted by another
thread, timer, or ISR.
TX_POOL_ERROR (0x02) Invalid memory pool pointer.
TX_PTR_ERROR (0x03) Invalid pointer to destination pointer.
TX_SIZE_ERROR (0X05) Requested size is zero or larger than
the pool.
TX_WAIT_ERROR (0x04) A wait option other than TX_NO_WAIT
was specified on a call from a non-
thread.
TX_CALLER_ERROR (0x13) Invalid caller of this service.
Allowed From
Initialization and threads
Preemption Possible
Yes
Example
TX_BYTE_POOL my_pool;
unsigned char*memory_ptr;
UINT status;
See Also
tx_byte_pool_create, tx_byte_pool_delete, tx_byte_pool_info_get,
tx_byte_pool_performance_info_get,
tx_byte_pool_performance_system_info_get, tx_byte_pool_prioritize,
tx_byte_release
User Guide
Memory Bytes 129
tx_byte_pool_create
Create memory pool of bytes
Prototype
UINT tx_byte_pool_create(TX_BYTE_POOL *pool_ptr,
CHAR *name_ptr, VOID *pool_start,
ULONG pool_size)
Description
This service creates a memory byte pool in the area specified. Initially the
pool consists of basically one very large free block. However, the pool is
broken into smaller blocks as allocations are made.
Input Parameters
pool_ptr Pointer to a memory pool control block.
name_ptr Pointer to the name of the memory pool.
pool_start Starting address of the memory pool.
pool_size Total number of bytes available for the memory
pool.
Return Values
TX_SUCCESS (0x00) Successful memory pool creation.
TX_POOL_ERROR (0x02) Invalid memory pool pointer. Either the
pointer is NULL or the pool is already
created.
TX_PTR_ERROR (0x03) Invalid starting address of the pool.
TX_SIZE_ERROR (0x05) Size of pool is invalid.
TX_CALLER_ERROR (0x13) Invalid caller of this service.
Allowed From
Initialization and threads
Preemption Possible
No
User Guide
Memory Bytes 131
Example
TX_BYTE_POOL my_pool;
UINT status;
See Also
tx_byte_allocate, tx_byte_pool_delete, tx_byte_pool_info_get,
tx_byte_pool_performance_info_get,
tx_byte_pool_performance_system_info_get, tx_byte_pool_prioritize,
tx_byte_release
tx_byte_pool_delete
Delete memory byte pool
Prototype
UINT tx_byte_pool_delete(TX_BYTE_POOL *pool_ptr)
Description
This service deletes the specified memory byte pool. All threads
suspended waiting for memory from this pool are resumed and given a
TX_DELETED return status.
Input Parameters
pool_ptr Pointer to a previously created memory pool.
Return Values
TX_SUCCESS (0x00) Successful memory pool deletion.
TX_POOL_ERROR (0x02) Invalid memory pool pointer.
TX_CALLER_ERROR (0x13) Invalid caller of this service.
Allowed From
Threads
Preemption Possible
Yes
User Guide
Memory Bytes 133
Example
TX_BYTE_POOL my_pool;
UINT status;
/* Delete entire memory pool. Assume that the pool has already
been created with a call to tx_byte_pool_create. */
status = tx_byte_pool_delete(&my_pool);
See Also
tx_byte_allocate, tx_byte_pool_create, tx_byte_pool_info_get,
tx_byte_pool_performance_info_get,
tx_byte_pool_performance_system_info_get, tx_byte_pool_prioritize,
tx_byte_release
tx_byte_pool_info_get
Retrieve information about byte pool
Mem ory Bytes
Prototype
UINT tx_byte_pool_info_get(TX_BYTE_POOL *pool_ptr, CHAR **name,
ULONG *available, ULONG *fragments,
TX_THREAD **first_suspended,
ULONG *suspended_count,
TX_BYTE_POOL **next_pool)
Description
This service retrieves information about the specified memory byte pool.
Input Parameters
pool_ptr Pointer to previously created memory pool.
name Pointer to destination for the pointer to the byte
pool’s name.
available Pointer to destination for the number of available
bytes in the pool.
fragments Pointer to destination for the total number of
memory fragments in the byte pool.
first_suspended Pointer to destination for the pointer to the thread
that is first on the suspension list of this byte
pool.
suspended_count Pointer to destination for the number of threads
currently suspended on this byte pool.
next_pool Pointer to destination for the pointer of the next
created byte pool.
User Guide
Memory Bytes 135
Return Values
TX_SUCCESS (0x00) Successful pool information retrieve.
TX_POOL_ERROR (0x02) Invalid memory pool pointer.
Allowed From
Initialization, threads, timers, and ISRs
Preemption Possible
No
Example
TX_BYTE_POOL my_pool;
CHAR *name;
ULONG available;
ULONG fragments;
TX_THREAD *first_suspended;
ULONG suspended_count;
TX_BYTE_POOL *next_pool;
UINT status;
See Also
tx_byte_allocate, tx_byte_pool_create, tx_byte_pool_delete,
tx_byte_pool_performance_info_get,
tx_byte_pool_performance_system_info_get, tx_byte_pool_prioritize,
tx_byte_release
tx_byte_pool_performance_info_get
Get byte pool performance information
Prototype
UINT tx_byte_pool_performance_info_get(TX_BYTE_POOL *pool_ptr,
ULONG *allocates, ULONG *releases,
ULONG *fragments_searched, ULONG *merges, ULONG *splits,
ULONG *suspensions, ULONG *timeouts);
Description
This service retrieves performance information about the specified
memory byte pool.
Input Parameters
pool_ptr Pointer to previously created memory byte pool.
allocates Pointer to destination for the number of allocate
requests performed on this pool.
releases Pointer to destination for the number of release
requests performed on this pool.
fragments_searched Pointer to destination for the number of internal
memory fragments searched during allocation
requests on this pool.
merges Pointer to destination for the number of internal
memory blocks merged during allocation
requests on this pool.
splits Pointer to destination for the number of internal
memory blocks split (fragments) created during
allocation requests on this pool.
suspensions Pointer to destination for the number of thread
allocation suspensions on this pool.
timeouts Pointer to destination for the number of allocate
suspension timeouts on this pool.
User Guide
Memory Bytes 137
Return Values
TX_SUCCESS (0x00) Successful byte pool
performance get.
TX_PTR_ERROR (0x03) Invalid byte pool pointer.
TX_FEATURE_NOT_ENABLED (0xFF) The system was not compiled
with performance information
enabled.
Allowed From
Initialization, threads, timers, and ISRs
Example
TX_BYTE_POOL my_pool;
ULONG fragments_searched;
ULONG merges;
ULONG splits;
ULONG allocates;
ULONG releases;
ULONG suspensions;
ULONG timeouts;
See Also
tx_byte_allocate, tx_byte_pool_create, tx_byte_pool_delete,
tx_byte_pool_info_get, tx_byte_pool_performance_system_info_get,
tx_byte_pool_prioritize, tx_byte_release
tx_byte_pool_performance_system_info_get
Get byte pool system performance information
Prototype
UINT tx_byte_pool_performance_system_info_get(ULONG *allocates,
ULONG *releases, ULONG *fragments_searched, ULONG *merges,
ULONG *splits, ULONG *suspensions, ULONG *timeouts);;
Description
This service retrieves performance information about all memory byte
pools in the system.
Input Parameters
allocates Pointer to destination for the number of allocate
requests performed on this pool.
releases Pointer to destination for the number of release
requests performed on this pool.
fragments_searched Pointer to destination for the total number of
internal memory fragments searched during
allocation requests on all byte pools.
merges Pointer to destination for the total number of
internal memory blocks merged during allocation
requests on all byte pools.
splits Pointer to destination for the total number of
internal memory blocks split (fragments) created
during allocation requests on all byte pools.
suspensions Pointer to destination for the total number of
thread allocation suspensions on all byte pools.
timeouts Pointer to destination for the total number of
allocate suspension timeouts on all byte pools.
User Guide
Memory Bytes 139
Return Values
TX_SUCCESS (0x00) Successful byte pool
performance get.
TX_FEATURE_NOT_ENABLED (0xFF) The system was not compiled
with performance information
enabled.
Allowed From
Initialization, threads, timers, and ISRs
Example
ULONG fragments_searched;
ULONG merges;
ULONG splits;
ULONG allocates;
ULONG releases;
ULONG suspensions;
ULONG timeouts;
See Also
tx_byte_allocate, tx_byte_pool_create, tx_byte_pool_delete,
tx_byte_pool_info_get, tx_byte_pool_performance_info_get,
tx_byte_pool_prioritize, tx_byte_release
tx_byte_pool_prioritize
Prioritize byte pool suspension list
Prototype
UINT tx_byte_pool_prioritize(TX_BYTE_POOL *pool_ptr)
Description
This service places the highest priority thread suspended for memory on
this pool at the front of the suspension list. All other threads remain in the
same FIFO order they were suspended in.
Input Parameters
pool_ptr Pointer to a memory pool control block.
Return Values
TX_SUCCESS (0x00) Successful memory pool prioritize.
TX_POOL_ERROR (0x02) Invalid memory pool pointer.
Allowed From
Initialization, threads, timers, and ISRs
Preemption Possible
No
User Guide
Memory Bytes 141
Example
TX_BYTE_POOL my_pool;
UINT status;
See Also
tx_byte_allocate, tx_byte_pool_create, tx_byte_pool_delete,
tx_byte_pool_info_get, tx_byte_pool_performance_info_get,
tx_byte_pool_performance_system_info_get, tx_byte_release
tx_byte_release
Release bytes back to memory pool
Prototype
UINT tx_byte_release(VOID *memory_ptr)
Description
This service releases a previously allocated memory area back to its
associated pool. If there are one or more threads suspended waiting for
memory from this pool, each suspended thread is given memory and
resumed until the memory is exhausted or until there are no more
suspended threads. This process of allocating memory to suspended
threads always begins with the first thread suspended.
i The application must prevent using the memory area after it is released.
Input Parameters
memory_ptr Pointer to the previously allocated memory area.
Return Values
TX_SUCCESS (0x00) Successful memory release.
TX_PTR_ERROR (0x03) Invalid memory area pointer.
TX_CALLER_ERROR (0x13) Invalid caller of this service.
Allowed From
Initialization and threads
Preemption Possible
Yes
User Guide
Memory Bytes 143
Example
unsigned char *memory_ptr;
UINT status;
See Also
tx_byte_allocate, tx_byte_pool_create, tx_byte_pool_delete,
tx_byte_pool_info_get, tx_byte_pool_performance_info_get,
tx_byte_pool_performance_system_info_get, tx_byte_pool_prioritize
tx_event_flags_create
Create event flags group
Event Flags
Prototype
UINT tx_event_flags_create(TX_EVENT_FLAGS_GROUP *group_ptr,
CHAR *name_ptr)
Description
This service creates a group of 32 event flags. All 32 event flags in the
group are initialized to zero. Each event flag is represented by a single bit.
Input Parameters
group_ptr Pointer to an event flags group control block.
name_ptr Pointer to the name of the event flags group.
Return Values
TX_SUCCESS (0x00) Successful event group creation.
TX_GROUP_ERROR (0x06) Invalid event group pointer. Either the
pointer is NULL or the event group is
already created.
TX_CALLER_ERROR (0x13) Invalid caller of this service.
Allowed From
Initialization and threads
Preemption Possible
No
User Guide
Event Flags 145
Example
TX_EVENT_FLAGS_GROUP my_event_group;
UINT status;
See Also
tx_event_flags_delete, tx_event_flags_get, tx_event_flags_info_get,
tx_event_flags_performance_info_get,
tx_event_flags_performance_system_info_get, tx_event_flags_set,
tx_event_flags_set_notify
tx_event_flags_delete
Delete event flags group
Prototype
UINT tx_event_flags_delete(TX_EVENT_FLAGS_GROUP *group_ptr)
Description
This service deletes the specified event flags group. All threads
suspended waiting for events from this group are resumed and given a
TX_DELETED return status.
Input Parameters
group_ptr Pointer to a previously created event flags group.
Return Values
TX_SUCCESS (0x00) Successful event flags group deletion.
TX_GROUP_ERROR (0x06) Invalid event flags group pointer.
TX_CALLER_ERROR (0x13) Invalid caller of this service.
Allowed From
Threads
Preemption Possible
Yes
User Guide
Event Flags 147
Example
TX_EVENT_FLAGS_GROUP my_event_flags_group;
UINT status;
See Also
tx_event_flags_create, tx_event_flags_get, tx_event_flags_info_get,
tx_event_flags_performance_info_get,
tx_event_flags_performance_system_info_get, tx_event_flags_set,
tx_event_flags_set_notify
tx_event_flags_get
Get event flags from event flags group
Prototype
UINT tx_event_flags_get(TX_EVENT_FLAGS_GROUP *group_ptr,
ULONG requested_flags, UINT get_option,
ULONG *actual_flags_ptr, ULONG wait_option)
Description
This service retrieves event flags from the specified event flags group.
Each event flags group contains 32 event flags. Each flag is represented
by a single bit. This service can retrieve a variety of event flag
combinations, as selected by the input parameters.
Input Parameters
group_ptr Pointer to a previously created event flags group.
requested_flags 32-bit unsigned variable that represents the
requested event flags.
get_option Specifies whether all or any of the requested
event flags are required. The following are valid
selections:
TX_AND (0x02)
TX_AND_CLEAR (0x03)
TX_OR (0x00)
TX_OR_CLEAR (0x01)
Selecting TX_AND or TX_AND_CLEAR
specifies that all event flags must be present in
the group. Selecting TX_OR or TX_OR_CLEAR
specifies that any event flag is satisfactory. Event
flags that satisfy the request are cleared (set to
zero) if TX_AND_CLEAR or TX_OR_CLEAR are
specified.
actual_flags_ptr Pointer to destination of where the retrieved
event flags are placed. Note that the actual flags
obtained may contain flags that were not
requested.
User Guide
Event Flags 149
Return Values
TX_SUCCESS (0x00) Successful event flags get.
TX_DELETED (0x01) Event flags group was deleted while
thread was suspended.
TX_NO_EVENTS (0x07) Service was unable to get the
specified events within the specified
time to wait.
TX_WAIT_ABORTED (0x1A) Suspension was aborted by another
thread, timer, or ISR.
TX_GROUP_ERROR (0x06) Invalid event flags group pointer.
TX_PTR_ERROR (0x03) Invalid pointer for actual event flags.
TX_WAIT_ERROR (0x04) A wait option other than TX_NO_WAIT
was specified on a call from a non-
thread.
TX_OPTION_ERROR (0x08) Invalid get-option was specified.
Allowed From
Initialization, threads, timers, and ISRs
Preemption Possible
Yes
Example
TX_EVENT_FLAGS_GROUP my_event_flags_group;
ULONG actual_events;
UINT status;
See Also
tx_event_flags_create, tx_event_flags_delete, tx_event_flags_info_get,
tx_event_flags_performance_info_get,
tx_event_flags_performance_system_info_get, tx_event_flags_set,
tx_event_flags_set_notify
User Guide
Event Flags 151
tx_event_flags_info_get
Retrieve information about event flags group
Event Flags
Prototype
UINT tx_event_flags_info_get(TX_EVENT_FLAGS_GROUP *group_ptr,
CHAR **name, ULONG *current_flags,
TX_THREAD **first_suspended,
ULONG *suspended_count,
TX_EVENT_FLAGS_GROUP **next_group)
Description
This service retrieves information about the specified event flags group.
Input Parameters
group_ptr Pointer to an event flags group control block.
name Pointer to destination for the pointer to the event
flags group’s name.
current_flags Pointer to destination for the current set flags in
the event flags group.
first_suspended Pointer to destination for the pointer to the thread
that is first on the suspension list of this event
flags group.
suspended_count Pointer to destination for the number of threads
currently suspended on this event flags group.
next_group Pointer to destination for the pointer of the next
created event flags group.
User Guide
Event Flags 153
Return Values
TX_SUCCESS (0x00) Successful event group information
retrieval.
TX_GROUP_ERROR (0x06) Invalid event group pointer.
Allowed From
Initialization, threads, timers, and ISRs
Preemption Possible
No
Example
TX_EVENT_FLAGS_GROUP my_event_group;
CHAR *name;
ULONG current_flags;
TX_THREAD *first_suspended;
ULONG suspended_count;
TX_EVENT_FLAGS_GROUP *next_group;
UINT status;
See Also
tx_event_flags_create, tx_event_flags_delete, tx_event_flags_get,
tx_event_flags_performance_info_get,
tx_event_flags_performance_system_info_get, tx_event_flags_set,
tx_event_flags_set_notify
tx_event_flags_performance info_get
Get event flags group performance information
Event Flags
Prototype
UINT tx_event_flags_performance_info_get(TX_EVENT_FLAGS_GROUP
*group_ptr, ULONG *sets, ULONG *gets,
ULONG *suspensions, ULONG *timeouts);
Description
This service retrieves performance information about the specified event
flags group.
Input Parameters
group_ptr Pointer to previously created event flags group.
sets Pointer to destination for the number of event
flags set requests performed on this group.
gets Pointer to destination for the number of event
flags get requests performed on this group.
suspensions Pointer to destination for the number of thread
event flags get suspensions on this group.
timeouts Pointer to destination for the number of event
flags get suspension timeouts on this group.
User Guide
Event Flags 155
Return Values
TX_SUCCESS (0x00) Successful event flags group
performance get.
TX_PTR_ERROR (0x03) Invalid event flags group pointer.
TX_FEATURE_NOT_ENABLED (0xFF) The system was not compiled
with performance information
enabled.
Allowed From
Initialization, threads, timers, and ISRs
Example
TX_EVENT_FLAGS_GROUP my_event_flag_group;
ULONG sets;
ULONG gets;
ULONG suspensions;
ULONG timeouts;
See Also
tx_event_flags_create, tx_event_flags_delete, tx_event_flags_get,
tx_event_flags_info_get, tx_event_flags_performance_system_info_get,
tx_event_flags_set, tx_event_flags_set_notify
tx_event_flags_performance_system_info_get
Retrieve performance system information
Event Flags
Prototype
UINT tx_event_flags_performance_system_info_get(ULONG *sets,
ULONG *gets,ULONG *suspensions, ULONG *timeouts);
Description
This service retrieves performance information about all event flags
groups in the system.
Input Parameters
sets Pointer to destination for the total number of
event flags set requests performed on all groups.
gets Pointer to destination for the total number of
event flags get requests performed on all groups.
suspensions Pointer to destination for the total number of
thread event flags get suspensions on all groups.
timeouts Pointer to destination for the total number of
event flags get suspension timeouts on all
groups.
Return Values
TX_SUCCESS (0x00) Successful event flags
system performance get.
TX_FEATURE_NOT_ENABLED (0xFF) The system was not
compiled with performance
information enabled.
User Guide
Event Flags 157
Allowed From
Initialization, threads, timers, and ISRs
Example
ULONG sets;
ULONG gets;
ULONG suspensions;
ULONG timeouts;
See Also
tx_event_flags_create, tx_event_flags_delete, tx_event_flags_get,
tx_event_flags_info_get, tx_event_flags_performance_info_get,
tx_event_flags_set, tx_event_flags_set_notify
tx_event_flags_set
Set event flags in an event flags group
Prototype
UINT tx_event_flags_set(TX_EVENT_FLAGS_GROUP *group_ptr,
ULONG flags_to_set,UINT set_option)
Description
This service sets or clears event flags in an event flags group, depending
upon the specified set-option. All suspended threads whose event flags
request is now satisfied are resumed.
Input Parameters
group_ptr Pointer to the previously created event flags
group control block.
flags_to_set Specifies the event flags to set or clear based
upon the set option selected.
set_option Specifies whether the event flags specified are
ANDed or ORed into the current event flags of
the group. The following are valid selections:
TX_AND (0x02)
TX_OR (0x00)
Selecting TX_AND specifies that the specified
event flags are ANDed into the current event
flags in the group. This option is often used to
clear event flags in a group. Otherwise, if TX_OR
is specified, the specified event flags are ORed
with the current event in the group.
Return Values
TX_SUCCESS (0x00) Successful event flags set.
TX_GROUP_ERROR (0x06) Invalid pointer to event flags group.
TX_OPTION_ERROR (0x08) Invalid set-option specified.
User Guide
Event Flags 159
Allowed From
Initialization, threads, timers, and ISRs
Preemption Possible
Yes
Example
TX_EVENT_FLAGS_GROUP my_event_flags_group;
UINT status;
See Also
tx_event_flags_create, tx_event_flags_delete, tx_event_flags_get,
tx_event_flags_info_get, tx_event_flags_performance_info_get,
tx_event_flags_performance_system_info_get, tx_event_flags_set_notify
tx_event_flags_set_notify
Notify application when event flags are set
Prototype
UINT tx_event_flags_set_notify(TX_EVENT_FLAGS_GROUP *group_ptr,
VOID (*events_set_notify)(TX_EVENT_FLAGS_GROUP *));
Description
This service registers a notification callback function that is called
whenever one or more event flags are set in the specified event flags
group. The processing of the notification callback is defined by the
application.
Input Parameters
group_ptr Pointer to previously created event flags group.
events_set_notify Pointer to application’s event flags set
notification function. If this value is TX_NULL,
notification is disabled.
Return Values
TX_SUCCESS (0x00) Successful registration of event
flags set notification.
TX_GROUP_ERROR (0x06) Invalid event flags group pointer.
TX_FEATURE_NOT_ENABLED(0xFF) The system was compiled with
notification capabilities disabled.
User Guide
Event Flags 161
Allowed From
Initialization, threads, timers, and ISRs
Example
TX_EVENT_FLAGS_GROUP my_group;
See Also
tx_event_flags_create, tx_event_flags_delete, tx_event_flags_get,
tx_event_flags_info_get, tx_event_flags_performance_info_get,
tx_event_flags_performance_system_info_get, tx_event_flags_set
tx_interrupt_control
Enable and disable interrupts
Interrupt Control
Prototype
UINT tx_interrupt_control(UINT new_posture)
Description
This service enables or disables interrupts as specified by the input
parameter new_posture.
Input Parameters
new_posture This parameter specifies whether interrupts are
disabled or enabled. Legal values include
TX_INT_DISABLE and TX_INT_ENABLE. The
actual values for these parameters are port
specific. In addition, some processing
architectures might support additional interrupt
disable postures. Please see the
readme_threadx.txt information supplied on the
distribution disk for more details.
Return Values
previous posture This service returns the previous interrupt
posture to the caller. This allows users of the
service to restore the previous posture after
interrupts are disabled.
User Guide
Interrupt Control 163
Allowed From
Threads, timers, and ISRs
Preemption Possible
No
Example
UINT my_old_posture;
/* Lockout interrupts */
my_old_posture = tx_interrupt_control(TX_INT_DISABLE);
See Also
None
tx_mutex_create
Create mutual exclusion mutex
Mutex
Prototype
UINT tx_mutex_create(TX_MUTEX *mutex_ptr,
CHAR *name_ptr, UINT priority_inherit)
Description
This service creates a mutex for inter-thread mutual exclusion for
resource protection.
Input Parameters
mutex_ptr Pointer to a mutex control block.
name_ptr Pointer to the name of the mutex.
priority_inherit Specifies whether or not this mutex supports
priority inheritance. If this value is TX_INHERIT,
then priority inheritance is supported. However, if
TX_NO_INHERIT is specified, priority
inheritance is not supported by this mutex.
Return Values
TX_SUCCESS (0x00) Successful mutex creation.
TX_MUTEX_ERROR (0x1C) Invalid mutex pointer. Either the
pointer is NULL or the mutex is already
created.
TX_CALLER_ERROR (0x13) Invalid caller of this service.
TX_INHERIT_ERROR (0x1F) Invalid priority inherit parameter.
Allowed From
Initialization and threads
Preemption Possible
No
User Guide
Mutex 165
Example
TX_MUTEX my_mutex;
UINT status;
See Also
tx_mutex_delete, tx_mutex_get, tx_mutex_info_get,
tx_mutex_performance_info_get,
tx_mutex_performance_system_info_get, tx_mutex_prioritize,
tx_mutex_put
tx_mutex_delete
Delete mutual exclusion mutex
Prototype
UINT tx_mutex_delete(TX_MUTEX *mutex_ptr)
Description
This service deletes the specified mutex. All threads suspended waiting
for the mutex are resumed and given a TX_DELETED return status.
Input Parameters
mutex_ptr Pointer to a previously created mutex.
Return Values
TX_SUCCESS (0x00) Successful mutex deletion.
TX_MUTEX_ERROR (0x1C) Invalid mutex pointer.
TX_CALLER_ERROR (0x13) Invalid caller of this service.
Allowed From
Threads
Preemption Possible
Yes
User Guide
Mutex 167
Example
TX_MUTEX my_mutex;
UINT status;
See Also
tx_mutex_create, tx_mutex_get, tx_mutex_info_get,
tx_mutex_performance_info_get,
tx_mutex_performance_system_info_get, tx_mutex_prioritize,
tx_mutex_put
tx_mutex_get
Obtain ownership of mutex
Prototype
UINT tx_mutex_get(TX_MUTEX *mutex_ptr, ULONG wait_option)
Description
This service attempts to obtain exclusive ownership of the specified
mutex. If the calling thread already owns the mutex, an internal counter is
incremented and a successful status is returned.
If the mutex is owned by another thread and this thread is higher priority
and priority inheritance was specified at mutex create, the lower priority
thread’s priority will be temporarily raised to that of the calling thread.
The priority of the lower priority thread owning a mutex with priority-
i inheritance should never be modified by an external thread during mutex
ownership.
Input Parameters
mutex_ptr Pointer to a previously created mutex.
wait_option Defines how the service behaves if the mutex is
already owned by another thread. The wait
options are defined as follows:
TX_NO_WAIT (0x00000000)
TX_WAIT_FOREVER (0xFFFFFFFF)
timeout value (0x00000001 through
0xFFFFFFFE)
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 Initialization.
Selecting TX_WAIT_FOREVER causes the
calling thread to suspend indefinitely until the
mutex is available.
Selecting a numeric value (1-0xFFFFFFFE)
specifies the maximum number of timer-ticks to
stay suspended while waiting for the mutex.
User Guide
Mutex 169
Return Values
TX_SUCCESS (0x00) Successful mutex get operation.
TX_DELETED (0x01) Mutex was deleted while thread was
suspended.
TX_NOT_AVAILABLE (0x1D) Service was unable to get ownership
of the mutex within the specified time
to wait.
TX_WAIT_ABORTED (0x1A) Suspension was aborted by another
thread, timer, or ISR.
TX_MUTEX_ERROR (0x1C) Invalid mutex pointer.
TX_WAIT_ERROR (0x04) A wait option other than TX_NO_WAIT
was specified on a call from a non-
thread.
TX_CALLER_ERROR (0x13) Invalid caller of this service.
Allowed From
Initialization and threads and timers
Preemption Possible
Yes
Example
TX_MUTEX my_mutex;
UINT status;
See Also
tx_mutex_create, tx_mutex_delete, tx_mutex_info_get,
tx_mutex_performance_info_get,
tx_mutex_performance_system_info_get, tx_mutex_prioritize,
tx_mutex_put
tx_mutex_info_get
Retrieve information about mutex
Prototype
UINT tx_mutex_info_get(TX_MUTEX *mutex_ptr, CHAR **name,
ULONG *count, TX_THREAD **owner,
TX_THREAD **first_suspended,
ULONG *suspended_count, TX_MUTEX **next_mutex)
Description
This service retrieves information from the specified mutex.
Input Parameters
mutex_ptr Pointer to mutex control block.
name Pointer to destination for the pointer to the
mutex’s name.
count Pointer to destination for the ownership count of
the mutex.
owner Pointer to destination for the owning thread’s
pointer.
first_suspended Pointer to destination for the pointer to the thread
that is first on the suspension list of this mutex.
suspended_count Pointer to destination for the number of threads
currently suspended on this mutex.
next_mutex Pointer to destination for the pointer of the next
created mutex.
i not required.
Return Values
TX_SUCCESS (0x00) Successful mutex information
retrieval.
TX_MUTEX_ERROR (0x1C) Invalid mutex pointer.
User Guide
Mutex 171
Allowed From
Initialization, threads, timers, and ISRs
Preemption Possible
No
Example
TX_MUTEX my_mutex;
CHAR *name;
ULONG count;
TX_THREAD *owner;
TX_THREAD *first_suspended;
ULONG suspended_count;
TX_MUTEX *next_mutex;
UINT status;
See Also
tx_mutex_create, tx_mutex_delete, tx_mutex_get,
tx_mutex_performance_info_get,
tx_mutex_performance_system_info_get, tx_mutex_prioritize,
tx_mutex_put
tx_mutex_performance_info_get
Get mutex performance information
Prototype
UINT tx_mutex_performance_info_get(TX_MUTEX *mutex_ptr, ULONG *puts,
ULONG *gets, ULONG *suspensions, ULONG *timeouts,
ULONG *inversions, ULONG *inheritances);
Description
This service retrieves performance information about the specified mutex.
Input Parameters
mutex_ptr Pointer to previously created mutex.
puts Pointer to destination for the number of put
requests performed on this mutex.
gets Pointer to destination for the number of get
requests performed on this mutex.
suspensions Pointer to destination for the number of thread
mutex get suspensions on this mutex.
timeouts Pointer to destination for the number of mutex
get suspension timeouts on this mutex.
inversions Pointer to destination for the number of thread
priority inversions on this mutex.
inheritances Pointer to destination for the number of thread
priority inheritance operations on this mutex.
User Guide
Mutex 173
Return Values
TX_SUCCESS (0x00) Successful mutex
performance get.
TX_PTR_ERROR (0x03) Invalid mutex pointer.
TX_FEATURE_NOT_ENABLED (0xFF) The system was not
compiled with performance
information enabled.
Allowed From
Initialization, threads, timers, and ISRs
Example
TX_MUTEX my_mutex;
ULONG puts;
ULONG gets;
ULONG suspensions;
ULONG timeouts;
ULONG inversions;
ULONG inheritances;
See Also
tx_mutex_create, tx_mutex_delete, tx_mutex_get, tx_mutex_info_get,
tx_mutex_performance_system_info_get, tx_mutex_prioritize,
tx_mutex_put
tx_mutex_performance_system_info_get
Get mutex system performance information
Prototype
UINT tx_mutex_performance_system_info_get(ULONG *puts, ULONG *gets,
ULONG *suspensions, ULONG *timeouts,
ULONG *inversions, ULONG *inheritances);
Description
This service retrieves performance information about all the mutexes in
the system.
Input Parameters
puts Pointer to destination for the total number of put
requests performed on all mutexes.
gets Pointer to destination for the total number of get
requests performed on all mutexes.
suspensions Pointer to destination for the total number of
thread mutex get suspensions on all mutexes.
timeouts Pointer to destination for the total number of
mutex get suspension timeouts on all mutexes.
inversions Pointer to destination for the total number of
thread priority inversions on all mutexes.
inheritances Pointer to destination for the total number of
thread priority inheritance operations on all
mutexes.
User Guide
Mutex 175
Return Values
TX_SUCCESS (0x00) Successful mutex system
performance get.
TX_FEATURE_NOT_ENABLED (0xFF) The system was not
compiled with performance
information enabled.
Allowed From
Initialization, threads, timers, and ISRs
Example
ULONG puts;
ULONG gets;
ULONG suspensions;
ULONG timeouts;
ULONG inversions;
ULONG inheritances;
See Also
tx_mutex_create, tx_mutex_delete, tx_mutex_get, tx_mutex_info_get,
tx_mutex_performance_info_get, tx_mutex_prioritize, tx_mutex_put
tx_mutex_prioritize
Prioritize mutex suspension list
Prototype
UINT tx_mutex_prioritize(TX_MUTEX *mutex_ptr)
Description
This service places the highest priority thread suspended for ownership of
the mutex at the front of the suspension list. All other threads remain in
the same FIFO order they were suspended in.
Input Parameters
mutex_ptr Pointer to the previously created mutex.
Return Values
TX_SUCCESS (0x00) Successful mutex prioritize.
TX_MUTEX_ERROR (0x1C) Invalid mutex pointer.
Allowed From
Initialization, threads, timers, and ISRs
Preemption Possible
No
User Guide
Mutex 177
Example
TX_MUTEX my_mutex;
UINT status;
See Also
tx_mutex_create, tx_mutex_delete, tx_mutex_get, tx_mutex_info_get,
tx_mutex_performance_info_get,
tx_mutex_performance_system_info_get, tx_mutex_put
tx_mutex_put
Release ownership of mutex
Prototype
UINT tx_mutex_put(TX_MUTEX *mutex_ptr)
Description
This service decrements the ownership count of the specified mutex. If
the ownership count is zero, the mutex is made available.
Input Parameters
mutex_ptr Pointer to the previously created mutex.
Return Values
TX_SUCCESS (0x00) Successful mutex release.
TX_NOT_OWNED (0x1E) Mutex is not owned by caller.
TX_MUTEX_ERROR (0x1C) Invalid pointer to mutex.
TX_CALLER_ERROR (0x13) Invalid caller of this service.
Allowed From
Initialization and threads
Preemption Possible
Yes
User Guide
Mutex 179
Example
TX_MUTEX my_mutex;
UINT status;
See Also
tx_mutex_create, tx_mutex_delete, tx_mutex_get, tx_mutex_info_get,
tx_mutex_performance_info_get,
tx_mutex_performance_system_info_get, tx_mutex_prioritize
tx_queue_create
Create message queue
Message Queues
Prototype
UINT tx_queue_create(TX_QUEUE *queue_ptr, CHAR *name_ptr,
UINT message_size,
VOID *queue_start, ULONG queue_size)
Description
This service creates a message queue that is typically used for inter-
thread communication. The total number of messages is calculated from
the specified message size and the total number of bytes in the queue.
If the total number of bytes specified in the queue’s memory area is not
i evenly divisible by the specified message size, the remaining bytes in the
memory area are not used.
Input Parameters
queue_ptr Pointer to a message queue control block.
name_ptr Pointer to the name of the message queue.
message_size Specifies the size of each message in the queue.
Message sizes range from 1 32-bit word to 16
32-bit words. Valid message size options are
numerical values from 1 through 16, inclusive.
queue_start Starting address of the message queue.
queue_size Total number of bytes available for the message
queue.
User Guide
Message Queues 181
Return Values
TX_SUCCESS (0x00) Successful message queue creation.
TX_QUEUE_ERROR (0x09) Invalid message queue pointer. Either
the pointer is NULL or the queue is
already created.
TX_PTR_ERROR (0x03) Invalid starting address of the
message queue.
TX_SIZE_ERROR (0x05) Size of message queue is invalid.
TX_CALLER_ERROR (0x13) Invalid caller of this service.
Allowed From
Initialization and threads
Preemption Possible
No
Example
TX_QUEUE my_queue;
UINT status;
See Also
tx_queue_delete, tx_queue_flush, tx_queue_front_send,
tx_queue_info_get, tx_queue_performance_info_get,
tx_queue_performance_system_info_get, tx_queue_prioritize,
tx_queue_receive, tx_queue_send, tx_queue_send_notify
tx_queue_delete
Delete message queue
Prototype
UINT tx_queue_delete(TX_QUEUE *queue_ptr)
Description
This service deletes the specified message queue. All threads suspended
waiting for a message from this queue are resumed and given a
TX_DELETED return status.
Input Parameters
queue_ptr Pointer to a previously created message queue.
Return Values
TX_SUCCESS (0x00) Successful message queue deletion.
TX_QUEUE_ERROR (0x09) Invalid message queue pointer.
TX_CALLER_ERROR (0x13) Invalid caller of this service.
Allowed From
Threads
Preemption Possible
Yes
User Guide
Message Queues 183
Example
TX_QUEUE my_queue;
UINT status;
See Also
tx_queue_create, tx_queue_flush, tx_queue_front_send,
tx_queue_info_get, tx_queue_performance_info_get,
tx_queue_performance_system_info_get, tx_queue_prioritize,
tx_queue_receive, tx_queue_send, tx_queue_send_notify
tx_queue_flush
Empty messages in message queue
Prototype
UINT tx_queue_flush(TX_QUEUE *queue_ptr)
Description
This service deletes all messages stored in the specified message queue.
If the queue is full, messages of all suspended threads are discarded.
Each suspended thread is then resumed with a return status that
indicates the message send was successful. If the queue is empty, this
service does nothing.
Input Parameters
queue_ptr Pointer to a previously created message queue.
Return Values
TX_SUCCESS (0x00) Successful message queue flush.
TX_QUEUE_ERROR (0x09) Invalid message queue pointer.
Allowed From
Initialization, threads, timers, and ISRs
Preemption Possible
Yes
User Guide
Message Queues 185
Example
TX_QUEUE my_queue;
UINT status;
See Also
tx_queue_create, tx_queue_delete, tx_queue_front_send,
tx_queue_info_get, tx_queue_performance_info_get,
tx_queue_performance_system_info_get, tx_queue_prioritize,
tx_queue_receive, tx_queue_send, tx_queue_send_notify
tx_queue_front_send
Send message to the front of queue
Message Queues
Prototype
UINT tx_queue_front_send(TX_QUEUE *queue_ptr,
VOID *source_ptr, ULONG wait_option)
Description
This service sends a message to the front location of the specified
message queue. The message is copied to the front of the queue from
the memory area specified by the source pointer.
Input Parameters
queue_ptr Pointer to a message queue control block.
source_ptr Pointer to the message.
wait_option Defines how the service behaves if the message
queue is full. The wait options are defined as
follows:
TX_NO_WAIT (0x00000000)
TX_WAIT_FOREVER (0xFFFFFFFF)
timeout value (0x00000001 through
0xFFFFFFFE)
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 there is
room in the queue.
Selecting a numeric value (1-0xFFFFFFFE)
specifies the maximum number of timer-ticks to
stay suspended while waiting for room in the
queue.
User Guide
Message Queues 187
Return Values
TX_SUCCESS (0x00) Successful sending of message.
TX_DELETED (0x01) Message queue was deleted while
thread was suspended.
TX_QUEUE_FULL (0x0B) Service was unable to send message
because the queue was full for the
duration of the specified time to wait.
TX_WAIT_ABORTED (0x1A) Suspension was aborted by another
thread, timer, or ISR.
TX_QUEUE_ERROR (0x09) Invalid message queue pointer.
TX_PTR_ERROR (0x03) Invalid source pointer for message.
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_QUEUE my_queue;
UINT status;
ULONG my_message[4];
See Also
tx_queue_create, tx_queue_delete, tx_queue_flush, tx_queue_info_get,
tx_queue_performance_info_get,
tx_queue_performance_system_info_get, tx_queue_prioritize,
tx_queue_receive, tx_queue_send, tx_queue_send_notify
User Guide
Message Queues 189
tx_queue_info_get
Retrieve information about queue
Prototype
UINT tx_queue_info_get(TX_QUEUE *queue_ptr, CHAR **name,
ULONG *enqueued, ULONG *available_storage
TX_THREAD **first_suspended, ULONG *suspended_count,
TX_QUEUE **next_queue)
Description
This service retrieves information about the specified message queue.
Input Parameters
queue_ptr Pointer to a previously created message queue.
name Pointer to destination for the pointer to the
queue’s name.
enqueued Pointer to destination for the number of
messages currently in the queue.
available_storage Pointer to destination for the number of
messages the queue currently has space for.
first_suspended Pointer to destination for the pointer to the thread
that is first on the suspension list of this queue.
suspended_count Pointer to destination for the number of threads
currently suspended on this queue.
next_queue Pointer to destination for the pointer of the next
created queue.
i not required.
Return Values
TX_SUCCESS (0x00) Successful queue information get.
TX_QUEUE_ERROR (0x09) Invalid message queue pointer.
User Guide
Message Queues 191
Allowed From
Initialization, threads, timers, and ISRs
Preemption Possible
No
Example
TX_QUEUE my_queue;
CHAR *name;
ULONG enqueued;
ULONG available_storage;
TX_THREAD *first_suspended;
ULONG suspended_count;
TX_QUEUE *next_queue;
UINT status;
See Also
tx_queue_create, tx_queue_delete, tx_queue_flush,
tx_queue_front_send, tx_queue_performance_info_get,
tx_queue_performance_system_info_get, tx_queue_prioritize,
tx_queue_receive, tx_queue_send, tx_queue_send_notify
tx_queue_performance_info_get
Get queue performance information
Prototype
UINT tx_queue_performance_info_get(TX_QUEUE *queue_ptr,
ULONG *messages_sent, ULONG *messages_received,
ULONG *empty_suspensions, ULONG *full_suspensions,
ULONG *full_errors, ULONG *timeouts);
Description
This service retrieves performance information about the specified queue.
Input Parameters
queue_ptr Pointer to previously created queue.
messages_sent Pointer to destination for the number of send
requests performed on this queue.
messages_received Pointer to destination for the number of receive
requests performed on this queue.
empty_suspensions Pointer to destination for the number of queue
empty suspensions on this queue.
full_suspensions Pointer to destination for the number of queue
full suspensions on this queue.
full_errors Pointer to destination for the number of queue
full errors on this queue.
timeouts Pointer to destination for the number of thread
suspension timeouts on this queue.
User Guide
Message Queues 193
Return Values
TX_SUCCESS (0x00) Successful queue performance
get.
TX_PTR_ERROR (0x03) Invalid queue pointer.
TX_FEATURE_NOT_ENABLED(0xFF) The system was not compiled
with performance information
enabled.
Allowed From
Initialization, threads, timers, and ISRs
Example
TX_QUEUE my_queue;
ULONG messages_sent;
ULONG messages_received;
ULONG empty_suspensions;
ULONG full_suspensions;
ULONG full_errors;
ULONG timeouts;
See Also
tx_queue_create, tx_queue_delete, tx_queue_flush,
tx_queue_front_send, tx_queue_info_get,
tx_queue_performance_system_info_get, tx_queue_prioritize,
tx_queue_receive, tx_queue_send, tx_queue_send_notify
tx_queue_performance_system_info_get
Get queue system performance information
Prototype
UINT tx_queue_performance_system_info_get(ULONG *messages_sent,
ULONG *messages_received, ULONG *empty_suspensions,
ULONG *full_suspensions, ULONG *full_errors,
ULONG *timeouts);
Description
This service retrieves performance information about all the queues in the
system.
Input Parameters
messages_sent Pointer to destination for the total number of
send requests performed on all queues.
messages_received Pointer to destination for the total number of
receive requests performed on all queues.
empty_suspensions Pointer to destination for the total number of
queue empty suspensions on all queues.
full_suspensions Pointer to destination for the total number of
queue full suspensions on all queues.
full_errors Pointer to destination for the total number of
queue full errors on all queues.
timeouts Pointer to destination for the total number of
thread suspension timeouts on all queues.
User Guide
Message Queues 195
Return Values
TX_SUCCESS (0x00) Successful queue system
performance get.
TX_FEATURE_NOT_ENABLED (0xFF) The system was not
compiled with performance
information enabled.
Allowed From
Initialization, threads, timers, and ISRs
Example
ULONG messages_sent;
ULONG messages_received;
ULONG empty_suspensions;
ULONG full_suspensions;
ULONG full_errors;
ULONG timeouts;
/* Retrieve performance information on all previously created
queues. */
status = tx_queue_performance_system_info_get(&messages_sent,
&messages_received, &empty_suspensions,
&full_suspensions, &full_errors, &timeouts);
See Also
tx_queue_create, tx_queue_delete, tx_queue_flush,
tx_queue_front_send, tx_queue_info_get,
tx_queue_performance_info_get, tx_queue_prioritize, tx_queue_receive,
tx_queue_send, tx_queue_send_notify
tx_queue_prioritize
Prioritize queue suspension list
Prototype
UINT tx_queue_prioritize(TX_QUEUE *queue_ptr)
Description
This service places the highest priority thread suspended for a message
(or to place a message) on this queue at the front of the suspension list.
All other threads remain in the same FIFO order they were suspended in.
Input Parameters
queue_ptr Pointer to a previously created message queue.
Return Values
TX_SUCCESS (0x00) Successful queue prioritize.
TX_QUEUE_ERROR (0x09) Invalid message queue pointer.
Allowed From
Initialization, threads, timers, and ISRs
Preemption Possible
No
User Guide
Message Queues 197
Example
TX_QUEUE my_queue;
UINT status;
See Also
tx_queue_create, tx_queue_delete, tx_queue_flush,
tx_queue_front_send, tx_queue_info_get,
tx_queue_performance_info_get,
tx_queue_performance_system_info_get, tx_queue_receive,
tx_queue_send, tx_queue_send_notify
tx_queue_receive
Get message from message queue
Prototype
UINT tx_queue_receive(TX_QUEUE *queue_ptr,
VOID *destination_ptr, ULONG wait_option)
Description
This service retrieves a message from the specified message queue. The
retrieved message is copied from the queue into the memory area
specified by the destination pointer. That message is then removed from
the queue.
The specified destination memory area must be large enough to hold the
i message; i.e., the message destination pointed to by destination_ptr
must be at least as large as the message size for this queue. Otherwise,
if the destination is not large enough, memory corruption occurs in the
following memory area.
Input Parameters
queue_ptr Pointer to a previously created message queue.
destination_ptr Location of where to copy the message.
wait_option Defines how the service behaves if the message
queue is empty. The wait options are defined as
follows:
TX_NO_WAIT (0x00000000)
TX_WAIT_FOREVER (0xFFFFFFFF)
timeout value (0x00000001
through
0xFFFFFFFE)
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
message is available.
User Guide
Message Queues 199
Return Values
TX_SUCCESS (0x00) Successful retrieval of message.
TX_DELETED (0x01) Message queue was deleted while
thread was suspended.
TX_QUEUE_EMPTY (0x0A) Service was unable to retrieve a
message because the queue was
empty for the duration of the specified
time to wait.
TX_WAIT_ABORTED (0x1A) Suspension was aborted by another
thread, timer, or ISR.
TX_QUEUE_ERROR (0x09) Invalid message queue pointer.
TX_PTR_ERROR (0x03) Invalid destination pointer for
message.
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_QUEUE my_queue;
UINT status;
ULONG my_message[4];
See Also
tx_queue_create, tx_queue_delete, tx_queue_flush,
tx_queue_front_send, tx_queue_info_get,
tx_queue_performance_info_get,
tx_queue_performance_system_info_get, tx_queue_prioritize,
tx_queue_send, tx_queue_send_notify
User Guide
Message Queues 201
tx_queue_send
Send message to message queue
Prototype
UINT tx_queue_send(TX_QUEUE *queue_ptr,
VOID *source_ptr, ULONG wait_option)
Description
This service sends a message to the specified message queue. The sent
message is copied to the queue from the memory area specified by the
source pointer.
Input Parameters
queue_ptr Pointer to a previously created message queue.
source_ptr Pointer to the message.
wait_option Defines how the service behaves if the message
queue is full. The wait options are defined as
follows:
TX_NO_WAIT (0x00000000)
TX_WAIT_FOREVER (0xFFFFFFFF)
timeout value (0x00000001 through
0xFFFFFFFE)
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 there is
room in the queue.
Selecting a numeric value (1-0xFFFFFFFE)
specifies the maximum number of timer-ticks to
stay suspended while waiting for room in the
queue.
User Guide
Message Queues 203
Return Values
TX_SUCCESS (0x00) Successful sending of message.
TX_DELETED (0x01) Message queue was deleted while
thread was suspended.
TX_QUEUE_FULL (0x0B) Service was unable to send message
because the queue was full for the
duration of the specified time to wait.
TX_WAIT_ABORTED (0x1A) Suspension was aborted by another
thread, timer, or ISR.
TX_QUEUE_ERROR (0x09) Invalid message queue pointer.
TX_PTR_ERROR (0x03) Invalid source pointer for message.
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_QUEUE my_queue;
UINT status;
ULONG my_message[4];
See Also
tx_queue_create, tx_queue_delete, tx_queue_flush,
tx_queue_front_send, tx_queue_info_get,
tx_queue_performance_info_get,
tx_queue_performance_system_info_get, tx_queue_prioritize,
tx_queue_receive, tx_queue_send_notify
User Guide
Message Queues 205
tx_queue_send_notify
Notify application when message is sent to queue
Prototype
UINT tx_queue_send_notify(TX_QUEUE *queue_ptr,
VOID (*queue_send_notify)(TX_QUEUE *));
Description
This service registers a notification callback function that is called
whenever a message is sent to the specified queue. The processing of
the notification callback is defined by the application.
Input Parameters
queue_ptr Pointer to previously created queue.
queue_send_notify Pointer to application’s queue send notification
function. If this value is TX_NULL, notification is
disabled.
Return Values
TX_SUCCESS (0x00) Successful registration of
queue send notification.
TX_QUEUE_ERROR (0x09) Invalid queue pointer.
TX_FEATURE_NOT_ENABLED(0xFF) The system was compiled
with notification capabilities
disabled.
Allowed From
Initialization, threads, timers, and ISRs
User Guide
Message Queues 207
Example
TX_QUEUE my_queue;
See Also
tx_queue_create, tx_queue_delete, tx_queue_flush,
tx_queue_front_send, tx_queue_info_get,
tx_queue_performance_info_get,
tx_queue_performance_system_info_get, tx_queue_prioritize,
tx_queue_receive, tx_queue_send
tx_semaphore_ceiling_put
Place an instance in counting semaphore with ceiling
Counting Sem aphores
Prototype
UINT tx_semaphore_ceiling_put(TX_SEMAPHORE *semaphore_ptr,
ULONG ceiling);
Description
This service puts an instance into the specified counting semaphore,
which in reality increments the counting semaphore by one. If the
counting semaphore’s current value is greater than or equal to the
specified ceiling, the instance will not be put and a
TX_CEILING_EXCEEDED error will be returned.
Input Parameters
semaphore_ptr Pointer to previously created semaphore.
ceiling Maximum limit allowed for the semaphore (valid
values range from 1 through 0xFFFFFFFF).
Return Values
TX_SUCCESS (0x00) Successful semaphore ceiling
put.
TX_CEILING_EXCEEDED (0x21) Put request exceeds ceiling.
TX_INVALID_CEILING (0x22) An invalid value of zero was
supplied for ceiling.
TX_SEMAPHORE_ERROR (0x03) Invalid semaphore pointer.
Allowed From
Initialization, threads, timers, and ISRs
User Guide
Counting Semaphores 209
Example
TX_SEMAPHORE my_semaphore;
See Also
tx_semaphore_create, tx_semaphore_delete, tx_semaphore_get,
tx_semaphore_info_get, tx_semaphore_performance_info_get,
tx_semaphore_performance_system_info_get, tx_semaphore_prioritize,
tx_semaphore_put, tx_semaphore_put_notify
tx_semaphore_create
Create counting semaphore
Counting Sem aphores
Prototype
UINT tx_semaphore_create(TX_SEMAPHORE *semaphore_ptr,
CHAR *name_ptr, ULONG initial_count)
Description
This service creates a counting semaphore for inter-thread
synchronization. The initial semaphore count is specified as an input
parameter.
Input Parameters
semaphore_ptr Pointer to a semaphore control block.
name_ptr Pointer to the name of the semaphore.
initial_count Specifies the initial count for this semaphore.
Legal values range from 0x00000000 through
0xFFFFFFFF.
Return Values
TX_SUCCESS (0x00) Successful semaphore
creation.
TX_SEMAPHORE_ERROR (0x0C) Invalid semaphore pointer.
Either the pointer is NULL or
the semaphore is already
created.
TX_CALLER_ERROR (0x13) Invalid caller of this service.
Allowed From
Initialization and threads
Preemption Possible
No
User Guide
Counting Semaphores 211
Example
TX_SEMAPHORE my_semaphore;
UINT status;
See Also
tx_semaphore_ceiling_put, tx_semaphore_delete, tx_semaphore_get,
tx_semaphore_info_get, tx_semaphore_performance_info_get,
tx_semaphore_performance_system_info_get, tx_semaphore_prioritize,
tx_semaphore_put, tx_semaphore_put_notify
tx_semaphore_delete
Delete counting semaphore
Counting Sem aphores
Prototype
UINT tx_semaphore_delete(TX_SEMAPHORE *semaphore_ptr)
Description
This service deletes the specified counting semaphore. All threads
suspended waiting for a semaphore instance are resumed and given a
TX_DELETED return status.
Input Parameters
semaphore_ptr Pointer to a previously created semaphore.
Return Values
TX_SUCCESS (0x00) Successful counting
semaphore deletion.
TX_SEMAPHORE_ERROR (0x0C) Invalid counting semaphore
pointer.
TX_CALLER_ERROR (0x13) Invalid caller of this service.
Allowed From
Threads
Preemption Possible
Yes
User Guide
Counting Semaphores 213
Example
TX_SEMAPHORE my_semaphore;
UINT status;
See Also
tx_semaphore_ceiling_put, tx_semaphore_create, tx_semaphore_get,
tx_semaphore_info_get, tx_semaphore_performance_info_get,
tx_semaphore_performance_system_info_gettx_semaphore_prioritize,
tx_semaphore_put, tx_semaphore_put_notify
tx_semaphore_get
Get instance from counting semaphore
Counting Sem aphores
Prototype
UINT tx_semaphore_get(TX_SEMAPHORE *semaphore_ptr,
ULONG wait_option)
Description
This service retrieves an instance (a single count) from the specified
counting semaphore. As a result, the specified semaphore’s count is
decreased by one.
Input Parameters
semaphore_ptr Pointer to a previously created counting
semaphore.
wait_option Defines how the service behaves if there are no
instances of the semaphore available; i.e., the
semaphore count is zero. The wait options are
defined as follows:
TX_NO_WAIT (0x00000000)
TX_WAIT_FOREVER (0xFFFFFFFF)
timeout value (0x00000001 through
0xFFFFFFFE)
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
semaphore instance is available.
Selecting a numeric value (1-0xFFFFFFFE)
specifies the maximum number of timer-ticks to
stay suspended while waiting for a semaphore
instance.
User Guide
Counting Semaphores 215
Return Values
TX_SUCCESS (0x00) Successful retrieval of a
semaphore instance.
TX_DELETED (0x01) Counting semaphore was
deleted while thread was
suspended.
TX_NO_INSTANCE (0x0D) Service was unable to
retrieve an instance of the
counting semaphore
(semaphore count is zero
within the specified time to
wait).
TX_WAIT_ABORTED (0x1A) Suspension was aborted by
another thread, timer, or
ISR.
TX_SEMAPHORE_ERROR (0x0C) Invalid counting semaphore
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_SEMAPHORE my_semaphore;
UINT status;
See Also
tx_semaphore_ceiling_put, tx_semaphore_create, tx_semahore_delete,
tx_semaphore_info_get, tx_semaphore_performance_info_get,
tx_semaphore_prioritize, tx_semaphore_put, tx_semaphore_put_notify
User Guide
Counting Semaphores 217
tx_semaphore_info_get
Retrieve information about semaphore
Counting Sem aphores
Prototype
UINT tx_semaphore_info_get(TX_SEMAPHORE *semaphore_ptr,
CHAR **name, ULONG *current_value,
TX_THREAD **first_suspended,
ULONG *suspended_count,
TX_SEMAPHORE **next_semaphore)
Description
This service retrieves information about the specified semaphore.
Input Parameters
semaphore_ptr Pointer to semaphore control block.
name Pointer to destination for the pointer to the
semaphore’s name.
current_value Pointer to destination for the current
semaphore’s count.
first_suspended Pointer to destination for the pointer to the thread
that is first on the suspension list of this
semaphore.
suspended_count Pointer to destination for the number of threads
currently suspended on this semaphore.
next_semaphore Pointer to destination for the pointer of the next
created semaphore.
i not required.
User Guide
Counting Semaphores 219
Return Values
TX_SUCCESS (0x00) Successful semaphore
information retrieval.
TX_SEMAPHORE_ERROR (0x0C) Invalid semaphore pointer.
Allowed From
Initialization, threads, timers, and ISRs
Preemption Possible
No
Example
TX_SEMAPHORE my_semaphore;
CHAR *name;
ULONG current_value;
TX_THREAD *first_suspended;
ULONG suspended_count;
TX_SEMAPHORE *next_semaphore;
UINT status;
See Also
tx_semaphore_ceiling_put, tx_semaphore_create, tx_semaphore_delete,
tx_semaphore_get, tx_semaphore_performance_info_get,
tx_semaphore_performance_system_info_get, tx_semaphore_prioritize,
tx_semaphore_put, tx_semaphore_put_notify
tx_semaphore_performance_info_get
Get semaphore performance information
Counting Sem aphores
Prototype
UINT tx_semaphore_performance_info_get(TX_SEMAPHORE *semaphore_ptr,
ULONG *puts, ULONG *gets,
ULONG *suspensions, ULONG *timeouts);
Description
This service retrieves performance information about the specified
semaphore.
Input Parameters
semaphore_ptr Pointer to previously created semaphore.
puts Pointer to destination for the number of put
requests performed on this semaphore.
gets Pointer to destination for the number of get
requests performed on this semaphore.
suspensions Pointer to destination for the number of thread
suspensions on this semaphore.
timeouts Pointer to destination for the number of thread
suspension timeouts on this semaphore.
User Guide
Counting Semaphores 221
Return Values
TX_SUCCESS (0x00) Successful semaphore
performance get.
TX_PTR_ERROR (0x03) Invalid semaphore pointer.
TX_FEATURE_NOT_ENABLED (0xFF) The system was not
compiled with performance
information enabled.
Allowed From
Initialization, threads, timers, and ISRs
Example
TX_SEMAPHORE my_semaphore;
ULONG puts;
ULONG gets;
ULONG suspensions;
ULONG timeouts;
See Also
tx_seamphore_ceiling_put, tx_semaphore_create, tx_semaphore_delete,
tx_semaphore_get, tx_semaphore_info_get,
tx_semaphore_performance_system_info_get, tx_semaphore_prioritize,
tx_semaphore_put, tx_semaphore_put_notify
tx_semaphore_performance_system_info_get
Get semaphore system performance information
Counting Sem aphores
Prototype
UINT tx_semaphore_performance_system_info_get(ULONG *puts,
ULONG *gets, ULONG *suspensions, ULONG *timeouts);
Description
This service retrieves performance information about all the semaphores
in the system.
Input Parameters
puts Pointer to destination for the total number of put
requests performed on all semaphores.
gets Pointer to destination for the total number of get
requests performed on all semaphores.
suspensions Pointer to destination for the total number of
thread suspensions on all semaphores.
timeouts Pointer to destination for the total number of
thread suspension timeouts on all semaphores.
User Guide
Counting Semaphores 223
Return Values
TX_SUCCESS (0x00) Successful semaphore
system performance get.
TX_FEATURE_NOT_ENABLED (0xFF) The system was not
compiled with performance
information enabled..
Allowed From
Initialization, threads, timers, and ISRs
Example
ULONG puts;
ULONG gets;
ULONG suspensions;
ULONG timeouts;
See Also
tx_seamphore_ceiling_put, tx_semaphore_create, tx_semaphore_delete,
tx_semaphore_get, tx_semaphore_info_get,
tx_semaphore_performance_info_get, tx_semaphore_prioritize,
tx_semaphore_put, tx_semaphore_put_notify
tx_semaphore_prioritize
Prioritize semaphore suspension list
Counting Sem aphores
Prototype
UINT tx_semaphore_prioritize(TX_SEMAPHORE *semaphore_ptr)
Description
This service places the highest priority thread suspended for an instance
of the semaphore at the front of the suspension list. All other threads
remain in the same FIFO order they were suspended in.
Input Parameters
semaphore_ptr Pointer to a previously created semaphore.
Return Values
TX_SUCCESS (0x00) Successful semaphore
prioritize.
TX_SEMAPHORE_ERROR (0x0C) Invalid counting semaphore
pointer.
Allowed From
Initialization, threads, timers, and ISRs
Preemption Possible
No
User Guide
Counting Semaphores 225
Example
TX_SEMAPHORE my_semaphore;
UINT status;
See Also
tx_semaphore_create, tx_semaphore_delete, tx_semaphore_get,
tx_semaphore_info_get, tx_semaphore_put
tx_semaphore_put
Place an instance in counting semaphore
Counting Sem aphores
Prototype
UINT tx_semaphore_put(TX_SEMAPHORE *semaphore_ptr)
Description
This service puts an instance into the specified counting semaphore,
which in reality increments the counting semaphore by one.
Input Parameters
semaphore_ptr Pointer to the previously created counting
semaphore control block.
Return Values
TX_SUCCESS (0x00) Successful semaphore put.
TX_SEMAPHORE_ERROR (0x0C) Invalid pointer to counting
semaphore.
Allowed From
Initialization, threads, timers, and ISRs
Preemption Possible
Yes
User Guide
Counting Semaphores 227
Example
TX_SEMAPHORE my_semaphore;
UINT status;
See Also
tx_semaphore_ceiling_put, tx_semaphore_create, tx_semaphore_delete,
tx_semaphore_info_get, tx_semaphore_performance_info_get,
tx_semaphore_performance_system_info_get, tx_semaphore_prioritize,
tx_semaphore_get, tx_semaphore_put_notify
tx_semaphore_put_notify
Notify application when semaphore is put
Counting Sem aphores
Prototype
UINT tx_semaphore_put_notify(TX_SEMAPHORE *semaphore_ptr,
VOID (*semaphore_put_notify)(TX_SEMAPHORE *));
Description
This service registers a notification callback function that is called
whenever the specified semaphore is put. The processing of the
notification callback is defined by the application.
Input Parameters
semaphore_ptr Pointer to previously created semaphore.
semaphore_put_notify Pointer to application’s semaphore put
notification function. If this value is TX_NULL,
notification is disabled.
Return Values
TX_SUCCESS (0x00) Successful registration of
semaphore put notification.
TX_SEMAPHORE_ERROR (0x0C) Invalid semaphore pointer.
TX_FEATURE_NOT_ENABLED (0xFF) The system was compiled
with notification capabilities
disabled.
Allowed From
Initialization, threads, timers, and ISRs
User Guide
Counting Semaphores 229
Example
TX_SEMAPHORE my_semaphore;
See Also
tx_seamphore_ceiling_put, tx_semaphore_create, tx_semaphore_delete,
tx_semaphore_get, tx_semaphore_info_get,
tx_semaphore_performance_info_get,
tx_semaphore_performance_system_info_get, tx_semaphore_prioritize,
tx_semaphore_put
tx_thread_create
Create application thread
Thread Control
Prototype
UINT tx_thread_create(TX_THREAD *thread_ptr,
CHAR *name_ptr, VOID (*entry_function)(ULONG),
ULONG entry_input, VOID *stack_start,
ULONG stack_size, UINT priority,
UINT preempt_threshold, ULONG time_slice,
UINT auto_start)
Description
This service creates an application thread that starts execution at the
specified task entry function. The stack, priority, preemption-threshold, and
time-slice are among the attributes specified by the input parameters. In
addition, the initial execution state of the thread is also specified.
Input Parameters
thread_ptr Pointer to a thread control block.
name_ptr Pointer to the name of the thread.
entry_function Specifies the initial C function for thread execution.
When a thread returns from this entry function, it is
placed in a completed state and suspended
indefinitely.
entry_input A 32-bit value that is passed to the thread’s entry
function when it first executes. The use for this
input is determined exclusively by the application.
stack_start Starting address of the stack’s memory area.
stack_size Number bytes in the stack memory area. The
thread’s stack area must be large enough to
handle its worst-case function call nesting and
local variable usage.
priority Numerical priority of thread. Legal values range
from 0 through (TX_MAX_PRIORITES-1), where a
value of 0 represents the highest priority.
preempt_threshold Highest priority level (0 through
(TX_MAX_PRIORITIES-1)) of disabled
User Guide
Thread Control 231
Return Values
TX_SUCCESS (0x00) Successful thread creation.
TX_THREAD_ERROR (0x0E) Invalid thread control
pointer. Either the pointer is
NULL or the thread is
already created.
TX_PTR_ERROR (0x03) Invalid starting address of
the entry point or the stack
area is invalid, usually
NULL.
TX_SIZE_ERROR (0x05) Size of stack area is invalid.
Threads must have at least
TX_MINIMUM_STACK
bytes to execute.
TX_PRIORITY_ERROR (0x0F) Invalid thread priority, which
is a value outside the range
of (0 through
(TX_MAX_PRIORITIES-1)).
TX_THRESH_ERROR (0x18) Invalid preemption-
threshold specified. This
value must be a valid priority
less than or equal to the
initial priority of the thread.
TX_START_ERROR (0x10) Invalid auto-start selection.
TX_CALLER_ERROR (0x13) Invalid caller of this service.
Allowed From
Initialization and threads
Preemption Possible
Yes
User Guide
Thread Control 233
Example
TX_THREAD my_thread;
UINT status;
...
See Also
tx_thread_delete, tx_thread_entry_exit_notify, tx_thread_identify,
tx_thread_info_get, tx_thread_performance_info_get,
tx_thread_performance_system_info_get,
tx_thread_preemption_change, tx_thread_priority_change,
tx_thread_relinquish, tx_thread_reset, tx_thread_resume,
tx_thread_sleep, tx_thread_stack_error_notify, tx_thread_suspend,
tx_thread_terminate, tx_thread_time_slice_change, tx_thread_wait_abort
tx_thread_delete
Delete application thread
Prototype
UINT tx_thread_delete(TX_THREAD *thread_ptr)
Description
This service deletes the specified application thread. Since the specified
thread must be in a terminated or completed state, this service cannot be
called from a thread attempting to delete itself.
Input Parameters
thread_ptr Pointer to a previously created application
thread.
Return Values
TX_SUCCESS (0x00) Successful thread deletion.
TX_THREAD_ERROR (0x0E) Invalid application thread pointer.
TX_DELETE_ERROR (0x11) Specified thread is not in a terminated
or completed state.
TX_CALLER_ERROR (0x13) Invalid caller of this service.
Allowed From
Threads and timers
Preemption Possible
No
User Guide
Thread Control 235
Example
TX_THREAD my_thread;
UINT status;
See Also
tx_thread_create, tx_thread_entry_exit_notify, tx_thread_identify,
tx_thread_info_get, tx_thread_performance_info_get,
tx_thread_performance_system_info_get,
tx_thread_preemption_change, tx_thread_priority_change,
tx_thread_relinquish, tx_thread_reset, tx_thread_resume,
tx_thread_sleep, tx_thread_stack_error_notify, tx_thread_suspend,
tx_thread_terminate, tx_thread_time_slice_change, tx_thread_wait_abort
tx_thread_entry_exit_notify
Notify application upon thread entry and exit
Prototype
UINT tx_thread_entry_exit_notify(TX_THREAD *thread_ptr,
VOID (*entry_exit_notify)(TX_THREAD *, UINT))
Description
This service registers a notification callback function that is called
whenever the specified thread is entered or exits. The processing of the
notification callback is defined by the application.
Input Parameters
thread_ptr Pointer to previously created thread.
entry_exit_notify Pointer to application’s thread entry/exit
notification function. The second parameter to
the entry/exit notification function designates if
an entry or exit is present. The value
TX_THREAD_ENTRY (0x00) indicates the
thread was entered, while the value
TX_THREAD_EXIT (0x01) indicates the thread
was exited. If this value is TX_NULL, notification
is disabled.
Return Values
TX_SUCCESS (0x00) Successful registration of the
thread entry/exit notification
function.
TX_THREAD_ERROR (0x0E) Invalid thread pointer.
TX_FEATURE_NOT_ENABLED (0xFF) The system was compiled with
notification capabilities
disabled.
Allowed From
Initialization, threads, timers, and ISRs
User Guide
Thread Control 237
Example
TX_THREAD my_thread;
See Also
tx_thread_create, tx_thread_delete, tx_thread_entry_exit_notify,
tx_thread_identify, tx_thread_info_get, tx_thread_performance_info_get,
tx_thread_performance_system_info_get,
tx_thread_preemption_change, tx_thread_priority_change,
tx_thread_relinquish, tx_thread_reset, tx_thread_resume,
tx_thread_sleep, tx_thread_stack_error_notify, tx_thread_suspend,
tx_thread_terminate, tx_thread_time_slice_change, tx_thread_wait_abort
tx_thread_identify
Retrieves pointer to currently executing thread
Prototype
TX_THREAD* tx_thread_identify(VOID)
Description
This service returns a pointer to the currently executing thread. If no
thread is executing, this service returns a null pointer.
If this service is called from an ISR, the return value represents the thread
i running prior to the executing interrupt handler.
Input Parameters
None
Return Values
thread pointer Pointer to the currently executing thread. If no
thread is executing, the return value is
TX_NULL.
Allowed From
Threads and ISRs
Preemption Possible
No
User Guide
Thread Control 239
Example
TX_THREAD *my_thread_ptr;
See Also
tx_thread_create, tx_thread_delete, tx_thread_entry_exit_notify,
tx_thread_info_get, tx_thread_performance_info_get,
tx_thread_performance_system_info_get,
tx_thread_preemption_change, tx_thread_priority_change,
tx_thread_relinquish, tx_thread_reset, tx_thread_resume,
tx_thread_sleep, tx_thread_stack_error_notify, tx_thread_suspend,
tx_thread_terminate, tx_thread_time_slice_change, tx_thread_wait_abort
tx_thread_info_get
Retrieve information about thread
Thread Control
Prototype
UINT tx_thread_info_get(TX_THREAD *thread_ptr, CHAR **name,
UINT *state, ULONG *run_count,
UINT *priority,
UINT *preemption_threshold,
ULONG *time_slice,
TX_THREAD **next_thread,
TX_THREAD **suspended_thread)
Description
This service retrieves information about the specified thread.
Input Parameters
thread_ptr Pointer to thread control block.
name Pointer to destination for the pointer to the
thread’s name.
state Pointer to destination for the thread’s current
execution state. Possible values are as follows:
TX_READY (0x00)
TX_COMPLETED (0x01)
TX_TERMINATED (0x02)
TX_SUSPENDED (0x03)
TX_SLEEP (0x04)
TX_QUEUE_SUSP (0x05)
TX_SEMAPHORE_SUSP (0x06)
TX_EVENT_FLAG (0x07)
TX_BLOCK_MEMORY (0x08)
TX_BYTE_MEMORY (0x09)
TX_MUTEX_SUSP (0x0D)
User Guide
Thread Control 241
Return Values
TX_SUCCESS (0x00) Successful thread information
retrieval.
TX_THREAD_ERROR (0x0E) Invalid thread control pointer.
Allowed From
Initialization, threads, timers, and ISRs
Preemption Possible
No
Example
TX_THREAD my_thread;
CHAR *name;
UINT state;
ULONG run_count;
UINT priority;
UINT preemption_threshold;
UINT time_slice;
TX_THREAD *next_thread;
TX_THREAD *suspended_thread;
UINT status;
See Also
tx_thread_create, tx_thread_delete, tx_thread_entry_exit_notify,
tx_thread_identify, tx_thread_performance_info_get,
tx_thread_performance_system_info_get,
tx_thread_preemption_change, tx_thread_priority_change,
tx_thread_relinquish, tx_thread_reset, tx_thread_resume,
tx_thread_sleep, tx_thread_stack_error_notify, tx_thread_suspend,
tx_thread_terminate, tx_thread_time_slice_change, tx_thread_wait_abort
User Guide
Thread Control 243
tx_thread_performance_info_get
Get thread performance information
Prototype
UINT tx_thread_performance_info_get(TX_THREAD *thread_ptr,
ULONG *resumptions, ULONG *suspensions,
ULONG *solicited_preemptions, ULONG *interrupt_preemptions,
ULONG *priority_inversions, ULONG *time_slices,
ULONG *relinquishes, ULONG *timeouts, ULONG *wait_aborts,
TX_THREAD **last_preempted_by);
Description
This service retrieves performance information about the specified thread.
Input Parameters
thread_ptr Pointer to previously created thread.
resumptions Pointer to destination for the number of
resumptions of this thread.
suspensions Pointer to destination for the number of
suspensions of this thread.
solicited_preemptions Pointer to destination for the number of
preemptions as a result of a ThreadX API
service call made by this thread.
interrupt_preemptions Pointer to destination for the number of
preemptions of this thread as a result of
interrupt processing.
priority_inversions Pointer to destination for the number of priority
inversions of this thread.
time_slices Pointer to destination for the number of time-
slices of this thread.
relinquishes Pointer to destination for the number of thread
relinquishes performed by this thread.
User Guide
Thread Control 245
Return Values
TX_SUCCESS (0x00) Successful thread
performance get.
TX_PTR_ERROR (0x03) Invalid thread pointer.
TX_FEATURE_NOT_ENABLED (0xFF) The system was not
compiled with performance
information enabled.
Allowed From
Initialization, threads, timers, and ISRs
Example
TX_THREAD my_thread;
ULONG resumptions;
ULONG suspensions;
ULONG solicited_preemptions;
ULONG interrupt_preemptions;
ULONG priority_inversions;
ULONG time_slices;
ULONG relinquishes;
ULONG timeouts;
ULONG wait_aborts;
TX_THREAD *last_preempted_by;
See Also
tx_thread_create, tx_thread_delete, tx_thread_entry_exit_notify,
tx_thread_identify, tx_thread_info_get,
tx_thread_performance_system_info_get,
tx_thread_preemption_change, tx_thread_priority_change,
tx_thread_relinquish, tx_thread_reset, tx_thread_resume,
tx_thread_sleep, tx_thread_stack_error_notify, tx_thread_suspend,
tx_thread_terminate, tx_thread_time_slice_change, tx_thread_wait_abort
User Guide
Thread Control 247
tx_thread_performance_system_info_get
Get thread system performance information
Prototype
UINT tx_thread_performance_system_info_get(ULONG *resumptions,
ULONG *suspensions, ULONG *solicited_preemptions,
ULONG *interrupt_preemptions, ULONG *priority_inversions,
ULONG *time_slices, ULONG *relinquishes, ULONG *timeouts,
ULONG *wait_aborts, ULONG *non_idle_returns,
ULONG *idle_returns);
Description
This service retrieves performance information about all the threads in the
system.
Input Parameters
resumptions Pointer to destination for the total number of
thread resumptions.
suspensions Pointer to destination for the total number of
thread suspensions.
solicited_preemptions Pointer to destination for the total number of
thread preemptions as a result of a thread
calling a ThreadX API service.
interrupt_preemptions Pointer to destination for the total number of
thread preemptions as a result of interrupt
processing.
priority_inversions Pointer to destination for the total number of
thread priority inversions.
time_slices Pointer to destination for the total number of
thread time-slices.
relinquishes Pointer to destination for the total number of
thread relinquishes.
User Guide
Thread Control 249
Return Values
TX_SUCCESS (0x00) Successful thread system
performance get.
TX_FEATURE_NOT_ENABLED (0xFF) The system was not
compiled with performance
information enabled.
Allowed From
Initialization, threads, timers, and ISRs
Example
ULONG resumptions;
ULONG suspensions;
ULONG solicited_preemptions;
ULONG interrupt_preemptions;
ULONG priority_inversions;
ULONG time_slices;
ULONG relinquishes;
ULONG timeouts;
ULONG wait_aborts;
ULONG non_idle_returns;
ULONG idle_returns;
See Also
tx_thread_create, tx_thread_delete, tx_thread_entry_exit_notify,
tx_thread_identify, tx_thread_info_get, tx_thread_performance_info_get,
tx_thread_preemption_change, tx_thread_priority_change,
tx_thread_relinquish, tx_thread_reset, tx_thread_resume,
tx_thread_sleep, tx_thread_stack_error_notify, tx_thread_suspend,
tx_thread_terminate, tx_thread_time_slice_change, tx_thread_wait_abort
User Guide
Thread Control 251
tx_thread_preemption_change
Change preemption-threshold of application thread
Prototype
UINT tx_thread_preemption_change(TX_THREAD *thread_ptr,
UINT new_threshold, UINT *old_threshold)
Description
This service changes the preemption-threshold of the specified thread.
The preemption-threshold prevents preemption of the specified thread by
threads equal to or less than the preemption-threshold value.
Input Parameters
thread_ptr Pointer to a previously created application
thread.
new_threshold New preemption-threshold priority level (0
through (TX_MAX_PRIORITIES-1)).
old_threshold Pointer to a location to return the previous
preemption-threshold.
Return Values
TX_SUCCESS (0x00) Successful preemption-threshold
change.
TX_THREAD_ERROR (0x0E) Invalid application thread pointer.
TX_THRESH_ERROR (0x18) Specified new preemption-threshold is
not a valid thread priority (a value other
than (0 through
(TX_MAX_PRIORITIES-1)) or is
greater than (lower priority) than the
current thread priority.
TX_PTR_ERROR (0x03) Invalid pointer to previous preemption-
threshold storage location.
TX_CALLER_ERROR (0x13) Invalid caller of this service.
User Guide
Thread Control 253
Allowed From
Threads and timers
Preemption Possible
Yes
Example
TX_THREAD my_thread;
UINT my_old_threshold;
UINT status;
See Also
tx_thread_create, tx_thread_delete, tx_thread_entry_exit_notify,
tx_thread_identify, tx_thread_info_get, tx_thread_performance_info_get,
tx_thread_performance_system_info_get, tx_thread_priority_change,
tx_thread_relinquish, tx_thread_reset, tx_thread_resume,
tx_thread_sleep, tx_thread_stack_error_notify, tx_thread_suspend,
tx_thread_terminate, tx_thread_time_slice_change, tx_thread_wait_abort
tx_thread_priority_change
Change priority of application thread
Prototype
UINT tx_thread_priority_change(TX_THREAD *thread_ptr,
UINT new_priority, UINT *old_priority)
Description
This service changes the priority of the specified thread. Valid priorities
range from 0 through (TX_MAX_PRIORITES-1), where 0 represents the
highest priority level.
Input Parameters
thread_ptr Pointer to a previously created application
thread.
new_priority New thread priority level (0 through
(TX_MAX_PRIORITIES-1)).
old_priority Pointer to a location to return the thread’s
previous priority.
Return Values
TX_SUCCESS (0x00) Successful priority change.
TX_THREAD_ERROR (0x0E) Invalid application thread pointer.
TX_PRIORITY_ERROR (0x0F) Specified new priority is not valid (a
value other than (0 through
(TX_MAX_PRIORITIES-1)).
TX_PTR_ERROR (0x03) Invalid pointer to previous priority
storage location.
TX_CALLER_ERROR (0x13) Invalid caller of this service.
User Guide
Thread Control 255
Allowed From
Threads and timers
Preemption Possible
Yes
Example
TX_THREAD my_thread;
UINT my_old_priority;
UINT status;
See Also
tx_thread_create, tx_thread_delete, tx_thread_entry_exit_notify,
tx_thread_identify, tx_thread_info_get, tx_thread_performance_info_get,
tx_thread_performance_system_info_get,
tx_thread_preemption_change, tx_thread_relinquish, tx_thread_reset,
tx_thread_resume, tx_thread_sleep, tx_thread_stack_error_notify,
tx_thread_suspend, tx_thread_terminate, tx_thread_time_slice_change,
tx_thread_wait_abort
tx_thread_relinquish
Relinquish control to other application threads
Prototype
VOID tx_thread_relinquish(VOID)
Description
This service relinquishes processor control to other ready-to-run threads
at the same or higher priority.
Input Parameters
None
Return Values
None
Allowed From
Threads
Preemption Possible
Yes
User Guide
Thread Control 257
Example
ULONG run_counter_1 = 0;
ULONG run_counter_2 = 0;
See Also
tx_thread_create, tx_thread_delete, tx_thread_entry_exit_notify,
tx_thread_identify, tx_thread_info_get, tx_thread_performance_info_get,
tx_thread_performance_system_info_get,
tx_thread_preemption_change, tx_thread_priority_change,
tx_thread_reset, tx_thread_resume, tx_thread_sleep,
tx_thread_stack_error_notify, tx_thread_suspend, tx_thread_terminate,
tx_thread_time_slice_change, tx_thread_wait_abort
tx_thread_reset
Reset thread
Prototype
UINT tx_thread_reset(TX_THREAD *thread_ptr);
Description
This service resets the specified thread to execute at the entry point
defined at thread creation. The thread must be in either a
TX_COMPLETED or TX_TERMINATED state for it to be reset
Input Parameters
thread_ptr Pointer to a previously created thread.
Return Values
TX_SUCCESS (0x00) Successful thread reset.
TX_NOT_DONE (0x20) Specified thread is not in a
TX_COMPLETED or
TX_TERMINATED state.
TX_THREAD_ERROR (0x0E) Invalid thread pointer.
TX_CALLER_ERROR (0x13) Invalid caller of this service.
Allowed From
Threads
User Guide
Thread Control 259
Example
TX_THREAD my_thread;
See Also
tx_thread_create, tx_thread_delete, tx_thread_entry_exit_notify,
tx_thread_identify, tx_thread_info_get, tx_thread_performance_info_get,
tx_thread_preformance_system_info_get,
tx_thread_preemption_change, tx_thread_priority_change,
tx_thread_relinquish, tx_thread_resume, tx_thread_sleep,
tx_thread_stack_error_notify, tx_thread_suspend, tx_thread_terminate,
tx_thread_time_slice_change, tx_thread_wait_abort
tx_thread_resume
Resume suspended application thread
Prototype
UINT tx_thread_resume(TX_THREAD *thread_ptr)
Description
This service resumes or prepares for execution a thread that was
previously suspended by a tx_thread_suspend call. In addition, this
service resumes threads that were created without an automatic start.
Input Parameters
thread_ptr Pointer to a suspended application thread.
Return Values
TX_SUCCESS (0x00) Successful thread resume.
TX_SUSPEND_LIFTED(0x19) Previously set delayed suspension
was lifted.
TX_THREAD_ERROR (0x0E) Invalid application thread pointer.
TX_RESUME_ERROR (0x12) Specified thread is not suspended or
was previously suspended by a
service other than
tx_thread_suspend.
Allowed From
Initialization, threads, timers, and ISRs
Preemption Possible
Yes
User Guide
Thread Control 261
Example
TX_THREAD my_thread;
UINT status;
See Also
tx_thread_create, tx_thread_delete, tx_thread_entry_exit_notify,
tx_thread_identify, tx_thread_info_get, tx_thread_performance_info_get,
tx_thread_performance_system_info_get,
tx_thread_preemption_change, tx_thread_priority_change,
tx_thread_relinquish, tx_thread_reset, tx_thread_sleep,
tx_thread_stack_error_notify, tx_thread_suspend, tx_thread_terminate,
tx_thread_time_slice_change, tx_thread_wait_abort
tx_thread_sleep
Suspend current thread for specified time
Prototype
UINT tx_thread_sleep(ULONG timer_ticks)
Description
This service causes the calling thread to suspend for the specified
number of timer ticks. The amount of physical time associated with a
timer tick is application specific. This service can be called only from an
application thread.
Input Parameters
timer_ticks The number of timer ticks to suspend the calling
application thread, ranging from 0 through
0xFFFFFFFF. If 0 is specified, the service returns
immediately.
Return Values
TX_SUCCESS (0x00) Successful thread sleep.
TX_WAIT_ABORTED (0x1A) Suspension was aborted by another
thread, timer, or ISR.
TX_CALLER_ERROR (0x13) Service called from a non-thread.
Allowed From
Threads
Preemption Possible
Yes
User Guide
Thread Control 263
Example
UINT status;
See Also
tx_thread_create, tx_thread_delete, tx_thread_entry_exit_notify,
tx_thread_identify, tx_thread_info_get, tx_thread_performance_info_get,
tx_thread_performance_system_info_get,
tx_thread_preemption_change, tx_thread_priority_change,
tx_thread_relinquish, tx_thread_reset, tx_thread_resume,
tx_thread_stack_error_notify, tx_thread_suspend, tx_thread_terminate,
tx_thread_time_slice_change, tx_thread_wait_abort
tx_thread_stack_error_notify
Register thread stack error notification callback
Prototype
UINT tx_thread_stack_error_notify(VOID (*error_handler)(TX_THREAD *));
Description
This service registers a notification callback function for handling thread
stack errors. When ThreadX detects a thread stack error during
execution, it will call this notification function to process the error.
Processing of the error is completely defined by the application. Anything
from suspending the violating thread to resetting the entire system may
be done.
Input Parameters
error_handler Pointer to application’s stack error handling
function. If this value is TX_NULL, the notification
is disabled.
Return Values
TX_SUCCESS (0x00) Successful thread reset.
TX_FEATURE_NOT_ENABLED(0xFF) The system was not compiled
with performance information
enabled.
Allowed From
Initialization, threads, timers, and ISRs
User Guide
Thread Control 265
Example
void my_stack_error_handler(TX_THREAD *thread_ptr);
See Also
tx_thread_create, tx_thread_delete, tx_thread_entry_exit_notify,
tx_thread_identify, tx_thread_info_get, tx_thread_performance_info_get,
tx_thread_preformance_system_info_get,
tx_thread_preemption_change, tx_thread_priority_change,
tx_thread_relinquish, tx_thread_reset, tx_thread_resume,
tx_thread_sleep, tx_thread_suspend, tx_thread_terminate,
tx_thread_time_slice_change, tx_thread_wait_abort
tx_thread_suspend
Suspend application thread
Prototype
UINT tx_thread_suspend(TX_THREAD *thread_ptr)
Description
This service suspends the specified application thread. A thread may call
this service to suspend itself.
Input Parameters
thread_ptr Pointer to an application thread.
Return Values
TX_SUCCESS (0x00) Successful thread suspend.
TX_THREAD_ERROR (0x0E) Invalid application thread
pointer.
TX_SUSPEND_ERROR (0x14) Specified thread is in a
terminated or
completed state.
TX_CALLER_ERROR (0x13) Invalid caller of this service.
Allowed From
Initialization, threads, timers, and ISRs
Preemption Possible
Yes
User Guide
Thread Control 267
Example
TX_THREAD my_thread;
UINT status;
See Also
tx_thread_create, tx_thread_delete, tx_thread_entry_exit_notify,
tx_thread_identify, tx_thread_info_get, tx_thread_performance_info_get,
tx_thread_performance_system_info_get,
tx_thread_preemption_change, tx_thread_priority_change,
tx_thread_relinquish, tx_thread_reset, tx_thread_resume,
tx_thread_sleep, tx_thread_stack_error_notify, tx_thread_terminate,
tx_thread_time_slice_change, tx_thread_wait_abort
tx_thread_terminate
Terminates application thread
Prototype
UINT tx_thread_terminate(TX_THREAD *thread_ptr)
Description
This service terminates the specified application thread regardless of
whether the thread is suspended or not. A thread may call this service to
terminate itself.
After being terminated, the thread must be reset for it to execute again.
i
Input Parameters
thread_ptr Pointer to application thread.
Return Values
TX_SUCCESS (0x00) Successful thread terminate.
TX_THREAD_ERROR (0x0E) Invalid application thread pointer.
TX_CALLER_ERROR (0x13) Invalid caller of this service.
Allowed From
Threads and timers
Preemption Possible
Yes
User Guide
Thread Control 269
Example
TX_THREAD my_thread;
UINT status;
See Also
tx_thread_create, tx_thread_delete, tx_thread_entry_exit_notify,
tx_thread_identify, tx_thread_info_get, tx_thread_performance_info_get,
tx_thread_performance_system_info_get,
tx_thread_preemption_change, tx_thread_priority_change,
tx_thread_relinquish, tx_thread_reset, tx_thread_resume,
tx_thread_sleep, tx_thread_stack_error_notify, tx_thread_suspend,
tx_thread_time_slice_change, tx_thread_wait_abort
tx_thread_time_slice_change
Changes time-slice of application thread
Prototype
UINT tx_thread_time_slice_change(TX_THREAD *thread_ptr,
ULONG new_time_slice, ULONG *old_time_slice)
Description
This service changes the time-slice of the specified application thread.
Selecting a time-slice for a thread insures that it won’t execute more than
the specified number of timer ticks before other threads of the same or
higher priorities have a chance to execute.
Return Values
TX_SUCCESS (0x00) Successful time-slice chance.
TX_THREAD_ERROR (0x0E) Invalid application thread pointer.
TX_PTR_ERROR (0x03) Invalid pointer to previous time-slice
storage location.
TX_CALLER_ERROR (0x13) Invalid caller of this service.
User Guide
Thread Control 271
Allowed From
Threads and timers
Preemption Possible
No
Example
TX_THREAD my_thread;
ULONG my_old_time_slice;
UINT status;
See Also
tx_thread_create, tx_thread_delete, tx_thread_entry_exit_notify,
tx_thread_identify, tx_thread_info_get, tx_thread_performance_info_get,
tx_thread_performance_system_info_get,
tx_thread_preemption_change, tx_thread_priority_change,
tx_thread_relinquish, tx_thread_reset, tx_thread_resume,
tx_thread_sleep, tx_thread_stack_error_notify, tx_thread_suspend,
tx_thread_terminate, tx_thread_wait_abort
tx_thread_wait_abort
Abort suspension of specified thread
Prototype
UINT tx_thread_wait_abort(TX_THREAD *thread_ptr)
Description
This service aborts sleep or any other object suspension of the specified
thread. If the wait is aborted, a TX_WAIT_ABORTED value is returned
from the service that the thread was waiting on.
This service does not release explicit suspension that is made by the
i tx_thread_suspend service.
Input Parameters
thread_ptr Pointer to a previously created application
thread.
Return Values
TX_SUCCESS (0x00) Successful thread wait
abort.
TX_THREAD_ERROR (0x0E) Invalid application thread
pointer.
TX_WAIT_ABORT_ERROR (0x1B) Specified thread is not in a
waiting state.
Allowed From
Initialization, threads, timers, and ISRs
Preemption Possible
Yes
User Guide
Thread Control 273
Example
TX_THREAD my_thread;
UINT status;
See Also
tx_thread_create, tx_thread_delete, tx_thread_entry_exit_notify,
tx_thread_identify, tx_thread_info_get, tx_thread_performance_info_get,
tx_thread_performance_system_info_get,
tx_thread_preemption_change, tx_thread_priority_change,
tx_thread_relinquish, tx_thread_reset, tx_thread_resume,
tx_thread_sleep, tx_thread_stack_error_notify, tx_thread_suspend,
tx_thread_terminate, tx_thread_time_slice_change
tx_time_get
Retrieves the current time
Application Tim ers
Prototype
ULONG tx_time_get(VOID)
Description
This service returns the contents of the internal system clock. Each timer-
tick increases the internal system clock by one. The system clock is set to
zero during initialization and can be changed to a specific value by the
service tx_time_set.
Input Parameters
None
Return Values
system clock ticks Value of the internal, free running, system clock.
Allowed From
Initialization, threads, timers, and ISRs
Preemption Possible
No
User Guide
Application Timers 275
Example
ULONG current_time;
See Also
tx_time_set
tx_time_set
Sets the current time
Prototype
VOID tx_time_set(ULONG new_time)
Description
This service sets the internal system clock to the specified value. Each
timer-tick increases the internal system clock by one.
Input Parameters
new_time New time to put in the system clock, legal values
range from 0 through 0xFFFFFFFF.
Return Values
None
Allowed From
Threads, timers, and ISRs
Preemption Possible
No
User Guide
Application Timers 277
Example
/* Set the internal system time to 0x1234. */
tx_time_set(0x1234);
/* Current time now contains 0x1234 until the next timer
interrupt. */
See Also
tx_time_get
tx_timer_activate
Activate application timer
Application Tim ers
Prototype
UINT tx_timer_activate(TX_TIMER *timer_ptr)
Description
This service activates the specified application timer. The expiration
routines of timers that expire at the same time are executed in the order
they were activated.
Input Parameters
timer_ptr Pointer to a previously created application timer.
Return Values
TX_SUCCESS (0x00) Successful application timer
activation.
TX_TIMER_ERROR (0x15) Invalid application timer
pointer.
TX_ACTIVATE_ERROR (0x17) Timer was already active.
Allowed From
Initialization, threads, timers, and ISRs
Preemption Possible
No
User Guide
Application Timers 279
Example
TX_TIMER my_timer;
UINT status;
See Also
tx_timer_change, tx_timer_create, tx_timer_deactivate, tx_timer_delete,
tx_timer_info_get, tx_timer_performance_info_get,
tx_timer_performance_system_info_get
tx_timer_change
Change application timer
Prototype
UINT tx_timer_change(TX_TIMER *timer_ptr,
ULONG initial_ticks, ULONG reschedule_ticks)
Description
This service changes the expiration characteristics of the specified
application timer. The timer must be deactivated prior to calling this
service.
Input Parameters
timer_ptr Pointer to a timer control block.
initial_ticks Specifies the initial number of ticks for timer
expiration. Legal values range from 1 through
0xFFFFFFFF.
reschedule_ticks Specifies the number of ticks for all timer
expirations after the first. A zero for this
parameter makes the timer a one-shot timer.
Otherwise, for periodic timers, legal values range
from 1 through 0xFFFFFFFF.
Return Values
TX_SUCCESS (0x00) Successful application timer change.
TX_TIMER_ERROR (0x15) Invalid application timer pointer.
TX_TICK_ERROR (0x16) Invalid value (a zero) supplied for initial
ticks.
TX_CALLER_ERROR (0x13) Invalid caller of this service.
User Guide
Application Timers 281
Allowed From
Threads, timers, and ISRs
Preemption Possible
No
Example
TX_TIMER my_timer;
UINT status;
See Also
tx_timer_activate, tx_timer_create, tx_timer_deactivate, tx_timer_delete,
tx_timer_info_get, tx_timer_performance_info_get,
tx_timer_performance_system_info_get
tx_timer_create
Create application timer
Prototype
UINT tx_timer_create(TX_TIMER *timer_ptr, CHAR *name_ptr,
VOID (*expiration_function)(ULONG),
ULONG expiration_input, ULONG initial_ticks,
ULONG reschedule_ticks, UINT auto_activate)
Description
This service creates an application timer with the specified expiration
function and periodic.
Input Parameters
timer_ptr Pointer to a timer control block
name_ptr Pointer to the name of the timer.
expiration_function Application function to call when the timer
expires.
expiration_input Input to pass to expiration function when timer
expires.
initial_ticks Specifies the initial number of ticks for timer
expiration. Legal values range from 1 through
0xFFFFFFFF.
reschedule_ticks Specifies the number of ticks for all timer
expirations after the first. A zero for this
parameter makes the timer a one-shot timer.
Otherwise, for periodic timers, legal values range
from 1 through 0xFFFFFFFF.
auto_activate Determines if the timer is automatically activated
during creation. If this value is
TX_AUTO_ACTIVATE (0x01) the timer is made
active. Otherwise, if the value
TX_NO_ACTIVATE (0x00) is selected, the timer
is created in a non-active state. In this case, a
subsequent tx_timer_activate service call is
necessary to get the timer actually started.
User Guide
Application Timers 283
Return Values
TX_SUCCESS (0x00) Successful application timer
creation.
TX_TIMER_ERROR (0x15) Invalid application timer pointer.
Either the pointer is NULL or the
timer is already created.
TX_TICK_ERROR (0x16) Invalid value (a zero) supplied for
initial ticks.
TX_ACTIVATE_ERROR (0x17) Invalid activation selected.
TX_CALLER_ERROR (0x13) Invalid caller of this service.
Allowed From
Initialization and threads
Preemption Possible
No
Example
TX_TIMER my_timer;
UINT status;
See Also
tx_timer_activate, tx_timer_change, tx_timer_deactivate, tx_timer_delete,
tx_timer_info_get, tx_timer_performance_info_get,
tx_timer_performance_system_info_get
tx_timer_deactivate
Deactivate application timer
Prototype
UINT tx_timer_deactivate(TX_TIMER *timer_ptr)
Description
This service deactivates the specified application timer. If the timer is
already deactivated, this service has no effect.
Input Parameters
timer_ptr Pointer to a previously created application timer.
Return Values
TX_SUCCESS (0x00) Successful application timer
deactivation.
TX_TIMER_ERROR (0x15) Invalid application timer pointer.
Allowed From
Initialization, threads, timers, and ISRs
Preemption Possible
No
User Guide
Application Timers 285
Example
TX_TIMER my_timer;
UINT status;
See Also
tx_timer_activate, tx_timer_change, tx_timer_create, tx_timer_delete,
tx_timer_info_get, tx_timer_performance_info_get,
tx_timer_performance_system_info_get
tx_timer_delete
Delete application timer
Prototype
UINT tx_timer_delete(TX_TIMER *timer_ptr)
Description
This service deletes the specified application timer.
Input Parameters
timer_ptr Pointer to a previously created application timer.
Return Values
TX_SUCCESS (0x00) Successful application timer deletion.
TX_TIMER_ERROR (0x15) Invalid application timer pointer.
TX_CALLER_ERROR (0x13) Invalid caller of this service.
Allowed From
Threads
Preemption Possible
No
User Guide
Application Timers 287
Example
TX_TIMER my_timer;
UINT status;
See Also
tx_timer_activate, tx_timer_change, tx_timer_create, tx_timer_deactivate,
tx_timer_info_get, tx_timer_performance_info_get,
tx_timer_performance_system_info_get
tx_timer_info_get
Retrieve information about an application timer
Application Tim ers
Prototype
UINT tx_timer_info_get(TX_TIMER *timer_ptr, CHAR **name,
UINT *active, ULONG *remaining_ticks,
ULONG *reschedule_ticks,
TX_TIMER **next_timer)
Description
This service retrieves information about the specified application timer.
Input Parameters
timer_ptr Pointer to a previously created application timer.
name Pointer to destination for the pointer to the
timer’s name.
active Pointer to destination for the timer active
indication. If the timer is inactive or this service
is called from the timer itself, a TX_FALSE value
is returned. Otherwise, if the timer is active, a
TX_TRUE value is returned.
remaining_ticks Pointer to destination for the number of timer
ticks left before the timer expires.
reschedule_ticks Pointer to destination for the number of timer
ticks that will be used to automatically
reschedule this timer. If the value is zero, then
the timer is a one-shot and won’t be
rescheduled.
next_timer Pointer to destination for the pointer of the next
created application timer.
User Guide
Application Timers 289
Return Values
TX_SUCCESS (0x00) Successful timer information retrieval.
TX_TIMER_ERROR (0x15) Invalid application timer pointer.
Allowed From
Initialization, threads, timers, and ISRs
Preemption Possible
No
Example
TX_TIMER my_timer;
CHAR *name;
UINT active;
ULONG remaining_ticks;
ULONG reschedule_ticks;
TX_TIMER *next_timer;
UINT status;
See Also
tx_timer_activate, tx_timer_change, tx_timer_create, tx_timer_deactivate,
tx_timer_delete, tx_timer_info_get, tx_timer_performance_info_get,
tx_timer_performance_system_info_get
tx_timer_performance_info_get
Get timer performance information
Prototype
UINT tx_timer_performance_info_get(TX_TIMER *timer_ptr,
ULONG *activates, ULONG *reactivates,
ULONG *deactivates, ULONG *expirations,
ULONG *expiration_adjusts);
Description
This service retrieves performance information about the specified
application timer.
Input Parameters
timer_ptr Pointer to previously created timer.
activates Pointer to destination for the number of activation
requests performed on this timer.
reactivates Pointer to destination for the number of
automatic reactivations performed on this
periodic timer.
deactivates Pointer to destination for the number of
deactivation requests performed on this timer.
expirations Pointer to destination for the number of
expirations of this timer.
expiration_adjusts Pointer to destination for the number of internal
expiration adjustments performed on this timer.
These adjustments are done in the timer
interrupt processing for timers that are larger
than the default timer list size (by default timers
with expirations greater than 32 ticks).
User Guide
Application Timers 291
i not required.
Return Values
TX_SUCCESS (0x00) Successful timer performance
get.
TX_PTR_ERROR (0x03) Invalid timer pointer.
TX_FEATURE_NOT_ENABLED(0xFF) The system was not compiled
with performance information
enabled.
Allowed From
Initialization, threads, timers, and ISRs
Example
TX_TIMER my_timer;
ULONG activates;
ULONG reactivates;
ULONG deactivates;
ULONG expirations;
ULONG expiration_adjusts;
See Also
tx_timer_activate, tx_timer_change, tx_timer_create,
tx_timer_deactivate, tx_timer_delete, tx_timer_info_get,
tx_timer_performance_system_info_get
tx_timer_performance_system_info_get
Get timer system performance information
Prototype
UINT tx_timer_performance_system_info_get(ULONG *activates,
ULONG *reactivates, ULONG *deactivates,
ULONG *expirations, ULONG *expiration_adjusts);
Description
This service retrieves performance information about all the application
timers in the system.
Input Parameters
activates Pointer to destination for the total number of
activation requests performed on all timers.
reactivates Pointer to destination for the total number of
automatic reactivation performed on all periodic
timers.
deactivates Pointer to destination for the total number of
deactivation requests performed on all timers.
expirations Pointer to destination for the total number of
expirations on all timers.
expiration_adjusts Pointer to destination for the total number of
internal expiration adjustments performed on all
timers. These adjustments are done in the timer
interrupt processing for timers that are larger
than the default timer list size (by default timers
with expirations greater than 32 ticks).
User Guide
Application Timers 293
Return Values
TX_SUCCESS (0x00) Successful timer system
performance get.
TX_FEATURE_NOT_ENABLED(0xFF) The system was not compiled
with performance information
enabled.
Allowed From
Initialization, threads, timers, and ISRs
Example
ULONG activates;
ULONG reactivates;
ULONG deactivates;
ULONG expirations;
ULONG expiration_adjusts;
See Also
tx_timer_activate, tx_timer_change, tx_timer_create,
tx_timer_deactivate, tx_timer_delete, tx_timer_info_get,
tx_timer_performance_info_get
User Guide
CHAPTER 5
User Guide
296 Device Drivers for ThreadX
Driver Functions
ThreadX device drivers are composed of eight basic
functional areas, as follows:
Driver Initialization
Driver Control
Driver Access
Driver Input
Driver Output
Driver Interrupts
Driver Status
Driver Termination
User Guide
Driver Functions 297
Driver Control After the driver is initialized and ready for operation,
this functional area is responsible for run-time
control. Typically, run-time control consists of making
changes to the underlying hardware device.
Examples include changing the baud rate of a serial
device or seeking a new sector on a disk.
Driver Access Some device drivers are called only from a single
application thread. In such cases, this functional area
is not needed. However, in applications where
multiple threads need simultaneous driver access,
their interaction must be controlled by adding assign/
release facilities in the device driver. Alternatively,
the application may use a semaphore to control
driver access and avoid extra overhead and
complication inside the driver.
User Guide
Simple Driver Example 299
i
the other driver functions. Typically, driver
initialization is called from tx_application_define.
VOID tx_sdriver_initialize(VOID)
{
Simple Driver Input for the simple driver centers around the input
Input semaphore. When a serial device input interrupt is
received, the input semaphore is set. If one or more
threads are waiting for a character from the driver,
the thread waiting the longest is resumed. If no
threads are waiting, the semaphore simply remains
set until a thread calls the drive input function.
User Guide
Simple Driver Example 301
UCHAR tx_sdriver_input(VOID)
{
VOID tx_sdriver_input_ISR(VOID)
{
/* See if an input character notification is pending. */
if (!tx_sdriver_input_semaphore.tx_semaphore_count)
{
/* If not, notify thread of an input character. */
tx_semaphore_put(&tx_sdriver_input_semaphore);
}
}
VOID tx_sdriver_output_ISR(VOID)
{
/* Notify thread last character transmit is
complete. */
tx_semaphore_put(&tx_sdriver_output_semaphore);
}
User Guide
Advanced Driver Issues 303
Circular Byte Circular byte buffers are typically used in drivers that
Buffers manage a simple serial hardware device like a
UART. Two circular buffers are most often used in
such situations—one for input and one for output.
Circular Buffer The input buffer is used to hold characters that arrive
Input before the application is ready for them. When an
input character is received (usually in an interrupt
service routine), the new character is retrieved from
the hardware device and placed into the input buffer
at the location pointed to by the write pointer. The
write pointer is then advanced to the next position in
UCHAR tx_input_buffer[MAX_SIZE];
UCHAR tx_input_write_ptr;
UCHAR tx_input_read_ptr;
/* Initialization. */
tx_input_write_ptr = &tx_input_buffer[0];
tx_input_read_ptr = &tx_input_buffer[0];
User Guide
Advanced Driver Issues 305
UCHAR tx_output_buffer[MAX_SIZE];
UCHAR tx_output_write_ptr;
UCHAR tx_output_read_ptr;
/* Initialization. */
tx_output_write_ptr = &tx_output_buffer[0];
tx_output_read_ptr = &tx_output_buffer[0];
TX_BLOCK_POOL tx_io_block_pool;
User Guide
Advanced Driver Issues 307
Input List
Input Head Pointer Input Tail Pointer
more buffers
in packet or
NULL
Output List
Output Head Pointer Output Tail Pointer
more buffers
in packet or
NULL
User Guide
Advanced Driver Issues 309
User Guide
CHAPTER 6
User Guide
312 Demonstration System for ThreadX
Overview
Each ThreadX product distribution contains a
demonstration system that runs on all supported
microprocessors.
Application Define
The tx_application_define function executes after
the basic ThreadX initialization is complete. It is
responsible for setting up all of the initial system
resources, including threads, queues, semaphores,
mutexes, event flags, and memory pools.
User Guide
Application Define 313
thread_4
thread_5
thread_6
thread_7
queue_0
semaphore_0
event_flags_0
mutex_0
block_pool_0
Thread 0
The function thread_0_entry marks the entry point
of the thread (lines 167-190). Thread_0 is the first
thread in the demonstration system to execute. Its
processing is simple: it increments its counter, sleeps
for 10 timer ticks, sets an event flag to wake up
thread_5, then repeats the sequence.
Thread 1
The function thread_1_entry marks the entry point
of the thread (lines 193-216). Thread_1 is the
second-to-last thread in the demonstration system to
execute. Its processing consists of incrementing its
counter, sending a message to thread_2 (through
queue_0), and repeating the sequence. Notice that
thread_1 suspends whenever queue_0 becomes
full (line 207).
Thread 2
The function thread_2_entry marks the entry point
of the thread (lines 219-243). Thread_2 is the last
thread in the demonstration system to execute. Its
processing consists of incrementing its counter,
getting a message from thread_1 (through
queue_0), and repeating the sequence. Notice that
thread_2 suspends whenever queue_0 becomes
empty (line 233).
User Guide
Threads 3 and 4 315
are also the only threads that are ready for execution
most of the time. They are also the only threads
created with time-slicing (lines 87 and 93). Each
thread is allowed to execute for a maximum of 4
timer ticks before the other thread is executed.
Threads 3 and 4
The function thread_3_and_4_entry marks the
entry point of both thread_3 and thread_4 (lines
246-280). Both threads have a priority of 8, which
makes them the third and fourth threads in the
demonstration system to execute. The processing for
each thread is the same: incrementing its counter,
getting semaphore_0, sleeping for 2 timer ticks,
releasing semaphore_0, and repeating the
sequence. Notice that each thread suspends
whenever semaphore_0 is unavailable (line 264).
Thread 5
The function thread_5_entry marks the entry point
of the thread (lines 283-305). Thread_5 is the
second thread in the demonstration system to
execute. Its processing consists of incrementing its
Threads 6 and 7
The function thread_6_and_7_entry marks the
entry point of both thread_6 and thread_7 (lines
307-358). Both threads have a priority of 8, which
makes them the fifth and sixth threads in the
demonstration system to execute. The processing for
each thread is the same: incrementing its counter,
getting mutex_0 twice, sleeping for 2 timer ticks,
releasing mutex_0 twice, and repeating the
sequence. Notice that each thread suspends
whenever mutex_0 is unavailable (line 325).
Also both threads use the same function for their
main processing. This presents no problems
because they both have their own unique stack, and
C is naturally reentrant. Each thread determines
which one it is by examination of the thread input
parameter (line 319), which is setup when they are
created (lines 126 and 133).
User Guide
Distribution file: demo_threadx.c 317
000 /* This is a small demo of the high-performance ThreadX kernel. It includes examples of eight
001 threads of different priorities, using a message queue, semaphore, mutex, event flags group,
002 byte pool, and block pool. */
003
004 #include "tx_api.h"
005
006 #define DEMO_STACK_SIZE 1024
007 #define DEMO_BYTE_POOL_SIZE 9120
008 #define DEMO_BLOCK_POOL_SIZE 100
009 #define DEMO_QUEUE_SIZE 100
010
011 /* Define the ThreadX object control blocks... */
012
013 TX_THREAD thread_0;
014 TX_THREAD thread_1;
015 TX_THREAD thread_2;
016 TX_THREAD thread_3;
017 TX_THREAD thread_4;
018 TX_THREAD thread_5;
019 TX_THREAD thread_6;
020 TX_THREAD thread_7;
021 TX_QUEUE queue_0;
022 TX_SEMAPHORE semaphore_0;
023 TX_MUTEX mutex_0;
024 TX_EVENT_FLAGS_GROUP event_flags_0;
025 TX_BYTE_POOL byte_pool_0;
026 TX_BLOCK_POOL block_pool_0;
027
028 /* Define the counters used in the demo application... */
029
030 ULONG thread_0_counter;
031 ULONG thread_1_counter;
032 ULONG thread_1_messages_sent;
033 ULONG thread_2_counter;
034 ULONG thread_2_messages_received;
035 ULONG thread_3_counter;
036 ULONG thread_4_counter;
037 ULONG thread_5_counter;
038 ULONG thread_6_counter;
039 ULONG thread_7_counter;
040
041 /* Define thread prototypes. */
042
043 void thread_0_entry(ULONG thread_input);
044 void thread_1_entry(ULONG thread_input);
045 void thread_2_entry(ULONG thread_input);
046 void thread_3_and_4_entry(ULONG thread_input);
047 void thread_5_entry(ULONG thread_input);
048 void thread_6_and_7_entry(ULONG thread_input);
049
050
051 /* Define main entry point. */
052
053 int main()
054 {
055
056 /* Enter the ThreadX kernel. */
057 tx_kernel_enter();
058 }
059
060 /* Define what the initial system looks like. */
061 void tx_application_define(void *first_unused_memory)
062 {
063
064 CHAR *pointer;
065
066 /* Create a byte memory pool from which to allocate the thread stacks. */
067 tx_byte_pool_create(&byte_pool_0, "byte pool 0", first_unused_memory,
068 DEMO_BYTE_POOL_SIZE);
069
070 /* Put system definition stuff in here, e.g., thread creates and other assorted
071 create information. */
User Guide
Distribution file: demo_threadx.c 319
072
073 /* Allocate the stack for thread 0. */
074 tx_byte_allocate(&byte_pool_0, &pointer, DEMO_STACK_SIZE, TX_NO_WAIT);
075
076 /* Create the main thread. */
077 tx_thread_create(&thread_0, "thread 0", thread_0_entry, 0,
078 pointer, DEMO_STACK_SIZE,
079 1, 1, TX_NO_TIME_SLICE, TX_AUTO_START);
080
081 /* Allocate the stack for thread 1. */
082 tx_byte_allocate(&byte_pool_0, &pointer, DEMO_STACK_SIZE, TX_NO_WAIT);
083
084 /* Create threads 1 and 2. These threads pass information through a ThreadX
085 message queue. It is also interesting to note that these threads have a time
086 slice. */
087 tx_thread_create(&thread_1, "thread 1", thread_1_entry, 1,
088 pointer, DEMO_STACK_SIZE,
089 16, 16, 4, TX_AUTO_START);
090
091 /* Allocate the stack for thread 2. */
092 tx_byte_allocate(&byte_pool_0, &pointer, DEMO_STACK_SIZE, TX_NO_WAIT);
093 tx_thread_create(&thread_2, "thread 2", thread_2_entry, 2,
094 pointer, DEMO_STACK_SIZE,
095 16, 16, 4, TX_AUTO_START);
096
097 /* Allocate the stack for thread 3. */
098 tx_byte_allocate(&byte_pool_0, &pointer, DEMO_STACK_SIZE, TX_NO_WAIT);
099
100 /* Create threads 3 and 4. These threads compete for a ThreadX counting semaphore.
101 An interesting thing here is that both threads share the same instruction area. */
102 tx_thread_create(&thread_3, "thread 3", thread_3_and_4_entry, 3,
103 pointer, DEMO_STACK_SIZE,
104 8, 8, TX_NO_TIME_SLICE, TX_AUTO_START);
105
106 /* Allocate the stack for thread 4. */
107 tx_byte_allocate(&byte_pool_0, &pointer, DEMO_STACK_SIZE, TX_NO_WAIT);
108
109 tx_thread_create(&thread_4, "thread 4", thread_3_and_4_entry, 4,
110 pointer, DEMO_STACK_SIZE,
111 8, 8, TX_NO_TIME_SLICE, TX_AUTO_START);
112
113 /* Allocate the stack for thread 5. */
114 tx_byte_allocate(&byte_pool_0, &pointer, DEMO_STACK_SIZE, TX_NO_WAIT);
115
116 /* Create thread 5. This thread simply pends on an event flag, which will be set
117 by thread_0. */
118 tx_thread_create(&thread_5, "thread 5", thread_5_entry, 5,
119 pointer, DEMO_STACK_SIZE,
120 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
121
122 /* Allocate the stack for thread 6. */
123 tx_byte_allocate(&byte_pool_0, &pointer, DEMO_STACK_SIZE, TX_NO_WAIT);
124
125 /* Create threads 6 and 7. These threads compete for a ThreadX mutex. */
126 tx_thread_create(&thread_6, "thread 6", thread_6_and_7_entry, 6,
127 pointer, DEMO_STACK_SIZE,
128 8, 8, TX_NO_TIME_SLICE, TX_AUTO_START);
129
130 /* Allocate the stack for thread 7. */
131 tx_byte_allocate(&byte_pool_0, &pointer, DEMO_STACK_SIZE, TX_NO_WAIT);
132
133 tx_thread_create(&thread_7, "thread 7", thread_6_and_7_entry, 7,
134 pointer, DEMO_STACK_SIZE,
135 8, 8, TX_NO_TIME_SLICE, TX_AUTO_START);
136
137 /* Allocate the message queue. */
138 tx_byte_allocate(&byte_pool_0, &pointer, DEMO_QUEUE_SIZE*sizeof(ULONG), TX_NO_WAIT);
139
140 /* Create the message queue shared by threads 1 and 2. */
141 tx_queue_create(&queue_0, "queue 0", TX_1_ULONG, pointer, DEMO_QUEUE_SIZE*sizeof(ULONG));
142
143 /* Create the semaphore used by threads 3 and 4. */
User Guide
Distribution file: demo_threadx.c 321
216 }
217
218
219 void thread_2_entry(ULONG thread_input)
220 {
221
222 ULONG received_message;
223 UINT status;
224
225 /* This thread retrieves messages placed on the queue by thread 1. */
226 while(1)
227 {
228
229 /* Increment the thread counter. */
230 thread_2_counter++;
231
232 /* Retrieve a message from the queue. */
233 status = tx_queue_receive(&queue_0, &received_message, TX_WAIT_FOREVER);
234
235 /* Check completion status and make sure the message is what we
236 expected. */
237 if ((status != TX_SUCCESS) || (received_message != thread_2_messages_received))
238 break;
239
240 /* Otherwise, all is okay. Increment the received message count. */
241 thread_2_messages_received++;
242 }
243 }
244
245
246 void thread_3_and_4_entry(ULONG thread_input)
247 {
248
249 UINT status;
250
251
252 /* This function is executed from thread 3 and thread 4. As the loop
253 below shows, these function compete for ownership of semaphore_0. */
254 while(1)
255 {
256
257 /* Increment the thread counter. */
258 if (thread_input == 3)
259 thread_3_counter++;
260 else
261 thread_4_counter++;
262
263 /* Get the semaphore with suspension. */
264 status = tx_semaphore_get(&semaphore_0, TX_WAIT_FOREVER);
265
266 /* Check status. */
267 if (status != TX_SUCCESS)
268 break;
269
270 /* Sleep for 2 ticks to hold the semaphore. */
271 tx_thread_sleep(2);
272
273 /* Release the semaphore. */
274 status = tx_semaphore_put(&semaphore_0);
275
276 /* Check status. */
277 if (status != TX_SUCCESS)
278 break;
279 }
280 }
281
282
283 void thread_5_entry(ULONG thread_input)
284 {
285
286 UINT status;
287 ULONG actual_flags;
288
289
290 /* This thread simply waits for an event in a forever loop. */
291 while(1)
292 {
293
294 /* Increment the thread counter. */
295 thread_5_counter++;
296
297 /* Wait for event flag 0. */
298 status = tx_event_flags_get(&event_flags_0, 0x1, TX_OR_CLEAR,
299 &actual_flags, TX_WAIT_FOREVER);
300
301 /* Check status. */
302 if ((status != TX_SUCCESS) || (actual_flags != 0x1))
303 break;
304 }
305 }
306
307 void thread_6_and_7_entry(ULONG thread_input)
308 {
309
310 UINT status;
311
312
313 /* This function is executed from thread 6 and thread 7. As the loop
314 below shows, these function compete for ownership of mutex_0. */
315 while(1)
316 {
317
318 /* Increment the thread counter. */
319 if (thread_input == 6)
320 thread_6_counter++;
321 else
322 thread_7_counter++;
323
324 /* Get the mutex with suspension. */
325 status = tx_mutex_get(&mutex_0, TX_WAIT_FOREVER);
326
327 /* Check status. */
328 if (status != TX_SUCCESS)
329 break;
330
331 /* Get the mutex again with suspension. This shows
332 that an owning thread may retrieve the mutex it
333 owns multiple times. */
334 status = tx_mutex_get(&mutex_0, TX_WAIT_FOREVER);
335
336 /* Check status. */
337 if (status != TX_SUCCESS)
338 break;
339
340 /* Sleep for 2 ticks to hold the mutex. */
341 tx_thread_sleep(2);
342
343 /* Release the mutex. */
344 status = tx_mutex_put(&mutex_0);
345
346 /* Check status. */
347 if (status != TX_SUCCESS)
348 break;
349
350 /* Release the mutex again. This will actually
351 release ownership since it was obtained twice. */
352 status = tx_mutex_put(&mutex_0);
353
354 /* Check status. */
355 if (status != TX_SUCCESS)
356 break;
357 }
358 }
User Guide
APPENDIX A
User Guide
324 ThreadX API Services
Function
User Guide
ThreadX API Services 325
UINT tx_event_flags_performance_info_get(TX_EVENT_FLAGS_GROUP
*group_ptr, ULONG *sets, ULONG *gets, ULONG *suspensions,
ULONG *timeouts);
Control
User Guide
ThreadX API Services 327
UINT tx_thread_stack_error_notify
VOID(*stack_error_handler)(TX_THREAD *));
UINT tx_timer_performance_system_info_get
ULONG *activates, ULONG *reactivates,
ULONG *deactivates, ULONG *expirations,
ULONG *expiration_adjusts);
User Guide
APPENDIX B
ThreadX Constants
1 Alphabetic Listings 330
1 Listing by Value 332
User Guide
330 ThreadX User Guide
Alphabetic TX_1_ULONG 1
Listings TX_2_ULONG 2
TX_4_ULONG 4
TX_8_ULONG 8
TX_16_ULONG 16
TX_ACTIVATE_ERROR 0x17
TX_AND 2
TX_AND_CLEAR 3
TX_AUTO_ACTIVATE 1
TX_AUTO_START 1
TX_BLOCK_MEMORY 8
TX_BYTE_MEMORY 9
TX_CALLER_ERROR 0x13
TX_CEILING_EXCEEDED 0x21
TX_COMPLETED 1
TX_DELETE_ERROR 0x11
TX_DELETED 0x01
TX_DONT_START 0
TX_EVENT_FLAG 7
TX_FALSE 0
TX_FEATURE_NOT_ENABLED 0xFF
TX_FILE 11
TX_GROUP_ERROR 0x06
TX_INHERIT 1
TX_INHERIT_ERROR 0x1F
TX_INVALID_CEILING 0x22
TX_IO_DRIVER 10
TX_LOOP_FOREVER 1
TX_MUTEX_ERROR 0x1C
TX_MUTEX_SUSP 13
TX_NO_ACTIVATE 0
User Guide
ThreadX Constants 331
TX_NO_EVENTS 0x07
TX_NO_INHERIT 0
TX_NO_INSTANCE 0x0D
TX_NO_MEMORY 0x10
TX_NO_TIME_SLICE 0
TX_NO_WAIT 0
TX_NOT_AVAILABLE 0x1D
TX_NOT_DONE 0x20
TX_NOT_OWNED 0x1E
TX_NULL 0
TX_OPTION_ERROR 0x08
TX_OR 0
TX_OR_CLEAR 1
TX_POOL_ERROR 0x02
TX_PRIORITY_ERROR 0x0F
TX_PTR_ERROR 0x03
TX_QUEUE_EMPTY 0x0A
TX_QUEUE_ERROR 0x09
TX_QUEUE_FULL 0x0B
TX_QUEUE_SUSP 5
TX_READY 0
TX_RESUME_ERROR 0x12
TX_SEMAPHORE_ERROR 0x0C
TX_SEMAPHORE_SUSP 6
TX_SIZE_ERROR 0x05
TX_SLEEP 4
TX_STACK_FILL 0xEFEFEFEFUL
TX_START_ERROR 0x10
TX_SUCCESS 0x00
TX_SUSPEND_ERROR 0x14
TX_SUSPEND_LIFTED 0x19
TX_SUSPENDED 3
TX_TCP_IP 12
TX_TERMINATED 2
TX_THREAD_ENTRY 0
TX_THREAD_ERROR 0x0E
TX_THREAD_EXIT 1
TX_THRESH_ERROR 0x18
TX_TICK_ERROR 0x16
TX_TIMER_ERROR 0x15
TX_TRUE 1
TX_WAIT_ABORT_ERROR 0x1B
TX_WAIT_ABORTED 0x1A
TX_WAIT_ERROR 0x04
TX_WAIT_FOREVER 0xFFFFFFFFUL
User Guide
ThreadX Constants 333
TX_LOOP_FOREVER 1
TX_DELETED 0x01
TX_OR_CLEAR 1
TX_THREAD_EXIT 1
TX_TRUE 1
TX_2_ULONG 2
TX_AND 2
TX_POOL_ERROR 0x02
TX_TERMINATED 2
TX_AND_CLEAR 3
TX_PTR_ERROR 0x03
TX_SUSPENDED 3
TX_4_ULONG 4
TX_SLEEP 4
TX_WAIT_ERROR 0x04
TX_QUEUE_SUSP 5
TX_SIZE_ERROR 0x05
TX_GROUP_ERROR 0x06
TX_SEMAPHORE_SUSP 6
TX_EVENT_FLAG 7
TX_NO_EVENTS 0x07
TX_8_ULONG 8
TX_BLOCK_MEMORY 8
TX_OPTION_ERROR 0x08
TX_BYTE_MEMORY 9
TX_QUEUE_ERROR 0x09
TX_IO_DRIVER 10
TX_QUEUE_EMPTY 0x0A
TX_FILE 11
TX_QUEUE_FULL 0x0B
TX_TCP_IP 12
TX_SEMAPHORE_ERROR 0x0C
TX_MUTEX_SUSP 13
TX_NO_INSTANCE 0x0D
TX_THREAD_ERROR 0x0E
TX_PRIORITY_ERROR 0x0F
TX_16_ULONG 16
TX_NO_MEMORY 0x10
TX_START_ERROR 0x10
TX_DELETE_ERROR 0x11
TX_RESUME_ERROR 0x12
TX_CALLER_ERROR 0x13
TX_SUSPEND_ERROR 0x14
TX_TIMER_ERROR 0x15
TX_TICK_ERROR 0x16
TX_ACTIVATE_ERROR 0x17
TX_THRESH_ERROR 0x18
TX_SUSPEND_LIFTED 0x19
TX_WAIT_ABORTED 0x1A
TX_WAIT_ABORT_ERROR 0x1B
TX_MUTEX_ERROR 0x1C
TX_NOT_AVAILABLE 0x1D
TX_NOT_OWNED 0x1E
TX_INHERIT_ERROR 0x1F
TX_NOT_DONE 0x20
TX_CEILING_EXCEEDED 0x21
TX_INVALID_CEILING 0x22
TX_FEATURE_NOT_ENABLED 0xFF
TX_STACK_FILL 0xEFEFEFEFUL
TX_WAIT_FOREVER 0xFFFFFFFFUL
User Guide
APPENDIX C
User Guide
336 ThreadX Data Types
TX_BLOCK_POOL
typedef struct TX_BLOCK_POOL_STRUCT
{
ULONG tx_block_pool_id;
CHAR *tx_block_pool_name;
ULONG tx_block_pool_available;
ULONG tx_block_pool_total;
UCHAR *tx_block_pool_available_list;
UCHAR *tx_block_pool_start;
ULONG tx_block_pool_size;
ULONG tx_block_pool_block_size;
struct TX_THREAD_STRUCT
*tx_block_pool_suspension_list;
ULONG tx_block_pool_suspended_count;
struct TX_BLOCK_POOL_STRUCT
*tx_block_pool_created_next,
*tx_block_pool_created_previous;
#ifdef TX_BLOCK_POOL_ENABLE_PERFORMANCE_INFO
ULONG tx_block_pool_performance_allocate_count;
ULONG tx_block_pool_performance_release_count;
ULONG tx_block_pool_performance_suspension_count;
ULONG tx_block_pool_performance_timeout_count;
#endif
} TX_BLOCK_POOL;
TX_BYTE_POOL
typedef struct TX_BYTE_POOL_STRUCT
{
ULONG tx_byte_pool_id;
CHAR *tx_byte_pool_name;
ULONG tx_byte_pool_available;
ULONG tx_byte_pool_fragments;
UCHAR *tx_byte_pool_list;
UCHAR *tx_byte_pool_search;
UCHAR *tx_byte_pool_start;
ULONG tx_byte_pool_size;
struct TX_THREAD_STRUCT
*tx_byte_pool_owner;
struct TX_THREAD_STRUCT
*tx_byte_pool_suspension_list;
ULONG tx_byte_pool_suspended_count;
struct TX_BYTE_POOL_STRUCT
*tx_byte_pool_created_next,
*tx_byte_pool_created_previous;
#ifdef TX_BYTE_POOL_ENABLE_PERFORMANCE_INFO
User Guide
TX_EVENT_FLAGS_GROUP 337
ULONG tx_byte_pool_performance_allocate_count;
ULONG tx_byte_pool_performance_release_count;
ULONG tx_byte_pool_performance_merge_count;
ULONG tx_byte_pool_performance_split_count;
ULONG tx_byte_pool_performance_search_count;
ULONG tx_byte_pool_performance_suspension_count;
ULONG tx_byte_pool_performance_timeout_count;
#endif
} TX_BYTE_POOL;
TX_EVENT_FLAGS_GROUP
typedef struct TX_EVENT_FLAGS_GROUP_STRUCT
{
ULONG tx_event_flags_group_id;
CHAR *tx_event_flags_group_name;
ULONG tx_event_flags_group_current;
UINT tx_event_flags_group_reset_search;
struct TX_THREAD_STRUCT
*tx_event_flags_group_suspension_list;
ULONG tx_event_flags_group_suspended_count;
struct TX_EVENT_FLAGS_GROUP_STRUCT
*tx_event_flags_group_created_next,
*tx_event_flags_group_created_previous;
ULONG tx_event_flags_group_delayed_clear;
#ifdef TX_EVENT_FLAGS_ENABLE_PERFORMANCE_INFO
ULONG tx_event_flags_group_performance_set_count;
ULONG tx_event_flags_group_performance_get_count;
ULONG tx_event_flags_group_performance_suspension_count;
ULONG tx_event_flags_group_performance_timeout_count;
#endif
#ifndef TX_DISABLE_NOTIFY_CALLBACKS
TX_MUTEX
typedef struct TX_MUTEX_STRUCT
{
ULONG tx_mutex_id;
CHAR *tx_mutex_name;
ULONG tx_mutex_ownership_count;
TX_THREAD *tx_mutex_owner;
UINT tx_mutex_inherit;
UINT tx_mutex_original_priority;
UINT tx_mutex_original_threshold;
struct TX_THREAD_STRUCT
*tx_mutex_suspension_list;
ULONG tx_mutex_suspended_count;
struct TX_MUTEX_STRUCT
*tx_mutex_created_next,
*tx_mutex_created_previous;
ULONG tx_mutex_highest_priority_waiting;
struct TX_MUTEX_STRUCT
*tx_mutex_owned_next,
*tx_mutex_owned_previous;
#ifdef TX_MUTEX_ENABLE_PERFORMANCE_INFO
ULONG tx_mutex_performance_put_count;
ULONG tx_mutex_performance_get_count;
ULONG tx_mutex_performance_suspension_count;
ULONG tx_mutex_performance_timeout_count;
ULONG tx_mutex_performance_priority_inversion_count;
ULONG tx_mutex_performance_priority_inheritance_count;
#endif
} TX_MUTEX;
TX_QUEUE
typedef struct TX_QUEUE_STRUCT
{
ULONG tx_queue_id;
CHAR *tx_queue_name;
UINT tx_queue_message_size;
ULONG tx_queue_capacity;
ULONG tx_queue_enqueued;
ULONG tx_queue_available_storage;
ULONG *tx_queue_start;
ULONG *tx_queue_end;
ULONG *tx_queue_read;
ULONG *tx_queue_write;
struct TX_THREAD_STRUCT
*tx_queue_suspension_list;
ULONG tx_queue_suspended_count;
struct TX_QUEUE_STRUCT
*tx_queue_created_next,
*tx_queue_created_previous;
#ifdef TX_QUEUE_ENABLE_PERFORMANCE_INFO
ULONG tx_queue_performance_messages_sent_count;
User Guide
TX_SEMAPHORE 339
ULONG tx_queue_performance_messages_received_count;
ULONG tx_queue_performance_empty_suspension_count;
ULONG tx_queue_performance_full_suspension_count;
ULONG tx_queue_performance_full_error_count;
ULONG tx_queue_performance_timeout_count;
#endif
#ifndef TX_DISABLE_NOTIFY_CALLBACKS
VOID *tx_queue_send_notify)(struct TX_QUEUE_STRUCT *);
#endif
} TX_QUEUE;
TX_SEMAPHORE
typedef struct TX_SEMAPHORE_STRUCT
{
ULONG tx_semaphore_id;
CHAR *tx_semaphore_name;
ULONG tx_semaphore_count;
struct TX_THREAD_STRUCT
*tx_semaphore_suspension_list;
ULONG tx_semaphore_suspended_count;
struct TX_SEMAPHORE_STRUCT
*tx_semaphore_created_next,
*tx_semaphore_created_previous;
#ifdef TX_SEMAPHORE_ENABLE_PERFORMANCE_INFO
ULONG tx_semaphore_performance_put_count;
ULONG tx_semaphore_performance_get_count;
ULONG tx_semaphore_performance_suspension_count;
ULONG tx_semaphore_performance_timeout_count;
#endif
#ifndef TX_DISABLE_NOTIFY_CALLBACKS
VOID (*tx_semaphore_put_notify)(struct TX_SEMAPHORE_STRUCT *);
#endif
} TX_SEMAPHORE;
TX_THREAD
typedef struct TX_THREAD_STRUCT
{
ULONG tx_thread_id;
ULONG tx_thread_run_count;
VOID *tx_thread_stack_ptr;
VOID *tx_thread_stack_start;
VOID *tx_thread_stack_end;
ULONG tx_thread_stack_size;
ULONG tx_thread_time_slice;
ULONG tx_thread_new_time_slice;
struct TX_THREAD_STRUCT
*tx_thread_ready_next,
*tx_thread_ready_previous;
CHAR *tx_thread_name;
UINT tx_thread_priority;
UINT tx_thread_state;
UINT tx_thread_delayed_suspend;
UINT tx_thread_suspending;
UINT tx_thread_preempt_threshold;
VOID *tx_thread_stack_highest_ptr;
VOID (*tx_thread_entry)(ULONG);
ULONG tx_thread_entry_parameter;
TX_TIMER_INTERNAL tx_thread_timer;
VOID (*tx_thread_suspend_cleanup)(struct TX_THREAD_STRUCT *);
VOID *tx_thread_suspend_control_block;
struct TX_THREAD_STRUCT
*tx_thread_suspended_next,
*tx_thread_suspended_previous;
ULONG tx_thread_suspend_info;
VOID *tx_thread_additional_suspend_info;
UINT tx_thread_suspend_option;
UINT tx_thread_suspend_status;
struct TX_THREAD_STRUCT
*tx_thread_created_next,
*tx_thread_created_previous;
VOID *tx_thread_filex_ptr;
UINT tx_thread_original_priority;
UINT tx_thread_original_preempt_threshold;
ULONG tx_thread_owned_mutex_count;
struct TX_MUTEX_STRUCT*tx_thread_owned_mutex_list;
#ifdef TX_THREAD_ENABLE_PERFORMANCE_INFO
ULONG tx_thread_performance_resume_count;
ULONG tx_thread_performance_suspend_count;
ULONG tx_thread_performance_solicited_preemption_count;
ULONG tx_thread_performance_interrupt_preemption_count;
User Guide
TX_TIMER 341
ULONG tx_thread_performance_priority_inversion_count;
struct TX_THREAD_STRUCT
*tx_thread_performance_last_preempting_thread;
ULONG tx_thread_performance_time_slice_count;
ULONG tx_thread_performance_relinquish_count;
ULONG tx_thread_performance_timeout_count;
ULONG tx_thread_performance_wait_abort_count;
#endif
#ifndef TX_DISABLE_NOTIFY_CALLBACKS
VOID (*tx_thread_entry_exit_notify)
(struct TX_THREAD_STRUCT *, UINT);
#endif
TX_THREAD_USER_EXTENSION
} TX_THREAD;
TX_TIMER
typedef struct TX_TIMER_STRUCT
{
ULONG tx_timer_id;
CHAR *tx_timer_name;
TX_TIMER_INTERNAL tx_timer_internal;
struct TX_TIMER_STRUCT
*tx_timer_created_next,
*tx_timer_created_previous;
#ifdef TX_TIMER_ENABLE_PERFORMANCE_INFO
ULONG tx_timer_performance_activate_count;
ULONG tx_timer_performance_reactivate_count;
ULONG tx_timer_performance_deactivate_count;
ULONG tx_timer_performance_expiration_count;
ULONG tx_timer_performance_expiration_adjust_count;
#endif
} TX_TIMER;
TX_TIMER_INTERNAL
typedef struct TX_TIMER_INTERNAL_STRUCT
{
ULONG tx_timer_internal_remaining_ticks;
ULONG tx_timer_internal_re_initialize_ticks;
VOID (*tx_timer_internal_timeout_function)(ULONG);
ULONG tx_timer_internal_timeout_param;
struct TX_TIMER_INTERNAL_STRUCT
*tx_timer_internal_active_next,
*tx_timer_internal_active_previous;
struct TX_TIMER_INTERNAL_STRUCT
*tx_timer_internal_list_head;
} TX_TIMER_INTERNAL;
User Guide
APPENDIX D
User Guide
344 ASCII Character Codes
0_ 1_ 2_ 3_ 4_ 5_ 6_ 7_
_0 NUL DLE SP 0 @ P ' p
_1 SOH DC1 ! 1 A Q a q
_2 STX DC2 " 2 B R b r
_3 ETX DC3 # 3 C S c s
_4 EOT DC4 $ 4 D T d t
_5 ENQ NAK % 5 E U e u
least significant nibble
User Guide
Index
Symbols number of 88, 91
total number of 88, 91
__tx_thread_context_restore 100 allocations
__tx_thread_context_save 100 number of 91
_application_ISR_entry 100 total number of 91
_tx_thread_context_restore 299 ANSI C 20
_tx_thread_context_save 299 application define 312
_tx_thread_stack_error_handler 62 application definition function 50
_tx_version_id 40 application downloaded to target 28
application entry point 48
A application linked 28
abort suspension of specified thread 272 application located on host 28
accelerated development application notification registration 70
benefit of ThreadX 26 application output request 305
activate an application timer 278 application resources 73, 79
activations application run-time behavior 63
number of 95 application specific modifications 21
total number of 95 application timer control block 95
adding assign/release facilities in the application timers 29, 46, 93, 94
device driver 297 application-specific modifications 21
advanced driver issue 303 application-specific processing 54
alleviating some buffer allocation architecture
processing 309
non-layering picokernel 20
allocate bytes of memory 126 ASCII character codes in HEX 344
allocate fixed-size block of memory 108 assembly language 20
allocation algorithm 90 asynchronous events 96
allocation of processing 22 available 79
allocation suspensions
high number of 88, 92 B
number of 88, 91
total number of 88, 91 Background Debug Mode (BDM) 28
allocation timeouts basic service call error checking
disable 36
User Guide
346 ThreadX User Guide
User Guide
Index 347
User Guide
Index 349
User Guide
Index 351
User Guide
Index 353
P priority ceiling 56
priority inheritance 57, 64, 81
packet I/O 303
priority inversion 56, 63, 78, 81
performance of embedded
priority inversions
microprocessors 306
number of 66
periodic interrupt 29
priority levels for ThreadX
periodic timers 93
defining 36
periodics 46
priority of internal ThreadX timer thread
physical memory 48
defining 37
picokernel 20 priority overhead 64
picokernel architecture 20 priority zero 96
pitfall 78, 81 priority-based scheduling 24
place an instance in counting process
semaphore 226 definition of 23
place an instance in counting semaphore process oriented operating system 23
with ceiling 208 processing bandwidth 63, 100
polling processing time allocation prior to real-time
definition of 298 kernels 24
polling as work aound to control loop processor allocation 25
response time 24
processor allocation logic 25
pool capacity 86, 90
processor isolation 25
pool memory area 87, 90
processor reset 44
portability of ThreadX 20, 26
processor-independent interface provided
preemption 55, 56 by ThreadX 25
preemption-threshold 56, 57, 64, 65, 78 producer-consumer 73
changing during run-time 57 product distribution 29
too low 66
program execution
preemptive scheduling 24
types of 44
premium package 29
protecting the software investment
priorities
ThreadX guarantees migration path 26
thread control block field 59 public resource 68, 73, 78, 93
prioritize block pool suspension list 122
memory blocks 86
prioritize byte pool suspension list 140 memory byte pool 89
prioritize mutex suspension list 176
prioritize queue suspension list 196 Q
prioritize semaphore suspension list 224
queue control 72
priority 54
queue empty suspensions
User Guide
Index 355
User Guide
Index 357
User Guide
Index 359
User Guide
Index 361
TX_TIMER_ENABLE_PERFORMANCE_ Windows 28
INFO 39, 95 write pointer 303, 304
tx_timer_info_get 98, 288
TX_TIMER_INTERNAL 341, 342
tx_timer_performance_info_get 95, 98,
290
tx_timer_performance_system_info_get 9
5, 98, 292
TX_TIMER_PROCESS_IN_ISR 37
TX_TIMER_THREAD_PRIORITY 37
TX_TIMER_THREAD_STACK_SIZE 37
tx_user.h 34, 35
types of program execution 44
typical thread stack 60
U
UART 303
un-deterministic behavior 85, 92
un-deterministic priority inversion 57, 64,
82
uninitialized data 46, 47
Unix 28
Unix development platform 30
unnecessary processing due to extra
poling 25
unpredictable behavior 50
user-supplied main function 49
using a semaphore to control driver
access 297
using ThreadX 31
V
version ID 40
W
watchdog services 46
User Guide