1bc37f7b0SMilanka Ringwald /* 2bc37f7b0SMilanka Ringwald * Copyright (C) 2016 BlueKitchen GmbH 3bc37f7b0SMilanka Ringwald * 4bc37f7b0SMilanka Ringwald * Redistribution and use in source and binary forms, with or without 5bc37f7b0SMilanka Ringwald * modification, are permitted provided that the following conditions 6bc37f7b0SMilanka Ringwald * are met: 7bc37f7b0SMilanka Ringwald * 8bc37f7b0SMilanka Ringwald * 1. Redistributions of source code must retain the above copyright 9bc37f7b0SMilanka Ringwald * notice, this list of conditions and the following disclaimer. 10bc37f7b0SMilanka Ringwald * 2. Redistributions in binary form must reproduce the above copyright 11bc37f7b0SMilanka Ringwald * notice, this list of conditions and the following disclaimer in the 12bc37f7b0SMilanka Ringwald * documentation and/or other materials provided with the distribution. 13bc37f7b0SMilanka Ringwald * 3. Neither the name of the copyright holders nor the names of 14bc37f7b0SMilanka Ringwald * contributors may be used to endorse or promote products derived 15bc37f7b0SMilanka Ringwald * from this software without specific prior written permission. 16bc37f7b0SMilanka Ringwald * 4. Any redistribution, use, or modification is done solely for 17bc37f7b0SMilanka Ringwald * personal benefit and not for any commercial purpose or for 18bc37f7b0SMilanka Ringwald * monetary gain. 19bc37f7b0SMilanka Ringwald * 20bc37f7b0SMilanka Ringwald * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 21bc37f7b0SMilanka Ringwald * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22bc37f7b0SMilanka Ringwald * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23bc37f7b0SMilanka Ringwald * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS 24bc37f7b0SMilanka Ringwald * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25bc37f7b0SMilanka Ringwald * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26bc37f7b0SMilanka Ringwald * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27bc37f7b0SMilanka Ringwald * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28bc37f7b0SMilanka Ringwald * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29bc37f7b0SMilanka Ringwald * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 30bc37f7b0SMilanka Ringwald * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31bc37f7b0SMilanka Ringwald * SUCH DAMAGE. 32bc37f7b0SMilanka Ringwald * 33bc37f7b0SMilanka Ringwald * Please inquire about commercial licensing options at 34bc37f7b0SMilanka Ringwald * [email protected] 35bc37f7b0SMilanka Ringwald * 36bc37f7b0SMilanka Ringwald */ 37bc37f7b0SMilanka Ringwald 38bc37f7b0SMilanka Ringwald /* 39bc37f7b0SMilanka Ringwald * btstack_ring_buffer.h 40bc37f7b0SMilanka Ringwald */ 41bc37f7b0SMilanka Ringwald 42bc37f7b0SMilanka Ringwald #ifndef __BTSTACK_RING_BUFFER_H 43bc37f7b0SMilanka Ringwald #define __BTSTACK_RING_BUFFER_H 44bc37f7b0SMilanka Ringwald 45bc37f7b0SMilanka Ringwald #if defined __cplusplus 46bc37f7b0SMilanka Ringwald extern "C" { 47bc37f7b0SMilanka Ringwald #endif 48bc37f7b0SMilanka Ringwald 49bc37f7b0SMilanka Ringwald typedef struct btstack_ring_buffer { 50bc37f7b0SMilanka Ringwald uint8_t * storage; 51*44e9e401SMilanka Ringwald uint32_t size; 52*44e9e401SMilanka Ringwald uint32_t last_read_index; 53*44e9e401SMilanka Ringwald uint32_t last_written_index; 54bc37f7b0SMilanka Ringwald uint8_t full; 55bc37f7b0SMilanka Ringwald } btstack_ring_buffer_t; 56bc37f7b0SMilanka Ringwald 57bc37f7b0SMilanka Ringwald // init ring buffer 58*44e9e401SMilanka Ringwald void btstack_ring_buffer_init(btstack_ring_buffer_t * ring_buffer, uint8_t * storage, uint32_t storage_size); 59bc37f7b0SMilanka Ringwald 60bc37f7b0SMilanka Ringwald // test if ring buffer is empty 61bc37f7b0SMilanka Ringwald int btstack_ring_buffer_empty(btstack_ring_buffer_t * ring_buffer); 62bc37f7b0SMilanka Ringwald 63bc37f7b0SMilanka Ringwald // number of bytes available for read 64bc37f7b0SMilanka Ringwald int btstack_ring_buffer_bytes_available(btstack_ring_buffer_t * ring_buffer); 65bc37f7b0SMilanka Ringwald 66bc37f7b0SMilanka Ringwald // free space for write given in number of bytes 67bc37f7b0SMilanka Ringwald int btstack_ring_buffer_bytes_free(btstack_ring_buffer_t * ring_buffer); 68bc37f7b0SMilanka Ringwald 69bc37f7b0SMilanka Ringwald // add byte block to ring buffer, 70*44e9e401SMilanka Ringwald int btstack_ring_buffer_write(btstack_ring_buffer_t * ring_buffer, uint8_t * data, uint32_t data_length); 71bc37f7b0SMilanka Ringwald 72bc37f7b0SMilanka Ringwald // fetch data_length bytes from ring buffer 73*44e9e401SMilanka Ringwald void btstack_ring_buffer_read(btstack_ring_buffer_t * ring_buffer, uint8_t * data, uint32_t data_length, uint32_t * number_of_bytes_read); 74bc37f7b0SMilanka Ringwald 75bc37f7b0SMilanka Ringwald 76bc37f7b0SMilanka Ringwald #if defined __cplusplus 77bc37f7b0SMilanka Ringwald } 78bc37f7b0SMilanka Ringwald #endif 79bc37f7b0SMilanka Ringwald 80bc37f7b0SMilanka Ringwald #endif // __BTSTACK_RING_BUFFER_H 81