zephyr/include/microkernel/fifo.h

154 lines
3.9 KiB
C

/*
* Copyright (c) 1997-2014 Wind River Systems, Inc.
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*/
/**
* @file
*
* @brief Microkernel FIFO header file.
*
*/
/**
* @brief Microkernel FIFOs
* @defgroup microkernel_fifo Microkernel FIFOs
* @ingroup microkernel_services
* @{
*/
#ifndef FIFO_H
#define FIFO_H
#include <sections.h>
/* externs */
#ifdef __cplusplus
extern "C" {
#endif
/**
* @cond internal
*/
extern int _task_fifo_ioctl(kfifo_t queue, int op);
/**
* @brief Initializer for microkernel FIFO
*/
#define __K_FIFO_DEFAULT(depth, width, buffer) \
{ \
.Nelms = depth,\
.element_size = width,\
.base = buffer,\
.end_point = (buffer + (depth * width)),\
.enqueue_point = buffer,\
.dequeue_point = buffer,\
.waiters = NULL,\
.num_used = 0,\
.high_watermark = 0,\
.count = 0,\
}
/**
* @endcond
*/
/**
* @brief FIFO enqueue request.
*
* This routine adds an item to the FIFO queue. When the FIFO is full,
* the routine will wait either for space to become available, or until the
* specified time limit is reached.
*
* @param queue FIFO queue.
* @param data Pointer to data to add to queue.
* @param timeout Determines the action to take when the FIFO is full.
* 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 Successfully added item to FIFO.
* @retval RC_TIME Timed out while waiting to add item to FIFO.
* @retval RC_FAIL Failed to immediately add item to FIFO when
* @a timeout = TICKS_NONE.
* @sa TICKS_NONE, TICKS_UNLIMITED
*/
extern int task_fifo_put(kfifo_t queue, void *data, int32_t timeout);
/**
* @brief FIFO dequeue request.
*
* This routine fetches the oldest item from the FIFO queue. When the FIFO is found empty,
* the routine will wait either until an item is added to the FIFO queue or until
* the specified time limit is reached.
*
* @param queue FIFO queue.
* @param data Pointer to storage location of the FIFO entry.
* @param timeout Affects the action to take when the FIFO is empty.
* 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 Successfully fetched item from FIFO.
* @retval RC_TIME Timed out while waiting to fetch item from FIFO.
* @retval RC_FAIL Failed to immediately fetch item from FIFO when
* @a timeout = TICKS_NONE.
* @sa TICKS_NONE, TICKS_UNLIMITED
*/
extern int task_fifo_get(kfifo_t queue, void *data, int32_t timeout);
/**
* @brief Query the number of FIFO entries.
*
* @param q FIFO queue.
*
* @return # of FIFO entries on query.
*/
#define task_fifo_size_get(q) _task_fifo_ioctl(q, 0)
/**
* @brief Purge the FIFO of all its entries.
*
* @return RC_OK on purge.
*/
#define task_fifo_purge(q) _task_fifo_ioctl(q, 1)
/**
* @brief Define a private microkernel FIFO.
*
* This declares and initializes a private FIFO. The new FIFO
* can be passed to the microkernel FIFO functions.
*
* @param name Name of the FIFO.
* @param depth Depth of the FIFO.
* @param width Width of the FIFO.
*/
#define DEFINE_FIFO(name, depth, width) \
static char __noinit __##name_buffer[(depth * width)]; \
struct _k_fifo_struct _k_fifo_obj_##name = \
__K_FIFO_DEFAULT(depth, width, __##name_buffer); \
const kfifo_t name = (kfifo_t)&_k_fifo_obj_##name;
#ifdef __cplusplus
}
#endif
/**
* @}
*/
#endif /* FIFO_H */