Skip to content

Commit 46f4196

Browse files
Added Configurable Queue Wait Time (#346)
1 parent 5b0f29e commit 46f4196

2 files changed

Lines changed: 36 additions & 17 deletions

File tree

threadX/inc/u_tx_queues.h

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55
#include "u_tx_debug.h"
66
#include <stdint.h>
77

8-
/*
9-
* Basically just a wrapper for ThreadX stuff. Lets you create/configure queues.
10-
*
11-
* Author: Blake Jackson
12-
*/
8+
// clang-format off
139

14-
/* Queue Config Macros */
15-
#define QUEUE_WAIT_TIME TX_NO_WAIT
10+
/*
11+
* Basically just a wrapper for ThreadX stuff. Lets you create/configure queues.
12+
*
13+
* Author: Blake Jackson
14+
*/
1615

1716
typedef struct {
1817
/* PUBLIC: Queue Configuration Settings */
@@ -29,12 +28,32 @@ typedef struct {
2928
size_t _words; /* Size of each queue message, in 32-bit words. */
3029
} queue_t;
3130

32-
/* API */
31+
/**
32+
* @brief Initializes a ThreadX queue configured in a 'queue_t' instance.
33+
*
34+
* @param byte_pool Pointer to the ThreadX application byte pool.
35+
* @param queue Pointer to the queue instance to initialize.
36+
*/
3337
uint8_t create_queue(TX_BYTE_POOL *byte_pool, queue_t *queue);
34-
uint8_t queue_send(queue_t *queue,
35-
void *message); // Sends a message to the specified queue.
36-
uint8_t
37-
queue_receive(queue_t *queue,
38-
void *message); // Receives a message from the specified queue
38+
39+
/**
40+
* @brief Adds a message to the back of a ThreadX queue.
41+
*
42+
* @param queue Pointer to queue to add to.
43+
* @param message Pointer to the message to add. The size of the message should match the queue's 'message_size' setting.
44+
* @param wait_time The amount of time (in ticks) to wait before timing out. Can either be 'TX_NO_WAIT', 'TX_WAIT_FOREVER', or a numeric value of ticks.
45+
*/
46+
uint8_t queue_send(queue_t *queue, void *message, uint32_t wait_time);
47+
48+
/**
49+
* @brief Removes the frontmost message in a ThreadX queue, and places it in a buffer provided in the 'message' parameter.
50+
*
51+
* @param queue Pointer to queue to get from.
52+
* @param message Pointer to a buffer to store the removed message. The size of the buffer should match the queue's 'message_size' setting.
53+
* @param wait_time The amount of time (in ticks) to wait before timing out. Can either be 'TX_NO_WAIT', 'TX_WAIT_FOREVER', or a numeric value of ticks.
54+
*/
55+
uint8_t queue_receive(queue_t *queue, void *message, uint32_t wait_time);
56+
57+
// clang-format on
3958

4059
#endif

threadX/src/u_tx_queues.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ uint8_t create_queue(TX_BYTE_POOL *byte_pool, queue_t *queue)
4242
return U_SUCCESS;
4343
}
4444

45-
uint8_t queue_send(queue_t *queue, void *message)
45+
uint8_t queue_send(queue_t *queue, void *message, uint32_t wait_time)
4646
{
4747
UINT status;
4848

@@ -54,7 +54,7 @@ uint8_t queue_send(queue_t *queue, void *message)
5454
memcpy(buffer, message, queue->_bytes);
5555

5656
/* Send message (buffer) to the queue. */
57-
status = tx_queue_send(&queue->_TX_QUEUE, buffer, QUEUE_WAIT_TIME);
57+
status = tx_queue_send(&queue->_TX_QUEUE, buffer, (ULONG)wait_time);
5858
if (status != TX_SUCCESS) {
5959
PRINTLN_ERROR("Failed to send message to queue (Status: %d/%s, Queue: %s).", status, tx_status_toString(status), queue->_TX_QUEUE.tx_queue_name);
6060
return U_ERROR;
@@ -63,7 +63,7 @@ uint8_t queue_send(queue_t *queue, void *message)
6363
return U_SUCCESS;
6464
}
6565

66-
uint8_t queue_receive(queue_t *queue, void *message)
66+
uint8_t queue_receive(queue_t *queue, void *message, uint32_t wait_time)
6767
{
6868
UINT status;
6969

@@ -72,7 +72,7 @@ uint8_t queue_receive(queue_t *queue, void *message)
7272
memset(buffer, 0, sizeof(buffer)); // Initialize buffer to zero
7373

7474
/* Receive message from the queue. */
75-
status = tx_queue_receive(&queue->_TX_QUEUE, buffer, QUEUE_WAIT_TIME);
75+
status = tx_queue_receive(&queue->_TX_QUEUE, buffer, (ULONG)wait_time);
7676
if (status == TX_QUEUE_EMPTY) {
7777
return U_QUEUE_EMPTY;
7878
}

0 commit comments

Comments
 (0)