Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
ac_buffer.c
00001 /* 00002 * Copyright (c) 2017, ARM Limited, All Rights Reserved 00003 * SPDX-License-Identifier: Apache-2.0 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); you may 00006 * not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 00013 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 /** 00018 * \file buffer.c 00019 * \copyright Copyright (c) ARM Ltd 2013 00020 * \author Donatien Garnier 00021 * \desc Module to ease ac_buffers' management 00022 */ 00023 00024 #include "string.h" 00025 00026 #include "acore/ac_buffer.h" 00027 #include "acore/ac_buffer_reader.h" 00028 #include "acore/ac_macros.h" 00029 00030 #include "acore/ac_debug.h" 00031 00032 void ac_buffer_init(ac_buffer_t *pBuf, const uint8_t *data, size_t size) 00033 { 00034 pBuf->data = data; 00035 pBuf->size = size; 00036 00037 pBuf->pNext = NULL; 00038 } 00039 00040 void ac_buffer_dup(ac_buffer_t *pBuf, const ac_buffer_t *pBufIn) 00041 { 00042 if (pBuf != pBufIn) { 00043 memcpy(pBuf, pBufIn, sizeof(ac_buffer_t)); 00044 } 00045 } 00046 00047 void ac_buffer_append(ac_buffer_t *pBuf, ac_buffer_t *pAppBuf) 00048 { 00049 while (pBuf->pNext != NULL) { 00050 pBuf = pBuf->pNext; 00051 } 00052 pBuf->pNext = pAppBuf; 00053 } 00054 00055 void ac_buffer_split(ac_buffer_t *pStartBuf, ac_buffer_t *pEndBuf, ac_buffer_t *pBuf, size_t length) 00056 { 00057 ac_buffer_dup(pStartBuf, pBuf); 00058 ac_buffer_dup(pEndBuf, pBuf); 00059 00060 ac_buffer_read_n_skip(pEndBuf, length); 00061 00062 while (length > ac_buffer_size(pStartBuf)) { 00063 length -= pStartBuf->size; 00064 pStartBuf = pStartBuf->pNext; 00065 } 00066 00067 pStartBuf->size = length; 00068 pStartBuf->pNext = NULL; 00069 } 00070 00071 /** Dump a ac_buffer's content to stdout (useful for debugging) 00072 * \param pBuf pointer to ac_buffer_t structure 00073 */ 00074 void ac_buffer_dump(ac_buffer_t *pBuf) 00075 { 00076 #if !defined(NDEBUG) 00077 ACORE_STDIO_LOCK(); 00078 while (pBuf != NULL) { 00079 size_t r = ac_buffer_size(pBuf); 00080 size_t i = 0; 00081 size_t j = 0; 00082 while (i < r) { 00083 for (j = i; j < MIN(i + 16, r); j++) { 00084 ACORE_STDIO_PRINT("%02x ", ac_buffer_data(pBuf)[j]); 00085 } 00086 ACORE_STDIO_PRINT("\r\n"); 00087 i = j; 00088 } 00089 pBuf = ac_buffer_next(pBuf); 00090 if (pBuf != NULL) { 00091 ACORE_STDIO_PRINT("->\r\n"); 00092 } 00093 } 00094 ACORE_STDIO_UNLOCK(); 00095 #else 00096 (void)pBuf; 00097 #endif 00098 }
Generated on Tue Jul 12 2022 13:54:00 by
