From 688f56aefcae7a045f02a843b6175d1b31636584 Mon Sep 17 00:00:00 2001 From: Dev10-sys Date: Thu, 22 Oct 2026 14:43:24 +0530 Subject: [PATCH 1/4] Added opt-in pointer callback mode and pointer creation APIs (#771, #772) Support passing full pointer-width context arguments to thread and timer callbacks on 64-bit architectures without truncation, while maintaining full backward compatibility for existing 32-bit ULONG callbacks. - Added tx_thread_create_ptr and tx_timer_create_ptr APIs for direct pointer context callbacks. - Added pointer entry and timeout fields in thread and timer control blocks with automatic dispatch in shell entry and timer threads. - Added TX_ENABLE_POINTER_CALLBACKS configuration option to allow transparent pointer passing with standard create APIs. - Preserved existing ULONG callback signatures across all ports and module manager interfaces. - Added regression tests covering 64-bit pointer argument transmission, error detection paths, and backward compatibility in both standard and SMP builds. Signed-off-by: Dev10-sys --- common/inc/tx_api.h | 50 +++ common/src/tx_thread_create.c | 112 ++++++- common/src/tx_thread_shell_entry.c | 11 +- common/src/tx_timer_create.c | 94 +++++- common/src/tx_timer_expiration_process.c | 20 +- common/src/tx_timer_thread_entry.c | 20 +- common/src/txe_thread_create.c | 141 ++++++++- common/src/txe_timer_create.c | 118 +++++++- common_smp/inc/tx_api.h | 50 +++ common_smp/src/tx_thread_create.c | 107 ++++++- common_smp/src/tx_thread_shell_entry.c | 11 +- common_smp/src/tx_timer_create.c | 94 +++++- common_smp/src/tx_timer_expiration_process.c | 20 +- common_smp/src/tx_timer_thread_entry.c | 18 +- common_smp/src/txe_thread_create.c | 141 ++++++++- common_smp/src/txe_timer_create.c | 114 ++++++- test/smp/cmake/regression/CMakeLists.txt | 1 + .../threadx_pointer_callback_test.c | 284 ++++++++++++++++++ test/tx/cmake/regression/CMakeLists.txt | 3 +- .../threadx_pointer_callback_test.c | 284 ++++++++++++++++++ 20 files changed, 1637 insertions(+), 56 deletions(-) create mode 100644 test/smp/regression/threadx_pointer_callback_test.c create mode 100644 test/tx/regression/threadx_pointer_callback_test.c diff --git a/common/inc/tx_api.h b/common/inc/tx_api.h index ed1f82918..b0d3d0e15 100644 --- a/common/inc/tx_api.h +++ b/common/inc/tx_api.h @@ -346,6 +346,8 @@ typedef struct TX_TIMER_INTERNAL_STRUCT /* Define the timeout function and timeout function parameter. */ VOID (*tx_timer_internal_timeout_function)(ULONG id); ULONG tx_timer_internal_timeout_param; + VOID (*tx_timer_internal_timeout_function_ptr)(VOID *id); + VOID *tx_timer_internal_timeout_param_ptr; /* Define the next and previous internal link pointers for active @@ -467,6 +469,8 @@ typedef struct TX_THREAD_STRUCT /* Define the thread's entry point and input parameter. */ VOID (*tx_thread_entry)(ULONG id); ULONG tx_thread_entry_parameter; + VOID (*tx_thread_entry_ptr)(VOID *id); + VOID *tx_thread_entry_parameter_ptr; /* Define the thread's timer block. This is used for thread sleep and timeout requests. */ @@ -1140,7 +1144,12 @@ UINT _tx_trace_interrupt_control(UINT new_posture); #define tx_semaphore_put _tx_semaphore_put #define tx_semaphore_put_notify _tx_semaphore_put_notify +#define tx_thread_create_ptr _tx_thread_create_ptr +#ifdef TX_ENABLE_POINTER_CALLBACKS +#define tx_thread_create _tx_thread_create_ptr +#else #define tx_thread_create _tx_thread_create +#endif #define tx_thread_delete _tx_thread_delete #define tx_thread_entry_exit_notify _tx_thread_entry_exit_notify #define tx_thread_identify _tx_thread_identify @@ -1163,7 +1172,12 @@ UINT _tx_trace_interrupt_control(UINT new_posture); #define tx_time_set _tx_time_set #define tx_timer_activate _tx_timer_activate #define tx_timer_change _tx_timer_change +#define tx_timer_create_ptr _tx_timer_create_ptr +#ifdef TX_ENABLE_POINTER_CALLBACKS +#define tx_timer_create _tx_timer_create_ptr +#else #define tx_timer_create _tx_timer_create +#endif #define tx_timer_deactivate _tx_timer_deactivate #define tx_timer_delete _tx_timer_delete #define tx_timer_info_get _tx_timer_info_get @@ -1263,7 +1277,12 @@ UINT _tx_trace_interrupt_control(UINT new_posture); #define tx_semaphore_put _txr_semaphore_put #define tx_semaphore_put_notify _txr_semaphore_put_notify +#define tx_thread_create_ptr(t,n,e,i,s,l,p,r,c,a) _txe_thread_create_ptr((t),(n),(e),(i),(s),(l),(p),(r),(c),(a),(sizeof(TX_THREAD))) +#ifdef TX_ENABLE_POINTER_CALLBACKS +#define tx_thread_create(t,n,e,i,s,l,p,r,c,a) _txe_thread_create_ptr((t),(n),(e),(i),(s),(l),(p),(r),(c),(a),(sizeof(TX_THREAD))) +#else #define tx_thread_create(t,n,e,i,s,l,p,r,c,a) _txr_thread_create((t),(n),(e),(i),(s),(l),(p),(r),(c),(a),(sizeof(TX_THREAD))) +#endif #define tx_thread_delete _txr_thread_delete #define tx_thread_entry_exit_notify _txr_thread_entry_exit_notify #define tx_thread_identify _tx_thread_identify @@ -1286,7 +1305,12 @@ UINT _tx_trace_interrupt_control(UINT new_posture); #define tx_time_set _tx_time_set #define tx_timer_activate _txr_timer_activate #define tx_timer_change _txr_timer_change +#define tx_timer_create_ptr(t,n,e,i,c,r,a) _txe_timer_create_ptr((t),(n),(e),(i),(c),(r),(a),(sizeof(TX_TIMER))) +#ifdef TX_ENABLE_POINTER_CALLBACKS +#define tx_timer_create(t,n,e,i,c,r,a) _txe_timer_create_ptr((t),(n),(e),(i),(c),(r),(a),(sizeof(TX_TIMER))) +#else #define tx_timer_create(t,n,e,i,c,r,a) _txr_timer_create((t),(n),(e),(i),(c),(r),(a),(sizeof(TX_TIMER))) +#endif #define tx_timer_deactivate _txr_timer_deactivate #define tx_timer_delete _txr_timer_delete #define tx_timer_info_get _txr_timer_info_get @@ -1374,7 +1398,12 @@ UINT _tx_el_interrupt_control(UINT new_posture); #define tx_semaphore_put _txe_semaphore_put #define tx_semaphore_put_notify _txe_semaphore_put_notify +#define tx_thread_create_ptr(t,n,e,i,s,l,p,r,c,a) _txe_thread_create_ptr((t),(n),(e),(i),(s),(l),(p),(r),(c),(a),(sizeof(TX_THREAD))) +#ifdef TX_ENABLE_POINTER_CALLBACKS +#define tx_thread_create(t,n,e,i,s,l,p,r,c,a) _txe_thread_create_ptr((t),(n),(e),(i),(s),(l),(p),(r),(c),(a),(sizeof(TX_THREAD))) +#else #define tx_thread_create(t,n,e,i,s,l,p,r,c,a) _txe_thread_create((t),(n),(e),(i),(s),(l),(p),(r),(c),(a),(sizeof(TX_THREAD))) +#endif #define tx_thread_delete _txe_thread_delete #define tx_thread_entry_exit_notify _txe_thread_entry_exit_notify #define tx_thread_identify _tx_thread_identify @@ -1397,7 +1426,12 @@ UINT _tx_el_interrupt_control(UINT new_posture); #define tx_time_set _tx_time_set #define tx_timer_activate _txe_timer_activate #define tx_timer_change _txe_timer_change +#define tx_timer_create_ptr(t,n,e,i,c,r,a) _txe_timer_create_ptr((t),(n),(e),(i),(c),(r),(a),(sizeof(TX_TIMER))) +#ifdef TX_ENABLE_POINTER_CALLBACKS +#define tx_timer_create(t,n,e,i,c,r,a) _txe_timer_create_ptr((t),(n),(e),(i),(c),(r),(a),(sizeof(TX_TIMER))) +#else #define tx_timer_create(t,n,e,i,c,r,a) _txe_timer_create((t),(n),(e),(i),(c),(r),(a),(sizeof(TX_TIMER))) +#endif #define tx_timer_deactivate _txe_timer_deactivate #define tx_timer_delete _txe_timer_delete #define tx_timer_info_get _txe_timer_info_get @@ -1704,6 +1738,11 @@ UINT _tx_thread_create(TX_THREAD *thread_ptr, TX_NAME_CONST CHAR *name_pt VOID *stack_start, ULONG stack_size, UINT priority, UINT preempt_threshold, ULONG time_slice, UINT auto_start); +UINT _tx_thread_create_ptr(TX_THREAD *thread_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*entry_function)(VOID *entry_input), VOID *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); @@ -1741,6 +1780,11 @@ UINT _txe_thread_create(TX_THREAD *thread_ptr, TX_NAME_CONST CHAR *name_p VOID *stack_start, ULONG stack_size, UINT priority, UINT preempt_threshold, ULONG time_slice, UINT auto_start, UINT thread_control_block_size); +UINT _txe_thread_create_ptr(TX_THREAD *thread_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*entry_function)(VOID *entry_input), VOID *entry_input, + VOID *stack_start, ULONG stack_size, + UINT priority, UINT preempt_threshold, + ULONG time_slice, UINT auto_start, UINT thread_control_block_size); UINT _txe_thread_delete(TX_THREAD *thread_ptr); UINT _txe_thread_entry_exit_notify(TX_THREAD *thread_ptr, VOID (*thread_entry_exit_notify)(TX_THREAD *notify_thread_ptr, UINT type)); UINT _txe_thread_info_get(TX_THREAD *thread_ptr, TX_NAME_CONST CHAR **name, UINT *state, ULONG *run_count, @@ -1788,6 +1832,9 @@ UINT _tx_timer_change(TX_TIMER *timer_ptr, ULONG initial_ticks, ULONG res UINT _tx_timer_create(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, VOID (*expiration_function)(ULONG input), ULONG expiration_input, ULONG initial_ticks, ULONG reschedule_ticks, UINT auto_activate); +UINT _tx_timer_create_ptr(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*expiration_function)(VOID *input), VOID *expiration_input, + ULONG initial_ticks, ULONG reschedule_ticks, UINT auto_activate); UINT _tx_timer_deactivate(TX_TIMER *timer_ptr); UINT _tx_timer_delete(TX_TIMER *timer_ptr); UINT _tx_timer_info_get(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR **name, UINT *active, ULONG *remaining_ticks, @@ -1809,6 +1856,9 @@ UINT _txe_timer_change(TX_TIMER *timer_ptr, ULONG initial_ticks, ULONG re UINT _txe_timer_create(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, VOID (*expiration_function)(ULONG input), ULONG expiration_input, ULONG initial_ticks, ULONG reschedule_ticks, UINT auto_activate, UINT timer_control_block_size); +UINT _txe_timer_create_ptr(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*expiration_function)(VOID *input), VOID *expiration_input, + ULONG initial_ticks, ULONG reschedule_ticks, UINT auto_activate, UINT timer_control_block_size); UINT _txe_timer_deactivate(TX_TIMER *timer_ptr); UINT _txe_timer_delete(TX_TIMER *timer_ptr); UINT _txe_timer_info_get(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR **name, UINT *active, ULONG *remaining_ticks, diff --git a/common/src/tx_thread_create.c b/common/src/tx_thread_create.c index 256e2f17b..fe6a0cb2b 100644 --- a/common/src/tx_thread_create.c +++ b/common/src/tx_thread_create.c @@ -77,10 +77,18 @@ /* Application Code */ /* _tx_timer_initialize Create system timer thread */ /* */ +static UINT _tx_thread_create_initial(TX_THREAD *thread_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*entry_function)(ULONG id), ULONG entry_input, + VOID (*entry_function_ptr)(VOID *id), VOID *entry_input_ptr, + VOID *stack_start, ULONG stack_size, UINT priority, UINT preempt_threshold, + ULONG time_slice, UINT auto_start); + /**************************************************************************/ -UINT _tx_thread_create(TX_THREAD *thread_ptr, TX_NAME_CONST CHAR *name_ptr, VOID (*entry_function)(ULONG id), ULONG entry_input, - VOID *stack_start, ULONG stack_size, UINT priority, UINT preempt_threshold, - ULONG time_slice, UINT auto_start) +static UINT _tx_thread_create_initial(TX_THREAD *thread_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*entry_function)(ULONG id), ULONG entry_input, + VOID (*entry_function_ptr)(VOID *id), VOID *entry_input_ptr, + VOID *stack_start, ULONG stack_size, UINT priority, UINT preempt_threshold, + ULONG time_slice, UINT auto_start) { TX_INTERRUPT_SAVE_AREA @@ -164,9 +172,11 @@ ULONG stack_fill_value; #endif /* Place the supplied parameters into the thread's control block. */ - thread_ptr -> tx_thread_name = name_ptr; - thread_ptr -> tx_thread_entry = entry_function; - thread_ptr -> tx_thread_entry_parameter = entry_input; + thread_ptr -> tx_thread_name = name_ptr; + thread_ptr -> tx_thread_entry = entry_function; + thread_ptr -> tx_thread_entry_parameter = entry_input; + thread_ptr -> tx_thread_entry_ptr = entry_function_ptr; + thread_ptr -> tx_thread_entry_parameter_ptr = entry_input_ptr; thread_ptr -> tx_thread_stack_start = stack_start; thread_ptr -> tx_thread_stack_size = stack_size; thread_ptr -> tx_thread_priority = priority; @@ -384,3 +394,93 @@ ULONG stack_fill_value; return(TX_SUCCESS); } + +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _tx_thread_create PORTABLE C */ +/* 6.3.0 */ +/* AUTHOR */ +/* */ +/* William E. Lamie, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This function creates a thread with ULONG input parameter. */ +/* */ +/* INPUT */ +/* */ +/* thread_ptr Thread control block pointer */ +/* name Pointer to thread name string */ +/* entry_function Entry function of the thread */ +/* entry_input 32-bit input value to thread */ +/* stack_start Pointer to start of stack */ +/* stack_size Stack size in bytes */ +/* priority Priority of thread */ +/* preempt_threshold Preemption threshold */ +/* time_slice Thread time-slice value */ +/* auto_start Automatic start selection */ +/* */ +/* OUTPUT */ +/* */ +/* return status Thread create return status */ +/* */ +/**************************************************************************/ +UINT _tx_thread_create(TX_THREAD *thread_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*entry_function)(ULONG id), ULONG entry_input, + VOID *stack_start, ULONG stack_size, UINT priority, UINT preempt_threshold, + ULONG time_slice, UINT auto_start) +{ + return(_tx_thread_create_initial(thread_ptr, name_ptr, + entry_function, entry_input, + TX_NULL, TX_NULL, + stack_start, stack_size, priority, preempt_threshold, + time_slice, auto_start)); +} + + +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _tx_thread_create_ptr PORTABLE C */ +/* 6.3.0 */ +/* AUTHOR */ +/* */ +/* William E. Lamie, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This function creates a thread with pointer context input. */ +/* */ +/* INPUT */ +/* */ +/* thread_ptr Thread control block pointer */ +/* name Pointer to thread name string */ +/* entry_function Entry function of the thread */ +/* entry_input Pointer input value to thread */ +/* stack_start Pointer to start of stack */ +/* stack_size Stack size in bytes */ +/* priority Priority of thread */ +/* preempt_threshold Preemption threshold */ +/* time_slice Thread time-slice value */ +/* auto_start Automatic start selection */ +/* */ +/* OUTPUT */ +/* */ +/* return status Thread create return status */ +/* */ +/**************************************************************************/ +UINT _tx_thread_create_ptr(TX_THREAD *thread_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*entry_function)(VOID *id), VOID *entry_input, + VOID *stack_start, ULONG stack_size, UINT priority, UINT preempt_threshold, + ULONG time_slice, UINT auto_start) +{ + return(_tx_thread_create_initial(thread_ptr, name_ptr, + TX_NULL, 0, + entry_function, entry_input, + stack_start, stack_size, priority, preempt_threshold, + time_slice, auto_start)); +} + diff --git a/common/src/tx_thread_shell_entry.c b/common/src/tx_thread_shell_entry.c index 2a16a00b6..93fa61316 100644 --- a/common/src/tx_thread_shell_entry.c +++ b/common/src/tx_thread_shell_entry.c @@ -105,7 +105,16 @@ VOID (*entry_exit_notify)(TX_THREAD *notify_thread_ptr, UINT type); #endif /* Call current thread's entry function. */ - (thread_ptr -> tx_thread_entry) (thread_ptr -> tx_thread_entry_parameter); + if (thread_ptr -> tx_thread_entry_ptr != TX_NULL) + { + + (thread_ptr -> tx_thread_entry_ptr)(thread_ptr -> tx_thread_entry_parameter_ptr); + } + else + { + + (thread_ptr -> tx_thread_entry)(thread_ptr -> tx_thread_entry_parameter); + } /* Suspend thread with a "completed" state. */ diff --git a/common/src/tx_timer_create.c b/common/src/tx_timer_create.c index 15eb866f7..b5a02bc5b 100644 --- a/common/src/tx_timer_create.c +++ b/common/src/tx_timer_create.c @@ -68,10 +68,16 @@ /* */ /* Application Code */ /* */ +static UINT _tx_timer_create_initial(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*expiration_function)(ULONG id), ULONG expiration_input, + VOID (*expiration_function_ptr)(VOID *id), VOID *expiration_input_ptr, + ULONG initial_ticks, ULONG reschedule_ticks, UINT auto_activate); + /**************************************************************************/ -UINT _tx_timer_create(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, - VOID (*expiration_function)(ULONG id), ULONG expiration_input, - ULONG initial_ticks, ULONG reschedule_ticks, UINT auto_activate) +static UINT _tx_timer_create_initial(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*expiration_function)(ULONG id), ULONG expiration_input, + VOID (*expiration_function_ptr)(VOID *id), VOID *expiration_input_ptr, + ULONG initial_ticks, ULONG reschedule_ticks, UINT auto_activate) { TX_INTERRUPT_SAVE_AREA @@ -89,6 +95,8 @@ TX_TIMER *previous_timer; timer_ptr -> tx_timer_internal.tx_timer_internal_re_initialize_ticks = reschedule_ticks; timer_ptr -> tx_timer_internal.tx_timer_internal_timeout_function = expiration_function; timer_ptr -> tx_timer_internal.tx_timer_internal_timeout_param = expiration_input; + timer_ptr -> tx_timer_internal.tx_timer_internal_timeout_function_ptr = expiration_function_ptr; + timer_ptr -> tx_timer_internal.tx_timer_internal_timeout_param_ptr = expiration_input_ptr; /* Disable interrupts to put the timer on the created list. */ TX_DISABLE @@ -161,3 +169,83 @@ TX_TIMER *previous_timer; return(TX_SUCCESS); } + +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _tx_timer_create PORTABLE C */ +/* 6.1 */ +/* AUTHOR */ +/* */ +/* William E. Lamie, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This function creates an application timer with ULONG input. */ +/* */ +/* INPUT */ +/* */ +/* timer_ptr Pointer to timer control blk */ +/* name_ptr Pointer to timer name */ +/* expiration_function Function to call on expiration*/ +/* expiration_input 32-bit input value for timer */ +/* initial_ticks Initial expiration ticks */ +/* reschedule_ticks Reschedule ticks */ +/* auto_activate Automatic activation flag */ +/* */ +/* OUTPUT */ +/* */ +/* TX_SUCCESS Successful completion status */ +/* */ +/**************************************************************************/ +UINT _tx_timer_create(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*expiration_function)(ULONG id), ULONG expiration_input, + ULONG initial_ticks, ULONG reschedule_ticks, UINT auto_activate) +{ + return(_tx_timer_create_initial(timer_ptr, name_ptr, + expiration_function, expiration_input, + TX_NULL, TX_NULL, + initial_ticks, reschedule_ticks, auto_activate)); +} + + +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _tx_timer_create_ptr PORTABLE C */ +/* 6.1 */ +/* AUTHOR */ +/* */ +/* William E. Lamie, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This function creates an application timer with pointer context. */ +/* */ +/* INPUT */ +/* */ +/* timer_ptr Pointer to timer control blk */ +/* name_ptr Pointer to timer name */ +/* expiration_function Function to call on expiration*/ +/* expiration_input Pointer input value for timer */ +/* initial_ticks Initial expiration ticks */ +/* reschedule_ticks Reschedule ticks */ +/* auto_activate Automatic activation flag */ +/* */ +/* OUTPUT */ +/* */ +/* TX_SUCCESS Successful completion status */ +/* */ +/**************************************************************************/ +UINT _tx_timer_create_ptr(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*expiration_function)(VOID *id), VOID *expiration_input, + ULONG initial_ticks, ULONG reschedule_ticks, UINT auto_activate) +{ + return(_tx_timer_create_initial(timer_ptr, name_ptr, + TX_NULL, 0, + expiration_function, expiration_input, + initial_ticks, reschedule_ticks, auto_activate)); +} + diff --git a/common/src/tx_timer_expiration_process.c b/common/src/tx_timer_expiration_process.c index 33923a937..2b1ae46c3 100644 --- a/common/src/tx_timer_expiration_process.c +++ b/common/src/tx_timer_expiration_process.c @@ -88,6 +88,8 @@ ULONG delta; TX_TIMER_INTERNAL *current_timer; VOID (*timeout_function)(ULONG id); ULONG timeout_param = ((ULONG) 0); +VOID (*timeout_function_ptr)(VOID *id); +VOID *timeout_param_ptr = TX_NULL; #ifdef TX_TIMER_ENABLE_PERFORMANCE_INFO TX_TIMER *timer_ptr; #endif @@ -264,7 +266,8 @@ TX_TIMER *timer_ptr; /* Set the timeout function to NULL in order to bypass the expiration. */ - timeout_function = TX_NULL; + timeout_function = TX_NULL; + timeout_function_ptr = TX_NULL; /* Make the timer appear that it is still active while interrupts are enabled. This will permit proper processing of a timer @@ -305,8 +308,10 @@ TX_TIMER *timer_ptr; /* Copy the calling function and ID into local variables before interrupts are re-enabled. */ - timeout_function = current_timer -> tx_timer_internal_timeout_function; - timeout_param = current_timer -> tx_timer_internal_timeout_param; + timeout_function = current_timer -> tx_timer_internal_timeout_function; + timeout_param = current_timer -> tx_timer_internal_timeout_param; + timeout_function_ptr = current_timer -> tx_timer_internal_timeout_function_ptr; + timeout_param_ptr = current_timer -> tx_timer_internal_timeout_param_ptr; /* Copy the reinitialize ticks into the remaining ticks. */ current_timer -> tx_timer_internal_remaining_ticks = current_timer -> tx_timer_internal_re_initialize_ticks; @@ -341,7 +346,12 @@ TX_TIMER *timer_ptr; TX_RESTORE /* Call the timer-expiration function, if non-NULL. */ - if (timeout_function != TX_NULL) + if (timeout_function_ptr != TX_NULL) + { + + (timeout_function_ptr) (timeout_param_ptr); + } + else if (timeout_function != TX_NULL) { (timeout_function) (timeout_param); @@ -362,7 +372,7 @@ TX_TIMER *timer_ptr; #ifdef TX_TIMER_ENABLE_PERFORMANCE_INFO /* Determine if this timer expired. */ - if (timeout_function != TX_NULL) + if ((timeout_function != TX_NULL) || (timeout_function_ptr != TX_NULL)) { /* Increment the total reactivations counter. */ diff --git a/common/src/tx_timer_thread_entry.c b/common/src/tx_timer_thread_entry.c index 971a0703f..82f7c397b 100644 --- a/common/src/tx_timer_thread_entry.c +++ b/common/src/tx_timer_thread_entry.c @@ -78,6 +78,8 @@ TX_TIMER_INTERNAL *previous_timer; TX_TIMER_INTERNAL *current_timer; VOID (*timeout_function)(ULONG id); ULONG timeout_param = ((ULONG) 0); +VOID (*timeout_function_ptr)(VOID *id); +VOID *timeout_param_ptr = TX_NULL; TX_THREAD *thread_ptr; #ifdef TX_REACTIVATE_INLINE TX_TIMER_INTERNAL **timer_list; /* Timer list pointer */ @@ -216,7 +218,8 @@ TX_TIMER *timer_ptr; /* Set the timeout function to NULL in order to bypass the expiration. */ - timeout_function = TX_NULL; + timeout_function = TX_NULL; + timeout_function_ptr = TX_NULL; /* Make the timer appear that it is still active while interrupts are enabled. This will permit proper processing of a timer @@ -257,8 +260,10 @@ TX_TIMER *timer_ptr; /* Copy the calling function and ID into local variables before interrupts are re-enabled. */ - timeout_function = current_timer -> tx_timer_internal_timeout_function; - timeout_param = current_timer -> tx_timer_internal_timeout_param; + timeout_function = current_timer -> tx_timer_internal_timeout_function; + timeout_param = current_timer -> tx_timer_internal_timeout_param; + timeout_function_ptr = current_timer -> tx_timer_internal_timeout_function_ptr; + timeout_param_ptr = current_timer -> tx_timer_internal_timeout_param_ptr; /* Copy the reinitialize ticks into the remaining ticks. */ current_timer -> tx_timer_internal_remaining_ticks = current_timer -> tx_timer_internal_re_initialize_ticks; @@ -293,7 +298,12 @@ TX_TIMER *timer_ptr; TX_RESTORE /* Call the timer-expiration function, if non-NULL. */ - if (timeout_function != TX_NULL) + if (timeout_function_ptr != TX_NULL) + { + + (timeout_function_ptr) (timeout_param_ptr); + } + else if (timeout_function != TX_NULL) { (timeout_function) (timeout_param); @@ -314,7 +324,7 @@ TX_TIMER *timer_ptr; #ifdef TX_TIMER_ENABLE_PERFORMANCE_INFO /* Determine if this timer expired. */ - if (timeout_function != TX_NULL) + if ((timeout_function != TX_NULL) || (timeout_function_ptr != TX_NULL)) { /* Increment the total reactivations counter. */ diff --git a/common/src/txe_thread_create.c b/common/src/txe_thread_create.c index cc5033b29..8b2ac00c0 100644 --- a/common/src/txe_thread_create.c +++ b/common/src/txe_thread_create.c @@ -80,9 +80,17 @@ /* */ /* Application Code */ /* */ +static UINT _txe_thread_create_initial(TX_THREAD *thread_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*entry_function)(ULONG id), ULONG entry_input, + VOID (*entry_function_ptr)(VOID *id), VOID *entry_input_ptr, + VOID *stack_start, ULONG stack_size, + UINT priority, UINT preempt_threshold, + ULONG time_slice, UINT auto_start, UINT thread_control_block_size); + /**************************************************************************/ -UINT _txe_thread_create(TX_THREAD *thread_ptr, TX_NAME_CONST CHAR *name_ptr, +static UINT _txe_thread_create_initial(TX_THREAD *thread_ptr, TX_NAME_CONST CHAR *name_ptr, VOID (*entry_function)(ULONG id), ULONG entry_input, + VOID (*entry_function_ptr)(VOID *id), VOID *entry_input_ptr, VOID *stack_start, ULONG stack_size, UINT priority, UINT preempt_threshold, ULONG time_slice, UINT auto_start, UINT thread_control_block_size) @@ -221,7 +229,7 @@ TX_THREAD *current_thread; } /* Check for invalid thread entry point. */ - else if (entry_function == TX_NULL) + else if ((entry_function == TX_NULL) && (entry_function_ptr == TX_NULL)) { /* Invalid stack or entry point, return appropriate error code. */ @@ -296,12 +304,135 @@ TX_THREAD *current_thread; { /* Call actual thread create function. */ - status = _tx_thread_create(thread_ptr, name_ptr, entry_function, entry_input, - stack_start, stack_size, priority, preempt_threshold, - time_slice, auto_start); + if (entry_function_ptr != TX_NULL) + { + status = _tx_thread_create_ptr(thread_ptr, name_ptr, + entry_function_ptr, entry_input_ptr, + stack_start, stack_size, priority, preempt_threshold, + time_slice, auto_start); + } + else + { + status = _tx_thread_create(thread_ptr, name_ptr, + entry_function, entry_input, + stack_start, stack_size, priority, preempt_threshold, + time_slice, auto_start); + } } /* Return completion status. */ return(status); } + +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _txe_thread_create PORTABLE C */ +/* 6.3.0 */ +/* AUTHOR */ +/* */ +/* William E. Lamie, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This function checks for errors in the thread create function call. */ +/* */ +/* INPUT */ +/* */ +/* thread_ptr Thread control block pointer */ +/* name_ptr Pointer to thread name string */ +/* entry_function Entry function of the thread */ +/* entry_input 32-bit input value to thread */ +/* stack_start Pointer to start of stack */ +/* stack_size Stack size in bytes */ +/* priority Priority of thread (0-31) */ +/* preempt_threshold Preemption threshold */ +/* time_slice Thread time-slice value */ +/* auto_start Automatic start selection */ +/* thread_control_block_size Size of thread control block */ +/* */ +/* OUTPUT */ +/* */ +/* TX_THREAD_ERROR Invalid thread pointer */ +/* TX_PTR_ERROR Invalid stack or function ptr */ +/* TX_SIZE_ERROR Invalid stack size */ +/* TX_PRIORITY_ERROR Invalid thread priority */ +/* TX_THRESH_ERROR Invalid preemption threshold */ +/* TX_START_ERROR Invalid start selection */ +/* TX_CALLER_ERROR Invalid caller of function */ +/* status Actual completion status */ +/* */ +/**************************************************************************/ +UINT _txe_thread_create(TX_THREAD *thread_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*entry_function)(ULONG id), ULONG entry_input, + VOID *stack_start, ULONG stack_size, + UINT priority, UINT preempt_threshold, + ULONG time_slice, UINT auto_start, UINT thread_control_block_size) +{ + return(_txe_thread_create_initial(thread_ptr, name_ptr, + entry_function, entry_input, + TX_NULL, TX_NULL, + stack_start, stack_size, + priority, preempt_threshold, + time_slice, auto_start, + thread_control_block_size)); +} + + +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _txe_thread_create_ptr PORTABLE C */ +/* 6.3.0 */ +/* AUTHOR */ +/* */ +/* William E. Lamie, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This function checks for errors in pointer context thread create. */ +/* */ +/* INPUT */ +/* */ +/* thread_ptr Thread control block pointer */ +/* name_ptr Pointer to thread name string */ +/* entry_function Entry function of the thread */ +/* entry_input Pointer input value to thread */ +/* stack_start Pointer to start of stack */ +/* stack_size Stack size in bytes */ +/* priority Priority of thread */ +/* preempt_threshold Preemption threshold */ +/* time_slice Thread time-slice value */ +/* auto_start Automatic start selection */ +/* thread_control_block_size Size of thread control block */ +/* */ +/* OUTPUT */ +/* */ +/* TX_THREAD_ERROR Invalid thread pointer */ +/* TX_PTR_ERROR Invalid stack or function ptr */ +/* TX_SIZE_ERROR Invalid stack size */ +/* TX_PRIORITY_ERROR Invalid thread priority */ +/* TX_THRESH_ERROR Invalid preemption threshold */ +/* TX_START_ERROR Invalid start selection */ +/* TX_CALLER_ERROR Invalid caller of function */ +/* status Actual completion status */ +/* */ +/**************************************************************************/ +UINT _txe_thread_create_ptr(TX_THREAD *thread_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*entry_function)(VOID *id), VOID *entry_input, + VOID *stack_start, ULONG stack_size, + UINT priority, UINT preempt_threshold, + ULONG time_slice, UINT auto_start, UINT thread_control_block_size) +{ + return(_txe_thread_create_initial(thread_ptr, name_ptr, + TX_NULL, 0, + entry_function, entry_input, + stack_start, stack_size, + priority, preempt_threshold, + time_slice, auto_start, + thread_control_block_size)); +} + diff --git a/common/src/txe_timer_create.c b/common/src/txe_timer_create.c index 8c481bde8..9e911e2ee 100644 --- a/common/src/txe_timer_create.c +++ b/common/src/txe_timer_create.c @@ -75,10 +75,16 @@ /* */ /* Application Code */ /* */ +static UINT _txe_timer_create_initial(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*expiration_function)(ULONG id), ULONG expiration_input, + VOID (*expiration_function_ptr)(VOID *id), VOID *expiration_input_ptr, + ULONG initial_ticks, ULONG reschedule_ticks, UINT auto_activate, UINT timer_control_block_size); + /**************************************************************************/ -UINT _txe_timer_create(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, - VOID (*expiration_function)(ULONG id), ULONG expiration_input, - ULONG initial_ticks, ULONG reschedule_ticks, UINT auto_activate, UINT timer_control_block_size) +static UINT _txe_timer_create_initial(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*expiration_function)(ULONG id), ULONG expiration_input, + VOID (*expiration_function_ptr)(VOID *id), VOID *expiration_input_ptr, + ULONG initial_ticks, ULONG reschedule_ticks, UINT auto_activate, UINT timer_control_block_size) { TX_INTERRUPT_SAVE_AREA @@ -223,11 +229,113 @@ TX_THREAD *thread_ptr; { /* Call actual application timer create function. */ - status = _tx_timer_create(timer_ptr, name_ptr, expiration_function, expiration_input, - initial_ticks, reschedule_ticks, auto_activate); + if (expiration_function_ptr != TX_NULL) + { + status = _tx_timer_create_ptr(timer_ptr, name_ptr, + expiration_function_ptr, expiration_input_ptr, + initial_ticks, reschedule_ticks, auto_activate); + } + else + { + status = _tx_timer_create(timer_ptr, name_ptr, + expiration_function, expiration_input, + initial_ticks, reschedule_ticks, auto_activate); + } } /* Return completion status. */ return(status); } + +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _txe_timer_create PORTABLE C */ +/* 6.1 */ +/* AUTHOR */ +/* */ +/* William E. Lamie, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This function checks for errors in timer create with ULONG input. */ +/* */ +/* INPUT */ +/* */ +/* timer_ptr Pointer to timer control blk */ +/* name_ptr Pointer to timer name */ +/* expiration_function Function to call on expiration*/ +/* expiration_input 32-bit input value for timer */ +/* initial_ticks Initial expiration ticks */ +/* reschedule_ticks Reschedule ticks */ +/* auto_activate Automatic activation flag */ +/* timer_control_block_size Size of timer control block */ +/* */ +/* OUTPUT */ +/* */ +/* TX_TIMER_ERROR Invalid timer pointer */ +/* TX_TICK_ERROR Invalid initial ticks */ +/* TX_ACTIVATE_ERROR Invalid auto-activate option */ +/* TX_CALLER_ERROR Invalid caller of function */ +/* status Actual completion status */ +/* */ +/**************************************************************************/ +UINT _txe_timer_create(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*expiration_function)(ULONG id), ULONG expiration_input, + ULONG initial_ticks, ULONG reschedule_ticks, UINT auto_activate, UINT timer_control_block_size) +{ + return(_txe_timer_create_initial(timer_ptr, name_ptr, + expiration_function, expiration_input, + TX_NULL, TX_NULL, + initial_ticks, reschedule_ticks, auto_activate, + timer_control_block_size)); +} + + +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _txe_timer_create_ptr PORTABLE C */ +/* 6.1 */ +/* AUTHOR */ +/* */ +/* William E. Lamie, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This function checks for errors in timer create with pointer input. */ +/* */ +/* INPUT */ +/* */ +/* timer_ptr Pointer to timer control blk */ +/* name_ptr Pointer to timer name */ +/* expiration_function Function to call on expiration*/ +/* expiration_input Pointer input value for timer */ +/* initial_ticks Initial expiration ticks */ +/* reschedule_ticks Reschedule ticks */ +/* auto_activate Automatic activation flag */ +/* timer_control_block_size Size of timer control block */ +/* */ +/* OUTPUT */ +/* */ +/* TX_TIMER_ERROR Invalid timer pointer */ +/* TX_TICK_ERROR Invalid initial ticks */ +/* TX_ACTIVATE_ERROR Invalid auto-activate option */ +/* TX_CALLER_ERROR Invalid caller of function */ +/* status Actual completion status */ +/* */ +/**************************************************************************/ +UINT _txe_timer_create_ptr(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*expiration_function)(VOID *id), VOID *expiration_input, + ULONG initial_ticks, ULONG reschedule_ticks, UINT auto_activate, UINT timer_control_block_size) +{ + return(_txe_timer_create_initial(timer_ptr, name_ptr, + TX_NULL, 0, + expiration_function, expiration_input, + initial_ticks, reschedule_ticks, auto_activate, + timer_control_block_size)); +} + diff --git a/common_smp/inc/tx_api.h b/common_smp/inc/tx_api.h index 77bd6218b..3774b7a3f 100644 --- a/common_smp/inc/tx_api.h +++ b/common_smp/inc/tx_api.h @@ -363,6 +363,8 @@ typedef struct TX_TIMER_INTERNAL_STRUCT /* Define the timeout function and timeout function parameter. */ VOID (*tx_timer_internal_timeout_function)(ULONG id); ULONG tx_timer_internal_timeout_param; + VOID (*tx_timer_internal_timeout_function_ptr)(VOID *id); + VOID *tx_timer_internal_timeout_param_ptr; /* Define the next and previous internal link pointers for active @@ -499,6 +501,8 @@ typedef struct TX_THREAD_STRUCT /* Define the thread's entry point and input parameter. */ VOID (*tx_thread_entry)(ULONG id); ULONG tx_thread_entry_parameter; + VOID (*tx_thread_entry_ptr)(VOID *id); + VOID *tx_thread_entry_parameter_ptr; /* Define the thread's timer block. This is used for thread sleep and timeout requests. */ @@ -1236,7 +1240,12 @@ UINT _tx_el_interrupt_control(UINT new_posture); #define tx_semaphore_put _tx_semaphore_put #define tx_semaphore_put_notify _tx_semaphore_put_notify +#define tx_thread_create_ptr _tx_thread_create_ptr +#ifdef TX_ENABLE_POINTER_CALLBACKS +#define tx_thread_create _tx_thread_create_ptr +#else #define tx_thread_create _tx_thread_create +#endif #define tx_thread_delete _tx_thread_delete #define tx_thread_entry_exit_notify _tx_thread_entry_exit_notify #define tx_thread_identify _tx_thread_identify @@ -1265,7 +1274,12 @@ UINT _tx_el_interrupt_control(UINT new_posture); #define tx_time_set _tx_time_set #define tx_timer_activate _tx_timer_activate #define tx_timer_change _tx_timer_change +#define tx_timer_create_ptr _tx_timer_create_ptr +#ifdef TX_ENABLE_POINTER_CALLBACKS +#define tx_timer_create _tx_timer_create_ptr +#else #define tx_timer_create _tx_timer_create +#endif #define tx_timer_deactivate _tx_timer_deactivate #define tx_timer_delete _tx_timer_delete #define tx_timer_info_get _tx_timer_info_get @@ -1364,7 +1378,12 @@ UINT _tx_el_interrupt_control(UINT new_posture); #define tx_semaphore_put _txr_semaphore_put #define tx_semaphore_put_notify _txr_semaphore_put_notify +#define tx_thread_create_ptr(t,n,e,i,s,l,p,r,c,a) _txe_thread_create_ptr((t),(n),(e),(i),(s),(l),(p),(r),(c),(a),(sizeof(TX_THREAD))) +#ifdef TX_ENABLE_POINTER_CALLBACKS +#define tx_thread_create(t,n,e,i,s,l,p,r,c,a) _txe_thread_create_ptr((t),(n),(e),(i),(s),(l),(p),(r),(c),(a),(sizeof(TX_THREAD))) +#else #define tx_thread_create(t,n,e,i,s,l,p,r,c,a) _txr_thread_create((t),(n),(e),(i),(s),(l),(p),(r),(c),(a),(sizeof(TX_THREAD))) +#endif #define tx_thread_delete _txr_thread_delete #define tx_thread_entry_exit_notify _txr_thread_entry_exit_notify #define tx_thread_identify _tx_thread_identify @@ -1393,7 +1412,12 @@ UINT _tx_el_interrupt_control(UINT new_posture); #define tx_time_set _tx_time_set #define tx_timer_activate _txr_timer_activate #define tx_timer_change _txr_timer_change +#define tx_timer_create_ptr(t,n,e,i,c,r,a) _txe_timer_create_ptr((t),(n),(e),(i),(c),(r),(a),(sizeof(TX_TIMER))) +#ifdef TX_ENABLE_POINTER_CALLBACKS +#define tx_timer_create(t,n,e,i,c,r,a) _txe_timer_create_ptr((t),(n),(e),(i),(c),(r),(a),(sizeof(TX_TIMER))) +#else #define tx_timer_create(t,n,e,i,c,r,a) _txr_timer_create((t),(n),(e),(i),(c),(r),(a),(sizeof(TX_TIMER))) +#endif #define tx_timer_deactivate _txr_timer_deactivate #define tx_timer_delete _txr_timer_delete #define tx_timer_info_get _txr_timer_info_get @@ -1481,7 +1505,12 @@ UINT _tx_el_interrupt_control(UINT new_posture); #define tx_semaphore_put _txe_semaphore_put #define tx_semaphore_put_notify _txe_semaphore_put_notify +#define tx_thread_create_ptr(t,n,e,i,s,l,p,r,c,a) _txe_thread_create_ptr((t),(n),(e),(i),(s),(l),(p),(r),(c),(a),(sizeof(TX_THREAD))) +#ifdef TX_ENABLE_POINTER_CALLBACKS +#define tx_thread_create(t,n,e,i,s,l,p,r,c,a) _txe_thread_create_ptr((t),(n),(e),(i),(s),(l),(p),(r),(c),(a),(sizeof(TX_THREAD))) +#else #define tx_thread_create(t,n,e,i,s,l,p,r,c,a) _txe_thread_create((t),(n),(e),(i),(s),(l),(p),(r),(c),(a),(sizeof(TX_THREAD))) +#endif #define tx_thread_delete _txe_thread_delete #define tx_thread_entry_exit_notify _txe_thread_entry_exit_notify #define tx_thread_identify _tx_thread_identify @@ -1510,7 +1539,12 @@ UINT _tx_el_interrupt_control(UINT new_posture); #define tx_time_set _tx_time_set #define tx_timer_activate _txe_timer_activate #define tx_timer_change _txe_timer_change +#define tx_timer_create_ptr(t,n,e,i,c,r,a) _txe_timer_create_ptr((t),(n),(e),(i),(c),(r),(a),(sizeof(TX_TIMER))) +#ifdef TX_ENABLE_POINTER_CALLBACKS +#define tx_timer_create(t,n,e,i,c,r,a) _txe_timer_create_ptr((t),(n),(e),(i),(c),(r),(a),(sizeof(TX_TIMER))) +#else #define tx_timer_create(t,n,e,i,c,r,a) _txe_timer_create((t),(n),(e),(i),(c),(r),(a),(sizeof(TX_TIMER))) +#endif #define tx_timer_deactivate _txe_timer_deactivate #define tx_timer_delete _txe_timer_delete #define tx_timer_info_get _txe_timer_info_get @@ -1747,6 +1781,11 @@ UINT _tx_thread_create(TX_THREAD *thread_ptr, TX_NAME_CONST CHAR *name_pt VOID *stack_start, ULONG stack_size, UINT priority, UINT preempt_threshold, ULONG time_slice, UINT auto_start); +UINT _tx_thread_create_ptr(TX_THREAD *thread_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*entry_function)(VOID *entry_input), VOID *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); @@ -1784,6 +1823,11 @@ UINT _txe_thread_create(TX_THREAD *thread_ptr, TX_NAME_CONST CHAR *name_p VOID *stack_start, ULONG stack_size, UINT priority, UINT preempt_threshold, ULONG time_slice, UINT auto_start, UINT thread_control_block_size); +UINT _txe_thread_create_ptr(TX_THREAD *thread_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*entry_function)(VOID *entry_input), VOID *entry_input, + VOID *stack_start, ULONG stack_size, + UINT priority, UINT preempt_threshold, + ULONG time_slice, UINT auto_start, UINT thread_control_block_size); UINT _txe_thread_delete(TX_THREAD *thread_ptr); UINT _txe_thread_entry_exit_notify(TX_THREAD *thread_ptr, VOID (*thread_entry_exit_notify)(TX_THREAD *notify_thread_ptr, UINT type)); UINT _txe_thread_info_get(TX_THREAD *thread_ptr, TX_NAME_CONST CHAR **name, UINT *state, ULONG *run_count, @@ -1809,6 +1853,9 @@ UINT _tx_timer_change(TX_TIMER *timer_ptr, ULONG initial_ticks, ULONG res UINT _tx_timer_create(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, VOID (*expiration_function)(ULONG input), ULONG expiration_input, ULONG initial_ticks, ULONG reschedule_ticks, UINT auto_activate); +UINT _tx_timer_create_ptr(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*expiration_function)(VOID *input), VOID *expiration_input, + ULONG initial_ticks, ULONG reschedule_ticks, UINT auto_activate); UINT _tx_timer_deactivate(TX_TIMER *timer_ptr); UINT _tx_timer_delete(TX_TIMER *timer_ptr); UINT _tx_timer_info_get(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR **name, UINT *active, ULONG *remaining_ticks, @@ -1830,6 +1877,9 @@ UINT _txe_timer_change(TX_TIMER *timer_ptr, ULONG initial_ticks, ULONG re UINT _txe_timer_create(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, VOID (*expiration_function)(ULONG input), ULONG expiration_input, ULONG initial_ticks, ULONG reschedule_ticks, UINT auto_activate, UINT timer_control_block_size); +UINT _txe_timer_create_ptr(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*expiration_function)(VOID *input), VOID *expiration_input, + ULONG initial_ticks, ULONG reschedule_ticks, UINT auto_activate, UINT timer_control_block_size); UINT _txe_timer_deactivate(TX_TIMER *timer_ptr); UINT _txe_timer_delete(TX_TIMER *timer_ptr); UINT _txe_timer_info_get(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR **name, UINT *active, ULONG *remaining_ticks, diff --git a/common_smp/src/tx_thread_create.c b/common_smp/src/tx_thread_create.c index 3b158f475..a4eb9e31b 100644 --- a/common_smp/src/tx_thread_create.c +++ b/common_smp/src/tx_thread_create.c @@ -78,11 +78,18 @@ /* Application Code */ /* _tx_timer_initialize Create system timer thread */ /* */ +static UINT _tx_thread_create_initial(TX_THREAD *thread_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*entry_function)(ULONG id), ULONG entry_input, + VOID (*entry_function_ptr)(VOID *id), VOID *entry_input_ptr, + VOID *stack_start, ULONG stack_size, UINT priority, UINT preempt_threshold, + ULONG time_slice, UINT auto_start); + /**************************************************************************/ -UINT _tx_thread_create(TX_THREAD *thread_ptr, TX_NAME_CONST CHAR *name_ptr, - VOID (*entry_function)(ULONG id), ULONG entry_input, - VOID *stack_start, ULONG stack_size, UINT priority, UINT preempt_threshold, - ULONG time_slice, UINT auto_start) +static UINT _tx_thread_create_initial(TX_THREAD *thread_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*entry_function)(ULONG id), ULONG entry_input, + VOID (*entry_function_ptr)(VOID *id), VOID *entry_input_ptr, + VOID *stack_start, ULONG stack_size, UINT priority, UINT preempt_threshold, + ULONG time_slice, UINT auto_start) { TX_INTERRUPT_SAVE_AREA @@ -165,6 +172,8 @@ ULONG stack_fill_value; thread_ptr -> tx_thread_name = name_ptr; thread_ptr -> tx_thread_entry = entry_function; thread_ptr -> tx_thread_entry_parameter = entry_input; + thread_ptr -> tx_thread_entry_ptr = entry_function_ptr; + thread_ptr -> tx_thread_entry_parameter_ptr = entry_input_ptr; thread_ptr -> tx_thread_stack_start = stack_start; thread_ptr -> tx_thread_stack_size = stack_size; thread_ptr -> tx_thread_priority = priority; @@ -402,3 +411,93 @@ ULONG stack_fill_value; return(TX_SUCCESS); } + +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _tx_thread_create PORTABLE SMP */ +/* 6.3.0 */ +/* AUTHOR */ +/* */ +/* William E. Lamie, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This function creates a thread with ULONG input parameter. */ +/* */ +/* INPUT */ +/* */ +/* thread_ptr Thread control block pointer */ +/* name Pointer to thread name string */ +/* entry_function Entry function of the thread */ +/* entry_input 32-bit input value to thread */ +/* stack_start Pointer to start of stack */ +/* stack_size Stack size in bytes */ +/* priority Priority of thread */ +/* preempt_threshold Preemption threshold */ +/* time_slice Thread time-slice value */ +/* auto_start Automatic start selection */ +/* */ +/* OUTPUT */ +/* */ +/* return status Thread create return status */ +/* */ +/**************************************************************************/ +UINT _tx_thread_create(TX_THREAD *thread_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*entry_function)(ULONG id), ULONG entry_input, + VOID *stack_start, ULONG stack_size, UINT priority, UINT preempt_threshold, + ULONG time_slice, UINT auto_start) +{ + return(_tx_thread_create_initial(thread_ptr, name_ptr, + entry_function, entry_input, + TX_NULL, TX_NULL, + stack_start, stack_size, priority, preempt_threshold, + time_slice, auto_start)); +} + + +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _tx_thread_create_ptr PORTABLE SMP */ +/* 6.3.0 */ +/* AUTHOR */ +/* */ +/* William E. Lamie, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This function creates a thread with pointer context input. */ +/* */ +/* INPUT */ +/* */ +/* thread_ptr Thread control block pointer */ +/* name Pointer to thread name string */ +/* entry_function Entry function of the thread */ +/* entry_input Pointer input value to thread */ +/* stack_start Pointer to start of stack */ +/* stack_size Stack size in bytes */ +/* priority Priority of thread */ +/* preempt_threshold Preemption threshold */ +/* time_slice Thread time-slice value */ +/* auto_start Automatic start selection */ +/* */ +/* OUTPUT */ +/* */ +/* return status Thread create return status */ +/* */ +/**************************************************************************/ +UINT _tx_thread_create_ptr(TX_THREAD *thread_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*entry_function)(VOID *id), VOID *entry_input, + VOID *stack_start, ULONG stack_size, UINT priority, UINT preempt_threshold, + ULONG time_slice, UINT auto_start) +{ + return(_tx_thread_create_initial(thread_ptr, name_ptr, + TX_NULL, 0, + entry_function, entry_input, + stack_start, stack_size, priority, preempt_threshold, + time_slice, auto_start)); +} + diff --git a/common_smp/src/tx_thread_shell_entry.c b/common_smp/src/tx_thread_shell_entry.c index 2a16a00b6..93fa61316 100644 --- a/common_smp/src/tx_thread_shell_entry.c +++ b/common_smp/src/tx_thread_shell_entry.c @@ -105,7 +105,16 @@ VOID (*entry_exit_notify)(TX_THREAD *notify_thread_ptr, UINT type); #endif /* Call current thread's entry function. */ - (thread_ptr -> tx_thread_entry) (thread_ptr -> tx_thread_entry_parameter); + if (thread_ptr -> tx_thread_entry_ptr != TX_NULL) + { + + (thread_ptr -> tx_thread_entry_ptr)(thread_ptr -> tx_thread_entry_parameter_ptr); + } + else + { + + (thread_ptr -> tx_thread_entry)(thread_ptr -> tx_thread_entry_parameter); + } /* Suspend thread with a "completed" state. */ diff --git a/common_smp/src/tx_timer_create.c b/common_smp/src/tx_timer_create.c index 81af4c9b7..0bf352de1 100644 --- a/common_smp/src/tx_timer_create.c +++ b/common_smp/src/tx_timer_create.c @@ -69,10 +69,16 @@ /* */ /* Application Code */ /* */ +static UINT _tx_timer_create_initial(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*expiration_function)(ULONG id), ULONG expiration_input, + VOID (*expiration_function_ptr)(VOID *id), VOID *expiration_input_ptr, + ULONG initial_ticks, ULONG reschedule_ticks, UINT auto_activate); + /**************************************************************************/ -UINT _tx_timer_create(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, - VOID (*expiration_function)(ULONG id), ULONG expiration_input, - ULONG initial_ticks, ULONG reschedule_ticks, UINT auto_activate) +static UINT _tx_timer_create_initial(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*expiration_function)(ULONG id), ULONG expiration_input, + VOID (*expiration_function_ptr)(VOID *id), VOID *expiration_input_ptr, + ULONG initial_ticks, ULONG reschedule_ticks, UINT auto_activate) { TX_INTERRUPT_SAVE_AREA @@ -90,6 +96,8 @@ TX_TIMER *previous_timer; timer_ptr -> tx_timer_internal.tx_timer_internal_re_initialize_ticks = reschedule_ticks; timer_ptr -> tx_timer_internal.tx_timer_internal_timeout_function = expiration_function; timer_ptr -> tx_timer_internal.tx_timer_internal_timeout_param = expiration_input; + timer_ptr -> tx_timer_internal.tx_timer_internal_timeout_function_ptr = expiration_function_ptr; + timer_ptr -> tx_timer_internal.tx_timer_internal_timeout_param_ptr = expiration_input_ptr; #ifdef TX_THREAD_SMP_ONLY_CORE_0_DEFAULT @@ -168,3 +176,83 @@ TX_TIMER *previous_timer; return(TX_SUCCESS); } + +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _tx_timer_create PORTABLE SMP */ +/* 6.1 */ +/* AUTHOR */ +/* */ +/* William E. Lamie, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This function creates an application timer with ULONG input. */ +/* */ +/* INPUT */ +/* */ +/* timer_ptr Pointer to timer control blk */ +/* name_ptr Pointer to timer name */ +/* expiration_function Function to call on expiration*/ +/* expiration_input 32-bit input value for timer */ +/* initial_ticks Initial expiration ticks */ +/* reschedule_ticks Reschedule ticks */ +/* auto_activate Automatic activation flag */ +/* */ +/* OUTPUT */ +/* */ +/* TX_SUCCESS Successful completion status */ +/* */ +/**************************************************************************/ +UINT _tx_timer_create(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*expiration_function)(ULONG id), ULONG expiration_input, + ULONG initial_ticks, ULONG reschedule_ticks, UINT auto_activate) +{ + return(_tx_timer_create_initial(timer_ptr, name_ptr, + expiration_function, expiration_input, + TX_NULL, TX_NULL, + initial_ticks, reschedule_ticks, auto_activate)); +} + + +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _tx_timer_create_ptr PORTABLE SMP */ +/* 6.1 */ +/* AUTHOR */ +/* */ +/* William E. Lamie, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This function creates an application timer with pointer context. */ +/* */ +/* INPUT */ +/* */ +/* timer_ptr Pointer to timer control blk */ +/* name_ptr Pointer to timer name */ +/* expiration_function Function to call on expiration*/ +/* expiration_input Pointer input value for timer */ +/* initial_ticks Initial expiration ticks */ +/* reschedule_ticks Reschedule ticks */ +/* auto_activate Automatic activation flag */ +/* */ +/* OUTPUT */ +/* */ +/* TX_SUCCESS Successful completion status */ +/* */ +/**************************************************************************/ +UINT _tx_timer_create_ptr(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*expiration_function)(VOID *id), VOID *expiration_input, + ULONG initial_ticks, ULONG reschedule_ticks, UINT auto_activate) +{ + return(_tx_timer_create_initial(timer_ptr, name_ptr, + TX_NULL, 0, + expiration_function, expiration_input, + initial_ticks, reschedule_ticks, auto_activate)); +} + diff --git a/common_smp/src/tx_timer_expiration_process.c b/common_smp/src/tx_timer_expiration_process.c index f54e982d8..7bca4b4e6 100644 --- a/common_smp/src/tx_timer_expiration_process.c +++ b/common_smp/src/tx_timer_expiration_process.c @@ -87,6 +87,8 @@ ULONG delta; TX_TIMER_INTERNAL *current_timer; VOID (*timeout_function)(ULONG id); ULONG timeout_param = ((ULONG) 0); +VOID (*timeout_function_ptr)(VOID *id); +VOID *timeout_param_ptr = TX_NULL; #ifdef TX_TIMER_ENABLE_PERFORMANCE_INFO TX_TIMER *timer_ptr; #endif @@ -263,7 +265,8 @@ TX_TIMER *timer_ptr; /* Set the timeout function to NULL in order to bypass the expiration. */ - timeout_function = TX_NULL; + timeout_function = TX_NULL; + timeout_function_ptr = TX_NULL; /* Make the timer appear that it is still active while interrupts are enabled. This will permit proper processing of a timer @@ -304,8 +307,10 @@ TX_TIMER *timer_ptr; /* Copy the calling function and ID into local variables before interrupts are re-enabled. */ - timeout_function = current_timer -> tx_timer_internal_timeout_function; - timeout_param = current_timer -> tx_timer_internal_timeout_param; + timeout_function = current_timer -> tx_timer_internal_timeout_function; + timeout_param = current_timer -> tx_timer_internal_timeout_param; + timeout_function_ptr = current_timer -> tx_timer_internal_timeout_function_ptr; + timeout_param_ptr = current_timer -> tx_timer_internal_timeout_param_ptr; /* Copy the reinitialize ticks into the remaining ticks. */ current_timer -> tx_timer_internal_remaining_ticks = current_timer -> tx_timer_internal_re_initialize_ticks; @@ -340,7 +345,12 @@ TX_TIMER *timer_ptr; TX_RESTORE /* Call the timer-expiration function, if non-NULL. */ - if (timeout_function != TX_NULL) + if (timeout_function_ptr != TX_NULL) + { + + (timeout_function_ptr) (timeout_param_ptr); + } + else if (timeout_function != TX_NULL) { (timeout_function) (timeout_param); @@ -361,7 +371,7 @@ TX_TIMER *timer_ptr; #ifdef TX_TIMER_ENABLE_PERFORMANCE_INFO /* Determine if this timer expired. */ - if (timeout_function != TX_NULL) + if ((timeout_function != TX_NULL) || (timeout_function_ptr != TX_NULL)) { /* Increment the total reactivations counter. */ diff --git a/common_smp/src/tx_timer_thread_entry.c b/common_smp/src/tx_timer_thread_entry.c index 51b165b23..274ddb438 100644 --- a/common_smp/src/tx_timer_thread_entry.c +++ b/common_smp/src/tx_timer_thread_entry.c @@ -80,6 +80,8 @@ TX_TIMER_INTERNAL *previous_timer; TX_TIMER_INTERNAL *current_timer; VOID (*timeout_function)(ULONG id); ULONG timeout_param = ((ULONG) 0); +VOID (*timeout_function_ptr)(VOID *id); +VOID *timeout_param_ptr = TX_NULL; TX_THREAD *thread_ptr; #ifdef TX_REACTIVATE_INLINE TX_TIMER_INTERNAL **timer_list; /* Timer list pointer */ @@ -257,7 +259,8 @@ UINT status; /* Set the timeout function to NULL in order to bypass the expiration. */ - timeout_function = TX_NULL; + timeout_function = TX_NULL; + timeout_function_ptr = TX_NULL; /* Make the timer appear that it is still active while interrupts are enabled. This will permit proper processing of a timer @@ -298,8 +301,10 @@ UINT status; /* Copy the calling function and ID into local variables before interrupts are re-enabled. */ - timeout_function = current_timer -> tx_timer_internal_timeout_function; - timeout_param = current_timer -> tx_timer_internal_timeout_param; + timeout_function = current_timer -> tx_timer_internal_timeout_function; + timeout_param = current_timer -> tx_timer_internal_timeout_param; + timeout_function_ptr = current_timer -> tx_timer_internal_timeout_function_ptr; + timeout_param_ptr = current_timer -> tx_timer_internal_timeout_param_ptr; /* Copy the reinitialize ticks into the remaining ticks. */ current_timer -> tx_timer_internal_remaining_ticks = current_timer -> tx_timer_internal_re_initialize_ticks; @@ -337,7 +342,12 @@ UINT status; #endif /* Call the timer-expiration function, if non-NULL. */ - if (timeout_function != TX_NULL) + if (timeout_function_ptr != TX_NULL) + { + + (timeout_function_ptr) (timeout_param_ptr); + } + else if (timeout_function != TX_NULL) { (timeout_function) (timeout_param); diff --git a/common_smp/src/txe_thread_create.c b/common_smp/src/txe_thread_create.c index cc5033b29..422daa23c 100644 --- a/common_smp/src/txe_thread_create.c +++ b/common_smp/src/txe_thread_create.c @@ -80,9 +80,17 @@ /* */ /* Application Code */ /* */ +static UINT _txe_thread_create_initial(TX_THREAD *thread_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*entry_function)(ULONG id), ULONG entry_input, + VOID (*entry_function_ptr)(VOID *id), VOID *entry_input_ptr, + VOID *stack_start, ULONG stack_size, + UINT priority, UINT preempt_threshold, + ULONG time_slice, UINT auto_start, UINT thread_control_block_size); + /**************************************************************************/ -UINT _txe_thread_create(TX_THREAD *thread_ptr, TX_NAME_CONST CHAR *name_ptr, +static UINT _txe_thread_create_initial(TX_THREAD *thread_ptr, TX_NAME_CONST CHAR *name_ptr, VOID (*entry_function)(ULONG id), ULONG entry_input, + VOID (*entry_function_ptr)(VOID *id), VOID *entry_input_ptr, VOID *stack_start, ULONG stack_size, UINT priority, UINT preempt_threshold, ULONG time_slice, UINT auto_start, UINT thread_control_block_size) @@ -221,7 +229,7 @@ TX_THREAD *current_thread; } /* Check for invalid thread entry point. */ - else if (entry_function == TX_NULL) + else if ((entry_function == TX_NULL) && (entry_function_ptr == TX_NULL)) { /* Invalid stack or entry point, return appropriate error code. */ @@ -296,12 +304,135 @@ TX_THREAD *current_thread; { /* Call actual thread create function. */ - status = _tx_thread_create(thread_ptr, name_ptr, entry_function, entry_input, - stack_start, stack_size, priority, preempt_threshold, - time_slice, auto_start); + if (entry_function_ptr != TX_NULL) + { + status = _tx_thread_create_ptr(thread_ptr, name_ptr, + entry_function_ptr, entry_input_ptr, + stack_start, stack_size, priority, preempt_threshold, + time_slice, auto_start); + } + else + { + status = _tx_thread_create(thread_ptr, name_ptr, + entry_function, entry_input, + stack_start, stack_size, priority, preempt_threshold, + time_slice, auto_start); + } } /* Return completion status. */ return(status); } + +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _txe_thread_create PORTABLE SMP */ +/* 6.3.0 */ +/* AUTHOR */ +/* */ +/* William E. Lamie, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This function checks for errors in the thread create function call. */ +/* */ +/* INPUT */ +/* */ +/* thread_ptr Thread control block pointer */ +/* name_ptr Pointer to thread name string */ +/* entry_function Entry function of the thread */ +/* entry_input 32-bit input value to thread */ +/* stack_start Pointer to start of stack */ +/* stack_size Stack size in bytes */ +/* priority Priority of thread (0-31) */ +/* preempt_threshold Preemption threshold */ +/* time_slice Thread time-slice value */ +/* auto_start Automatic start selection */ +/* thread_control_block_size Size of thread control block */ +/* */ +/* OUTPUT */ +/* */ +/* TX_THREAD_ERROR Invalid thread pointer */ +/* TX_PTR_ERROR Invalid stack or function ptr */ +/* TX_SIZE_ERROR Invalid stack size */ +/* TX_PRIORITY_ERROR Invalid thread priority */ +/* TX_THRESH_ERROR Invalid preemption threshold */ +/* TX_START_ERROR Invalid start selection */ +/* TX_CALLER_ERROR Invalid caller of function */ +/* status Actual completion status */ +/* */ +/**************************************************************************/ +UINT _txe_thread_create(TX_THREAD *thread_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*entry_function)(ULONG id), ULONG entry_input, + VOID *stack_start, ULONG stack_size, + UINT priority, UINT preempt_threshold, + ULONG time_slice, UINT auto_start, UINT thread_control_block_size) +{ + return(_txe_thread_create_initial(thread_ptr, name_ptr, + entry_function, entry_input, + TX_NULL, TX_NULL, + stack_start, stack_size, + priority, preempt_threshold, + time_slice, auto_start, + thread_control_block_size)); +} + + +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _txe_thread_create_ptr PORTABLE SMP */ +/* 6.3.0 */ +/* AUTHOR */ +/* */ +/* William E. Lamie, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This function checks for errors in pointer context thread create. */ +/* */ +/* INPUT */ +/* */ +/* thread_ptr Thread control block pointer */ +/* name_ptr Pointer to thread name string */ +/* entry_function Entry function of the thread */ +/* entry_input Pointer input value to thread */ +/* stack_start Pointer to start of stack */ +/* stack_size Stack size in bytes */ +/* priority Priority of thread */ +/* preempt_threshold Preemption threshold */ +/* time_slice Thread time-slice value */ +/* auto_start Automatic start selection */ +/* thread_control_block_size Size of thread control block */ +/* */ +/* OUTPUT */ +/* */ +/* TX_THREAD_ERROR Invalid thread pointer */ +/* TX_PTR_ERROR Invalid stack or function ptr */ +/* TX_SIZE_ERROR Invalid stack size */ +/* TX_PRIORITY_ERROR Invalid thread priority */ +/* TX_THRESH_ERROR Invalid preemption threshold */ +/* TX_START_ERROR Invalid start selection */ +/* TX_CALLER_ERROR Invalid caller of function */ +/* status Actual completion status */ +/* */ +/**************************************************************************/ +UINT _txe_thread_create_ptr(TX_THREAD *thread_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*entry_function)(VOID *id), VOID *entry_input, + VOID *stack_start, ULONG stack_size, + UINT priority, UINT preempt_threshold, + ULONG time_slice, UINT auto_start, UINT thread_control_block_size) +{ + return(_txe_thread_create_initial(thread_ptr, name_ptr, + TX_NULL, 0, + entry_function, entry_input, + stack_start, stack_size, + priority, preempt_threshold, + time_slice, auto_start, + thread_control_block_size)); +} + diff --git a/common_smp/src/txe_timer_create.c b/common_smp/src/txe_timer_create.c index 8c481bde8..0ea098dc3 100644 --- a/common_smp/src/txe_timer_create.c +++ b/common_smp/src/txe_timer_create.c @@ -75,9 +75,15 @@ /* */ /* Application Code */ /* */ +static UINT _txe_timer_create_initial(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*expiration_function)(ULONG id), ULONG expiration_input, + VOID (*expiration_function_ptr)(VOID *id), VOID *expiration_input_ptr, + ULONG initial_ticks, ULONG reschedule_ticks, UINT auto_activate, UINT timer_control_block_size); + /**************************************************************************/ -UINT _txe_timer_create(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, +static UINT _txe_timer_create_initial(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, VOID (*expiration_function)(ULONG id), ULONG expiration_input, + VOID (*expiration_function_ptr)(VOID *id), VOID *expiration_input_ptr, ULONG initial_ticks, ULONG reschedule_ticks, UINT auto_activate, UINT timer_control_block_size) { @@ -223,11 +229,113 @@ TX_THREAD *thread_ptr; { /* Call actual application timer create function. */ - status = _tx_timer_create(timer_ptr, name_ptr, expiration_function, expiration_input, - initial_ticks, reschedule_ticks, auto_activate); + if (expiration_function_ptr != TX_NULL) + { + status = _tx_timer_create_ptr(timer_ptr, name_ptr, + expiration_function_ptr, expiration_input_ptr, + initial_ticks, reschedule_ticks, auto_activate); + } + else + { + status = _tx_timer_create(timer_ptr, name_ptr, + expiration_function, expiration_input, + initial_ticks, reschedule_ticks, auto_activate); + } } /* Return completion status. */ return(status); } + +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _txe_timer_create PORTABLE SMP */ +/* 6.1 */ +/* AUTHOR */ +/* */ +/* William E. Lamie, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This function checks for errors in the timer create function call. */ +/* */ +/* INPUT */ +/* */ +/* timer_ptr Pointer to timer control blk */ +/* name_ptr Pointer to timer name */ +/* expiration_function Function to call on expiration*/ +/* expiration_input 32-bit input value for timer */ +/* initial_ticks Initial expiration ticks */ +/* reschedule_ticks Reschedule ticks */ +/* auto_activate Automatic activation flag */ +/* timer_control_block_size Size of timer control block */ +/* */ +/* OUTPUT */ +/* */ +/* TX_TIMER_ERROR Invalid timer pointer */ +/* TX_TICK_ERROR Invalid initial ticks */ +/* TX_ACTIVATE_ERROR Invalid auto-activate option */ +/* TX_CALLER_ERROR Invalid caller of function */ +/* status Actual completion status */ +/* */ +/**************************************************************************/ +UINT _txe_timer_create(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*expiration_function)(ULONG id), ULONG expiration_input, + ULONG initial_ticks, ULONG reschedule_ticks, UINT auto_activate, UINT timer_control_block_size) +{ + return(_txe_timer_create_initial(timer_ptr, name_ptr, + expiration_function, expiration_input, + TX_NULL, TX_NULL, + initial_ticks, reschedule_ticks, auto_activate, + timer_control_block_size)); +} + + +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _txe_timer_create_ptr PORTABLE SMP */ +/* 6.1 */ +/* AUTHOR */ +/* */ +/* William E. Lamie, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This function checks for errors in timer create with pointer input. */ +/* */ +/* INPUT */ +/* */ +/* timer_ptr Pointer to timer control blk */ +/* name_ptr Pointer to timer name */ +/* expiration_function Function to call on expiration*/ +/* expiration_input Pointer input value for timer */ +/* initial_ticks Initial expiration ticks */ +/* reschedule_ticks Reschedule ticks */ +/* auto_activate Automatic activation flag */ +/* timer_control_block_size Size of timer control block */ +/* */ +/* OUTPUT */ +/* */ +/* TX_TIMER_ERROR Invalid timer pointer */ +/* TX_TICK_ERROR Invalid initial ticks */ +/* TX_ACTIVATE_ERROR Invalid auto-activate option */ +/* TX_CALLER_ERROR Invalid caller of function */ +/* status Actual completion status */ +/* */ +/**************************************************************************/ +UINT _txe_timer_create_ptr(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*expiration_function)(VOID *id), VOID *expiration_input, + ULONG initial_ticks, ULONG reschedule_ticks, UINT auto_activate, UINT timer_control_block_size) +{ + return(_txe_timer_create_initial(timer_ptr, name_ptr, + TX_NULL, 0, + expiration_function, expiration_input, + initial_ticks, reschedule_ticks, auto_activate, + timer_control_block_size)); +} + diff --git a/test/smp/cmake/regression/CMakeLists.txt b/test/smp/cmake/regression/CMakeLists.txt index cdf0c5859..ad270c12f 100644 --- a/test/smp/cmake/regression/CMakeLists.txt +++ b/test/smp/cmake/regression/CMakeLists.txt @@ -132,6 +132,7 @@ set(regression_test_cases ${SOURCE_DIR}/threadx_timer_simple_test.c ${SOURCE_DIR}/threadx_trace_basic_test.c ${SOURCE_DIR}/threadx_trace_entry_update_test.c + ${SOURCE_DIR}/threadx_pointer_callback_test.c ${SOURCE_DIR}/threadx_initialize_kernel_setup_test.c) add_custom_command( diff --git a/test/smp/regression/threadx_pointer_callback_test.c b/test/smp/regression/threadx_pointer_callback_test.c new file mode 100644 index 000000000..0726f5219 --- /dev/null +++ b/test/smp/regression/threadx_pointer_callback_test.c @@ -0,0 +1,284 @@ +/*************************************************************************** + * Copyright (c) 2024 Microsoft Corporation + * Copyright (c) 2026-present Eclipse ThreadX contributors + * + * This program and the accompanying materials are made available under the + * terms of the MIT License which is available at + * https://opensource.org/licenses/MIT. + * + * SPDX-License-Identifier: MIT + **************************************************************************/ + +#include +#include +#include "tx_api.h" +#include "tx_thread.h" +#include "tx_timer.h" + +/* Define test control globals for standalone execution. */ +#ifndef CTEST +void test_control_return(UINT status); +#else +extern void test_control_return(UINT status); +#endif + +static unsigned long error = 0; + +static TX_THREAD thread_0; +static TX_THREAD thread_ptr_test; +static TX_THREAD thread_ulong_test; + +static TX_TIMER timer_ptr_test; +static TX_TIMER timer_ulong_test; + +static void *received_thread_ptr_ctx = TX_NULL; +static void *received_timer_ptr_ctx = TX_NULL; +static ULONG received_thread_ulong_ctx = 0; +static ULONG received_timer_ulong_ctx = 0; + +static volatile UINT thread_ptr_executed = 0; +static volatile UINT thread_ulong_executed = 0; +static volatile UINT timer_ptr_executed = 0; +static volatile UINT timer_ulong_executed = 0; + +#if (defined(__x86_64__) || defined(_WIN64) || defined(__aarch64__) || (defined(__riscv_xlen) && (__riscv_xlen == 64)) || defined(__LP64__) || defined(_LP64)) +#define TEST_PTR_VAL_1 ((VOID *)(ALIGN_TYPE) 0x123456789ABCDEF0ULL) +#define TEST_PTR_VAL_2 ((VOID *)(ALIGN_TYPE) 0xDEADBEEFCAFEBABEULL) +#else +#define TEST_PTR_VAL_1 ((VOID *)(ALIGN_TYPE) 0x12345678UL) +#define TEST_PTR_VAL_2 ((VOID *)(ALIGN_TYPE) 0xDEADBEEFUL) +#endif +#define TEST_ULONG_VAL_1 ((ULONG) 0x55AA1234UL) +#define TEST_ULONG_VAL_2 ((ULONG) 0x99887766UL) + +static void thread_ptr_entry(VOID *entry_input) +{ + received_thread_ptr_ctx = entry_input; + thread_ptr_executed = 1; + while (1) + { + tx_thread_sleep(100); + } +} + +static void thread_ulong_entry(ULONG entry_input) +{ + received_thread_ulong_ctx = entry_input; + thread_ulong_executed = 1; + while (1) + { + tx_thread_sleep(100); + } +} + +static void timer_ptr_expiration(VOID *expiration_input) +{ + received_timer_ptr_ctx = expiration_input; + timer_ptr_executed = 1; +} + +static void timer_ulong_expiration(ULONG expiration_input) +{ + received_timer_ulong_ctx = expiration_input; + timer_ulong_executed = 1; +} + +static void thread_0_entry(ULONG thread_input) +{ + UINT status; + VOID *expected_thread_ptr = TEST_PTR_VAL_1; + VOID *expected_timer_ptr = TEST_PTR_VAL_2; + + TX_PARAMETER_NOT_USED(thread_input); + + printf("Running Pointer Callback Regression Test............................ "); + + /* Resume pointer thread and standard thread. */ + tx_thread_resume(&thread_ptr_test); + tx_thread_resume(&thread_ulong_test); + + /* Sleep to allow threads and timers to execute. */ + tx_thread_sleep(5); + + /* Verify pointer thread context reception without 32-bit truncation. */ + if (thread_ptr_executed != 1) + { + error++; + } + if (received_thread_ptr_ctx != expected_thread_ptr) + { + error++; + } + + /* Verify standard ULONG thread context reception. */ + if (thread_ulong_executed != 1) + { + error++; + } + if (received_thread_ulong_ctx != TEST_ULONG_VAL_1) + { + error++; + } + + /* Verify pointer timer context reception without 32-bit truncation. */ + if (timer_ptr_executed != 1) + { + error++; + } + if (received_timer_ptr_ctx != expected_timer_ptr) + { + error++; + } + + /* Verify standard ULONG timer context reception. */ + if (timer_ulong_executed != 1) + { + error++; + } + if (received_timer_ulong_ctx != TEST_ULONG_VAL_2) + { + error++; + } + +#ifndef TX_DISABLE_ERROR_CHECKING + TX_THREAD dummy_thread; + TX_TIMER dummy_timer; + CHAR dummy_stack[1024]; + + dummy_thread.tx_thread_id = 0; + dummy_timer.tx_timer_id = 0; + + /* Test error checking paths for pointer thread create. */ + status = tx_thread_create_ptr(TX_NULL, "bad", thread_ptr_entry, expected_thread_ptr, + dummy_stack, sizeof(dummy_stack), 16, 16, TX_NO_TIME_SLICE, TX_DONT_START); + if (status != TX_THREAD_ERROR) + { + error++; + } + + status = tx_thread_create_ptr(&dummy_thread, "bad", TX_NULL, expected_thread_ptr, + dummy_stack, sizeof(dummy_stack), 16, 16, TX_NO_TIME_SLICE, TX_DONT_START); + if (status != TX_PTR_ERROR) + { + error++; + } + + status = tx_thread_create_ptr(&dummy_thread, "bad", thread_ptr_entry, expected_thread_ptr, + TX_NULL, sizeof(dummy_stack), 16, 16, TX_NO_TIME_SLICE, TX_DONT_START); + if (status != TX_PTR_ERROR) + { + error++; + } + + status = tx_thread_create_ptr(&dummy_thread, "bad", thread_ptr_entry, expected_thread_ptr, + dummy_stack, 0, 16, 16, TX_NO_TIME_SLICE, TX_DONT_START); + if (status != TX_SIZE_ERROR) + { + error++; + } + + /* Test error checking paths for pointer timer create. */ + status = tx_timer_create_ptr(TX_NULL, "bad", timer_ptr_expiration, expected_timer_ptr, + 1, 0, TX_NO_ACTIVATE); + if (status != TX_TIMER_ERROR) + { + error++; + } + + status = tx_timer_create_ptr(&dummy_timer, "bad", timer_ptr_expiration, expected_timer_ptr, + 0, 0, TX_NO_ACTIVATE); + if (status != TX_TICK_ERROR) + { + error++; + } + + status = tx_timer_create_ptr(&dummy_timer, "bad", timer_ptr_expiration, expected_timer_ptr, + 1, 0, 0xFF); + if (status != TX_ACTIVATE_ERROR) + { + error++; + } +#endif + + /* Clean up created objects. */ + tx_timer_deactivate(&timer_ptr_test); + tx_timer_delete(&timer_ptr_test); + tx_timer_deactivate(&timer_ulong_test); + tx_timer_delete(&timer_ulong_test); + + tx_thread_terminate(&thread_ptr_test); + tx_thread_delete(&thread_ptr_test); + tx_thread_terminate(&thread_ulong_test); + tx_thread_delete(&thread_ulong_test); + + if (error) + { + printf("ERROR!\n"); + test_control_return(1); + } + else + { + printf("SUCCESS!\n"); + test_control_return(0); + } +} + +#ifdef CTEST +void test_application_define(void *first_unused_memory) +#else +void threadx_pointer_callback_application_define(void *first_unused_memory) +#endif +{ + UINT status; + CHAR *pointer = (CHAR *) first_unused_memory; + + /* Create primary test thread. */ + status = tx_thread_create(&thread_0, "thread 0", thread_0_entry, 0, + pointer, 2048, + 10, 10, TX_NO_TIME_SLICE, TX_AUTO_START); + pointer += 2048; + + /* Create pointer callback thread. */ + status += tx_thread_create_ptr(&thread_ptr_test, "ptr thread", thread_ptr_entry, TEST_PTR_VAL_1, + pointer, 2048, + 12, 12, TX_NO_TIME_SLICE, TX_DONT_START); + pointer += 2048; + + /* Create standard ULONG callback thread. */ + status += tx_thread_create(&thread_ulong_test, "ulong thread", thread_ulong_entry, TEST_ULONG_VAL_1, + pointer, 2048, + 12, 12, TX_NO_TIME_SLICE, TX_DONT_START); + pointer += 2048; + + /* Create pointer timer. */ + status += tx_timer_create_ptr(&timer_ptr_test, "ptr timer", timer_ptr_expiration, TEST_PTR_VAL_2, + 2, 0, TX_AUTO_ACTIVATE); + + /* Create standard ULONG timer. */ + status += tx_timer_create(&timer_ulong_test, "ulong timer", timer_ulong_expiration, TEST_ULONG_VAL_2, + 2, 0, TX_AUTO_ACTIVATE); + + if (status != TX_SUCCESS) + { + printf("Running Pointer Callback Regression Test............................ INITIALIZATION ERROR!\n"); + test_control_return(1); + } +} + +#ifndef CTEST +void test_control_return(UINT status) +{ + exit((int) status); +} + +int main(void) +{ + tx_kernel_enter(); + return 0; +} + +void tx_application_define(void *first_unused_memory) +{ + threadx_pointer_callback_application_define(first_unused_memory); +} +#endif diff --git a/test/tx/cmake/regression/CMakeLists.txt b/test/tx/cmake/regression/CMakeLists.txt index 6b94a8576..e4259f556 100644 --- a/test/tx/cmake/regression/CMakeLists.txt +++ b/test/tx/cmake/regression/CMakeLists.txt @@ -113,7 +113,8 @@ set(regression_test_cases ${SOURCE_DIR}/threadx_timer_simple_test.c ${SOURCE_DIR}/threadx_trace_basic_test.c ${SOURCE_DIR}/threadx_trace_entry_update_test.c - ${SOURCE_DIR}/threadx_initialize_kernel_setup_test.c) + ${SOURCE_DIR}/threadx_initialize_kernel_setup_test.c + ${SOURCE_DIR}/threadx_pointer_callback_test.c) add_custom_command( OUTPUT ${GENERATED_LOW_LEVEL_SOURCE} diff --git a/test/tx/regression/threadx_pointer_callback_test.c b/test/tx/regression/threadx_pointer_callback_test.c new file mode 100644 index 000000000..0726f5219 --- /dev/null +++ b/test/tx/regression/threadx_pointer_callback_test.c @@ -0,0 +1,284 @@ +/*************************************************************************** + * Copyright (c) 2024 Microsoft Corporation + * Copyright (c) 2026-present Eclipse ThreadX contributors + * + * This program and the accompanying materials are made available under the + * terms of the MIT License which is available at + * https://opensource.org/licenses/MIT. + * + * SPDX-License-Identifier: MIT + **************************************************************************/ + +#include +#include +#include "tx_api.h" +#include "tx_thread.h" +#include "tx_timer.h" + +/* Define test control globals for standalone execution. */ +#ifndef CTEST +void test_control_return(UINT status); +#else +extern void test_control_return(UINT status); +#endif + +static unsigned long error = 0; + +static TX_THREAD thread_0; +static TX_THREAD thread_ptr_test; +static TX_THREAD thread_ulong_test; + +static TX_TIMER timer_ptr_test; +static TX_TIMER timer_ulong_test; + +static void *received_thread_ptr_ctx = TX_NULL; +static void *received_timer_ptr_ctx = TX_NULL; +static ULONG received_thread_ulong_ctx = 0; +static ULONG received_timer_ulong_ctx = 0; + +static volatile UINT thread_ptr_executed = 0; +static volatile UINT thread_ulong_executed = 0; +static volatile UINT timer_ptr_executed = 0; +static volatile UINT timer_ulong_executed = 0; + +#if (defined(__x86_64__) || defined(_WIN64) || defined(__aarch64__) || (defined(__riscv_xlen) && (__riscv_xlen == 64)) || defined(__LP64__) || defined(_LP64)) +#define TEST_PTR_VAL_1 ((VOID *)(ALIGN_TYPE) 0x123456789ABCDEF0ULL) +#define TEST_PTR_VAL_2 ((VOID *)(ALIGN_TYPE) 0xDEADBEEFCAFEBABEULL) +#else +#define TEST_PTR_VAL_1 ((VOID *)(ALIGN_TYPE) 0x12345678UL) +#define TEST_PTR_VAL_2 ((VOID *)(ALIGN_TYPE) 0xDEADBEEFUL) +#endif +#define TEST_ULONG_VAL_1 ((ULONG) 0x55AA1234UL) +#define TEST_ULONG_VAL_2 ((ULONG) 0x99887766UL) + +static void thread_ptr_entry(VOID *entry_input) +{ + received_thread_ptr_ctx = entry_input; + thread_ptr_executed = 1; + while (1) + { + tx_thread_sleep(100); + } +} + +static void thread_ulong_entry(ULONG entry_input) +{ + received_thread_ulong_ctx = entry_input; + thread_ulong_executed = 1; + while (1) + { + tx_thread_sleep(100); + } +} + +static void timer_ptr_expiration(VOID *expiration_input) +{ + received_timer_ptr_ctx = expiration_input; + timer_ptr_executed = 1; +} + +static void timer_ulong_expiration(ULONG expiration_input) +{ + received_timer_ulong_ctx = expiration_input; + timer_ulong_executed = 1; +} + +static void thread_0_entry(ULONG thread_input) +{ + UINT status; + VOID *expected_thread_ptr = TEST_PTR_VAL_1; + VOID *expected_timer_ptr = TEST_PTR_VAL_2; + + TX_PARAMETER_NOT_USED(thread_input); + + printf("Running Pointer Callback Regression Test............................ "); + + /* Resume pointer thread and standard thread. */ + tx_thread_resume(&thread_ptr_test); + tx_thread_resume(&thread_ulong_test); + + /* Sleep to allow threads and timers to execute. */ + tx_thread_sleep(5); + + /* Verify pointer thread context reception without 32-bit truncation. */ + if (thread_ptr_executed != 1) + { + error++; + } + if (received_thread_ptr_ctx != expected_thread_ptr) + { + error++; + } + + /* Verify standard ULONG thread context reception. */ + if (thread_ulong_executed != 1) + { + error++; + } + if (received_thread_ulong_ctx != TEST_ULONG_VAL_1) + { + error++; + } + + /* Verify pointer timer context reception without 32-bit truncation. */ + if (timer_ptr_executed != 1) + { + error++; + } + if (received_timer_ptr_ctx != expected_timer_ptr) + { + error++; + } + + /* Verify standard ULONG timer context reception. */ + if (timer_ulong_executed != 1) + { + error++; + } + if (received_timer_ulong_ctx != TEST_ULONG_VAL_2) + { + error++; + } + +#ifndef TX_DISABLE_ERROR_CHECKING + TX_THREAD dummy_thread; + TX_TIMER dummy_timer; + CHAR dummy_stack[1024]; + + dummy_thread.tx_thread_id = 0; + dummy_timer.tx_timer_id = 0; + + /* Test error checking paths for pointer thread create. */ + status = tx_thread_create_ptr(TX_NULL, "bad", thread_ptr_entry, expected_thread_ptr, + dummy_stack, sizeof(dummy_stack), 16, 16, TX_NO_TIME_SLICE, TX_DONT_START); + if (status != TX_THREAD_ERROR) + { + error++; + } + + status = tx_thread_create_ptr(&dummy_thread, "bad", TX_NULL, expected_thread_ptr, + dummy_stack, sizeof(dummy_stack), 16, 16, TX_NO_TIME_SLICE, TX_DONT_START); + if (status != TX_PTR_ERROR) + { + error++; + } + + status = tx_thread_create_ptr(&dummy_thread, "bad", thread_ptr_entry, expected_thread_ptr, + TX_NULL, sizeof(dummy_stack), 16, 16, TX_NO_TIME_SLICE, TX_DONT_START); + if (status != TX_PTR_ERROR) + { + error++; + } + + status = tx_thread_create_ptr(&dummy_thread, "bad", thread_ptr_entry, expected_thread_ptr, + dummy_stack, 0, 16, 16, TX_NO_TIME_SLICE, TX_DONT_START); + if (status != TX_SIZE_ERROR) + { + error++; + } + + /* Test error checking paths for pointer timer create. */ + status = tx_timer_create_ptr(TX_NULL, "bad", timer_ptr_expiration, expected_timer_ptr, + 1, 0, TX_NO_ACTIVATE); + if (status != TX_TIMER_ERROR) + { + error++; + } + + status = tx_timer_create_ptr(&dummy_timer, "bad", timer_ptr_expiration, expected_timer_ptr, + 0, 0, TX_NO_ACTIVATE); + if (status != TX_TICK_ERROR) + { + error++; + } + + status = tx_timer_create_ptr(&dummy_timer, "bad", timer_ptr_expiration, expected_timer_ptr, + 1, 0, 0xFF); + if (status != TX_ACTIVATE_ERROR) + { + error++; + } +#endif + + /* Clean up created objects. */ + tx_timer_deactivate(&timer_ptr_test); + tx_timer_delete(&timer_ptr_test); + tx_timer_deactivate(&timer_ulong_test); + tx_timer_delete(&timer_ulong_test); + + tx_thread_terminate(&thread_ptr_test); + tx_thread_delete(&thread_ptr_test); + tx_thread_terminate(&thread_ulong_test); + tx_thread_delete(&thread_ulong_test); + + if (error) + { + printf("ERROR!\n"); + test_control_return(1); + } + else + { + printf("SUCCESS!\n"); + test_control_return(0); + } +} + +#ifdef CTEST +void test_application_define(void *first_unused_memory) +#else +void threadx_pointer_callback_application_define(void *first_unused_memory) +#endif +{ + UINT status; + CHAR *pointer = (CHAR *) first_unused_memory; + + /* Create primary test thread. */ + status = tx_thread_create(&thread_0, "thread 0", thread_0_entry, 0, + pointer, 2048, + 10, 10, TX_NO_TIME_SLICE, TX_AUTO_START); + pointer += 2048; + + /* Create pointer callback thread. */ + status += tx_thread_create_ptr(&thread_ptr_test, "ptr thread", thread_ptr_entry, TEST_PTR_VAL_1, + pointer, 2048, + 12, 12, TX_NO_TIME_SLICE, TX_DONT_START); + pointer += 2048; + + /* Create standard ULONG callback thread. */ + status += tx_thread_create(&thread_ulong_test, "ulong thread", thread_ulong_entry, TEST_ULONG_VAL_1, + pointer, 2048, + 12, 12, TX_NO_TIME_SLICE, TX_DONT_START); + pointer += 2048; + + /* Create pointer timer. */ + status += tx_timer_create_ptr(&timer_ptr_test, "ptr timer", timer_ptr_expiration, TEST_PTR_VAL_2, + 2, 0, TX_AUTO_ACTIVATE); + + /* Create standard ULONG timer. */ + status += tx_timer_create(&timer_ulong_test, "ulong timer", timer_ulong_expiration, TEST_ULONG_VAL_2, + 2, 0, TX_AUTO_ACTIVATE); + + if (status != TX_SUCCESS) + { + printf("Running Pointer Callback Regression Test............................ INITIALIZATION ERROR!\n"); + test_control_return(1); + } +} + +#ifndef CTEST +void test_control_return(UINT status) +{ + exit((int) status); +} + +int main(void) +{ + tx_kernel_enter(); + return 0; +} + +void tx_application_define(void *first_unused_memory) +{ + threadx_pointer_callback_application_define(first_unused_memory); +} +#endif From 55e99fb2919cf37841fd6119a3a53cd59320885a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Desbiens?= Date: Thu, 26 Nov 2026 08:39:22 -0500 Subject: [PATCH 2/4] Restored the module stack and user mode when resetting threads MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A module thread can complete while its kernel stack is active. Resetting it used that stack and the privileged mode left by the kernel call. Restored the saved module stack and configured mode, and rebuilt the initial frame using the original module entry information. The Cortex-M3 and Cortex-M4 QEMU lifecycle tests completed and restarted protected workers with the original scalar argument and user mode. Assisted-by: Codex (GPT-6.2-Sol) Signed-off-by: Frédéric Desbiens --- .../src/txm_module_manager_thread_reset.c | 14 ++++++---- .../cmake/module_qemu/tests/harness_checks.c | 2 +- .../cmake/module_qemu/tests/module_services.c | 26 ++++++++++++------- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/common_modules/module_manager/src/txm_module_manager_thread_reset.c b/common_modules/module_manager/src/txm_module_manager_thread_reset.c index 334070bf2..fb0e5424b 100644 --- a/common_modules/module_manager/src/txm_module_manager_thread_reset.c +++ b/common_modules/module_manager/src/txm_module_manager_thread_reset.c @@ -134,6 +134,13 @@ TXM_MODULE_THREAD_ENTRY_INFO *thread_entry_info; /* Get the module instance. */ module_instance = thread_ptr -> tx_thread_module_instance_ptr; + /* A module can complete or be terminated while in a kernel call. + Restore the module stack and mode before building its entry frame. */ + thread_ptr -> tx_thread_stack_start = thread_ptr -> tx_thread_module_stack_start; + thread_ptr -> tx_thread_stack_end = thread_ptr -> tx_thread_module_stack_end; + thread_ptr -> tx_thread_stack_size = thread_ptr -> tx_thread_module_stack_size; + thread_ptr -> tx_thread_module_current_user_mode = thread_ptr -> tx_thread_module_user_mode; + /* Execute Port-Specific completion processing. If needed, it is typically defined in txm_module_port.h. */ TXM_MODULE_MANAGER_THREAD_RESET_PORT_COMPLETION(thread_ptr, module_instance) @@ -148,11 +155,8 @@ TXM_MODULE_THREAD_ENTRY_INFO *thread_entry_info; TX_MEMSET(thread_ptr -> tx_thread_stack_start, ((UCHAR) TX_STACK_FILL), thread_ptr -> tx_thread_stack_size); #endif - /* Setup pointer to the thread entry information structure, which will live at the top of each - module thread's stack. This will allow the module thread entry function to avoid direct - access to the actual thread control block. */ - thread_entry_info = (TXM_MODULE_THREAD_ENTRY_INFO *) (((UCHAR *) thread_ptr -> tx_thread_stack_end) + (2*sizeof(ULONG)) + 1); - thread_entry_info = (TXM_MODULE_THREAD_ENTRY_INFO *) (((ALIGN_TYPE)(thread_entry_info)) & (~0x3)); + /* Reuse the entry information above the module stack. */ + thread_entry_info = (TXM_MODULE_THREAD_ENTRY_INFO *) thread_ptr -> tx_thread_module_entry_info_ptr; /* Place the thread entry information pointer in the thread control block so it can be picked up in the following stack build function. This is supplied to the module's shell entry function diff --git a/test/tx/cmake/module_qemu/tests/harness_checks.c b/test/tx/cmake/module_qemu/tests/harness_checks.c index 4b7cff05d..70547ba53 100644 --- a/test/tx/cmake/module_qemu/tests/harness_checks.c +++ b/test/tx/cmake/module_qemu/tests/harness_checks.c @@ -34,7 +34,7 @@ VOID harness_check_services(ULONG cycle) harness_expect("module object allocation", MODULE_SHARED[MODULE_OUT_OBJECT_STATUS], (ULONG) TX_SUCCESS); harness_expect("module object creation and queue send", MODULE_SHARED[MODULE_OUT_CREATE_STATUS], (ULONG) TX_SUCCESS); harness_expect("module worker received the message", MODULE_SHARED[MODULE_OUT_QUEUE_VALUE], MODULE_QUEUE_MESSAGE); - harness_expect("module worker ran once", MODULE_SHARED[MODULE_OUT_WORKER_RUNS], 1UL); + harness_expect("module worker ran before and after reset", MODULE_SHARED[MODULE_OUT_WORKER_RUNS], 2UL); harness_expect("module semaphore get", MODULE_SHARED[MODULE_OUT_SEMAPHORE_STATUS], (ULONG) TX_SUCCESS); harness_expect("module sleep lasted its ticks", (ULONG) (MODULE_SHARED[MODULE_OUT_SLEEP_TICKS] >= EXPECTED_SLEEP_TICKS), (ULONG) TX_TRUE); diff --git a/test/tx/cmake/module_qemu/tests/module_services.c b/test/tx/cmake/module_qemu/tests/module_services.c index e2fcce44b..7f74b4a5f 100644 --- a/test/tx/cmake/module_qemu/tests/module_services.c +++ b/test/tx/cmake/module_qemu/tests/module_services.c @@ -71,18 +71,18 @@ static VOID record_status(ULONG word, UINT status) static VOID worker_entry(ULONG thread_input) { ULONG message; +ULONG control; - (VOID) thread_input; - - for (;;) + __asm__ volatile ("mrs %0, control" : "=r"(control)); + message = 0UL; + if (tx_queue_receive(message_queue, &message, WAIT_TICKS) == TX_SUCCESS) { - message = 0UL; - if (tx_queue_receive(message_queue, &message, TX_WAIT_FOREVER) == TX_SUCCESS) + if ((thread_input == MODULE_QUEUE_MESSAGE) && (control == MODULE_SHARED[MODULE_OUT_CONTROL])) { MODULE_SHARED[MODULE_OUT_QUEUE_VALUE] = message; - MODULE_SHARED[MODULE_OUT_WORKER_RUNS] = MODULE_SHARED[MODULE_OUT_WORKER_RUNS] + 1UL; - (VOID) tx_semaphore_put(done_semaphore); + MODULE_SHARED[MODULE_OUT_WORKER_RUNS]++; } + (VOID) tx_semaphore_put(done_semaphore); } } @@ -109,13 +109,19 @@ ULONG kernel_word; record_status(MODULE_OUT_CREATE_STATUS, tx_queue_create(message_queue, "module queue", TX_1_ULONG, queue_storage, sizeof(queue_storage))); record_status(MODULE_OUT_CREATE_STATUS, tx_semaphore_create(done_semaphore, "module semaphore", 0UL)); - record_status(MODULE_OUT_CREATE_STATUS, tx_thread_create(worker_thread, "module worker", worker_entry, 0UL, + record_status(MODULE_OUT_CREATE_STATUS, tx_thread_create(worker_thread, "module worker", worker_entry, + MODULE_QUEUE_MESSAGE, worker_stack, sizeof(worker_stack), - 2U, 2U, TX_NO_TIME_SLICE, TX_AUTO_START)); + 0U, 0U, TX_NO_TIME_SLICE, TX_AUTO_START)); message = MODULE_QUEUE_MESSAGE; record_status(MODULE_OUT_CREATE_STATUS, tx_queue_send(message_queue, &message, TX_NO_WAIT)); - MODULE_SHARED[MODULE_OUT_SEMAPHORE_STATUS] = (ULONG) tx_semaphore_get(done_semaphore, WAIT_TICKS); + record_status(MODULE_OUT_SEMAPHORE_STATUS, tx_semaphore_get(done_semaphore, WAIT_TICKS)); + + record_status(MODULE_OUT_CREATE_STATUS, tx_thread_reset(worker_thread)); + record_status(MODULE_OUT_CREATE_STATUS, tx_thread_resume(worker_thread)); + record_status(MODULE_OUT_CREATE_STATUS, tx_queue_send(message_queue, &message, TX_NO_WAIT)); + record_status(MODULE_OUT_SEMAPHORE_STATUS, tx_semaphore_get(done_semaphore, WAIT_TICKS)); start_time = tx_time_get(); (VOID) tx_thread_sleep(SLEEP_TICKS); From cd23e548814c8c092bf754c9eb3ab7eb2005f17f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Desbiens?= Date: Thu, 26 Nov 2026 08:39:54 -0500 Subject: [PATCH 3/4] Enabled pointer-context creation in loadable modules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #771 The pointer creation services had native entry points only. Modules need to carry the callback and context through the manager dispatch ABI and run the callback in module context. Added module requests for both services. The module thread shell calls the typed entry with its original argument. The timer path snapshots the callback and context and queues delivery to the module callback thread. The option preserves existing member offsets and increases the sizes of enabled thread, timer, and module entry structures. Linux covered 146/146 changed kernel lines and 56/56 branches. Cortex-M4 QEMU covered 83/83 changed shared module lines and 16/16 branches. Cortex-M3/M4 passed 20/20 QEMU tests, including M4 ISR timers. Cortex-R52 and Cortex-A35 UP/SMP manager builds passed. FreeRTOS passed 6/6 tests across both option settings. Assisted-by: Codex (GPT-6.2-Sol) Signed-off-by: Frédéric Desbiens --- .github/workflows/module_qemu.yml | 46 ++++---- common/inc/tx_api.h | 28 ++++- common/inc/tx_timer.h | 13 +++ common/inc/tx_user_sample.h | 4 +- common/src/tx_timer_create.c | 19 +++- common/src/tx_timer_expiration_process.c | 13 ++- common/src/tx_timer_thread_entry.c | 13 ++- common/src/txe_timer_create.c | 23 +++- common_modules/inc/txm_module.h | 38 +++++++ common_modules/inc/txm_module_user_sample.h | 3 + ...txm_module_callback_request_thread_entry.c | 15 +++ .../module_lib/src/txm_thread_create.c | 27 +++++ .../module_lib/src/txm_timer_create.c | 22 ++++ .../inc/txm_module_manager_dispatch.h | 59 +++++++++- .../src/txm_module_manager_callback_request.c | 4 + .../src/txm_module_manager_kernel_dispatch.c | 40 ++++++- .../src/txm_module_manager_thread_create.c | 52 +++++++++ ...m_module_manager_timer_notify_trampoline.c | 37 +++++++ common_smp/inc/tx_api.h | 28 ++++- common_smp/inc/tx_timer.h | 13 +++ common_smp/src/tx_timer_create.c | 19 +++- common_smp/src/tx_timer_expiration_process.c | 13 ++- common_smp/src/tx_timer_thread_entry.c | 13 ++- common_smp/src/txe_timer_create.c | 23 +++- .../src/txm_module_thread_shell_entry.c | 3 +- .../src/txm_module_thread_shell_entry.c | 3 +- .../src/txm_module_thread_shell_entry.c | 3 +- .../src/txm_module_thread_shell_entry.c | 3 +- .../src/txm_module_thread_shell_entry.c | 3 +- .../src/txm_module_thread_shell_entry.c | 3 +- .../src/txm_module_thread_shell_entry.c | 3 +- .../src/txm_module_thread_shell_entry.c | 3 +- .../src/txm_module_thread_shell_entry.c | 3 +- .../src/txm_module_thread_shell_entry.c | 3 +- .../src/txm_module_thread_shell_entry.c | 3 +- .../src/txm_module_thread_shell_entry.c | 3 +- .../src/txm_module_thread_shell_entry.c | 3 +- .../src/txm_module_thread_shell_entry.c | 3 +- .../src/txm_module_thread_shell_entry.c | 3 +- .../src/txm_module_thread_shell_entry.c | 3 +- .../src/txm_module_thread_shell_entry.c | 3 +- .../src/txm_module_thread_shell_entry.c | 3 +- .../src/txm_module_thread_shell_entry.c | 3 +- .../src/txm_module_thread_shell_entry.c | 3 +- .../src/txm_module_thread_shell_entry.c | 3 +- .../src/txm_module_thread_shell_entry.c | 3 +- .../src/txm_module_thread_shell_entry.c | 3 +- .../src/txm_module_thread_shell_entry.c | 3 +- .../src/txm_module_thread_shell_entry.c | 3 +- .../src/txm_module_thread_shell_entry.c | 3 +- .../src/txm_module_thread_shell_entry.c | 3 +- .../src/txm_module_thread_shell_entry.c | 3 +- .../src/txm_module_thread_shell_entry.c | 3 +- .../src/txm_module_thread_shell_entry.c | 3 +- .../src/txm_module_thread_shell_entry.c | 3 +- .../src/txm_module_thread_shell_entry.c | 3 +- test/smp/cmake/CMakeLists.txt | 6 +- .../threadx_pointer_callback_test.c | 48 +++++++- test/tx/cmake/CMakeLists.txt | 6 +- test/tx/cmake/module_qemu/CMakeLists.txt | 5 + test/tx/cmake/module_qemu/src/module_shared.h | 4 + .../cmake/module_qemu/tests/harness_checks.c | 6 + .../cmake/module_qemu/tests/module_services.c | 103 ++++++++++++++++++ .../module_qemu/tests/test_module_lifecycle.c | 56 ++++++++++ .../threadx_pointer_callback_test.c | 48 +++++++- 65 files changed, 842 insertions(+), 101 deletions(-) diff --git a/.github/workflows/module_qemu.yml b/.github/workflows/module_qemu.yml index 7cc627090..bc153dc39 100644 --- a/.github/workflows/module_qemu.yml +++ b/.github/workflows/module_qemu.yml @@ -122,30 +122,30 @@ jobs: status=0 for port in cortex_m3 cortex_m4; do - build="build/module_qemu_$port" - echo "" - echo "==============================================================" - echo "== $port" - echo "==============================================================" + for pointer_context in OFF ON; do + config="$port (pointer context $pointer_context)" + build="build/module_qemu_${port}_$pointer_context" + echo "== $config" - if ! cmake -S test/tx/cmake/module_qemu -B "$build" -G Ninja \ - -DCMAKE_TOOLCHAIN_FILE="$PWD/test/tx/cmake/module_qemu/arm-none-eabi-qemu.cmake" \ - -DMODULE_QEMU_PORT="$port"; then - echo "::error::$port: CMake configure failed" - status=1 - continue - fi - if ! cmake --build "$build"; then - echo "::error::$port: the images did not build" - status=1 - continue - fi - # --no-tests=error: the tests are registered only when QEMU and - # Python are found, and ctest's default would pass on none. - if ! ctest --test-dir "$build" --output-on-failure --no-tests=error; then - echo "::error::$port: one or more images failed on QEMU, or no tests were registered" - status=1 - fi + if ! cmake -S test/tx/cmake/module_qemu -B "$build" -G Ninja \ + -DCMAKE_TOOLCHAIN_FILE="$PWD/test/tx/cmake/module_qemu/arm-none-eabi-qemu.cmake" \ + -DMODULE_QEMU_PORT="$port" -DMODULE_QEMU_POINTER_CONTEXT="$pointer_context"; then + echo "::error::$config: CMake configure failed" + status=1 + continue + fi + if ! cmake --build "$build"; then + echo "::error::$config: the images did not build" + status=1 + continue + fi + # --no-tests=error: the tests are registered only when QEMU and + # Python are found, and ctest's default would pass on none. + if ! ctest --test-dir "$build" --output-on-failure --no-tests=error; then + echo "::error::$config: one or more images failed on QEMU, or no tests were registered" + status=1 + fi + done done exit $status diff --git a/common/inc/tx_api.h b/common/inc/tx_api.h index 2295dc2b6..e7d6461b1 100644 --- a/common/inc/tx_api.h +++ b/common/inc/tx_api.h @@ -372,6 +372,12 @@ typedef struct TX_TIMER_INTERNAL_STRUCT #endif +#ifdef TX_ENABLE_POINTER_CONTEXT +/* Deliver a snapshotted pointer callback through the object's owner. */ +typedef VOID (*TX_TIMER_POINTER_DISPATCH)(VOID *owner, VOID (*callback)(VOID *), VOID *input); +#endif + + /* Define the timer structure utilized by the application. */ typedef struct TX_TIMER_STRUCT @@ -417,6 +423,8 @@ typedef struct TX_TIMER_STRUCT /* Pointer callback storage follows the port and user fields. */ VOID (*tx_timer_timeout_function_ptr)(VOID *input); VOID *tx_timer_timeout_param_ptr; + TX_TIMER_POINTER_DISPATCH tx_timer_timeout_dispatch; + VOID *tx_timer_timeout_owner; #endif } TX_TIMER; @@ -1152,9 +1160,13 @@ UINT _tx_trace_interrupt_control(UINT new_posture); #define tx_semaphore_put _tx_semaphore_put #define tx_semaphore_put_notify _tx_semaphore_put_notify -#if defined(TX_ENABLE_POINTER_CONTEXT) && !defined(TXM_MODULE) +#ifdef TX_ENABLE_POINTER_CONTEXT +#ifdef TXM_MODULE +#define tx_thread_create_ptr(t,n,e,i,s,l,p,r,c,a) _txe_thread_create_ptr((t),(n),(e),(i),(s),(l),(p),(r),(c),(a),(sizeof(TX_THREAD))) +#else #define tx_thread_create_ptr _tx_thread_create_ptr #endif +#endif #define tx_thread_create _tx_thread_create #define tx_thread_delete _tx_thread_delete #define tx_thread_entry_exit_notify _tx_thread_entry_exit_notify @@ -1178,9 +1190,13 @@ UINT _tx_trace_interrupt_control(UINT new_posture); #define tx_time_set _tx_time_set #define tx_timer_activate _tx_timer_activate #define tx_timer_change _tx_timer_change -#if defined(TX_ENABLE_POINTER_CONTEXT) && !defined(TXM_MODULE) +#ifdef TX_ENABLE_POINTER_CONTEXT +#ifdef TXM_MODULE +#define tx_timer_create_ptr(t,n,e,i,c,r,a) _txe_timer_create_ptr((t),(n),(e),(i),(c),(r),(a),(sizeof(TX_TIMER))) +#else #define tx_timer_create_ptr _tx_timer_create_ptr #endif +#endif #define tx_timer_create _tx_timer_create #define tx_timer_deactivate _tx_timer_deactivate #define tx_timer_delete _tx_timer_delete @@ -1281,7 +1297,7 @@ UINT _tx_trace_interrupt_control(UINT new_posture); #define tx_semaphore_put _txr_semaphore_put #define tx_semaphore_put_notify _txr_semaphore_put_notify -#if defined(TX_ENABLE_POINTER_CONTEXT) && !defined(TXM_MODULE) +#ifdef TX_ENABLE_POINTER_CONTEXT #define tx_thread_create_ptr(t,n,e,i,s,l,p,r,c,a) _txe_thread_create_ptr((t),(n),(e),(i),(s),(l),(p),(r),(c),(a),(sizeof(TX_THREAD))) #endif #define tx_thread_create(t,n,e,i,s,l,p,r,c,a) _txr_thread_create((t),(n),(e),(i),(s),(l),(p),(r),(c),(a),(sizeof(TX_THREAD))) @@ -1307,7 +1323,7 @@ UINT _tx_trace_interrupt_control(UINT new_posture); #define tx_time_set _tx_time_set #define tx_timer_activate _txr_timer_activate #define tx_timer_change _txr_timer_change -#if defined(TX_ENABLE_POINTER_CONTEXT) && !defined(TXM_MODULE) +#ifdef TX_ENABLE_POINTER_CONTEXT #define tx_timer_create_ptr(t,n,e,i,c,r,a) _txe_timer_create_ptr((t),(n),(e),(i),(c),(r),(a),(sizeof(TX_TIMER))) #endif #define tx_timer_create(t,n,e,i,c,r,a) _txr_timer_create((t),(n),(e),(i),(c),(r),(a),(sizeof(TX_TIMER))) @@ -1398,7 +1414,7 @@ UINT _tx_el_interrupt_control(UINT new_posture); #define tx_semaphore_put _txe_semaphore_put #define tx_semaphore_put_notify _txe_semaphore_put_notify -#if defined(TX_ENABLE_POINTER_CONTEXT) && !defined(TXM_MODULE) +#ifdef TX_ENABLE_POINTER_CONTEXT #define tx_thread_create_ptr(t,n,e,i,s,l,p,r,c,a) _txe_thread_create_ptr((t),(n),(e),(i),(s),(l),(p),(r),(c),(a),(sizeof(TX_THREAD))) #endif #define tx_thread_create(t,n,e,i,s,l,p,r,c,a) _txe_thread_create((t),(n),(e),(i),(s),(l),(p),(r),(c),(a),(sizeof(TX_THREAD))) @@ -1424,7 +1440,7 @@ UINT _tx_el_interrupt_control(UINT new_posture); #define tx_time_set _tx_time_set #define tx_timer_activate _txe_timer_activate #define tx_timer_change _txe_timer_change -#if defined(TX_ENABLE_POINTER_CONTEXT) && !defined(TXM_MODULE) +#ifdef TX_ENABLE_POINTER_CONTEXT #define tx_timer_create_ptr(t,n,e,i,c,r,a) _txe_timer_create_ptr((t),(n),(e),(i),(c),(r),(a),(sizeof(TX_TIMER))) #endif #define tx_timer_create(t,n,e,i,c,r,a) _txe_timer_create((t),(n),(e),(i),(c),(r),(a),(sizeof(TX_TIMER))) diff --git a/common/inc/tx_timer.h b/common/inc/tx_timer.h index b49c573e6..7b8baaf0b 100644 --- a/common/inc/tx_timer.h +++ b/common/inc/tx_timer.h @@ -8,6 +8,7 @@ * * SPDX-License-Identifier: MIT **************************************************************************/ +// Portions of this file were generated with AI assistance. /**************************************************************************/ @@ -204,4 +205,16 @@ TIMER_DECLARE ULONG _tx_timer_performance__expiration_adjust_count; #endif +#ifdef TX_ENABLE_POINTER_CONTEXT +UINT _tx_timer_create_ptr_dispatch(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*expiration_function)(VOID *), VOID *expiration_input, + TX_TIMER_POINTER_DISPATCH dispatch, VOID *owner, + ULONG initial_ticks, ULONG reschedule_ticks, UINT auto_activate); +UINT _txe_timer_create_ptr_dispatch(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*expiration_function)(VOID *), VOID *expiration_input, + TX_TIMER_POINTER_DISPATCH dispatch, VOID *owner, + ULONG initial_ticks, ULONG reschedule_ticks, UINT auto_activate, + UINT timer_control_block_size); +#endif + #endif diff --git a/common/inc/tx_user_sample.h b/common/inc/tx_user_sample.h index cc73ce81a..f06e113d3 100644 --- a/common/inc/tx_user_sample.h +++ b/common/inc/tx_user_sample.h @@ -198,8 +198,8 @@ */ /* Enable tx_thread_create_ptr and tx_timer_create_ptr with VOID * contexts. - Use the same setting when building ThreadX and its applications, since - this option adds callback storage to TX_THREAD and TX_TIMER. */ + Use the same setting for the kernel, applications, Module Manager, module + library, and loadable modules. It changes the TX_THREAD and TX_TIMER sizes. */ /* #define TX_ENABLE_POINTER_CONTEXT diff --git a/common/src/tx_timer_create.c b/common/src/tx_timer_create.c index 82636c2ea..ee27ef70e 100644 --- a/common/src/tx_timer_create.c +++ b/common/src/tx_timer_create.c @@ -72,12 +72,14 @@ static UINT _tx_timer_create_initial(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, VOID (*expiration_function)(ULONG id), ULONG expiration_input, VOID (*expiration_function_ptr)(VOID *id), VOID *expiration_input_ptr, + TX_TIMER_POINTER_DISPATCH dispatch, VOID *owner, ULONG initial_ticks, ULONG reschedule_ticks, UINT auto_activate); /**************************************************************************/ static UINT _tx_timer_create_initial(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, VOID (*expiration_function)(ULONG id), ULONG expiration_input, VOID (*expiration_function_ptr)(VOID *id), VOID *expiration_input_ptr, + TX_TIMER_POINTER_DISPATCH dispatch, VOID *owner, ULONG initial_ticks, ULONG reschedule_ticks, UINT auto_activate) #else UINT _tx_timer_create(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, @@ -104,6 +106,8 @@ TX_TIMER *previous_timer; #ifdef TX_ENABLE_POINTER_CONTEXT timer_ptr -> tx_timer_timeout_function_ptr = expiration_function_ptr; timer_ptr -> tx_timer_timeout_param_ptr = expiration_input_ptr; + timer_ptr -> tx_timer_timeout_dispatch = dispatch; + timer_ptr -> tx_timer_timeout_owner = owner; #endif /* Disable interrupts to put the timer on the created list. */ @@ -215,7 +219,7 @@ UINT _tx_timer_create(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, { return(_tx_timer_create_initial(timer_ptr, name_ptr, expiration_function, expiration_input, - TX_NULL, TX_NULL, + TX_NULL, TX_NULL, TX_NULL, TX_NULL, initial_ticks, reschedule_ticks, auto_activate)); } @@ -255,7 +259,18 @@ UINT _tx_timer_create_ptr(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, { return(_tx_timer_create_initial(timer_ptr, name_ptr, TX_NULL, 0, - expiration_function, expiration_input, + expiration_function, expiration_input, TX_NULL, TX_NULL, + initial_ticks, reschedule_ticks, auto_activate)); +} + +/* Create a pointer timer with owner-specific callback delivery. */ +UINT _tx_timer_create_ptr_dispatch(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*expiration_function)(VOID *), VOID *expiration_input, + TX_TIMER_POINTER_DISPATCH dispatch, VOID *owner, + ULONG initial_ticks, ULONG reschedule_ticks, UINT auto_activate) +{ + return(_tx_timer_create_initial(timer_ptr, name_ptr, TX_NULL, 0UL, + expiration_function, expiration_input, dispatch, owner, initial_ticks, reschedule_ticks, auto_activate)); } #endif /* TX_ENABLE_POINTER_CONTEXT */ diff --git a/common/src/tx_timer_expiration_process.c b/common/src/tx_timer_expiration_process.c index f5d0722e1..44087c731 100644 --- a/common/src/tx_timer_expiration_process.c +++ b/common/src/tx_timer_expiration_process.c @@ -93,6 +93,8 @@ ULONG timeout_param = ((ULONG) 0); VOID (*timeout_function_ptr)(VOID *id); VOID *timeout_param_ptr = TX_NULL; TX_TIMER *pointer_timer; +TX_TIMER_POINTER_DISPATCH timeout_dispatch = TX_NULL; +VOID *timeout_owner = TX_NULL; #endif #ifdef TX_TIMER_ENABLE_PERFORMANCE_INFO TX_TIMER *timer_ptr; @@ -324,6 +326,8 @@ TX_TIMER *timer_ptr; TX_USER_TIMER_POINTER_GET(current_timer, pointer_timer) timeout_function_ptr = pointer_timer -> tx_timer_timeout_function_ptr; timeout_param_ptr = pointer_timer -> tx_timer_timeout_param_ptr; + timeout_dispatch = pointer_timer -> tx_timer_timeout_dispatch; + timeout_owner = pointer_timer -> tx_timer_timeout_owner; } #endif @@ -364,7 +368,14 @@ TX_TIMER *timer_ptr; if (timeout_function_ptr != TX_NULL) { - (timeout_function_ptr) (timeout_param_ptr); + if (timeout_dispatch != TX_NULL) + { + (timeout_dispatch)(timeout_owner, timeout_function_ptr, timeout_param_ptr); + } + else + { + (timeout_function_ptr)(timeout_param_ptr); + } } else #endif diff --git a/common/src/tx_timer_thread_entry.c b/common/src/tx_timer_thread_entry.c index e932c2724..f80dba218 100644 --- a/common/src/tx_timer_thread_entry.c +++ b/common/src/tx_timer_thread_entry.c @@ -83,6 +83,8 @@ ULONG timeout_param = ((ULONG) 0); VOID (*timeout_function_ptr)(VOID *id); VOID *timeout_param_ptr = TX_NULL; TX_TIMER *pointer_timer; +TX_TIMER_POINTER_DISPATCH timeout_dispatch = TX_NULL; +VOID *timeout_owner = TX_NULL; #endif TX_THREAD *thread_ptr; #ifdef TX_REACTIVATE_INLINE @@ -276,6 +278,8 @@ TX_TIMER *timer_ptr; TX_USER_TIMER_POINTER_GET(current_timer, pointer_timer) timeout_function_ptr = pointer_timer -> tx_timer_timeout_function_ptr; timeout_param_ptr = pointer_timer -> tx_timer_timeout_param_ptr; + timeout_dispatch = pointer_timer -> tx_timer_timeout_dispatch; + timeout_owner = pointer_timer -> tx_timer_timeout_owner; } #endif @@ -316,7 +320,14 @@ TX_TIMER *timer_ptr; if (timeout_function_ptr != TX_NULL) { - (timeout_function_ptr) (timeout_param_ptr); + if (timeout_dispatch != TX_NULL) + { + (timeout_dispatch)(timeout_owner, timeout_function_ptr, timeout_param_ptr); + } + else + { + (timeout_function_ptr)(timeout_param_ptr); + } } else #endif diff --git a/common/src/txe_timer_create.c b/common/src/txe_timer_create.c index a7f1f79b1..1f6123b4d 100644 --- a/common/src/txe_timer_create.c +++ b/common/src/txe_timer_create.c @@ -79,12 +79,14 @@ static UINT _txe_timer_create_initial(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, VOID (*expiration_function)(ULONG id), ULONG expiration_input, VOID (*expiration_function_ptr)(VOID *id), VOID *expiration_input_ptr, + TX_TIMER_POINTER_DISPATCH dispatch, VOID *owner, ULONG initial_ticks, ULONG reschedule_ticks, UINT auto_activate, UINT timer_control_block_size); /**************************************************************************/ static UINT _txe_timer_create_initial(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, VOID (*expiration_function)(ULONG id), ULONG expiration_input, VOID (*expiration_function_ptr)(VOID *id), VOID *expiration_input_ptr, + TX_TIMER_POINTER_DISPATCH dispatch, VOID *owner, ULONG initial_ticks, ULONG reschedule_ticks, UINT auto_activate, UINT timer_control_block_size) #else UINT _txe_timer_create(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, @@ -238,8 +240,8 @@ TX_THREAD *thread_ptr; #ifdef TX_ENABLE_POINTER_CONTEXT if (expiration_function_ptr != TX_NULL) { - status = _tx_timer_create_ptr(timer_ptr, name_ptr, - expiration_function_ptr, expiration_input_ptr, + status = _tx_timer_create_ptr_dispatch(timer_ptr, name_ptr, + expiration_function_ptr, expiration_input_ptr, dispatch, owner, initial_ticks, reschedule_ticks, auto_activate); } else @@ -298,7 +300,7 @@ UINT _txe_timer_create(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, { return(_txe_timer_create_initial(timer_ptr, name_ptr, expiration_function, expiration_input, - TX_NULL, TX_NULL, + TX_NULL, TX_NULL, TX_NULL, TX_NULL, initial_ticks, reschedule_ticks, auto_activate, timer_control_block_size)); } @@ -344,8 +346,21 @@ UINT _txe_timer_create_ptr(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, { return(_txe_timer_create_initial(timer_ptr, name_ptr, TX_NULL, 0, - expiration_function, expiration_input, + expiration_function, expiration_input, TX_NULL, TX_NULL, initial_ticks, reschedule_ticks, auto_activate, timer_control_block_size)); } + +/* Validate a pointer timer request and carry its callback to the owner's dispatcher. */ +UINT _txe_timer_create_ptr_dispatch(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*expiration_function)(VOID *), VOID *expiration_input, + TX_TIMER_POINTER_DISPATCH dispatch, VOID *owner, + ULONG initial_ticks, ULONG reschedule_ticks, UINT auto_activate, + UINT timer_control_block_size) +{ + return(_txe_timer_create_initial(timer_ptr, name_ptr, TX_NULL, 0UL, + expiration_function, expiration_input, dispatch, owner, + initial_ticks, reschedule_ticks, auto_activate, + timer_control_block_size)); +} #endif /* TX_ENABLE_POINTER_CONTEXT */ diff --git a/common_modules/inc/txm_module.h b/common_modules/inc/txm_module.h index 2a4764842..0b35844b2 100644 --- a/common_modules/inc/txm_module.h +++ b/common_modules/inc/txm_module.h @@ -224,6 +224,7 @@ extern "C" { #define TXM_QUEUE_SEND_CALLBACK 2 #define TXM_SEMAPHORE_PUT_CALLBACK 3 #define TXM_THREAD_ENTRY_EXIT_CALLBACK 4 +#define TXM_TIMER_CALLBACK_PTR 5 /* Determine the ThreadX kernel API call IDs. */ @@ -324,6 +325,8 @@ extern "C" { #define TXM_MODULE_OBJECT_POINTER_GET_EXTENDED_CALL 94 #define TXM_MODULE_OBJECT_ALLOCATE_CALL 95 #define TXM_MODULE_OBJECT_DEALLOCATE_CALL 96 +#define TXM_THREAD_CREATE_PTR_CALL 97 +#define TXM_TIMER_CREATE_PTR_CALL 98 #define TXM_MODULE_PORT_EXTENSION_API_ID_START 500 #define TXM_MODULE_PORT_EXTENSION_API_ID_END 999 @@ -493,6 +496,10 @@ typedef struct TXM_MODULE_THREAD_ENTRY_INFO_STRUCT VOID *txm_module_thread_entry_info_reserved; ALIGN_TYPE (*txm_module_thread_entry_info_kernel_call_dispatcher)(ULONG kernel_request, ALIGN_TYPE param_1, ALIGN_TYPE param_2, ALIGN_TYPE param_3); TXM_MODULE_THREAD_ENTRY_INFO_USER_EXTENSION +#ifdef TX_ENABLE_POINTER_CONTEXT + VOID (*txm_module_thread_entry_info_entry_ptr)(VOID *input); + VOID *txm_module_thread_entry_info_parameter_ptr; +#endif } TXM_MODULE_THREAD_ENTRY_INFO; @@ -522,6 +529,27 @@ typedef struct TXM_MODULE_ALLOCATED_OBJECT_STRUCT extern ALIGN_TYPE (*_txm_module_kernel_call_dispatcher)(ULONG type, ALIGN_TYPE param_1, ALIGN_TYPE param_2, ALIGN_TYPE param3); +#ifdef TXM_MODULE +#ifdef TX_ENABLE_POINTER_CONTEXT +/* A pointer entry uses the typed fields reserved at the end of the entry info. */ +static inline VOID _txm_module_thread_entry_call(const TXM_MODULE_THREAD_ENTRY_INFO *thread_info) +{ + if (thread_info -> txm_module_thread_entry_info_entry == TX_NULL) + { + (thread_info -> txm_module_thread_entry_info_entry_ptr)(thread_info -> txm_module_thread_entry_info_parameter_ptr); + } + else + { + (thread_info -> txm_module_thread_entry_info_entry)(thread_info -> txm_module_thread_entry_info_parameter); + } +} +#define TXM_MODULE_THREAD_ENTRY_CALL(info) _txm_module_thread_entry_call(info) +#else +#define TXM_MODULE_THREAD_ENTRY_CALL(info) ((info) -> txm_module_thread_entry_info_entry)((info) -> txm_module_thread_entry_info_parameter) +#endif +#endif + + /* Define specific module function prototypes. */ #define txm_module_application_request _txm_module_application_request @@ -638,6 +666,13 @@ UINT _txm_module_manager_thread_create(TX_THREAD *thread_ptr, TX_NAME_CONST CHA VOID (*entry_function)(ULONG), ULONG entry_input, VOID *stack_start, ULONG stack_size, UINT priority, UINT preempt_threshold, ULONG time_slice, UINT auto_start, UINT thread_control_block_size, TXM_MODULE_INSTANCE *module_instance); +#ifdef TX_ENABLE_POINTER_CONTEXT +UINT _txm_module_manager_thread_create_ptr(TX_THREAD *thread_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*shell_function)(TX_THREAD *, TXM_MODULE_INSTANCE *), + VOID (*entry_function)(VOID *), VOID *entry_input, + VOID *stack_start, ULONG stack_size, UINT priority, UINT preempt_threshold, + ULONG time_slice, UINT auto_start, UINT thread_control_block_size, TXM_MODULE_INSTANCE *module_instance); +#endif UINT _txm_module_manager_thread_reset(TX_THREAD *thread_ptr); VOID _txm_module_manager_name_build(CHAR *module_name, CHAR *thread_name, CHAR *combined_name); VOID _txm_module_manager_thread_stack_build(TX_THREAD *thread_ptr, VOID (*shell_function)(TX_THREAD *, TXM_MODULE_INSTANCE *)); @@ -679,6 +714,9 @@ VOID _txm_module_manager_queue_notify_trampoline(TX_QUEUE *queue_ptr); VOID _txm_module_manager_semaphore_notify_trampoline(TX_SEMAPHORE *semaphore_ptr); VOID _txm_module_manager_thread_notify_trampoline(TX_THREAD *thread_ptr, UINT type); VOID _txm_module_manager_timer_notify_trampoline(ULONG id); +#ifdef TX_ENABLE_POINTER_CONTEXT +VOID _txm_module_manager_timer_notify_pointer(VOID *owner, VOID (*callback)(VOID *), VOID *id); +#endif /* Define port specific module manager prototypes. */ diff --git a/common_modules/inc/txm_module_user_sample.h b/common_modules/inc/txm_module_user_sample.h index 889e0b91c..196b63841 100644 --- a/common_modules/inc/txm_module_user_sample.h +++ b/common_modules/inc/txm_module_user_sample.h @@ -8,6 +8,7 @@ * * SPDX-License-Identifier: MIT **************************************************************************/ +// Portions of this file were generated with AI assistance. /**************************************************************************/ @@ -108,6 +109,7 @@ /* #define TXM_SEMAPHORE_PUT_CALL_NOT_USED */ /* #define TXM_SEMAPHORE_PUT_NOTIFY_CALL_NOT_USED */ /* #define TXM_THREAD_CREATE_CALL_NOT_USED */ +/* #define TXM_THREAD_CREATE_PTR_CALL_NOT_USED */ /* #define TXM_THREAD_DELETE_CALL_NOT_USED */ /* #define TXM_THREAD_ENTRY_EXIT_NOTIFY_CALL_NOT_USED */ /* #define TXM_THREAD_IDENTIFY_CALL_NOT_USED */ @@ -132,6 +134,7 @@ /* #define TXM_TIMER_ACTIVATE_CALL_NOT_USED */ /* #define TXM_TIMER_CHANGE_CALL_NOT_USED */ /* #define TXM_TIMER_CREATE_CALL_NOT_USED */ +/* #define TXM_TIMER_CREATE_PTR_CALL_NOT_USED */ /* #define TXM_TIMER_DEACTIVATE_CALL_NOT_USED */ /* #define TXM_TIMER_DELETE_CALL_NOT_USED */ /* #define TXM_TIMER_INFO_GET_CALL_NOT_USED */ diff --git a/common_modules/module_lib/src/txm_module_callback_request_thread_entry.c b/common_modules/module_lib/src/txm_module_callback_request_thread_entry.c index cf030f928..e45f719f7 100644 --- a/common_modules/module_lib/src/txm_module_callback_request_thread_entry.c +++ b/common_modules/module_lib/src/txm_module_callback_request_thread_entry.c @@ -8,6 +8,7 @@ * * SPDX-License-Identifier: MIT **************************************************************************/ +// Portions of this file were generated with AI assistance. /**************************************************************************/ @@ -82,6 +83,9 @@ TX_QUEUE *request_queue; TXM_MODULE_CALLBACK_MESSAGE callback_message; ULONG activation_count; VOID (*timer_callback)(ULONG); +#if defined(TX_ENABLE_POINTER_CONTEXT) && !defined(TXM_TIMER_CREATE_PTR_CALL_NOT_USED) +VOID (*timer_callback_ptr)(VOID *); +#endif VOID (*events_set_notify)(TX_EVENT_FLAGS_GROUP *); VOID (*semaphore_put_notify)(TX_SEMAPHORE *); VOID (*queue_send_notify)(TX_QUEUE *); @@ -133,6 +137,17 @@ UINT status; break; +#if defined(TX_ENABLE_POINTER_CONTEXT) && !defined(TXM_TIMER_CREATE_PTR_CALL_NOT_USED) + case TXM_TIMER_CALLBACK_PTR: + + /* Restore the original types used by the module caller. + MISRA C:2023 Rules 11.1 and 11.6 apply to the ABI casts. */ + timer_callback_ptr = (VOID (*)(VOID *)) callback_message.txm_module_callback_message_application_function; + (timer_callback_ptr)((VOID *) callback_message.txm_module_callback_message_param_1); + + break; +#endif + case TXM_EVENTS_SET_CALLBACK: /* Setup events set callback pointer. */ diff --git a/common_modules/module_lib/src/txm_thread_create.c b/common_modules/module_lib/src/txm_thread_create.c index f17a01859..ea0882ee3 100644 --- a/common_modules/module_lib/src/txm_thread_create.c +++ b/common_modules/module_lib/src/txm_thread_create.c @@ -95,3 +95,30 @@ ALIGN_TYPE extra_parameters[9]; return(return_value); } #endif + +#if defined(TX_ENABLE_POINTER_CONTEXT) && !defined(TXM_THREAD_CREATE_PTR_CALL_NOT_USED) +/* Pack the typed entry and context for the Module Manager. MISRA C:2023 + Rules 11.1 and 11.6 apply to the address-sized dispatch arguments. */ +UINT _txe_thread_create_ptr(TX_THREAD *thread_ptr, TX_NAME_CONST CHAR *name_ptr, VOID (*entry_function)(VOID *id), VOID *entry_input, VOID *stack_start, ULONG stack_size, UINT priority, UINT preempt_threshold, ULONG time_slice, UINT auto_start, UINT thread_control_block_size) +{ + +UINT return_value; +ALIGN_TYPE extra_parameters[9]; + + extra_parameters[0] = (ALIGN_TYPE) entry_function; + extra_parameters[1] = (ALIGN_TYPE) entry_input; + extra_parameters[2] = (ALIGN_TYPE) stack_start; + extra_parameters[3] = (ALIGN_TYPE) stack_size; + extra_parameters[4] = (ALIGN_TYPE) priority; + extra_parameters[5] = (ALIGN_TYPE) preempt_threshold; + extra_parameters[6] = (ALIGN_TYPE) time_slice; + extra_parameters[7] = (ALIGN_TYPE) auto_start; + extra_parameters[8] = (ALIGN_TYPE) thread_control_block_size; + + /* Call module manager dispatcher. */ + return_value = (UINT) (_txm_module_kernel_call_dispatcher)(TXM_THREAD_CREATE_PTR_CALL, (ALIGN_TYPE) thread_ptr, (ALIGN_TYPE) name_ptr, (ALIGN_TYPE) extra_parameters); + + /* Return value to the caller. */ + return(return_value); +} +#endif diff --git a/common_modules/module_lib/src/txm_timer_create.c b/common_modules/module_lib/src/txm_timer_create.c index 7adba9010..f90379101 100644 --- a/common_modules/module_lib/src/txm_timer_create.c +++ b/common_modules/module_lib/src/txm_timer_create.c @@ -87,3 +87,25 @@ ALIGN_TYPE extra_parameters[6]; return(return_value); } #endif + +#if defined(TX_ENABLE_POINTER_CONTEXT) && !defined(TXM_TIMER_CREATE_PTR_CALL_NOT_USED) +/* Pack a pointer timer request for the module manager. */ +UINT _txe_timer_create_ptr(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*expiration_function)(VOID *), VOID *expiration_input, + ULONG initial_ticks, ULONG reschedule_ticks, UINT auto_activate, UINT timer_control_block_size) +{ +ALIGN_TYPE extra_parameters[6]; + + /* The module dispatcher carries addresses in ABI words. + MISRA C:2023 Rules 11.1 and 11.6 apply to the packing casts. */ + extra_parameters[0] = (ALIGN_TYPE) expiration_function; + extra_parameters[1] = (ALIGN_TYPE) expiration_input; + extra_parameters[2] = (ALIGN_TYPE) initial_ticks; + extra_parameters[3] = (ALIGN_TYPE) reschedule_ticks; + extra_parameters[4] = (ALIGN_TYPE) auto_activate; + extra_parameters[5] = (ALIGN_TYPE) timer_control_block_size; + + return((UINT) (_txm_module_kernel_call_dispatcher)(TXM_TIMER_CREATE_PTR_CALL, (ALIGN_TYPE) timer_ptr, + (ALIGN_TYPE) name_ptr, (ALIGN_TYPE) extra_parameters)); +} +#endif diff --git a/common_modules/module_manager/inc/txm_module_manager_dispatch.h b/common_modules/module_manager/inc/txm_module_manager_dispatch.h index cc9dac2f2..3fd7b4fc6 100644 --- a/common_modules/module_manager/inc/txm_module_manager_dispatch.h +++ b/common_modules/module_manager/inc/txm_module_manager_dispatch.h @@ -2055,7 +2055,7 @@ VOID (*semaphore_put_notify)(TX_SEMAPHORE *); } #endif -#ifndef TXM_THREAD_CREATE_CALL_NOT_USED +#if !defined(TXM_THREAD_CREATE_CALL_NOT_USED) || (defined(TX_ENABLE_POINTER_CONTEXT) && !defined(TXM_THREAD_CREATE_PTR_CALL_NOT_USED)) /* UINT _txe_thread_create( TX_THREAD *thread_ptr, -> param_0 TX_NAME_CONST CHAR *name_ptr, -> param_1 @@ -2069,10 +2069,17 @@ VOID (*semaphore_put_notify)(TX_SEMAPHORE *); UINT auto_start, -> extra_parameters[7] UINT thread_control_block_size -> extra_parameters[8] ); */ -static ALIGN_TYPE _txm_module_manager_tx_thread_create_dispatch(TXM_MODULE_INSTANCE *module_instance, ALIGN_TYPE param_0, ALIGN_TYPE param_1, ALIGN_TYPE *extra_parameters) +static ALIGN_TYPE _txm_module_manager_tx_thread_create_dispatch(TXM_MODULE_INSTANCE *module_instance, ALIGN_TYPE param_0, ALIGN_TYPE param_1, + ALIGN_TYPE *extra_parameters +#if defined(TX_ENABLE_POINTER_CONTEXT) && !defined(TXM_THREAD_CREATE_PTR_CALL_NOT_USED) && !defined(TXM_THREAD_CREATE_CALL_NOT_USED) + , UINT pointer_context +#endif + ) { +#ifndef TXM_THREAD_CREATE_CALL_NOT_USED ALIGN_TYPE return_value; +#endif if (module_instance -> txm_module_instance_property_flags & TXM_MODULE_MEMORY_PROTECTION) { @@ -2095,6 +2102,24 @@ ALIGN_TYPE return_value; return(TX_THRESH_ERROR); } +#if defined(TX_ENABLE_POINTER_CONTEXT) && !defined(TXM_THREAD_CREATE_PTR_CALL_NOT_USED) +#ifndef TXM_THREAD_CREATE_CALL_NOT_USED + if (pointer_context == TX_TRUE) +#endif + { + /* The module library packs the original pointer types as dispatch words. + MISRA C:2023 Rules 11.1 and 11.6 apply to restoring those types. */ + return((ALIGN_TYPE) _txm_module_manager_thread_create_ptr( + (TX_THREAD *) param_0, (TX_NAME_CONST CHAR *) param_1, + module_instance -> txm_module_instance_shell_entry_function, + (VOID (*)(VOID *)) extra_parameters[0], (VOID *) extra_parameters[1], + (VOID *) extra_parameters[2], (ULONG) extra_parameters[3], + (UINT) extra_parameters[4], (UINT) extra_parameters[5], (ULONG) extra_parameters[6], + (UINT) extra_parameters[7], (UINT) extra_parameters[8], module_instance)); + } +#endif + +#ifndef TXM_THREAD_CREATE_CALL_NOT_USED return_value = (ALIGN_TYPE) _txm_module_manager_thread_create( (TX_THREAD *) param_0, (TX_NAME_CONST CHAR *) param_1, @@ -2111,6 +2136,7 @@ ALIGN_TYPE return_value; module_instance ); return(return_value); +#endif } #endif @@ -2896,7 +2922,7 @@ ALIGN_TYPE return_value; } #endif -#ifndef TXM_TIMER_CREATE_CALL_NOT_USED +#if !defined(TXM_TIMER_CREATE_CALL_NOT_USED) || (defined(TX_ENABLE_POINTER_CONTEXT) && !defined(TXM_TIMER_CREATE_PTR_CALL_NOT_USED)) /* UINT _txe_timer_create( TX_TIMER *timer_ptr, -> param_0 TX_NAME_CONST CHAR *name_ptr, -> param_1 @@ -2907,12 +2933,19 @@ ALIGN_TYPE return_value; UINT auto_activate, -> extra_parameters[4] UINT timer_control_block_size -> extra_parameters[5] ); */ -static ALIGN_TYPE _txm_module_manager_tx_timer_create_dispatch(TXM_MODULE_INSTANCE *module_instance, ALIGN_TYPE param_0, ALIGN_TYPE param_1, ALIGN_TYPE *extra_parameters) +static ALIGN_TYPE _txm_module_manager_tx_timer_create_dispatch(TXM_MODULE_INSTANCE *module_instance, ALIGN_TYPE param_0, ALIGN_TYPE param_1, + ALIGN_TYPE *extra_parameters +#if defined(TX_ENABLE_POINTER_CONTEXT) && !defined(TXM_TIMER_CREATE_PTR_CALL_NOT_USED) && !defined(TXM_TIMER_CREATE_CALL_NOT_USED) + , UINT pointer_context +#endif + ) { +#ifndef TXM_TIMER_CREATE_CALL_NOT_USED ALIGN_TYPE return_value; TX_TIMER *timer_ptr; VOID (*expiration_function)(ULONG); +#endif if (module_instance -> txm_module_instance_property_flags & TXM_MODULE_MEMORY_PROTECTION) { @@ -2926,6 +2959,23 @@ VOID (*expiration_function)(ULONG); return(TXM_MODULE_INVALID_MEMORY); } +#if defined(TX_ENABLE_POINTER_CONTEXT) && !defined(TXM_TIMER_CREATE_PTR_CALL_NOT_USED) +#ifndef TXM_TIMER_CREATE_CALL_NOT_USED + if (pointer_context == TX_TRUE) +#endif + { + /* Restore the pointer types from the module dispatch words. + MISRA C:2023 Rules 11.1 and 11.6 apply to those casts. */ + return((ALIGN_TYPE) _txe_timer_create_ptr_dispatch( + (TX_TIMER *) param_0, (TX_NAME_CONST CHAR *) param_1, + (VOID (*)(VOID *)) extra_parameters[0], (VOID *) extra_parameters[1], + _txm_module_manager_timer_notify_pointer, module_instance, + (ULONG) extra_parameters[2], (ULONG) extra_parameters[3], + (UINT) extra_parameters[4], (UINT) extra_parameters[5])); + } +#endif + +#ifndef TXM_TIMER_CREATE_CALL_NOT_USED /* Is it a disable request? */ if ((void *) extra_parameters[0] == TX_NULL) { @@ -2966,6 +3016,7 @@ VOID (*expiration_function)(ULONG); } } return(return_value); +#endif } #endif diff --git a/common_modules/module_manager/src/txm_module_manager_callback_request.c b/common_modules/module_manager/src/txm_module_manager_callback_request.c index bae5c00bc..9a6e0729b 100644 --- a/common_modules/module_manager/src/txm_module_manager_callback_request.c +++ b/common_modules/module_manager/src/txm_module_manager_callback_request.c @@ -8,6 +8,7 @@ * * SPDX-License-Identifier: MIT **************************************************************************/ +// Portions of this file were generated with AI assistance. /**************************************************************************/ @@ -96,6 +97,9 @@ UINT status; /* Does this entry match the new callback message? */ if ((queued_message -> txm_module_callback_message_application_function == callback_message -> txm_module_callback_message_application_function) && +#if defined(TX_ENABLE_POINTER_CONTEXT) && !defined(TXM_TIMER_CREATE_PTR_CALL_NOT_USED) + (queued_message -> txm_module_callback_message_type == callback_message -> txm_module_callback_message_type) && +#endif (queued_message -> txm_module_callback_message_param_1 == callback_message -> txm_module_callback_message_param_1) && (queued_message -> txm_module_callback_message_param_2 == callback_message -> txm_module_callback_message_param_2) && (queued_message -> txm_module_callback_message_param_3 == callback_message -> txm_module_callback_message_param_3) && diff --git a/common_modules/module_manager/src/txm_module_manager_kernel_dispatch.c b/common_modules/module_manager/src/txm_module_manager_kernel_dispatch.c index aa377430d..bacafc594 100644 --- a/common_modules/module_manager/src/txm_module_manager_kernel_dispatch.c +++ b/common_modules/module_manager/src/txm_module_manager_kernel_dispatch.c @@ -8,6 +8,7 @@ * * SPDX-License-Identifier: MIT **************************************************************************/ +// Portions of this file were generated with AI assistance. /**************************************************************************/ @@ -524,7 +525,24 @@ TXM_MODULE_INSTANCE *module_instance; #ifndef TXM_THREAD_CREATE_CALL_NOT_USED case TXM_THREAD_CREATE_CALL: { - return_value = _txm_module_manager_tx_thread_create_dispatch(module_instance, param_0, param_1, (ALIGN_TYPE *) param_2); + return_value = _txm_module_manager_tx_thread_create_dispatch(module_instance, param_0, param_1, (ALIGN_TYPE *) param_2 + #if defined(TX_ENABLE_POINTER_CONTEXT) && !defined(TXM_THREAD_CREATE_PTR_CALL_NOT_USED) + , TX_FALSE + #endif + ); + break; + } + #endif + + #if defined(TX_ENABLE_POINTER_CONTEXT) && !defined(TXM_THREAD_CREATE_PTR_CALL_NOT_USED) + case TXM_THREAD_CREATE_PTR_CALL: + { + return_value = _txm_module_manager_tx_thread_create_dispatch(module_instance, param_0, param_1, + (ALIGN_TYPE *) param_2 + #ifndef TXM_THREAD_CREATE_CALL_NOT_USED + , TX_TRUE + #endif + ); break; } #endif @@ -716,7 +734,25 @@ TXM_MODULE_INSTANCE *module_instance; #ifndef TXM_TIMER_CREATE_CALL_NOT_USED case TXM_TIMER_CREATE_CALL: { - return_value = _txm_module_manager_tx_timer_create_dispatch(module_instance, param_0, param_1, (ALIGN_TYPE *) param_2); + return_value = _txm_module_manager_tx_timer_create_dispatch(module_instance, param_0, param_1, + (ALIGN_TYPE *) param_2 + #if defined(TX_ENABLE_POINTER_CONTEXT) && !defined(TXM_TIMER_CREATE_PTR_CALL_NOT_USED) + , TX_FALSE + #endif + ); + break; + } + #endif + + #if defined(TX_ENABLE_POINTER_CONTEXT) && !defined(TXM_TIMER_CREATE_PTR_CALL_NOT_USED) + case TXM_TIMER_CREATE_PTR_CALL: + { + return_value = _txm_module_manager_tx_timer_create_dispatch(module_instance, param_0, param_1, + (ALIGN_TYPE *) param_2 + #ifndef TXM_TIMER_CREATE_CALL_NOT_USED + , TX_TRUE + #endif + ); break; } #endif diff --git a/common_modules/module_manager/src/txm_module_manager_thread_create.c b/common_modules/module_manager/src/txm_module_manager_thread_create.c index 51b85e1b4..24a7c1dbb 100644 --- a/common_modules/module_manager/src/txm_module_manager_thread_create.c +++ b/common_modules/module_manager/src/txm_module_manager_thread_create.c @@ -84,12 +84,22 @@ /* _txm_module_manager_kernel_dispatch Kernel dispatch function */ /* */ /**************************************************************************/ +#ifdef TX_ENABLE_POINTER_CONTEXT +static UINT _txm_module_manager_thread_create_initial(TX_THREAD *thread_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*shell_function)(TX_THREAD *, TXM_MODULE_INSTANCE *), + VOID (*entry_function)(ULONG id), ULONG entry_input, + VOID (*entry_function_ptr)(VOID *), VOID *entry_input_ptr, + VOID *stack_start, ULONG stack_size, UINT priority, UINT preempt_threshold, + ULONG time_slice, UINT auto_start, + UINT thread_control_block_size, TXM_MODULE_INSTANCE *module_instance) +#else UINT _txm_module_manager_thread_create(TX_THREAD *thread_ptr, TX_NAME_CONST CHAR *name_ptr, VOID (*shell_function)(TX_THREAD *, TXM_MODULE_INSTANCE *), VOID (*entry_function)(ULONG id), ULONG entry_input, VOID *stack_start, ULONG stack_size, UINT priority, UINT preempt_threshold, ULONG time_slice, UINT auto_start, UINT thread_control_block_size, TXM_MODULE_INSTANCE *module_instance) +#endif { TX_INTERRUPT_SAVE_AREA @@ -193,7 +203,11 @@ ULONG i; } /* Check for invalid thread entry point. */ +#ifdef TX_ENABLE_POINTER_CONTEXT + if ((entry_function == TX_NULL) && (entry_function_ptr == TX_NULL)) +#else if (entry_function == TX_NULL) +#endif { /* Invalid stack or entry point, return appropriate error code. */ @@ -372,6 +386,10 @@ ULONG i; thread_ptr -> tx_thread_name = name_ptr; thread_ptr -> tx_thread_entry = entry_function; thread_ptr -> tx_thread_entry_parameter = entry_input; +#ifdef TX_ENABLE_POINTER_CONTEXT + thread_ptr -> tx_thread_entry_ptr = entry_function_ptr; + thread_ptr -> tx_thread_entry_parameter_ptr = entry_input_ptr; +#endif thread_ptr -> tx_thread_stack_start = stack_start; thread_ptr -> tx_thread_stack_size = stack_size; thread_ptr -> tx_thread_priority = priority; @@ -457,6 +475,10 @@ ULONG i; thread_entry_info -> txm_module_thread_entry_info_code_base_address = module_instance -> txm_module_instance_code_start; thread_entry_info -> txm_module_thread_entry_info_entry = thread_ptr -> tx_thread_entry; thread_entry_info -> txm_module_thread_entry_info_parameter = thread_ptr -> tx_thread_entry_parameter; +#ifdef TX_ENABLE_POINTER_CONTEXT + thread_entry_info -> txm_module_thread_entry_info_entry_ptr = thread_ptr -> tx_thread_entry_ptr; + thread_entry_info -> txm_module_thread_entry_info_parameter_ptr = thread_ptr -> tx_thread_entry_parameter_ptr; +#endif thread_entry_info -> txm_module_thread_entry_info_callback_request_queue = &(module_instance -> txm_module_instance_callback_request_queue); thread_entry_info -> txm_module_thread_entry_info_callback_request_thread = &(module_instance -> txm_module_instance_callback_request_thread); @@ -768,3 +790,33 @@ ULONG i; /* Return success. */ return(TX_SUCCESS); } + +#ifdef TX_ENABLE_POINTER_CONTEXT +/* Create a module thread that receives an ULONG entry argument. */ +UINT _txm_module_manager_thread_create(TX_THREAD *thread_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*shell_function)(TX_THREAD *, TXM_MODULE_INSTANCE *), + VOID (*entry_function)(ULONG id), ULONG entry_input, + VOID *stack_start, ULONG stack_size, UINT priority, UINT preempt_threshold, + ULONG time_slice, UINT auto_start, + UINT thread_control_block_size, TXM_MODULE_INSTANCE *module_instance) +{ + return(_txm_module_manager_thread_create_initial(thread_ptr, name_ptr, shell_function, + entry_function, entry_input, TX_NULL, TX_NULL, + stack_start, stack_size, priority, preempt_threshold, + time_slice, auto_start, thread_control_block_size, module_instance)); +} + +/* Create a module thread that receives a pointer entry argument. */ +UINT _txm_module_manager_thread_create_ptr(TX_THREAD *thread_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*shell_function)(TX_THREAD *, TXM_MODULE_INSTANCE *), + VOID (*entry_function)(VOID *id), VOID *entry_input, + VOID *stack_start, ULONG stack_size, UINT priority, UINT preempt_threshold, + ULONG time_slice, UINT auto_start, + UINT thread_control_block_size, TXM_MODULE_INSTANCE *module_instance) +{ + return(_txm_module_manager_thread_create_initial(thread_ptr, name_ptr, shell_function, + TX_NULL, 0UL, entry_function, entry_input, + stack_start, stack_size, priority, preempt_threshold, + time_slice, auto_start, thread_control_block_size, module_instance)); +} +#endif diff --git a/common_modules/module_manager/src/txm_module_manager_timer_notify_trampoline.c b/common_modules/module_manager/src/txm_module_manager_timer_notify_trampoline.c index b2df699bd..aa1fec03f 100644 --- a/common_modules/module_manager/src/txm_module_manager_timer_notify_trampoline.c +++ b/common_modules/module_manager/src/txm_module_manager_timer_notify_trampoline.c @@ -8,6 +8,7 @@ * * SPDX-License-Identifier: MIT **************************************************************************/ +// Portions of this file were generated with AI assistance. /**************************************************************************/ @@ -133,3 +134,39 @@ CHAR *internal_ptr; } } +#if defined(TX_ENABLE_POINTER_CONTEXT) && !defined(TXM_TIMER_CREATE_PTR_CALL_NOT_USED) +/* Queue a pointer timer expiration using the callback captured at expiration. */ +VOID _txm_module_manager_timer_notify_pointer(VOID *owner, VOID (*callback)(VOID *), VOID *id) +{ +TX_INTERRUPT_SAVE_AREA + +TXM_MODULE_INSTANCE *module_instance = owner; +TXM_MODULE_CALLBACK_MESSAGE callback_message = {0}; + + TX_DISABLE + + if ((module_instance -> txm_module_instance_id == TXM_MODULE_ID) && + (module_instance -> txm_module_instance_state == TXM_MODULE_STARTED)) + { + callback_message.txm_module_callback_message_type = TXM_TIMER_CALLBACK_PTR; + callback_message.txm_module_callback_message_activation_count = 1; + + /* The queue ABI stores a generic callback and pointer-width words. + MISRA C:2023 Rules 11.1 and 11.6 apply to these conversions. */ + callback_message.txm_module_callback_message_application_function = (VOID (*)(VOID)) callback; + callback_message.txm_module_callback_message_param_1 = (ALIGN_TYPE) id; + + TX_RESTORE + + _txm_module_manager_callback_request(&(module_instance -> txm_module_instance_callback_request_queue), + &callback_message); + } + else + { + _txm_module_manager_callback_error_count++; + + TX_RESTORE + } +} +#endif + diff --git a/common_smp/inc/tx_api.h b/common_smp/inc/tx_api.h index 7a9820b19..c498b5cdb 100644 --- a/common_smp/inc/tx_api.h +++ b/common_smp/inc/tx_api.h @@ -396,6 +396,12 @@ typedef struct TX_TIMER_INTERNAL_STRUCT #endif +#ifdef TX_ENABLE_POINTER_CONTEXT +/* Deliver a snapshotted pointer callback through the object's owner. */ +typedef VOID (*TX_TIMER_POINTER_DISPATCH)(VOID *owner, VOID (*callback)(VOID *), VOID *input); +#endif + + /* Define the timer structure utilized by the application. */ typedef struct TX_TIMER_STRUCT @@ -441,6 +447,8 @@ typedef struct TX_TIMER_STRUCT /* Pointer callback storage follows the port and user fields. */ VOID (*tx_timer_timeout_function_ptr)(VOID *input); VOID *tx_timer_timeout_param_ptr; + TX_TIMER_POINTER_DISPATCH tx_timer_timeout_dispatch; + VOID *tx_timer_timeout_owner; #endif } TX_TIMER; @@ -1248,9 +1256,13 @@ UINT _tx_el_interrupt_control(UINT new_posture); #define tx_semaphore_put _tx_semaphore_put #define tx_semaphore_put_notify _tx_semaphore_put_notify -#if defined(TX_ENABLE_POINTER_CONTEXT) && !defined(TXM_MODULE) +#ifdef TX_ENABLE_POINTER_CONTEXT +#ifdef TXM_MODULE +#define tx_thread_create_ptr(t,n,e,i,s,l,p,r,c,a) _txe_thread_create_ptr((t),(n),(e),(i),(s),(l),(p),(r),(c),(a),(sizeof(TX_THREAD))) +#else #define tx_thread_create_ptr _tx_thread_create_ptr #endif +#endif #define tx_thread_create _tx_thread_create #define tx_thread_delete _tx_thread_delete #define tx_thread_entry_exit_notify _tx_thread_entry_exit_notify @@ -1280,9 +1292,13 @@ UINT _tx_el_interrupt_control(UINT new_posture); #define tx_time_set _tx_time_set #define tx_timer_activate _tx_timer_activate #define tx_timer_change _tx_timer_change -#if defined(TX_ENABLE_POINTER_CONTEXT) && !defined(TXM_MODULE) +#ifdef TX_ENABLE_POINTER_CONTEXT +#ifdef TXM_MODULE +#define tx_timer_create_ptr(t,n,e,i,c,r,a) _txe_timer_create_ptr((t),(n),(e),(i),(c),(r),(a),(sizeof(TX_TIMER))) +#else #define tx_timer_create_ptr _tx_timer_create_ptr #endif +#endif #define tx_timer_create _tx_timer_create #define tx_timer_deactivate _tx_timer_deactivate #define tx_timer_delete _tx_timer_delete @@ -1382,7 +1398,7 @@ UINT _tx_el_interrupt_control(UINT new_posture); #define tx_semaphore_put _txr_semaphore_put #define tx_semaphore_put_notify _txr_semaphore_put_notify -#if defined(TX_ENABLE_POINTER_CONTEXT) && !defined(TXM_MODULE) +#ifdef TX_ENABLE_POINTER_CONTEXT #define tx_thread_create_ptr(t,n,e,i,s,l,p,r,c,a) _txe_thread_create_ptr((t),(n),(e),(i),(s),(l),(p),(r),(c),(a),(sizeof(TX_THREAD))) #endif #define tx_thread_create(t,n,e,i,s,l,p,r,c,a) _txr_thread_create((t),(n),(e),(i),(s),(l),(p),(r),(c),(a),(sizeof(TX_THREAD))) @@ -1414,7 +1430,7 @@ UINT _tx_el_interrupt_control(UINT new_posture); #define tx_time_set _tx_time_set #define tx_timer_activate _txr_timer_activate #define tx_timer_change _txr_timer_change -#if defined(TX_ENABLE_POINTER_CONTEXT) && !defined(TXM_MODULE) +#ifdef TX_ENABLE_POINTER_CONTEXT #define tx_timer_create_ptr(t,n,e,i,c,r,a) _txe_timer_create_ptr((t),(n),(e),(i),(c),(r),(a),(sizeof(TX_TIMER))) #endif #define tx_timer_create(t,n,e,i,c,r,a) _txr_timer_create((t),(n),(e),(i),(c),(r),(a),(sizeof(TX_TIMER))) @@ -1505,7 +1521,7 @@ UINT _tx_el_interrupt_control(UINT new_posture); #define tx_semaphore_put _txe_semaphore_put #define tx_semaphore_put_notify _txe_semaphore_put_notify -#if defined(TX_ENABLE_POINTER_CONTEXT) && !defined(TXM_MODULE) +#ifdef TX_ENABLE_POINTER_CONTEXT #define tx_thread_create_ptr(t,n,e,i,s,l,p,r,c,a) _txe_thread_create_ptr((t),(n),(e),(i),(s),(l),(p),(r),(c),(a),(sizeof(TX_THREAD))) #endif #define tx_thread_create(t,n,e,i,s,l,p,r,c,a) _txe_thread_create((t),(n),(e),(i),(s),(l),(p),(r),(c),(a),(sizeof(TX_THREAD))) @@ -1537,7 +1553,7 @@ UINT _tx_el_interrupt_control(UINT new_posture); #define tx_time_set _tx_time_set #define tx_timer_activate _txe_timer_activate #define tx_timer_change _txe_timer_change -#if defined(TX_ENABLE_POINTER_CONTEXT) && !defined(TXM_MODULE) +#ifdef TX_ENABLE_POINTER_CONTEXT #define tx_timer_create_ptr(t,n,e,i,c,r,a) _txe_timer_create_ptr((t),(n),(e),(i),(c),(r),(a),(sizeof(TX_TIMER))) #endif #define tx_timer_create(t,n,e,i,c,r,a) _txe_timer_create((t),(n),(e),(i),(c),(r),(a),(sizeof(TX_TIMER))) diff --git a/common_smp/inc/tx_timer.h b/common_smp/inc/tx_timer.h index 71a65b27a..8986afc9e 100644 --- a/common_smp/inc/tx_timer.h +++ b/common_smp/inc/tx_timer.h @@ -8,6 +8,7 @@ * * SPDX-License-Identifier: MIT **************************************************************************/ +// Portions of this file were generated with AI assistance. /**************************************************************************/ @@ -206,4 +207,16 @@ TIMER_DECLARE ULONG _tx_timer_performance__expiration_adjust_count; #endif +#ifdef TX_ENABLE_POINTER_CONTEXT +UINT _tx_timer_create_ptr_dispatch(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*expiration_function)(VOID *), VOID *expiration_input, + TX_TIMER_POINTER_DISPATCH dispatch, VOID *owner, + ULONG initial_ticks, ULONG reschedule_ticks, UINT auto_activate); +UINT _txe_timer_create_ptr_dispatch(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*expiration_function)(VOID *), VOID *expiration_input, + TX_TIMER_POINTER_DISPATCH dispatch, VOID *owner, + ULONG initial_ticks, ULONG reschedule_ticks, UINT auto_activate, + UINT timer_control_block_size); +#endif + #endif diff --git a/common_smp/src/tx_timer_create.c b/common_smp/src/tx_timer_create.c index e74236f0a..61358e4fa 100644 --- a/common_smp/src/tx_timer_create.c +++ b/common_smp/src/tx_timer_create.c @@ -73,12 +73,14 @@ static UINT _tx_timer_create_initial(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, VOID (*expiration_function)(ULONG id), ULONG expiration_input, VOID (*expiration_function_ptr)(VOID *id), VOID *expiration_input_ptr, + TX_TIMER_POINTER_DISPATCH dispatch, VOID *owner, ULONG initial_ticks, ULONG reschedule_ticks, UINT auto_activate); /**************************************************************************/ static UINT _tx_timer_create_initial(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, VOID (*expiration_function)(ULONG id), ULONG expiration_input, VOID (*expiration_function_ptr)(VOID *id), VOID *expiration_input_ptr, + TX_TIMER_POINTER_DISPATCH dispatch, VOID *owner, ULONG initial_ticks, ULONG reschedule_ticks, UINT auto_activate) #else UINT _tx_timer_create(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, @@ -105,6 +107,8 @@ TX_TIMER *previous_timer; #ifdef TX_ENABLE_POINTER_CONTEXT timer_ptr -> tx_timer_timeout_function_ptr = expiration_function_ptr; timer_ptr -> tx_timer_timeout_param_ptr = expiration_input_ptr; + timer_ptr -> tx_timer_timeout_dispatch = dispatch; + timer_ptr -> tx_timer_timeout_owner = owner; #endif #ifdef TX_THREAD_SMP_ONLY_CORE_0_DEFAULT @@ -222,7 +226,7 @@ UINT _tx_timer_create(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, { return(_tx_timer_create_initial(timer_ptr, name_ptr, expiration_function, expiration_input, - TX_NULL, TX_NULL, + TX_NULL, TX_NULL, TX_NULL, TX_NULL, initial_ticks, reschedule_ticks, auto_activate)); } @@ -262,7 +266,18 @@ UINT _tx_timer_create_ptr(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, { return(_tx_timer_create_initial(timer_ptr, name_ptr, TX_NULL, 0, - expiration_function, expiration_input, + expiration_function, expiration_input, TX_NULL, TX_NULL, + initial_ticks, reschedule_ticks, auto_activate)); +} + +/* Create a pointer timer with owner-specific callback delivery. */ +UINT _tx_timer_create_ptr_dispatch(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*expiration_function)(VOID *), VOID *expiration_input, + TX_TIMER_POINTER_DISPATCH dispatch, VOID *owner, + ULONG initial_ticks, ULONG reschedule_ticks, UINT auto_activate) +{ + return(_tx_timer_create_initial(timer_ptr, name_ptr, TX_NULL, 0UL, + expiration_function, expiration_input, dispatch, owner, initial_ticks, reschedule_ticks, auto_activate)); } #endif /* TX_ENABLE_POINTER_CONTEXT */ diff --git a/common_smp/src/tx_timer_expiration_process.c b/common_smp/src/tx_timer_expiration_process.c index cd94f396a..b741cdfc5 100644 --- a/common_smp/src/tx_timer_expiration_process.c +++ b/common_smp/src/tx_timer_expiration_process.c @@ -92,6 +92,8 @@ ULONG timeout_param = ((ULONG) 0); VOID (*timeout_function_ptr)(VOID *id); VOID *timeout_param_ptr = TX_NULL; TX_TIMER *pointer_timer; +TX_TIMER_POINTER_DISPATCH timeout_dispatch = TX_NULL; +VOID *timeout_owner = TX_NULL; #endif #ifdef TX_TIMER_ENABLE_PERFORMANCE_INFO TX_TIMER *timer_ptr; @@ -323,6 +325,8 @@ TX_TIMER *timer_ptr; TX_USER_TIMER_POINTER_GET(current_timer, pointer_timer) timeout_function_ptr = pointer_timer -> tx_timer_timeout_function_ptr; timeout_param_ptr = pointer_timer -> tx_timer_timeout_param_ptr; + timeout_dispatch = pointer_timer -> tx_timer_timeout_dispatch; + timeout_owner = pointer_timer -> tx_timer_timeout_owner; } #endif @@ -363,7 +367,14 @@ TX_TIMER *timer_ptr; if (timeout_function_ptr != TX_NULL) { - (timeout_function_ptr) (timeout_param_ptr); + if (timeout_dispatch != TX_NULL) + { + (timeout_dispatch)(timeout_owner, timeout_function_ptr, timeout_param_ptr); + } + else + { + (timeout_function_ptr)(timeout_param_ptr); + } } else #endif diff --git a/common_smp/src/tx_timer_thread_entry.c b/common_smp/src/tx_timer_thread_entry.c index 504ba960a..806b70909 100644 --- a/common_smp/src/tx_timer_thread_entry.c +++ b/common_smp/src/tx_timer_thread_entry.c @@ -85,6 +85,8 @@ ULONG timeout_param = ((ULONG) 0); VOID (*timeout_function_ptr)(VOID *id); VOID *timeout_param_ptr = TX_NULL; TX_TIMER *pointer_timer; +TX_TIMER_POINTER_DISPATCH timeout_dispatch = TX_NULL; +VOID *timeout_owner = TX_NULL; #endif TX_THREAD *thread_ptr; #ifdef TX_REACTIVATE_INLINE @@ -317,6 +319,8 @@ UINT status; TX_USER_TIMER_POINTER_GET(current_timer, pointer_timer) timeout_function_ptr = pointer_timer -> tx_timer_timeout_function_ptr; timeout_param_ptr = pointer_timer -> tx_timer_timeout_param_ptr; + timeout_dispatch = pointer_timer -> tx_timer_timeout_dispatch; + timeout_owner = pointer_timer -> tx_timer_timeout_owner; } #endif @@ -360,7 +364,14 @@ UINT status; if (timeout_function_ptr != TX_NULL) { - (timeout_function_ptr) (timeout_param_ptr); + if (timeout_dispatch != TX_NULL) + { + (timeout_dispatch)(timeout_owner, timeout_function_ptr, timeout_param_ptr); + } + else + { + (timeout_function_ptr)(timeout_param_ptr); + } } else #endif diff --git a/common_smp/src/txe_timer_create.c b/common_smp/src/txe_timer_create.c index c3fe31b11..6ff0ef769 100644 --- a/common_smp/src/txe_timer_create.c +++ b/common_smp/src/txe_timer_create.c @@ -79,12 +79,14 @@ static UINT _txe_timer_create_initial(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, VOID (*expiration_function)(ULONG id), ULONG expiration_input, VOID (*expiration_function_ptr)(VOID *id), VOID *expiration_input_ptr, + TX_TIMER_POINTER_DISPATCH dispatch, VOID *owner, ULONG initial_ticks, ULONG reschedule_ticks, UINT auto_activate, UINT timer_control_block_size); /**************************************************************************/ static UINT _txe_timer_create_initial(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, VOID (*expiration_function)(ULONG id), ULONG expiration_input, VOID (*expiration_function_ptr)(VOID *id), VOID *expiration_input_ptr, + TX_TIMER_POINTER_DISPATCH dispatch, VOID *owner, ULONG initial_ticks, ULONG reschedule_ticks, UINT auto_activate, UINT timer_control_block_size) #else UINT _txe_timer_create(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, @@ -238,8 +240,8 @@ TX_THREAD *thread_ptr; #ifdef TX_ENABLE_POINTER_CONTEXT if (expiration_function_ptr != TX_NULL) { - status = _tx_timer_create_ptr(timer_ptr, name_ptr, - expiration_function_ptr, expiration_input_ptr, + status = _tx_timer_create_ptr_dispatch(timer_ptr, name_ptr, + expiration_function_ptr, expiration_input_ptr, dispatch, owner, initial_ticks, reschedule_ticks, auto_activate); } else @@ -298,7 +300,7 @@ UINT _txe_timer_create(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, { return(_txe_timer_create_initial(timer_ptr, name_ptr, expiration_function, expiration_input, - TX_NULL, TX_NULL, + TX_NULL, TX_NULL, TX_NULL, TX_NULL, initial_ticks, reschedule_ticks, auto_activate, timer_control_block_size)); } @@ -344,8 +346,21 @@ UINT _txe_timer_create_ptr(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, { return(_txe_timer_create_initial(timer_ptr, name_ptr, TX_NULL, 0, - expiration_function, expiration_input, + expiration_function, expiration_input, TX_NULL, TX_NULL, initial_ticks, reschedule_ticks, auto_activate, timer_control_block_size)); } + +/* Validate a pointer timer request and carry its callback to the owner's dispatcher. */ +UINT _txe_timer_create_ptr_dispatch(TX_TIMER *timer_ptr, TX_NAME_CONST CHAR *name_ptr, + VOID (*expiration_function)(VOID *), VOID *expiration_input, + TX_TIMER_POINTER_DISPATCH dispatch, VOID *owner, + ULONG initial_ticks, ULONG reschedule_ticks, UINT auto_activate, + UINT timer_control_block_size) +{ + return(_txe_timer_create_initial(timer_ptr, name_ptr, TX_NULL, 0UL, + expiration_function, expiration_input, dispatch, owner, + initial_ticks, reschedule_ticks, auto_activate, + timer_control_block_size)); +} #endif /* TX_ENABLE_POINTER_CONTEXT */ diff --git a/ports_module/cortex_a35/ac6/module_lib/src/txm_module_thread_shell_entry.c b/ports_module/cortex_a35/ac6/module_lib/src/txm_module_thread_shell_entry.c index adf4163f7..85c91c1d0 100644 --- a/ports_module/cortex_a35/ac6/module_lib/src/txm_module_thread_shell_entry.c +++ b/ports_module/cortex_a35/ac6/module_lib/src/txm_module_thread_shell_entry.c @@ -8,6 +8,7 @@ * * SPDX-License-Identifier: MIT **************************************************************************/ +// Portions of this file were generated with AI assistance. /**************************************************************************/ @@ -143,7 +144,7 @@ VOID (*entry_exit_notify)(TX_THREAD *notify_thread_ptr, UINT type); #endif /* Call current thread's entry function. */ - (thread_info -> txm_module_thread_entry_info_entry) (thread_info -> txm_module_thread_entry_info_parameter); + TXM_MODULE_THREAD_ENTRY_CALL(thread_info); /* Suspend thread with a "completed" state. */ diff --git a/ports_module/cortex_a35/gnu/module_lib/src/txm_module_thread_shell_entry.c b/ports_module/cortex_a35/gnu/module_lib/src/txm_module_thread_shell_entry.c index 922b9306f..ecdd3eb7c 100644 --- a/ports_module/cortex_a35/gnu/module_lib/src/txm_module_thread_shell_entry.c +++ b/ports_module/cortex_a35/gnu/module_lib/src/txm_module_thread_shell_entry.c @@ -8,6 +8,7 @@ * * SPDX-License-Identifier: MIT **************************************************************************/ +// Portions of this file were generated with AI assistance. /**************************************************************************/ @@ -143,7 +144,7 @@ VOID (*entry_exit_notify)(TX_THREAD *notify_thread_ptr, UINT type); #endif /* Call current thread's entry function. */ - (thread_info -> txm_module_thread_entry_info_entry) (thread_info -> txm_module_thread_entry_info_parameter); + TXM_MODULE_THREAD_ENTRY_CALL(thread_info); /* Suspend thread with a "completed" state. */ diff --git a/ports_module/cortex_a35_smp/ac6/module_lib/src/txm_module_thread_shell_entry.c b/ports_module/cortex_a35_smp/ac6/module_lib/src/txm_module_thread_shell_entry.c index 4559ac0ea..ad809a923 100644 --- a/ports_module/cortex_a35_smp/ac6/module_lib/src/txm_module_thread_shell_entry.c +++ b/ports_module/cortex_a35_smp/ac6/module_lib/src/txm_module_thread_shell_entry.c @@ -8,6 +8,7 @@ * * SPDX-License-Identifier: MIT **************************************************************************/ +// Portions of this file were generated with AI assistance. /**************************************************************************/ @@ -135,7 +136,7 @@ VOID (*entry_exit_notify)(TX_THREAD *notify_thread_ptr, UINT type); #endif /* Call current thread's entry function. */ - (thread_info -> txm_module_thread_entry_info_entry) (thread_info -> txm_module_thread_entry_info_parameter); + TXM_MODULE_THREAD_ENTRY_CALL(thread_info); /* Suspend thread with a "completed" state. */ diff --git a/ports_module/cortex_a35_smp/gnu/module_lib/src/txm_module_thread_shell_entry.c b/ports_module/cortex_a35_smp/gnu/module_lib/src/txm_module_thread_shell_entry.c index ba56d9e3d..ebad10596 100644 --- a/ports_module/cortex_a35_smp/gnu/module_lib/src/txm_module_thread_shell_entry.c +++ b/ports_module/cortex_a35_smp/gnu/module_lib/src/txm_module_thread_shell_entry.c @@ -8,6 +8,7 @@ * * SPDX-License-Identifier: MIT **************************************************************************/ +// Portions of this file were generated with AI assistance. /**************************************************************************/ @@ -135,7 +136,7 @@ VOID (*entry_exit_notify)(TX_THREAD *notify_thread_ptr, UINT type); #endif /* Call current thread's entry function. */ - (thread_info -> txm_module_thread_entry_info_entry) (thread_info -> txm_module_thread_entry_info_parameter); + TXM_MODULE_THREAD_ENTRY_CALL(thread_info); /* Suspend thread with a "completed" state. */ diff --git a/ports_module/cortex_a7/ac5/module_lib/src/txm_module_thread_shell_entry.c b/ports_module/cortex_a7/ac5/module_lib/src/txm_module_thread_shell_entry.c index 4925fe47b..ad5749893 100644 --- a/ports_module/cortex_a7/ac5/module_lib/src/txm_module_thread_shell_entry.c +++ b/ports_module/cortex_a7/ac5/module_lib/src/txm_module_thread_shell_entry.c @@ -8,6 +8,7 @@ * * SPDX-License-Identifier: MIT **************************************************************************/ +// Portions of this file were generated with AI assistance. /**************************************************************************/ @@ -138,7 +139,7 @@ VOID _txm_module_thread_shell_entry(TX_THREAD *thread_ptr, TXM_MODULE_THREAD_EN #endif /* Call current thread's entry function. */ - (thread_info -> txm_module_thread_entry_info_entry) (thread_info -> txm_module_thread_entry_info_parameter); + TXM_MODULE_THREAD_ENTRY_CALL(thread_info); /* Suspend thread with a "completed" state. */ diff --git a/ports_module/cortex_a7/gnu/module_lib/src/txm_module_thread_shell_entry.c b/ports_module/cortex_a7/gnu/module_lib/src/txm_module_thread_shell_entry.c index 73a38340d..7b5c3e6a1 100644 --- a/ports_module/cortex_a7/gnu/module_lib/src/txm_module_thread_shell_entry.c +++ b/ports_module/cortex_a7/gnu/module_lib/src/txm_module_thread_shell_entry.c @@ -8,6 +8,7 @@ * * SPDX-License-Identifier: MIT **************************************************************************/ +// Portions of this file were generated with AI assistance. /**************************************************************************/ @@ -144,7 +145,7 @@ VOID (*entry_exit_notify)(TX_THREAD *, UINT); #endif /* Call current thread's entry function. */ - (thread_info -> txm_module_thread_entry_info_entry) (thread_info -> txm_module_thread_entry_info_parameter); + TXM_MODULE_THREAD_ENTRY_CALL(thread_info); /* Suspend thread with a "completed" state. */ diff --git a/ports_module/cortex_a7/iar/module_lib/src/txm_module_thread_shell_entry.c b/ports_module/cortex_a7/iar/module_lib/src/txm_module_thread_shell_entry.c index cfe18ef19..2654e656a 100644 --- a/ports_module/cortex_a7/iar/module_lib/src/txm_module_thread_shell_entry.c +++ b/ports_module/cortex_a7/iar/module_lib/src/txm_module_thread_shell_entry.c @@ -8,6 +8,7 @@ * * SPDX-License-Identifier: MIT **************************************************************************/ +// Portions of this file were generated with AI assistance. /**************************************************************************/ @@ -139,7 +140,7 @@ VOID _txm_module_thread_shell_entry(TX_THREAD *thread_ptr, TXM_MODULE_THREAD_EN #endif /* Call current thread's entry function. */ - (thread_info -> txm_module_thread_entry_info_entry) (thread_info -> txm_module_thread_entry_info_parameter); + TXM_MODULE_THREAD_ENTRY_CALL(thread_info); /* Suspend thread with a "completed" state. */ diff --git a/ports_module/cortex_m0+/ac6/module_lib/src/txm_module_thread_shell_entry.c b/ports_module/cortex_m0+/ac6/module_lib/src/txm_module_thread_shell_entry.c index 13f57b8de..f6c46e7a8 100644 --- a/ports_module/cortex_m0+/ac6/module_lib/src/txm_module_thread_shell_entry.c +++ b/ports_module/cortex_m0+/ac6/module_lib/src/txm_module_thread_shell_entry.c @@ -8,6 +8,7 @@ * * SPDX-License-Identifier: MIT **************************************************************************/ +// Portions of this file were generated with AI assistance. /**************************************************************************/ @@ -137,7 +138,7 @@ VOID _txm_module_thread_shell_entry(TX_THREAD *thread_ptr, TXM_MODULE_THREAD_EN #endif /* Call current thread's entry function. */ - (thread_info -> txm_module_thread_entry_info_entry) (thread_info -> txm_module_thread_entry_info_parameter); + TXM_MODULE_THREAD_ENTRY_CALL(thread_info); /* Suspend thread with a "completed" state. */ diff --git a/ports_module/cortex_m0+/gnu/module_lib/src/txm_module_thread_shell_entry.c b/ports_module/cortex_m0+/gnu/module_lib/src/txm_module_thread_shell_entry.c index 2bb3bf7eb..9d6ffafa6 100644 --- a/ports_module/cortex_m0+/gnu/module_lib/src/txm_module_thread_shell_entry.c +++ b/ports_module/cortex_m0+/gnu/module_lib/src/txm_module_thread_shell_entry.c @@ -8,6 +8,7 @@ * * SPDX-License-Identifier: MIT **************************************************************************/ +// Portions of this file were generated with AI assistance. /**************************************************************************/ @@ -137,7 +138,7 @@ VOID _txm_module_thread_shell_entry(TX_THREAD *thread_ptr, TXM_MODULE_THREAD_EN #endif /* Call current thread's entry function. */ - (thread_info -> txm_module_thread_entry_info_entry) (thread_info -> txm_module_thread_entry_info_parameter); + TXM_MODULE_THREAD_ENTRY_CALL(thread_info); /* Suspend thread with a "completed" state. */ diff --git a/ports_module/cortex_m0+/iar/module_lib/src/txm_module_thread_shell_entry.c b/ports_module/cortex_m0+/iar/module_lib/src/txm_module_thread_shell_entry.c index 8983b8329..e6e22bc9e 100644 --- a/ports_module/cortex_m0+/iar/module_lib/src/txm_module_thread_shell_entry.c +++ b/ports_module/cortex_m0+/iar/module_lib/src/txm_module_thread_shell_entry.c @@ -8,6 +8,7 @@ * * SPDX-License-Identifier: MIT **************************************************************************/ +// Portions of this file were generated with AI assistance. /**************************************************************************/ @@ -137,7 +138,7 @@ VOID _txm_module_thread_shell_entry(TX_THREAD *thread_ptr, TXM_MODULE_THREAD_EN #endif /* Call current thread's entry function. */ - (thread_info -> txm_module_thread_entry_info_entry) (thread_info -> txm_module_thread_entry_info_parameter); + TXM_MODULE_THREAD_ENTRY_CALL(thread_info); /* Suspend thread with a "completed" state. */ diff --git a/ports_module/cortex_m23/ac6/module_lib/src/txm_module_thread_shell_entry.c b/ports_module/cortex_m23/ac6/module_lib/src/txm_module_thread_shell_entry.c index 0be91d63c..ee1dcda3d 100644 --- a/ports_module/cortex_m23/ac6/module_lib/src/txm_module_thread_shell_entry.c +++ b/ports_module/cortex_m23/ac6/module_lib/src/txm_module_thread_shell_entry.c @@ -8,6 +8,7 @@ * * SPDX-License-Identifier: MIT **************************************************************************/ +// Portions of this file were generated with AI assistance. /**************************************************************************/ @@ -139,7 +140,7 @@ VOID _txm_module_thread_shell_entry(TX_THREAD *thread_ptr, TXM_MODULE_THREAD_EN #endif /* Call current thread's entry function. */ - (thread_info -> txm_module_thread_entry_info_entry) (thread_info -> txm_module_thread_entry_info_parameter); + TXM_MODULE_THREAD_ENTRY_CALL(thread_info); /* Suspend thread with a "completed" state. */ diff --git a/ports_module/cortex_m23/gnu/module_lib/src/txm_module_thread_shell_entry.c b/ports_module/cortex_m23/gnu/module_lib/src/txm_module_thread_shell_entry.c index b4e753782..3075b6489 100644 --- a/ports_module/cortex_m23/gnu/module_lib/src/txm_module_thread_shell_entry.c +++ b/ports_module/cortex_m23/gnu/module_lib/src/txm_module_thread_shell_entry.c @@ -8,6 +8,7 @@ * * SPDX-License-Identifier: MIT **************************************************************************/ +// Portions of this file were generated with AI assistance. /**************************************************************************/ @@ -137,7 +138,7 @@ VOID _txm_module_thread_shell_entry(TX_THREAD *thread_ptr, TXM_MODULE_THREAD_EN #endif /* Call current thread's entry function. */ - (thread_info -> txm_module_thread_entry_info_entry) (thread_info -> txm_module_thread_entry_info_parameter); + TXM_MODULE_THREAD_ENTRY_CALL(thread_info); /* Suspend thread with a "completed" state. */ diff --git a/ports_module/cortex_m23/iar/module_lib/src/txm_module_thread_shell_entry.c b/ports_module/cortex_m23/iar/module_lib/src/txm_module_thread_shell_entry.c index 1bcfe689b..f51c8a25b 100644 --- a/ports_module/cortex_m23/iar/module_lib/src/txm_module_thread_shell_entry.c +++ b/ports_module/cortex_m23/iar/module_lib/src/txm_module_thread_shell_entry.c @@ -8,6 +8,7 @@ * * SPDX-License-Identifier: MIT **************************************************************************/ +// Portions of this file were generated with AI assistance. /**************************************************************************/ @@ -137,7 +138,7 @@ VOID _txm_module_thread_shell_entry(TX_THREAD *thread_ptr, TXM_MODULE_THREAD_EN #endif /* Call current thread's entry function. */ - (thread_info -> txm_module_thread_entry_info_entry) (thread_info -> txm_module_thread_entry_info_parameter); + TXM_MODULE_THREAD_ENTRY_CALL(thread_info); /* Suspend thread with a "completed" state. */ diff --git a/ports_module/cortex_m3/ac5/module_lib/src/txm_module_thread_shell_entry.c b/ports_module/cortex_m3/ac5/module_lib/src/txm_module_thread_shell_entry.c index b1e803f9d..c660abba4 100644 --- a/ports_module/cortex_m3/ac5/module_lib/src/txm_module_thread_shell_entry.c +++ b/ports_module/cortex_m3/ac5/module_lib/src/txm_module_thread_shell_entry.c @@ -8,6 +8,7 @@ * * SPDX-License-Identifier: MIT **************************************************************************/ +// Portions of this file were generated with AI assistance. /**************************************************************************/ @@ -138,7 +139,7 @@ VOID _txm_module_thread_shell_entry(TX_THREAD *thread_ptr, TXM_MODULE_THREAD_EN #endif /* Call current thread's entry function. */ - (thread_info -> txm_module_thread_entry_info_entry) (thread_info -> txm_module_thread_entry_info_parameter); + TXM_MODULE_THREAD_ENTRY_CALL(thread_info); /* Suspend thread with a "completed" state. */ diff --git a/ports_module/cortex_m3/ac6/module_lib/src/txm_module_thread_shell_entry.c b/ports_module/cortex_m3/ac6/module_lib/src/txm_module_thread_shell_entry.c index 518704d74..fce3a1852 100644 --- a/ports_module/cortex_m3/ac6/module_lib/src/txm_module_thread_shell_entry.c +++ b/ports_module/cortex_m3/ac6/module_lib/src/txm_module_thread_shell_entry.c @@ -8,6 +8,7 @@ * * SPDX-License-Identifier: MIT **************************************************************************/ +// Portions of this file were generated with AI assistance. /**************************************************************************/ @@ -139,7 +140,7 @@ VOID _txm_module_thread_shell_entry(TX_THREAD *thread_ptr, TXM_MODULE_THREAD_EN #endif /* Call current thread's entry function. */ - (thread_info -> txm_module_thread_entry_info_entry) (thread_info -> txm_module_thread_entry_info_parameter); + TXM_MODULE_THREAD_ENTRY_CALL(thread_info); /* Suspend thread with a "completed" state. */ diff --git a/ports_module/cortex_m3/gnu/module_lib/src/txm_module_thread_shell_entry.c b/ports_module/cortex_m3/gnu/module_lib/src/txm_module_thread_shell_entry.c index e8af97a97..9c15a83c5 100644 --- a/ports_module/cortex_m3/gnu/module_lib/src/txm_module_thread_shell_entry.c +++ b/ports_module/cortex_m3/gnu/module_lib/src/txm_module_thread_shell_entry.c @@ -8,6 +8,7 @@ * * SPDX-License-Identifier: MIT **************************************************************************/ +// Portions of this file were generated with AI assistance. /**************************************************************************/ @@ -137,7 +138,7 @@ VOID _txm_module_thread_shell_entry(TX_THREAD *thread_ptr, TXM_MODULE_THREAD_EN #endif /* Call current thread's entry function. */ - (thread_info -> txm_module_thread_entry_info_entry) (thread_info -> txm_module_thread_entry_info_parameter); + TXM_MODULE_THREAD_ENTRY_CALL(thread_info); /* Suspend thread with a "completed" state. */ diff --git a/ports_module/cortex_m3/iar/module_lib/src/txm_module_thread_shell_entry.c b/ports_module/cortex_m3/iar/module_lib/src/txm_module_thread_shell_entry.c index d4fd04ec6..99746e10b 100644 --- a/ports_module/cortex_m3/iar/module_lib/src/txm_module_thread_shell_entry.c +++ b/ports_module/cortex_m3/iar/module_lib/src/txm_module_thread_shell_entry.c @@ -8,6 +8,7 @@ * * SPDX-License-Identifier: MIT **************************************************************************/ +// Portions of this file were generated with AI assistance. /**************************************************************************/ @@ -137,7 +138,7 @@ VOID _txm_module_thread_shell_entry(TX_THREAD *thread_ptr, TXM_MODULE_THREAD_EN #endif /* Call current thread's entry function. */ - (thread_info -> txm_module_thread_entry_info_entry) (thread_info -> txm_module_thread_entry_info_parameter); + TXM_MODULE_THREAD_ENTRY_CALL(thread_info); /* Suspend thread with a "completed" state. */ diff --git a/ports_module/cortex_m33/ac6/module_lib/src/txm_module_thread_shell_entry.c b/ports_module/cortex_m33/ac6/module_lib/src/txm_module_thread_shell_entry.c index bf6fcb5f7..022f8196e 100644 --- a/ports_module/cortex_m33/ac6/module_lib/src/txm_module_thread_shell_entry.c +++ b/ports_module/cortex_m33/ac6/module_lib/src/txm_module_thread_shell_entry.c @@ -8,6 +8,7 @@ * * SPDX-License-Identifier: MIT **************************************************************************/ +// Portions of this file were generated with AI assistance. /**************************************************************************/ @@ -139,7 +140,7 @@ VOID _txm_module_thread_shell_entry(TX_THREAD *thread_ptr, TXM_MODULE_THREAD_EN #endif /* Call current thread's entry function. */ - (thread_info -> txm_module_thread_entry_info_entry) (thread_info -> txm_module_thread_entry_info_parameter); + TXM_MODULE_THREAD_ENTRY_CALL(thread_info); /* Suspend thread with a "completed" state. */ diff --git a/ports_module/cortex_m33/gnu/module_lib/src/txm_module_thread_shell_entry.c b/ports_module/cortex_m33/gnu/module_lib/src/txm_module_thread_shell_entry.c index 0fa4f2de5..111b25955 100644 --- a/ports_module/cortex_m33/gnu/module_lib/src/txm_module_thread_shell_entry.c +++ b/ports_module/cortex_m33/gnu/module_lib/src/txm_module_thread_shell_entry.c @@ -8,6 +8,7 @@ * * SPDX-License-Identifier: MIT **************************************************************************/ +// Portions of this file were generated with AI assistance. /**************************************************************************/ @@ -137,7 +138,7 @@ VOID _txm_module_thread_shell_entry(TX_THREAD *thread_ptr, TXM_MODULE_THREAD_EN #endif /* Call current thread's entry function. */ - (thread_info -> txm_module_thread_entry_info_entry) (thread_info -> txm_module_thread_entry_info_parameter); + TXM_MODULE_THREAD_ENTRY_CALL(thread_info); /* Suspend thread with a "completed" state. */ diff --git a/ports_module/cortex_m33/iar/module_lib/src/txm_module_thread_shell_entry.c b/ports_module/cortex_m33/iar/module_lib/src/txm_module_thread_shell_entry.c index 1d2e17201..bdb6b20d9 100644 --- a/ports_module/cortex_m33/iar/module_lib/src/txm_module_thread_shell_entry.c +++ b/ports_module/cortex_m33/iar/module_lib/src/txm_module_thread_shell_entry.c @@ -8,6 +8,7 @@ * * SPDX-License-Identifier: MIT **************************************************************************/ +// Portions of this file were generated with AI assistance. /**************************************************************************/ @@ -137,7 +138,7 @@ VOID _txm_module_thread_shell_entry(TX_THREAD *thread_ptr, TXM_MODULE_THREAD_EN #endif /* Call current thread's entry function. */ - (thread_info -> txm_module_thread_entry_info_entry) (thread_info -> txm_module_thread_entry_info_parameter); + TXM_MODULE_THREAD_ENTRY_CALL(thread_info); /* Suspend thread with a "completed" state. */ diff --git a/ports_module/cortex_m4/ac5/module_lib/src/txm_module_thread_shell_entry.c b/ports_module/cortex_m4/ac5/module_lib/src/txm_module_thread_shell_entry.c index b7bccaa82..388c36164 100644 --- a/ports_module/cortex_m4/ac5/module_lib/src/txm_module_thread_shell_entry.c +++ b/ports_module/cortex_m4/ac5/module_lib/src/txm_module_thread_shell_entry.c @@ -8,6 +8,7 @@ * * SPDX-License-Identifier: MIT **************************************************************************/ +// Portions of this file were generated with AI assistance. /**************************************************************************/ @@ -138,7 +139,7 @@ VOID _txm_module_thread_shell_entry(TX_THREAD *thread_ptr, TXM_MODULE_THREAD_EN #endif /* Call current thread's entry function. */ - (thread_info -> txm_module_thread_entry_info_entry) (thread_info -> txm_module_thread_entry_info_parameter); + TXM_MODULE_THREAD_ENTRY_CALL(thread_info); /* Suspend thread with a "completed" state. */ diff --git a/ports_module/cortex_m4/ac6/module_lib/src/txm_module_thread_shell_entry.c b/ports_module/cortex_m4/ac6/module_lib/src/txm_module_thread_shell_entry.c index e75e693d6..07048cc83 100644 --- a/ports_module/cortex_m4/ac6/module_lib/src/txm_module_thread_shell_entry.c +++ b/ports_module/cortex_m4/ac6/module_lib/src/txm_module_thread_shell_entry.c @@ -8,6 +8,7 @@ * * SPDX-License-Identifier: MIT **************************************************************************/ +// Portions of this file were generated with AI assistance. /**************************************************************************/ @@ -139,7 +140,7 @@ VOID _txm_module_thread_shell_entry(TX_THREAD *thread_ptr, TXM_MODULE_THREAD_EN #endif /* Call current thread's entry function. */ - (thread_info -> txm_module_thread_entry_info_entry) (thread_info -> txm_module_thread_entry_info_parameter); + TXM_MODULE_THREAD_ENTRY_CALL(thread_info); /* Suspend thread with a "completed" state. */ diff --git a/ports_module/cortex_m4/gnu/module_lib/src/txm_module_thread_shell_entry.c b/ports_module/cortex_m4/gnu/module_lib/src/txm_module_thread_shell_entry.c index 30632c1e1..ed276900b 100644 --- a/ports_module/cortex_m4/gnu/module_lib/src/txm_module_thread_shell_entry.c +++ b/ports_module/cortex_m4/gnu/module_lib/src/txm_module_thread_shell_entry.c @@ -8,6 +8,7 @@ * * SPDX-License-Identifier: MIT **************************************************************************/ +// Portions of this file were generated with AI assistance. /**************************************************************************/ @@ -137,7 +138,7 @@ VOID _txm_module_thread_shell_entry(TX_THREAD *thread_ptr, TXM_MODULE_THREAD_EN #endif /* Call current thread's entry function. */ - (thread_info -> txm_module_thread_entry_info_entry) (thread_info -> txm_module_thread_entry_info_parameter); + TXM_MODULE_THREAD_ENTRY_CALL(thread_info); /* Suspend thread with a "completed" state. */ diff --git a/ports_module/cortex_m4/iar/module_lib/src/txm_module_thread_shell_entry.c b/ports_module/cortex_m4/iar/module_lib/src/txm_module_thread_shell_entry.c index 5d7767aed..b968a706d 100644 --- a/ports_module/cortex_m4/iar/module_lib/src/txm_module_thread_shell_entry.c +++ b/ports_module/cortex_m4/iar/module_lib/src/txm_module_thread_shell_entry.c @@ -8,6 +8,7 @@ * * SPDX-License-Identifier: MIT **************************************************************************/ +// Portions of this file were generated with AI assistance. /**************************************************************************/ @@ -137,7 +138,7 @@ VOID _txm_module_thread_shell_entry(TX_THREAD *thread_ptr, TXM_MODULE_THREAD_EN #endif /* Call current thread's entry function. */ - (thread_info -> txm_module_thread_entry_info_entry) (thread_info -> txm_module_thread_entry_info_parameter); + TXM_MODULE_THREAD_ENTRY_CALL(thread_info); /* Suspend thread with a "completed" state. */ diff --git a/ports_module/cortex_m7/ac5/module_lib/src/txm_module_thread_shell_entry.c b/ports_module/cortex_m7/ac5/module_lib/src/txm_module_thread_shell_entry.c index 48f5b3a8d..2ad99288e 100644 --- a/ports_module/cortex_m7/ac5/module_lib/src/txm_module_thread_shell_entry.c +++ b/ports_module/cortex_m7/ac5/module_lib/src/txm_module_thread_shell_entry.c @@ -8,6 +8,7 @@ * * SPDX-License-Identifier: MIT **************************************************************************/ +// Portions of this file were generated with AI assistance. /**************************************************************************/ @@ -138,7 +139,7 @@ VOID _txm_module_thread_shell_entry(TX_THREAD *thread_ptr, TXM_MODULE_THREAD_EN #endif /* Call current thread's entry function. */ - (thread_info -> txm_module_thread_entry_info_entry) (thread_info -> txm_module_thread_entry_info_parameter); + TXM_MODULE_THREAD_ENTRY_CALL(thread_info); /* Suspend thread with a "completed" state. */ diff --git a/ports_module/cortex_m7/ac6/module_lib/src/txm_module_thread_shell_entry.c b/ports_module/cortex_m7/ac6/module_lib/src/txm_module_thread_shell_entry.c index bd3c0c7ce..98ce7ce3b 100644 --- a/ports_module/cortex_m7/ac6/module_lib/src/txm_module_thread_shell_entry.c +++ b/ports_module/cortex_m7/ac6/module_lib/src/txm_module_thread_shell_entry.c @@ -8,6 +8,7 @@ * * SPDX-License-Identifier: MIT **************************************************************************/ +// Portions of this file were generated with AI assistance. /**************************************************************************/ @@ -139,7 +140,7 @@ VOID _txm_module_thread_shell_entry(TX_THREAD *thread_ptr, TXM_MODULE_THREAD_EN #endif /* Call current thread's entry function. */ - (thread_info -> txm_module_thread_entry_info_entry) (thread_info -> txm_module_thread_entry_info_parameter); + TXM_MODULE_THREAD_ENTRY_CALL(thread_info); /* Suspend thread with a "completed" state. */ diff --git a/ports_module/cortex_m7/gnu/module_lib/src/txm_module_thread_shell_entry.c b/ports_module/cortex_m7/gnu/module_lib/src/txm_module_thread_shell_entry.c index 3eb08b2b3..487d1ed5f 100644 --- a/ports_module/cortex_m7/gnu/module_lib/src/txm_module_thread_shell_entry.c +++ b/ports_module/cortex_m7/gnu/module_lib/src/txm_module_thread_shell_entry.c @@ -8,6 +8,7 @@ * * SPDX-License-Identifier: MIT **************************************************************************/ +// Portions of this file were generated with AI assistance. /**************************************************************************/ @@ -137,7 +138,7 @@ VOID _txm_module_thread_shell_entry(TX_THREAD *thread_ptr, TXM_MODULE_THREAD_EN #endif /* Call current thread's entry function. */ - (thread_info -> txm_module_thread_entry_info_entry) (thread_info -> txm_module_thread_entry_info_parameter); + TXM_MODULE_THREAD_ENTRY_CALL(thread_info); /* Suspend thread with a "completed" state. */ diff --git a/ports_module/cortex_m7/iar/module_lib/src/txm_module_thread_shell_entry.c b/ports_module/cortex_m7/iar/module_lib/src/txm_module_thread_shell_entry.c index c858fb2b9..c7c5e3da4 100644 --- a/ports_module/cortex_m7/iar/module_lib/src/txm_module_thread_shell_entry.c +++ b/ports_module/cortex_m7/iar/module_lib/src/txm_module_thread_shell_entry.c @@ -8,6 +8,7 @@ * * SPDX-License-Identifier: MIT **************************************************************************/ +// Portions of this file were generated with AI assistance. /**************************************************************************/ @@ -137,7 +138,7 @@ VOID _txm_module_thread_shell_entry(TX_THREAD *thread_ptr, TXM_MODULE_THREAD_EN #endif /* Call current thread's entry function. */ - (thread_info -> txm_module_thread_entry_info_entry) (thread_info -> txm_module_thread_entry_info_parameter); + TXM_MODULE_THREAD_ENTRY_CALL(thread_info); /* Suspend thread with a "completed" state. */ diff --git a/ports_module/cortex_r4/ac6/module_lib/src/txm_module_thread_shell_entry.c b/ports_module/cortex_r4/ac6/module_lib/src/txm_module_thread_shell_entry.c index ec0d81c63..4c4a12f27 100644 --- a/ports_module/cortex_r4/ac6/module_lib/src/txm_module_thread_shell_entry.c +++ b/ports_module/cortex_r4/ac6/module_lib/src/txm_module_thread_shell_entry.c @@ -8,6 +8,7 @@ * * SPDX-License-Identifier: MIT **************************************************************************/ +// Portions of this file were generated with AI assistance. /**************************************************************************/ @@ -139,7 +140,7 @@ VOID _txm_module_thread_shell_entry(TX_THREAD *thread_ptr, TXM_MODULE_THREAD_EN #endif /* Call current thread's entry function. */ - (thread_info -> txm_module_thread_entry_info_entry) (thread_info -> txm_module_thread_entry_info_parameter); + TXM_MODULE_THREAD_ENTRY_CALL(thread_info); /* Suspend thread with a "completed" state. */ diff --git a/ports_module/cortex_r4/iar/module_lib/src/txm_module_thread_shell_entry.c b/ports_module/cortex_r4/iar/module_lib/src/txm_module_thread_shell_entry.c index b27e06e3b..bed9aaefd 100644 --- a/ports_module/cortex_r4/iar/module_lib/src/txm_module_thread_shell_entry.c +++ b/ports_module/cortex_r4/iar/module_lib/src/txm_module_thread_shell_entry.c @@ -8,6 +8,7 @@ * * SPDX-License-Identifier: MIT **************************************************************************/ +// Portions of this file were generated with AI assistance. /**************************************************************************/ @@ -137,7 +138,7 @@ VOID _txm_module_thread_shell_entry(TX_THREAD *thread_ptr, TXM_MODULE_THREAD_EN #endif /* Call current thread's entry function. */ - (thread_info -> txm_module_thread_entry_info_entry) (thread_info -> txm_module_thread_entry_info_parameter); + TXM_MODULE_THREAD_ENTRY_CALL(thread_info); /* Suspend thread with a "completed" state. */ diff --git a/ports_module/cortex_r52/gnu/module_lib/src/txm_module_thread_shell_entry.c b/ports_module/cortex_r52/gnu/module_lib/src/txm_module_thread_shell_entry.c index 4f01b7a8c..ee8df74e2 100644 --- a/ports_module/cortex_r52/gnu/module_lib/src/txm_module_thread_shell_entry.c +++ b/ports_module/cortex_r52/gnu/module_lib/src/txm_module_thread_shell_entry.c @@ -8,6 +8,7 @@ * * SPDX-License-Identifier: MIT **************************************************************************/ +// Portions of this file were generated with AI assistance. /**************************************************************************/ @@ -137,7 +138,7 @@ VOID _txm_module_thread_shell_entry(TX_THREAD *thread_ptr, TXM_MODULE_THREAD_EN #endif /* Call current thread's entry function. */ - (thread_info -> txm_module_thread_entry_info_entry) (thread_info -> txm_module_thread_entry_info_parameter); + TXM_MODULE_THREAD_ENTRY_CALL(thread_info); /* Suspend thread with a "completed" state. */ diff --git a/ports_module/rxv2/iar/module_lib/src/txm_module_thread_shell_entry.c b/ports_module/rxv2/iar/module_lib/src/txm_module_thread_shell_entry.c index 1242184cc..380aae495 100644 --- a/ports_module/rxv2/iar/module_lib/src/txm_module_thread_shell_entry.c +++ b/ports_module/rxv2/iar/module_lib/src/txm_module_thread_shell_entry.c @@ -8,6 +8,7 @@ * * SPDX-License-Identifier: MIT **************************************************************************/ +// Portions of this file were generated with AI assistance. /**************************************************************************/ @@ -137,7 +138,7 @@ VOID _txm_module_thread_shell_entry(TX_THREAD *thread_ptr, TXM_MODULE_THREAD_EN #endif /* Call current thread's entry function. */ - (thread_info -> txm_module_thread_entry_info_entry) (thread_info -> txm_module_thread_entry_info_parameter); + TXM_MODULE_THREAD_ENTRY_CALL(thread_info); /* Suspend thread with a "completed" state. */ diff --git a/test/smp/cmake/CMakeLists.txt b/test/smp/cmake/CMakeLists.txt index 90f3651c4..15685b95f 100644 --- a/test/smp/cmake/CMakeLists.txt +++ b/test/smp/cmake/CMakeLists.txt @@ -14,9 +14,6 @@ set(CMAKE_C_EXTENSIONS OFF) # Set build configurations option(TX_ENABLE_POINTER_CONTEXT "Exercise the pointer context APIs" OFF) -if(TX_ENABLE_POINTER_CONTEXT) - add_compile_definitions(TX_ENABLE_POINTER_CONTEXT) -endif() set(BUILD_CONFIGURATIONS default_build_coverage disable_notify_callbacks_build stack_checking_build stack_checking_rand_fill_build @@ -65,6 +62,9 @@ endif() enable_testing() add_subdirectory(threadx_smp) +if(TX_ENABLE_POINTER_CONTEXT) + target_compile_definitions(threadx_smp PUBLIC TX_ENABLE_POINTER_CONTEXT) +endif() add_subdirectory(regression) add_subdirectory(samples) diff --git a/test/smp/regression/threadx_pointer_callback_test.c b/test/smp/regression/threadx_pointer_callback_test.c index 0726f5219..98c319c22 100644 --- a/test/smp/regression/threadx_pointer_callback_test.c +++ b/test/smp/regression/threadx_pointer_callback_test.c @@ -8,6 +8,7 @@ * * SPDX-License-Identifier: MIT **************************************************************************/ +// Portions of this file were generated with AI assistance. #include #include @@ -30,6 +31,8 @@ static TX_THREAD thread_ulong_test; static TX_TIMER timer_ptr_test; static TX_TIMER timer_ulong_test; +static TX_TIMER timer_silent_test; +static TX_TIMER timer_dispatched_test; static void *received_thread_ptr_ctx = TX_NULL; static void *received_timer_ptr_ctx = TX_NULL; @@ -40,6 +43,7 @@ static volatile UINT thread_ptr_executed = 0; static volatile UINT thread_ulong_executed = 0; static volatile UINT timer_ptr_executed = 0; static volatile UINT timer_ulong_executed = 0; +static volatile UINT timer_dispatched = 0; #if (defined(__x86_64__) || defined(_WIN64) || defined(__aarch64__) || (defined(__riscv_xlen) && (__riscv_xlen == 64)) || defined(__LP64__) || defined(_LP64)) #define TEST_PTR_VAL_1 ((VOID *)(ALIGN_TYPE) 0x123456789ABCDEF0ULL) @@ -74,13 +78,23 @@ static void thread_ulong_entry(ULONG entry_input) static void timer_ptr_expiration(VOID *expiration_input) { received_timer_ptr_ctx = expiration_input; - timer_ptr_executed = 1; + timer_ptr_executed++; } static void timer_ulong_expiration(ULONG expiration_input) { received_timer_ulong_ctx = expiration_input; - timer_ulong_executed = 1; + timer_ulong_executed++; +} + +/* Verify the owner and callback delivered to the timer dispatcher. */ +static void timer_dispatch(VOID *owner, VOID (*callback)(VOID *), VOID *context) +{ + if ((owner == &timer_dispatched_test) && (callback == timer_ptr_expiration) && + (context == TEST_PTR_VAL_2)) + { + timer_dispatched++; + } } static void thread_0_entry(ULONG thread_input) @@ -200,6 +214,36 @@ static void thread_0_entry(ULONG thread_input) } #endif + /* Defer the first pointer callback for a full wheel turn, then reload all timers. */ + status = tx_timer_change(&timer_ptr_test, TX_TIMER_ENTRIES + 1, 2); + status |= tx_timer_change(&timer_ulong_test, 1, 2); + status |= tx_timer_create_ptr(&timer_silent_test, "silent timer", TX_NULL, TX_NULL, + 1, 2, TX_AUTO_ACTIVATE); + status |= _txe_timer_create_ptr_dispatch(&timer_dispatched_test, "dispatched timer", + timer_ptr_expiration, expected_timer_ptr, timer_dispatch, + &timer_dispatched_test, 1, 0, TX_AUTO_ACTIVATE, + sizeof(TX_TIMER)); + status |= tx_timer_activate(&timer_ptr_test); + status |= tx_timer_activate(&timer_ulong_test); + if (status != TX_SUCCESS) + { + error++; + } + + tx_thread_sleep(5); + if ((timer_ptr_executed != 1) || (timer_ulong_executed < 2) || (timer_dispatched != 1)) + { + error++; + } + + tx_thread_sleep(TX_TIMER_ENTRIES + 4); + if ((timer_ptr_executed < 3) || (received_timer_ptr_ctx != expected_timer_ptr)) + { + error++; + } + tx_timer_delete(&timer_silent_test); + tx_timer_delete(&timer_dispatched_test); + /* Clean up created objects. */ tx_timer_deactivate(&timer_ptr_test); tx_timer_delete(&timer_ptr_test); diff --git a/test/tx/cmake/CMakeLists.txt b/test/tx/cmake/CMakeLists.txt index 61b7c9982..a1b765b59 100644 --- a/test/tx/cmake/CMakeLists.txt +++ b/test/tx/cmake/CMakeLists.txt @@ -25,9 +25,6 @@ set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_C_EXTENSIONS OFF) option(TX_ENABLE_POINTER_CONTEXT "Exercise the pointer context APIs" OFF) -if(TX_ENABLE_POINTER_CONTEXT) - add_compile_definitions(TX_ENABLE_POINTER_CONTEXT) -endif() # Set build configurations set(BUILD_CONFIGURATIONS default_build_coverage disable_notify_callbacks_build @@ -97,6 +94,9 @@ endif() enable_testing() add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../../.. threadx) +if(TX_ENABLE_POINTER_CONTEXT) + target_compile_definitions(threadx PUBLIC TX_ENABLE_POINTER_CONTEXT) +endif() add_subdirectory(regression) add_subdirectory(samples) diff --git a/test/tx/cmake/module_qemu/CMakeLists.txt b/test/tx/cmake/module_qemu/CMakeLists.txt index 44c40f039..a69889af4 100644 --- a/test/tx/cmake/module_qemu/CMakeLists.txt +++ b/test/tx/cmake/module_qemu/CMakeLists.txt @@ -46,6 +46,7 @@ project(threadx_module_qemu LANGUAGES C ASM) set(MODULE_QEMU_PORT "cortex_m3" CACHE STRING "Cortex-M module port to build and run") set_property(CACHE MODULE_QEMU_PORT PROPERTY STRINGS cortex_m3 cortex_m4) +option(MODULE_QEMU_POINTER_CONTEXT "Exercise the pointer-context module APIs" OFF) if(MODULE_QEMU_PORT STREQUAL "cortex_m3") set(PORT_CPU_FLAGS -mcpu=cortex-m3 -mthumb) @@ -67,6 +68,10 @@ message(STATUS "Module port: ${MODULE_QEMU_PORT}, QEMU machine: ${QEMU_MACHINE}" add_compile_options(${PORT_CPU_FLAGS} -g -O0 -ffunction-sections -fdata-sections) add_link_options(${PORT_CPU_FLAGS}) +if(MODULE_QEMU_POINTER_CONTEXT) + add_compile_definitions(TX_ENABLE_POINTER_CONTEXT) +endif() + # --------------------------------------------------------------------------- # The kernel and the Module Manager, built with the module port's headers. # diff --git a/test/tx/cmake/module_qemu/src/module_shared.h b/test/tx/cmake/module_qemu/src/module_shared.h index a50200c37..58e763356 100644 --- a/test/tx/cmake/module_qemu/src/module_shared.h +++ b/test/tx/cmake/module_qemu/src/module_shared.h @@ -59,6 +59,10 @@ #define MODULE_OUT_KERNEL_READ_DONE ((ULONG) 17UL) /* Kernel word read completed */ #define MODULE_OUT_KERNEL_VALUE ((ULONG) 18UL) /* Value read from the kernel word */ #define MODULE_OUT_CONTROL ((ULONG) 19UL) /* CONTROL as seen by the start thread */ +#define MODULE_OUT_POINTER_STATUS ((ULONG) 20UL) /* First pointer API error */ +#define MODULE_OUT_POINTER_THREADS ((ULONG) 21UL) /* Thread entries with intact context */ +#define MODULE_OUT_POINTER_TIMERS ((ULONG) 22UL) /* Pointer callbacks with intact context */ +#define MODULE_OUT_LEGACY_TIMERS ((ULONG) 23UL) /* Legacy callbacks with intact input */ #define MODULE_DONE ((ULONG) 31UL) /* The context switch test points a thread's stack at the bottom of this area, diff --git a/test/tx/cmake/module_qemu/tests/harness_checks.c b/test/tx/cmake/module_qemu/tests/harness_checks.c index 70547ba53..b07a4aed0 100644 --- a/test/tx/cmake/module_qemu/tests/harness_checks.c +++ b/test/tx/cmake/module_qemu/tests/harness_checks.c @@ -38,6 +38,12 @@ VOID harness_check_services(ULONG cycle) harness_expect("module semaphore get", MODULE_SHARED[MODULE_OUT_SEMAPHORE_STATUS], (ULONG) TX_SUCCESS); harness_expect("module sleep lasted its ticks", (ULONG) (MODULE_SHARED[MODULE_OUT_SLEEP_TICKS] >= EXPECTED_SLEEP_TICKS), (ULONG) TX_TRUE); +#ifdef TX_ENABLE_POINTER_CONTEXT + harness_expect("module pointer services status", MODULE_SHARED[MODULE_OUT_POINTER_STATUS], TX_SUCCESS); + harness_expect("module pointer thread ran before and after reset", MODULE_SHARED[MODULE_OUT_POINTER_THREADS], 2UL); + harness_expect("module pointer timer callback", MODULE_SHARED[MODULE_OUT_POINTER_TIMERS], 1UL); + harness_expect("module legacy timer callback", MODULE_SHARED[MODULE_OUT_LEGACY_TIMERS], 1UL); +#endif } diff --git a/test/tx/cmake/module_qemu/tests/module_services.c b/test/tx/cmake/module_qemu/tests/module_services.c index 7f74b4a5f..63961a056 100644 --- a/test/tx/cmake/module_qemu/tests/module_services.c +++ b/test/tx/cmake/module_qemu/tests/module_services.c @@ -55,6 +55,13 @@ static TX_SEMAPHORE *done_semaphore; static ULONG worker_stack[WORKER_STACK_SIZE / sizeof(ULONG)]; static ULONG queue_storage[4]; +#ifdef TX_ENABLE_POINTER_CONTEXT +static TX_THREAD *pointer_thread; +static TX_TIMER *context_timer; +static ULONG pointer_stack[WORKER_STACK_SIZE / sizeof(ULONG)]; +static ULONG callback_context; +#endif + VOID module_start(ULONG id); @@ -86,6 +93,98 @@ ULONG control; } } +#ifdef TX_ENABLE_POINTER_CONTEXT +/* Count a thread entry only if the pointer still names module data. */ +static VOID pointer_worker_entry(VOID *context) +{ + if (context == &callback_context) + { + MODULE_SHARED[MODULE_OUT_POINTER_THREADS]++; + } + (VOID) tx_semaphore_put(done_semaphore); +} + +/* Count a pointer timer callback in the module's execution mode. */ +static VOID pointer_timer_entry(VOID *context) +{ +ULONG control; + + __asm__ volatile ("mrs %0, control" : "=r"(control)); + if ((context == &callback_context) && (control == MODULE_SHARED[MODULE_OUT_CONTROL])) + { + MODULE_SHARED[MODULE_OUT_POINTER_TIMERS]++; + } + (VOID) tx_semaphore_put(done_semaphore); +} + +/* Check that the legacy timer still passes its scalar input. */ +static VOID legacy_timer_entry(ULONG input) +{ + if (input == MODULE_QUEUE_MESSAGE) + { + MODULE_SHARED[MODULE_OUT_LEGACY_TIMERS]++; + } + (VOID) tx_semaphore_put(done_semaphore); +} + +/* Exercise pointer delivery, reset, and timer reuse through module calls. */ +static VOID check_pointer_services(VOID) +{ +ULONG status_word = MODULE_OUT_POINTER_STATUS; + + record_status(status_word, txm_module_object_allocate((VOID **) &pointer_thread, sizeof(TX_THREAD))); + record_status(status_word, txm_module_object_allocate((VOID **) &context_timer, sizeof(TX_TIMER))); + if (MODULE_SHARED[status_word] != TX_SUCCESS) + { + return; + } + + if (tx_thread_create_ptr(pointer_thread, "no entry", TX_NULL, &callback_context, + pointer_stack, sizeof(pointer_stack), 0U, 0U, + TX_NO_TIME_SLICE, TX_DONT_START) != TX_PTR_ERROR) + { + record_status(status_word, TX_NOT_DONE); + } + + /* The higher-priority worker completes before the start thread resets it. */ + record_status(status_word, tx_thread_create_ptr(pointer_thread, "pointer worker", pointer_worker_entry, + &callback_context, pointer_stack, sizeof(pointer_stack), + 0U, 0U, TX_NO_TIME_SLICE, TX_AUTO_START)); + record_status(status_word, tx_semaphore_get(done_semaphore, WAIT_TICKS)); + record_status(status_word, tx_thread_reset(pointer_thread)); + record_status(status_word, tx_thread_resume(pointer_thread)); + record_status(status_word, tx_semaphore_get(done_semaphore, WAIT_TICKS)); + + record_status(status_word, tx_timer_create_ptr(context_timer, "pointer timer", pointer_timer_entry, + &callback_context, 1UL, 0UL, TX_AUTO_ACTIVATE)); + record_status(status_word, tx_semaphore_get(done_semaphore, WAIT_TICKS)); + record_status(status_word, tx_timer_delete(context_timer)); + + record_status(status_word, txm_module_object_allocate((VOID **) &context_timer, sizeof(TX_TIMER))); + if (MODULE_SHARED[status_word] != TX_SUCCESS) + { + return; + } + record_status(status_word, tx_timer_create_ptr(context_timer, "silent timer", TX_NULL, + &callback_context, 1UL, 0UL, TX_AUTO_ACTIVATE)); + (VOID) tx_thread_sleep(SLEEP_TICKS); + if (tx_semaphore_get(done_semaphore, TX_NO_WAIT) != TX_NO_INSTANCE) + { + record_status(status_word, TX_NOT_DONE); + } + record_status(status_word, tx_timer_delete(context_timer)); + + record_status(status_word, txm_module_object_allocate((VOID **) &context_timer, sizeof(TX_TIMER))); + if (MODULE_SHARED[status_word] != TX_SUCCESS) + { + return; + } + record_status(status_word, tx_timer_create(context_timer, "legacy timer", legacy_timer_entry, + MODULE_QUEUE_MESSAGE, 1UL, 0UL, TX_AUTO_ACTIVATE)); + record_status(status_word, tx_semaphore_get(done_semaphore, WAIT_TICKS)); +} +#endif + VOID module_start(ULONG id) { @@ -127,6 +226,10 @@ ULONG kernel_word; (VOID) tx_thread_sleep(SLEEP_TICKS); MODULE_SHARED[MODULE_OUT_SLEEP_TICKS] = tx_time_get() - start_time; +#ifdef TX_ENABLE_POINTER_CONTEXT + check_pointer_services(); +#endif + kernel_word = MODULE_SHARED[MODULE_IN_KERNEL_WORD]; if (kernel_word != 0UL) { diff --git a/test/tx/cmake/module_qemu/tests/test_module_lifecycle.c b/test/tx/cmake/module_qemu/tests/test_module_lifecycle.c index 8c241e793..130b7497d 100644 --- a/test/tx/cmake/module_qemu/tests/test_module_lifecycle.c +++ b/test/tx/cmake/module_qemu/tests/test_module_lifecycle.c @@ -39,6 +39,52 @@ extern UCHAR module_services_protected[]; static TXM_MODULE_INSTANCE test_module; +#ifdef TX_ENABLE_POINTER_CONTEXT +/* Timer messages with different callback types must remain separate. */ +static VOID check_timer_message_types(VOID) +{ +TX_QUEUE queue; +TXM_MODULE_CALLBACK_MESSAGE message = {0}; +ULONG storage[3U * (sizeof(TXM_MODULE_CALLBACK_MESSAGE) / sizeof(ULONG))]; +UINT status; + + status = tx_queue_create(&queue, "test callback queue", + sizeof(TXM_MODULE_CALLBACK_MESSAGE) / sizeof(ULONG), + storage, sizeof(storage)); + harness_expect("test callback queue created", status, TX_SUCCESS); + if (status != TX_SUCCESS) + { + return; + } + + message.txm_module_callback_message_type = TXM_TIMER_CALLBACK; + message.txm_module_callback_message_activation_count = 1; + _txm_module_manager_callback_request(&queue, &message); + + message.txm_module_callback_message_type = TXM_TIMER_CALLBACK_PTR; + _txm_module_manager_callback_request(&queue, &message); + _txm_module_manager_callback_request(&queue, &message); + + harness_expect("received scalar timer message", tx_queue_receive(&queue, &message, TX_NO_WAIT), TX_SUCCESS); + harness_expect("scalar timer message type", message.txm_module_callback_message_type, TXM_TIMER_CALLBACK); + harness_expect("scalar timer message count", message.txm_module_callback_message_activation_count, 1UL); + harness_expect("received pointer timer message", tx_queue_receive(&queue, &message, TX_NO_WAIT), TX_SUCCESS); + harness_expect("pointer timer message type", message.txm_module_callback_message_type, TXM_TIMER_CALLBACK_PTR); + harness_expect("pointer timer message count", message.txm_module_callback_message_activation_count, 2UL); + harness_expect("test callback queue deleted", tx_queue_delete(&queue), TX_SUCCESS); +} + +/* A snapshotted expiration cannot be delivered after stop or unload. */ +static VOID check_inactive_timer_notification(TXM_MODULE_INSTANCE *module_instance) +{ +ULONG errors_before = _txm_module_manager_callback_error_count; + + _txm_module_manager_timer_notify_pointer(module_instance, TX_NULL, TX_NULL); + harness_expect("inactive module rejected timer notification", + _txm_module_manager_callback_error_count, errors_before + 1UL); +} +#endif + VOID harness_test(VOID) { @@ -47,6 +93,10 @@ ULONG available_before; harness_print("Module lifecycle: protected module, load/start/stop/unload twice\n"); +#ifdef TX_ENABLE_POINTER_CONTEXT + check_timer_message_types(); +#endif + available_before = harness_module_pool_available(); for (cycle = 1UL; cycle <= LIFECYCLE_CYCLES; cycle++) @@ -70,7 +120,13 @@ ULONG available_before; harness_expect("no memory fault", harness_fault_count, 0UL); harness_expect("module stop", (ULONG) txm_module_manager_stop(&test_module), (ULONG) TX_SUCCESS); +#ifdef TX_ENABLE_POINTER_CONTEXT + check_inactive_timer_notification(&test_module); +#endif harness_expect("module unload", (ULONG) txm_module_manager_unload(&test_module), (ULONG) TX_SUCCESS); +#ifdef TX_ENABLE_POINTER_CONTEXT + check_inactive_timer_notification(&test_module); +#endif harness_expect("module memory returned", harness_module_pool_available(), available_before); } } diff --git a/test/tx/regression/threadx_pointer_callback_test.c b/test/tx/regression/threadx_pointer_callback_test.c index 0726f5219..98c319c22 100644 --- a/test/tx/regression/threadx_pointer_callback_test.c +++ b/test/tx/regression/threadx_pointer_callback_test.c @@ -8,6 +8,7 @@ * * SPDX-License-Identifier: MIT **************************************************************************/ +// Portions of this file were generated with AI assistance. #include #include @@ -30,6 +31,8 @@ static TX_THREAD thread_ulong_test; static TX_TIMER timer_ptr_test; static TX_TIMER timer_ulong_test; +static TX_TIMER timer_silent_test; +static TX_TIMER timer_dispatched_test; static void *received_thread_ptr_ctx = TX_NULL; static void *received_timer_ptr_ctx = TX_NULL; @@ -40,6 +43,7 @@ static volatile UINT thread_ptr_executed = 0; static volatile UINT thread_ulong_executed = 0; static volatile UINT timer_ptr_executed = 0; static volatile UINT timer_ulong_executed = 0; +static volatile UINT timer_dispatched = 0; #if (defined(__x86_64__) || defined(_WIN64) || defined(__aarch64__) || (defined(__riscv_xlen) && (__riscv_xlen == 64)) || defined(__LP64__) || defined(_LP64)) #define TEST_PTR_VAL_1 ((VOID *)(ALIGN_TYPE) 0x123456789ABCDEF0ULL) @@ -74,13 +78,23 @@ static void thread_ulong_entry(ULONG entry_input) static void timer_ptr_expiration(VOID *expiration_input) { received_timer_ptr_ctx = expiration_input; - timer_ptr_executed = 1; + timer_ptr_executed++; } static void timer_ulong_expiration(ULONG expiration_input) { received_timer_ulong_ctx = expiration_input; - timer_ulong_executed = 1; + timer_ulong_executed++; +} + +/* Verify the owner and callback delivered to the timer dispatcher. */ +static void timer_dispatch(VOID *owner, VOID (*callback)(VOID *), VOID *context) +{ + if ((owner == &timer_dispatched_test) && (callback == timer_ptr_expiration) && + (context == TEST_PTR_VAL_2)) + { + timer_dispatched++; + } } static void thread_0_entry(ULONG thread_input) @@ -200,6 +214,36 @@ static void thread_0_entry(ULONG thread_input) } #endif + /* Defer the first pointer callback for a full wheel turn, then reload all timers. */ + status = tx_timer_change(&timer_ptr_test, TX_TIMER_ENTRIES + 1, 2); + status |= tx_timer_change(&timer_ulong_test, 1, 2); + status |= tx_timer_create_ptr(&timer_silent_test, "silent timer", TX_NULL, TX_NULL, + 1, 2, TX_AUTO_ACTIVATE); + status |= _txe_timer_create_ptr_dispatch(&timer_dispatched_test, "dispatched timer", + timer_ptr_expiration, expected_timer_ptr, timer_dispatch, + &timer_dispatched_test, 1, 0, TX_AUTO_ACTIVATE, + sizeof(TX_TIMER)); + status |= tx_timer_activate(&timer_ptr_test); + status |= tx_timer_activate(&timer_ulong_test); + if (status != TX_SUCCESS) + { + error++; + } + + tx_thread_sleep(5); + if ((timer_ptr_executed != 1) || (timer_ulong_executed < 2) || (timer_dispatched != 1)) + { + error++; + } + + tx_thread_sleep(TX_TIMER_ENTRIES + 4); + if ((timer_ptr_executed < 3) || (received_timer_ptr_ctx != expected_timer_ptr)) + { + error++; + } + tx_timer_delete(&timer_silent_test); + tx_timer_delete(&timer_dispatched_test); + /* Clean up created objects. */ tx_timer_deactivate(&timer_ptr_test); tx_timer_delete(&timer_ptr_test); From 290606a8d385f97a8db2bb79b908ae708a1fa973 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Desbiens?= Date: Thu, 26 Nov 2026 09:04:49 -0500 Subject: [PATCH 4/4] Updated ARMv7-M module sources for pointer thread entries MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The generated Cortex-M3, M4, and M7 module shells dispatched pointer thread entries, but the ARMv7-M sources still used the scalar call. Applied the same dispatch to the four toolchain sources. Regenerating the 12 ports with the module copy script produced identical files. Assisted-by: Codex (GPT-6.2-Sol) Signed-off-by: Frédéric Desbiens --- .../ac5/module_lib/src/txm_module_thread_shell_entry.c | 3 ++- .../ac6/module_lib/src/txm_module_thread_shell_entry.c | 3 ++- .../gnu/module_lib/src/txm_module_thread_shell_entry.c | 3 ++- .../iar/module_lib/src/txm_module_thread_shell_entry.c | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/ports_arch/ARMv7-M/threadx_modules/ac5/module_lib/src/txm_module_thread_shell_entry.c b/ports_arch/ARMv7-M/threadx_modules/ac5/module_lib/src/txm_module_thread_shell_entry.c index 0e46caea5..2ab4b867d 100644 --- a/ports_arch/ARMv7-M/threadx_modules/ac5/module_lib/src/txm_module_thread_shell_entry.c +++ b/ports_arch/ARMv7-M/threadx_modules/ac5/module_lib/src/txm_module_thread_shell_entry.c @@ -8,6 +8,7 @@ * * SPDX-License-Identifier: MIT **************************************************************************/ +// Portions of this file were generated with AI assistance. /**************************************************************************/ @@ -138,7 +139,7 @@ VOID _txm_module_thread_shell_entry(TX_THREAD *thread_ptr, TXM_MODULE_THREAD_EN #endif /* Call current thread's entry function. */ - (thread_info -> txm_module_thread_entry_info_entry) (thread_info -> txm_module_thread_entry_info_parameter); + TXM_MODULE_THREAD_ENTRY_CALL(thread_info); /* Suspend thread with a "completed" state. */ diff --git a/ports_arch/ARMv7-M/threadx_modules/ac6/module_lib/src/txm_module_thread_shell_entry.c b/ports_arch/ARMv7-M/threadx_modules/ac6/module_lib/src/txm_module_thread_shell_entry.c index cd286c2dc..49400aa2c 100644 --- a/ports_arch/ARMv7-M/threadx_modules/ac6/module_lib/src/txm_module_thread_shell_entry.c +++ b/ports_arch/ARMv7-M/threadx_modules/ac6/module_lib/src/txm_module_thread_shell_entry.c @@ -8,6 +8,7 @@ * * SPDX-License-Identifier: MIT **************************************************************************/ +// Portions of this file were generated with AI assistance. /**************************************************************************/ @@ -139,7 +140,7 @@ VOID _txm_module_thread_shell_entry(TX_THREAD *thread_ptr, TXM_MODULE_THREAD_EN #endif /* Call current thread's entry function. */ - (thread_info -> txm_module_thread_entry_info_entry) (thread_info -> txm_module_thread_entry_info_parameter); + TXM_MODULE_THREAD_ENTRY_CALL(thread_info); /* Suspend thread with a "completed" state. */ diff --git a/ports_arch/ARMv7-M/threadx_modules/gnu/module_lib/src/txm_module_thread_shell_entry.c b/ports_arch/ARMv7-M/threadx_modules/gnu/module_lib/src/txm_module_thread_shell_entry.c index 01f2f9093..82057a5fd 100644 --- a/ports_arch/ARMv7-M/threadx_modules/gnu/module_lib/src/txm_module_thread_shell_entry.c +++ b/ports_arch/ARMv7-M/threadx_modules/gnu/module_lib/src/txm_module_thread_shell_entry.c @@ -8,6 +8,7 @@ * * SPDX-License-Identifier: MIT **************************************************************************/ +// Portions of this file were generated with AI assistance. /**************************************************************************/ @@ -137,7 +138,7 @@ VOID _txm_module_thread_shell_entry(TX_THREAD *thread_ptr, TXM_MODULE_THREAD_EN #endif /* Call current thread's entry function. */ - (thread_info -> txm_module_thread_entry_info_entry) (thread_info -> txm_module_thread_entry_info_parameter); + TXM_MODULE_THREAD_ENTRY_CALL(thread_info); /* Suspend thread with a "completed" state. */ diff --git a/ports_arch/ARMv7-M/threadx_modules/iar/module_lib/src/txm_module_thread_shell_entry.c b/ports_arch/ARMv7-M/threadx_modules/iar/module_lib/src/txm_module_thread_shell_entry.c index 0f892ce5f..161706df9 100644 --- a/ports_arch/ARMv7-M/threadx_modules/iar/module_lib/src/txm_module_thread_shell_entry.c +++ b/ports_arch/ARMv7-M/threadx_modules/iar/module_lib/src/txm_module_thread_shell_entry.c @@ -8,6 +8,7 @@ * * SPDX-License-Identifier: MIT **************************************************************************/ +// Portions of this file were generated with AI assistance. /**************************************************************************/ @@ -137,7 +138,7 @@ VOID _txm_module_thread_shell_entry(TX_THREAD *thread_ptr, TXM_MODULE_THREAD_EN #endif /* Call current thread's entry function. */ - (thread_info -> txm_module_thread_entry_info_entry) (thread_info -> txm_module_thread_entry_info_parameter); + TXM_MODULE_THREAD_ENTRY_CALL(thread_info); /* Suspend thread with a "completed" state. */