diff --git a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF51/TARGET_MCU_NRF51822_UNIFIED/sdk/softdevice/s130/mbed_lib.json b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF51/TARGET_MCU_NRF51822_UNIFIED/sdk/softdevice/s130/mbed_lib.json new file mode 100644 index 00000000000..46a44cf81c8 --- /dev/null +++ b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF51/TARGET_MCU_NRF51822_UNIFIED/sdk/softdevice/s130/mbed_lib.json @@ -0,0 +1,20 @@ +{ + "name": "softdevice", + "config": { + "nrf_enable_logging": { + "help": "When '1' NRF_LOG_* outputs will be sent to stdout.", + "value": "0", + "macro_name": "NRF_LOG_ENABLED" + } + }, + "macros": [ + "SOFTDEVICE_PRESENT=1", + "S130" + ], + "target_overrides": { + "*": { + "target.features_add": ["BLE"], + "target.bootloader_img": "hex/s130_nrf51_2.0.0_softdevice.hex" + } + } +} diff --git a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_11/libraries/util/nrf_log.c b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_11/libraries/util/nrf_log.c index 3c26bf540e2..3c75c011f11 100644 --- a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_11/libraries/util/nrf_log.c +++ b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_11/libraries/util/nrf_log.c @@ -182,9 +182,9 @@ uint32_t log_uart_init() UART_TX_BUF_SIZE, uart_error_cb, #ifdef NRF51 - APP_IRQ_PRIORITY_LOW + APP_IRQ_PRIORITY_LOW, #elif defined(NRF52) - APP_IRQ_PRIORITY_LOWEST + APP_IRQ_PRIORITY_LOWEST, #endif err_code); diff --git a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_11/softdevice/common/softdevice_handler/softdevice_handler.c b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_11/softdevice/common/softdevice_handler/softdevice_handler.c index a884968210f..8d93da6b810 100644 --- a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_11/softdevice/common/softdevice_handler/softdevice_handler.c +++ b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_11/softdevice/common/softdevice_handler/softdevice_handler.c @@ -62,12 +62,7 @@ #include "nrf_ble.h" #endif - -#if defined(NRF_LOG_USES_RTT) && NRF_LOG_USES_RTT == 1 #define SD_HANDLER_LOG(...) NRF_LOG_PRINTF(__VA_ARGS__) -#else -#define SD_HANDLER_LOG(...) -#endif #if defined(NRF_LOG_USES_RTT) && NRF_LOG_USES_RTT == 1 #define SD_HANDLER_LOG_INIT() NRF_LOG_INIT() @@ -410,7 +405,8 @@ uint32_t softdevice_enable_get_default_config(uint8_t central_links_count, } -#if defined(NRF_LOG_USES_RTT) && NRF_LOG_USES_RTT == 1 +#if (defined(NRF_LOG_USES_RTT) && NRF_LOG_USES_RTT == 1) || \ + (defined(NRF_LOG_USES_UART) && NRF_LOG_USES_UART == 1) static inline uint32_t ram_total_size_get(void) { #ifdef NRF51 @@ -453,7 +449,6 @@ uint32_t sd_check_ram_start(uint32_t sd_req_ram_start) #endif//__CC_ARM if (ram_start != sd_req_ram_start) { -#if defined(NRF_LOG_USES_RTT) && NRF_LOG_USES_RTT == 1 uint32_t app_ram_size= ram_end_address_get(); SD_HANDLER_LOG("RAM START ADDR 0x%x should be adjusted to 0x%x\r\n", ram_start, @@ -461,7 +456,6 @@ uint32_t sd_check_ram_start(uint32_t sd_req_ram_start) app_ram_size -= sd_req_ram_start; SD_HANDLER_LOG("RAM SIZE should be adjusted to 0x%x \r\n", app_ram_size); -#endif //NRF_LOG_USES_RTT return NRF_SUCCESS; } #endif//defined(S130) || defined(S132) || defined(S332) @@ -490,22 +484,18 @@ uint32_t softdevice_enable(ble_enable_params_t * p_ble_enable_params) app_ram_base); err_code = sd_ble_enable(p_ble_enable_params, &app_ram_base); -#if defined(NRF_LOG_USES_RTT) && NRF_LOG_USES_RTT == 1 + // MODIFIED the rest of this function to match logging implementation in SDK13 if (app_ram_base != ram_start) { - uint32_t app_ram_size= ram_end_address_get(); - SD_HANDLER_LOG("sd_ble_enable: app_ram_base should be adjusted to 0x%x\r\n", - app_ram_base); - app_ram_size -= app_ram_base; - SD_HANDLER_LOG("ram size should be adjusted to 0x%x \r\n", - app_ram_size); + SD_HANDLER_LOG("sd_ble_enable: RAM start should be adjusted to 0x%x\r\n", + app_ram_base); + SD_HANDLER_LOG("RAM size should be adjusted to 0x%x \r\n", + ram_end_address_get() - app_ram_base); } else if (err_code != NRF_SUCCESS) { SD_HANDLER_LOG("sd_ble_enable: error 0x%x\r\n", err_code); - while(1); } -#endif // NRF_LOG_USES_RTT return err_code; #else return NRF_SUCCESS; diff --git a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/TARGET_SOFTDEVICE_S132_FULL/mbed_lib.json b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/TARGET_SOFTDEVICE_S132_FULL/mbed_lib.json index 158c66c33f3..d3219863dbf 100644 --- a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/TARGET_SOFTDEVICE_S132_FULL/mbed_lib.json +++ b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/TARGET_SOFTDEVICE_S132_FULL/mbed_lib.json @@ -1,5 +1,12 @@ { "name": "softdevice", + "config": { + "nrf_enable_logging": { + "help": "When '1' NRF_LOG_* outputs will be sent to stdout.", + "value": "0", + "macro_name": "NRF_LOG_ENABLED" + } + }, "macros": [ "SOFTDEVICE_PRESENT=1", "S132", @@ -34,7 +41,8 @@ "NRF_SDH_BLE_STACK_OBSERVER_PRIO=0", "NRF_SDH_SOC_STACK_OBSERVER_PRIO=0", "FDS_BACKEND=2", - "SWI_DISABLE1=1" + "SWI_DISABLE1=1", + "NRF_STRERROR_ENABLED=1" ], "target_overrides": { "*": { diff --git a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/TARGET_SOFTDEVICE_S140_FULL/mbed_lib.json b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/TARGET_SOFTDEVICE_S140_FULL/mbed_lib.json index 838a47704b6..deb3e8f8b52 100644 --- a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/TARGET_SOFTDEVICE_S140_FULL/mbed_lib.json +++ b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/TARGET_SOFTDEVICE_S140_FULL/mbed_lib.json @@ -1,5 +1,12 @@ { "name": "softdevice", + "config": { + "nrf_enable_logging": { + "help": "When '1' NRF_LOG_* outputs will be sent to stdout.", + "value": "0", + "macro_name": "NRF_LOG_ENABLED" + } + }, "macros": [ "SOFTDEVICE_PRESENT=1", "S140", @@ -34,7 +41,8 @@ "NRF_SDH_BLE_STACK_OBSERVER_PRIO=0", "NRF_SDH_SOC_STACK_OBSERVER_PRIO=0", "FDS_BACKEND=2", - "SWI_DISABLE1=1" + "SWI_DISABLE1=1", + "NRF_STRERROR_ENABLED=1" ], "target_overrides": { "*": { diff --git a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/libraries/README.md b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/libraries/README.md index 0c6f23f19b4..a47b2657f48 100644 --- a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/libraries/README.md +++ b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/libraries/README.md @@ -6,6 +6,10 @@ components/libraries Only essential folders have been copied over. +`experimental_log/nrf_log.h` has been removed and reimplemented in `TARGET_NRF5x/nrf_log.h` to +provide optional logging via mbed stdout. Only the minimum required headers have been left in +experimental_log folder. + Removed: * block_dev/ * bootloader/ diff --git a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/libraries/experimental_log/nrf_log_backend_rtt.h b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/libraries/experimental_log/nrf_log_backend_rtt.h deleted file mode 100644 index 66eeeb65453..00000000000 --- a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/libraries/experimental_log/nrf_log_backend_rtt.h +++ /dev/null @@ -1,73 +0,0 @@ -/** - * Copyright (c) 2017 - 2017, 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 - * - * @defgroup nrf_log_backend_rtt Log RTT backend - * @{ - * @ingroup nrf_log - * @brief Log RTT backend. - */ - -#ifndef NRF_LOG_BACKEND_RTT_H -#define NRF_LOG_BACKEND_RTT_H - -#include "nrf_log_backend_interface.h" - -extern const nrf_log_backend_api_t nrf_log_backend_rtt_api; - -typedef struct { - nrf_log_backend_t backend; -} nrf_log_backend_rtt_t; - -/** - * @brief RTT backend definition - * - * @param _name Name of the instance. - */ -#define NRF_LOG_BACKEND_RTT_DEF(_name) \ - static nrf_log_backend_rtt_t _name = { \ - .backend = {.p_api = &nrf_log_backend_rtt_api}, \ - } - -void nrf_log_backend_rtt_init(void); -#endif //NRF_LOG_BACKEND_RTT_H - -/** @} */ diff --git a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/libraries/experimental_log/nrf_log_backend_uart.h b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/libraries/experimental_log/nrf_log_backend_uart.h deleted file mode 100644 index 4f9ce12900e..00000000000 --- a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/libraries/experimental_log/nrf_log_backend_uart.h +++ /dev/null @@ -1,68 +0,0 @@ -/** - * Copyright (c) 2016 - 2017, 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 - * - * @defgroup nrf_log_backend_uart Log UART backend - * @{ - * @ingroup nrf_log - * @brief Log UART backend. - */ - -#ifndef NRF_LOG_BACKEND_UART_H -#define NRF_LOG_BACKEND_UART_H - -#include "nrf_log_backend_interface.h" - -extern const nrf_log_backend_api_t nrf_log_backend_uart_api; - -typedef struct { - nrf_log_backend_t backend; -} nrf_log_backend_uart_t; - -#define NRF_LOG_BACKEND_UART_DEF(name) \ - static nrf_log_backend_uart_t name = { \ - .backend = {.p_api = &nrf_log_backend_uart_api}, \ - } - -void nrf_log_backend_uart_init(void); -#endif //NRF_LOG_BACKEND_UART_H - -/** @} */ diff --git a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/libraries/experimental_log/nrf_log_default_backends.h b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/libraries/experimental_log/nrf_log_default_backends.h deleted file mode 100644 index 982f3b1b5e3..00000000000 --- a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/libraries/experimental_log/nrf_log_default_backends.h +++ /dev/null @@ -1,81 +0,0 @@ -/** - * Copyright (c) 2017 - 2017, 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. - * - */ -#ifndef NRF_LOG_DEFAULT_BACKENDS_H__ -#define NRF_LOG_DEFAULT_BACKENDS_H__ - -/**@file - * @addtogroup nrf_log Logger module - * @ingroup app_common - * - * @defgroup nrf_log_default_backends Functions for initializing and adding default backends - * @{ - * @ingroup nrf_log - * @brief The nrf_log default backends. - */ - -#include "sdk_config.h" -#include "sdk_errors.h" -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @def NRF_LOG_DEFAULT_BACKENDS_INIT - * @brief Macro for initializing default backends. - * - * Each backend enabled in configuration is initialized and added as a backend to the logger. - */ -#if NRF_LOG_ENABLED -#define NRF_LOG_DEFAULT_BACKENDS_INIT() nrf_log_default_backends_init() -#else -#define NRF_LOG_DEFAULT_BACKENDS_INIT() -#endif - -void nrf_log_default_backends_init(void); - -#ifdef __cplusplus -} -#endif - -/** @} */ - -#endif // NRF_LOG_DEFAULT_BACKENDS_H__ diff --git a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/libraries/experimental_log/nrf_log_str_formatter.h b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/libraries/experimental_log/nrf_log_str_formatter.h deleted file mode 100644 index 134812d4cc0..00000000000 --- a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/libraries/experimental_log/nrf_log_str_formatter.h +++ /dev/null @@ -1,67 +0,0 @@ -/** - * Copyright (c) 2016 - 2017, 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. - * - */ -#ifndef NRF_LOG_STR_FORMATTER_H -#define NRF_LOG_STR_FORMATTER_H - -#include -#include "nrf_fprintf.h" -#include "nrf_log_ctrl.h" - -typedef struct -{ - uint32_t timestamp; - uint16_t module_id; - nrf_log_severity_t severity; - bool raw; - uint8_t use_colors; -} nrf_log_str_formatter_entry_params_t; - -void nrf_log_std_entry_process(char const * p_str, - uint32_t const * p_args, - uint32_t nargs, - nrf_log_str_formatter_entry_params_t * p_params, - nrf_fprintf_ctx_t * p_ctx); - -void nrf_log_hexdump_entry_process(uint8_t * p_data, - uint32_t data_len, - nrf_log_str_formatter_entry_params_t * p_params, - nrf_fprintf_ctx_t * p_ctx); - -#endif //NRF_LOG_STR_FORMATTER_H diff --git a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/libraries/experimental_log/src/nrf_log_backend_rtt.c b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/libraries/experimental_log/src/nrf_log_backend_rtt.c deleted file mode 100644 index 03c32ca670f..00000000000 --- a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/libraries/experimental_log/src/nrf_log_backend_rtt.c +++ /dev/null @@ -1,101 +0,0 @@ -/** - * Copyright (c) 2016 - 2017, 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_common.h" -#if NRF_MODULE_ENABLED(NRF_LOG) && NRF_MODULE_ENABLED(NRF_LOG_BACKEND_RTT) -#include "nrf_log_backend_rtt.h" -#include "nrf_log_backend_serial.h" -#include "nrf_log_str_formatter.h" -#include "nrf_log_internal.h" -#include -#include - -static uint8_t m_string_buff[NRF_LOG_BACKEND_RTT_TEMP_BUFFER_SIZE]; - -void nrf_log_backend_rtt_init(void) -{ - SEGGER_RTT_Init(); -} - -static void serial_tx(void const * p_context, char const * buffer, size_t len) -{ - if (len) - { - uint32_t idx = 0; - uint32_t processed; - uint32_t watchdog_counter = 10; - do - { - processed = SEGGER_RTT_WriteNoLock(0, &buffer[idx], len); - idx += processed; - len -= processed; - if (processed == 0) - { - // If RTT is not connected then ensure that logger does not block - watchdog_counter--; - if (watchdog_counter == 0) - { - break; - } - } - } while (len); - } -} -static void nrf_log_backend_rtt_put(nrf_log_backend_t const * p_backend, - nrf_log_entry_t * p_msg) -{ - nrf_log_backend_serial_put(p_backend, p_msg, m_string_buff, NRF_LOG_BACKEND_RTT_TEMP_BUFFER_SIZE, serial_tx); -} - -static void nrf_log_backend_rtt_flush(nrf_log_backend_t const * p_backend) -{ - -} - -static void nrf_log_backend_rtt_panic_set(nrf_log_backend_t const * p_backend) -{ - -} - -const nrf_log_backend_api_t nrf_log_backend_rtt_api = { - .put = nrf_log_backend_rtt_put, - .flush = nrf_log_backend_rtt_flush, - .panic_set = nrf_log_backend_rtt_panic_set, -}; -#endif //NRF_MODULE_ENABLED(NRF_LOG) && NRF_MODULE_ENABLED(NRF_LOG_BACKEND_RTT) diff --git a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/libraries/experimental_log/src/nrf_log_backend_serial.c b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/libraries/experimental_log/src/nrf_log_backend_serial.c deleted file mode 100644 index 194b9a7b5b0..00000000000 --- a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/libraries/experimental_log/src/nrf_log_backend_serial.c +++ /dev/null @@ -1,116 +0,0 @@ -/** - * Copyright (c) 2016 - 2017, 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_common.h" -#if NRF_MODULE_ENABLED(NRF_LOG) -#include "nrf_log_backend_serial.h" -#include "nrf_log_str_formatter.h" -#include "nrf_log_internal.h" - -void nrf_log_backend_serial_put(nrf_log_backend_t const * p_backend, - nrf_log_entry_t * p_msg, - uint8_t * p_buffer, - uint32_t length, - nrf_fprintf_fwrite tx_func) -{ - nrf_memobj_get(p_msg); - - nrf_fprintf_ctx_t fprintf_ctx = { - .p_io_buffer = (char *)p_buffer, - .io_buffer_size = length, - .io_buffer_cnt = 0, - .auto_flush = false, - .p_user_ctx = NULL, - .fwrite = tx_func - }; - - nrf_log_str_formatter_entry_params_t params; - - nrf_log_header_t header; - uint32_t memobj_offset = 0; - nrf_memobj_read(p_msg, &header, HEADER_SIZE*sizeof(uint32_t), memobj_offset); - memobj_offset = HEADER_SIZE*sizeof(uint32_t); - - params.timestamp = header.timestamp; - params.module_id = header.module_id; - params.use_colors = NRF_LOG_USES_COLORS; - - /*lint -save -e438*/ - if (header.base.generic.type == HEADER_TYPE_STD) - { - char const * p_log_str = (char const *)((uint32_t)header.base.std.addr); - params.severity = (nrf_log_severity_t)header.base.std.severity; - params.raw = header.base.std.raw; - uint32_t nargs = header.base.std.nargs; - uint32_t args[NRF_LOG_MAX_NUM_OF_ARGS]; - - nrf_memobj_read(p_msg, args, nargs*sizeof(uint32_t), memobj_offset); - memobj_offset += (nargs*sizeof(uint32_t)); - - nrf_log_std_entry_process(p_log_str, - args, - nargs, - ¶ms, - &fprintf_ctx); - - } - else if (header.base.generic.type == HEADER_TYPE_HEXDUMP) - { - uint32_t data_len = header.base.hexdump.len; - params.severity = (nrf_log_severity_t)header.base.hexdump.severity; - params.raw = header.base.hexdump.raw; - uint8_t data_buf[8]; - uint32_t chunk_len; - do - { - chunk_len = sizeof(data_buf) > data_len ? data_len : sizeof(data_buf); - nrf_memobj_read(p_msg, data_buf, chunk_len, memobj_offset); - memobj_offset += chunk_len; - data_len -= chunk_len; - - nrf_log_hexdump_entry_process(data_buf, - chunk_len, - ¶ms, - &fprintf_ctx); - } while (data_len > 0); - } - nrf_memobj_put(p_msg); - /*lint -restore*/ -} -#endif //NRF_LOG_ENABLED diff --git a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/libraries/experimental_log/src/nrf_log_backend_serial.h b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/libraries/experimental_log/src/nrf_log_backend_serial.h deleted file mode 100644 index 583bc72945e..00000000000 --- a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/libraries/experimental_log/src/nrf_log_backend_serial.h +++ /dev/null @@ -1,77 +0,0 @@ -/** - * Copyright (c) 2017 - 2017, 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. - * - */ -#ifndef NRF_LOG_BACKEND_SERIAL_H -#define NRF_LOG_BACKEND_SERIAL_H -/**@file - * @addtogroup nrf_log Logger module - * @ingroup app_common - * - * @defgroup nrf_log_backend_serial Common part of serial backends - * @{ - * @ingroup nrf_log - * @brief The nrf_log serial backend common put function. - */ - - -#include "nrf_log_backend_interface.h" -#include "nrf_fprintf.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief A function for processing logger entry with simple serial interface as output. - * - * - */ -void nrf_log_backend_serial_put(nrf_log_backend_t const * p_backend, - nrf_log_entry_t * p_msg, - uint8_t * p_buffer, - uint32_t length, - nrf_fprintf_fwrite tx_func); - -#endif //NRF_LOG_BACKEND_SERIAL_H - -#ifdef __cplusplus -} -#endif - -/** @} */ diff --git a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/libraries/experimental_log/src/nrf_log_backend_uart.c b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/libraries/experimental_log/src/nrf_log_backend_uart.c deleted file mode 100644 index f81018c0daf..00000000000 --- a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/libraries/experimental_log/src/nrf_log_backend_uart.c +++ /dev/null @@ -1,116 +0,0 @@ -/** - * Copyright (c) 2016 - 2017, 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_common.h" -#if NRF_MODULE_ENABLED(NRF_LOG) && NRF_MODULE_ENABLED(NRF_LOG_BACKEND_UART) -#include "nrf_log_backend_uart.h" -#include "nrf_log_backend_serial.h" -#include "nrf_log_internal.h" -#include "nrf_drv_uart.h" -#include "app_error.h" - -nrf_drv_uart_t m_uart = NRF_DRV_UART_INSTANCE(0); - -static uint8_t m_string_buff[NRF_LOG_BACKEND_UART_TEMP_BUFFER_SIZE]; -static volatile bool m_xfer_done; -static bool m_async_mode; -static void uart_evt_handler(nrf_drv_uart_event_t * p_event, void * p_context) -{ - m_xfer_done = true; -} - -static void uart_init(bool async_mode) -{ - nrf_drv_uart_config_t config = NRF_DRV_UART_DEFAULT_CONFIG; - config.pseltxd = NRF_LOG_BACKEND_UART_TX_PIN; - config.pselrxd = NRF_UART_PSEL_DISCONNECTED; - config.pselcts = NRF_UART_PSEL_DISCONNECTED; - config.pselrts = NRF_UART_PSEL_DISCONNECTED; - config.baudrate = (nrf_uart_baudrate_t)NRF_LOG_BACKEND_UART_BAUDRATE; - ret_code_t err_code = nrf_drv_uart_init(&m_uart, &config, async_mode ? uart_evt_handler : NULL); - APP_ERROR_CHECK(err_code); - - m_async_mode = async_mode; -} - -void nrf_log_backend_uart_init(void) -{ - bool async_mode = NRF_LOG_DEFERRED ? true : false; - uart_init(async_mode); -} - -static void serial_tx(void const * p_context, char const * p_buffer, size_t len) -{ - uint8_t len8 = (uint8_t)(len & 0x000000FF); - m_xfer_done = false; - ret_code_t err_code = nrf_drv_uart_tx(&m_uart, (uint8_t *)p_buffer, len8); - APP_ERROR_CHECK(err_code); - /* wait for completion since buffer is reused*/ - while (m_async_mode && (m_xfer_done == false)) - { - - } - -} - -static void nrf_log_backend_uart_put(nrf_log_backend_t const * p_backend, - nrf_log_entry_t * p_msg) -{ - nrf_log_backend_serial_put(p_backend, p_msg, m_string_buff, - NRF_LOG_BACKEND_UART_TEMP_BUFFER_SIZE, serial_tx); -} - -static void nrf_log_backend_uart_flush(nrf_log_backend_t const * p_backend) -{ - -} - -static void nrf_log_backend_uart_panic_set(nrf_log_backend_t const * p_backend) -{ - nrf_drv_uart_uninit(&m_uart); - - uart_init(false); -} - -const nrf_log_backend_api_t nrf_log_backend_uart_api = { - .put = nrf_log_backend_uart_put, - .flush = nrf_log_backend_uart_flush, - .panic_set = nrf_log_backend_uart_panic_set, -}; -#endif //NRF_MODULE_ENABLED(NRF_LOG) && NRF_MODULE_ENABLED(NRF_LOG_BACKEND_UART) diff --git a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/libraries/experimental_log/src/nrf_log_default_backends.c b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/libraries/experimental_log/src/nrf_log_default_backends.c deleted file mode 100644 index 039bf64590f..00000000000 --- a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/libraries/experimental_log/src/nrf_log_default_backends.c +++ /dev/null @@ -1,76 +0,0 @@ -/** - * Copyright (c) 2017 - 2017, 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_common.h" -#if NRF_MODULE_ENABLED(NRF_LOG) -#include "nrf_log_default_backends.h" -#include "nrf_log_ctrl.h" -#include "nrf_log_internal.h" -#include "nrf_assert.h" - -#if defined(NRF_LOG_BACKEND_RTT_ENABLED) && NRF_LOG_BACKEND_RTT_ENABLED -#include "nrf_log_backend_rtt.h" -NRF_LOG_BACKEND_RTT_DEF(rtt_log_backend); -#endif - -#if defined(NRF_LOG_BACKEND_UART_ENABLED) && NRF_LOG_BACKEND_UART_ENABLED -#include "nrf_log_backend_uart.h" -NRF_LOG_BACKEND_UART_DEF(uart_log_backend); -#endif - -void nrf_log_default_backends_init(void) -{ - int32_t backend_id = -1; - (void)backend_id; -#if defined(NRF_LOG_BACKEND_RTT_ENABLED) && NRF_LOG_BACKEND_RTT_ENABLED - nrf_log_backend_rtt_init(); - backend_id = nrf_log_backend_add(&rtt_log_backend.backend, NRF_LOG_SEVERITY_DEBUG); - ASSERT(backend_id >= 0); - nrf_log_backend_enable(&rtt_log_backend.backend); -#endif - -#if defined(NRF_LOG_BACKEND_UART_ENABLED) && NRF_LOG_BACKEND_UART_ENABLED - nrf_log_backend_uart_init(); - backend_id = nrf_log_backend_add(&uart_log_backend.backend, NRF_LOG_SEVERITY_DEBUG); - ASSERT(backend_id >= 0); - nrf_log_backend_enable(&uart_log_backend.backend); -#endif -} -#endif diff --git a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/libraries/experimental_log/src/nrf_log_frontend.c b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/libraries/experimental_log/src/nrf_log_frontend.c deleted file mode 100644 index 459dc3e0b4d..00000000000 --- a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/libraries/experimental_log/src/nrf_log_frontend.c +++ /dev/null @@ -1,1146 +0,0 @@ -/** - * Copyright (c) 2016 - 2017, 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_common.h" -#if NRF_MODULE_ENABLED(NRF_LOG) -#include "app_util.h" -#include "app_util_platform.h" -#include "nrf_log.h" -#include "nrf_log_internal.h" -#include "nrf_log_ctrl.h" -#include "nrf_section.h" -#include "nrf_memobj.h" -#include "nrf_atomic.h" -#include - -STATIC_ASSERT((NRF_LOG_BUFSIZE % 4) == 0); -STATIC_ASSERT(IS_POWER_OF_TWO(NRF_LOG_BUFSIZE)); - -#define NRF_LOG_BUF_WORDS (NRF_LOG_BUFSIZE/4) - -#if NRF_LOG_BUF_WORDS < 32 -#warning "NRF_LOG_BUFSIZE too small, significant number of logs may be lost." -#endif - -NRF_MEMOBJ_POOL_DEF(mempool, NRF_LOG_MSGPOOL_ELEMENT_SIZE, NRF_LOG_MSGPOOL_ELEMENT_COUNT); - -#define NRF_LOG_BACKENDS_FULL 0xFF -#define NRF_LOG_FILTER_BITS_PER_BACKEND 3 -#define NRF_LOG_MAX_BACKENDS (32/NRF_LOG_FILTER_BITS_PER_BACKEND) -#define NRF_LOG_MAX_HEXDUMP (NRF_LOG_MSGPOOL_ELEMENT_SIZE*NRF_LOG_MSGPOOL_ELEMENT_COUNT/2) - -/** - * brief An internal control block of the logger - * - * @note Circular buffer is using never cleared indexes and a mask. It means - * that logger may break when indexes overflows. However, it is quite unlikely. - * With rate of 1000 log entries with 2 parameters per second such situation - * would happen after 12 days. - */ -typedef struct -{ - uint32_t wr_idx; // Current write index (never reset) - uint32_t rd_idx; // Current read index (never_reset) - uint32_t mask; // Size of buffer (must be power of 2) presented as mask - uint32_t buffer[NRF_LOG_BUF_WORDS]; - nrf_log_timestamp_func_t timestamp_func; // A pointer to function that returns timestamp - nrf_log_backend_t * p_backend_head; - nrf_atomic_flag_t log_skipping; - nrf_atomic_flag_t log_skipped; - bool autoflush; -} log_data_t; - -static log_data_t m_log_data; -static const char * m_overflow_info = "Overflow"; -/*lint -save -esym(526,log_const_data*) -esym(526,log_dynamic_data*)*/ -NRF_SECTION_DEF(log_dynamic_data, nrf_log_module_dynamic_data_t); -NRF_SECTION_DEF(log_const_data, nrf_log_module_const_data_t); -/*lint -restore*/ -NRF_LOG_MODULE_REGISTER(); -// Helper macros for section variables. -#define NRF_LOG_DYNAMIC_SECTION_VARS_GET(i) NRF_SECTION_ITEM_GET(log_dynamic_data, nrf_log_module_dynamic_data_t, (i)) - -#define NRF_LOG_CONST_SECTION_VARS_GET(i) NRF_SECTION_ITEM_GET(log_const_data, nrf_log_module_const_data_t, (i)) -#define NRF_LOG_CONST_SECTION_VARS_COUNT NRF_SECTION_ITEM_COUNT(log_const_data, nrf_log_module_const_data_t) - -#define PUSHED_HEADER_FILL(P_HDR, OFFSET, LENGTH) \ - (P_HDR)->base.pushed.type = HEADER_TYPE_PUSHED; \ - (P_HDR)->base.pushed.offset = OFFSET; \ - (P_HDR)->base.pushed.len = LENGTH - - -ret_code_t nrf_log_init(nrf_log_timestamp_func_t timestamp_func) -{ - if (NRF_LOG_USES_TIMESTAMP && (timestamp_func == NULL)) - { - return NRF_ERROR_INVALID_PARAM; - } - - m_log_data.mask = NRF_LOG_BUF_WORDS - 1; - m_log_data.wr_idx = 0; - m_log_data.rd_idx = 0; - m_log_data.log_skipped = 0; - m_log_data.log_skipping = 0; - m_log_data.autoflush = NRF_LOG_DEFERRED ? false : true; - if (NRF_LOG_USES_TIMESTAMP) - { - m_log_data.timestamp_func = timestamp_func; - } - - ret_code_t err_code = nrf_memobj_pool_init(&mempool); - if (err_code != NRF_SUCCESS) - { - return err_code; - } - - uint32_t modules_cnt = NRF_LOG_CONST_SECTION_VARS_COUNT; - uint32_t i; - if (NRF_LOG_FILTERS_ENABLED) - { - uint32_t j; - //sort modules by name - for (i = 0; i < modules_cnt; i++) - { - uint32_t idx = 0; - - for (j = 0; j < modules_cnt; j++) - { - if (i != j) - { - char const * p_name0 = NRF_LOG_CONST_SECTION_VARS_GET(i)->p_module_name; - char const * p_name1 = NRF_LOG_CONST_SECTION_VARS_GET(j)->p_module_name; - if (strncmp(p_name0, p_name1, 20) > 0) - { - idx++; - } - } - - } - nrf_log_module_dynamic_data_t * p_module_ddata = NRF_LOG_DYNAMIC_SECTION_VARS_GET(i); - p_module_ddata->filter = 0; - p_module_ddata->module_id = i; - p_module_ddata->order_idx = idx; - } - } - else - { - for(i = 0; i < modules_cnt; i++) - { - nrf_log_module_dynamic_data_t * p_module_ddata = NRF_LOG_DYNAMIC_SECTION_VARS_GET(i); - p_module_ddata->module_id = i; - } - } - - return NRF_SUCCESS; -} - -uint32_t nrf_log_module_cnt_get(void) -{ - return NRF_LOG_CONST_SECTION_VARS_COUNT; -} - -static ret_code_t module_idx_get(uint32_t * p_idx, bool ordered_idx) -{ - if (ordered_idx) - { - uint32_t module_cnt = nrf_log_module_cnt_get(); - uint32_t i; - for (i = 0; i < module_cnt; i++) - { - nrf_log_module_dynamic_data_t * p_module_data = NRF_LOG_DYNAMIC_SECTION_VARS_GET(i); - if (p_module_data->order_idx == *p_idx) - { - *p_idx = i; - return NRF_SUCCESS; - } - } - return NRF_ERROR_NOT_FOUND; - } - else - { - return NRF_SUCCESS; - } -} -const char * nrf_log_module_name_get(uint32_t module_id, bool ordered_idx) -{ - if (module_idx_get(&module_id, ordered_idx) == NRF_SUCCESS) - { - nrf_log_module_const_data_t * p_module_data = NRF_LOG_CONST_SECTION_VARS_GET(module_id); - return p_module_data->p_module_name; - } - else - { - return NULL; - } -} - -uint8_t nrf_log_color_id_get(uint32_t module_id, nrf_log_severity_t severity) -{ - nrf_log_module_const_data_t * p_module_data = NRF_LOG_CONST_SECTION_VARS_GET(module_id); - uint8_t color_id; - switch (severity) - { - case NRF_LOG_SEVERITY_ERROR: - color_id = NRF_LOG_ERROR_COLOR; - break; - case NRF_LOG_SEVERITY_WARNING: - color_id = NRF_LOG_WARNING_COLOR; - break; - case NRF_LOG_SEVERITY_INFO: - color_id = p_module_data->info_color_id; - break; - case NRF_LOG_SEVERITY_DEBUG: - color_id = p_module_data->debug_color_id; - break; - default: - color_id = 0; - break; - } - return color_id; -} - -static uint32_t higher_lvl_get(uint32_t lvls) -{ - uint32_t top_lvl = 0; - uint32_t tmp_lvl; - uint32_t i; - - //Find highest level enabled by backends - for (i = 0; i < (32/NRF_LOG_LEVEL_BITS); i+=NRF_LOG_LEVEL_BITS) - { - tmp_lvl = BF_GET(lvls,NRF_LOG_LEVEL_BITS, i); - if (tmp_lvl > top_lvl) - { - top_lvl = tmp_lvl; - } - } - return top_lvl; -} - -void nrf_log_module_filter_set(uint32_t backend_id, uint32_t module_id, nrf_log_severity_t severity) -{ - if (NRF_LOG_FILTERS_ENABLED) - { - nrf_log_module_dynamic_data_t * p_module_filter = NRF_LOG_DYNAMIC_SECTION_VARS_GET(module_id); - p_module_filter->filter_lvls &= ~(NRF_LOG_LEVEL_MASK << (NRF_LOG_LEVEL_BITS * backend_id)); - p_module_filter->filter_lvls |= (severity & NRF_LOG_LEVEL_MASK) << (NRF_LOG_LEVEL_BITS * backend_id); - p_module_filter->filter = higher_lvl_get(p_module_filter->filter_lvls); - } -} - -nrf_log_severity_t nrf_log_module_filter_get(uint32_t backend_id, - uint32_t module_id, - bool ordered_idx, - bool dynamic) -{ - nrf_log_severity_t severity = NRF_LOG_SEVERITY_NONE; - if (NRF_LOG_FILTERS_ENABLED && dynamic) - { - if (module_idx_get(&module_id, ordered_idx) == NRF_SUCCESS) - { - nrf_log_module_dynamic_data_t * p_module_filter = - NRF_LOG_DYNAMIC_SECTION_VARS_GET(module_id); - severity = (nrf_log_severity_t)((p_module_filter->filter_lvls >> (NRF_LOG_LEVEL_BITS * backend_id)) & - NRF_LOG_LEVEL_MASK); - } - } - else if (!dynamic) - { - if (module_idx_get(&module_id, ordered_idx) == NRF_SUCCESS) - { - nrf_log_module_const_data_t * p_module_data = - NRF_LOG_CONST_SECTION_VARS_GET(module_id); - severity = (nrf_log_severity_t)p_module_data->compiled_lvl; - } - } - return severity; -} - -/** - * @brief Skips the oldest, not pushed logs to make space for new logs. - * @details This function moves forward read index to prepare space for new logs. - */ - -static void log_skip(void) -{ - (void)nrf_atomic_flag_set(&m_log_data.log_skipped); - (void)nrf_atomic_flag_set(&m_log_data.log_skipping); - - uint32_t rd_idx = m_log_data.rd_idx; - uint32_t mask = m_log_data.mask; - nrf_log_header_t * p_header = (nrf_log_header_t *)&m_log_data.buffer[rd_idx & mask]; - nrf_log_header_t header; - - // Skip any string that is pushed to the circular buffer. - while (p_header->base.generic.type == HEADER_TYPE_PUSHED) - { - rd_idx += PUSHED_HEADER_SIZE; - rd_idx += (p_header->base.pushed.len + p_header->base.pushed.offset); - p_header = (nrf_log_header_t *)&m_log_data.buffer[rd_idx & mask]; - } - - uint32_t i; - for (i = 0; i < HEADER_SIZE; i++) - { - ((uint32_t*)&header)[i] = m_log_data.buffer[rd_idx++ & mask]; - } - - switch (header.base.generic.type) - { - case HEADER_TYPE_HEXDUMP: - rd_idx += CEIL_DIV(header.base.hexdump.len, sizeof(uint32_t)); - break; - case HEADER_TYPE_STD: - rd_idx += header.base.std.nargs; - break; - default: - ASSERT(false); - break; - } - - uint32_t log_skipping_tmp = nrf_atomic_flag_clear_fetch(&m_log_data.log_skipping); - //update read index only if log_skip was not interrupted by another log skip - if (log_skipping_tmp) - { - m_log_data.rd_idx = rd_idx; - } -} - - -static inline void std_header_set(uint32_t severity_mid, - char const * const p_str, - uint32_t nargs, - uint32_t wr_idx, - uint32_t mask) -{ - - - //Prepare header - in reverse order to ensure that packet type is validated (set to STD as last action) - uint16_t module_id = severity_mid >> NRF_LOG_MODULE_ID_POS; - ASSERT(module_id < nrf_log_module_cnt_get()); - m_log_data.buffer[(wr_idx + 1) & mask] = module_id; - - if (NRF_LOG_USES_TIMESTAMP) - { - m_log_data.buffer[(wr_idx + 2) & mask] = m_log_data.timestamp_func(); - } - - nrf_log_header_t * p_header = (nrf_log_header_t *)&m_log_data.buffer[wr_idx & mask]; - p_header->base.std.raw = (severity_mid & NRF_LOG_RAW) ? 1 : 0; - p_header->base.std.severity = severity_mid & NRF_LOG_LEVEL_MASK; - p_header->base.std.nargs = nargs; - p_header->base.std.addr = ((uint32_t)(p_str) & STD_ADDR_MASK); - p_header->base.std.type = HEADER_TYPE_STD; -} - -/** - * @brief Allocates chunk in a buffer for one entry and injects overflow if - * there is no room for requested entry. - * - * @param content_len Number of 32bit arguments. In case of allocating for hex dump it - * is the size of the buffer in 32bit words (ceiled). - * @param p_wr_idx Pointer to write index. - * - * @return True if successful allocation, false otherwise. - * - */ -static inline bool buf_prealloc(uint32_t content_len, uint32_t * p_wr_idx) -{ - uint32_t req_len = content_len + HEADER_SIZE; - uint32_t ovflw_tag_size = HEADER_SIZE; - bool ret = true; - CRITICAL_REGION_ENTER(); - *p_wr_idx = m_log_data.wr_idx; - uint32_t available_words = (m_log_data.mask + 1) - (m_log_data.wr_idx - m_log_data.rd_idx); - uint32_t required_words = req_len + ovflw_tag_size; // room for current entry and overflow - while (required_words > available_words) - { - if (NRF_LOG_ALLOW_OVERFLOW) - { - log_skip(); - available_words = (m_log_data.mask + 1) - (m_log_data.wr_idx - m_log_data.rd_idx); - } - else - { - if (available_words >= HEADER_SIZE) - { - // Overflow entry is injected - std_header_set(NRF_LOG_LEVEL_WARNING, m_overflow_info, 0, m_log_data.wr_idx, m_log_data.mask); - req_len = HEADER_SIZE; - } - else - { - // No more room for any logs. - req_len = 0; - } - ret = false; - break; - } - - } - /* Mark header as invalid.*/ - nrf_log_generic_header_t * p_header = (nrf_log_generic_header_t *)&m_log_data.buffer[m_log_data.wr_idx & m_log_data.mask]; - p_header->type = HEADER_TYPE_INVALID; - - m_log_data.wr_idx += req_len; - - CRITICAL_REGION_EXIT(); - return ret; -} - - -/** - * @brief Function for preallocating a continuous chunk of memory from circular buffer. - * - * If buffer does not fit starting from current position it will be allocated at - * the beginning of the circular buffer and offset will be returned indicating - * how much memory has been ommited at the end of the buffer. Function is - * using critical section. - * - * @param len32 Length of buffer to allocate. Given in words. - * @param p_offset Offset of the buffer. - * @param p_wr_idx Pointer to write index. - * - * @return A pointer to the allocated buffer. NULL if allocation failed. - */ -static inline uint32_t * cont_buf_prealloc(uint32_t len32, - uint32_t * p_offset, - uint32_t * p_wr_idx) -{ - uint32_t * p_buf = NULL; - - len32 += PUSHED_HEADER_SIZE; // Increment because 32bit header is needed to be stored. - - CRITICAL_REGION_ENTER(); - *p_wr_idx = m_log_data.wr_idx; - uint32_t available_words = (m_log_data.mask + 1) - - (m_log_data.wr_idx - m_log_data.rd_idx); - if (len32 <= available_words) - { - // buffer will fit as is - p_buf = &m_log_data.buffer[(m_log_data.wr_idx + 1) & m_log_data.mask]; - m_log_data.wr_idx += len32; - *p_offset = 0; - } - else if (len32 < (m_log_data.rd_idx & m_log_data.mask)) - { - // wraping to the begining of the buffer - m_log_data.wr_idx += (len32 + available_words - 1); - *p_offset = available_words - 1; - p_buf = m_log_data.buffer; - } - available_words = (m_log_data.mask + 1) - (m_log_data.wr_idx - m_log_data.rd_idx); - // If there is no more room for even overflow tag indicate failed allocation. - if (available_words < HEADER_SIZE) - { - p_buf = NULL; - } - CRITICAL_REGION_EXIT(); - - return p_buf; -} - - -uint32_t nrf_log_push(char * const p_str) -{ - if ((m_log_data.autoflush) || (p_str == NULL)) - { - return (uint32_t)p_str; - } - - uint32_t mask = m_log_data.mask; - uint32_t slen = strlen(p_str) + 1; - uint32_t buflen = CEIL_DIV(slen, sizeof(uint32_t)); - uint32_t offset = 0; - uint32_t wr_idx; - char * p_dst_str = (char *)cont_buf_prealloc(buflen, &offset, &wr_idx); - if (p_dst_str) - { - nrf_log_header_t * p_header = (nrf_log_header_t *)&m_log_data.buffer[wr_idx & mask]; - PUSHED_HEADER_FILL(p_header, offset, buflen); - memcpy(p_dst_str, p_str, slen); - } - return (uint32_t)p_dst_str; -} - -static inline void std_n(uint32_t severity_mid, char const * const p_str, uint32_t const * args, uint32_t nargs) -{ - uint32_t mask = m_log_data.mask; - uint32_t wr_idx; - - if (buf_prealloc(nargs, &wr_idx)) - { - // Proceed only if buffer was successfully preallocated. - - uint32_t data_idx = wr_idx + HEADER_SIZE; - uint32_t i; - for (i = 0; i < nargs; i++) - { - m_log_data.buffer[data_idx++ & mask] =args[i]; - } - std_header_set(severity_mid, p_str, nargs, wr_idx, mask); - } - if (m_log_data.autoflush) - { - NRF_LOG_FLUSH(); - } - -} - -void nrf_log_frontend_std_0(uint32_t severity_mid, char const * const p_str) -{ - std_n(severity_mid, p_str, NULL, 0); -} - - -void nrf_log_frontend_std_1(uint32_t severity_mid, - char const * const p_str, - uint32_t val0) -{ - uint32_t args[] = {val0}; - std_n(severity_mid, p_str, args, ARRAY_SIZE(args)); -} - - -void nrf_log_frontend_std_2(uint32_t severity_mid, - char const * const p_str, - uint32_t val0, - uint32_t val1) -{ - uint32_t args[] = {val0, val1}; - std_n(severity_mid, p_str, args, ARRAY_SIZE(args)); -} - - -void nrf_log_frontend_std_3(uint32_t severity_mid, - char const * const p_str, - uint32_t val0, - uint32_t val1, - uint32_t val2) -{ - uint32_t args[] = {val0, val1, val2}; - std_n(severity_mid, p_str, args, ARRAY_SIZE(args)); -} - - -void nrf_log_frontend_std_4(uint32_t severity_mid, - char const * const p_str, - uint32_t val0, - uint32_t val1, - uint32_t val2, - uint32_t val3) -{ - uint32_t args[] = {val0, val1, val2, val3}; - std_n(severity_mid, p_str, args, ARRAY_SIZE(args)); -} - - -void nrf_log_frontend_std_5(uint32_t severity_mid, - char const * const p_str, - uint32_t val0, - uint32_t val1, - uint32_t val2, - uint32_t val3, - uint32_t val4) -{ - uint32_t args[] = {val0, val1, val2, val3, val4}; - std_n(severity_mid, p_str, args, ARRAY_SIZE(args)); -} - - -void nrf_log_frontend_std_6(uint32_t severity_mid, - char const * const p_str, - uint32_t val0, - uint32_t val1, - uint32_t val2, - uint32_t val3, - uint32_t val4, - uint32_t val5) -{ - uint32_t args[] = {val0, val1, val2, val3, val4, val5}; - std_n(severity_mid, p_str, args, ARRAY_SIZE(args)); -} - - -void nrf_log_frontend_hexdump(uint32_t severity_mid, - const void * const p_data, - uint16_t length) -{ - uint32_t mask = m_log_data.mask; - - uint32_t wr_idx; - if (buf_prealloc(CEIL_DIV(length, sizeof(uint32_t)), &wr_idx)) - { - uint32_t header_wr_idx = wr_idx; - wr_idx += HEADER_SIZE; - - uint32_t space0 = sizeof(uint32_t) * (m_log_data.mask + 1 - (wr_idx & mask)); - if (length <= space0) - { - memcpy(&m_log_data.buffer[wr_idx & mask], p_data, length); - } - else - { - memcpy(&m_log_data.buffer[wr_idx & mask], p_data, space0); - length -= space0; - memcpy(&m_log_data.buffer[0], &((uint8_t *)p_data)[space0], length); - } - - //Prepare header - in reverse order to ensure that packet type is validated (set to HEXDUMP as last action) - if (NRF_LOG_USES_TIMESTAMP) - { - m_log_data.buffer[(header_wr_idx + 2) & mask] = m_log_data.timestamp_func(); - } - - m_log_data.buffer[(header_wr_idx + 1) & mask] = severity_mid >> NRF_LOG_MODULE_ID_POS; - //Header prepare - nrf_log_header_t * p_header = (nrf_log_header_t *)&m_log_data.buffer[header_wr_idx & mask]; - p_header->base.hexdump.raw = (severity_mid & NRF_LOG_RAW) ? 1 : 0; - p_header->base.hexdump.severity = severity_mid & NRF_LOG_LEVEL_MASK; - p_header->base.hexdump.offset = 0; - p_header->base.hexdump.len = length; - p_header->base.hexdump.type = HEADER_TYPE_HEXDUMP; - - - - } - - if (m_log_data.autoflush) - { - NRF_LOG_FLUSH(); - } -} - - -bool buffer_is_empty(void) -{ - return (m_log_data.rd_idx == m_log_data.wr_idx); -} - - -bool nrf_log_frontend_dequeue(void) -{ - if (buffer_is_empty()) - { - return false; - } - m_log_data.log_skipped = 0; - //It has to be ensured that reading rd_idx occurs after skipped flag is cleared. - __DSB(); - uint32_t rd_idx = m_log_data.rd_idx; - uint32_t mask = m_log_data.mask; - nrf_log_header_t * p_header = (nrf_log_header_t *)&m_log_data.buffer[rd_idx & mask]; - nrf_log_header_t header; - nrf_memobj_t * p_msg_buf = NULL; - uint32_t memobj_offset = 0; - uint32_t severity = 0; - - // Skip any string that is pushed to the circular buffer. - while (p_header->base.generic.type == HEADER_TYPE_PUSHED) - { - rd_idx += PUSHED_HEADER_SIZE; - rd_idx += (p_header->base.pushed.len + p_header->base.pushed.offset); - p_header = (nrf_log_header_t *)&m_log_data.buffer[rd_idx & mask]; - } - - uint32_t i; - for (i = 0; i < HEADER_SIZE; i++) - { - ((uint32_t*)&header)[i] = m_log_data.buffer[rd_idx++ & mask]; - } - - if (header.base.generic.type == HEADER_TYPE_HEXDUMP) - { - uint32_t orig_data_len = header.base.hexdump.len; - uint32_t data_len = MIN(header.base.hexdump.len, NRF_LOG_MAX_HEXDUMP); //limit the data - header.base.hexdump.len = data_len; - uint32_t msg_buf_size8 = sizeof(uint32_t)*HEADER_SIZE + data_len; - severity = header.base.hexdump.severity; - p_msg_buf = nrf_memobj_alloc(&mempool, msg_buf_size8); - - if (p_msg_buf) - { - nrf_memobj_get(p_msg_buf); - nrf_memobj_write(p_msg_buf, &header, HEADER_SIZE*sizeof(uint32_t), memobj_offset); - memobj_offset += HEADER_SIZE*sizeof(uint32_t); - - uint32_t space0 = sizeof(uint32_t) * (mask + 1 - (rd_idx & mask)); - if (data_len > space0) - { - uint8_t * ptr0 = space0 ? - (uint8_t *)&m_log_data.buffer[rd_idx & mask] : - (uint8_t *)&m_log_data.buffer[0]; - uint8_t len0 = space0 ? space0 : data_len; - uint8_t * ptr1 = space0 ? - (uint8_t *)&m_log_data.buffer[0] : NULL; - uint8_t len1 = space0 ? data_len - space0 : 0; - - nrf_memobj_write(p_msg_buf, ptr0, len0, memobj_offset); - memobj_offset += len0; - if (ptr1) - { - nrf_memobj_write(p_msg_buf, ptr1, len1, memobj_offset); - } - } - else - { - uint8_t * p_data = (uint8_t *)&m_log_data.buffer[rd_idx & mask]; - nrf_memobj_write(p_msg_buf, p_data, data_len, memobj_offset); - } - rd_idx += CEIL_DIV(orig_data_len, 4); - } - } - else if (header.base.generic.type == HEADER_TYPE_STD) // standard entry - { - header.base.std.nargs = MIN(header.base.std.nargs, NRF_LOG_MAX_NUM_OF_ARGS); - uint32_t msg_buf_size32 = HEADER_SIZE + header.base.std.nargs; - severity = header.base.std.severity; - - p_msg_buf = nrf_memobj_alloc(&mempool, msg_buf_size32*sizeof(uint32_t)); - - if (p_msg_buf) - { - nrf_memobj_get(p_msg_buf); - nrf_memobj_write(p_msg_buf, &header, HEADER_SIZE*sizeof(uint32_t), memobj_offset); - memobj_offset += HEADER_SIZE*sizeof(uint32_t); - - for (i = 0; i < header.base.std.nargs; i++) - { - nrf_memobj_write(p_msg_buf, &m_log_data.buffer[rd_idx++ & mask], - sizeof(uint32_t), memobj_offset); - memobj_offset += sizeof(uint32_t); - } - } - } - else if (header.base.generic.type == HEADER_TYPE_INVALID && (m_log_data.log_skipped == 0)) - { - //invalid type can only occur if log entry was interrupted by log_process. It is likly final flush - // and finding invalid type means that last entry in the buffer was reached (the one that was interrupted). - // Stop processing immediately. - return false; - } - else - { - //Do nothing. In case of log overflow buffer can contain corrupted data. - } - - if (p_msg_buf) - { - nrf_log_backend_t * p_backend = m_log_data.p_backend_head; - if (NRF_LOG_ALLOW_OVERFLOW && m_log_data.log_skipped) - { - // Check if any log was skipped during log processing. Do not forward log if skipping - // occured because data may be invalid. - nrf_memobj_put(p_msg_buf); - } - else - { - while (p_backend) - { - bool entry_accepted = false; - if (nrf_log_backend_is_enabled(p_backend) == true) - { - if (NRF_LOG_FILTERS_ENABLED) - { - uint8_t backend_id = nrf_log_backend_id_get(p_backend); - uint32_t filter_lvls = NRF_LOG_DYNAMIC_SECTION_VARS_GET(header.module_id)->filter_lvls; - uint32_t backend_lvl = (filter_lvls >> (backend_id*NRF_LOG_LEVEL_BITS)) - & NRF_LOG_LEVEL_MASK; - if (backend_lvl >= severity) - { - entry_accepted = true; - } - } - else - { - (void)severity; - entry_accepted = true; - } - } - if (entry_accepted) - { - nrf_log_backend_put(p_backend, p_msg_buf); - } - p_backend = p_backend->p_next; - } - - nrf_memobj_put(p_msg_buf); - - if (NRF_LOG_ALLOW_OVERFLOW) - { - // Read index can be moved forward only if dequeueing process was not interrupt by - // skipping procedure. If NRF_LOG_ALLOW_OVERFLOW is set then in case of buffer gets full - // and new logger entry occurs, oldest entry is removed. In that case read index is - // changed and updating it here would corrupt the internal circular buffer. - CRITICAL_REGION_ENTER(); - if (m_log_data.log_skipped == 0) - { - m_log_data.rd_idx = rd_idx; - } - CRITICAL_REGION_EXIT(); - } - else - { - m_log_data.rd_idx = rd_idx; - } - } - } - - return buffer_is_empty() ? false : true; -} - -static int32_t backend_id_assign(void) -{ - int32_t candidate_id; - nrf_log_backend_t * p_backend; - bool id_available; - for (candidate_id = 0; candidate_id < NRF_LOG_MAX_BACKENDS; candidate_id++) - { - p_backend = m_log_data.p_backend_head; - id_available = true; - while (p_backend) - { - if (nrf_log_backend_id_get(p_backend) == candidate_id) - { - id_available = false; - break; - } - p_backend = p_backend->p_next; - } - if (id_available) - { - return candidate_id; - } - } - return -1; -} - -int32_t nrf_log_backend_add(nrf_log_backend_t * p_backend, nrf_log_severity_t severity) -{ - int32_t id = backend_id_assign(); - if (id == -1) - { - return id; - } - - nrf_log_backend_id_set(p_backend, id); - //add to list - if (m_log_data.p_backend_head == NULL) - { - m_log_data.p_backend_head = p_backend; - p_backend->p_next = NULL; - } - else - { - p_backend->p_next = m_log_data.p_backend_head->p_next; - m_log_data.p_backend_head->p_next = p_backend; - } - - if (NRF_LOG_FILTERS_ENABLED) - { - uint32_t i; - for (i = 0; i < nrf_log_module_cnt_get(); i++) - { - nrf_log_severity_t buildin_lvl = nrf_log_module_filter_get(id, i, false, false); - nrf_log_severity_t actual_severity = MIN(buildin_lvl, severity); - nrf_log_module_filter_set(nrf_log_backend_id_get(p_backend), i, actual_severity); - } - } - - return id; -} - -void nrf_log_backend_remove(nrf_log_backend_t * p_backend) -{ - nrf_log_backend_t * p_curr = m_log_data.p_backend_head; - nrf_log_backend_t * p_prev = NULL; - while (p_curr != p_backend) - { - p_prev = p_curr; - p_curr = p_curr->p_next; - } - - if (p_prev) - { - p_prev->p_next = p_backend->p_next; - } - else - { - m_log_data.p_backend_head = NULL; - } -} - -void nrf_log_panic(void) -{ - nrf_log_backend_t * p_backend = m_log_data.p_backend_head; - m_log_data.autoflush = true; - while (p_backend) - { - nrf_log_backend_enable(p_backend); - nrf_log_backend_panic_set(p_backend); - p_backend = p_backend->p_next; - } -} - -#if NRF_LOG_CLI_CMDS -#include "nrf_cli.h" - -static const char * m_severity_lvls[] = { - "none", - "error", - "warning", - "info", - "debug", -}; - -static const char * m_severity_lvls_sorted[] = { - "debug", - "error", - "info", - "none", - "warning", -}; - -static void log_status(nrf_cli_t const * p_cli, size_t argc, char **argv) -{ - uint32_t modules_cnt = nrf_log_module_cnt_get(); - uint32_t backend_id = p_cli->p_log_backend->backend.id; - uint32_t i; - - if (!nrf_log_backend_is_enabled(&p_cli->p_log_backend->backend)) - { - nrf_cli_fprintf(p_cli, NRF_CLI_ERROR, "Logs are halted!\r\n"); - } - nrf_cli_fprintf(p_cli, NRF_CLI_NORMAL, "%-24s | current | buildin \r\n", "module_name"); - nrf_cli_fprintf(p_cli, NRF_CLI_NORMAL, "------------------------------------------\r\n"); - for (i = 0; i < modules_cnt; i++) - { - nrf_log_severity_t module_dynamic_lvl = nrf_log_module_filter_get(backend_id, i, true, true); - nrf_log_severity_t module_compiled_lvl = nrf_log_module_filter_get(backend_id, i, true, false); - nrf_log_severity_t actual_compiled_lvl = MIN(module_compiled_lvl, (nrf_log_severity_t)NRF_LOG_DEFAULT_LEVEL); - nrf_cli_fprintf(p_cli, NRF_CLI_NORMAL, "%-24s | %-7s | %s%s\r\n", - nrf_log_module_name_get(i, true), - m_severity_lvls[module_dynamic_lvl], - m_severity_lvls[actual_compiled_lvl], - actual_compiled_lvl < module_compiled_lvl ? "*" : ""); - } -} - -static bool module_id_get(const char * p_name, uint32_t * p_id) -{ - uint32_t modules_cnt = nrf_log_module_cnt_get(); - const char * p_tmp_name; - uint32_t j; - for (j = 0; j < modules_cnt; j++) - { - p_tmp_name = nrf_log_module_name_get(j, false); - if (strncmp(p_tmp_name, p_name, 32) == 0) - { - *p_id = j; - break; - } - } - return (j != modules_cnt); -} - -static bool module_id_filter_set(uint32_t backend_id, - uint32_t module_id, - nrf_log_severity_t lvl) -{ - nrf_log_severity_t buildin_lvl = nrf_log_module_filter_get(backend_id, module_id, false, false); - if (lvl > buildin_lvl) - { - return false; - } - else - { - nrf_log_module_filter_set(backend_id, module_id, lvl); - return true; - } -} - -static void log_ctrl(nrf_cli_t const * p_cli, size_t argc, char **argv) -{ - uint32_t backend_id = p_cli->p_log_backend->backend.id; - nrf_log_severity_t lvl; - uint32_t first_m_name_idx; - uint32_t i; - bool all_modules = false; - - if (argc > 0) - { - if (strncmp(argv[0], "enable", 7) == 0) - { - if (argc == 1) - { - nrf_cli_fprintf(p_cli, NRF_CLI_ERROR, "Bad parameter count.\r\n"); - return; - } - - if (argc == 2) - { - all_modules = true; - } - - for (i = 0; i < ARRAY_SIZE(m_severity_lvls); i++) - { - if (strncmp(argv[1], m_severity_lvls[i], 10) == 0) - { - break; - } - } - - if (i == ARRAY_SIZE(m_severity_lvls)) - { - nrf_cli_fprintf(p_cli, NRF_CLI_ERROR, "Unknown severity level: %s\r\n", argv[1]); - return; - } - - lvl = (nrf_log_severity_t)i; - first_m_name_idx = 2; - - } - else if (strncmp(argv[0], "disable", 8) == 0) - { - if (argc == 1) - { - all_modules = true; - } - lvl = NRF_LOG_SEVERITY_NONE; - first_m_name_idx = 1; - } - else - { - nrf_cli_fprintf(p_cli, NRF_CLI_ERROR, "Unknown option: %s\r\n", argv[0]); - return; - } - - if (all_modules) - { - for (i = 0; i < nrf_log_module_cnt_get(); i++) - { - if (module_id_filter_set(backend_id, i, lvl) == false) - { - nrf_cli_fprintf(p_cli, NRF_CLI_ERROR, "Level unavailable for module: %s\r\n", nrf_log_module_name_get(i, false)); - } - } - } - else - { - for (i = first_m_name_idx; i < argc; i++) - { - uint32_t module_id = 0; - if (module_id_get(argv[i], &module_id) == false) - { - nrf_cli_fprintf(p_cli, NRF_CLI_ERROR, "Unknown module:%s\r\n", argv[i]); - } - - if (module_id_filter_set(backend_id, module_id, lvl) == false) - { - nrf_cli_fprintf(p_cli, NRF_CLI_ERROR, "Level unavailable for module: %s\r\n", nrf_log_module_name_get(module_id, false)); - } - } - } - } -} -static void module_name_get(size_t idx, nrf_cli_static_entry_t * p_static); - -NRF_CLI_CREATE_DYNAMIC_CMD(m_module_name, module_name_get); - -static void module_name_get(size_t idx, nrf_cli_static_entry_t * p_static) -{ - p_static->handler = NULL; - p_static->p_help = NULL; - p_static->p_subcmd = &m_module_name; - p_static->p_syntax = nrf_log_module_name_get(idx, true); -} - -static void severity_lvl_get(size_t idx, nrf_cli_static_entry_t * p_static) -{ - p_static->handler = NULL; - p_static->p_help = NULL; - p_static->p_subcmd = &m_module_name; - p_static->p_syntax = (idx < ARRAY_SIZE(m_severity_lvls_sorted)) ? - m_severity_lvls_sorted[idx] : NULL; -} - -NRF_CLI_CREATE_DYNAMIC_CMD(m_severity_lvl, severity_lvl_get); - -static void log_halt(nrf_cli_t const * p_cli, size_t argc, char **argv) -{ - nrf_log_backend_disable(&p_cli->p_log_backend->backend); -} - -static void log_go(nrf_cli_t const * p_cli, size_t argc, char **argv) -{ - nrf_log_backend_enable(&p_cli->p_log_backend->backend); -} - -NRF_CLI_CREATE_STATIC_SUBCMD_SET(m_sub_log_stat) -{ - NRF_CLI_CMD(disable, &m_module_name, - "'log disable .. ' disables logs in specified " - "modules (all if no modules specified).", - log_ctrl), - NRF_CLI_CMD(enable, &m_severity_lvl, - "'log enable ... ' enables logs up to given level in " - "specified modules (all if no modules specified).", - log_ctrl), - NRF_CLI_CMD(go, NULL, "Resume logging", log_go), - NRF_CLI_CMD(halt, NULL, "Halt logging", log_halt), - NRF_CLI_CMD(status, NULL, "Logger status", log_status), - NRF_CLI_SUBCMD_SET_END -}; - -static void log_cmd(nrf_cli_t const * p_cli, size_t argc, char **argv) -{ - if ((argc == 1) || nrf_cli_help_requested(p_cli)) - { - nrf_cli_help_print(p_cli, NULL, 0); - return; - } - - nrf_cli_fprintf(p_cli, NRF_CLI_ERROR, "%s:%s%s\r\n", argv[0], " unknown parameter: ", argv[1]); -} - -NRF_CLI_CMD_REGISTER(log, &m_sub_log_stat, "Commands for controlling logger", log_cmd); - -#endif //NRF_LOG_CLI_CMDS - -#endif // NRF_MODULE_ENABLED(NRF_LOG) diff --git a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/libraries/experimental_log/src/nrf_log_internal.h b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/libraries/experimental_log/src/nrf_log_internal.h deleted file mode 100644 index 3cf7b0600c6..00000000000 --- a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/libraries/experimental_log/src/nrf_log_internal.h +++ /dev/null @@ -1,548 +0,0 @@ -/** - * Copyright (c) 2016 - 2017, 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. - * - */ -#ifndef NRF_LOG_INTERNAL_H__ -#define NRF_LOG_INTERNAL_H__ -#include "sdk_common.h" -#include "nrf.h" -#include "nrf_error.h" -#include "app_util.h" -#include -#include - -#ifndef NRF_LOG_ERROR_COLOR - #define NRF_LOG_ERROR_COLOR NRF_LOG_COLOR_DEFAULT -#endif - -#ifndef NRF_LOG_WARNING_COLOR - #define NRF_LOG_WARNING_COLOR NRF_LOG_COLOR_DEFAULT -#endif - -#ifndef NRF_LOG_INFO_COLOR - #define NRF_LOG_INFO_COLOR NRF_LOG_COLOR_DEFAULT -#endif - -#ifndef NRF_LOG_DEBUG_COLOR - #define NRF_LOG_DEBUG_COLOR NRF_LOG_COLOR_DEFAULT -#endif - - -#ifndef NRF_LOG_COLOR_DEFAULT -#define NRF_LOG_COLOR_DEFAULT 0 -#endif - -#ifndef NRF_LOG_DEFAULT_LEVEL -#define NRF_LOG_DEFAULT_LEVEL 0 -#endif - -#ifndef NRF_LOG_USES_COLORS -#define NRF_LOG_USES_COLORS 0 -#endif - -#ifndef NRF_LOG_USES_TIMESTAMP -#define NRF_LOG_USES_TIMESTAMP 0 -#endif - -#ifndef NRF_LOG_FILTERS_ENABLED -#define NRF_LOG_FILTERS_ENABLED 0 -#endif - -#ifndef NRF_LOG_MODULE_NAME - #define NRF_LOG_MODULE_NAME app -#endif - -#define NRF_LOG_LEVEL_ERROR 1UL -#define NRF_LOG_LEVEL_WARNING 2UL -#define NRF_LOG_LEVEL_INFO 3UL -#define NRF_LOG_LEVEL_DEBUG 4UL -#define NRF_LOG_LEVEL_INTERNAL 5UL -#define NRF_LOG_LEVEL_BITS 3 -#define NRF_LOG_LEVEL_MASK ((1UL << NRF_LOG_LEVEL_BITS) - 1) -#define NRF_LOG_RAW_POS 4U -#define NRF_LOG_RAW (1UL << NRF_LOG_RAW_POS) -#define NRF_LOG_MODULE_ID_BITS 16 -#define NRF_LOG_MODULE_ID_POS 16 -#define NRF_LOG_LEVEL_INFO_RAW (NRF_LOG_RAW | NRF_LOG_LEVEL_INFO) - -#define NRF_LOG_MAX_NUM_OF_ARGS 6 - -/* - * For GCC sections are sorted in the group by the linker. For IAR and KEIL it is assumed that linker will sort - * dynamic and const section in the same order (but in different locations). Proper message formatting - * is based on that assumption. - */ -#if defined(__GNUC__) -#define NRF_LOG_DYNAMIC_SECTION_NAME(_module_name) CONCAT_2(log_dynamic_data_,_module_name) -#define NRF_LOG_CONST_SECTION_NAME(_module_name) CONCAT_2(log_const_data_,_module_name) -#else -#define NRF_LOG_DYNAMIC_SECTION_NAME(_module_name) log_dynamic_data -#define NRF_LOG_CONST_SECTION_NAME(_module_name) log_const_data -#endif - -#define NRF_LOG_MODULE_DATA CONCAT_3(m_nrf_log_,NRF_LOG_MODULE_NAME,_logs_data) -#define NRF_LOG_MODULE_DATA_DYNAMIC CONCAT_2(NRF_LOG_MODULE_DATA,_dynamic) -#define NRF_LOG_MODULE_DATA_CONST CONCAT_2(NRF_LOG_MODULE_DATA,_const) - -#if NRF_LOG_FILTERS_ENABLED && NRF_LOG_ENABLED - #define NRF_LOG_FILTER NRF_LOG_MODULE_DATA_DYNAMIC.filter -#else - #undef NRF_LOG_FILTER - #define NRF_LOG_FILTER NRF_LOG_LEVEL_DEBUG -#endif - -#if NRF_LOG_ENABLED -#define NRF_LOG_MODULE_ID NRF_LOG_MODULE_DATA_DYNAMIC.module_id -#else -#define NRF_LOG_MODULE_ID 0 -#endif - - -#define LOG_INTERNAL_X(N, ...) CONCAT_2(LOG_INTERNAL_, N) (__VA_ARGS__) -#define LOG_INTERNAL(type, ...) LOG_INTERNAL_X(NUM_VA_ARGS_LESS_1( \ - __VA_ARGS__), type, __VA_ARGS__) -#if NRF_LOG_ENABLED -#define NRF_LOG_INTERNAL_LOG_PUSH(_str) nrf_log_push(_str) -#define LOG_INTERNAL_0(type, str) \ - nrf_log_frontend_std_0(type, str) -#define LOG_INTERNAL_1(type, str, arg0) \ - /*lint -save -e571*/nrf_log_frontend_std_1(type, str, (uint32_t)(arg0))/*lint -restore*/ -#define LOG_INTERNAL_2(type, str, arg0, arg1) \ - /*lint -save -e571*/nrf_log_frontend_std_2(type, str, (uint32_t)(arg0), \ - (uint32_t)(arg1))/*lint -restore*/ -#define LOG_INTERNAL_3(type, str, arg0, arg1, arg2) \ - /*lint -save -e571*/nrf_log_frontend_std_3(type, str, (uint32_t)(arg0), \ - (uint32_t)(arg1), (uint32_t)(arg2))/*lint -restore*/ -#define LOG_INTERNAL_4(type, str, arg0, arg1, arg2, arg3) \ - /*lint -save -e571*/nrf_log_frontend_std_4(type, str, (uint32_t)(arg0), \ - (uint32_t)(arg1), (uint32_t)(arg2), (uint32_t)(arg3))/*lint -restore*/ -#define LOG_INTERNAL_5(type, str, arg0, arg1, arg2, arg3, arg4) \ - /*lint -save -e571*/nrf_log_frontend_std_5(type, str, (uint32_t)(arg0), \ - (uint32_t)(arg1), (uint32_t)(arg2), (uint32_t)(arg3), (uint32_t)(arg4))/*lint -restore*/ -#define LOG_INTERNAL_6(type, str, arg0, arg1, arg2, arg3, arg4, arg5) \ - /*lint -save -e571*/nrf_log_frontend_std_6(type, str, (uint32_t)(arg0), \ - (uint32_t)(arg1), (uint32_t)(arg2), (uint32_t)(arg3), (uint32_t)(arg4), (uint32_t)(arg5))/*lint -restore*/ - - -#else //NRF_LOG_ENABLED -#define NRF_LOG_INTERNAL_LOG_PUSH(_str) (void)(_str) -#define LOG_INTERNAL_0(_type, _str) \ - (void)(_type); (void)(_str) -#define LOG_INTERNAL_1(_type, _str, _arg0) \ - (void)(_type); (void)(_str); (void)(_arg0) -#define LOG_INTERNAL_2(_type, _str, _arg0, _arg1) \ - (void)(_type); (void)(_str); (void)(_arg0); (void)(_arg1) -#define LOG_INTERNAL_3(_type, _str, _arg0, _arg1, _arg2) \ - (void)(_type); (void)(_str); (void)(_arg0); (void)(_arg1); (void)(_arg2) -#define LOG_INTERNAL_4(_type, _str, _arg0, _arg1, _arg2, _arg3) \ - (void)(_type); (void)(_str); (void)(_arg0); (void)(_arg1); (void)(_arg2); (void)(_arg3) -#define LOG_INTERNAL_5(_type, _str, _arg0, _arg1, _arg2, _arg3, _arg4) \ - (void)(_type); (void)(_str); (void)(_arg0); (void)(_arg1); (void)(_arg2); (void)(_arg3); (void)(_arg4) -#define LOG_INTERNAL_6(_type, _str, _arg0, _arg1, _arg2, _arg3, _arg4, _arg5) \ - (void)(_type); (void)(_str); (void)(_arg0); (void)(_arg1); (void)(_arg2); (void)(_arg3); (void)(_arg4); (void)(_arg5) -#endif //NRF_LOG_ENABLED && (NRF_LOG_DEFAULT_LEVEL >= NRF_LOG_LEVEL_ERROR) - -#define LOG_SEVERITY_MOD_ID(severity) ((severity) | NRF_LOG_MODULE_ID << NRF_LOG_MODULE_ID_POS) - -#if NRF_LOG_ENABLED -#define LOG_HEXDUMP(_severity, _p_data, _length) \ - nrf_log_frontend_hexdump((_severity), (_p_data), (_length)) -#else -#define LOG_HEXDUMP(_severity, _p_data, _length) \ - (void)(_severity); (void)(_p_data); (void)_length -#endif - -#define NRF_LOG_INTERNAL_ERROR(...) \ - if (NRF_LOG_ENABLED && (NRF_LOG_LEVEL >= NRF_LOG_LEVEL_ERROR) && \ - (NRF_LOG_LEVEL_ERROR <= NRF_LOG_DEFAULT_LEVEL)) \ - { \ - if (NRF_LOG_FILTER >= NRF_LOG_LEVEL_ERROR) \ - { \ - LOG_INTERNAL(LOG_SEVERITY_MOD_ID(NRF_LOG_LEVEL_ERROR), __VA_ARGS__); \ - } \ - } -#define NRF_LOG_INTERNAL_HEXDUMP_ERROR(p_data, len) \ - if (NRF_LOG_ENABLED && (NRF_LOG_LEVEL >= NRF_LOG_LEVEL_ERROR) && \ - (NRF_LOG_LEVEL_ERROR <= NRF_LOG_DEFAULT_LEVEL)) \ - { \ - if (NRF_LOG_FILTER >= NRF_LOG_LEVEL_ERROR) \ - { \ - LOG_HEXDUMP(LOG_SEVERITY_MOD_ID(NRF_LOG_LEVEL_ERROR), \ - (p_data), (len)); \ - } \ - } - -#define NRF_LOG_INTERNAL_WARNING(...) \ - if (NRF_LOG_ENABLED && (NRF_LOG_LEVEL >= NRF_LOG_LEVEL_WARNING) && \ - (NRF_LOG_LEVEL_WARNING <= NRF_LOG_DEFAULT_LEVEL)) \ - { \ - if (NRF_LOG_FILTER >= NRF_LOG_LEVEL_WARNING) \ - { \ - LOG_INTERNAL(LOG_SEVERITY_MOD_ID(NRF_LOG_LEVEL_WARNING), __VA_ARGS__); \ - } \ - } -#define NRF_LOG_INTERNAL_HEXDUMP_WARNING(p_data, len) \ - if (NRF_LOG_ENABLED && (NRF_LOG_LEVEL >= NRF_LOG_LEVEL_WARNING) && \ - (NRF_LOG_LEVEL_WARNING <= NRF_LOG_DEFAULT_LEVEL)) \ - { \ - if (NRF_LOG_FILTER >= NRF_LOG_LEVEL_WARNING) \ - { \ - LOG_HEXDUMP(LOG_SEVERITY_MOD_ID(NRF_LOG_LEVEL_WARNING, \ - (p_data), (len)); \ - } \ - } - -#define NRF_LOG_INTERNAL_INFO(...) \ - if (NRF_LOG_ENABLED && (NRF_LOG_LEVEL >= NRF_LOG_LEVEL_INFO) && \ - (NRF_LOG_LEVEL_INFO <= NRF_LOG_DEFAULT_LEVEL)) \ - { \ - if (NRF_LOG_FILTER >= NRF_LOG_LEVEL_INFO) \ - { \ - LOG_INTERNAL(LOG_SEVERITY_MOD_ID(NRF_LOG_LEVEL_INFO), __VA_ARGS__); \ - } \ - } - -#define NRF_LOG_INTERNAL_RAW_INFO(...) \ - if (NRF_LOG_ENABLED && (NRF_LOG_LEVEL >= NRF_LOG_LEVEL_INFO) && \ - (NRF_LOG_LEVEL_INFO <= NRF_LOG_DEFAULT_LEVEL)) \ - { \ - if (NRF_LOG_FILTER >= NRF_LOG_LEVEL_INFO) \ - { \ - LOG_INTERNAL(LOG_SEVERITY_MOD_ID(NRF_LOG_LEVEL_INFO | NRF_LOG_RAW), \ - __VA_ARGS__); \ - } \ - } - -#define NRF_LOG_INTERNAL_HEXDUMP_INFO(p_data, len) \ - if (NRF_LOG_ENABLED && (NRF_LOG_LEVEL >= NRF_LOG_LEVEL_INFO) && \ - (NRF_LOG_LEVEL_INFO <= NRF_LOG_DEFAULT_LEVEL)) \ - { \ - if (NRF_LOG_FILTER >= NRF_LOG_LEVEL_INFO) \ - { \ - LOG_HEXDUMP(LOG_SEVERITY_MOD_ID(NRF_LOG_LEVEL_INFO), \ - (p_data), (len)); \ - } \ - } - -#define NRF_LOG_INTERNAL_RAW_HEXDUMP_INFO(p_data, len) \ - if (NRF_LOG_ENABLED && (NRF_LOG_LEVEL >= NRF_LOG_LEVEL_INFO) && \ - (NRF_LOG_LEVEL_INFO <= NRF_LOG_DEFAULT_LEVEL)) \ - { \ - if (NRF_LOG_FILTER >= NRF_LOG_LEVEL_INFO) \ - { \ - LOG_HEXDUMP(LOG_SEVERITY_MOD_ID(NRF_LOG_LEVEL_INFO_RAW), \ - (p_data), (len)); \ - } \ - } - -#define NRF_LOG_INTERNAL_DEBUG(...) \ - if (NRF_LOG_ENABLED && (NRF_LOG_LEVEL >= NRF_LOG_LEVEL_DEBUG) && \ - (NRF_LOG_LEVEL_DEBUG <= NRF_LOG_DEFAULT_LEVEL)) \ - { \ - if (NRF_LOG_FILTER >= NRF_LOG_LEVEL_DEBUG) \ - { \ - LOG_INTERNAL(LOG_SEVERITY_MOD_ID(NRF_LOG_LEVEL_DEBUG), __VA_ARGS__); \ - } \ - } -#define NRF_LOG_INTERNAL_HEXDUMP_DEBUG(p_data, len) \ - if (NRF_LOG_ENABLED && (NRF_LOG_LEVEL >= NRF_LOG_LEVEL_DEBUG) && \ - (NRF_LOG_LEVEL_DEBUG <= NRF_LOG_DEFAULT_LEVEL)) \ - { \ - if (NRF_LOG_FILTER >= NRF_LOG_LEVEL_DEBUG) \ - { \ - LOG_HEXDUMP(LOG_SEVERITY_MOD_ID(NRF_LOG_LEVEL_DEBUG), \ - (p_data), (len)); \ - } \ - } - -#if NRF_MODULE_ENABLED(NRF_LOG) -#define NRF_LOG_INTERNAL_GETCHAR() nrf_log_getchar() -#else -#define NRF_LOG_INTERNAL_GETCHAR() (void) -#endif - -typedef struct -{ - uint16_t module_id; - uint16_t order_idx; - uint32_t filter; - uint32_t filter_lvls; -} nrf_log_module_dynamic_data_t; - -typedef struct -{ - const char * p_module_name; - uint8_t info_color_id; - uint8_t debug_color_id; - uint8_t compiled_lvl; -} nrf_log_module_const_data_t; - -extern nrf_log_module_dynamic_data_t NRF_LOG_MODULE_DATA_DYNAMIC; - -/** - * Set of macros for encoding and decoding header for log entries. - * There are 3 types of entries: - * 1. Standard entry (STD) - * An entry consists of header, pointer to string and values. Header contains - * severity leveland determines number of arguments and thus size of the entry. - * Since flash address space starts from 0x00000000 and is limited to kB rather - * than MB 22 bits are used to store the address (4MB). It is used that way to - * save one RAM memory. - * - * -------------------------------- - * |TYPE|SEVERITY|NARGS| P_STR | - * |------------------------------| - * | Module_ID (optional) | - * |------------------------------| - * | TIMESTAMP (optional) | - * |------------------------------| - * | ARG0 | - * |------------------------------| - * | .... | - * |------------------------------| - * | ARG(nargs-1) | - * -------------------------------- - * - * 2. Hexdump entry (HEXDUMP) is used for dumping raw data. An entry consists of - * header, optional timestamp, pointer to string and data. A header contains - * length (10bit) and offset which is updated after backend processes part of - * data. - * - * -------------------------------- - * |TYPE|SEVERITY|NARGS|OFFSET|LEN| - * |------------------------------| - * | Module_ID (optional) | - * |------------------------------| - * | TIMESTAMP (optional) | - * |------------------------------| - * | P_STR | - * |------------------------------| - * | data | - * |------------------------------| - * | data | dummy | - * -------------------------------- - * - * 3. Pushed string. If string is pushed into the logger internal buffer it is - * stored as PUSHED entry. It consists of header, unused data (optional) and - * string. Unused data is present if string does not not fit into a buffer - * without wrapping (and string cannot be wrapped). In that case header - * contains information about offset. - * - * -------------------------------- - * |TYPE| OFFSET | LEN | - * |------------------------------| - * | OFFSET | - * |------------------------------| - * end| OFFSET | - * 0|------------------------------| - * | STRING | - * |------------------------------| - * | STRING | dummy | - * -------------------------------- - */ - -#define STD_ADDR_MASK ((uint32_t)(1U << 22) - 1U) -#define HEADER_TYPE_STD 1U -#define HEADER_TYPE_HEXDUMP 2U -#define HEADER_TYPE_PUSHED 0U -#define HEADER_TYPE_INVALID 3U - -typedef struct -{ - uint32_t type : 2; - uint32_t raw : 1; - uint32_t data : 29; -} nrf_log_generic_header_t; - -typedef struct -{ - uint32_t type : 2; - uint32_t raw : 1; - uint32_t severity : 3; - uint32_t nargs : 4; - uint32_t addr : 22; -} nrf_log_std_header_t; - -typedef struct -{ - uint32_t type : 2; - uint32_t raw : 1; - uint32_t severity : 3; - uint32_t offset : 10; - uint32_t reserved : 6; - uint32_t len : 10; -} nrf_log_hexdump_header_t; - -typedef struct -{ - uint32_t type : 2; - uint32_t reserved0 : 4; - uint32_t offset : 10; - uint32_t reserved1 : 6; - uint32_t len : 10; -} nrf_log_pushed_header_t; - -typedef struct -{ - union { - nrf_log_generic_header_t generic; - nrf_log_std_header_t std; - nrf_log_hexdump_header_t hexdump; - nrf_log_pushed_header_t pushed; - uint32_t raw; - } base; - uint32_t module_id; - uint32_t timestamp; -} nrf_log_header_t; - -#define HEADER_SIZE (sizeof(nrf_log_header_t)/sizeof(uint32_t) - \ - (NRF_LOG_USES_TIMESTAMP ? 0 : 1)) - -#define PUSHED_HEADER_SIZE (sizeof(nrf_log_pushed_header_t)/sizeof(uint32_t)) - -//Implementation assumes that pushed header has one word. -STATIC_ASSERT(PUSHED_HEADER_SIZE == 1); -/** - * @brief A function for logging raw string. - * - * @param severity_mid Severity. - * @param p_str A pointer to a string. - */ -void nrf_log_frontend_std_0(uint32_t severity_mid, char const * const p_str); - -/** - * @brief A function for logging a formatted string with one argument. - * - * @param severity_mid Severity. - * @param p_str A pointer to a formatted string. - * @param val0 An argument. - */ -void nrf_log_frontend_std_1(uint32_t severity_mid, - char const * const p_str, - uint32_t val0); - -/** - * @brief A function for logging a formatted string with 2 arguments. - * - * @param severity_mid Severity. - * @param p_str A pointer to a formatted string. - * @param val0, val1 Arguments for formatting string. - */ -void nrf_log_frontend_std_2(uint32_t severity_mid, - char const * const p_str, - uint32_t val0, - uint32_t val1); - -/** - * @brief A function for logging a formatted string with 3 arguments. - * - * @param severity_mid Severity. - * @param p_str A pointer to a formatted string. - * @param val0, val1, val2 Arguments for formatting string. - */ -void nrf_log_frontend_std_3(uint32_t severity_mid, - char const * const p_str, - uint32_t val0, - uint32_t val1, - uint32_t val2); - -/** - * @brief A function for logging a formatted string with 4 arguments. - * - * @param severity_mid Severity. - * @param p_str A pointer to a formatted string. - * @param val0, val1, val2, val3 Arguments for formatting string. - */ -void nrf_log_frontend_std_4(uint32_t severity_mid, - char const * const p_str, - uint32_t val0, - uint32_t val1, - uint32_t val2, - uint32_t val3); - -/** - * @brief A function for logging a formatted string with 5 arguments. - * - * @param severity_mid Severity. - * @param p_str A pointer to a formatted string. - * @param val0, val1, val2, val3, val4 Arguments for formatting string. - */ -void nrf_log_frontend_std_5(uint32_t severity_mid, - char const * const p_str, - uint32_t val0, - uint32_t val1, - uint32_t val2, - uint32_t val3, - uint32_t val4); - -/** - * @brief A function for logging a formatted string with 6 arguments. - * - * @param severity_mid Severity. - * @param p_str A pointer to a formatted string. - * @param val0, val1, val2, val3, val4, val5 Arguments for formatting string. - */ -void nrf_log_frontend_std_6(uint32_t severity_mid, - char const * const p_str, - uint32_t val0, - uint32_t val1, - uint32_t val2, - uint32_t val3, - uint32_t val4, - uint32_t val5); - -/** - * @brief A function for logging raw data. - * - * @param severity_mid Severity. - * @param p_str A pointer to a string which is prefixing the data. - * @param p_data A pointer to data to be dumped. - * @param length Length of data (in bytes). - * - */ -void nrf_log_frontend_hexdump(uint32_t severity_mid, - const void * const p_data, - uint16_t length); - -/** - * @brief A function for reading a byte from log backend. - * - * @return Byte. - */ -uint8_t nrf_log_getchar(void); -#endif // NRF_LOG_INTERNAL_H__ diff --git a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/libraries/experimental_log/src/nrf_log_str_formatter.c b/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/libraries/experimental_log/src/nrf_log_str_formatter.c deleted file mode 100644 index accdf224fc7..00000000000 --- a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/libraries/experimental_log/src/nrf_log_str_formatter.c +++ /dev/null @@ -1,209 +0,0 @@ -/** - * Copyright (c) 2016 - 2017, 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_common.h" -#if NRF_MODULE_ENABLED(NRF_LOG) -#include "nrf_log_str_formatter.h" -#include "nrf_log_internal.h" -#include "nrf_log_ctrl.h" -#include "nrf_fprintf.h" -#include - -#define NRF_LOG_COLOR_CODE_DEFAULT "\x1B[0m" -#define NRF_LOG_COLOR_CODE_BLACK "\x1B[1;30m" -#define NRF_LOG_COLOR_CODE_RED "\x1B[1;31m" -#define NRF_LOG_COLOR_CODE_GREEN "\x1B[1;32m" -#define NRF_LOG_COLOR_CODE_YELLOW "\x1B[1;33m" -#define NRF_LOG_COLOR_CODE_BLUE "\x1B[1;34m" -#define NRF_LOG_COLOR_CODE_MAGENTA "\x1B[1;35m" -#define NRF_LOG_COLOR_CODE_CYAN "\x1B[1;36m" -#define NRF_LOG_COLOR_CODE_WHITE "\x1B[1;37m" - -static const char * severity_names[] = { - NULL, - "error", - "warning", - "info", - "debug" -}; - -static const char * m_colors[] = { - NRF_LOG_COLOR_CODE_DEFAULT, - NRF_LOG_COLOR_CODE_BLACK, - NRF_LOG_COLOR_CODE_RED, - NRF_LOG_COLOR_CODE_GREEN, - NRF_LOG_COLOR_CODE_YELLOW, - NRF_LOG_COLOR_CODE_BLUE, - NRF_LOG_COLOR_CODE_MAGENTA, - NRF_LOG_COLOR_CODE_CYAN, - NRF_LOG_COLOR_CODE_WHITE, -}; - -static void prefix_process(nrf_log_str_formatter_entry_params_t * p_params, - nrf_fprintf_ctx_t * p_ctx) -{ - if (!(p_params->raw)) - { - if (p_params->use_colors) - { - nrf_fprintf(p_ctx, "%s", - m_colors[nrf_log_color_id_get( p_params->module_id, p_params->severity)]); - } - - if (NRF_LOG_USES_TIMESTAMP) - { - nrf_fprintf(p_ctx, "[%08lu] ", p_params->timestamp); - } - - nrf_fprintf(p_ctx, "<%s> %s: ", - severity_names[p_params->severity], nrf_log_module_name_get(p_params->module_id, false)); - } -} - -static void postfix_process(nrf_log_str_formatter_entry_params_t * p_params, - nrf_fprintf_ctx_t * p_ctx, - bool newline) -{ - if (!p_params->raw) - { - if (p_params->use_colors) - { - nrf_fprintf(p_ctx, "%s", m_colors[0]); - } - nrf_fprintf(p_ctx, "\r\n"); - } - else if (newline) - { - nrf_fprintf(p_ctx, "\r\n"); - } - nrf_fprintf_buffer_flush(p_ctx); -} - -void nrf_log_std_entry_process(char const * p_str, - uint32_t const * p_args, - uint32_t nargs, - nrf_log_str_formatter_entry_params_t * p_params, - nrf_fprintf_ctx_t * p_ctx) -{ - bool auto_flush = p_ctx->auto_flush; - p_ctx->auto_flush = false; - - prefix_process(p_params, p_ctx); - - switch (nargs) - { - case 0: - nrf_fprintf(p_ctx, p_str); - break; - case 1: - nrf_fprintf(p_ctx, p_str, p_args[0]); - break; - case 2: - nrf_fprintf(p_ctx, p_str, p_args[0], p_args[1]); - break; - case 3: - nrf_fprintf(p_ctx, p_str, p_args[0], p_args[1], p_args[2]); - break; - case 4: - nrf_fprintf(p_ctx, p_str, p_args[0], p_args[1], p_args[2], p_args[3]); - break; - case 5: - nrf_fprintf(p_ctx, p_str, p_args[0], p_args[1], p_args[2], p_args[3], p_args[4]); - break; - case 6: - nrf_fprintf(p_ctx, p_str, p_args[0], p_args[1], p_args[2], p_args[3], p_args[4], p_args[5]); - break; - - default: - break; - } - - postfix_process(p_params, p_ctx, false); - p_ctx->auto_flush = auto_flush; -} - -#define HEXDUMP_BYTES_IN_LINE 8 - -void nrf_log_hexdump_entry_process(uint8_t * p_data, - uint32_t data_len, - nrf_log_str_formatter_entry_params_t * p_params, - nrf_fprintf_ctx_t * p_ctx) -{ - if (data_len > HEXDUMP_BYTES_IN_LINE) - { - return; - } - bool auto_flush = p_ctx->auto_flush; - p_ctx->auto_flush = false; - - prefix_process(p_params, p_ctx); - - uint32_t i; - - for (i = 0; i < HEXDUMP_BYTES_IN_LINE; i++) - { - if (i < data_len) - { - nrf_fprintf(p_ctx, " %02x", p_data[i]); - } - else - { - nrf_fprintf(p_ctx, " "); - } - } - nrf_fprintf(p_ctx, "|"); - - for (i = 0; i < HEXDUMP_BYTES_IN_LINE; i++) - { - if (i < data_len) - { - char c = (char)p_data[i]; - nrf_fprintf(p_ctx, "%c", isprint((int)c) ? c :'.'); - } - else - { - nrf_fprintf(p_ctx, " "); - } - } - - postfix_process(p_params, p_ctx, true); - - p_ctx->auto_flush = auto_flush; -} -#endif //NRF_LOG_ENABLED diff --git a/targets/TARGET_NORDIC/TARGET_NRF5x/app_uart.h b/targets/TARGET_NORDIC/TARGET_NRF5x/app_uart.h new file mode 100644 index 00000000000..b0e2e1690cc --- /dev/null +++ b/targets/TARGET_NORDIC/TARGET_NRF5x/app_uart.h @@ -0,0 +1,98 @@ +/* mbed Microcontroller Library + * Copyright (c) 2017 ARM Limited + * + * 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. + */ + +#ifndef APP_UART_H_ +#define APP_UART_H_ + +// This replacement provides forwarding of nrf logging to +// stdout when NRF_LOG_USES_UART is enabled + +#include +#include "nrf_error.h" +#include "nrf51_bitfields.h" +#include "cmsis_compiler.h" + +#define app_uart_put(c) putc(c, stdout) + +__STATIC_INLINE uint32_t app_uart_get(uint8_t *c) { + *c = getc(stdin); + return NRF_SUCCESS; +} + +/**@brief UART Flow Control modes for the peripheral. + */ +typedef enum +{ + APP_UART_FLOW_CONTROL_DISABLED, /**< UART Hw Flow Control is disabled. */ + APP_UART_FLOW_CONTROL_ENABLED, /**< Standard UART Hw Flow Control is enabled. */ + APP_UART_FLOW_CONTROL_LOW_POWER /**< Specialized UART Hw Flow Control is used. The Low Power setting allows the \nRFXX to Power Off the UART module when CTS is in-active, and re-enabling the UART when the CTS signal becomes active. This allows the \nRFXX to safe power by only using the UART module when it is needed by the remote site. */ +} app_uart_flow_control_t; + + +/**@brief Enumeration which defines events used by the UART module upon data reception or error. + * + * @details The event type is used to indicate the type of additional information in the event + * @ref app_uart_evt_t. + */ +typedef enum +{ + APP_UART_DATA_READY, /**< An event indicating that UART data has been received. The data is available in the FIFO and can be fetched using @ref app_uart_get. */ + APP_UART_FIFO_ERROR, /**< An error in the FIFO module used by the app_uart module has occured. The FIFO error code is stored in app_uart_evt_t.data.error_code field. */ + APP_UART_COMMUNICATION_ERROR, /**< An communication error has occured during reception. The error is stored in app_uart_evt_t.data.error_communication field. */ + APP_UART_TX_EMPTY, /**< An event indicating that UART has completed transmission of all available data in the TX FIFO. */ + APP_UART_DATA, /**< An event indicating that UART data has been received, and data is present in data field. This event is only used when no FIFO is configured. */ +} app_uart_evt_type_t; + + +/**@brief UART communication structure holding configuration settings for the peripheral. + */ +typedef struct +{ + uint8_t rx_pin_no; /**< RX pin number. */ + uint8_t tx_pin_no; /**< TX pin number. */ + uint8_t rts_pin_no; /**< RTS pin number, only used if flow control is enabled. */ + uint8_t cts_pin_no; /**< CTS pin number, only used if flow control is enabled. */ + app_uart_flow_control_t flow_control; /**< Flow control setting, if flow control is used, the system will use low power UART mode, based on CTS signal. */ + bool use_parity; /**< Even parity if TRUE, no parity if FALSE. */ + uint32_t baud_rate; /**< Baud rate configuration. */ +} app_uart_comm_params_t; + +/**@brief Struct containing events from the UART module. + * + * @details The app_uart_evt_t is used to notify the application of asynchronous events when data + * are received on the UART peripheral or in case an error occured during data reception. + */ +typedef struct +{ + app_uart_evt_type_t evt_type; /**< Type of event. */ + union + { + uint32_t error_communication; /**< Field used if evt_type is: APP_UART_COMMUNICATION_ERROR. This field contains the value in the ERRORSRC register for the UART peripheral. The UART_ERRORSRC_x defines from nrf5x_bitfields.h can be used to parse the error code. See also the \nRFXX Series Reference Manual for specification. */ + uint32_t error_code; /**< Field used if evt_type is: NRF_ERROR_x. Additional status/error code if the error event type is APP_UART_FIFO_ERROR. This error code refer to errors defined in nrf_error.h. */ + uint8_t value; /**< Field used if evt_type is: NRF_ERROR_x. Additional status/error code if the error event type is APP_UART_FIFO_ERROR. This error code refer to errors defined in nrf_error.h. */ + } data; +} app_uart_evt_t; + +//#define APP_IRQ_PRIORITY_LOW -1, +//#define APP_IRQ_PRIORITY_LOWEST -1, + +#define APP_UART_FIFO_INIT(P_COMM_PARAMS, RX_BUF_SIZE, TX_BUF_SIZE, EVT_HANDLER, IRQ_PRIO, ERR_CODE) \ + do \ + { \ + (void)P_COMM_PARAMS; \ + ERR_CODE = 0; \ + } while (0) +#endif // APP_UART_H_ \ No newline at end of file diff --git a/targets/TARGET_NORDIC/TARGET_NRF5x/bsp.h b/targets/TARGET_NORDIC/TARGET_NRF5x/bsp.h new file mode 100644 index 00000000000..65d31081219 --- /dev/null +++ b/targets/TARGET_NORDIC/TARGET_NRF5x/bsp.h @@ -0,0 +1,33 @@ +/* mbed Microcontroller Library + * Copyright (c) 2017 ARM Limited + * + * 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. + */ + +// Dummy header file to satify import requirement of nrf_log.c +// when NRF_LOG_USES_UART is enabled + +#ifndef DUMMY_BSP_H_ +#define DUMMY_BSP_H_ + +const int RX_PIN_NUMBER = -1; +const int TX_PIN_NUMBER = -1; +const int RTS_PIN_NUMBER = -1; +const int CTS_PIN_NUMBER = -1; + +// This is not used for any functional code so does not need to be correct +#ifndef NRF51 +#define NRF51 +#endif + +#endif // DUMMY_BSP_H_ \ No newline at end of file diff --git a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/libraries/experimental_log/nrf_log.h b/targets/TARGET_NORDIC/TARGET_NRF5x/nrf_log.h similarity index 62% rename from targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/libraries/experimental_log/nrf_log.h rename to targets/TARGET_NORDIC/TARGET_NRF5x/nrf_log.h index 967bc1a28a6..9fb0001327b 100644 --- a/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_14_2/libraries/experimental_log/nrf_log.h +++ b/targets/TARGET_NORDIC/TARGET_NRF5x/nrf_log.h @@ -39,25 +39,17 @@ */ /**@file * - * @defgroup nrf_log Logger module + * @defgroup Replacement nrf_log Logger module * @{ - * @ingroup app_common * - * @brief The nrf_log module interface. + * @brief Redirects the nrf log interface to mbed stdout logging . */ #ifndef NRF_LOG_H_ #define NRF_LOG_H_ -#include "sdk_common.h" -#include "nrf_section.h" -#if NRF_MODULE_ENABLED(NRF_LOG) -#include "nrf_strerror.h" -#define NRF_LOG_ERROR_STRING_GET(code) nrf_strerror_get(code) -#else -#define NRF_LOG_ERROR_STRING_GET(code) "" -#endif - +#include +#include "mbed_debug.h" #ifdef __cplusplus extern "C" { @@ -67,13 +59,16 @@ extern "C" { * * The severity level can be defined in a module to override the default. */ +#define NRF_LOG_LEVEL_ERROR 1UL +#define NRF_LOG_LEVEL_WARNING 2UL +#define NRF_LOG_LEVEL_INFO 3UL +#define NRF_LOG_LEVEL_DEBUG 4UL +#define NRF_LOG_LEVEL_INTERNAL 5UL + #ifndef NRF_LOG_LEVEL - #define NRF_LOG_LEVEL NRF_LOG_DEFAULT_LEVEL + #define NRF_LOG_LEVEL NRF_LOG_LEVEL_INFO #endif - -#include "nrf_log_internal.h" - /** @def NRF_LOG_ERROR * @brief Macro for logging error messages. It takes a printf-like, formatted * string with up to seven arguments. @@ -101,16 +96,34 @@ extern "C" { * * @details This macro is compiled only if @ref NRF_LOG_LEVEL includes debug logs. */ - -#define NRF_LOG_ERROR(...) NRF_LOG_INTERNAL_ERROR(__VA_ARGS__) -#define NRF_LOG_WARNING(...) NRF_LOG_INTERNAL_WARNING( __VA_ARGS__) -#define NRF_LOG_INFO(...) NRF_LOG_INTERNAL_INFO( __VA_ARGS__) -#define NRF_LOG_DEBUG(...) NRF_LOG_INTERNAL_DEBUG( __VA_ARGS__) +#define NRF_LOG_DEBUG(x, ...) \ + if (NRF_LOG_ENABLED && (NRF_LOG_LEVEL >= NRF_LOG_LEVEL_DEBUG)) \ + { \ + printf("[NRF_DBG] "x"\r\n", ##__VA_ARGS__); \ + } + +#define NRF_LOG_WARNING(x, ...) \ + if (NRF_LOG_ENABLED && (NRF_LOG_LEVEL >= NRF_LOG_LEVEL_WARNING)) \ + { \ + printf("[NRF_WRN] "x"\r\n", ##__VA_ARGS__); \ + } + +#define NRF_LOG_ERROR(x, ...) \ + if (NRF_LOG_ENABLED && (NRF_LOG_LEVEL >= NRF_LOG_LEVEL_ERROR)) \ + { \ + printf("[NRF_ERR] "x"\r\n", ##__VA_ARGS__); \ + } + +#define NRF_LOG_INFO(x, ...) \ + if (NRF_LOG_ENABLED && (NRF_LOG_LEVEL >= NRF_LOG_LEVEL_INFO)) \ + { \ + printf("[NRF_INF] "x"\r\n", ##__VA_ARGS__); \ + } /** * @brief A macro for logging a formatted string without any prefix or timestamp. */ -#define NRF_LOG_RAW_INFO(...) NRF_LOG_INTERNAL_RAW_INFO( __VA_ARGS__) +#define NRF_LOG_RAW_INFO(x, ...) printf(x, ##__VA_ARGS__); /** @def NRF_LOG_HEXDUMP_ERROR * @brief Macro for logging raw bytes. @@ -140,29 +153,30 @@ extern "C" { * @param p_data Pointer to data. * @param len Data length in bytes. */ -#define NRF_LOG_HEXDUMP_ERROR(p_data, len) NRF_LOG_INTERNAL_HEXDUMP_ERROR(p_data, len) -#define NRF_LOG_HEXDUMP_WARNING(p_data, len) NRF_LOG_INTERNAL_HEXDUMP_WARNING(p_data, len) -#define NRF_LOG_HEXDUMP_INFO(p_data, len) NRF_LOG_INTERNAL_HEXDUMP_INFO(p_data, len) -#define NRF_LOG_HEXDUMP_DEBUG(p_data, len) NRF_LOG_INTERNAL_HEXDUMP_DEBUG(p_data, len) +// #define NRF_LOG_HEXDUMP_ERROR(p_data, len) NRF_LOG_INTERNAL_HEXDUMP_ERROR(p_data, len) +// #define NRF_LOG_HEXDUMP_WARNING(p_data, len) NRF_LOG_INTERNAL_HEXDUMP_WARNING(p_data, len) +// #define NRF_LOG_HEXDUMP_INFO(p_data, len) NRF_LOG_INTERNAL_HEXDUMP_INFO(p_data, len) +// #define NRF_LOG_HEXDUMP_DEBUG(p_data, len) NRF_LOG_INTERNAL_HEXDUMP_DEBUG(p_data, len) -/** - * @brief Macro for logging hexdump without any prefix or timestamp. - */ -#define NRF_LOG_RAW_HEXDUMP_INFO(p_data, len) NRF_LOG_INTERNAL_RAW_HEXDUMP_INFO(p_data, len) +// /** +// * @brief Macro for logging hexdump without any prefix or timestamp. +// */ +// #define NRF_LOG_RAW_HEXDUMP_INFO(p_data, len) NRF_LOG_INTERNAL_RAW_HEXDUMP_INFO(p_data, len) /** * @brief A macro for blocking reading from bidirectional backend used for logging. * * Macro call is blocking and returns when single byte is received. */ -#define NRF_LOG_GETCHAR() NRF_LOG_INTERNAL_GETCHAR() +#define NRF_LOG_GETCHAR() getc(stdin) + /** * @brief A macro for copying a string to internal logger buffer if logs are deferred. * * @param _str String. */ -#define NRF_LOG_PUSH(_str) NRF_LOG_INTERNAL_LOG_PUSH(_str) +// #define NRF_LOG_PUSH(_str) NRF_LOG_INTERNAL_LOG_PUSH(_str) /** * @brief Function for copying a string to the internal logger buffer if logs are deferred. @@ -177,7 +191,10 @@ extern "C" { * * @return Address to the location where the string is stored in the internal logger buffer. */ -uint32_t nrf_log_push(char * const p_str); +// __STATIC_INLINE uint32_t nrf_log_push(char * const p_str) { +// (void)p_str; +// return -1; +// } /** * @brief Macro to be used in a formatted string to a pass float number to the log. @@ -202,28 +219,28 @@ uint32_t nrf_log_push(char * const p_str); * @def NRF_LOG_MODULE_REGISTER * @brief Macro for registering an independent module. */ -#if NRF_LOG_ENABLED - -#ifdef UNIT_TEST -#define _CONST -#define COMPILED_LOG_LEVEL 4 -#else -#define _CONST const -#define COMPILED_LOG_LEVEL NRF_LOG_LEVEL -#endif -#define NRF_LOG_MODULE_REGISTER() \ - NRF_SECTION_ITEM_REGISTER(NRF_LOG_CONST_SECTION_NAME(NRF_LOG_MODULE_NAME), \ - _CONST nrf_log_module_const_data_t NRF_LOG_MODULE_DATA_CONST) = { \ - .p_module_name = STRINGIFY(NRF_LOG_MODULE_NAME), \ - .info_color_id = NRF_LOG_INFO_COLOR, \ - .debug_color_id = NRF_LOG_DEBUG_COLOR, \ - .compiled_lvl = COMPILED_LOG_LEVEL, \ - }; \ - NRF_SECTION_ITEM_REGISTER(NRF_LOG_DYNAMIC_SECTION_NAME(NRF_LOG_MODULE_NAME), \ - nrf_log_module_dynamic_data_t NRF_LOG_MODULE_DATA_DYNAMIC) -#else -#define NRF_LOG_MODULE_REGISTER() /*lint -save -e19*/ /*lint -restore*/ -#endif +// #if NRF_LOG_ENABLED + +// #ifdef UNIT_TEST +// #define _CONST +// #define COMPILED_LOG_LEVEL 4 +// #else +// #define _CONST const +// #define COMPILED_LOG_LEVEL NRF_LOG_LEVEL +// #endif +// #define NRF_LOG_MODULE_REGISTER() \ +// NRF_SECTION_ITEM_REGISTER(NRF_LOG_CONST_SECTION_NAME(NRF_LOG_MODULE_NAME), \ +// _CONST nrf_log_module_const_data_t NRF_LOG_MODULE_DATA_CONST) = { \ +// .p_module_name = STRINGIFY(NRF_LOG_MODULE_NAME), \ +// .info_color_id = NRF_LOG_INFO_COLOR, \ +// .debug_color_id = NRF_LOG_DEBUG_COLOR, \ +// .compiled_lvl = COMPILED_LOG_LEVEL, \ +// }; \ +// NRF_SECTION_ITEM_REGISTER(NRF_LOG_DYNAMIC_SECTION_NAME(NRF_LOG_MODULE_NAME), \ +// nrf_log_module_dynamic_data_t NRF_LOG_MODULE_DATA_DYNAMIC) +// #else +// #define NRF_LOG_MODULE_REGISTER() /*lint -save -e19*/ /*lint -restore*/ +// #endif #ifdef __cplusplus }