tk_snd_mbx

Send Message to Mailbox

See Also

[C Language Interface]

ER ercd = tk_snd_mbx ( ID mbxid, T_MSG *pk_msg ) ;

[Parameters]

ID       mbxid    Mailbox ID
T_MSG*   pk_msg   Message packet address

[Return Parameters]

ER	ercd	Error code

[Error Codes]

E_OK     Normal completion
E_ID     Invalid ID number (mbxid is invalid or cannot be used)
E_NOEXS  Object does not exist (the mailbox specified in mbxid does not exist)
E_PAR    Parameter error (pk_msg is a value that cannot be used)

[Description]

Sends the message packet having pk_msg as its start address to the mailbox specified in mbxid. The message packet contents are not copied; only the start address (pk_msg) is passed at the time of message receipt.

If tasks are already waiting for messages in the same mailbox, the WAIT state of the task at the head of the queue is released, and the pk_msg passed to tk_snd_mbx is sent to that task, becoming a parameter returned by tk_rcv_mbx. If there are no tasks waiting for messages in the specified mailbox, the sent message goes in the message queue of that mailbox. In neither case does the task issuing tk_snd_mbx enter WAIT state.

pk_msg is the start address of the packet containing the message, including its header. The message header has the following format.


typedef struct t_msg {
	?	?	/* Content is implementation-defined (but fixed length) */
} T_MSG;

typedef struct t_msg_pri {
	T_MSG	msgque;	/* message queue area */
	PRI	msgpri;	/* message priority */
} T_MSG_PRI;

The message header is T_MSG (if TA_MFIFO attribute is specified) or @T_MSG@_PRI (if TA_MPRI). In either case, the message header has a fixed size, which can be obtained by sizeof(T_MSG) or sizeof(@T_MSG@_PRI). The actual message must be put in the area after the header. There is no limit on message size, which may be of variable length.

[Additional Notes]

Messages are sent by tk_snd_mbx regardless of the status of the receiving tasks. In other words, message sending is asynchronous. What waits in the queue is not the task itself, but the sent message. So while there are queues of waiting messages and receiving tasks, the sending task does not go to WAIT state.

[Difference with T-Kernel]

In µT-Kernel, there is no concept of user space and there is only what T-Kernel calls shared space. Only the start address of the message in shared memory is actually sent and received between the mailboxes. So, it must be noted that the message be placed in shared space instead of user space when used in T-Kernel. In µT-Kernel, awareness of this is not required because everything is placed in shared space.

Comments

Click here to Post a Comment