• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 *
3 * SPDX-License-Identifier: GPL-2.0
4 *
5 * Copyright (C) 2011-2018 ARM or its affiliates
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 *
18 */
19 
20 #include "acamera_loop_buf.h"
21 
acamera_loop_buffer_init(acamera_loop_buf_ptr_t p_buf,uint8_t * p_data_buf,int data_buf_size)22 void acamera_loop_buffer_init( acamera_loop_buf_ptr_t p_buf, uint8_t *p_data_buf, int data_buf_size )
23 {
24     p_buf->head = p_buf->tail = 0;
25     p_buf->p_data_buf = p_data_buf;
26     p_buf->data_buf_size = data_buf_size;
27 }
28 
acamera_loop_buffer_read_u8(acamera_loop_buf_ptr_t p_buf,int pos)29 uint8_t acamera_loop_buffer_read_u8( acamera_loop_buf_ptr_t p_buf, int pos )
30 {
31     pos += p_buf->tail;
32     if ( pos >= p_buf->data_buf_size ) {
33         pos -= p_buf->data_buf_size;
34     }
35     return p_buf->p_data_buf[pos];
36 }
37 
acamera_loop_buffer_write_u8(acamera_loop_buf_ptr_t p_buf,int pos,uint8_t sample)38 int acamera_loop_buffer_write_u8( acamera_loop_buf_ptr_t p_buf, int pos, uint8_t sample )
39 {
40     pos += p_buf->head;
41     if ( pos >= p_buf->data_buf_size ) {
42         pos -= p_buf->data_buf_size;
43     }
44     p_buf->p_data_buf[pos++] = sample;
45     if ( pos >= p_buf->data_buf_size ) {
46         pos -= p_buf->data_buf_size;
47     }
48     return pos;
49 }
50