Skip to content
GeMRTOS
GeMRTOS

The Generic eMbedded Multiprocessor RTOS

  • Home
  • Download Now!
  • GeMRTOS
    • License
    • Download
    • GeMRTOS Documentation
      • Documentation Browser
      • GeMRTOS Manuals
    • GeMRTOS repository
  • Log in
  • Contact us
Search
GeMRTOS
GeMRTOS

The Generic eMbedded Multiprocessor RTOS

  • Download Now!!!
  • GeMRTOS
    • License
    • Download now!
    • GeMRTOS documentation
    • GeMRTOS repository
  • Login
  • Contact us
  • FPGA Laboratory ACCESS
  • Cursos de FPGA (en español)
  • Challenges
GeMRTOS
GeMRTOS

The Generic eMbedded Multiprocessor RTOS

  • Home
  • Download Now!
  • GeMRTOS
    • License
    • Download
    • GeMRTOS Documentation
      • Documentation Browser
      • GeMRTOS Manuals
    • GeMRTOS repository
  • Log in
  • Contact us
Search
GeMRTOS
GeMRTOS

The Generic eMbedded Multiprocessor RTOS

  • Download Now!!!
  • GeMRTOS
    • License
    • Download now!
    • GeMRTOS documentation
    • GeMRTOS repository
  • Login
  • Contact us
  • FPGA Laboratory ACCESS
  • Cursos de FPGA (en español)
  • Challenges

GeMRTOS - Getting started

  • Introduction to GeMRTOS
  • Getting Started with GeMRTOS: Multiprocessor RTOS for Altera FPGA (Nios II & Nios V)
  • API references
  • Platform Designer Flow for GeMRTOS Nios V FPGA Development
  • GeMRTOS RTOS Task Periods: Infinite Loop vs Periodic Tasks
  • Install Quartus Prime and WSL for GeMRTOS Nios V on Windows

GeMRTOS - Features

  • GeMRTOS Mutex and Critical Sections in Multiprocessor RTOS
  • GeMRTOS Signals: Runtime Exception Handling for Nios V RTOS
  • GeMRTOS System Architecture – Multiprocessor Design with Altera Nios V Processors
  • Hybrid Partition Scheduling in GeMRTOS, Multiprocessor RTOS for Altera FPGA
  • GeMRTOS Scheduling Lists: EDF and Fixed Priority RTOS Guide
  • GeMRTOS Tasks: Types, Creation, and Scheduling for Nios V
  • GeMRTOS Trigger Resources: Event Handling Beyond Interrupts
  • GeMRTOS Controller: Complete FPGA RTOS Hardware Guide
  • Data Structures in GeMRTOS: Control Blocks and Linked Lists
  • GeMRTOS Semaphores: Binary and Counting API for Nios V RTOS
  • GeMRTOS Message Queue: Producer-Consumer API for Nios V RTOS

General

  • Using GCC with MinGW for the GeMRTOS Windows Simulation
  • Error (16031): Current Internal Configuration mode does not support memory initialization or ROM. Select Internal Configuration mode with ERAM.
  • newlib Thread Safety in GeMRTOS Nios V Multiprocessor RTOS
  • Set Up Questa-Intel FPGA Edition License for GeMRTOS Nios V
  • Installing Nios II Software Built Tools (SBT) for Eclipse in Quartus Prime starting from version 19.1
  • Fix Quartus Prime 23.1 Fatal Error When Creating ALTPLL IP
  • Fix Missing SDRAM Controller IP in Quartus Prime for GeMRTOS
  • GeMRTOS Nios: Fix 256MB Compile Boundary with -relax-all
  • Questa Simulation Setup for GeMRTOS Nios V: Two Common Fixes
  • Quartus Warning 113015: mem_init.hex Width Mismatch BSP Fix
  • GeMRTOS Secondary Processors Not Booting: nios2-download Fix
  • Fix Quartus Prime System Console: jvm.dll and awt.dll Errors
  • Eclipse does not start after full Quartus Prime instalation
  • Home
  • GeMRTOS KnowledgeBase
  • GeMRTOS Message Queue: Producer-Consumer API for Nios V RTOS

GeMRTOS Message Queue: Producer-Consumer API for Nios V RTOS

GeMRTOS message queue is an inter-task communication resource that lets independent tasks exchange data asynchronously in a GeMRTOS multiprocessor RTOS running on Altera FPGA platforms with Nios V processors. Using a producer-consumer pattern, one or more producer tasks send messages to the queue while subscribed consumer tasks receive them. This page covers the complete message queue API: how to create a queue, subscribe consumers, send formatted or raw messages, and receive data — along with the T_QUEUE_RESOURCE structure reference.

How GeMRTOS Message Queues Work #

The message queue is a resource that enables independent tasks to exchange information. A producer task sends messages to the message queue; each message remains associated with the queue until either (1) all subscribed consumer tasks have read (consumed) it, or (2) a timeout expires. The producer task remains suspended until all consumers have received the message or the timeout fires. Consumer tasks that have already received all pending messages remain suspended waiting for the next one.

GeMRTOS message queue producer-consumer diagram showing message flow between tasks

Message Queue API Reference #

Creating a Message Queue #

Create a new message queue resource with:

GS_RCB *gu_MessageQueueCreate(void);

The gu_MessageQueueCreate function allocates and initializes a new message queue resource built on the GS_RCB structure, with T_QUEUE_RESOURCE fields appended. The function can be called from main code or from a task, but must be called before any subscribe, send, or receive operation on that queue.

Returns: pointer to the new message queue resource (GS_RCB), or NULL if no queue resource is available.

Subscribing a Consumer Task #

A consumer task must subscribe to a message queue before it can receive messages — and, unlike a generic subscribe call, this is also where its receive buffer is registered:

GS_ECB *gu_MessageQueueSubscribe(GS_TCB *ptcb, GS_RCB *presource,
                                  void *buffer_msg, G_UINT32 buffer_length);

The gu_MessageQueueSubscribe function registers the specified task as a consumer of the given message queue resource, binding the buffer it will receive messages into for the lifetime of the subscription. A task must be subscribed before calling gu_MessageQueueReceive. The queue must have been previously created with gu_MessageQueueCreate.

ParameterDescription
ptcbPointer to the task control block (TCB) to subscribe.
presourcePointer to the message queue resource to subscribe to.
buffer_msgPointer to the memory buffer where received messages will be stored for this subscription.
buffer_lengthMaximum number of bytes the buffer can hold.

Returns: pointer to the GS_ECB event associated with this subscription, or NULL on error.

Sending Formatted Messages #

A producer task sends a printf-style formatted message with:

G_UINT32 gu_MessageQueuePrintf(GS_RCB *prcb, const char *format, ...);

The gu_MessageQueuePrintf function sends a formatted message to the specified queue. The calling task remains suspended until the message has been delivered to all subscribed consumers. The format string follows standard printf conventions, supporting embedded format tags replaced by subsequent arguments.

ParameterDescription
prcbPointer to the message queue resource (returned by gu_MessageQueueCreate).
formatPrintf-style format string with embedded format tags.

Returns: G_TRUE always — this call reports a fixed success flag, not a delivery count (see gu_MessageQueueSend below for a call that reports how many subscribers actually received the message, including partial-delivery/timeout cases).

Sending Raw Messages #

A producer task sends a raw byte message, with an explicit timeout, using:

int gu_MessageQueueSend(GS_RCB *prcb, const char *pmsg, int msg_length,
                         G_UINT64 timeout);

The gu_MessageQueueSend function sends a message buffer to the queue. The calling task remains suspended until the message has been delivered to all subscribed consumers or the timeout expires.

ParameterDescription
prcbPointer to the message queue resource (returned by gu_MessageQueueCreate).
pmsgPointer to the message buffer to send.
msg_lengthLength of the message in bytes.
timeoutMaximum time to wait for all consumers to receive the message, in system ticks. Pass 0 to attempt delivery without waiting.

Returns: the number of subscribers the message was delivered to, as a positive value if delivery to all subscribers completed; a negative value (the negated partial-delivery count) if the timeout expired before every subscriber received it. This is not a G_TRUE/G_FALSE success flag — check the sign and magnitude to know exactly how many receivers were reached.

Receiving Messages #

A subscribed consumer task receives the next pending message with:

int gu_MessageQueueReceive(GS_RCB *prcb);

The gu_MessageQueueReceive function copies the next message from the queue into the buffer registered earlier at gu_MessageQueueSubscribe time — it does not take a buffer argument of its own. The task must have been previously subscribed. If the received message is larger than the buffer length given at subscribe time, it is silently truncated to fit.

ParameterDescription
prcbPointer to the message queue resource already subscribed to.

Returns: the number of bytes actually received (may be less than the message length if the subscription’s buffer was too small); ERR_RECEIVE_ABORT (0xFFFFFFFF) if the receive was aborted. This is a byte count, not a G_TRUE/G_FALSE boolean — a return value of 0 means an empty message was delivered, not a failure.

Destroying a Message Queue #

G_UINT32 gu_MessageQueueDestroy(GS_RCB *pqueue);

gu_MessageQueueDestroy returns a message queue’s GS_RCB to the free pool. It fails (returns G_FALSE) if the queue still has subscribers or pending sender/receiver events — a queue must be idle before it can be destroyed.

T_QUEUE_RESOURCE Structure #

The T_QUEUE_RESOURCE structure is embedded as the queue field within a GS_RCB resource. Access its fields using: (GS_RCB *)->queue.<field>

TypeFieldDescription
G_UINT32MQ_subscribersNumber of receive subscribers currently registered on this queue.
G_UINT32MQ_seq_sendSequence number for the next ECB to send.

Key Takeaways #

  • The GeMRTOS message queue implements an asynchronous producer-consumer IPC pattern for Nios V FPGA RTOS, suspending the producer until all subscribers have consumed the message or a timeout fires.
  • Consumer tasks must call gu_MessageQueueSubscribe before receiving messages — this same call also binds the receive buffer for the subscription’s whole lifetime.
  • gu_MessageQueueReceive takes no buffer argument — it always writes into the buffer given at subscribe time, and truncates messages that exceed that buffer’s length.
  • Use gu_MessageQueuePrintf for human-readable formatted messages (always blocks until every subscriber has it, returns a fixed success flag) and gu_MessageQueueSend for raw binary data with an explicit timeout (returns a real delivered-subscriber count, positive on full delivery, negative on partial/timeout).
  • The message queue resource is built on GeMRTOS’s GS_RCB and linked-list infrastructure; T_QUEUE_RESOURCE fields (MQ_subscribers, MQ_seq_send) are accessed via (GS_RCB *)->queue.<field>.
Share This Article :
  • Facebook
  • Twitter
  • LinkedIn
  • Pinterest
Still stuck? How can we help?

How can we help?

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Table of Contents
  • How GeMRTOS Message Queues Work
  • Message Queue API Reference
    • Creating a Message Queue
    • Subscribing a Consumer Task
    • Sending Formatted Messages
    • Sending Raw Messages
    • Receiving Messages
    • Destroying a Message Queue
  • T_QUEUE_RESOURCE Structure
  • Key Takeaways

Copyright © 2026 - contact us - Dorrego 287 - B8000FLE - Bahía Blanca - Argentina - +542914311867  GeMRTOS

Nios II, Nios V, Quartus Prime, ModelsSim are property of their respective companies.
GeMRTOS is property of R. Cayssials.
**All contact forms on this site are protected by reCAPTCHA. Google Privacy

GeMRTOS joins Intel Partner Alliance as Gold member.