2015-04-11 07:44:37 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1997-2014 Wind River Systems, Inc.
|
|
|
|
*
|
2015-10-07 00:00:37 +08:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2015-04-11 07:44:37 +08:00
|
|
|
*
|
2015-10-07 00:00:37 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2015-04-11 07:44:37 +08:00
|
|
|
*
|
2015-10-07 00:00:37 +08:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2015-04-11 07:44:37 +08:00
|
|
|
*/
|
|
|
|
|
2015-07-09 22:21:14 +08:00
|
|
|
/**
|
|
|
|
* @file mailbox.h
|
|
|
|
* @brief Microkernel mailbox header file
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2015-06-19 21:59:15 +08:00
|
|
|
#ifndef _MAILBOX_H
|
|
|
|
#define _MAILBOX_H
|
2015-04-11 07:44:37 +08:00
|
|
|
|
2015-07-09 22:21:14 +08:00
|
|
|
|
|
|
|
/**
|
2015-08-29 21:40:34 +08:00
|
|
|
* @brief Microkernel Mailboxes
|
|
|
|
* @defgroup microkernel_mailbox Microkernel Mailboxes
|
|
|
|
* @ingroup microkernel_services
|
2015-07-09 22:21:14 +08:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2015-04-11 07:44:37 +08:00
|
|
|
/* externs */
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2015-09-14 07:03:22 +08:00
|
|
|
/**
|
|
|
|
* @cond internal
|
|
|
|
*/
|
2015-08-11 05:37:25 +08:00
|
|
|
extern void _task_mbox_block_put(kmbox_t mbox,
|
2015-10-16 01:54:35 +08:00
|
|
|
kpriority_t prio,
|
|
|
|
struct k_msg *M,
|
|
|
|
ksem_t sem);
|
2015-04-11 07:44:37 +08:00
|
|
|
|
|
|
|
extern void _task_mbox_data_get(struct k_msg *M);
|
|
|
|
|
2015-09-14 07:03:22 +08:00
|
|
|
/**
|
|
|
|
* @brief Initializer for microkernel mailbox
|
|
|
|
*/
|
|
|
|
#define __K_MAILBOX_DEFAULT \
|
|
|
|
{ \
|
|
|
|
.writers = NULL, \
|
|
|
|
.readers = NULL, \
|
|
|
|
.count = 0, \
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @endcond
|
|
|
|
*/
|
2015-04-11 07:44:37 +08:00
|
|
|
|
2015-07-09 22:21:14 +08:00
|
|
|
/**
|
2016-02-11 00:40:11 +08:00
|
|
|
* @brief Send a message to a mailbox.
|
2015-07-09 22:21:14 +08:00
|
|
|
*
|
|
|
|
* This routine sends a message to a mailbox and looks for a matching receiver.
|
|
|
|
*
|
2015-12-03 22:56:31 +08:00
|
|
|
* @param mbox Mailbox.
|
|
|
|
* @param prio Priority of data transfer.
|
|
|
|
* @param M Pointer to message to send.
|
2016-02-11 00:40:11 +08:00
|
|
|
* @param timeout Determines the action to take when there is no waiting receiver.
|
|
|
|
* For TICKS_NONE, return immediately.
|
|
|
|
* For TICKS_UNLIMITED, wait as long as necessary.
|
|
|
|
* Otherwise, wait up to the specified number of ticks before timing out.
|
2015-07-09 22:21:14 +08:00
|
|
|
*
|
2016-02-11 00:40:11 +08:00
|
|
|
* @return RC_OK Successfully delivered message.
|
|
|
|
* @return RC_TIME Timed out while waiting to deliver message.
|
2015-12-03 22:56:31 +08:00
|
|
|
* @return RC_FAIL Failed to immediately deliver message when
|
2016-02-11 00:40:11 +08:00
|
|
|
* @a timeout = TICKS_NONE.
|
|
|
|
* @sa TICKS_NONE, TICKS_UNLIMITED
|
|
|
|
*
|
2015-07-09 22:21:14 +08:00
|
|
|
*/
|
2015-12-03 22:56:31 +08:00
|
|
|
extern int task_mbox_put(kmbox_t mbox, kpriority_t prio,
|
|
|
|
struct k_msg *M, int32_t timeout);
|
2015-05-11 22:46:39 +08:00
|
|
|
|
2015-07-09 22:21:14 +08:00
|
|
|
/**
|
2016-02-11 00:40:11 +08:00
|
|
|
* @brief Get @b struct @b k_msg message header structure information from
|
2015-08-29 21:57:22 +08:00
|
|
|
* a mailbox and wait with timeout.
|
2015-08-29 21:40:34 +08:00
|
|
|
*
|
2016-02-11 00:40:11 +08:00
|
|
|
* @param mbox Mailbox.
|
|
|
|
* @param M Pointer to message.
|
|
|
|
* @param timeout Determines the action to take when there is no waiting receiver.
|
|
|
|
* For TICKS_NONE, return immediately.
|
|
|
|
* For TICKS_UNLIMITED, wait as long as necessary.
|
|
|
|
* Otherwise, wait up to the specified number of ticks before timing out.
|
|
|
|
*
|
|
|
|
* @return RC_OK Successfully received message.
|
|
|
|
* @return RC_TIME Timed out while waiting to receive message.
|
2015-12-04 00:38:31 +08:00
|
|
|
* @return RC_FAIL Failed to immediately receive message when
|
2016-02-11 00:40:11 +08:00
|
|
|
* @a timeout = TICKS_NONE.
|
|
|
|
* @sa TICKS_NONE, TICKS_UNLIMITED
|
2015-07-09 22:21:14 +08:00
|
|
|
*/
|
2015-12-04 00:38:31 +08:00
|
|
|
extern int task_mbox_get(kmbox_t mbox, struct k_msg *M, int32_t timeout);
|
2015-05-11 22:46:39 +08:00
|
|
|
|
2015-07-09 22:21:14 +08:00
|
|
|
/**
|
2016-02-11 00:40:11 +08:00
|
|
|
* @brief Send a message asynchronously to a mailbox.
|
2015-07-09 22:21:14 +08:00
|
|
|
*
|
|
|
|
* This routine sends a message to a mailbox and does not wait for a matching
|
2016-02-11 00:40:11 +08:00
|
|
|
* receiver. No exchange header is returned to the sender. When the data
|
2015-07-09 22:21:14 +08:00
|
|
|
* has been transferred to the receiver, the semaphore signaling is performed.
|
|
|
|
*
|
2016-02-11 00:40:11 +08:00
|
|
|
* @param b Mailbox to which to send message.
|
|
|
|
* @param p Priority of data transfer.
|
|
|
|
* @param m Pointer to message to send.
|
|
|
|
* @param s Semaphore to signal when transfer is complete.
|
2015-07-09 22:21:14 +08:00
|
|
|
*
|
|
|
|
* @return N/A
|
|
|
|
*/
|
2015-08-11 05:37:25 +08:00
|
|
|
#define task_mbox_block_put(b, p, m, s) _task_mbox_block_put(b, p, m, s)
|
2015-07-09 22:21:14 +08:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2016-02-11 00:40:11 +08:00
|
|
|
* @brief Get message data.
|
2015-07-09 22:21:14 +08:00
|
|
|
*
|
2016-02-11 00:40:11 +08:00
|
|
|
* Call this routine for one of two reasons:
|
|
|
|
* 1. To transfer data when the call to @a task_mbox_get() yields an existing
|
|
|
|
* field in the @b struct @b k_msg header structure.
|
|
|
|
* 2. To wake up and release a transmitting task currently blocked from calling
|
|
|
|
* @b task_mbox_put[wait|wait_timeout]().
|
2015-08-29 21:40:34 +08:00
|
|
|
*
|
2016-02-11 00:40:11 +08:00
|
|
|
* @param m Message from which to get data.
|
2015-07-09 22:21:14 +08:00
|
|
|
*
|
|
|
|
* @return N/A
|
|
|
|
*/
|
2015-04-11 07:44:37 +08:00
|
|
|
#define task_mbox_data_get(m) _task_mbox_data_get(m)
|
2015-07-09 22:21:14 +08:00
|
|
|
|
|
|
|
/**
|
2016-02-11 00:40:11 +08:00
|
|
|
* @brief Retrieve message data into a block, with time-limited waiting.
|
|
|
|
*
|
|
|
|
* @param M Message from which to get data.
|
|
|
|
* @param block Block.
|
|
|
|
* @param pool_id Memory pool name.
|
|
|
|
* @param timeout Determines the action to take when no waiting sender exists.
|
|
|
|
* For TICKS_NONE, return immediately.
|
|
|
|
* For TICKS_UNLIMITED, wait as long as necessary.
|
|
|
|
* Otherwise, wait up to the specified number of ticks before timing out.
|
|
|
|
*
|
|
|
|
* @retval RC_OK Successful retrieval of message data.
|
|
|
|
* @retval RC_TIME Timed out while waiting to receive message data.
|
2015-12-05 00:02:13 +08:00
|
|
|
* @retval RC_FAIL Failed to immediately receive message data when
|
2016-02-11 00:40:11 +08:00
|
|
|
* @a timeout = TICKS_NONE.
|
|
|
|
* @sa TICKS_NONE, TICKS_UNLIMITED
|
2015-07-09 22:21:14 +08:00
|
|
|
*/
|
2015-12-05 00:02:13 +08:00
|
|
|
extern int task_mbox_data_block_get(struct k_msg *M, struct k_block *block,
|
|
|
|
kmemory_pool_t pool_id, int32_t timeout);
|
2015-07-18 04:00:06 +08:00
|
|
|
|
|
|
|
/**
|
2016-02-11 00:40:11 +08:00
|
|
|
* @brief Define a private microkernel mailbox.
|
2015-07-18 04:00:06 +08:00
|
|
|
*
|
2016-02-11 00:40:11 +08:00
|
|
|
* This routine declares and initializes a private mailbox. The new mailbox
|
2015-07-18 04:00:06 +08:00
|
|
|
* can be passed to the microkernel mailbox functions.
|
|
|
|
*
|
|
|
|
* @param name Name of the mailbox
|
|
|
|
*/
|
|
|
|
#define DEFINE_MAILBOX(name) \
|
2015-10-16 01:54:35 +08:00
|
|
|
struct _k_mbox_struct _k_mbox_obj_##name = __K_MAILBOX_DEFAULT; \
|
|
|
|
const kmbox_t name = (kmbox_t)&_k_mbox_obj_##name;
|
2015-07-18 04:00:06 +08:00
|
|
|
|
2015-04-11 07:44:37 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-07-09 22:21:14 +08:00
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
2015-06-19 21:59:15 +08:00
|
|
|
#endif /* _MAILBOX_H */
|