SuperTinyKernel™ RTOS 1.08.x
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
Loading...
Searching...
No Matches
STK ThreadX API

ThreadX interface for C++ API of SuperTinyKernel RTOS. More...

Classes

struct  TX_THREAD_STRUCT
struct  TX_MUTEX_STRUCT
struct  TX_SEMAPHORE_STRUCT
struct  TX_EVENT_FLAGS_GROUP_STRUCT
struct  TX_QUEUE_STRUCT
struct  TX_BLOCK_POOL_STRUCT
struct  TX_BYTE_POOL_STRUCT
struct  TX_TIMER_STRUCT

Macros

#define TX_TIMER_TICKS_PER_SECOND   (1000UL)
#define TX_MAX_PRIORITIES   (32U)
#define TX_STK_MAX_THREADS   (16U)
#define TX_TIMER_THREAD_PRIORITY   (0U)
#define TX_TIMER_THREAD_STACK_SIZE   (1024U) /* kept for source compatibility, see above */
#define TX_STK_THREAD_STORAGE_WORDS   (24U)
#define TX_STK_MUTEX_STORAGE_WORDS   (16U)
#define TX_STK_SEMAPHORE_STORAGE_WORDS   (16U)
#define TX_STK_QUEUE_STORAGE_WORDS   (48U)
#define TX_STK_BLOCK_POOL_STORAGE_WORDS   (32U)
#define TX_STK_BYTE_POOL_STORAGE_WORDS   (26U)
#define TX_STK_EVENT_FLAGS_STORAGE_DWORDS   (16U)
#define TX_STK_TIMER_STORAGE_DWORDS   (8U)
#define AZURE_RTOS_THREADX
#define THREADX_MAJOR_VERSION   6
#define THREADX_MINOR_VERSION   5
#define THREADX_PATCH_VERSION   2
#define THREADX_BUILD_VERSION   202603
#define TX_STK_WRAPPER_NAME   "ThreadX API on SuperTinyKernel"
#define VOID   void
#define TX_NAME_CONST   const
#define TX_NO_WAIT   ((ULONG) 0)
#define TX_WAIT_FOREVER   ((ULONG) 0xFFFFFFFFUL)
#define TX_AND   ((UINT) 2)
#define TX_AND_CLEAR   ((UINT) 3)
#define TX_OR   ((UINT) 0)
#define TX_OR_CLEAR   ((UINT) 1)
#define TX_1_ULONG   ((UINT) 1)
#define TX_2_ULONG   ((UINT) 2)
#define TX_4_ULONG   ((UINT) 4)
#define TX_8_ULONG   ((UINT) 8)
#define TX_16_ULONG   ((UINT) 16)
#define TX_NO_TIME_SLICE   ((ULONG) 0)
#define TX_AUTO_START   ((UINT) 1)
#define TX_DONT_START   ((UINT) 0)
#define TX_AUTO_ACTIVATE   ((UINT) 1)
#define TX_NO_ACTIVATE   ((UINT) 0)
#define TX_TRUE   ((UINT) 1)
#define TX_FALSE   ((UINT) 0)
#define TX_NULL   ((void *) 0)
#define TX_INHERIT   ((UINT) 1)
#define TX_NO_INHERIT   ((UINT) 0)
#define TX_THREAD_ENTRY   ((UINT) 0)
#define TX_THREAD_EXIT   ((UINT) 1)
#define TX_NO_SUSPENSIONS   ((UINT) 0)
#define TX_NO_MESSAGES   ((UINT) 0)
#define TX_EMPTY   ((ULONG) 0)
#define TX_CLEAR_ID   ((ULONG) 0)
#define TX_INT_DISABLE   ((UINT) 1)
#define TX_INT_ENABLE   ((UINT) 0)
#define TX_READY   ((UINT) 0)
#define TX_COMPLETED   ((UINT) 1)
#define TX_TERMINATED   ((UINT) 2)
#define TX_SUSPENDED   ((UINT) 3)
#define TX_SLEEP   ((UINT) 4)
#define TX_QUEUE_SUSP   ((UINT) 5)
#define TX_SEMAPHORE_SUSP   ((UINT) 6)
#define TX_EVENT_FLAG   ((UINT) 7)
#define TX_BLOCK_MEMORY   ((UINT) 8)
#define TX_BYTE_MEMORY   ((UINT) 9)
#define TX_IO_DRIVER   ((UINT) 10)
#define TX_FILE   ((UINT) 11)
#define TX_TCP_IP   ((UINT) 12)
#define TX_MUTEX_SUSP   ((UINT) 13)
#define TX_PRIORITY_CHANGE   ((UINT) 14)
#define TX_SUCCESS   ((UINT) 0x00)
#define TX_DELETED   ((UINT) 0x01)
#define TX_POOL_ERROR   ((UINT) 0x02)
#define TX_PTR_ERROR   ((UINT) 0x03)
#define TX_WAIT_ERROR   ((UINT) 0x04)
#define TX_SIZE_ERROR   ((UINT) 0x05)
#define TX_GROUP_ERROR   ((UINT) 0x06)
#define TX_NO_EVENTS   ((UINT) 0x07)
#define TX_OPTION_ERROR   ((UINT) 0x08)
#define TX_QUEUE_ERROR   ((UINT) 0x09)
#define TX_QUEUE_EMPTY   ((UINT) 0x0A)
#define TX_QUEUE_FULL   ((UINT) 0x0B)
#define TX_SEMAPHORE_ERROR   ((UINT) 0x0C)
#define TX_NO_INSTANCE   ((UINT) 0x0D)
#define TX_THREAD_ERROR   ((UINT) 0x0E)
#define TX_PRIORITY_ERROR   ((UINT) 0x0F)
#define TX_NO_MEMORY   ((UINT) 0x10)
#define TX_START_ERROR   ((UINT) 0x10)
#define TX_DELETE_ERROR   ((UINT) 0x11)
#define TX_RESUME_ERROR   ((UINT) 0x12)
#define TX_CALLER_ERROR   ((UINT) 0x13)
#define TX_SUSPEND_ERROR   ((UINT) 0x14)
#define TX_TIMER_ERROR   ((UINT) 0x15)
#define TX_TICK_ERROR   ((UINT) 0x16)
#define TX_ACTIVATE_ERROR   ((UINT) 0x17)
#define TX_THRESH_ERROR   ((UINT) 0x18)
#define TX_SUSPEND_LIFTED   ((UINT) 0x19)
#define TX_WAIT_ABORTED   ((UINT) 0x1A)
#define TX_WAIT_ABORT_ERROR   ((UINT) 0x1B)
#define TX_MUTEX_ERROR   ((UINT) 0x1C)
#define TX_NOT_AVAILABLE   ((UINT) 0x1D)
#define TX_NOT_OWNED   ((UINT) 0x1E)
#define TX_INHERIT_ERROR   ((UINT) 0x1F)
#define TX_NOT_DONE   ((UINT) 0x20)
#define TX_CEILING_EXCEEDED   ((UINT) 0x21)
#define TX_INVALID_PRIORITY   ((UINT) 0x22)
#define TX_FEATURE_NOT_ENABLED   ((UINT) 0xFF)
#define TX_THREAD_ID   ((ULONG) 0x54485244UL)
#define TX_MUTEX_ID   ((ULONG) 0x4D555445UL)
#define TX_QUEUE_ID   ((ULONG) 0x51554555UL)
#define TX_SEMAPHORE_ID   ((ULONG) 0x53454D41UL)
#define TX_EVENT_FLAGS_ID   ((ULONG) 0x4556454EUL)
#define TX_BLOCK_POOL_ID   ((ULONG) 0x424C4F43UL)
#define TX_BYTE_POOL_ID   ((ULONG) 0x42595445UL)
#define TX_TIMER_ID   ((ULONG) 0x54494D52UL)
#define TX_DISABLE   { unsigned int tx_stk_old_posture_ = tx_interrupt_control(TX_INT_DISABLE);
#define TX_RESTORE   (void) tx_interrupt_control(tx_stk_old_posture_); }

Typedefs

typedef char CHAR
typedef unsigned char UCHAR
typedef int INT
typedef unsigned int UINT
typedef int LONG
typedef unsigned int ULONG
typedef unsigned long long ULONG64
typedef short SHORT
typedef unsigned short USHORT
typedef uintptr_t ALIGN_TYPE
typedef struct TX_THREAD_STRUCT TX_THREAD
typedef struct TX_MUTEX_STRUCT TX_MUTEX
typedef struct TX_SEMAPHORE_STRUCT TX_SEMAPHORE
typedef struct TX_EVENT_FLAGS_GROUP_STRUCT TX_EVENT_FLAGS_GROUP
typedef struct TX_QUEUE_STRUCT TX_QUEUE
typedef struct TX_BLOCK_POOL_STRUCT TX_BLOCK_POOL
typedef struct TX_BYTE_POOL_STRUCT TX_BYTE_POOL
typedef struct TX_TIMER_STRUCT TX_TIMER

Functions

void tx_application_define (void *first_unused_memory)
void tx_kernel_enter (void)
UINT tx_interrupt_control (UINT new_posture)
ULONG tx_time_get (void)
void tx_time_set (ULONG new_time)
UINT tx_thread_create (TX_THREAD *thread_ptr, const CHAR *name_ptr, void(*entry_function)(ULONG entry_input), ULONG entry_input, void *stack_start, ULONG stack_size, UINT priority, UINT preempt_threshold, ULONG time_slice, UINT auto_start)
UINT tx_thread_delete (TX_THREAD *thread_ptr)
UINT tx_thread_entry_exit_notify (TX_THREAD *thread_ptr, void(*thread_entry_exit_notify)(TX_THREAD *notify_thread_ptr, UINT type))
TX_THREAD * tx_thread_identify (void)
UINT tx_thread_info_get (TX_THREAD *thread_ptr, const CHAR **name, UINT *state, ULONG *run_count, UINT *priority, UINT *preemption_threshold, ULONG *time_slice, TX_THREAD **next_thread, TX_THREAD **next_suspended_thread)
UINT tx_thread_preemption_change (TX_THREAD *thread_ptr, UINT new_threshold, UINT *old_threshold)
UINT tx_thread_priority_change (TX_THREAD *thread_ptr, UINT new_priority, UINT *old_priority)
void tx_thread_relinquish (void)
UINT tx_thread_reset (TX_THREAD *thread_ptr)
UINT tx_thread_resume (TX_THREAD *thread_ptr)
UINT tx_thread_sleep (ULONG timer_ticks)
UINT tx_thread_stack_error_notify (void(*stack_error_handler)(TX_THREAD *thread_ptr))
UINT tx_thread_suspend (TX_THREAD *thread_ptr)
UINT tx_thread_terminate (TX_THREAD *thread_ptr)
UINT tx_thread_time_slice_change (TX_THREAD *thread_ptr, ULONG new_time_slice, ULONG *old_time_slice)
UINT tx_thread_wait_abort (TX_THREAD *thread_ptr)
UINT tx_mutex_create (TX_MUTEX *mutex_ptr, const CHAR *name_ptr, UINT inherit)
UINT tx_mutex_delete (TX_MUTEX *mutex_ptr)
UINT tx_mutex_get (TX_MUTEX *mutex_ptr, ULONG wait_option)
UINT tx_mutex_put (TX_MUTEX *mutex_ptr)
UINT tx_mutex_info_get (TX_MUTEX *mutex_ptr, const CHAR **name, ULONG *count, TX_THREAD **owner, TX_THREAD **first_suspended, ULONG *suspended_count, TX_MUTEX **next_mutex)
UINT tx_mutex_prioritize (TX_MUTEX *mutex_ptr)
UINT tx_semaphore_create (TX_SEMAPHORE *semaphore_ptr, const CHAR *name_ptr, ULONG initial_count)
UINT tx_semaphore_delete (TX_SEMAPHORE *semaphore_ptr)
UINT tx_semaphore_get (TX_SEMAPHORE *semaphore_ptr, ULONG wait_option)
UINT tx_semaphore_put (TX_SEMAPHORE *semaphore_ptr)
UINT tx_semaphore_ceiling_put (TX_SEMAPHORE *semaphore_ptr, ULONG ceiling)
UINT tx_semaphore_info_get (TX_SEMAPHORE *semaphore_ptr, const CHAR **name, ULONG *current_value, TX_THREAD **first_suspended, ULONG *suspended_count, TX_SEMAPHORE **next_semaphore)
UINT tx_semaphore_prioritize (TX_SEMAPHORE *semaphore_ptr)
UINT tx_semaphore_put_notify (TX_SEMAPHORE *semaphore_ptr, void(*semaphore_put_notify)(TX_SEMAPHORE *notify_semaphore_ptr))
UINT tx_event_flags_create (TX_EVENT_FLAGS_GROUP *group_ptr, const CHAR *name_ptr)
UINT tx_event_flags_delete (TX_EVENT_FLAGS_GROUP *group_ptr)
UINT tx_event_flags_get (TX_EVENT_FLAGS_GROUP *group_ptr, ULONG requested_flags, UINT get_option, ULONG *actual_flags_ptr, ULONG wait_option)
UINT tx_event_flags_set (TX_EVENT_FLAGS_GROUP *group_ptr, ULONG flags_to_set, UINT set_option)
UINT tx_event_flags_info_get (TX_EVENT_FLAGS_GROUP *group_ptr, const CHAR **name, ULONG *current_flags, TX_THREAD **first_suspended, ULONG *suspended_count, TX_EVENT_FLAGS_GROUP **next_group)
UINT tx_event_flags_set_notify (TX_EVENT_FLAGS_GROUP *group_ptr, void(*events_set_notify)(TX_EVENT_FLAGS_GROUP *notify_group_ptr))
UINT tx_queue_create (TX_QUEUE *queue_ptr, const CHAR *name_ptr, UINT message_size, void *queue_start, ULONG queue_size)
UINT tx_queue_delete (TX_QUEUE *queue_ptr)
UINT tx_queue_flush (TX_QUEUE *queue_ptr)
UINT tx_queue_info_get (TX_QUEUE *queue_ptr, const CHAR **name, ULONG *enqueued, ULONG *available_storage, TX_THREAD **first_suspended, ULONG *suspended_count, TX_QUEUE **next_queue)
UINT tx_queue_prioritize (TX_QUEUE *queue_ptr)
UINT tx_queue_receive (TX_QUEUE *queue_ptr, void *destination_ptr, ULONG wait_option)
UINT tx_queue_send (TX_QUEUE *queue_ptr, void *source_ptr, ULONG wait_option)
UINT tx_queue_front_send (TX_QUEUE *queue_ptr, void *source_ptr, ULONG wait_option)
UINT tx_queue_send_notify (TX_QUEUE *queue_ptr, void(*queue_send_notify)(TX_QUEUE *notify_queue_ptr))
UINT tx_block_pool_create (TX_BLOCK_POOL *pool_ptr, const CHAR *name_ptr, ULONG block_size, void *pool_start, ULONG pool_size)
UINT tx_block_pool_delete (TX_BLOCK_POOL *pool_ptr)
UINT tx_block_allocate (TX_BLOCK_POOL *pool_ptr, void **block_ptr, ULONG wait_option)
UINT tx_block_release (void *block_ptr)
UINT tx_block_pool_info_get (TX_BLOCK_POOL *pool_ptr, const CHAR **name, ULONG *available_blocks, ULONG *total_blocks, TX_THREAD **first_suspended, ULONG *suspended_count, TX_BLOCK_POOL **next_pool)
UINT tx_block_pool_prioritize (TX_BLOCK_POOL *pool_ptr)
UINT tx_byte_pool_create (TX_BYTE_POOL *pool_ptr, const CHAR *name_ptr, void *pool_start, ULONG pool_size)
UINT tx_byte_pool_delete (TX_BYTE_POOL *pool_ptr)
UINT tx_byte_allocate (TX_BYTE_POOL *pool_ptr, void **memory_ptr, ULONG memory_size, ULONG wait_option)
UINT tx_byte_release (void *memory_ptr)
UINT tx_byte_pool_info_get (TX_BYTE_POOL *pool_ptr, const CHAR **name, ULONG *available_bytes, ULONG *fragments, TX_THREAD **first_suspended, ULONG *suspended_count, TX_BYTE_POOL **next_pool)
UINT tx_byte_pool_prioritize (TX_BYTE_POOL *pool_ptr)
UINT tx_timer_create (TX_TIMER *timer_ptr, const CHAR *name_ptr, void(*expiration_function)(ULONG input), ULONG expiration_input, ULONG initial_ticks, ULONG reschedule_ticks, UINT auto_activate)
UINT tx_timer_delete (TX_TIMER *timer_ptr)
UINT tx_timer_activate (TX_TIMER *timer_ptr)
UINT tx_timer_deactivate (TX_TIMER *timer_ptr)
UINT tx_timer_change (TX_TIMER *timer_ptr, ULONG initial_ticks, ULONG reschedule_ticks)
UINT tx_timer_info_get (TX_TIMER *timer_ptr, const CHAR **name, UINT *active, ULONG *remaining_ticks, ULONG *reschedule_ticks, TX_TIMER **next_timer)

Detailed Description

ThreadX interface for C++ API of SuperTinyKernel RTOS.

This header is a drop-in replacement for ThreadX's tx_api.h: application code written against the standard tx_* C API compiles unchanged, while the implementation (threadx_stk.cpp) maps it onto STK (sched::SwitchStrategyPreemptionThreshold<TX_MAX_PRIORITIES, true> = ThreadX-style priority + preemption-threshold + time-slicing).

The header is plain C (also valid C++). Control blocks are caller-allocated as in ThreadX; the STK objects live in the opaque storage member of each control block (placement-new, no heap).

See README.md in this folder for the full list of differences from native ThreadX.

Macro Definition Documentation

◆ AZURE_RTOS_THREADX

#define AZURE_RTOS_THREADX

Definition at line 109 of file tx_api.h.

◆ THREADX_BUILD_VERSION

#define THREADX_BUILD_VERSION   202603

Definition at line 113 of file tx_api.h.

◆ THREADX_MAJOR_VERSION

#define THREADX_MAJOR_VERSION   6

Definition at line 110 of file tx_api.h.

◆ THREADX_MINOR_VERSION

#define THREADX_MINOR_VERSION   5

Definition at line 111 of file tx_api.h.

◆ THREADX_PATCH_VERSION

#define THREADX_PATCH_VERSION   2

Definition at line 112 of file tx_api.h.

◆ TX_16_ULONG

#define TX_16_ULONG   ((UINT) 16)

Definition at line 153 of file tx_api.h.

Referenced by tx_queue_create().

◆ TX_1_ULONG

#define TX_1_ULONG   ((UINT) 1)
Examples
blinky-threadx/demo_threadx.c.

Definition at line 149 of file tx_api.h.

Referenced by tx_application_define(), and tx_queue_create().

◆ TX_2_ULONG

#define TX_2_ULONG   ((UINT) 2)

Definition at line 150 of file tx_api.h.

◆ TX_4_ULONG

#define TX_4_ULONG   ((UINT) 4)

Definition at line 151 of file tx_api.h.

◆ TX_8_ULONG

#define TX_8_ULONG   ((UINT) 8)

Definition at line 152 of file tx_api.h.

◆ TX_ACTIVATE_ERROR

#define TX_ACTIVATE_ERROR   ((UINT) 0x17)

Definition at line 217 of file tx_api.h.

Referenced by tx_timer_activate(), tx_timer_change(), and tx_timer_create().

◆ TX_AND

#define TX_AND   ((UINT) 2)

Definition at line 145 of file tx_api.h.

Referenced by tx_event_flags_get(), and tx_event_flags_set().

◆ TX_AND_CLEAR

#define TX_AND_CLEAR   ((UINT) 3)

Definition at line 146 of file tx_api.h.

Referenced by tx_event_flags_get().

◆ TX_AUTO_ACTIVATE

#define TX_AUTO_ACTIVATE   ((UINT) 1)

Definition at line 157 of file tx_api.h.

Referenced by tx_timer_create().

◆ TX_AUTO_START

#define TX_AUTO_START   ((UINT) 1)

◆ TX_BLOCK_MEMORY

#define TX_BLOCK_MEMORY   ((UINT) 8)

Definition at line 184 of file tx_api.h.

Referenced by tx_block_allocate().

◆ TX_BLOCK_POOL_ID

#define TX_BLOCK_POOL_ID   ((ULONG) 0x424C4F43UL)

Definition at line 237 of file tx_api.h.

Referenced by tx_block_pool_create().

◆ TX_BYTE_MEMORY

#define TX_BYTE_MEMORY   ((UINT) 9)

Definition at line 185 of file tx_api.h.

Referenced by tx_byte_allocate().

◆ TX_BYTE_POOL_ID

#define TX_BYTE_POOL_ID   ((ULONG) 0x42595445UL)

Definition at line 238 of file tx_api.h.

Referenced by tx_byte_pool_create().

◆ TX_CALLER_ERROR

◆ TX_CEILING_EXCEEDED

#define TX_CEILING_EXCEEDED   ((UINT) 0x21)

Definition at line 227 of file tx_api.h.

Referenced by tx_semaphore_ceiling_put(), and tx_semaphore_put().

◆ TX_CLEAR_ID

◆ TX_COMPLETED

#define TX_COMPLETED   ((UINT) 1)

Definition at line 177 of file tx_api.h.

Referenced by tx_thread_delete(), tx_thread_reset(), and tx_thread_terminate().

◆ TX_DELETE_ERROR

#define TX_DELETE_ERROR   ((UINT) 0x11)

Definition at line 211 of file tx_api.h.

Referenced by tx_thread_delete().

◆ TX_DELETED

#define TX_DELETED   ((UINT) 0x01)

Definition at line 194 of file tx_api.h.

◆ TX_DISABLE

#define TX_DISABLE   { unsigned int tx_stk_old_posture_ = tx_interrupt_control(TX_INT_DISABLE);

Definition at line 480 of file tx_api.h.

◆ TX_DONT_START

#define TX_DONT_START   ((UINT) 0)

Definition at line 156 of file tx_api.h.

◆ TX_EMPTY

#define TX_EMPTY   ((ULONG) 0)

Definition at line 168 of file tx_api.h.

◆ TX_EVENT_FLAG

#define TX_EVENT_FLAG   ((UINT) 7)

Definition at line 183 of file tx_api.h.

Referenced by tx_event_flags_get().

◆ TX_EVENT_FLAGS_ID

#define TX_EVENT_FLAGS_ID   ((ULONG) 0x4556454EUL)

Definition at line 236 of file tx_api.h.

Referenced by tx_event_flags_create().

◆ TX_FALSE

#define TX_FALSE   ((UINT) 0)

Definition at line 160 of file tx_api.h.

Referenced by tx_timer_info_get().

◆ TX_FEATURE_NOT_ENABLED

#define TX_FEATURE_NOT_ENABLED   ((UINT) 0xFF)

Definition at line 229 of file tx_api.h.

Referenced by tx_timer_create().

◆ TX_FILE

#define TX_FILE   ((UINT) 11)

Definition at line 187 of file tx_api.h.

◆ TX_GROUP_ERROR

◆ TX_INHERIT

#define TX_INHERIT   ((UINT) 1)

Definition at line 162 of file tx_api.h.

Referenced by tx_mutex_create().

◆ TX_INHERIT_ERROR

#define TX_INHERIT_ERROR   ((UINT) 0x1F)

Definition at line 225 of file tx_api.h.

Referenced by tx_mutex_create().

◆ TX_INT_DISABLE

#define TX_INT_DISABLE   ((UINT) 1)

Definition at line 172 of file tx_api.h.

Referenced by tx_interrupt_control().

◆ TX_INT_ENABLE

#define TX_INT_ENABLE   ((UINT) 0)

Definition at line 173 of file tx_api.h.

Referenced by tx_interrupt_control().

◆ TX_INVALID_PRIORITY

#define TX_INVALID_PRIORITY   ((UINT) 0x22)

Definition at line 228 of file tx_api.h.

◆ TX_IO_DRIVER

#define TX_IO_DRIVER   ((UINT) 10)

Definition at line 186 of file tx_api.h.

◆ TX_MAX_PRIORITIES

#define TX_MAX_PRIORITIES   (32U)

Definition at line 55 of file tx_api.h.

Referenced by tx_thread_create(), and tx_thread_priority_change().

◆ TX_MUTEX_ERROR

#define TX_MUTEX_ERROR   ((UINT) 0x1C)

◆ TX_MUTEX_ID

#define TX_MUTEX_ID   ((ULONG) 0x4D555445UL)

Definition at line 233 of file tx_api.h.

Referenced by tx_mutex_create().

◆ TX_MUTEX_SUSP

#define TX_MUTEX_SUSP   ((UINT) 13)

Definition at line 189 of file tx_api.h.

Referenced by tx_mutex_get().

◆ TX_NAME_CONST

◆ TX_NO_ACTIVATE

#define TX_NO_ACTIVATE   ((UINT) 0)

Definition at line 158 of file tx_api.h.

◆ TX_NO_EVENTS

#define TX_NO_EVENTS   ((UINT) 0x07)

Definition at line 200 of file tx_api.h.

Referenced by tx_event_flags_get().

◆ TX_NO_INHERIT

#define TX_NO_INHERIT   ((UINT) 0)
Examples
blinky-threadx/demo_threadx.c.

Definition at line 163 of file tx_api.h.

Referenced by tx_application_define().

◆ TX_NO_INSTANCE

#define TX_NO_INSTANCE   ((UINT) 0x0D)

Definition at line 206 of file tx_api.h.

Referenced by tx_semaphore_get().

◆ TX_NO_MEMORY

#define TX_NO_MEMORY   ((UINT) 0x10)

Definition at line 209 of file tx_api.h.

Referenced by tx_block_allocate(), and tx_byte_allocate().

◆ TX_NO_MESSAGES

#define TX_NO_MESSAGES   ((UINT) 0)

Definition at line 167 of file tx_api.h.

◆ TX_NO_SUSPENSIONS

#define TX_NO_SUSPENSIONS   ((UINT) 0)

Definition at line 166 of file tx_api.h.

◆ TX_NO_TIME_SLICE

#define TX_NO_TIME_SLICE   ((ULONG) 0)

◆ TX_NO_WAIT

#define TX_NO_WAIT   ((ULONG) 0)
Examples
blinky-threadx/demo_threadx.c.

Definition at line 143 of file tx_api.h.

Referenced by tx_application_define().

◆ TX_NOT_AVAILABLE

#define TX_NOT_AVAILABLE   ((UINT) 0x1D)

Definition at line 223 of file tx_api.h.

Referenced by tx_mutex_get().

◆ TX_NOT_DONE

#define TX_NOT_DONE   ((UINT) 0x20)

Definition at line 226 of file tx_api.h.

Referenced by tx_thread_reset().

◆ TX_NOT_OWNED

#define TX_NOT_OWNED   ((UINT) 0x1E)

Definition at line 224 of file tx_api.h.

Referenced by tx_mutex_put().

◆ TX_NULL

#define TX_NULL   ((void *) 0)
Examples
blinky-threadx/demo_threadx.c.

Definition at line 161 of file tx_api.h.

Referenced by tx_application_define().

◆ TX_OPTION_ERROR

#define TX_OPTION_ERROR   ((UINT) 0x08)

Definition at line 201 of file tx_api.h.

Referenced by tx_event_flags_get(), tx_event_flags_set(), and tx_semaphore_ceiling_put().

◆ TX_OR

#define TX_OR   ((UINT) 0)

◆ TX_OR_CLEAR

#define TX_OR_CLEAR   ((UINT) 1)
Examples
blinky-threadx/demo_threadx.c, and blinky_c-threadx/example.c.

Definition at line 148 of file tx_api.h.

Referenced by thread_5_entry(), and wait_flag().

◆ TX_POOL_ERROR

◆ TX_PRIORITY_CHANGE

#define TX_PRIORITY_CHANGE   ((UINT) 14)

Definition at line 190 of file tx_api.h.

◆ TX_PRIORITY_ERROR

#define TX_PRIORITY_ERROR   ((UINT) 0x0F)

Definition at line 208 of file tx_api.h.

Referenced by tx_thread_create(), and tx_thread_priority_change().

◆ TX_PTR_ERROR

◆ TX_QUEUE_EMPTY

#define TX_QUEUE_EMPTY   ((UINT) 0x0A)

Definition at line 203 of file tx_api.h.

Referenced by tx_queue_receive().

◆ TX_QUEUE_ERROR

#define TX_QUEUE_ERROR   ((UINT) 0x09)

◆ TX_QUEUE_FULL

#define TX_QUEUE_FULL   ((UINT) 0x0B)

Definition at line 204 of file tx_api.h.

◆ TX_QUEUE_ID

#define TX_QUEUE_ID   ((ULONG) 0x51554555UL)

Definition at line 234 of file tx_api.h.

Referenced by tx_queue_create().

◆ TX_QUEUE_SUSP

#define TX_QUEUE_SUSP   ((UINT) 5)

Definition at line 181 of file tx_api.h.

Referenced by tx_queue_receive().

◆ TX_READY

#define TX_READY   ((UINT) 0)

Definition at line 176 of file tx_api.h.

Referenced by tx_thread_suspend().

◆ TX_RESTORE

#define TX_RESTORE   (void) tx_interrupt_control(tx_stk_old_posture_); }

Definition at line 481 of file tx_api.h.

◆ TX_RESUME_ERROR

#define TX_RESUME_ERROR   ((UINT) 0x12)

Definition at line 212 of file tx_api.h.

Referenced by tx_thread_resume().

◆ TX_SEMAPHORE_ERROR

◆ TX_SEMAPHORE_ID

#define TX_SEMAPHORE_ID   ((ULONG) 0x53454D41UL)

Definition at line 235 of file tx_api.h.

Referenced by tx_semaphore_create().

◆ TX_SEMAPHORE_SUSP

#define TX_SEMAPHORE_SUSP   ((UINT) 6)

Definition at line 182 of file tx_api.h.

Referenced by tx_semaphore_get().

◆ TX_SIZE_ERROR

#define TX_SIZE_ERROR   ((UINT) 0x05)

◆ TX_SLEEP

#define TX_SLEEP   ((UINT) 4)

Definition at line 180 of file tx_api.h.

◆ TX_START_ERROR

#define TX_START_ERROR   ((UINT) 0x10)

Definition at line 210 of file tx_api.h.

Referenced by tx_thread_create().

◆ TX_STK_BLOCK_POOL_STORAGE_WORDS

#define TX_STK_BLOCK_POOL_STORAGE_WORDS   (32U)

Definition at line 90 of file tx_api.h.

◆ TX_STK_BYTE_POOL_STORAGE_WORDS

#define TX_STK_BYTE_POOL_STORAGE_WORDS   (26U)

Definition at line 93 of file tx_api.h.

◆ TX_STK_EVENT_FLAGS_STORAGE_DWORDS

#define TX_STK_EVENT_FLAGS_STORAGE_DWORDS   (16U)

Definition at line 99 of file tx_api.h.

◆ TX_STK_MAX_THREADS

#define TX_STK_MAX_THREADS   (16U)

Definition at line 61 of file tx_api.h.

◆ TX_STK_MUTEX_STORAGE_WORDS

#define TX_STK_MUTEX_STORAGE_WORDS   (16U)

Definition at line 80 of file tx_api.h.

◆ TX_STK_QUEUE_STORAGE_WORDS

#define TX_STK_QUEUE_STORAGE_WORDS   (48U)

Definition at line 87 of file tx_api.h.

◆ TX_STK_SEMAPHORE_STORAGE_WORDS

#define TX_STK_SEMAPHORE_STORAGE_WORDS   (16U)

Definition at line 83 of file tx_api.h.

◆ TX_STK_THREAD_STORAGE_WORDS

#define TX_STK_THREAD_STORAGE_WORDS   (24U)

Definition at line 77 of file tx_api.h.

◆ TX_STK_TIMER_STORAGE_DWORDS

#define TX_STK_TIMER_STORAGE_DWORDS   (8U)

Definition at line 102 of file tx_api.h.

◆ TX_STK_WRAPPER_NAME

#define TX_STK_WRAPPER_NAME   "ThreadX API on SuperTinyKernel"

Definition at line 114 of file tx_api.h.

◆ TX_SUCCESS

#define TX_SUCCESS   ((UINT) 0x00)

◆ TX_SUSPEND_ERROR

#define TX_SUSPEND_ERROR   ((UINT) 0x14)

Definition at line 214 of file tx_api.h.

Referenced by tx_thread_suspend().

◆ TX_SUSPEND_LIFTED

#define TX_SUSPEND_LIFTED   ((UINT) 0x19)

Definition at line 219 of file tx_api.h.

Referenced by tx_thread_resume().

◆ TX_SUSPENDED

#define TX_SUSPENDED   ((UINT) 3)

Definition at line 179 of file tx_api.h.

Referenced by IsNotStarted(), tx_thread_create(), and tx_thread_reset().

◆ TX_TCP_IP

#define TX_TCP_IP   ((UINT) 12)

Definition at line 188 of file tx_api.h.

◆ TX_TERMINATED

#define TX_TERMINATED   ((UINT) 2)

Definition at line 178 of file tx_api.h.

Referenced by tx_thread_delete(), tx_thread_reset(), and tx_thread_terminate().

◆ TX_THREAD_ENTRY

#define TX_THREAD_ENTRY   ((UINT) 0)

Definition at line 164 of file tx_api.h.

◆ TX_THREAD_ERROR

◆ TX_THREAD_EXIT

#define TX_THREAD_EXIT   ((UINT) 1)

Definition at line 165 of file tx_api.h.

Referenced by tx_thread_terminate().

◆ TX_THREAD_ID

#define TX_THREAD_ID   ((ULONG) 0x54485244UL)

Definition at line 232 of file tx_api.h.

Referenced by tx_thread_create().

◆ TX_THRESH_ERROR

#define TX_THRESH_ERROR   ((UINT) 0x18)

Definition at line 218 of file tx_api.h.

Referenced by tx_thread_create(), and tx_thread_preemption_change().

◆ TX_TICK_ERROR

#define TX_TICK_ERROR   ((UINT) 0x16)

Definition at line 216 of file tx_api.h.

Referenced by tx_timer_change(), and tx_timer_create().

◆ TX_TIMER_ERROR

#define TX_TIMER_ERROR   ((UINT) 0x15)

◆ TX_TIMER_ID

#define TX_TIMER_ID   ((ULONG) 0x54494D52UL)

Definition at line 239 of file tx_api.h.

Referenced by tx_timer_create().

◆ TX_TIMER_THREAD_PRIORITY

#define TX_TIMER_THREAD_PRIORITY   (0U)

Definition at line 68 of file tx_api.h.

◆ TX_TIMER_THREAD_STACK_SIZE

#define TX_TIMER_THREAD_STACK_SIZE   (1024U) /* kept for source compatibility, see above */

Definition at line 71 of file tx_api.h.

◆ TX_TIMER_TICKS_PER_SECOND

#define TX_TIMER_TICKS_PER_SECOND   (1000UL)

Definition at line 49 of file tx_api.h.

Referenced by tx_kernel_enter().

◆ TX_TRUE

#define TX_TRUE   ((UINT) 1)

Definition at line 159 of file tx_api.h.

Referenced by tx_timer_info_get().

◆ TX_WAIT_ABORT_ERROR

#define TX_WAIT_ABORT_ERROR   ((UINT) 0x1B)

Definition at line 221 of file tx_api.h.

Referenced by tx_thread_wait_abort().

◆ TX_WAIT_ABORTED

#define TX_WAIT_ABORTED   ((UINT) 0x1A)

Definition at line 220 of file tx_api.h.

Referenced by tx_thread_sleep().

◆ TX_WAIT_ERROR

#define TX_WAIT_ERROR   ((UINT) 0x04)

◆ TX_WAIT_FOREVER

#define TX_WAIT_FOREVER   ((ULONG) 0xFFFFFFFFUL)

◆ VOID

Typedef Documentation

◆ ALIGN_TYPE

typedef uintptr_t ALIGN_TYPE

Definition at line 135 of file tx_api.h.

◆ CHAR

typedef char CHAR
Examples
blinky-threadx/demo_threadx.c.

Definition at line 121 of file tx_api.h.

◆ INT

typedef int INT

Definition at line 123 of file tx_api.h.

◆ LONG

typedef int LONG

Definition at line 129 of file tx_api.h.

◆ SHORT

typedef short SHORT

Definition at line 133 of file tx_api.h.

◆ TX_BLOCK_POOL

◆ TX_BYTE_POOL

◆ TX_EVENT_FLAGS_GROUP

◆ TX_MUTEX

◆ TX_QUEUE

◆ TX_SEMAPHORE

◆ TX_THREAD

◆ TX_TIMER

typedef struct TX_TIMER_STRUCT TX_TIMER

◆ UCHAR

typedef unsigned char UCHAR
Examples
blinky-threadx/demo_threadx.c.

Definition at line 122 of file tx_api.h.

◆ UINT

typedef unsigned int UINT
Examples
blinky-threadx/demo_threadx.c.

Definition at line 124 of file tx_api.h.

◆ ULONG

typedef unsigned int ULONG
Examples
blinky-threadx/demo_threadx.c, and blinky_c-threadx/example.c.

Definition at line 130 of file tx_api.h.

◆ ULONG64

typedef unsigned long long ULONG64

Definition at line 132 of file tx_api.h.

◆ USHORT

typedef unsigned short USHORT

Definition at line 134 of file tx_api.h.

Function Documentation

◆ tx_application_define()

void tx_application_define ( void * first_unused_memory)
Examples
blinky-threadx/demo_threadx.c, and blinky_c-threadx/example.c.

Definition at line 132 of file demo_threadx.c.

133{
134
135CHAR *pointer = TX_NULL;
136
137
138 /* Create a byte memory pool from which to allocate the thread stacks. */
140
141 /* Put system definition stuff in here, e.g. thread creates and other assorted
142 create information. */
143
144 /* Allocate the stack for thread 0. */
146
147 /* Create the main thread. */
148 tx_thread_create(&thread_0, "thread 0", thread_0_entry, 0,
149 pointer, DEMO_STACK_SIZE,
151
152
153 /* Allocate the stack for thread 1. */
155
156 /* Create threads 1 and 2. These threads pass information through a ThreadX
157 message queue. It is also interesting to note that these threads have a time
158 slice. */
159 tx_thread_create(&thread_1, "thread 1", thread_1_entry, 1,
160 pointer, DEMO_STACK_SIZE,
161 16, 16, 4, TX_AUTO_START);
162
163 /* Allocate the stack for thread 2. */
165
166 tx_thread_create(&thread_2, "thread 2", thread_2_entry, 2,
167 pointer, DEMO_STACK_SIZE,
168 16, 16, 4, TX_AUTO_START);
169
170 /* Allocate the stack for thread 3. */
172
173 /* Create threads 3 and 4. These threads compete for a ThreadX counting semaphore.
174 An interesting thing here is that both threads share the same instruction area. */
176 pointer, DEMO_STACK_SIZE,
178
179 /* Allocate the stack for thread 4. */
181
183 pointer, DEMO_STACK_SIZE,
185
186 /* Allocate the stack for thread 5. */
188
189 /* Create thread 5. This thread simply pends on an event flag which will be set
190 by thread_0. */
191 tx_thread_create(&thread_5, "thread 5", thread_5_entry, 5,
192 pointer, DEMO_STACK_SIZE,
194
195 /* Allocate the stack for thread 6. */
197
198 /* Create threads 6 and 7. These threads compete for a ThreadX mutex. */
200 pointer, DEMO_STACK_SIZE,
202
203 /* Allocate the stack for thread 7. */
205
207 pointer, DEMO_STACK_SIZE,
209
210 /* Allocate the message queue. */
212
213 /* Create the message queue shared by threads 1 and 2. */
214 tx_queue_create(&queue_0, "queue 0", TX_1_ULONG, pointer, DEMO_QUEUE_SIZE*sizeof(ULONG));
215
216 /* Create the semaphore used by threads 3 and 4. */
217 tx_semaphore_create(&semaphore_0, "semaphore 0", 1);
218
219 /* Create the event flags group used by threads 1 and 5. */
220 tx_event_flags_create(&event_flags_0, "event flags 0");
221
222 /* Create the mutex used by thread 6 and 7 without priority inheritance. */
224
225 /* Allocate the memory for a small block pool. */
227
228 /* Create a block memory pool to allocate a message buffer from. */
229 tx_block_pool_create(&block_pool_0, "block pool 0", sizeof(ULONG), pointer, DEMO_BLOCK_POOL_SIZE);
230
231 /* Allocate a block and release the block memory. */
233
234 /* Release the block back to the pool. */
235 tx_block_release(pointer);
236}
UCHAR memory_area[9120]
TX_BLOCK_POOL block_pool_0
void thread_2_entry(ULONG thread_input)
TX_THREAD thread_0
#define DEMO_STACK_SIZE
void thread_1_entry(ULONG thread_input)
void thread_0_entry(ULONG thread_input)
#define DEMO_BYTE_POOL_SIZE
TX_MUTEX mutex_0
void thread_6_and_7_entry(ULONG thread_input)
TX_THREAD thread_3
TX_QUEUE queue_0
#define DEMO_QUEUE_SIZE
void thread_5_entry(ULONG thread_input)
TX_BYTE_POOL byte_pool_0
TX_THREAD thread_5
TX_THREAD thread_4
TX_SEMAPHORE semaphore_0
TX_THREAD thread_2
TX_THREAD thread_7
TX_THREAD thread_1
TX_EVENT_FLAGS_GROUP event_flags_0
TX_THREAD thread_6
#define DEMO_BLOCK_POOL_SIZE
void thread_3_and_4_entry(ULONG thread_input)
#define TX_NO_INHERIT
Definition tx_api.h:163
UINT tx_semaphore_create(TX_SEMAPHORE *semaphore_ptr, const CHAR *name_ptr, ULONG initial_count)
UINT tx_queue_create(TX_QUEUE *queue_ptr, const CHAR *name_ptr, UINT message_size, void *queue_start, ULONG queue_size)
UINT tx_event_flags_create(TX_EVENT_FLAGS_GROUP *group_ptr, const CHAR *name_ptr)
#define TX_NULL
Definition tx_api.h:161
UINT tx_mutex_create(TX_MUTEX *mutex_ptr, const CHAR *name_ptr, UINT inherit)
UINT tx_thread_create(TX_THREAD *thread_ptr, const CHAR *name_ptr, void(*entry_function)(ULONG entry_input), ULONG entry_input, void *stack_start, ULONG stack_size, UINT priority, UINT preempt_threshold, ULONG time_slice, UINT auto_start)
UINT tx_byte_allocate(TX_BYTE_POOL *pool_ptr, void **memory_ptr, ULONG memory_size, ULONG wait_option)
UINT tx_block_release(void *block_ptr)
#define VOID
Definition tx_api.h:120
#define TX_NO_WAIT
Definition tx_api.h:143
#define TX_1_ULONG
Definition tx_api.h:149
#define TX_NO_TIME_SLICE
Definition tx_api.h:154
UINT tx_block_pool_create(TX_BLOCK_POOL *pool_ptr, const CHAR *name_ptr, ULONG block_size, void *pool_start, ULONG pool_size)
unsigned int ULONG
Definition tx_api.h:130
UINT tx_block_allocate(TX_BLOCK_POOL *pool_ptr, void **block_ptr, ULONG wait_option)
char CHAR
Definition tx_api.h:121
#define TX_AUTO_START
Definition tx_api.h:155
UINT tx_byte_pool_create(TX_BYTE_POOL *pool_ptr, const CHAR *name_ptr, void *pool_start, ULONG pool_size)

References app_main(), APP_PRIORITY, block_pool_0, byte_pool_0, DEMO_BLOCK_POOL_SIZE, DEMO_BYTE_POOL_SIZE, DEMO_QUEUE_SIZE, DEMO_STACK_SIZE, event_flags_0, g_flags, memory_area, mutex_0, queue_0, semaphore_0, stack_app_main, STACK_SIZE, thread_0, thread_0_entry(), thread_1, thread_1_entry(), thread_2, thread_2_entry(), thread_3, thread_3_and_4_entry(), thread_4, thread_5, thread_5_entry(), thread_6, thread_6_and_7_entry(), thread_7, tid_app_main, TX_1_ULONG, TX_AUTO_START, tx_block_allocate(), tx_block_pool_create(), tx_block_release(), tx_byte_allocate(), tx_byte_pool_create(), tx_event_flags_create(), tx_mutex_create(), TX_NO_INHERIT, TX_NO_TIME_SLICE, TX_NO_WAIT, TX_NULL, tx_queue_create(), tx_semaphore_create(), tx_thread_create(), and VOID.

Referenced by tx_kernel_enter().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tx_block_allocate()

UINT tx_block_allocate ( TX_BLOCK_POOL * pool_ptr,
void ** block_ptr,
ULONG wait_option )
Examples
blinky-threadx/demo_threadx.c.

Definition at line 2052 of file threadx_stk.cpp.

2053{
2054 UINT result;
2055
2056 if (!IsValidBlockPool(pool_ptr))
2057 {
2058 result = TX_POOL_ERROR;
2059 }
2060 else if (block_ptr == nullptr)
2061 {
2062 result = TX_PTR_ERROR;
2063 }
2064 else if (!CanBlock(wait_option))
2065 {
2066 result = TX_WAIT_ERROR;
2067 }
2068 else
2069 {
2070 void *blk = nullptr;
2072
2073 {
2074 const ScopedWaitKind ws(TX_BLOCK_MEMORY, wait_option);
2075
2076 wr = BlockPoolOf(pool_ptr)->TimedAllocEx(&blk, ToStkTimeout(wait_option));
2077 }
2078
2079 result = WaitResultToTx(wr, TX_NO_MEMORY);
2080
2081 if ((result == TX_SUCCESS) && (blk != nullptr))
2082 {
2083 // store the owner in the hidden header, hand out the area behind it
2084 *static_cast<TX_BLOCK_POOL **>(blk) = pool_ptr;
2085 *block_ptr = (static_cast<uint8_t *>(blk) + BLOCK_HDR_SIZE);
2086 }
2087 else if (result == TX_SUCCESS)
2088 {
2089 result = TX_NO_MEMORY;
2090 }
2091 else
2092 {
2093 // noop: error status is already set
2094 }
2095 }
2096
2097 return result;
2098}
unsigned int UINT
Definition tx_api.h:124
#define TX_SUCCESS
Definition tx_api.h:193
#define TX_WAIT_ERROR
Definition tx_api.h:197
#define TX_POOL_ERROR
Definition tx_api.h:195
#define TX_PTR_ERROR
Definition tx_api.h:196
#define TX_BLOCK_MEMORY
Definition tx_api.h:184
struct TX_BLOCK_POOL_STRUCT TX_BLOCK_POOL
#define TX_NO_MEMORY
Definition tx_api.h:209
EWaitResult
Wait result (see IKernelService::Wait).
Definition stk_common.h:138

References TX_BLOCK_MEMORY, TX_NO_MEMORY, TX_POOL_ERROR, TX_PTR_ERROR, TX_SUCCESS, TX_WAIT_ERROR, and VOID.

Referenced by tx_application_define().

Here is the caller graph for this function:

◆ tx_block_pool_create()

UINT tx_block_pool_create ( TX_BLOCK_POOL * pool_ptr,
const CHAR * name_ptr,
ULONG block_size,
void * pool_start,
ULONG pool_size )
Examples
blinky-threadx/demo_threadx.c.

Definition at line 1977 of file threadx_stk.cpp.

1979{
1980 UINT result;
1981
1982 if (pool_ptr == nullptr)
1983 {
1984 result = TX_POOL_ERROR;
1985 }
1986 else if (pool_ptr->tx_block_pool_id == TX_BLOCK_POOL_ID)
1987 {
1988 result = TX_POOL_ERROR; // already created
1989 }
1990 else if ((pool_start == nullptr) || ((reinterpret_cast<uintptr_t>(pool_start) % sizeof(void *)) != 0U))
1991 {
1992 result = TX_PTR_ERROR;
1993 }
1994 else if (block_size == 0U)
1995 {
1996 result = TX_SIZE_ERROR;
1997 }
1998 else if (InIsr())
1999 {
2000 result = TX_CALLER_ERROR;
2001 }
2002 else
2003 {
2004 const size_t stride = stk::memory::BlockMemoryPool::AlignBlockSize(static_cast<size_t>(block_size) + BLOCK_HDR_SIZE);
2005 size_t capacity = (static_cast<size_t>(pool_size) / stride);
2006
2007 if (capacity < 1U)
2008 {
2009 result = TX_SIZE_ERROR;
2010 }
2011 else
2012 {
2014
2015 stk::memory::BlockMemoryPool *const p = new (static_cast<void *>(pool_ptr->tx_block_pool_stk_storage))
2016 stk::memory::BlockMemoryPool(capacity, static_cast<size_t>(block_size) + BLOCK_HDR_SIZE,
2017 static_cast<uint8_t *>(pool_start), (capacity * stride), name_ptr);
2018 p->SetTraceName(name_ptr);
2019
2020 pool_ptr->tx_block_pool_name = name_ptr;
2022 result = TX_SUCCESS;
2023 }
2024 }
2025
2026 return result;
2027}
#define TX_BLOCK_POOL_ID
Definition tx_api.h:237
#define TX_SIZE_ERROR
Definition tx_api.h:198
#define TX_CALLER_ERROR
Definition tx_api.h:213
constexpr T Min(T a, T b) noexcept
Compile-time minimum of two values.
Definition stk_defs.h:752
Fixed-size block allocator with O(1) alloc/free and proper task-blocking semantics.
static const size_t CAPACITY_MAX
Max capacity supported (number of blocks).
static constexpr size_t AlignBlockSize(size_t raw_size, size_t alignment=ALIGN_DEFAULT)
Round a raw block size up to the nearest multiple of alignment.
void SetTraceName(const char *name)
Set name.
Definition stk_common.h:617
ALIGN_TYPE tx_block_pool_stk_storage[(32U)]
Definition tx_api.h:311
const CHAR * tx_block_pool_name
Definition tx_api.h:310

References stk::memory::BlockMemoryPool::AlignBlockSize(), stk::memory::BlockMemoryPool::CAPACITY_MAX, stk::Min(), stk::ITraceable::SetTraceName(), TX_BLOCK_POOL_ID, TX_BLOCK_POOL_STRUCT::tx_block_pool_id, TX_BLOCK_POOL_STRUCT::tx_block_pool_name, TX_BLOCK_POOL_STRUCT::tx_block_pool_stk_storage, TX_CALLER_ERROR, TX_NAME_CONST, TX_POOL_ERROR, TX_PTR_ERROR, TX_SIZE_ERROR, TX_SUCCESS, and VOID.

Referenced by tx_application_define().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tx_block_pool_delete()

UINT tx_block_pool_delete ( TX_BLOCK_POOL * pool_ptr)

Definition at line 2029 of file threadx_stk.cpp.

2030{
2031 UINT result;
2032
2033 if (!IsValidBlockPool(pool_ptr))
2034 {
2035 result = TX_POOL_ERROR;
2036 }
2037 else if (InIsr())
2038 {
2039 result = TX_CALLER_ERROR;
2040 }
2041 else
2042 {
2043 // API contract of STK: no thread may be waiting on the pool (waiters are not resumed with TX_DELETED)
2044 pool_ptr->tx_block_pool_id = TX_CLEAR_ID;
2045 BlockPoolOf(pool_ptr)->~BlockMemoryPool();
2046 result = TX_SUCCESS;
2047 }
2048
2049 return result;
2050}
#define TX_CLEAR_ID
Definition tx_api.h:169

References TX_BLOCK_POOL_STRUCT::tx_block_pool_id, TX_CALLER_ERROR, TX_CLEAR_ID, TX_POOL_ERROR, and TX_SUCCESS.

◆ tx_block_pool_info_get()

UINT tx_block_pool_info_get ( TX_BLOCK_POOL * pool_ptr,
const CHAR ** name,
ULONG * available_blocks,
ULONG * total_blocks,
TX_THREAD ** first_suspended,
ULONG * suspended_count,
TX_BLOCK_POOL ** next_pool )

Definition at line 2126 of file threadx_stk.cpp.

2129{
2130 UINT result;
2131
2132 if (!IsValidBlockPool(pool_ptr))
2133 {
2134 result = TX_POOL_ERROR;
2135 }
2136 else
2137 {
2138 stk::memory::BlockMemoryPool *const p = BlockPoolOf(pool_ptr);
2139
2140 if (name != nullptr) { *name = pool_ptr->tx_block_pool_name; }
2141 if (available_blocks != nullptr) { *available_blocks = static_cast<ULONG>(p->GetFreeCount()); }
2142 if (total_blocks != nullptr) { *total_blocks = static_cast<ULONG>(p->GetCapacity()); }
2143 if (first_suspended != nullptr) { *first_suspended = nullptr; }
2144 if (suspended_count != nullptr) { *suspended_count = 0U; }
2145 if (next_pool != nullptr) { *next_pool = nullptr; }
2146
2147 result = TX_SUCCESS;
2148 }
2149
2150 return result;
2151}
size_t GetFreeCount() const
Get the number of free (available) blocks.
size_t GetCapacity() const
Get the total block capacity of the pool.

References stk::memory::BlockMemoryPool::GetCapacity(), stk::memory::BlockMemoryPool::GetFreeCount(), TX_BLOCK_POOL_STRUCT::tx_block_pool_name, TX_NAME_CONST, TX_POOL_ERROR, and TX_SUCCESS.

Here is the call graph for this function:

◆ tx_block_pool_prioritize()

UINT tx_block_pool_prioritize ( TX_BLOCK_POOL * pool_ptr)

Definition at line 2153 of file threadx_stk.cpp.

2154{
2155 return (IsValidBlockPool(pool_ptr) ? TX_SUCCESS : TX_POOL_ERROR); // noop: FIFO wait list
2156}

References TX_POOL_ERROR, and TX_SUCCESS.

◆ tx_block_release()

UINT tx_block_release ( void * block_ptr)
Examples
blinky-threadx/demo_threadx.c.

Definition at line 2100 of file threadx_stk.cpp.

2101{
2102 UINT result;
2103
2104 if (block_ptr == nullptr)
2105 {
2106 result = TX_PTR_ERROR;
2107 }
2108 else
2109 {
2110 void *const blk = (static_cast<uint8_t *>(block_ptr) - BLOCK_HDR_SIZE);
2111 TX_BLOCK_POOL *const pool = *static_cast<TX_BLOCK_POOL **>(blk);
2112
2113 if (!IsValidBlockPool(pool))
2114 {
2115 result = TX_PTR_ERROR; // not a block handed out by tx_block_allocate()
2116 }
2117 else
2118 {
2119 result = (BlockPoolOf(pool)->Free(blk) ? TX_SUCCESS : TX_PTR_ERROR);
2120 }
2121 }
2122
2123 return result;
2124}

References TX_PTR_ERROR, TX_SUCCESS, and VOID.

Referenced by tx_application_define().

Here is the caller graph for this function:

◆ tx_byte_allocate()

UINT tx_byte_allocate ( TX_BYTE_POOL * pool_ptr,
void ** memory_ptr,
ULONG memory_size,
ULONG wait_option )
Examples
blinky-threadx/demo_threadx.c.

Definition at line 2346 of file threadx_stk.cpp.

2347{
2348 UINT result;
2349
2350 if (!IsValidBytePool(pool_ptr))
2351 {
2352 result = TX_POOL_ERROR;
2353 }
2354 else if (memory_ptr == nullptr)
2355 {
2356 result = TX_PTR_ERROR;
2357 }
2358 else if ((memory_size == 0U) || (static_cast<size_t>(memory_size) > BytePoolOf(pool_ptr)->Pool().GetMaxRequest()))
2359 {
2360 result = TX_SIZE_ERROR; // can never succeed, do not block on it
2361 }
2362 else if (!CanBlock(wait_option))
2363 {
2364 result = TX_WAIT_ERROR;
2365 }
2366 else
2367 {
2368 void *mem = nullptr;
2369
2370 const ScopedWaitKind ws(TX_BYTE_MEMORY, wait_option);
2371
2372 result = WaitResultToTx(
2373 BytePoolOf(pool_ptr)->Pool().TimedAllocEx(&mem, static_cast<size_t>(memory_size), ToStkTimeout(wait_option)),
2374 TX_NO_MEMORY);
2375
2376 if (result == TX_SUCCESS)
2377 {
2378 *memory_ptr = mem;
2379 }
2380 }
2381
2382 return result;
2383}
#define TX_BYTE_MEMORY
Definition tx_api.h:185

References TX_BYTE_MEMORY, TX_NO_MEMORY, TX_POOL_ERROR, TX_PTR_ERROR, TX_SIZE_ERROR, TX_SUCCESS, TX_WAIT_ERROR, and VOID.

Referenced by tx_application_define().

Here is the caller graph for this function:

◆ tx_byte_pool_create()

UINT tx_byte_pool_create ( TX_BYTE_POOL * pool_ptr,
const CHAR * name_ptr,
void * pool_start,
ULONG pool_size )
Examples
blinky-threadx/demo_threadx.c.

Definition at line 2264 of file threadx_stk.cpp.

2265{
2266 UINT result;
2267
2268 if (pool_ptr == nullptr)
2269 {
2270 result = TX_POOL_ERROR;
2271 }
2272 else if (pool_ptr->tx_byte_pool_id == TX_BYTE_POOL_ID)
2273 {
2274 result = TX_POOL_ERROR; // already created
2275 }
2276 else if (pool_start == nullptr)
2277 {
2278 result = TX_PTR_ERROR;
2279 }
2280 else if (static_cast<size_t>(pool_size) < stk::memory::BytePool::RequiredSize(1U))
2281 {
2282 result = TX_SIZE_ERROR; // cannot hold even one block (BytePool asserts on this, so reject it here)
2283 }
2284 else if (InIsr())
2285 {
2286 result = TX_CALLER_ERROR;
2287 }
2288 else
2289 {
2290 StkBytePool *const p = new (static_cast<void *>(pool_ptr->tx_byte_pool_stk_storage))
2291 StkBytePool(static_cast<uint8_t *>(pool_start), static_cast<size_t>(pool_size), name_ptr);
2292
2293 if (!p->IsValid())
2294 {
2295 p->~StkBytePool(); // area is too small once aligned
2296 result = TX_SIZE_ERROR;
2297 }
2298 else
2299 {
2300 pool_ptr->tx_byte_pool_name = name_ptr;
2301 pool_ptr->tx_byte_pool_id = TX_BYTE_POOL_ID;
2302
2303 {
2305 BytePoolLink(p);
2306 }
2307
2308 result = TX_SUCCESS;
2309 }
2310 }
2311
2312 return result;
2313}
#define TX_BYTE_POOL_ID
Definition tx_api.h:238
static constexpr size_t RequiredSize(size_t payload_size)
Compute the pool space consumed by a single allocation of payload_size bytes.
RAII-style low-level synchronization primitive for atomic code execution. Used as building brick for ...
Definition stk_sync_cs.h:58
ALIGN_TYPE tx_byte_pool_stk_storage[(26U)]
Definition tx_api.h:318
ULONG tx_byte_pool_id
Definition tx_api.h:316
const CHAR * tx_byte_pool_name
Definition tx_api.h:317

References stk::memory::BytePool::RequiredSize(), TX_BYTE_POOL_ID, TX_BYTE_POOL_STRUCT::tx_byte_pool_id, TX_BYTE_POOL_STRUCT::tx_byte_pool_name, TX_BYTE_POOL_STRUCT::tx_byte_pool_stk_storage, TX_CALLER_ERROR, TX_NAME_CONST, TX_POOL_ERROR, TX_PTR_ERROR, TX_SIZE_ERROR, TX_SUCCESS, and VOID.

Referenced by tx_application_define().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tx_byte_pool_delete()

UINT tx_byte_pool_delete ( TX_BYTE_POOL * pool_ptr)

Definition at line 2315 of file threadx_stk.cpp.

2316{
2317 UINT result;
2318
2319 if (!IsValidBytePool(pool_ptr))
2320 {
2321 result = TX_POOL_ERROR;
2322 }
2323 else if (InIsr())
2324 {
2325 result = TX_CALLER_ERROR;
2326 }
2327 else
2328 {
2329 StkBytePool *const p = BytePoolOf(pool_ptr);
2330
2331 // API contract of STK: no thread may be waiting on the pool (waiters are not resumed with TX_DELETED)
2332 pool_ptr->tx_byte_pool_id = TX_CLEAR_ID;
2333
2334 {
2336 BytePoolUnlink(p);
2337 }
2338
2339 p->~StkBytePool();
2340 result = TX_SUCCESS;
2341 }
2342
2343 return result;
2344}

References TX_BYTE_POOL_STRUCT::tx_byte_pool_id, TX_CALLER_ERROR, TX_CLEAR_ID, TX_POOL_ERROR, and TX_SUCCESS.

◆ tx_byte_pool_info_get()

UINT tx_byte_pool_info_get ( TX_BYTE_POOL * pool_ptr,
const CHAR ** name,
ULONG * available_bytes,
ULONG * fragments,
TX_THREAD ** first_suspended,
ULONG * suspended_count,
TX_BYTE_POOL ** next_pool )

Definition at line 2416 of file threadx_stk.cpp.

2419{
2420 UINT result;
2421
2422 if (!IsValidBytePool(pool_ptr))
2423 {
2424 result = TX_POOL_ERROR;
2425 }
2426 else
2427 {
2428 size_t available = 0U;
2429 size_t largest = 0U;
2430 size_t frags = 0U;
2431
2432 BytePoolOf(pool_ptr)->Pool().GetInfo(available, largest, frags); // consistent snapshot, takes its own critical section
2433
2434 if (name != nullptr) { *name = pool_ptr->tx_byte_pool_name; }
2435 if (available_bytes != nullptr) { *available_bytes = static_cast<ULONG>(available); }
2436 if (fragments != nullptr) { *fragments = static_cast<ULONG>(frags); }
2437 if (first_suspended != nullptr) { *first_suspended = nullptr; } // BytePool does not expose its wait list yet
2438 if (suspended_count != nullptr) { *suspended_count = 0U; }
2439 if (next_pool != nullptr) { *next_pool = nullptr; }
2440
2441 result = TX_SUCCESS;
2442 }
2443
2444 return result;
2445}

References TX_BYTE_POOL_STRUCT::tx_byte_pool_name, TX_NAME_CONST, TX_POOL_ERROR, and TX_SUCCESS.

◆ tx_byte_pool_prioritize()

UINT tx_byte_pool_prioritize ( TX_BYTE_POOL * pool_ptr)

Definition at line 2447 of file threadx_stk.cpp.

2448{
2449 return (IsValidBytePool(pool_ptr) ? TX_SUCCESS : TX_POOL_ERROR); // noop: FIFO wait list
2450}

References TX_POOL_ERROR, and TX_SUCCESS.

◆ tx_byte_release()

UINT tx_byte_release ( void * memory_ptr)

Definition at line 2385 of file threadx_stk.cpp.

2386{
2387 UINT result;
2388
2389 if (memory_ptr == nullptr)
2390 {
2391 result = TX_PTR_ERROR;
2392 }
2393 else
2394 {
2395 StkBytePool *owner;
2396
2397 {
2399 owner = BytePoolFind(memory_ptr);
2400 }
2401
2402 // BytePool::Free() validates the block (range, alignment, state marker) and wakes blocked allocators
2403 if (owner == nullptr)
2404 {
2405 result = TX_PTR_ERROR; // not inside any byte pool
2406 }
2407 else
2408 {
2409 result = (owner->Pool().Free(memory_ptr) ? TX_SUCCESS : TX_PTR_ERROR); // error: foreign pointer or double release
2410 }
2411 }
2412
2413 return result;
2414}

References TX_PTR_ERROR, TX_SUCCESS, and VOID.

◆ tx_event_flags_create()

UINT tx_event_flags_create ( TX_EVENT_FLAGS_GROUP * group_ptr,
const CHAR * name_ptr )
Examples
blinky-threadx/demo_threadx.c, and blinky_c-threadx/example.c.

Definition at line 1513 of file threadx_stk.cpp.

1514{
1515 UINT result;
1516
1517 if (group_ptr == nullptr)
1518 {
1519 result = TX_GROUP_ERROR;
1520 }
1521 else if (group_ptr->tx_event_flags_group_id == TX_EVENT_FLAGS_ID)
1522 {
1523 result = TX_GROUP_ERROR; // already created
1524 }
1525 else if (InIsr())
1526 {
1527 result = TX_CALLER_ERROR;
1528 }
1529 else
1530 {
1531 StkEventFlags *const g = new (static_cast<void *>(group_ptr->tx_event_flags_group_stk_storage))
1532 StkEventFlags(0U);
1533 g->SetTraceName(name_ptr);
1534
1535 group_ptr->tx_event_flags_group_name = name_ptr;
1536 group_ptr->tx_event_flags_group_set_notify = nullptr;
1538 result = TX_SUCCESS;
1539 }
1540
1541 return result;
1542}
#define TX_GROUP_ERROR
Definition tx_api.h:199
#define TX_EVENT_FLAGS_ID
Definition tx_api.h:236
ULONG64 tx_event_flags_group_stk_storage[(16U)]
Definition tx_api.h:295
void(* tx_event_flags_group_set_notify)(struct TX_EVENT_FLAGS_GROUP_STRUCT *notify_group_ptr)
Definition tx_api.h:294
const CHAR * tx_event_flags_group_name
Definition tx_api.h:293

References TX_CALLER_ERROR, TX_EVENT_FLAGS_GROUP_STRUCT::tx_event_flags_group_id, TX_EVENT_FLAGS_GROUP_STRUCT::tx_event_flags_group_name, TX_EVENT_FLAGS_GROUP_STRUCT::tx_event_flags_group_set_notify, TX_EVENT_FLAGS_GROUP_STRUCT::tx_event_flags_group_stk_storage, TX_EVENT_FLAGS_ID, TX_GROUP_ERROR, TX_NAME_CONST, and TX_SUCCESS.

Referenced by tx_application_define().

Here is the caller graph for this function:

◆ tx_event_flags_delete()

UINT tx_event_flags_delete ( TX_EVENT_FLAGS_GROUP * group_ptr)

Definition at line 1544 of file threadx_stk.cpp.

1545{
1546 UINT result;
1547
1548 if (!IsValidEf(group_ptr))
1549 {
1550 result = TX_GROUP_ERROR;
1551 }
1552 else if (InIsr())
1553 {
1554 result = TX_CALLER_ERROR;
1555 }
1556 else
1557 {
1558 // API contract of STK: no thread may be waiting on the group (waiters are not resumed with TX_DELETED)
1560 EfOf(group_ptr)->~EventFlagsT();
1561 result = TX_SUCCESS;
1562 }
1563
1564 return result;
1565}

References TX_CALLER_ERROR, TX_CLEAR_ID, TX_EVENT_FLAGS_GROUP_STRUCT::tx_event_flags_group_id, TX_GROUP_ERROR, and TX_SUCCESS.

◆ tx_event_flags_get()

UINT tx_event_flags_get ( TX_EVENT_FLAGS_GROUP * group_ptr,
ULONG requested_flags,
UINT get_option,
ULONG * actual_flags_ptr,
ULONG wait_option )
Examples
blinky-threadx/demo_threadx.c, and blinky_c-threadx/example.c.

Definition at line 1567 of file threadx_stk.cpp.

1569{
1570 UINT result;
1571
1572 if (!IsValidEf(group_ptr))
1573 {
1574 result = TX_GROUP_ERROR;
1575 }
1576 else if (actual_flags_ptr == nullptr)
1577 {
1578 result = TX_PTR_ERROR;
1579 }
1580 else if ((get_option > TX_AND_CLEAR) || (requested_flags == 0U))
1581 {
1582 result = TX_OPTION_ERROR;
1583 }
1584 else if (!CanBlock(wait_option))
1585 {
1586 result = TX_WAIT_ERROR;
1587 }
1588 else
1589 {
1590 // TX_AND -> wait for all requested flags, TX_OR -> any of them; ThreadX clears matched flags only
1591 // for the *_CLEAR options (bit 0), STK clears by default
1592 uint32_t opts = ((get_option & TX_AND) != 0U) ? StkEventFlags::OPT_WAIT_ALL : StkEventFlags::OPT_WAIT_ANY;
1593 if ((get_option & 1U) == 0U)
1594 {
1595 opts |= StkEventFlags::OPT_NO_CLEAR;
1596 }
1597
1598 uint64_t actual = 0U;
1600 {
1601 const ScopedWaitKind ws(TX_EVENT_FLAG, wait_option);
1602
1603 wr = EfOf(group_ptr)->WaitEx(static_cast<uint64_t>(requested_flags), opts, ToStkTimeout(wait_option), actual);
1604 }
1605
1606 result = WaitResultToTx(wr, TX_NO_EVENTS);
1607
1608 if (result == TX_SUCCESS)
1609 {
1610 // like ThreadX: the whole group's flags word as it was when the request was satisfied (before auto-clear)
1611 *actual_flags_ptr = static_cast<ULONG>(actual); // the flags are in the low 32 bits
1612 }
1613 }
1614
1615 return result;
1616}
#define TX_EVENT_FLAG
Definition tx_api.h:183
#define TX_AND_CLEAR
Definition tx_api.h:146
#define TX_OPTION_ERROR
Definition tx_api.h:201
#define TX_AND
Definition tx_api.h:145
#define TX_NO_EVENTS
Definition tx_api.h:200

References TX_AND, TX_AND_CLEAR, TX_EVENT_FLAG, TX_GROUP_ERROR, TX_NO_EVENTS, TX_OPTION_ERROR, TX_PTR_ERROR, TX_SUCCESS, and TX_WAIT_ERROR.

Referenced by thread_5_entry(), and wait_flag().

Here is the caller graph for this function:

◆ tx_event_flags_info_get()

UINT tx_event_flags_info_get ( TX_EVENT_FLAGS_GROUP * group_ptr,
const CHAR ** name,
ULONG * current_flags,
TX_THREAD ** first_suspended,
ULONG * suspended_count,
TX_EVENT_FLAGS_GROUP ** next_group )

Definition at line 1658 of file threadx_stk.cpp.

1660{
1661 UINT result;
1662
1663 if (!IsValidEf(group_ptr))
1664 {
1665 result = TX_GROUP_ERROR;
1666 }
1667 else
1668 {
1669 if (name != nullptr) { *name = group_ptr->tx_event_flags_group_name; }
1670 if (current_flags != nullptr) { *current_flags = static_cast<ULONG>(EfOf(group_ptr)->Get()); }
1671 if (next_group != nullptr) { *next_group = nullptr; }
1672
1673 FillSuspended(*EfOf(group_ptr), first_suspended, suspended_count);
1674
1675 result = TX_SUCCESS;
1676 }
1677
1678 return result;
1679}

References TX_EVENT_FLAGS_GROUP_STRUCT::tx_event_flags_group_name, TX_GROUP_ERROR, TX_NAME_CONST, and TX_SUCCESS.

◆ tx_event_flags_set()

UINT tx_event_flags_set ( TX_EVENT_FLAGS_GROUP * group_ptr,
ULONG flags_to_set,
UINT set_option )
Examples
blinky-threadx/demo_threadx.c, and blinky_c-threadx/example.c.

Definition at line 1618 of file threadx_stk.cpp.

1619{
1620 UINT result;
1621
1622 if (!IsValidEf(group_ptr))
1623 {
1624 result = TX_GROUP_ERROR;
1625 }
1626 else if ((set_option != TX_OR) && (set_option != TX_AND))
1627 {
1628 result = TX_OPTION_ERROR;
1629 }
1630 else
1631 {
1632 StkEventFlags *const g = EfOf(group_ptr);
1633
1634 if (set_option == TX_OR)
1635 {
1636 if (flags_to_set != 0U)
1637 {
1638 (void)g->Set(static_cast<uint64_t>(flags_to_set)); // wakes all waiters, each re-evaluates its own condition
1639 }
1640 }
1641 else
1642 {
1643 // TX_AND: group = group & flags_to_set (cannot satisfy any waiter, so nobody is woken)
1644 (void)g->And(static_cast<uint64_t>(flags_to_set)); // the upper half of the group is always 0
1645 }
1646
1647 if (group_ptr->tx_event_flags_group_set_notify != nullptr)
1648 {
1649 group_ptr->tx_event_flags_group_set_notify(group_ptr);
1650 }
1651
1652 result = TX_SUCCESS;
1653 }
1654
1655 return result;
1656}
#define TX_OR
Definition tx_api.h:147

References TX_AND, TX_EVENT_FLAGS_GROUP_STRUCT::tx_event_flags_group_set_notify, TX_GROUP_ERROR, TX_OPTION_ERROR, TX_OR, and TX_SUCCESS.

Referenced by app_main(), signal_func(), and thread_0_entry().

Here is the caller graph for this function:

◆ tx_event_flags_set_notify()

UINT tx_event_flags_set_notify ( TX_EVENT_FLAGS_GROUP * group_ptr,
void(* events_set_notify )(TX_EVENT_FLAGS_GROUP *notify_group_ptr) )

Definition at line 1681 of file threadx_stk.cpp.

1683{
1684 UINT result;
1685
1686 if (!IsValidEf(group_ptr))
1687 {
1688 result = TX_GROUP_ERROR;
1689 }
1690 else
1691 {
1692 group_ptr->tx_event_flags_group_set_notify = events_set_notify;
1693 result = TX_SUCCESS;
1694 }
1695
1696 return result;
1697}

References TX_EVENT_FLAGS_GROUP_STRUCT::tx_event_flags_group_set_notify, TX_GROUP_ERROR, TX_SUCCESS, and VOID.

◆ tx_interrupt_control()

UINT tx_interrupt_control ( UINT new_posture)

Definition at line 468 of file threadx_stk.cpp.

469{
470 // absolute posture semantics: disable once, enable once, return the previous posture
471 const UINT old_posture = (g_IntDisabled ? TX_INT_DISABLE : TX_INT_ENABLE);
472
473 if ((new_posture == TX_INT_DISABLE) && !g_IntDisabled)
474 {
476 g_IntDisabled = true;
477 }
478 else if ((new_posture != TX_INT_DISABLE) && g_IntDisabled)
479 {
480 g_IntDisabled = false;
482 }
483 else
484 {
485 // noop: already in the requested posture
486 }
487
488 return old_posture;
489}
#define TX_INT_DISABLE
Definition tx_api.h:172
#define TX_INT_ENABLE
Definition tx_api.h:173
static Session Enter(const Session ses=DEFAULT_SESSION)
Enter a critical section.
static void Exit(const Session ses=DEFAULT_SESSION)
Exit a critical section.

References stk::hw::CriticalSection::Enter(), stk::hw::CriticalSection::Exit(), TX_INT_DISABLE, and TX_INT_ENABLE.

Here is the call graph for this function:

◆ tx_kernel_enter()

void tx_kernel_enter ( void )
Examples
blinky-threadx/demo_threadx.c, and blinky_c-threadx/example.c.

Definition at line 457 of file threadx_stk.cpp.

458{
459 g_StkKernel.Initialize(static_cast<uint32_t>(1000000UL / TX_TIMER_TICKS_PER_SECOND));
460
461 // ThreadX passes the first unused memory address here. STK works with caller-supplied memory only.
462 tx_application_define(nullptr);
463
464 // does not return for KERNEL_STATIC, for KERNEL_DYNAMIC returns when all threads have exited
465 g_StkKernel.Start();
466}
#define TX_TIMER_TICKS_PER_SECOND
Definition tx_api.h:49
void tx_application_define(void *first_unused_memory)

References tx_application_define(), TX_TIMER_TICKS_PER_SECOND, and VOID.

Referenced by app_run(), and main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tx_mutex_create()

UINT tx_mutex_create ( TX_MUTEX * mutex_ptr,
const CHAR * name_ptr,
UINT inherit )
Examples
blinky-threadx/demo_threadx.c.

Definition at line 1138 of file threadx_stk.cpp.

1139{
1140 UINT result;
1141
1142 if (mutex_ptr == nullptr)
1143 {
1144 result = TX_MUTEX_ERROR;
1145 }
1146 else if (mutex_ptr->tx_mutex_id == TX_MUTEX_ID)
1147 {
1148 result = TX_MUTEX_ERROR; // already created
1149 }
1150 else if (inherit > TX_INHERIT)
1151 {
1152 result = TX_INHERIT_ERROR;
1153 }
1154 else if (InIsr())
1155 {
1156 result = TX_CALLER_ERROR;
1157 }
1158 else
1159 {
1160 stk::sync::Mutex *const m = new (static_cast<void *>(mutex_ptr->tx_mutex_stk_storage)) stk::sync::Mutex();
1161 m->SetTraceName(name_ptr);
1162
1163 mutex_ptr->tx_mutex_name = name_ptr;
1164 mutex_ptr->tx_mutex_id = TX_MUTEX_ID;
1165 result = TX_SUCCESS;
1166 }
1167
1168 return result;
1169}
#define TX_INHERIT_ERROR
Definition tx_api.h:225
#define TX_MUTEX_ERROR
Definition tx_api.h:222
#define TX_MUTEX_ID
Definition tx_api.h:233
#define TX_INHERIT
Definition tx_api.h:162
Recursive mutex primitive that allows the same thread to acquire the lock multiple times.
const CHAR * tx_mutex_name
Definition tx_api.h:278
ULONG tx_mutex_id
Definition tx_api.h:277
ALIGN_TYPE tx_mutex_stk_storage[(16U)]
Definition tx_api.h:279

References stk::ITraceable::SetTraceName(), TX_CALLER_ERROR, TX_INHERIT, TX_INHERIT_ERROR, TX_MUTEX_ERROR, TX_MUTEX_ID, TX_MUTEX_STRUCT::tx_mutex_id, TX_MUTEX_STRUCT::tx_mutex_name, TX_MUTEX_STRUCT::tx_mutex_stk_storage, TX_NAME_CONST, and TX_SUCCESS.

Referenced by tx_application_define().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tx_mutex_delete()

UINT tx_mutex_delete ( TX_MUTEX * mutex_ptr)

Definition at line 1171 of file threadx_stk.cpp.

1172{
1173 UINT result;
1174
1175 if (!IsValidMutex(mutex_ptr))
1176 {
1177 result = TX_MUTEX_ERROR;
1178 }
1179 else if (InIsr())
1180 {
1181 result = TX_CALLER_ERROR;
1182 }
1183 else
1184 {
1185 // API contract of STK: no thread may be waiting on the mutex (waiters are not resumed with TX_DELETED)
1186 mutex_ptr->tx_mutex_id = TX_CLEAR_ID;
1187 MutexOf(mutex_ptr)->~Mutex();
1188 result = TX_SUCCESS;
1189 }
1190
1191 return result;
1192}

References TX_CALLER_ERROR, TX_CLEAR_ID, TX_MUTEX_ERROR, TX_MUTEX_STRUCT::tx_mutex_id, and TX_SUCCESS.

◆ tx_mutex_get()

UINT tx_mutex_get ( TX_MUTEX * mutex_ptr,
ULONG wait_option )
Examples
blinky-threadx/demo_threadx.c.

Definition at line 1194 of file threadx_stk.cpp.

1195{
1196 UINT result;
1197
1198 if (!IsValidMutex(mutex_ptr))
1199 {
1200 result = TX_MUTEX_ERROR;
1201 }
1202 else if (InIsr() || !KernelRunning())
1203 {
1204 result = TX_CALLER_ERROR;
1205 }
1206 else if (!CanBlock(wait_option))
1207 {
1208 result = TX_WAIT_ERROR;
1209 }
1210 else
1211 {
1212 const ScopedWaitKind ws(TX_MUTEX_SUSP, wait_option);
1213
1214 result = WaitResultToTx(MutexOf(mutex_ptr)->TimedLockEx(ToStkTimeout(wait_option)), TX_NOT_AVAILABLE);
1215 }
1216
1217 return result;
1218}
#define TX_NOT_AVAILABLE
Definition tx_api.h:223
#define TX_MUTEX_SUSP
Definition tx_api.h:189

References TX_CALLER_ERROR, TX_MUTEX_ERROR, TX_MUTEX_SUSP, TX_NOT_AVAILABLE, and TX_WAIT_ERROR.

Referenced by thread_6_and_7_entry().

Here is the caller graph for this function:

◆ tx_mutex_info_get()

UINT tx_mutex_info_get ( TX_MUTEX * mutex_ptr,
const CHAR ** name,
ULONG * count,
TX_THREAD ** owner,
TX_THREAD ** first_suspended,
ULONG * suspended_count,
TX_MUTEX ** next_mutex )

Definition at line 1245 of file threadx_stk.cpp.

1247{
1248 UINT result;
1249
1250 if (!IsValidMutex(mutex_ptr))
1251 {
1252 result = TX_MUTEX_ERROR;
1253 }
1254 else
1255 {
1256 stk::sync::Mutex *const m = MutexOf(mutex_ptr);
1257
1258 if (name != nullptr) { *name = mutex_ptr->tx_mutex_name; }
1259 if (count != nullptr) { *count = m->GetRecursionCount(); }
1260 if (owner != nullptr) { *owner = ThreadFromTid(m->GetOwner()); }
1261 if (next_mutex != nullptr) { *next_mutex = nullptr; }
1262
1263 FillSuspended(*m, first_suspended, suspended_count);
1264
1265 result = TX_SUCCESS;
1266 }
1267
1268 return result;
1269}
TId GetOwner() const
Get owner of the mutex.
uint16_t GetRecursionCount() const
Get current recursion depth.

References stk::sync::Mutex::GetOwner(), stk::sync::Mutex::GetRecursionCount(), TX_MUTEX_ERROR, TX_MUTEX_STRUCT::tx_mutex_name, TX_NAME_CONST, and TX_SUCCESS.

Here is the call graph for this function:

◆ tx_mutex_prioritize()

UINT tx_mutex_prioritize ( TX_MUTEX * mutex_ptr)

Definition at line 1271 of file threadx_stk.cpp.

1272{
1273 // waiters are served in FIFO order, priority ordering of the wait list is not supported (noop)
1274 return (IsValidMutex(mutex_ptr) ? TX_SUCCESS : TX_MUTEX_ERROR);
1275}

References TX_MUTEX_ERROR, and TX_SUCCESS.

◆ tx_mutex_put()

UINT tx_mutex_put ( TX_MUTEX * mutex_ptr)
Examples
blinky-threadx/demo_threadx.c.

Definition at line 1220 of file threadx_stk.cpp.

1221{
1222 UINT result;
1223
1224 if (!IsValidMutex(mutex_ptr))
1225 {
1226 result = TX_MUTEX_ERROR;
1227 }
1228 else if (InIsr() || !KernelRunning())
1229 {
1230 result = TX_CALLER_ERROR;
1231 }
1232 else if (MutexOf(mutex_ptr)->GetOwner() != stk::GetTid())
1233 {
1234 result = TX_NOT_OWNED;
1235 }
1236 else
1237 {
1238 MutexOf(mutex_ptr)->Unlock();
1239 result = TX_SUCCESS;
1240 }
1241
1242 return result;
1243}
#define TX_NOT_OWNED
Definition tx_api.h:224
static TId GetTid()
Get task/thread Id of the calling task.
Definition stk_helper.h:374

References stk::GetTid(), TX_CALLER_ERROR, TX_MUTEX_ERROR, TX_NOT_OWNED, and TX_SUCCESS.

Referenced by thread_6_and_7_entry().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tx_queue_create()

UINT tx_queue_create ( TX_QUEUE * queue_ptr,
const CHAR * name_ptr,
UINT message_size,
void * queue_start,
ULONG queue_size )
Examples
blinky-threadx/demo_threadx.c.

Definition at line 1727 of file threadx_stk.cpp.

1729{
1730 UINT result;
1731
1732 if (queue_ptr == nullptr)
1733 {
1734 result = TX_QUEUE_ERROR;
1735 }
1736 else if (queue_ptr->tx_queue_id == TX_QUEUE_ID)
1737 {
1738 result = TX_QUEUE_ERROR; // already created
1739 }
1740 else if (queue_start == nullptr)
1741 {
1742 result = TX_PTR_ERROR;
1743 }
1744 else if ((message_size < TX_1_ULONG) || (message_size > TX_16_ULONG))
1745 {
1746 result = TX_SIZE_ERROR;
1747 }
1748 else if (InIsr())
1749 {
1750 result = TX_CALLER_ERROR;
1751 }
1752 else
1753 {
1754 const size_t msg_bytes = (static_cast<size_t>(message_size) * sizeof(ULONG));
1755 const size_t capacity = (static_cast<size_t>(queue_size) / msg_bytes);
1756
1757 if ((capacity < 1U) || (capacity > stk::sync::MessageQueue::CAPACITY_MAX))
1758 {
1759 result = TX_SIZE_ERROR;
1760 }
1761 else
1762 {
1763 stk::sync::MessageQueue *const q = new (static_cast<void *>(queue_ptr->tx_queue_stk_storage))
1764 stk::sync::MessageQueue(static_cast<uint8_t *>(queue_start), capacity, msg_bytes);
1765 q->SetTraceName(name_ptr);
1766
1767 queue_ptr->tx_queue_name = name_ptr;
1768 queue_ptr->tx_queue_message_size = message_size;
1769 queue_ptr->tx_queue_send_notify = nullptr;
1770 queue_ptr->tx_queue_id = TX_QUEUE_ID;
1771 result = TX_SUCCESS;
1772 }
1773 }
1774
1775 return result;
1776}
#define TX_QUEUE_ID
Definition tx_api.h:234
#define TX_QUEUE_ERROR
Definition tx_api.h:202
#define TX_16_ULONG
Definition tx_api.h:153
Fixed-capacity, fixed-message-size FIFO queue for inter-task communication.
static const size_t CAPACITY_MAX
Max capacity supported (number of messages).
ALIGN_TYPE tx_queue_stk_storage[(48U)]
Definition tx_api.h:304
const CHAR * tx_queue_name
Definition tx_api.h:301
ULONG tx_queue_id
Definition tx_api.h:300
UINT tx_queue_message_size
Definition tx_api.h:302
void(* tx_queue_send_notify)(struct TX_QUEUE_STRUCT *notify_queue_ptr)
Definition tx_api.h:303

References stk::sync::MessageQueue::CAPACITY_MAX, stk::ITraceable::SetTraceName(), TX_16_ULONG, TX_1_ULONG, TX_CALLER_ERROR, TX_NAME_CONST, TX_PTR_ERROR, TX_QUEUE_ERROR, TX_QUEUE_ID, TX_QUEUE_STRUCT::tx_queue_id, TX_QUEUE_STRUCT::tx_queue_message_size, TX_QUEUE_STRUCT::tx_queue_name, TX_QUEUE_STRUCT::tx_queue_send_notify, TX_QUEUE_STRUCT::tx_queue_stk_storage, TX_SIZE_ERROR, TX_SUCCESS, and VOID.

Referenced by tx_application_define().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tx_queue_delete()

UINT tx_queue_delete ( TX_QUEUE * queue_ptr)

Definition at line 1778 of file threadx_stk.cpp.

1779{
1780 UINT result;
1781
1782 if (!IsValidQueue(queue_ptr))
1783 {
1784 result = TX_QUEUE_ERROR;
1785 }
1786 else if (InIsr())
1787 {
1788 result = TX_CALLER_ERROR;
1789 }
1790 else
1791 {
1792 // API contract of STK: no thread may be waiting on the queue (waiters are not resumed with TX_DELETED)
1793 queue_ptr->tx_queue_id = TX_CLEAR_ID;
1794 QueueOf(queue_ptr)->~MessageQueue();
1795 result = TX_SUCCESS;
1796 }
1797
1798 return result;
1799}

References TX_CALLER_ERROR, TX_CLEAR_ID, TX_QUEUE_ERROR, TX_QUEUE_STRUCT::tx_queue_id, and TX_SUCCESS.

◆ tx_queue_flush()

UINT tx_queue_flush ( TX_QUEUE * queue_ptr)

Definition at line 1801 of file threadx_stk.cpp.

1802{
1803 UINT result;
1804
1805 if (!IsValidQueue(queue_ptr))
1806 {
1807 result = TX_QUEUE_ERROR;
1808 }
1809 else
1810 {
1811 QueueOf(queue_ptr)->Reset();
1812 result = TX_SUCCESS;
1813 }
1814
1815 return result;
1816}

References TX_QUEUE_ERROR, and TX_SUCCESS.

◆ tx_queue_front_send()

UINT tx_queue_front_send ( TX_QUEUE * queue_ptr,
void * source_ptr,
ULONG wait_option )

Definition at line 1899 of file threadx_stk.cpp.

1900{
1901 return QueueSend(queue_ptr, source_ptr, wait_option, true);
1902}

References VOID.

◆ tx_queue_info_get()

UINT tx_queue_info_get ( TX_QUEUE * queue_ptr,
const CHAR ** name,
ULONG * enqueued,
ULONG * available_storage,
TX_THREAD ** first_suspended,
ULONG * suspended_count,
TX_QUEUE ** next_queue )

Definition at line 1818 of file threadx_stk.cpp.

1820{
1821 UINT result;
1822
1823 if (!IsValidQueue(queue_ptr))
1824 {
1825 result = TX_QUEUE_ERROR;
1826 }
1827 else
1828 {
1829 stk::sync::MessageQueue *const q = QueueOf(queue_ptr);
1830
1831 if (name != nullptr) { *name = queue_ptr->tx_queue_name; }
1832 if (enqueued != nullptr) { *enqueued = static_cast<ULONG>(q->GetCount()); }
1833 if (available_storage != nullptr) { *available_storage = static_cast<ULONG>(q->GetSpace()); }
1834 if (first_suspended != nullptr) { *first_suspended = nullptr; }
1835 if (suspended_count != nullptr) { *suspended_count = 0U; }
1836 if (next_queue != nullptr) { *next_queue = nullptr; }
1837
1838 result = TX_SUCCESS;
1839 }
1840
1841 return result;
1842}
size_t GetSpace() const
Get the number of free slots currently available.
size_t GetCount() const
Get the current number of messages in the queue.

References stk::sync::MessageQueue::GetCount(), stk::sync::MessageQueue::GetSpace(), TX_NAME_CONST, TX_QUEUE_ERROR, TX_QUEUE_STRUCT::tx_queue_name, and TX_SUCCESS.

Here is the call graph for this function:

◆ tx_queue_prioritize()

UINT tx_queue_prioritize ( TX_QUEUE * queue_ptr)

Definition at line 1844 of file threadx_stk.cpp.

1845{
1846 return (IsValidQueue(queue_ptr) ? TX_SUCCESS : TX_QUEUE_ERROR); // noop: FIFO wait list
1847}

References TX_QUEUE_ERROR, and TX_SUCCESS.

◆ tx_queue_receive()

UINT tx_queue_receive ( TX_QUEUE * queue_ptr,
void * destination_ptr,
ULONG wait_option )
Examples
blinky-threadx/demo_threadx.c.

Definition at line 1904 of file threadx_stk.cpp.

1905{
1906 UINT result;
1907
1908 if (!IsValidQueue(queue_ptr))
1909 {
1910 result = TX_QUEUE_ERROR;
1911 }
1912 else if (destination_ptr == nullptr)
1913 {
1914 result = TX_PTR_ERROR;
1915 }
1916 else if (!CanBlock(wait_option))
1917 {
1918 result = TX_WAIT_ERROR;
1919 }
1920 else
1921 {
1922 const ScopedWaitKind ws(TX_QUEUE_SUSP, wait_option);
1923
1924 result = WaitResultToTx(QueueOf(queue_ptr)->GetEx(destination_ptr, ToStkTimeout(wait_option)), TX_QUEUE_EMPTY);
1925 }
1926
1927 return result;
1928}
#define TX_QUEUE_EMPTY
Definition tx_api.h:203
#define TX_QUEUE_SUSP
Definition tx_api.h:181

References TX_PTR_ERROR, TX_QUEUE_EMPTY, TX_QUEUE_ERROR, TX_QUEUE_SUSP, TX_WAIT_ERROR, and VOID.

Referenced by thread_2_entry().

Here is the caller graph for this function:

◆ tx_queue_send()

UINT tx_queue_send ( TX_QUEUE * queue_ptr,
void * source_ptr,
ULONG wait_option )
Examples
blinky-threadx/demo_threadx.c.

Definition at line 1894 of file threadx_stk.cpp.

1895{
1896 return QueueSend(queue_ptr, source_ptr, wait_option, false);
1897}

References VOID.

Referenced by thread_1_entry().

Here is the caller graph for this function:

◆ tx_queue_send_notify()

UINT tx_queue_send_notify ( TX_QUEUE * queue_ptr,
void(* queue_send_notify )(TX_QUEUE *notify_queue_ptr) )

Definition at line 1930 of file threadx_stk.cpp.

1931{
1932 UINT result;
1933
1934 if (!IsValidQueue(queue_ptr))
1935 {
1936 result = TX_QUEUE_ERROR;
1937 }
1938 else
1939 {
1940 queue_ptr->tx_queue_send_notify = queue_send_notify;
1941 result = TX_SUCCESS;
1942 }
1943
1944 return result;
1945}

References TX_QUEUE_ERROR, TX_QUEUE_STRUCT::tx_queue_send_notify, TX_SUCCESS, and VOID.

◆ tx_semaphore_ceiling_put()

UINT tx_semaphore_ceiling_put ( TX_SEMAPHORE * semaphore_ptr,
ULONG ceiling )

Definition at line 1409 of file threadx_stk.cpp.

1410{
1411 UINT result;
1412
1413 if (!IsValidSem(semaphore_ptr))
1414 {
1415 result = TX_SEMAPHORE_ERROR;
1416 }
1417 else if (ceiling == 0U)
1418 {
1419 result = TX_OPTION_ERROR;
1420 }
1421 else
1422 {
1423 // the ceiling check and the signal are made atomically by the semaphore: with a waiter present the
1424 // signal is handed over directly and the counter does not grow, so the ceiling can be exceeded only
1425 // when nobody is waiting
1426 result = (SemOf(semaphore_ptr)->TrySignal(ceiling) ? TX_SUCCESS : TX_CEILING_EXCEEDED);
1427 }
1428
1429 if ((result == TX_SUCCESS) && (semaphore_ptr->tx_semaphore_put_notify != nullptr))
1430 {
1431 semaphore_ptr->tx_semaphore_put_notify(semaphore_ptr);
1432 }
1433
1434 return result;
1435}
static PosixSemaphore * SemOf(sem_t *o)
#define TX_SEMAPHORE_ERROR
Definition tx_api.h:205
#define TX_CEILING_EXCEEDED
Definition tx_api.h:227
void(* tx_semaphore_put_notify)(struct TX_SEMAPHORE_STRUCT *notify_semaphore_ptr)
Definition tx_api.h:286

References SemOf(), TX_CEILING_EXCEEDED, TX_OPTION_ERROR, TX_SEMAPHORE_ERROR, TX_SEMAPHORE_STRUCT::tx_semaphore_put_notify, and TX_SUCCESS.

Here is the call graph for this function:

◆ tx_semaphore_create()

UINT tx_semaphore_create ( TX_SEMAPHORE * semaphore_ptr,
const CHAR * name_ptr,
ULONG initial_count )
Examples
blinky-threadx/demo_threadx.c.

Definition at line 1308 of file threadx_stk.cpp.

1309{
1310 UINT result;
1311
1312 if (semaphore_ptr == nullptr)
1313 {
1314 result = TX_SEMAPHORE_ERROR;
1315 }
1316 else if (semaphore_ptr->tx_semaphore_id == TX_SEMAPHORE_ID)
1317 {
1318 result = TX_SEMAPHORE_ERROR; // already created
1319 }
1320 else if (InIsr())
1321 {
1322 result = TX_CALLER_ERROR;
1323 }
1324 else
1325 {
1326 StkSemaphore *const s = new (static_cast<void *>(semaphore_ptr->tx_semaphore_stk_storage))
1327 StkSemaphore(initial_count, StkSemaphore::COUNT_MAX);
1328 s->SetTraceName(name_ptr);
1329
1330 semaphore_ptr->tx_semaphore_name = name_ptr;
1331 semaphore_ptr->tx_semaphore_put_notify = nullptr;
1332 semaphore_ptr->tx_semaphore_id = TX_SEMAPHORE_ID;
1333 result = TX_SUCCESS;
1334 }
1335
1336 return result;
1337}
stk::sync::SemaphoreT< ULONG > StkSemaphore
#define TX_SEMAPHORE_ID
Definition tx_api.h:235
static constexpr ULONG COUNT_MAX
ULONG tx_semaphore_id
Definition tx_api.h:284
ALIGN_TYPE tx_semaphore_stk_storage[(16U)]
Definition tx_api.h:287
const CHAR * tx_semaphore_name
Definition tx_api.h:285

References stk::sync::SemaphoreT< ULONG >::COUNT_MAX, TX_CALLER_ERROR, TX_NAME_CONST, TX_SEMAPHORE_ERROR, TX_SEMAPHORE_ID, TX_SEMAPHORE_STRUCT::tx_semaphore_id, TX_SEMAPHORE_STRUCT::tx_semaphore_name, TX_SEMAPHORE_STRUCT::tx_semaphore_put_notify, TX_SEMAPHORE_STRUCT::tx_semaphore_stk_storage, and TX_SUCCESS.

Referenced by tx_application_define().

Here is the caller graph for this function:

◆ tx_semaphore_delete()

UINT tx_semaphore_delete ( TX_SEMAPHORE * semaphore_ptr)

Definition at line 1339 of file threadx_stk.cpp.

1340{
1341 UINT result;
1342
1343 if (!IsValidSem(semaphore_ptr))
1344 {
1345 result = TX_SEMAPHORE_ERROR;
1346 }
1347 else if (InIsr())
1348 {
1349 result = TX_CALLER_ERROR;
1350 }
1351 else
1352 {
1353 // API contract of STK: no thread may be waiting on the semaphore (waiters are not resumed with TX_DELETED)
1354 semaphore_ptr->tx_semaphore_id = TX_CLEAR_ID;
1355 SemOf(semaphore_ptr)->~StkSemaphore();
1356 result = TX_SUCCESS;
1357 }
1358
1359 return result;
1360}

References SemOf(), TX_CALLER_ERROR, TX_CLEAR_ID, TX_SEMAPHORE_ERROR, TX_SEMAPHORE_STRUCT::tx_semaphore_id, and TX_SUCCESS.

Here is the call graph for this function:

◆ tx_semaphore_get()

UINT tx_semaphore_get ( TX_SEMAPHORE * semaphore_ptr,
ULONG wait_option )
Examples
blinky-threadx/demo_threadx.c.

Definition at line 1362 of file threadx_stk.cpp.

1363{
1364 UINT result;
1365
1366 if (!IsValidSem(semaphore_ptr))
1367 {
1368 result = TX_SEMAPHORE_ERROR;
1369 }
1370 else if (!CanBlock(wait_option))
1371 {
1372 result = TX_WAIT_ERROR;
1373 }
1374 else
1375 {
1376 const ScopedWaitKind ws(TX_SEMAPHORE_SUSP, wait_option);
1377
1378 result = WaitResultToTx(SemOf(semaphore_ptr)->WaitEx(ToStkTimeout(wait_option)), TX_NO_INSTANCE);
1379 }
1380
1381 return result;
1382}
#define TX_SEMAPHORE_SUSP
Definition tx_api.h:182
#define TX_NO_INSTANCE
Definition tx_api.h:206

References SemOf(), TX_NO_INSTANCE, TX_SEMAPHORE_ERROR, TX_SEMAPHORE_SUSP, and TX_WAIT_ERROR.

Referenced by thread_3_and_4_entry().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tx_semaphore_info_get()

UINT tx_semaphore_info_get ( TX_SEMAPHORE * semaphore_ptr,
const CHAR ** name,
ULONG * current_value,
TX_THREAD ** first_suspended,
ULONG * suspended_count,
TX_SEMAPHORE ** next_semaphore )

Definition at line 1437 of file threadx_stk.cpp.

1439{
1440 UINT result;
1441
1442 if (!IsValidSem(semaphore_ptr))
1443 {
1444 result = TX_SEMAPHORE_ERROR;
1445 }
1446 else
1447 {
1448 if (name != nullptr) { *name = semaphore_ptr->tx_semaphore_name; }
1449 if (current_value != nullptr) { *current_value = SemOf(semaphore_ptr)->GetCount(); }
1450 if (next_semaphore != nullptr) { *next_semaphore = nullptr; }
1451
1452 FillSuspended(*SemOf(semaphore_ptr), first_suspended, suspended_count);
1453
1454 result = TX_SUCCESS;
1455 }
1456
1457 return result;
1458}

References SemOf(), TX_NAME_CONST, TX_SEMAPHORE_ERROR, TX_SEMAPHORE_STRUCT::tx_semaphore_name, and TX_SUCCESS.

Here is the call graph for this function:

◆ tx_semaphore_prioritize()

UINT tx_semaphore_prioritize ( TX_SEMAPHORE * semaphore_ptr)

Definition at line 1460 of file threadx_stk.cpp.

1461{
1462 return (IsValidSem(semaphore_ptr) ? TX_SUCCESS : TX_SEMAPHORE_ERROR); // noop: FIFO wait list
1463}

References TX_SEMAPHORE_ERROR, and TX_SUCCESS.

◆ tx_semaphore_put()

UINT tx_semaphore_put ( TX_SEMAPHORE * semaphore_ptr)
Examples
blinky-threadx/demo_threadx.c.

Definition at line 1384 of file threadx_stk.cpp.

1385{
1386 UINT result;
1387
1388 if (!IsValidSem(semaphore_ptr))
1389 {
1390 result = TX_SEMAPHORE_ERROR;
1391 }
1392 else if (!SemOf(semaphore_ptr)->TrySignal())
1393 {
1394 result = TX_CEILING_EXCEEDED; // counter saturated at the maximum of ULONG (ThreadX itself would wrap)
1395 }
1396 else
1397 {
1398 if (semaphore_ptr->tx_semaphore_put_notify != nullptr)
1399 {
1400 semaphore_ptr->tx_semaphore_put_notify(semaphore_ptr);
1401 }
1402
1403 result = TX_SUCCESS;
1404 }
1405
1406 return result;
1407}

References SemOf(), TX_CEILING_EXCEEDED, TX_SEMAPHORE_ERROR, TX_SEMAPHORE_STRUCT::tx_semaphore_put_notify, and TX_SUCCESS.

Referenced by thread_3_and_4_entry().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tx_semaphore_put_notify()

UINT tx_semaphore_put_notify ( TX_SEMAPHORE * semaphore_ptr,
void(* semaphore_put_notify )(TX_SEMAPHORE *notify_semaphore_ptr) )

Definition at line 1465 of file threadx_stk.cpp.

1467{
1468 UINT result;
1469
1470 if (!IsValidSem(semaphore_ptr))
1471 {
1472 result = TX_SEMAPHORE_ERROR;
1473 }
1474 else
1475 {
1476 semaphore_ptr->tx_semaphore_put_notify = semaphore_put_notify;
1477 result = TX_SUCCESS;
1478 }
1479
1480 return result;
1481}

References TX_SEMAPHORE_ERROR, TX_SEMAPHORE_STRUCT::tx_semaphore_put_notify, TX_SUCCESS, and VOID.

◆ tx_thread_create()

UINT tx_thread_create ( TX_THREAD * thread_ptr,
const CHAR * name_ptr,
void(* entry_function )(ULONG entry_input),
ULONG entry_input,
void * stack_start,
ULONG stack_size,
UINT priority,
UINT preempt_threshold,
ULONG time_slice,
UINT auto_start )
Examples
blinky-threadx/demo_threadx.c, and blinky_c-threadx/example.c.

Definition at line 515 of file threadx_stk.cpp.

520{
521 UINT result;
522
523 if (thread_ptr == nullptr)
524 {
525 result = TX_THREAD_ERROR;
526 }
527 else if (thread_ptr->tx_thread_id == TX_THREAD_ID)
528 {
529 result = TX_THREAD_ERROR; // already created
530 }
531 else if ((entry_function == nullptr) || (stack_start == nullptr) ||
532 ((reinterpret_cast<uintptr_t>(stack_start) % alignof(stk::Word)) != 0U))
533 {
534 result = TX_PTR_ERROR;
535 }
536 else if (stack_size < static_cast<ULONG>(STK_STACK_SIZE_MIN * sizeof(stk::Word)))
537 {
538 result = TX_SIZE_ERROR;
539 }
540 else if (priority >= TX_MAX_PRIORITIES)
541 {
542 result = TX_PRIORITY_ERROR;
543 }
544 else if (preempt_threshold > priority) // numerically greater = lower than the thread's own priority
545 {
546 result = TX_THRESH_ERROR;
547 }
548 else if (auto_start > TX_AUTO_START)
549 {
550 result = TX_START_ERROR;
551 }
552 else if (InIsr())
553 {
554 result = TX_CALLER_ERROR;
555 }
556 else
557 {
558 thread_ptr->tx_thread_run_count = 0U;
559 thread_ptr->tx_thread_stack_start = stack_start;
560 thread_ptr->tx_thread_stack_size = stack_size;
561 thread_ptr->tx_thread_time_slice = time_slice;
562 thread_ptr->tx_thread_name = name_ptr;
563 thread_ptr->tx_thread_priority = priority;
564 thread_ptr->tx_thread_state = TX_SUSPENDED;
565 thread_ptr->tx_thread_preempt_threshold = preempt_threshold;
566 thread_ptr->tx_thread_entry = entry_function;
567 thread_ptr->tx_thread_entry_parameter = entry_input;
568 thread_ptr->tx_thread_entry_exit_notify = nullptr;
569 thread_ptr->tx_thread_extension_ptr = nullptr;
570 thread_ptr->tx_thread_stk_start_priority = priority;
571 thread_ptr->tx_thread_stk_start_threshold = preempt_threshold;
572 thread_ptr->tx_thread_stk_start_time_slice = time_slice;
573
574 StkThread *const th = new (static_cast<void *>(thread_ptr->tx_thread_stk_storage)) StkThread(thread_ptr);
575
576 result = TX_SUCCESS;
577
578 if (auto_start == TX_AUTO_START)
579 {
580 result = RegisterThread(th);
581 }
582
583 if (result == TX_SUCCESS)
584 {
585 thread_ptr->tx_thread_id = TX_THREAD_ID;
586 }
587 else
588 {
589 th->~StkThread();
590 }
591 }
592
593 return result;
594}
#define STK_STACK_SIZE_MIN
Minimum stack size in elements of Word, shared by all stack allocation lower-bound checks.
Definition stk_defs.h:646
#define TX_SUSPENDED
Definition tx_api.h:179
#define TX_THRESH_ERROR
Definition tx_api.h:218
#define TX_THREAD_ID
Definition tx_api.h:232
#define TX_PRIORITY_ERROR
Definition tx_api.h:208
#define TX_MAX_PRIORITIES
Definition tx_api.h:55
#define TX_THREAD_ERROR
Definition tx_api.h:207
#define TX_START_ERROR
Definition tx_api.h:210
uintptr_t Word
Native processor word type.
Definition stk_common.h:206
void(* tx_thread_entry)(ULONG entry_input)
Definition tx_api.h:265
ULONG tx_thread_stack_size
Definition tx_api.h:259
UINT tx_thread_preempt_threshold
Definition tx_api.h:264
UINT tx_thread_stk_start_threshold
Definition tx_api.h:270
UINT tx_thread_stk_start_priority
Definition tx_api.h:269
UINT tx_thread_state
Definition tx_api.h:263
ULONG tx_thread_entry_parameter
Definition tx_api.h:266
ALIGN_TYPE tx_thread_stk_storage[(24U)]
Definition tx_api.h:272
void * tx_thread_stack_start
Definition tx_api.h:258
void(* tx_thread_entry_exit_notify)(struct TX_THREAD_STRUCT *thread_ptr, UINT condition)
Definition tx_api.h:267
ULONG tx_thread_id
Definition tx_api.h:256
ULONG tx_thread_run_count
Definition tx_api.h:257
ULONG tx_thread_stk_start_time_slice
Definition tx_api.h:271
ULONG tx_thread_time_slice
Definition tx_api.h:260
UINT tx_thread_priority
Definition tx_api.h:262
const CHAR * tx_thread_name
Definition tx_api.h:261
void * tx_thread_extension_ptr
Definition tx_api.h:268

References STK_STACK_SIZE_MIN, TX_AUTO_START, TX_CALLER_ERROR, TX_MAX_PRIORITIES, TX_NAME_CONST, TX_PRIORITY_ERROR, TX_PTR_ERROR, TX_SIZE_ERROR, TX_START_ERROR, TX_SUCCESS, TX_SUSPENDED, TX_THREAD_STRUCT::tx_thread_entry, TX_THREAD_STRUCT::tx_thread_entry_exit_notify, TX_THREAD_STRUCT::tx_thread_entry_parameter, TX_THREAD_ERROR, TX_THREAD_STRUCT::tx_thread_extension_ptr, TX_THREAD_ID, TX_THREAD_STRUCT::tx_thread_id, TX_THREAD_STRUCT::tx_thread_name, TX_THREAD_STRUCT::tx_thread_preempt_threshold, TX_THREAD_STRUCT::tx_thread_priority, TX_THREAD_STRUCT::tx_thread_run_count, TX_THREAD_STRUCT::tx_thread_stack_size, TX_THREAD_STRUCT::tx_thread_stack_start, TX_THREAD_STRUCT::tx_thread_state, TX_THREAD_STRUCT::tx_thread_stk_start_priority, TX_THREAD_STRUCT::tx_thread_stk_start_threshold, TX_THREAD_STRUCT::tx_thread_stk_start_time_slice, TX_THREAD_STRUCT::tx_thread_stk_storage, TX_THREAD_STRUCT::tx_thread_time_slice, TX_THRESH_ERROR, and VOID.

Referenced by app_main(), and tx_application_define().

Here is the caller graph for this function:

◆ tx_thread_delete()

UINT tx_thread_delete ( TX_THREAD * thread_ptr)

Definition at line 596 of file threadx_stk.cpp.

597{
598 UINT result;
599
600 if (!IsValidThread(thread_ptr))
601 {
602 result = TX_THREAD_ERROR;
603 }
604 else if (InIsr())
605 {
606 result = TX_CALLER_ERROR;
607 }
608 else if ((thread_ptr->tx_thread_state != TX_COMPLETED) && (thread_ptr->tx_thread_state != TX_TERMINATED))
609 {
610 result = TX_DELETE_ERROR;
611 }
612 else
613 {
614 StkThread *const th = ThreadOf(thread_ptr);
615
616 if (!WaitThreadRemoved(th))
617 {
618 result = TX_DELETE_ERROR; // the kernel still references the thread
619 }
620 else
621 {
622 thread_ptr->tx_thread_id = TX_CLEAR_ID;
623 th->~StkThread();
624 result = TX_SUCCESS;
625 }
626 }
627
628 return result;
629}
#define TX_COMPLETED
Definition tx_api.h:177
#define TX_DELETE_ERROR
Definition tx_api.h:211
#define TX_TERMINATED
Definition tx_api.h:178

References TX_CALLER_ERROR, TX_CLEAR_ID, TX_COMPLETED, TX_DELETE_ERROR, TX_SUCCESS, TX_TERMINATED, TX_THREAD_ERROR, TX_THREAD_STRUCT::tx_thread_id, and TX_THREAD_STRUCT::tx_thread_state.

◆ tx_thread_entry_exit_notify()

UINT tx_thread_entry_exit_notify ( TX_THREAD * thread_ptr,
void(* thread_entry_exit_notify )(TX_THREAD *notify_thread_ptr, UINT type) )

Definition at line 631 of file threadx_stk.cpp.

633{
634 UINT result;
635
636 if (!IsValidThread(thread_ptr))
637 {
638 result = TX_THREAD_ERROR;
639 }
640 else
641 {
642 thread_ptr->tx_thread_entry_exit_notify = thread_entry_exit_notify;
643 result = TX_SUCCESS;
644 }
645
646 return result;
647}

References TX_SUCCESS, TX_THREAD_STRUCT::tx_thread_entry_exit_notify, TX_THREAD_ERROR, and VOID.

◆ tx_thread_identify()

TX_THREAD * tx_thread_identify ( void )
Examples
blinky_c-threadx/example.c.

Definition at line 649 of file threadx_stk.cpp.

650{
651 StkThread *const th = CurrentThread();
652
653 return ((th != nullptr) ? th->m_tx : nullptr);
654}

References VOID.

Referenced by app_main().

Here is the caller graph for this function:

◆ tx_thread_info_get()

UINT tx_thread_info_get ( TX_THREAD * thread_ptr,
const CHAR ** name,
UINT * state,
ULONG * run_count,
UINT * priority,
UINT * preemption_threshold,
ULONG * time_slice,
TX_THREAD ** next_thread,
TX_THREAD ** next_suspended_thread )

Definition at line 656 of file threadx_stk.cpp.

659{
660 UINT result;
661
662 if (!IsValidThread(thread_ptr))
663 {
664 result = TX_THREAD_ERROR;
665 }
666 else
667 {
668 if (name != nullptr) { *name = thread_ptr->tx_thread_name; }
669 if (state != nullptr) { *state = ThreadStateOf(thread_ptr); }
670 if (run_count != nullptr) { *run_count = thread_ptr->tx_thread_run_count; }
671 if (priority != nullptr) { *priority = thread_ptr->tx_thread_priority; }
672 if (preemption_threshold != nullptr) { *preemption_threshold = thread_ptr->tx_thread_preempt_threshold; }
673 if (time_slice != nullptr) { *time_slice = thread_ptr->tx_thread_time_slice; }
674
675 // the kernel does not expose its internal created/suspended lists
676 if (next_thread != nullptr) { *next_thread = nullptr; }
677 if (next_suspended_thread != nullptr) { *next_suspended_thread = nullptr; }
678
679 result = TX_SUCCESS;
680 }
681
682 return result;
683}

References TX_NAME_CONST, TX_SUCCESS, TX_THREAD_ERROR, TX_THREAD_STRUCT::tx_thread_name, TX_THREAD_STRUCT::tx_thread_preempt_threshold, TX_THREAD_STRUCT::tx_thread_priority, TX_THREAD_STRUCT::tx_thread_run_count, and TX_THREAD_STRUCT::tx_thread_time_slice.

◆ tx_thread_preemption_change()

UINT tx_thread_preemption_change ( TX_THREAD * thread_ptr,
UINT new_threshold,
UINT * old_threshold )

Definition at line 685 of file threadx_stk.cpp.

686{
687 UINT result;
688
689 if (!IsValidThread(thread_ptr))
690 {
691 result = TX_THREAD_ERROR;
692 }
693 else if (old_threshold == nullptr)
694 {
695 result = TX_PTR_ERROR;
696 }
697 else if (new_threshold > thread_ptr->tx_thread_priority)
698 {
699 result = TX_THRESH_ERROR;
700 }
701 else if (InIsr())
702 {
703 result = TX_CALLER_ERROR;
704 }
705 else
706 {
707 StkThread *const th = ThreadOf(thread_ptr);
708
709 *old_threshold = thread_ptr->tx_thread_preempt_threshold;
710
711 thread_ptr->tx_thread_preempt_threshold = new_threshold;
712 th->m_weight = ToStkWeight(thread_ptr->tx_thread_priority, new_threshold);
713
714 if (th->m_registered && !th->m_removed)
715 {
716 // run-time threshold change, handled by the strategy (releases/creates the thread's hold)
717 stk::SetWeight(stk::GetTidFromUserTask(th), th->m_weight);
718 }
719
720 result = TX_SUCCESS;
721 }
722
723 return result;
724}
TId GetTidFromUserTask(const ITask *task) noexcept
Get task identifier from ITask instance.
Definition stk_arch.h:775
static Weight SetWeight(TId tid, Weight weight)
Change the base scheduling weight of a task at run-time.
Definition stk_helper.h:655

References stk::GetTidFromUserTask(), stk::SetWeight(), TX_CALLER_ERROR, TX_PTR_ERROR, TX_SUCCESS, TX_THREAD_ERROR, TX_THREAD_STRUCT::tx_thread_preempt_threshold, TX_THREAD_STRUCT::tx_thread_priority, and TX_THRESH_ERROR.

Here is the call graph for this function:

◆ tx_thread_priority_change()

UINT tx_thread_priority_change ( TX_THREAD * thread_ptr,
UINT new_priority,
UINT * old_priority )

Definition at line 726 of file threadx_stk.cpp.

727{
728 UINT result;
729
730 if (!IsValidThread(thread_ptr))
731 {
732 result = TX_THREAD_ERROR;
733 }
734 else if (new_priority >= TX_MAX_PRIORITIES)
735 {
736 result = TX_PRIORITY_ERROR;
737 }
738 else if (old_priority == nullptr)
739 {
740 result = TX_PTR_ERROR;
741 }
742 else if (InIsr())
743 {
744 result = TX_CALLER_ERROR;
745 }
746 else
747 {
748 StkThread *const th = ThreadOf(thread_ptr);
749
750 *old_priority = thread_ptr->tx_thread_priority;
751
752 // as in ThreadX: a threshold numerically smaller than the new priority is kept, otherwise
753 // (the new priority is more urgent than the threshold) it is lowered to the new priority
754 UINT new_threshold = thread_ptr->tx_thread_preempt_threshold;
755 if (new_priority < new_threshold)
756 {
757 new_threshold = new_priority;
758 }
759
760 thread_ptr->tx_thread_priority = new_priority;
761 thread_ptr->tx_thread_preempt_threshold = new_threshold;
762 th->m_weight = ToStkWeight(new_priority, new_threshold);
763
764 if (th->m_registered && !th->m_removed)
765 {
766 stk::SetWeight(stk::GetTidFromUserTask(th), th->m_weight);
767 }
768
769 result = TX_SUCCESS;
770 }
771
772 return result;
773}

References stk::GetTidFromUserTask(), stk::SetWeight(), TX_CALLER_ERROR, TX_MAX_PRIORITIES, TX_PRIORITY_ERROR, TX_PTR_ERROR, TX_SUCCESS, TX_THREAD_ERROR, TX_THREAD_STRUCT::tx_thread_preempt_threshold, and TX_THREAD_STRUCT::tx_thread_priority.

Here is the call graph for this function:

◆ tx_thread_relinquish()

void tx_thread_relinquish ( void )

Definition at line 775 of file threadx_stk.cpp.

776{
777 if (!InIsr() && KernelRunning())
778 {
779 stk::Yield(); // tx_thread_relinquish semantics (sched::SwitchStrategyPreemptionThreshold handles it in OnTaskYield())
780 }
781}
static void Yield()
Notify scheduler to switch to the next runnable task.
Definition stk_helper.h:562

References VOID, and stk::Yield().

Here is the call graph for this function:

◆ tx_thread_reset()

UINT tx_thread_reset ( TX_THREAD * thread_ptr)

Definition at line 783 of file threadx_stk.cpp.

784{
785 UINT result;
786
787 if (!IsValidThread(thread_ptr))
788 {
789 result = TX_THREAD_ERROR;
790 }
791 else if (InIsr())
792 {
793 result = TX_CALLER_ERROR;
794 }
795 else if ((thread_ptr->tx_thread_state != TX_COMPLETED) && (thread_ptr->tx_thread_state != TX_TERMINATED))
796 {
797 result = TX_NOT_DONE;
798 }
799 else
800 {
801 StkThread *th = ThreadOf(thread_ptr);
802
803 if (!WaitThreadRemoved(th))
804 {
805 result = TX_NOT_DONE; // the kernel is still removing the thread, try again later
806 }
807 else
808 {
809 // restore creation parameters and re-create the STK task object
810 thread_ptr->tx_thread_priority = thread_ptr->tx_thread_stk_start_priority;
813 thread_ptr->tx_thread_state = TX_SUSPENDED;
814
815 th->~StkThread();
816 new (static_cast<void *>(thread_ptr->tx_thread_stk_storage)) StkThread(thread_ptr);
817
818 result = TX_SUCCESS; // resume it with tx_thread_resume()
819 }
820 }
821
822 return result;
823}
#define TX_NOT_DONE
Definition tx_api.h:226

References TX_CALLER_ERROR, TX_COMPLETED, TX_NOT_DONE, TX_SUCCESS, TX_SUSPENDED, TX_TERMINATED, TX_THREAD_ERROR, TX_THREAD_STRUCT::tx_thread_preempt_threshold, TX_THREAD_STRUCT::tx_thread_priority, TX_THREAD_STRUCT::tx_thread_state, TX_THREAD_STRUCT::tx_thread_stk_start_priority, TX_THREAD_STRUCT::tx_thread_stk_start_threshold, TX_THREAD_STRUCT::tx_thread_stk_start_time_slice, TX_THREAD_STRUCT::tx_thread_stk_storage, and TX_THREAD_STRUCT::tx_thread_time_slice.

◆ tx_thread_resume()

UINT tx_thread_resume ( TX_THREAD * thread_ptr)

Definition at line 920 of file threadx_stk.cpp.

921{
922 UINT result = TX_RESUME_ERROR;
923
924 if (!IsValidThread(thread_ptr))
925 {
926 result = TX_THREAD_ERROR;
927 }
928 else
929 {
930 StkThread *const th = ThreadOf(thread_ptr);
931 bool start = false;
932
933 {
935
936 // claim the start: a concurrent tx_thread_resume() (task or ISR) must not pass the thread to the kernel twice
937 start = IsNotStarted(thread_ptr, th);
938 if (start)
939 {
940 th->m_registered = true;
941 }
942 }
943
944 if (start)
945 {
946 // first start (TX_DONT_START) or restart after tx_thread_reset(), allowed from an ISR too
947 // (the kernel adds a task from an ISR immediately), on failure RegisterThread() rolls the claim back
948 result = RegisterThread(th);
949 }
950 else
951 {
952 // tx_thread_state is not modified, see tx_thread_suspend()
953 switch (g_StkKernel.ResumeTask(th))
954 {
955 case stk::RESUME_DONE:
956 result = TX_SUCCESS;
957 break;
958 case stk::RESUME_LIFTED: // deferred suspension withdrawn before it took effect
959 result = TX_SUSPEND_LIFTED;
960 break;
961 default: // RESUME_NOT_SUSPENDED / RESUME_FAIL
962 result = TX_RESUME_ERROR;
963 break;
964 }
965 }
966 }
967
968 return result;
969}
static bool IsNotStarted(const TX_THREAD *tx, const StkThread *th)
#define TX_RESUME_ERROR
Definition tx_api.h:212
#define TX_SUSPEND_LIFTED
Definition tx_api.h:219
@ RESUME_LIFTED
Deferred suspension was cancelled before it took effect.
Definition stk_common.h:187
@ RESUME_DONE
Suspended task has been resumed.
Definition stk_common.h:186

References IsNotStarted(), stk::RESUME_DONE, stk::RESUME_LIFTED, TX_RESUME_ERROR, TX_SUCCESS, TX_SUSPEND_LIFTED, and TX_THREAD_ERROR.

Here is the call graph for this function:

◆ tx_thread_sleep()

UINT tx_thread_sleep ( ULONG timer_ticks)
Examples
blinky-threadx/demo_threadx.c, and blinky_c-threadx/example.c.

Definition at line 825 of file threadx_stk.cpp.

826{
827 UINT result;
828 StkThread *const th = CurrentThread();
829
830 if (th == nullptr)
831 {
832 result = TX_CALLER_ERROR;
833 }
834 else if (timer_ticks == 0U)
835 {
836 result = TX_SUCCESS;
837 }
838 else
839 {
840 th->m_abort = false;
841
842 // WAIT_INFINITE (INT32_MAX) is a valid very long sleep, ThreadX has no infinite sleep
843 stk::Sleep(ToStkTimeout(timer_ticks)); // reported as TX_SLEEP by ThreadStateOf() (kernel state SLEEPING)
844
845 if (th->m_abort)
846 {
847 th->m_abort = false;
848 result = TX_WAIT_ABORTED;
849 }
850 else
851 {
852 result = TX_SUCCESS;
853 }
854 }
855
856 return result;
857}
#define TX_WAIT_ABORTED
Definition tx_api.h:220
static bool Sleep(Timeout tick_count)
Put calling process into a sleep state.
Definition stk_helper.h:495

References stk::Sleep(), TX_CALLER_ERROR, TX_SUCCESS, and TX_WAIT_ABORTED.

Referenced by clock_thread(), signal_func(), thread_0_entry(), thread_3_and_4_entry(), and thread_6_and_7_entry().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tx_thread_stack_error_notify()

UINT tx_thread_stack_error_notify ( void(* stack_error_handler )(TX_THREAD *thread_ptr))

Definition at line 859 of file threadx_stk.cpp.

860{
861 // STK reports a stack overflow with KERNEL_PANIC_STACK_CORRUPT (see stk::IKernel panic handling),
862 // there is no per-thread callback: accepted for source compatibility and ignored.
863 (void)stack_error_handler;
864 return TX_SUCCESS;
865}

References TX_SUCCESS, and VOID.

◆ tx_thread_suspend()

UINT tx_thread_suspend ( TX_THREAD * thread_ptr)
Examples
blinky_c-threadx/example.c.

Definition at line 873 of file threadx_stk.cpp.

874{
875 UINT result = TX_SUSPEND_ERROR;
876
877 if (!IsValidThread(thread_ptr))
878 {
879 result = TX_THREAD_ERROR;
880 }
881 else if (!KernelRunning())
882 {
883 result = TX_CALLER_ERROR;
884 }
885 else
886 {
887 StkThread *const th = ThreadOf(thread_ptr);
888 bool eligible;
889
890 {
892
893 // only a thread which is known to the kernel and has not completed/terminated
894 eligible = (th->m_registered && !th->m_removed && (thread_ptr->tx_thread_state == TX_READY));
895 }
896
897 // tx_thread_state is intentionally not modified: TX_SUSPENDED is derived from the kernel by ThreadStateOf()
898 // (IKernel::GetTaskState()). A thread blocked in a sleep/wait keeps reporting its wait state until the wait
899 // ends (ThreadX "delayed suspension"), and a lifted suspension leaves nothing to restore.
900 if (eligible)
901 {
902 // for the calling thread this returns after it has been resumed (SUSPEND_DONE)
903 switch (g_StkKernel.SuspendTask(th))
904 {
906 case stk::SUSPEND_DEFERRED: // sleeping/waiting: the kernel parks the thread when the sleep/wait ends,
907 // its wait result is preserved
908 result = TX_SUCCESS;
909 break;
910 default: // SUSPEND_ALREADY / SUSPEND_FAIL
911 result = TX_SUSPEND_ERROR;
912 break;
913 }
914 }
915 }
916
917 return result;
918}
#define TX_READY
Definition tx_api.h:176
#define TX_SUSPEND_ERROR
Definition tx_api.h:214
@ SUSPEND_DONE
Task was runnable and is suspended now.
Definition stk_common.h:174
@ SUSPEND_DEFERRED
Task is sleeping/waiting: it will be suspended when the sleep/wait ends (wait result is preserved).
Definition stk_common.h:175

References stk::SUSPEND_DEFERRED, stk::SUSPEND_DONE, TX_CALLER_ERROR, TX_READY, TX_SUCCESS, TX_SUSPEND_ERROR, TX_THREAD_ERROR, and TX_THREAD_STRUCT::tx_thread_state.

Referenced by app_main().

Here is the caller graph for this function:

◆ tx_thread_terminate()

UINT tx_thread_terminate ( TX_THREAD * thread_ptr)

Definition at line 971 of file threadx_stk.cpp.

972{
973 UINT result;
974
975 if (!IsValidThread(thread_ptr))
976 {
977 result = TX_THREAD_ERROR;
978 }
979 else if (InIsr())
980 {
981 result = TX_CALLER_ERROR;
982 }
983 else if ((thread_ptr->tx_thread_state == TX_COMPLETED) || (thread_ptr->tx_thread_state == TX_TERMINATED))
984 {
985 result = TX_SUCCESS;
986 }
987 else
988 {
989 StkThread *const th = ThreadOf(thread_ptr);
990 const bool is_self = (CurrentThread() == th);
991 bool in_kernel;
992
993 {
995
996 in_kernel = (th->m_registered && !th->m_removed);
997 thread_ptr->tx_thread_state = TX_TERMINATED;
998 }
999
1000 if (thread_ptr->tx_thread_entry_exit_notify != nullptr)
1001 {
1002 thread_ptr->tx_thread_entry_exit_notify(thread_ptr, TX_THREAD_EXIT);
1003 }
1004
1005 if (in_kernel)
1006 {
1007 if (is_self)
1008 {
1009 // the calling thread is switched out and removed by the kernel, does not return
1010 stk::ExitTask();
1011 }
1012 else
1013 {
1014 // OnExit() fires from the kernel tick once the task is actually removed
1015 g_StkKernel.ScheduleTaskRemoval(th);
1016 }
1017 }
1018
1019 result = TX_SUCCESS;
1020 }
1021
1022 return result;
1023}
#define TX_THREAD_EXIT
Definition tx_api.h:165
static void ExitTask()
Terminate the calling task: schedule its removal and switch it out. Does not return.
Definition stk_helper.h:578

References stk::ExitTask(), TX_CALLER_ERROR, TX_COMPLETED, TX_SUCCESS, TX_TERMINATED, TX_THREAD_STRUCT::tx_thread_entry_exit_notify, TX_THREAD_ERROR, TX_THREAD_EXIT, and TX_THREAD_STRUCT::tx_thread_state.

Here is the call graph for this function:

◆ tx_thread_time_slice_change()

UINT tx_thread_time_slice_change ( TX_THREAD * thread_ptr,
ULONG new_time_slice,
ULONG * old_time_slice )

Definition at line 1025 of file threadx_stk.cpp.

1026{
1027 UINT result;
1028
1029 if (!IsValidThread(thread_ptr))
1030 {
1031 result = TX_THREAD_ERROR;
1032 }
1033 else if (old_time_slice == nullptr)
1034 {
1035 result = TX_PTR_ERROR;
1036 }
1037 else if (InIsr())
1038 {
1039 result = TX_CALLER_ERROR;
1040 }
1041 else
1042 {
1043 StkThread *const th = ThreadOf(thread_ptr);
1044
1045 *old_time_slice = thread_ptr->tx_thread_time_slice;
1046 thread_ptr->tx_thread_time_slice = new_time_slice;
1047
1048 const stk::Timeout ticks = ((new_time_slice == TX_NO_TIME_SLICE) ? stk::NO_TIME_SLICE :
1049 static_cast<stk::Timeout>(stk::Min<ULONG>(new_time_slice, static_cast<ULONG>(stk::WAIT_INFINITE) - 1U)));
1050
1051 th->m_time_slice = ticks;
1052
1053 if (th->m_registered && !th->m_removed)
1054 {
1056 }
1057
1058 result = TX_SUCCESS;
1059 }
1060
1061 return result;
1062}
static Timeout SetTimeSlice(TId tid, Timeout ticks)
Change the time-slice quantum of a task at run-time and reload its slice.
Definition stk_helper.h:682
int32_t Timeout
Timeout time (ticks).
Definition stk_common.h:216
static constexpr Timeout NO_TIME_SLICE
Time-slice quantum value: no time-slicing for the task (it runs until it blocks, yields or is preempt...
Definition stk_common.h:296
static constexpr Timeout WAIT_INFINITE
Timeout value: block indefinitely until the synchronization object is signaled.
Definition stk_common.h:274

References stk::GetTidFromUserTask(), stk::Min(), stk::NO_TIME_SLICE, stk::SetTimeSlice(), TX_CALLER_ERROR, TX_NO_TIME_SLICE, TX_PTR_ERROR, TX_SUCCESS, TX_THREAD_ERROR, TX_THREAD_STRUCT::tx_thread_time_slice, and stk::WAIT_INFINITE.

Here is the call graph for this function:

◆ tx_thread_wait_abort()

UINT tx_thread_wait_abort ( TX_THREAD * thread_ptr)

Definition at line 1064 of file threadx_stk.cpp.

1065{
1066 UINT result;
1067
1068 if (!IsValidThread(thread_ptr))
1069 {
1070 result = TX_THREAD_ERROR;
1071 }
1072 else
1073 {
1074 StkThread *const th = ThreadOf(thread_ptr);
1075
1077
1078 if (th->m_registered && !th->m_removed)
1079 {
1080 if (!g_StkKernel.GetTaskState(th, info))
1081 {
1082 info.state = stk::TASK_STATE_REMOVED; // not queryable: not blocked as far as we can tell
1083 }
1084 }
1085
1086 // exact: a thread suspended by tx_thread_suspend() is reported as SUSPENDED, not as sleeping
1087 const bool sleeping = (info.state == stk::TASK_STATE_SLEEPING);
1088 const bool waiting = (info.state == stk::TASK_STATE_WAITING);
1089
1090 if (!sleeping && !waiting)
1091 {
1092 result = TX_WAIT_ABORT_ERROR;
1093 }
1094 else
1095 {
1096 if (sleeping)
1097 {
1098 th->m_abort = true; // lets tx_thread_sleep() report TX_WAIT_ABORTED
1099 }
1100
1101 // ends a plain sleep and cancels a sync-object wait (reported as WAIT_RESULT_CANCELED) identically
1103 result = TX_SUCCESS;
1104 }
1105 }
1106
1107 return result;
1108}
#define TX_WAIT_ABORT_ERROR
Definition tx_api.h:221
static void SleepCancel(TId task_id)
Cancel sleep of the task.
Definition stk_helper.h:539
@ TASK_STATE_SLEEPING
Sleeping via Sleep()/SleepUntil(), with a finite or an infinite timeout.
Definition stk_common.h:85
@ TASK_STATE_REMOVED
The task is not bound to a kernel slot (never added, or already removed).
Definition stk_common.h:83
@ TASK_STATE_WAITING
Blocked on a synchronization object (IKernelService::Wait). KERNEL_SYNC mode only.
Definition stk_common.h:86
Snapshot of the kernel-side state of a task, filled in by IKernel::GetTaskState().
Definition stk_common.h:384
ETaskState state
Task state.
Definition stk_common.h:385

References stk::GetTidFromUserTask(), stk::SleepCancel(), stk::TaskStateInfo::state, stk::TASK_STATE_REMOVED, stk::TASK_STATE_SLEEPING, stk::TASK_STATE_WAITING, TX_SUCCESS, TX_THREAD_ERROR, TX_WAIT_ABORT_ERROR, and stk::WAIT_INFINITE.

Here is the call graph for this function:

◆ tx_time_get()

ULONG tx_time_get ( void )

Definition at line 491 of file threadx_stk.cpp.

492{
493 ULONG result = 0U;
494
495 if (KernelInitialized())
496 {
497 result = static_cast<ULONG>(static_cast<int64_t>(stk::GetTicks()) + g_TimeOffset);
498 }
499
500 return result;
501}
static Ticks GetTicks()
Get number of ticks elapsed since kernel start.
Definition stk_helper.h:448

References stk::GetTicks(), and VOID.

Here is the call graph for this function:

◆ tx_time_set()

void tx_time_set ( ULONG new_time)

Definition at line 503 of file threadx_stk.cpp.

504{
505 if (KernelInitialized())
506 {
507 g_TimeOffset = (static_cast<int64_t>(new_time) - static_cast<int64_t>(stk::GetTicks()));
508 }
509}

References stk::GetTicks(), and VOID.

Here is the call graph for this function:

◆ tx_timer_activate()

UINT tx_timer_activate ( TX_TIMER * timer_ptr)

Definition at line 2686 of file threadx_stk.cpp.

2687{
2688 UINT result;
2689
2690 if (!IsValidTimer(timer_ptr))
2691 {
2692 result = TX_TIMER_ERROR;
2693 }
2694 else
2695 {
2696 // a new expiration is relative to the moment of the call, the delay is the one of tx_timer_create/change
2697 result = TimerResultToTx(g_TimerHost.ActivateSync(*TimerOf(timer_ptr)), TX_ACTIVATE_ERROR);
2698 }
2699
2700 return result;
2701}
static PosixTimer * TimerOf(timer_t id)
#define TX_TIMER_ERROR
Definition tx_api.h:215
#define TX_ACTIVATE_ERROR
Definition tx_api.h:217

References TimerOf(), TX_ACTIVATE_ERROR, and TX_TIMER_ERROR.

Referenced by tx_timer_create().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tx_timer_change()

UINT tx_timer_change ( TX_TIMER * timer_ptr,
ULONG initial_ticks,
ULONG reschedule_ticks )

Definition at line 2719 of file threadx_stk.cpp.

2720{
2721 UINT result;
2722
2723 if (!IsValidTimer(timer_ptr))
2724 {
2725 result = TX_TIMER_ERROR;
2726 }
2727 else if (initial_ticks == 0U)
2728 {
2729 result = TX_TICK_ERROR;
2730 }
2731 else
2732 {
2733 // ThreadX requires the timer to be deactivated (TX_ACTIVATE_ERROR otherwise), the new values are used by
2734 // the next tx_timer_activate()
2735 result = TimerResultToTx(g_TimerHost.ChangeSync(*TimerOf(timer_ptr), ToStkTicks(initial_ticks),
2736 ToStkTicks(reschedule_ticks)), TX_ACTIVATE_ERROR);
2737
2738 if (result == TX_SUCCESS)
2739 {
2740 timer_ptr->tx_timer_initial_ticks = initial_ticks;
2741 timer_ptr->tx_timer_reschedule_ticks = reschedule_ticks;
2742 }
2743 }
2744
2745 return result;
2746}
#define TX_TICK_ERROR
Definition tx_api.h:216
ULONG tx_timer_initial_ticks
Definition tx_api.h:329
ULONG tx_timer_reschedule_ticks
Definition tx_api.h:330

References TimerOf(), TX_ACTIVATE_ERROR, TX_SUCCESS, TX_TICK_ERROR, TX_TIMER_ERROR, TX_TIMER_STRUCT::tx_timer_initial_ticks, and TX_TIMER_STRUCT::tx_timer_reschedule_ticks.

Here is the call graph for this function:

◆ tx_timer_create()

UINT tx_timer_create ( TX_TIMER * timer_ptr,
const CHAR * name_ptr,
void(* expiration_function )(ULONG input),
ULONG expiration_input,
ULONG initial_ticks,
ULONG reschedule_ticks,
UINT auto_activate )

Definition at line 2582 of file threadx_stk.cpp.

2585{
2586 UINT result;
2587
2588 if (timer_ptr == nullptr)
2589 {
2590 result = TX_TIMER_ERROR;
2591 }
2592 else if (timer_ptr->tx_timer_id == TX_TIMER_ID)
2593 {
2594 result = TX_TIMER_ERROR; // already created
2595 }
2596 else if (expiration_function == nullptr)
2597 {
2598 result = TX_FEATURE_NOT_ENABLED; // ThreadX reports TX_FUNCTION_ERROR (0x20) here, not defined in the API subset
2599 }
2600 else if (initial_ticks == 0U)
2601 {
2602 result = TX_TICK_ERROR;
2603 }
2604 else if (auto_activate > TX_AUTO_ACTIVATE)
2605 {
2606 result = TX_ACTIVATE_ERROR;
2607 }
2608 else if (InIsr() || !KernelInitialized())
2609 {
2610 result = TX_CALLER_ERROR;
2611 }
2612 else
2613 {
2614 result = EnsureTimerHost();
2615
2616 if (result == TX_SUCCESS)
2617 {
2618 timer_ptr->tx_timer_name = name_ptr;
2619 timer_ptr->tx_timer_expiration_function = expiration_function;
2620 timer_ptr->tx_timer_expiration_input = expiration_input;
2621 timer_ptr->tx_timer_initial_ticks = initial_ticks;
2622 timer_ptr->tx_timer_reschedule_ticks = reschedule_ticks;
2623
2624 StkTimer *const t = new (static_cast<void *>(timer_ptr->tx_timer_stk_storage)) StkTimer(timer_ptr);
2625
2626 // store the parameters in the timer (it is not started yet, so this cannot fail on activity)
2627 result = TimerResultToTx(g_TimerHost.ChangeSync(*t, ToStkTicks(initial_ticks), ToStkTicks(reschedule_ticks)),
2629
2630 if (result == TX_SUCCESS)
2631 {
2632 timer_ptr->tx_timer_id = TX_TIMER_ID;
2633
2634 if (auto_activate == TX_AUTO_ACTIVATE)
2635 {
2636 result = tx_timer_activate(timer_ptr);
2637
2638 if (result != TX_SUCCESS)
2639 {
2640 timer_ptr->tx_timer_id = TX_CLEAR_ID;
2641 }
2642 }
2643 }
2644
2645 if (result != TX_SUCCESS)
2646 {
2647 t->~StkTimer();
2648 }
2649 }
2650 }
2651
2652 return result;
2653}
#define TX_AUTO_ACTIVATE
Definition tx_api.h:157
#define TX_TIMER_ID
Definition tx_api.h:239
#define TX_FEATURE_NOT_ENABLED
Definition tx_api.h:229
UINT tx_timer_activate(TX_TIMER *timer_ptr)
ULONG tx_timer_expiration_input
Definition tx_api.h:328
ULONG tx_timer_id
Definition tx_api.h:325
void(* tx_timer_expiration_function)(ULONG input)
Definition tx_api.h:327
ULONG64 tx_timer_stk_storage[(8U)]
Definition tx_api.h:331
const CHAR * tx_timer_name
Definition tx_api.h:326

References TX_ACTIVATE_ERROR, TX_AUTO_ACTIVATE, TX_CALLER_ERROR, TX_CLEAR_ID, TX_FEATURE_NOT_ENABLED, TX_NAME_CONST, TX_SUCCESS, TX_TICK_ERROR, tx_timer_activate(), TX_TIMER_ERROR, TX_TIMER_STRUCT::tx_timer_expiration_function, TX_TIMER_STRUCT::tx_timer_expiration_input, TX_TIMER_ID, TX_TIMER_STRUCT::tx_timer_id, TX_TIMER_STRUCT::tx_timer_initial_ticks, TX_TIMER_STRUCT::tx_timer_name, TX_TIMER_STRUCT::tx_timer_reschedule_ticks, TX_TIMER_STRUCT::tx_timer_stk_storage, and VOID.

Here is the call graph for this function:

◆ tx_timer_deactivate()

UINT tx_timer_deactivate ( TX_TIMER * timer_ptr)

Definition at line 2703 of file threadx_stk.cpp.

2704{
2705 UINT result;
2706
2707 if (!IsValidTimer(timer_ptr))
2708 {
2709 result = TX_TIMER_ERROR;
2710 }
2711 else
2712 {
2713 result = TimerResultToTx(g_TimerHost.StopSync(*TimerOf(timer_ptr)), TX_SUCCESS);
2714 }
2715
2716 return result;
2717}

References TimerOf(), TX_SUCCESS, and TX_TIMER_ERROR.

Here is the call graph for this function:

◆ tx_timer_delete()

UINT tx_timer_delete ( TX_TIMER * timer_ptr)

Definition at line 2655 of file threadx_stk.cpp.

2656{
2657 UINT result;
2658
2659 if (!IsValidTimer(timer_ptr))
2660 {
2661 result = TX_TIMER_ERROR;
2662 }
2663 else if (InIsr())
2664 {
2665 result = TX_CALLER_ERROR;
2666 }
2667 else
2668 {
2669 StkTimer *const t = TimerOf(timer_ptr);
2670
2671 timer_ptr->tx_timer_id = TX_CLEAR_ID;
2672
2673 // when StopSync() returns the host holds no reference to the timer (a queued expiration is removed, a
2674 // running expiration function has returned), so the storage can be released by the caller right after
2675 // this function. Called from an expiration function the wait for running functions is skipped (see
2676 // TimerHost "Synchronous API"): do not delete a timer from the expiration function of another timer.
2677 (void)g_TimerHost.StopSync(*t);
2678
2679 t->~StkTimer();
2680 result = TX_SUCCESS;
2681 }
2682
2683 return result;
2684}

References TimerOf(), TX_CALLER_ERROR, TX_CLEAR_ID, TX_SUCCESS, TX_TIMER_ERROR, and TX_TIMER_STRUCT::tx_timer_id.

Here is the call graph for this function:

◆ tx_timer_info_get()

UINT tx_timer_info_get ( TX_TIMER * timer_ptr,
const CHAR ** name,
UINT * active,
ULONG * remaining_ticks,
ULONG * reschedule_ticks,
TX_TIMER ** next_timer )

Definition at line 2748 of file threadx_stk.cpp.

2750{
2751 UINT result;
2752
2753 if (!IsValidTimer(timer_ptr))
2754 {
2755 result = TX_TIMER_ERROR;
2756 }
2757 else
2758 {
2759 StkTimerHost::TimerInfo info = {};
2760
2761 // consistent snapshot made by the tick task (advisory when called from an ISR)
2762 result = TimerResultToTx(g_TimerHost.QuerySync(*TimerOf(timer_ptr), info), TX_TIMER_ERROR);
2763
2764 if (result == TX_SUCCESS)
2765 {
2766 if (name != nullptr) { *name = timer_ptr->tx_timer_name; }
2767 if (active != nullptr) { *active = (info.active ? TX_TRUE : TX_FALSE); }
2768 if (remaining_ticks != nullptr) { *remaining_ticks = static_cast<ULONG>(info.remaining); }
2769 if (reschedule_ticks != nullptr) { *reschedule_ticks = static_cast<ULONG>(info.period); }
2770 if (next_timer != nullptr) { *next_timer = nullptr; }
2771 }
2772 }
2773
2774 return result;
2775}
#define TX_TRUE
Definition tx_api.h:159
#define TX_FALSE
Definition tx_api.h:160

References TimerOf(), TX_FALSE, TX_NAME_CONST, TX_SUCCESS, TX_TIMER_ERROR, TX_TIMER_STRUCT::tx_timer_name, and TX_TRUE.

Here is the call graph for this function: