1 /* 2 * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef KFIFO_H 16 #define KFIFO_H 1 17 18 #include "plat_types.h" 19 20 #if defined(__cplusplus) 21 extern "C" { 22 #endif 23 24 struct kfifo { 25 unsigned char *buffer; /* the buffer holding the data */ 26 unsigned int size; /* the size of the allocated buffer */ 27 unsigned int in; /* data is added at offset (in % size) */ 28 unsigned int out; /* data is extracted from off. (out % size) */ 29 }; 30 31 void kfifo_init(struct kfifo *k, unsigned char *buff, unsigned int len); 32 unsigned int kfifo_put(struct kfifo *k, unsigned char *buff, unsigned int len); 33 unsigned int kfifo_get(struct kfifo *k, unsigned char *buff, unsigned int len); 34 unsigned int kfifo_peek(struct kfifo *k, unsigned int len_want, unsigned char **buff1, unsigned char **buff2, unsigned int *len1, unsigned int *len2); 35 unsigned int kfifo_peek_to_buf(struct kfifo *fifo, unsigned char *buff, unsigned int len); 36 unsigned int kfifo_len(struct kfifo *fifo); 37 unsigned int kfifo_available(struct kfifo *fifo); 38 39 #if defined(__cplusplus) 40 } 41 #endif 42 43 #endif /* KFIFO_H */ 44