2 * Support for Intel Camera Imaging ISP subsystem.
3 * Copyright (c) 2015, Intel Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 #ifndef _IA_CSS_CIRCBUF_DESC_H_
16 #define _IA_CSS_CIRCBUF_DESC_H_
18 #include <type_support.h>
19 #include <math_support.h>
20 #include <storage_class.h>
21 #include <platform_support.h>
23 #include "ia_css_circbuf_comm.h"
24 /****************************************************************
28 ****************************************************************/
30 * @brief Test if the circular buffer is empty.
32 * @param cb_desc The pointer to the circular buffer descriptor.
35 * - true when it is empty.
36 * - false when it is not empty.
38 STORAGE_CLASS_INLINE bool ia_css_circbuf_desc_is_empty(
39 ia_css_circbuf_desc_t *cb_desc)
41 OP___assert(cb_desc != NULL);
42 return (cb_desc->end == cb_desc->start);
46 * @brief Test if the circular buffer descriptor is full.
48 * @param cb_desc The pointer to the circular buffer
52 * - true when it is full.
53 * - false when it is not full.
55 STORAGE_CLASS_INLINE bool ia_css_circbuf_desc_is_full(
56 ia_css_circbuf_desc_t *cb_desc)
58 OP___assert(cb_desc != NULL);
59 return (OP_std_modadd(cb_desc->end, 1, cb_desc->size) == cb_desc->start);
63 * @brief Initialize the circular buffer descriptor
65 * @param cb_desc The pointer circular buffer descriptor
66 * @param size The size of the circular buffer
68 STORAGE_CLASS_INLINE void ia_css_circbuf_desc_init(
69 ia_css_circbuf_desc_t *cb_desc,
72 OP___assert(cb_desc != NULL);
77 * @brief Get a position in the circular buffer descriptor.
79 * @param cb The pointer to the circular buffer descriptor.
80 * @param base The base position.
81 * @param offset The offset.
83 * @return the position in the circular buffer descriptor.
85 STORAGE_CLASS_INLINE uint8_t ia_css_circbuf_desc_get_pos_at_offset(
86 ia_css_circbuf_desc_t *cb_desc,
91 OP___assert(cb_desc != NULL);
92 OP___assert(cb_desc->size > 0);
94 /* step 1: adjust the offset */
96 offset += cb_desc->size;
99 /* step 2: shift and round by the upper limit */
100 dest = OP_std_modadd(base, offset, cb_desc->size);
106 * @brief Get the offset between two positions in the circular buffer
108 * Get the offset from the source position to the terminal position,
109 * along the direction in which the new elements come in.
111 * @param cb_desc The pointer to the circular buffer descriptor.
112 * @param src_pos The source position.
113 * @param dest_pos The terminal position.
115 * @return the offset.
117 STORAGE_CLASS_INLINE int ia_css_circbuf_desc_get_offset(
118 ia_css_circbuf_desc_t *cb_desc,
123 OP___assert(cb_desc != NULL);
125 offset = (int)(dest_pos - src_pos);
126 offset += (offset < 0) ? cb_desc->size : 0;
132 * @brief Get the number of available elements.
134 * @param cb_desc The pointer to the circular buffer.
136 * @return The number of available elements.
138 STORAGE_CLASS_INLINE uint32_t ia_css_circbuf_desc_get_num_elems(
139 ia_css_circbuf_desc_t *cb_desc)
142 OP___assert(cb_desc != NULL);
144 num = ia_css_circbuf_desc_get_offset(cb_desc,
148 return (uint32_t)num;
152 * @brief Get the number of free elements.
154 * @param cb_desc The pointer to the circular buffer descriptor.
156 * @return: The number of free elements.
158 STORAGE_CLASS_INLINE uint32_t ia_css_circbuf_desc_get_free_elems(
159 ia_css_circbuf_desc_t *cb_desc)
162 OP___assert(cb_desc != NULL);
164 num = ia_css_circbuf_desc_get_offset(cb_desc,
168 return (cb_desc->size - num);
170 #endif /*_IA_CSS_CIRCBUF_DESC_H_ */