aboutsummaryrefslogtreecommitdiff
path: root/thirdparty/nRF5_SDK_15.0.0_a53641a/components/iot/iot_file
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2018-08-23 17:08:59 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2018-08-23 17:12:21 +0200
commit3061ecca3d0fdfb87dabbf5f63c9e06c2a30f53a (patch)
treeab49cc16ed0b853452c5c2ed2d3042416d628986 /thirdparty/nRF5_SDK_15.0.0_a53641a/components/iot/iot_file
downloadiot-sensors-master.tar.gz
iot-sensors-master.tar.bz2
iot-sensors-master.tar.xz
iot-sensors-master.zip
o Initial import.HEADmaster
Diffstat (limited to 'thirdparty/nRF5_SDK_15.0.0_a53641a/components/iot/iot_file')
-rw-r--r--thirdparty/nRF5_SDK_15.0.0_a53641a/components/iot/iot_file/iot_file.c195
-rw-r--r--thirdparty/nRF5_SDK_15.0.0_a53641a/components/iot/iot_file/iot_file.h175
-rw-r--r--thirdparty/nRF5_SDK_15.0.0_a53641a/components/iot/iot_file/iot_file_port.h147
-rw-r--r--thirdparty/nRF5_SDK_15.0.0_a53641a/components/iot/iot_file/static/iot_file_static.c220
-rw-r--r--thirdparty/nRF5_SDK_15.0.0_a53641a/components/iot/iot_file/static/iot_file_static.h86
5 files changed, 823 insertions, 0 deletions
diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/iot/iot_file/iot_file.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/iot/iot_file/iot_file.c
new file mode 100644
index 0000000..285be29
--- /dev/null
+++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/iot/iot_file/iot_file.c
@@ -0,0 +1,195 @@
+/**
+ * Copyright (c) 2015 - 2018, Nordic Semiconductor ASA
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form, except as embedded into a Nordic
+ * Semiconductor ASA integrated circuit in a product or a software update for
+ * such product, must reproduce the above copyright notice, this list of
+ * conditions and the following disclaimer in the documentation and/or other
+ * materials provided with the distribution.
+ *
+ * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * 4. This software, with or without modification, must only be used with a
+ * Nordic Semiconductor ASA integrated circuit.
+ *
+ * 5. Any software provided in binary form under this license must not be reverse
+ * engineered, decompiled, modified and/or disassembled.
+ *
+ * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+#include "sdk_config.h"
+#include "iot_file.h"
+#include "iot_common.h"
+
+/**
+ * @defgroup api_param_check API Parameters check macros.
+ *
+ * @details Macros that verify parameters passed to the module in the APIs. These macros
+ * could be mapped to nothing in final versions of code to save execution and size.
+ * IOT_FILE_DISABLE_API_PARAM_CHECK should be set to 0 to enable these checks.
+ *
+ * @{
+ */
+#if (IOT_FILE_DISABLE_API_PARAM_CHECK == 0)
+
+/**@brief Verify NULL parameters are not passed to API by application. */
+#define NULL_PARAM_CHECK(PARAM) \
+ if ((PARAM) == NULL) \
+ { \
+ return (NRF_ERROR_NULL | IOT_FILE_ERR_BASE); \
+ }
+
+#else // IOT_FILE_DISABLE_API_PARAM_CHECK
+
+#define NULL_PARAM_CHECK(PARAM)
+
+#endif // IOT_FILE_DISABLE_API_PARAM_CHECK
+/** @} */
+
+
+/**
+ * @brief Function to open IoT file. Depending on port, it should allocate required buffer.
+ */
+uint32_t iot_file_fopen(iot_file_t * p_file, uint32_t requested_size)
+{
+ NULL_PARAM_CHECK(p_file);
+
+ if (p_file->open != NULL)
+ {
+ return p_file->open(p_file, requested_size);
+ }
+ else
+ {
+ p_file->buffer_size = requested_size;
+ return NRF_ERROR_API_NOT_IMPLEMENTED;
+ }
+}
+
+
+/**
+ * @brief Function to write data buffer into a file.
+ */
+uint32_t iot_file_fwrite(iot_file_t * p_file, const void * p_data, uint32_t size)
+{
+ NULL_PARAM_CHECK(p_file);
+
+ if (p_file->write != NULL)
+ {
+ return p_file->write(p_file, p_data, size);
+ }
+ else
+ {
+ return NRF_ERROR_API_NOT_IMPLEMENTED;
+ }
+}
+
+
+/**
+ * @brief Function to read data buffer from file.
+ */
+uint32_t iot_file_fread(iot_file_t * p_file, void * p_data, uint32_t size)
+{
+ NULL_PARAM_CHECK(p_file);
+
+ if (p_file->read != NULL)
+ {
+ return p_file->read(p_file, p_data, size);
+ }
+ else
+ {
+ return NRF_ERROR_API_NOT_IMPLEMENTED;
+ }
+}
+
+
+/**
+ * @brief Function to read current cursor position.
+ */
+uint32_t iot_file_ftell(iot_file_t * p_file, uint32_t * p_cursor)
+{
+ NULL_PARAM_CHECK(p_file);
+
+ if (p_file->tell != NULL)
+ {
+ return p_file->tell(p_file, p_cursor);
+ }
+ else
+ {
+ return NRF_ERROR_API_NOT_IMPLEMENTED;
+ }
+}
+
+
+/**
+ * @brief Function to set current cursor position.
+ */
+uint32_t iot_file_fseek(iot_file_t * p_file, uint32_t cursor)
+{
+ NULL_PARAM_CHECK(p_file);
+
+ if (p_file->seek != NULL)
+ {
+ return p_file->seek(p_file, cursor);
+ }
+ else
+ {
+ return NRF_ERROR_API_NOT_IMPLEMENTED;
+ }
+}
+
+
+/**
+ * @brief Function to rewind file cursor.
+ */
+uint32_t iot_file_frewind(iot_file_t * p_file)
+{
+ NULL_PARAM_CHECK(p_file);
+
+ if (p_file->rewind != NULL)
+ {
+ return p_file->rewind(p_file);
+ }
+ else
+ {
+ return NRF_ERROR_API_NOT_IMPLEMENTED;
+ }
+}
+
+
+/**
+ * @brief Function to close IoT file. Depending on port, it should free used buffer.
+ */
+uint32_t iot_file_fclose(iot_file_t * p_file)
+{
+ NULL_PARAM_CHECK(p_file);
+
+ if (p_file->close != NULL)
+ {
+ return p_file->close(p_file);
+ }
+ else
+ {
+ return NRF_ERROR_API_NOT_IMPLEMENTED;
+ }
+}
+
diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/iot/iot_file/iot_file.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/iot/iot_file/iot_file.h
new file mode 100644
index 0000000..c4afa7b
--- /dev/null
+++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/iot/iot_file/iot_file.h
@@ -0,0 +1,175 @@
+/**
+ * Copyright (c) 2015 - 2018, Nordic Semiconductor ASA
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form, except as embedded into a Nordic
+ * Semiconductor ASA integrated circuit in a product or a software update for
+ * such product, must reproduce the above copyright notice, this list of
+ * conditions and the following disclaimer in the documentation and/or other
+ * materials provided with the distribution.
+ *
+ * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * 4. This software, with or without modification, must only be used with a
+ * Nordic Semiconductor ASA integrated circuit.
+ *
+ * 5. Any software provided in binary form under this license must not be reverse
+ * engineered, decompiled, modified and/or disassembled.
+ *
+ * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+/**
+ * @file iot_file.h
+ * @brief IoT File abstraction API.
+ */
+
+#ifndef IOT_FILE_H__
+#define IOT_FILE_H__
+
+#include "iot_common.h"
+#include "iot_file_port.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @ingroup iot_sdk_common
+ * @addtogroup iot_file IoT File
+ * @brief IoT File abstraction definition.
+ * @{
+ * @defgroup iot_file_abstraction IoT file abstraction
+ * @{
+ * @brief Structures and public API definition.
+ */
+
+/**
+ * @enum iot_file_evt_t
+ * @brief List of events returned in callback for file ports with asynchronous operation
+ * like open, read, write and close.
+ */
+typedef enum {
+ IOT_FILE_OPENED, /**< Event indicates that file has been opened.*/
+ IOT_FILE_WRITE_COMPLETE, /**< Event indicates that single write operation has been completed.*/
+ IOT_FILE_READ_COMPLETE, /**< Event indicates that single read operation has been completed.*/
+ IOT_FILE_CLOSED, /**< Event indicates that file has been closed.*/
+ IOT_FILE_ERROR /**< Event indicates that file encountered a problem.*/
+} iot_file_evt_t;
+
+/**
+ * @brief IoT File user callback type definition.
+ *
+ * @param[in] p_file Reference to an IoT file instance.
+ * @param[in] event Event structure describing what has happened.
+ * @param[in] result Result code (should be NRF_SUCCESS for all events except errors).
+ * @param[in] p_data Pointer to memory buffer.
+ * @param[in] size Size of data stored in memory buffer.
+ *
+ * @retval None.
+ */
+typedef void (*iot_file_callback_t) (iot_file_t * p_file, iot_file_evt_t event, uint32_t result, void * p_data, uint32_t size);
+
+/**
+ * @brief Function to open IoT file. Depending on port, it should allocate required buffer.
+ *
+ * @param[in] p_file Pointer to an IoT file instance.
+ * @param[in] requested_size Maximum number of bytes to be read/written.
+ *
+ * @retval NRF_SUCCESS on successful execution of procedure, else an error code indicating reason
+ * for failure.
+ */
+uint32_t iot_file_fopen(iot_file_t * p_file, uint32_t requested_size);
+
+/**
+ * @brief Function to write data buffer into a file.
+ *
+ * @param[in] p_file Pointer to an IoT file instance.
+ * @param[in] p_data Pointer to data block which will be written into the file.
+ * @param[in] size Number of bytes to be written.
+ *
+ * @retval NRF_SUCCESS on successful execution of procedure, else an error code indicating reason
+ * for failure.
+ */
+uint32_t iot_file_fwrite(iot_file_t * p_file, const void * p_data, uint32_t size);
+
+/**
+ * @brief Function to read data buffer from file.
+ *
+ * @param[in] p_file Pointer to an IoT file instance.
+ * @param[in] p_data Pointer to data block to be filled with read data.
+ * @param[in] size Number of bytes to be read.
+ *
+ * @retval NRF_SUCCESS on successful execution of procedure, else an error code indicating reason
+ * for failure.
+ */
+uint32_t iot_file_fread(iot_file_t * p_file, void * p_data, uint32_t size);
+
+/**
+ * @brief Function to read current cursor position.
+ *
+ * @param[in] p_file Pointer to an IoT file instance.
+ * @param[out] p_cursor Current value of a cursor.
+ *
+ * @retval NRF_SUCCESS on successful execution of procedure, else an error code indicating reason
+ * for failure.
+ */
+uint32_t iot_file_ftell(iot_file_t * p_file, uint32_t * p_cursor);
+
+/**
+ * @brief Function to set current cursor position.
+ *
+ * @param[in] p_file Pointer to an IoT file instance.
+ * @param[in] cursor New cursor value.
+ *
+ * @retval NRF_SUCCESS on successful execution of procedure, else an error code indicating reason
+ * for failure.
+ */
+uint32_t iot_file_fseek(iot_file_t * p_file, uint32_t cursor);
+
+/**
+ * @brief Function to rewind file cursor.
+ *
+ * @param[in] p_file Pointer to an IoT file instance.
+ *
+ * @retval NRF_SUCCESS on successful execution of procedure, else an error code indicating reason
+ * for failure.
+ */
+uint32_t iot_file_frewind(iot_file_t * p_file);
+
+/**
+ * @brief Function to close IoT file. Depending on port, it should free used buffer.
+ *
+ * @param[in] p_file Pointer to an IoT file instance.
+ *
+ * @retval NRF_SUCCESS on successful execution of procedure, else an error code indicating reason
+ * for failure.
+ */
+uint32_t iot_file_fclose(iot_file_t * p_file);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // IOT_FILE_H__
+
+/** @} */
+/** @} */
diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/iot/iot_file/iot_file_port.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/iot/iot_file/iot_file_port.h
new file mode 100644
index 0000000..23e53d3
--- /dev/null
+++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/iot/iot_file/iot_file_port.h
@@ -0,0 +1,147 @@
+/**
+ * Copyright (c) 2015 - 2018, Nordic Semiconductor ASA
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form, except as embedded into a Nordic
+ * Semiconductor ASA integrated circuit in a product or a software update for
+ * such product, must reproduce the above copyright notice, this list of
+ * conditions and the following disclaimer in the documentation and/or other
+ * materials provided with the distribution.
+ *
+ * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * 4. This software, with or without modification, must only be used with a
+ * Nordic Semiconductor ASA integrated circuit.
+ *
+ * 5. Any software provided in binary form under this license must not be reverse
+ * engineered, decompiled, modified and/or disassembled.
+ *
+ * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+/**
+ * @file iot_file_port.h
+ * @brief Types and definitions used while writing port.
+ */
+
+#ifndef IOT_FILE_PORT_H__
+#define IOT_FILE_PORT_H__
+
+/**
+ * @defgroup iot_file_port_defs IoT file definition for port libraries.
+ * @{
+ * @ingroup iot_file
+ * @brief Type definitions for port modules.
+ */
+#include <stdint.h>
+#include <string.h>
+#include "nordic_common.h"
+#include "sdk_config.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+//NOTE: Port functions don't need to check if p_file exists, because call can be done only on a correct file instance.
+
+#define IOT_FILE_INVALID_CURSOR 0xFFFFFFFF
+
+/**
+ * @enum iot_file_type_t
+ * @brief Supported file type values.
+ */
+typedef enum
+{
+ IOT_FILE_TYPE_UNKNOWN = 0, /**< File type used for describing not initialized files. */
+ IOT_FILE_TYPE_PSTORAGE_RAW, /**< File type used for accessing flash memory. */
+ IOT_FILE_TYPE_STATIC /**< File type used for representing static buffers. */
+} iot_file_type_t;
+
+/**
+ * @brief iot_file_t structure forward definition.
+ */
+typedef struct iot_file_struct_t iot_file_t;
+
+/**
+ * @brief IoT File fopen() callback type definition.
+ */
+typedef uint32_t (*iot_fopen_t)(iot_file_t * p_file, uint32_t requested_size);
+
+/**
+ * @brief IoT File fwrite() callback type definition.
+ */
+typedef uint32_t (*iot_fwrite_t)(iot_file_t * p_file, const void * p_data, uint32_t size);
+
+/**
+ * @brief IoT File fread() callback type definition.
+ */
+typedef uint32_t (*iot_fread_t)(iot_file_t * p_file, void * p_data, uint32_t size);
+
+/**
+ * @brief IoT File ftell() callback type definition.
+ */
+typedef uint32_t (*iot_ftell_t)(iot_file_t * p_file, uint32_t * p_cursor);
+
+/**
+ * @brief IoT File fseek() callback type definition.
+ */
+typedef uint32_t (*iot_fseek_t)(iot_file_t * p_file, uint32_t cursor);
+
+/**
+ * @brief IoT File frewind() callback type definition.
+ */
+typedef uint32_t (*iot_frewind_t)(iot_file_t * p_file);
+
+/**
+ * @brief IoT File fclose() callback type definition.
+ */
+typedef uint32_t (*iot_fclose_t)(iot_file_t * p_file);
+
+/**
+ * @brief Generic IoT File instance structure.
+ */
+struct iot_file_struct_t
+{
+ const char * p_filename; /**< Public. String constant describing file name. */
+ iot_file_type_t type; /**< Public. Type of file. Each type should be added into iot_file_type_t enum. */
+ uint32_t file_size; /**< Public. Number of valid bytes inside file. */
+
+ uint32_t cursor; /**< Internal. Cursor describing which byte will be read/written. */
+ uint32_t buffer_size; /**< Internal. Size of data buffer. */
+ void * p_buffer; /**< Internal. Pointer to a data buffer set by calling fopen. */
+ void * p_callback; /**< Internal. User callback used in order to notify about finished file operations. */
+ void * p_arg; /**< Internal. User defined argument, used inside the port. */
+ iot_fopen_t open; /**< Internal. Callback for fopen operation assigned by particular port. */
+ iot_fwrite_t write; /**< Internal. Callback for fwrite operation assigned by particular port. */
+ iot_fread_t read; /**< Internal. Callback for fread operation assigned by particular port. */
+ iot_ftell_t tell; /**< Internal. Callback for ftell operation assigned by particular port. */
+ iot_fseek_t seek; /**< Internal. Callback for fseek operation assigned by particular port. */
+ iot_frewind_t rewind; /**< Internal. Callback for frewind operation assigned by particular port. */
+ iot_fclose_t close; /**< Internal. Callback for fclose operation assigned by particular port. */
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // IOT_FILE_PORT_H__
+
+/** @} */
diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/iot/iot_file/static/iot_file_static.c b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/iot/iot_file/static/iot_file_static.c
new file mode 100644
index 0000000..4712992
--- /dev/null
+++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/iot/iot_file/static/iot_file_static.c
@@ -0,0 +1,220 @@
+/**
+ * Copyright (c) 2015 - 2018, Nordic Semiconductor ASA
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form, except as embedded into a Nordic
+ * Semiconductor ASA integrated circuit in a product or a software update for
+ * such product, must reproduce the above copyright notice, this list of
+ * conditions and the following disclaimer in the documentation and/or other
+ * materials provided with the distribution.
+ *
+ * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * 4. This software, with or without modification, must only be used with a
+ * Nordic Semiconductor ASA integrated circuit.
+ *
+ * 5. Any software provided in binary form under this license must not be reverse
+ * engineered, decompiled, modified and/or disassembled.
+ *
+ * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+#include "sdk_config.h"
+#include "iot_file_static.h"
+#include "iot_common.h"
+#include <string.h>
+
+#if IOT_FILE_CONFIG_LOG_ENABLED
+
+#define NRF_LOG_MODULE_NAME iot_file_static
+
+#define NRF_LOG_LEVEL IOT_FILE_CONFIG_LOG_LEVEL
+#define NRF_LOG_INFO_COLOR IOT_FILE_CONFIG_INFO_COLOR
+#define NRF_LOG_DEBUG_COLOR IOT_FILE_CONFIG_DEBUG_COLOR
+
+#include "nrf_log.h"
+NRF_LOG_MODULE_REGISTER();
+
+#define FSTATIC_TRC NRF_LOG_DEBUG /**< Used for getting trace of execution in the module. */
+#define FSTATIC_ERR NRF_LOG_ERROR /**< Used for logging errors in the module. */
+#define FSTATIC_DUMP NRF_LOG_HEXDUMP_DEBUG /**< Used for dumping octet information to get details of bond information etc. */
+
+#else // IOT_FILE_CONFIG_LOG_ENABLED
+
+#define FSTATIC_TRC(...) /**< Disables traces. */
+#define FSTATIC_DUMP(...) /**< Disables dumping of octet streams. */
+#define FSTATIC_ERR(...) /**< Disables error logs. */
+
+#endif // IOT_FILE_CONFIG_LOG_ENABLED
+
+/**
+ * @defgroup api_param_check API Parameters check macros.
+ *
+ * @details Macros that verify parameters passed to the module in the APIs. These macros
+ * could be mapped to nothing in final versions of code to save execution and size.
+ * IOT_FILE_STATIC_DISABLE_API_PARAM_CHECK should be set to 0 to enable these checks.
+ *
+ * @{
+ */
+
+#if (IOT_FILE_DISABLE_API_PARAM_CHECK == 0)
+
+/**@brief Verify NULL parameters are not passed to API by application. */
+#define NULL_PARAM_CHECK(PARAM) \
+ if ((PARAM) == NULL) \
+ { \
+ return (NRF_ERROR_NULL | IOT_FILE_ERR_BASE); \
+ }
+
+#else // IOT_FILE_DISABLE_API_PARAM_CHECK
+
+#define NULL_PARAM_CHECK(PARAM)
+
+#endif // IOT_FILE_DISABLE_API_PARAM_CHECK
+/** @} */
+
+#define CHECK_CURSOR(PARAM) \
+ if ((PARAM) == IOT_FILE_INVALID_CURSOR) \
+ { \
+ return (NRF_ERROR_INVALID_STATE | IOT_FILE_ERR_BASE); \
+ }
+
+/**@brief Static buffer fwrite port function definition. */
+static uint32_t internal_fwrite(iot_file_t * p_file, const void * p_data, uint32_t size)
+{
+ NULL_PARAM_CHECK(p_data);
+ CHECK_CURSOR(p_file->cursor);
+
+ if ((size + p_file->cursor) > p_file->buffer_size)
+ {
+ return (NRF_ERROR_DATA_SIZE | IOT_FILE_ERR_BASE);
+ }
+
+ memcpy(((uint8_t *)p_file->p_buffer + p_file->cursor), p_data, size);
+ p_file->cursor += size;
+
+ if (p_file->cursor > p_file->file_size)
+ {
+ p_file->file_size = p_file->cursor;
+ }
+
+ return NRF_SUCCESS;
+}
+
+
+/**@brief Static buffer fread port function definition. */
+static uint32_t internal_fread(iot_file_t * p_file, void * p_data, uint32_t size)
+{
+ NULL_PARAM_CHECK(p_data);
+ CHECK_CURSOR(p_file->cursor);
+
+ if (size + p_file->cursor > p_file->file_size)
+ {
+ return (NRF_ERROR_DATA_SIZE | IOT_FILE_ERR_BASE);
+ }
+
+ memcpy(p_data, (uint8_t *)p_file->p_buffer + p_file->cursor, size);
+ p_file->cursor += size;
+
+ return NRF_SUCCESS;
+}
+
+
+/**@brief Static ftell port function definition. */
+static uint32_t internal_ftell(iot_file_t * p_file, uint32_t * p_cursor)
+{
+ NULL_PARAM_CHECK(p_cursor);
+ CHECK_CURSOR(p_file->cursor);
+
+ *p_cursor = p_file->cursor;
+
+ return NRF_SUCCESS;
+}
+
+
+/**@brief Static fseek port function definition. */
+static uint32_t internal_fseek(iot_file_t * p_file, uint32_t cursor)
+{
+ CHECK_CURSOR(p_file->cursor);
+
+ if (cursor > p_file->buffer_size)
+ {
+ FSTATIC_ERR("Cursor outside file!");
+ return (NRF_ERROR_INVALID_PARAM | IOT_FILE_ERR_BASE);
+ }
+
+ p_file->cursor = cursor;
+
+ return NRF_SUCCESS;
+}
+
+
+/**@brief Static frewind port function definition. */
+static uint32_t internal_frewind(iot_file_t * p_file)
+{
+ CHECK_CURSOR(p_file->cursor);
+
+ p_file->cursor = 0;
+
+ return NRF_SUCCESS;
+}
+
+
+/**@brief Static fopen port function definition. */
+static uint32_t internal_fopen(iot_file_t * p_file, uint32_t requested_size)
+{
+ p_file->cursor = 0;
+
+ if (requested_size != 0)
+ {
+ p_file->file_size = requested_size;
+ }
+
+ return NRF_SUCCESS;
+}
+
+
+/**@brief Static fclose port function definition. */
+static uint32_t internal_fclose(iot_file_t * p_file)
+{
+ p_file->cursor = IOT_FILE_INVALID_CURSOR;
+
+ return NRF_SUCCESS;
+}
+
+
+/**@brief This function is used to assign correct callbacks and file type to passed IoT File instance. */
+void iot_file_static_assign(iot_file_t * p_file)
+{
+ if (p_file == NULL)
+ {
+ return;
+ }
+
+ p_file->type = IOT_FILE_TYPE_STATIC;
+ p_file->write = internal_fwrite;
+ p_file->read = internal_fread;
+ p_file->tell = internal_ftell;
+ p_file->seek = internal_fseek;
+ p_file->rewind = internal_frewind;
+ p_file->open = internal_fopen;
+ p_file->close = internal_fclose;
+}
diff --git a/thirdparty/nRF5_SDK_15.0.0_a53641a/components/iot/iot_file/static/iot_file_static.h b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/iot/iot_file/static/iot_file_static.h
new file mode 100644
index 0000000..de3ea02
--- /dev/null
+++ b/thirdparty/nRF5_SDK_15.0.0_a53641a/components/iot/iot_file/static/iot_file_static.h
@@ -0,0 +1,86 @@
+/**
+ * Copyright (c) 2015 - 2018, Nordic Semiconductor ASA
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form, except as embedded into a Nordic
+ * Semiconductor ASA integrated circuit in a product or a software update for
+ * such product, must reproduce the above copyright notice, this list of
+ * conditions and the following disclaimer in the documentation and/or other
+ * materials provided with the distribution.
+ *
+ * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * 4. This software, with or without modification, must only be used with a
+ * Nordic Semiconductor ASA integrated circuit.
+ *
+ * 5. Any software provided in binary form under this license must not be reverse
+ * engineered, decompiled, modified and/or disassembled.
+ *
+ * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+/**
+ * @file iot_file_static.h
+ * @brief FILE port for static buffers.
+ */
+
+#ifndef IOT_FILE_STATIC_H__
+#define IOT_FILE_STATIC_H__
+
+#include "iot_file_port.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @defgroup iot_file_static IoT file port for static buffers
+ * @ingroup iot_file
+ * @{
+ * @brief Macro function which simplifies file setup process and file type assigning function.
+ */
+
+/**
+ * @brief This macro function configures passed file as a static buffer file.
+ */
+#define IOT_FILE_STATIC_INIT(p_iot_file, p_file_name, p_mem, size) \
+ do { \
+ (p_iot_file)->p_filename = p_file_name; \
+ (p_iot_file)->cursor = IOT_FILE_INVALID_CURSOR; \
+ (p_iot_file)->p_buffer = p_mem; \
+ (p_iot_file)->buffer_size = size; \
+ (p_iot_file)->file_size = 0; \
+ (p_iot_file)->p_callback = NULL; \
+ iot_file_static_assign(p_iot_file); \
+ } while (0)
+
+/**
+ * @brief This function is used to assign correct callbacks and file type to passed IoT File instance.
+ */
+void iot_file_static_assign(iot_file_t * p_file);
+
+/** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // IOT_FILE_STATIC_H__