Message Queue

  • This is the Message Queue implementation with fixed size of user initialization.

  • The main buffer structure variable and the internal data buffer both should be declared on the application side and the pointers of the variables are used in the module.

Usage

  1. All API functions have the first argument as the buffer instance.

  2. Internal data buffer size and pointer are initialized with module init function.

  3. Module read and module write functions are used to read/write data bytes.

  4. Other API functions to return the status of buffer whether empty or full.

  5. Return codes of API functions are defined in header file.

Message queue calls

Function

Description

rs_msg_queue_init

Function to initialize the message queue

rs_msg_queue_push

Function to push the data into the message queue buffer

rs_msg_queue_pop

Function to pop the data from the message queue buffer

rs_msg_queue_peek

Function to get top of the data from the buffer

rs_msg_queue_get_used_space

Function to get buffer count

rs_msg_queue_get_free_size

Function to get remaining bytes

rs_msg_queue_get_msg_size

Function to get next message or else to get the full message size.

rs_msg_queue_is_full

Function to know the buffer is full or not

rs_msg_queue_is_empty

Function to know the buffer is empty or not

rs_msg_queue_flush

Function to reset the elements of the ring buffer structure

Feature Supported

  • Message queue supports two different types of queues - FIFO and LIFO

See also

Macro’s are
  1. RS_MSG_QUEUE_TYPE_FIFO 1

  2. RS_MSG_QUEUE_TYPE_LIFO 2

  • Message queue supports to get the full message size in the queue as well as next message size in the queue

See also

Macro’s are
  1. RS_MSG_QUEUE_GET_NEXT_MSG_SIZE 1

  2. RS_MSG_QUEUE_GET_FULL_MSG_SIZE 2

  • Message queue supports Push, Pop, Peek operations.

  • Message queue supports overwrite feature in the queue for both LIFO and FIFO

  • It supports Reset feature to reset the queue elements

  • Message queue supports data size format

See also

  1. It has fixed data size. In queue it contains data with fixed length.

  2. It also supports varying data size. In queue it contains both data length and data message.

Limitations

See also

1.Message queue doesn’t support overwrite feature for LIFO queue type of varying data size. 2.For fixed data size, push, pop and other opeation should be with fixed data size

Error Code

  • Every API’s for the message queue module returns some success or failure values. Please refer below section,

Example Demo

Please refer below section,

Message Queue Header Details

Documentation from the relevant header as follows:

Message Queue Specific APIs.

Defines macros and functions specific to Message Queue functionality

Author

Embien RAPIDSEA Team

Copyright

Embien Technologies India Pvt. Ltd.

Defines

RS_MSG_QUEUE_TYPE_FIFO
RS_MSG_QUEUE_TYPE_LIFO
RS_MSG_QUEUE_GET_NEXT_MSG_SIZE
RS_MSG_QUEUE_GET_FULL_MSG_SIZE

Typedefs

typedef struct tag_rs_msg_queue rs_msg_queue_t

Structure for setting up message queue

Functions

rs_ret_val_t rs_msg_queue_init(rs_msg_queue_t *ptr_msg_queue, uint8_t *ptr_buf, uint8_t u8_queue_type, uint8_t u8_enable_overwrite, uint32_t u32_buf_size, uint32_t u32_data_size)

Initialize the queue with buffer and buffer size.

This function Initializes the queue with buffer and buffer size

Parameters:
  • ptr_msg_queue[in] - Pointer to the structure

  • ptr_buf[in] - Pointer to the message data

  • u8_queue_type[in] - Message queue type LIFO or FIFO

  • u8_enable_overwrite[in] - Overwrite oldest message if it is enable

  • u32_buf_size[in] - Size of the message data

  • u32_data_size[in] - Size of the push data size in bytes

Returns:

0 on success or error code on failure

rs_ret_val_t rs_msg_queue_push(rs_msg_queue_t *ptr_msg_queue, void *ptr_data, uint32_t u32_data_size)

Push the message data as a element in the queue.

This function pushes the message data with different data types as a element in the queue as per the size

Parameters:
  • ptr_msg_queue[in] - Pointer to the structure

  • ptr_data[out] - Pointer to the message data

  • u32_data_size[in] - Size of the message data

Returns:

0 on success or error code on failure

rs_ret_val_t rs_msg_queue_pop(rs_msg_queue_t *ptr_msg_queue, void *ptr_data, uint32_t u32_max_size)

Pop the message data from the queue as per the given size of input.

This function pops the message data from the queue as per the given size of input

Parameters:
  • ptr_msg_queue[in] - Pointer to the structure

  • ptr_data[out] - Pointer to the message data

  • u32_max-size[in] - maximum size of the message data

Returns:

0 on success or error code on failure

rs_ret_val_t rs_msg_queue_peek(rs_msg_queue_t *ptr_msg_queue, void *ptr_data, int32_t u32_max_size)
uint32_t rs_msg_queue_get_used_space(rs_msg_queue_t *ptr_msg_queue)

Returns the current consumed bytes in the queue.

This function returns the current consumed bytes in the data buffer

Parameters:

ptr_msg_queue[in] - Pointer to the structure

Returns:

Used space in bytes

rs_ret_val_t rs_msg_queue_is_full(rs_msg_queue_t *ptr_msg_queue)

Checks and return queue is full or not full.

This function checks and return queue is full or not full

Parameters:

ptr_msg_queue[in] - Pointer to the structure

Returns:

0 on success or error code on failure

rs_ret_val_t rs_msg_queue_is_empty(rs_msg_queue_t *ptr_msg_queue)

Checks and return queue is empty or not empty.

This function checks and return queue is empty or not empty

Parameters:

ptr_msg_queue[in] - Pointer to the structure

Returns:

0 on success or error code on failure

rs_ret_val_t rs_msg_queue_flush(rs_msg_queue_t *ptr_msg_queue)

Flush all the elements in the queue.

This function flushes all the elements in the queue

Parameters:

ptr_msg_queue – - Pointer to the structure

Returns:

0 on success or error code on failure

rs_ret_val_t rs_msg_queue_get_free_size(rs_msg_queue_t *ptr_msg_queue)

Returns remaining bytes in the queue.

This function returns remaining bytes in the queue

Parameters:

ptr_msg_queue[in] - Pointer to the structure

Returns:

Remaining bytes

rs_ret_val_t rs_msg_queue_get_msg_size(rs_msg_queue_t *ptr_msg_queue, uint8_t u8_get_size_type)

Returns message full size or next message size.

This function returns full size or next message size

Parameters:
  • ptr_msg_queue[in] - Pointer to the structure

  • u8_get_size_type[in] - Type of the message either to get size for next message size or full message size

Returns:

Remaining bytes

struct tag_rs_msg_queue
#include <rs_msg_queue.h>

Structure for setting up message queue

Public Members

uint8_t *ptr_buf

Pointer to the storage area

uint8_t queue_type

Message Queue Type LIFO or FIFO

uint32_t buf_size

Size of the storage area

uint32_t data_size

Size of push data size

int32_t read_index

Next index to read from

int32_t write_index

Next index to write to

uint8_t enable_overwrite

Overwrite the message if it is enable when the queue is full