Import Mbed OS hard-float snapshot
This commit is contained in:
98
connectivity/nfc/libraries/acore/source/ac_buffer.c
Normal file
98
connectivity/nfc/libraries/acore/source/ac_buffer.c
Normal file
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright (c) 2017, ARM Limited, All Rights Reserved
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* \file buffer.c
|
||||
* \copyright Copyright (c) ARM Ltd 2013
|
||||
* \author Donatien Garnier
|
||||
* \desc Module to ease ac_buffers' management
|
||||
*/
|
||||
|
||||
#include "string.h"
|
||||
|
||||
#include "acore/ac_buffer.h"
|
||||
#include "acore/ac_buffer_reader.h"
|
||||
#include "acore/ac_macros.h"
|
||||
|
||||
#include "acore/ac_debug.h"
|
||||
|
||||
void ac_buffer_init(ac_buffer_t *pBuf, const uint8_t *data, size_t size)
|
||||
{
|
||||
pBuf->data = data;
|
||||
pBuf->size = size;
|
||||
|
||||
pBuf->pNext = NULL;
|
||||
}
|
||||
|
||||
void ac_buffer_dup(ac_buffer_t *pBuf, const ac_buffer_t *pBufIn)
|
||||
{
|
||||
if (pBuf != pBufIn) {
|
||||
memcpy(pBuf, pBufIn, sizeof(ac_buffer_t));
|
||||
}
|
||||
}
|
||||
|
||||
void ac_buffer_append(ac_buffer_t *pBuf, ac_buffer_t *pAppBuf)
|
||||
{
|
||||
while (pBuf->pNext != NULL) {
|
||||
pBuf = pBuf->pNext;
|
||||
}
|
||||
pBuf->pNext = pAppBuf;
|
||||
}
|
||||
|
||||
void ac_buffer_split(ac_buffer_t *pStartBuf, ac_buffer_t *pEndBuf, ac_buffer_t *pBuf, size_t length)
|
||||
{
|
||||
ac_buffer_dup(pStartBuf, pBuf);
|
||||
ac_buffer_dup(pEndBuf, pBuf);
|
||||
|
||||
ac_buffer_read_n_skip(pEndBuf, length);
|
||||
|
||||
while (length > ac_buffer_size(pStartBuf)) {
|
||||
length -= pStartBuf->size;
|
||||
pStartBuf = pStartBuf->pNext;
|
||||
}
|
||||
|
||||
pStartBuf->size = length;
|
||||
pStartBuf->pNext = NULL;
|
||||
}
|
||||
|
||||
/** Dump a ac_buffer's content to stdout (useful for debugging)
|
||||
* \param pBuf pointer to ac_buffer_t structure
|
||||
*/
|
||||
void ac_buffer_dump(ac_buffer_t *pBuf)
|
||||
{
|
||||
#if !defined(NDEBUG)
|
||||
ACORE_STDIO_LOCK();
|
||||
while (pBuf != NULL) {
|
||||
size_t r = ac_buffer_size(pBuf);
|
||||
size_t i = 0;
|
||||
size_t j = 0;
|
||||
while (i < r) {
|
||||
for (j = i; j < MIN(i + 16, r); j++) {
|
||||
ACORE_STDIO_PRINT("%02x ", ac_buffer_data(pBuf)[j]);
|
||||
}
|
||||
ACORE_STDIO_PRINT("\r\n");
|
||||
i = j;
|
||||
}
|
||||
pBuf = ac_buffer_next(pBuf);
|
||||
if (pBuf != NULL) {
|
||||
ACORE_STDIO_PRINT("->\r\n");
|
||||
}
|
||||
}
|
||||
ACORE_STDIO_UNLOCK();
|
||||
#else
|
||||
(void)pBuf;
|
||||
#endif
|
||||
}
|
||||
116
connectivity/nfc/libraries/acore/source/ac_buffer_builder.c
Normal file
116
connectivity/nfc/libraries/acore/source/ac_buffer_builder.c
Normal file
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Copyright (c) 2017, ARM Limited, All Rights Reserved
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* \file buffer_builder.c
|
||||
* \copyright Copyright (c) ARM Ltd 2015
|
||||
* \author Donatien Garnier
|
||||
*/
|
||||
|
||||
#include "acore/ac_buffer_builder.h"
|
||||
#include "acore/ac_buffer_reader.h"
|
||||
#include "acore/ac_macros.h"
|
||||
|
||||
#include "string.h"
|
||||
|
||||
#define VOID
|
||||
#define ENSURE_WRITE_LENGTH(pBuilder, n) do{ if( ac_buffer_builder_space(pBuilder) < n ) { return; } }while(0);
|
||||
|
||||
void ac_buffer_builder_init(ac_buffer_builder_t *pBuilder, uint8_t *data, size_t size)
|
||||
{
|
||||
pBuilder->data = data;
|
||||
pBuilder->size = size;
|
||||
ac_buffer_init(&pBuilder->ac_buffer, data, 0);
|
||||
}
|
||||
|
||||
void ac_buffer_builder_from_buffer(ac_buffer_builder_t *pBuilder)
|
||||
{
|
||||
pBuilder->data = (uint8_t *)pBuilder->ac_buffer.data;
|
||||
pBuilder->size = pBuilder->ac_buffer.size;
|
||||
pBuilder->ac_buffer.size = 0;
|
||||
}
|
||||
|
||||
void ac_buffer_builder_reset(ac_buffer_builder_t *pBuilder)
|
||||
{
|
||||
ac_buffer_init(&pBuilder->ac_buffer, pBuilder->data, 0);
|
||||
}
|
||||
|
||||
void ac_buffer_builder_set_full(ac_buffer_builder_t *pBuilder)
|
||||
{
|
||||
ac_buffer_init(&pBuilder->ac_buffer, pBuilder->data, pBuilder->size);
|
||||
}
|
||||
|
||||
void ac_buffer_builder_write_be(ac_buffer_builder_t *pBuilder, const uint8_t *buf, size_t size)
|
||||
{
|
||||
ENSURE_WRITE_LENGTH(pBuilder, size);
|
||||
buf += size;
|
||||
while (size > 0) {
|
||||
buf--;
|
||||
*ac_buffer_builder_write_position(pBuilder) = *buf;
|
||||
pBuilder->ac_buffer.size++;
|
||||
size--;
|
||||
}
|
||||
}
|
||||
|
||||
void ac_buffer_builder_write_le(ac_buffer_builder_t *pBuilder, const uint8_t *buf, size_t size)
|
||||
{
|
||||
ENSURE_WRITE_LENGTH(pBuilder, size);
|
||||
memcpy(ac_buffer_builder_write_position(pBuilder), buf, size);
|
||||
pBuilder->ac_buffer.size += size;
|
||||
}
|
||||
|
||||
void ac_buffer_builder_write_be_at(ac_buffer_builder_t *pBuilder, size_t pos, const uint8_t *buf, size_t size)
|
||||
{
|
||||
size_t currentPos = pBuilder->ac_buffer.size;
|
||||
pBuilder->ac_buffer.size = pos;
|
||||
ac_buffer_builder_write_be(pBuilder, buf, size);
|
||||
pBuilder->ac_buffer.size = currentPos;
|
||||
}
|
||||
|
||||
void ac_buffer_builder_write_le_at(ac_buffer_builder_t *pBuilder, size_t pos, const uint8_t *buf, size_t size)
|
||||
{
|
||||
size_t currentPos = pBuilder->ac_buffer.size;
|
||||
pBuilder->ac_buffer.size = pos;
|
||||
ac_buffer_builder_write_le(pBuilder, buf, size);
|
||||
pBuilder->ac_buffer.size = currentPos;
|
||||
}
|
||||
|
||||
void ac_buffer_builder_write_n_skip(ac_buffer_builder_t *pBuilder, size_t size)
|
||||
{
|
||||
ENSURE_WRITE_LENGTH(pBuilder, size);
|
||||
pBuilder->ac_buffer.size += size;
|
||||
}
|
||||
|
||||
void ac_buffer_builder_copy_n_bytes(ac_buffer_builder_t *pBuilderOut, ac_buffer_t *pBufIn, size_t size)
|
||||
{
|
||||
ENSURE_WRITE_LENGTH(pBuilderOut, size);
|
||||
if (ac_buffer_reader_readable(pBufIn) < size) {
|
||||
return;
|
||||
}
|
||||
while (size > 0) {
|
||||
size_t cpy = ac_buffer_reader_current_buffer_length(pBufIn);
|
||||
cpy = MIN(cpy, size);
|
||||
ac_buffer_builder_write_n_bytes(pBuilderOut, ac_buffer_reader_current_buffer_pointer(pBufIn), cpy);
|
||||
ac_buffer_read_n_skip(pBufIn, cpy);
|
||||
size -= cpy;
|
||||
}
|
||||
}
|
||||
|
||||
void ac_buffer_builder_compact(ac_buffer_builder_t *pBuilder)
|
||||
{
|
||||
memmove(pBuilder->data, ac_buffer_data(&pBuilder->ac_buffer), ac_buffer_size(&pBuilder->ac_buffer));
|
||||
pBuilder->ac_buffer.data = pBuilder->data;
|
||||
}
|
||||
166
connectivity/nfc/libraries/acore/source/ac_buffer_reader.c
Normal file
166
connectivity/nfc/libraries/acore/source/ac_buffer_reader.c
Normal file
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
* Copyright (c) 2017, ARM Limited, All Rights Reserved
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* \file buffer_reader.c
|
||||
* \copyright Copyright (c) ARM Ltd 2015
|
||||
* \author Donatien Garnier
|
||||
*/
|
||||
|
||||
#include "acore/ac_buffer_reader.h"
|
||||
#include "acore/ac_macros.h"
|
||||
|
||||
#include "string.h"
|
||||
|
||||
#define VOID
|
||||
#define ENSURE_READ_LENGTH(pBuf, n) do{ if( ac_buffer_reader_readable(pBuf) < n ) { return; } }while(0);
|
||||
|
||||
static inline void update_buf(ac_buffer_t *pBuf)
|
||||
{
|
||||
while (ac_buffer_size(pBuf) == 0) {
|
||||
if (ac_buffer_next(pBuf) != NULL) {
|
||||
ac_buffer_t *pNext = ac_buffer_next(pBuf);
|
||||
ac_buffer_init(pBuf, ac_buffer_data(pNext), ac_buffer_size(pNext));
|
||||
pBuf->pNext = ac_buffer_next(pNext);
|
||||
} else if (pBuf->data != NULL) {
|
||||
ac_buffer_init(pBuf, NULL, 0);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ac_buffer_read_be(ac_buffer_t *pBuf, uint8_t *buf, size_t size)
|
||||
{
|
||||
ENSURE_READ_LENGTH(pBuf, size);
|
||||
buf += size;
|
||||
while (size > 0) {
|
||||
buf--;
|
||||
*buf = *ac_buffer_data(pBuf);
|
||||
pBuf->data++;
|
||||
pBuf->size--;
|
||||
update_buf(pBuf);
|
||||
size--;
|
||||
}
|
||||
}
|
||||
|
||||
void ac_buffer_read_le(ac_buffer_t *pBuf, uint8_t *buf, size_t size)
|
||||
{
|
||||
ENSURE_READ_LENGTH(pBuf, size);
|
||||
while (size > 0) {
|
||||
size_t cpy = ac_buffer_size(pBuf);
|
||||
cpy = MIN(cpy, size);
|
||||
memcpy(buf, ac_buffer_data(pBuf), cpy);
|
||||
pBuf->data += cpy;
|
||||
pBuf->size -= cpy;
|
||||
update_buf(pBuf);
|
||||
size -= cpy;
|
||||
buf += cpy;
|
||||
}
|
||||
}
|
||||
|
||||
void ac_buffer_read_n_skip(ac_buffer_t *pBuf, size_t size)
|
||||
{
|
||||
ENSURE_READ_LENGTH(pBuf, size);
|
||||
while (size > 0) {
|
||||
size_t cpy = ac_buffer_size(pBuf);
|
||||
cpy = MIN(cpy, size);
|
||||
pBuf->data += cpy;
|
||||
pBuf->size -= cpy;
|
||||
update_buf(pBuf);
|
||||
size -= cpy;
|
||||
}
|
||||
}
|
||||
|
||||
size_t ac_buffer_reader_readable(const ac_buffer_t *pBuf)
|
||||
{
|
||||
size_t r = 0;
|
||||
while (pBuf != NULL) {
|
||||
r += ac_buffer_size(pBuf);
|
||||
pBuf = ac_buffer_next(pBuf);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
const uint8_t *ac_buffer_reader_current_buffer_pointer(ac_buffer_t *pBuf)
|
||||
{
|
||||
update_buf(pBuf);
|
||||
return ac_buffer_data(pBuf);
|
||||
}
|
||||
|
||||
size_t ac_buffer_reader_current_buffer_length(ac_buffer_t *pBuf)
|
||||
{
|
||||
update_buf(pBuf);
|
||||
return ac_buffer_size(pBuf);
|
||||
}
|
||||
|
||||
bool ac_buffer_reader_cmp_bytes(const ac_buffer_t *pBuf, const uint8_t *bytes, size_t length)
|
||||
{
|
||||
ac_buffer_t reader;
|
||||
|
||||
if (length > ac_buffer_reader_readable(pBuf)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ac_buffer_dup(&reader, pBuf);
|
||||
|
||||
while (length > 0) {
|
||||
size_t sz = ac_buffer_reader_current_buffer_length(&reader);
|
||||
if (sz > length) {
|
||||
sz = length;
|
||||
}
|
||||
int c = memcmp(ac_buffer_reader_current_buffer_pointer(&reader), bytes, sz);
|
||||
if (c) {
|
||||
return false;
|
||||
}
|
||||
length -= sz;
|
||||
bytes += sz;
|
||||
ac_buffer_read_n_skip(&reader, sz);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ac_buffer_reader_cmp(const ac_buffer_t *pBuf1, const ac_buffer_t *pBuf2)
|
||||
{
|
||||
ac_buffer_t reader1;
|
||||
ac_buffer_t reader2;
|
||||
|
||||
if (ac_buffer_reader_readable(pBuf1) != ac_buffer_reader_readable(pBuf2)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ac_buffer_dup(&reader1, pBuf1);
|
||||
ac_buffer_dup(&reader2, pBuf2);
|
||||
|
||||
size_t length = ac_buffer_reader_readable(pBuf1);
|
||||
while (length > 0) {
|
||||
size_t sz1 = ac_buffer_reader_current_buffer_length(&reader1);
|
||||
size_t sz2 = ac_buffer_reader_current_buffer_length(&reader2);
|
||||
|
||||
size_t sz = MIN(sz1, sz2);
|
||||
|
||||
int c = memcmp(ac_buffer_reader_current_buffer_pointer(&reader1), ac_buffer_reader_current_buffer_pointer(&reader2), sz);
|
||||
if (c) {
|
||||
return false;
|
||||
}
|
||||
length -= sz;
|
||||
ac_buffer_read_n_skip(&reader1, sz);
|
||||
ac_buffer_read_n_skip(&reader2, sz);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
50
connectivity/nfc/libraries/acore/source/ac_stream.c
Normal file
50
connectivity/nfc/libraries/acore/source/ac_stream.c
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2017, ARM Limited, All Rights Reserved
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* \file stream.c
|
||||
* \copyright Copyright (c) ARM Ltd 2015
|
||||
* \author Donatien Garnier
|
||||
*/
|
||||
|
||||
#include "acore/ac_stream.h"
|
||||
#include "acore/ac_macros.h"
|
||||
|
||||
//Called by supplier
|
||||
void ac_istream_init(ac_istream_t *pac_istream, ac_istream_fn fn, void *pUserParam)
|
||||
{
|
||||
pac_istream->fn = fn;
|
||||
pac_istream->pUserParam = pUserParam;
|
||||
}
|
||||
|
||||
//Called by consumer
|
||||
void ac_istream_pull(ac_istream_t *pac_istream, ac_buffer_t *pDataIn, bool *pClose, size_t maxLength)
|
||||
{
|
||||
pac_istream->fn(pDataIn, pClose, maxLength, pac_istream->pUserParam);
|
||||
}
|
||||
|
||||
//Called by consumer
|
||||
void ac_ostream_init(ac_ostream_t *pac_ostream, ac_ostream_fn fn, void *pUserParam)
|
||||
{
|
||||
pac_ostream->fn = fn;
|
||||
pac_ostream->pUserParam = pUserParam;
|
||||
}
|
||||
|
||||
//Called by supplier
|
||||
void ac_ostream_push(ac_ostream_t *pac_ostream, ac_buffer_t *pDataOut, bool closed)
|
||||
{
|
||||
pac_ostream->fn(pDataOut, closed, pac_ostream->pUserParam);
|
||||
}
|
||||
Reference in New Issue
Block a user