Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ target_sources(${PROJECT_NAME}
${CMAKE_CURRENT_LIST_DIR}/src/tx_queue_delete.c
${CMAKE_CURRENT_LIST_DIR}/src/tx_queue_flush.c
${CMAKE_CURRENT_LIST_DIR}/src/tx_queue_front_send.c
${CMAKE_CURRENT_LIST_DIR}/src/tx_queue_peek.c
${CMAKE_CURRENT_LIST_DIR}/src/tx_queue_info_get.c
${CMAKE_CURRENT_LIST_DIR}/src/tx_queue_initialize.c
${CMAKE_CURRENT_LIST_DIR}/src/tx_queue_performance_info_get.c
Expand Down Expand Up @@ -164,6 +165,7 @@ target_sources(${PROJECT_NAME}
${CMAKE_CURRENT_LIST_DIR}/src/txe_queue_delete.c
${CMAKE_CURRENT_LIST_DIR}/src/txe_queue_flush.c
${CMAKE_CURRENT_LIST_DIR}/src/txe_queue_front_send.c
${CMAKE_CURRENT_LIST_DIR}/src/txe_queue_peek.c
${CMAKE_CURRENT_LIST_DIR}/src/txe_queue_info_get.c
${CMAKE_CURRENT_LIST_DIR}/src/txe_queue_prioritize.c
${CMAKE_CURRENT_LIST_DIR}/src/txe_queue_receive.c
Expand Down
6 changes: 6 additions & 0 deletions common/inc/tx_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,7 @@ UINT _tx_trace_interrupt_control(UINT new_posture);
#define tx_queue_send _tx_queue_send
#define tx_queue_send_notify _tx_queue_send_notify
#define tx_queue_front_send _tx_queue_front_send
#define tx_queue_peek _tx_queue_peek
#define tx_queue_prioritize _tx_queue_prioritize

#define tx_semaphore_ceiling_put _tx_semaphore_ceiling_put
Expand Down Expand Up @@ -1250,6 +1251,7 @@ UINT _tx_trace_interrupt_control(UINT new_posture);
#define tx_queue_send _txr_queue_send
#define tx_queue_send_notify _txr_queue_send_notify
#define tx_queue_front_send _txr_queue_front_send
#define tx_queue_peek _txr_queue_peek
#define tx_queue_prioritize _txr_queue_prioritize

#define tx_semaphore_ceiling_put _txr_semaphore_ceiling_put
Expand Down Expand Up @@ -1361,6 +1363,7 @@ UINT _tx_el_interrupt_control(UINT new_posture);
#define tx_queue_send _txe_queue_send
#define tx_queue_send_notify _txe_queue_send_notify
#define tx_queue_front_send _txe_queue_front_send
#define tx_queue_peek _txe_queue_peek
#define tx_queue_prioritize _txe_queue_prioritize

#define tx_semaphore_ceiling_put _txe_semaphore_ceiling_put
Expand Down Expand Up @@ -1620,6 +1623,7 @@ UINT _tx_queue_receive(TX_QUEUE *queue_ptr, VOID *destination_ptr, ULONG
UINT _tx_queue_send(TX_QUEUE *queue_ptr, VOID *source_ptr, ULONG wait_option);
UINT _tx_queue_send_notify(TX_QUEUE *queue_ptr, VOID (*queue_send_notify)(TX_QUEUE *notify_queue_ptr));
UINT _tx_queue_front_send(TX_QUEUE *queue_ptr, VOID *source_ptr, ULONG wait_option);
UINT _tx_queue_peek(TX_QUEUE *queue_ptr, VOID *destination_ptr, ULONG wait_option);


/* Define error checking shells for API services. These are only referenced by the
Expand All @@ -1636,6 +1640,7 @@ UINT _txe_queue_receive(TX_QUEUE *queue_ptr, VOID *destination_ptr, ULONG
UINT _txe_queue_send(TX_QUEUE *queue_ptr, VOID *source_ptr, ULONG wait_option);
UINT _txe_queue_send_notify(TX_QUEUE *queue_ptr, VOID (*queue_send_notify)(TX_QUEUE *notify_queue_ptr));
UINT _txe_queue_front_send(TX_QUEUE *queue_ptr, VOID *source_ptr, ULONG wait_option);
UINT _txe_queue_peek(TX_QUEUE *queue_ptr, VOID *destination_ptr, ULONG wait_option);
#ifdef TX_ENABLE_MULTI_ERROR_CHECKING
UINT _txr_queue_create(TX_QUEUE *queue_ptr, TX_NAME_CONST CHAR *name_ptr, UINT message_size,
VOID *queue_start, ULONG queue_size, UINT queue_control_block_size);
Expand All @@ -1648,6 +1653,7 @@ UINT _txr_queue_receive(TX_QUEUE *queue_ptr, VOID *destination_ptr, ULONG
UINT _txr_queue_send(TX_QUEUE *queue_ptr, VOID *source_ptr, ULONG wait_option);
UINT _txr_queue_send_notify(TX_QUEUE *queue_ptr, VOID (*queue_send_notify)(TX_QUEUE *notify_queue_ptr));
UINT _txr_queue_front_send(TX_QUEUE *queue_ptr, VOID *source_ptr, ULONG wait_option);
UINT _txr_queue_peek(TX_QUEUE *queue_ptr, VOID *destination_ptr, ULONG wait_option);
#endif


Expand Down
1 change: 1 addition & 0 deletions common/inc/tx_trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ typedef struct TX_TRACE_OBJECT_ENTRY_STRUCT
#define TX_TRACE_QUEUE_RECEIVE 68 /* I1 = queue ptr, I2 = destination ptr, I3 = wait option, I4 = enqueued */
#define TX_TRACE_QUEUE_SEND 69 /* I1 = queue ptr, I2 = source ptr, I3 = wait option, I4 = enqueued */
#define TX_TRACE_QUEUE_SEND_NOTIFY 70 /* I1 = queue ptr */
#define TX_TRACE_QUEUE_PEEK 71 /* I1 = queue ptr, I2 = destination ptr, I3 = wait option, I4 = enqueued */
#define TX_TRACE_SEMAPHORE_CEILING_PUT 80 /* I1 = semaphore ptr, I2 = current count, I3 = suspended count,I4 =ceiling */
#define TX_TRACE_SEMAPHORE_CREATE 81 /* I1 = semaphore ptr, I2 = initial count, I3 = stack ptr */
#define TX_TRACE_SEMAPHORE_DELETE 82 /* I1 = semaphore ptr, I2 = stack ptr */
Expand Down
142 changes: 142 additions & 0 deletions common/src/tx_queue_peek.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/***************************************************************************
* 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
**************************************************************************/


/**************************************************************************/
/**************************************************************************/
/** */
/** ThreadX Component */
/** */
/** Queue */
/** */
/**************************************************************************/
/**************************************************************************/

#define TX_SOURCE_CODE


/* Include necessary system files. */

#include "tx_api.h"
#include "tx_trace.h"
#include "tx_thread.h"
#include "tx_queue.h"


/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _tx_queue_peek PORTABLE C */
/* */
/* DESCRIPTION */
/* */
/* This function copies the message at the front of the specified */
/* queue without removing it. The message is the one the next */
/* tx_queue_receive would return. This function never suspends, so */
/* it may be called from threads, timers and ISRs. Only TX_NO_WAIT is */
/* supported as wait option; the parameter is reserved for a future */
/* blocking peek. */
/* */
/* INPUT */
/* */
/* queue_ptr Pointer to queue control block */
/* destination_ptr Pointer to message destination */
/* **** MUST BE LARGE ENOUGH TO */
/* HOLD MESSAGE **** */
/* wait_option Suspension option, must be */
/* TX_NO_WAIT */
/* */
/* OUTPUT */
/* */
/* TX_SUCCESS Message copied */
/* TX_QUEUE_EMPTY Queue is empty */
/* TX_WAIT_ERROR Wait option is not TX_NO_WAIT */
/* */
/* CALLS */
/* */
/* None */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* */
/**************************************************************************/
UINT _tx_queue_peek(TX_QUEUE *queue_ptr, VOID *destination_ptr, ULONG wait_option)
{

TX_INTERRUPT_SAVE_AREA

TX_THREAD *thread_ptr;
ULONG *source;
ULONG *destination;
UINT size;
UINT status;


/* Blocking peek is not supported. */
if (wait_option != TX_NO_WAIT)
{

status = TX_WAIT_ERROR;
}
else
{

/* Disable interrupts to peek at the queue. */
TX_DISABLE

/* If trace is enabled, insert this event into the trace buffer. */
TX_TRACE_IN_LINE_INSERT(TX_TRACE_QUEUE_PEEK, queue_ptr, TX_POINTER_TO_ULONG_CONVERT(destination_ptr), wait_option, queue_ptr -> tx_queue_enqueued, TX_TRACE_QUEUE_EVENTS)

/* Determine if there is anything in the queue. */
if (queue_ptr -> tx_queue_enqueued != TX_NO_MESSAGES)
{

/* Default to the message at the read pointer. */
source = queue_ptr -> tx_queue_read;

/* Threads suspended on a non-empty queue are senders waiting on a full queue.
A front send suspension at the head is what tx_queue_receive returns next. */
if (queue_ptr -> tx_queue_suspended_count != TX_NO_SUSPENSIONS)
{

thread_ptr = queue_ptr -> tx_queue_suspension_list;
if (thread_ptr -> tx_thread_suspend_option == TX_TRUE)
{

source = TX_VOID_TO_ULONG_POINTER_CONVERT(thread_ptr -> tx_thread_additional_suspend_info);
}
}

/* Setup destination pointer and size. */
destination = TX_VOID_TO_ULONG_POINTER_CONVERT(destination_ptr);
size = queue_ptr -> tx_queue_message_size;

/* Copy message. Note that the source and destination pointers are
incremented by the macro. */
TX_QUEUE_MESSAGE_COPY(source, destination, size)

status = TX_SUCCESS;
}
else
{

status = TX_QUEUE_EMPTY;
}

/* Restore interrupts. */
TX_RESTORE
}

/* Return completion status. */
return(status);
}

106 changes: 106 additions & 0 deletions common/src/txe_queue_peek.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/***************************************************************************
* 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
**************************************************************************/


/**************************************************************************/
/**************************************************************************/
/** */
/** ThreadX Component */
/** */
/** Queue */
/** */
/**************************************************************************/
/**************************************************************************/

#define TX_SOURCE_CODE


/* Include necessary system files. */

#include "tx_api.h"
#include "tx_queue.h"


/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _txe_queue_peek PORTABLE C */
/* */
/* DESCRIPTION */
/* */
/* This function checks for errors in the queue peek function call. */
/* */
/* INPUT */
/* */
/* queue_ptr Pointer to queue control block */
/* destination_ptr Pointer to message destination */
/* **** MUST BE LARGE ENOUGH TO */
/* HOLD MESSAGE **** */
/* wait_option Suspension option, must be */
/* TX_NO_WAIT */
/* */
/* OUTPUT */
/* */
/* TX_QUEUE_ERROR Invalid queue pointer */
/* TX_PTR_ERROR Invalid destination pointer (NULL)*/
/* TX_WAIT_ERROR Wait option is not TX_NO_WAIT */
/* status Actual completion status */
/* */
/* CALLS */
/* */
/* _tx_queue_peek Actual queue peek function */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* */
/**************************************************************************/
UINT _txe_queue_peek(TX_QUEUE *queue_ptr, VOID *destination_ptr, ULONG wait_option)
{

UINT status;


/* Check for an invalid queue pointer. */
if (queue_ptr == TX_NULL)
{

/* Queue pointer is invalid, return appropriate error code. */
status = TX_QUEUE_ERROR;
}

/* Now check for invalid queue ID. */
else if (queue_ptr -> tx_queue_id != TX_QUEUE_ID)
{

/* Queue pointer is invalid, return appropriate error code. */
status = TX_QUEUE_ERROR;
}

/* Check for an invalid destination for message. */
else if (destination_ptr == TX_NULL)
{

/* Null destination pointer, return appropriate error. */
status = TX_PTR_ERROR;
}
else
{

/* Call actual queue peek function, which also rejects any wait option
other than TX_NO_WAIT. */
status = _tx_queue_peek(queue_ptr, destination_ptr, wait_option);
}

/* Return completion status. */
return(status);
}

1 change: 1 addition & 0 deletions common_modules/inc/txm_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ 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_QUEUE_PEEK_CALL 97

#define TXM_MODULE_PORT_EXTENSION_API_ID_START 500
#define TXM_MODULE_PORT_EXTENSION_API_ID_END 999
Expand Down
1 change: 1 addition & 0 deletions common_modules/inc/txm_module_user_sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
/* #define TXM_QUEUE_FLUSH_CALL_NOT_USED */
/* #define TXM_QUEUE_FRONT_SEND_CALL_NOT_USED */
/* #define TXM_QUEUE_INFO_GET_CALL_NOT_USED */
/* #define TXM_QUEUE_PEEK_CALL_NOT_USED */
/* #define TXM_QUEUE_PERFORMANCE_INFO_GET_CALL_NOT_USED */
/* #define TXM_QUEUE_PERFORMANCE_SYSTEM_INFO_GET_CALL_NOT_USED */
/* #define TXM_QUEUE_PRIORITIZE_CALL_NOT_USED */
Expand Down
Loading
Loading