Arrow / Mbed OS DAPLink Reset
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers circ_buf.h Source File

circ_buf.h

Go to the documentation of this file.
00001 /**
00002  * @file    circ_buf.h
00003  * @brief   Implementation of a circular buffer
00004  *
00005  * DAPLink Interface Firmware
00006  * Copyright (c) 2016-2016, ARM Limited, All Rights Reserved
00007  * SPDX-License-Identifier: Apache-2.0
00008  *
00009  * Licensed under the Apache License, Version 2.0 (the "License"); you may
00010  * not use this file except in compliance with the License.
00011  * You may obtain a copy of the License at
00012  *
00013  * http://www.apache.org/licenses/LICENSE-2.0
00014  *
00015  * Unless required by applicable law or agreed to in writing, software
00016  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00017  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00018  * See the License for the specific language governing permissions and
00019  * limitations under the License.
00020  */
00021 
00022 #ifndef CIRC_BUF_H
00023 #define CIRC_BUF_H
00024 
00025 #include <stdbool.h>
00026 #include <stdint.h>
00027 
00028 #ifdef __cplusplus
00029 extern "C" {
00030 #endif
00031 
00032 typedef struct {
00033     uint32_t head;
00034     uint32_t tail;
00035     uint32_t size;
00036     uint8_t *buf;
00037 } circ_buf_t;
00038 
00039 // Initialize or reinitialize a circular buffer
00040 void circ_buf_init(circ_buf_t *circ_buf, uint8_t *buffer, uint32_t size);
00041 
00042 // Push a byte into the circular buffer
00043 void circ_buf_push(circ_buf_t *circ_buf, uint8_t data);
00044 
00045 // Return a byte from the circular buffer
00046 uint8_t circ_buf_pop(circ_buf_t *circ_buf);
00047 
00048 // Get the number of bytes in the circular buffer
00049 uint32_t circ_buf_count_used(circ_buf_t *circ_buf);
00050 
00051 // Get the number of free spots left in the circular buffer
00052 uint32_t circ_buf_count_free(circ_buf_t *circ_buf);
00053 
00054 // Attempt to read size bytes from the buffer. Return the number of bytes read
00055 uint32_t circ_buf_read(circ_buf_t *circ_buf, uint8_t *data, uint32_t size);
00056 
00057 // Attempt to write size bytes to the buffer. Return the number of bytes written
00058 uint32_t circ_buf_write(circ_buf_t *circ_buf, const uint8_t *data, uint32_t size);
00059 
00060 #ifdef __cplusplus
00061 }
00062 #endif
00063 
00064 #endif