Skip to content

Commit

Permalink
externals/nrf52: Modify log output codes for spresense
Browse files Browse the repository at this point in the history
Modify for spresense to output logs to standard output.
  • Loading branch information
SPRESENSE committed Jul 20, 2022
1 parent 686de10 commit 5e1c599
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "app_util.h"
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include "nrf_log_instance.h"
#include "nrf_log_types.h"

Expand Down Expand Up @@ -134,9 +135,13 @@
#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__)
#define stringify(x) #x
#define MODULE_NAME(x) stringify(x)
#define LOG_INTERNAL(level, ...) \
printf("[" #level "][%s] ", MODULE_NAME(NRF_LOG_MODULE_NAME)); \
printf(__VA_ARGS__); \
printf("\n");

#if NRF_LOG_ENABLED
#define NRF_LOG_INTERNAL_LOG_PUSH(_str) nrf_log_push(_str)
#define LOG_INTERNAL_0(type, str) \
Expand Down Expand Up @@ -195,7 +200,7 @@
{ \
if (NRF_LOG_INST_FILTER(p_inst) >= level) \
{ \
LOG_INTERNAL(LOG_SEVERITY_INST_ID(level_id, p_inst), __VA_ARGS__); \
LOG_INTERNAL(level, __VA_ARGS__); \
} \
}

Expand All @@ -205,7 +210,7 @@
{ \
if (NRF_LOG_FILTER >= level) \
{ \
LOG_INTERNAL(LOG_SEVERITY_MOD_ID(level_id), __VA_ARGS__); \
LOG_INTERNAL(level, __VA_ARGS__); \
} \
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@
#include "nrf_queue.h"
#include "app_util_platform.h"

//#define BLE_DBGPRT_ENABLE
#ifdef BLE_DBGPRT_ENABLE
#include <stdio.h>
#define NRF_LOG_INST_WARNING printf
#define NRF_LOG_INST_DEBUG(...)
#if NRF_QUEUE_CONFIG_LOG_ENABLED
#define NRF_LOG_LEVEL NRF_QUEUE_CONFIG_LOG_LEVEL
#define NRF_LOG_INIT_FILTER_LEVEL NRF_QUEUE_CONFIG_LOG_INIT_FILTER_LEVEL
#define NRF_LOG_INFO_COLOR NRF_QUEUE_CONFIG_INFO_COLOR
#define NRF_LOG_DEBUG_COLOR NRF_QUEUE_CONFIG_DEBUG_COLOR
#else
#define NRF_LOG_INST_WARNING(...)
#define NRF_LOG_INST_DEBUG(...)
#endif
#define NRF_LOG_LEVEL 0
#endif // NRF_QUEUE_CONFIG_LOG_ENABLED
#include "nrf_log.h"

#define __STATIC_INLINE static __inline

Expand Down Expand Up @@ -221,7 +221,7 @@ ret_code_t nrf_queue_push(nrf_queue_t const * p_queue, void const * p_element)

CRITICAL_REGION_EXIT();

NRF_LOG_INST_DEBUG(p_queue->p_log, "pushed element 0x%08X, status:%d", p_element, status);
NRF_LOG_INST_DEBUG(p_queue->p_log, "pushed element 0x%p, status:%ld", p_element, status);
return status;
}

Expand Down Expand Up @@ -279,7 +279,7 @@ ret_code_t nrf_queue_generic_pop(nrf_queue_t const * p_queue,
}

CRITICAL_REGION_EXIT();
NRF_LOG_INST_DEBUG(p_queue->p_log, "%s element 0x%08X, status:%d",
NRF_LOG_INST_DEBUG(p_queue->p_log, "%s element 0x%p, status:%ld",
just_peek ? "peeked" : "popped", p_element, status);
return status;
}
Expand Down Expand Up @@ -384,7 +384,7 @@ ret_code_t nrf_queue_write(nrf_queue_t const * p_queue,

CRITICAL_REGION_EXIT();

NRF_LOG_INST_DEBUG(p_queue->p_log, "Write %d elements (start address: 0x%08X), status:%d",
NRF_LOG_INST_DEBUG(p_queue->p_log, "Write %d elements (start address: 0x%p), status:%ld",
element_count, p_data, status);
return status;
}
Expand All @@ -397,6 +397,8 @@ size_t nrf_queue_in(nrf_queue_t const * p_queue,
ASSERT(p_queue != NULL);
ASSERT(p_data != NULL);

size_t req_element_count = element_count;

if (element_count == 0)
{
return 0;
Expand All @@ -418,7 +420,7 @@ size_t nrf_queue_in(nrf_queue_t const * p_queue,

CRITICAL_REGION_EXIT();

NRF_LOG_INST_DEBUG(p_queue->p_log, "Put in %d elements (start address: 0x%08X), requested :%d",
NRF_LOG_INST_DEBUG(p_queue->p_log, "Put in %d elements (start address: 0x%p), requested :%d",
element_count, p_data, req_element_count);

return element_count;
Expand Down Expand Up @@ -491,7 +493,7 @@ ret_code_t nrf_queue_read(nrf_queue_t const * p_queue,

CRITICAL_REGION_EXIT();

NRF_LOG_INST_DEBUG(p_queue->p_log, "Read %d elements (start address: 0x%08X), status :%d",
NRF_LOG_INST_DEBUG(p_queue->p_log, "Read %d elements (start address: 0x%p), status :%ld",
element_count, p_data, status);
return status;
}
Expand All @@ -503,7 +505,7 @@ size_t nrf_queue_out(nrf_queue_t const * p_queue,
ASSERT(p_queue != NULL);
ASSERT(p_data != NULL);

//size_t req_element_count = element_count;
size_t req_element_count = element_count;

if (element_count == 0)
{
Expand All @@ -519,7 +521,7 @@ size_t nrf_queue_out(nrf_queue_t const * p_queue,

CRITICAL_REGION_EXIT();

NRF_LOG_INST_DEBUG(p_queue->p_log, "Out %d elements (start address: 0x%08X), requested :%d",
NRF_LOG_INST_DEBUG(p_queue->p_log, "Out %d elements (start address: 0x%p), requested :%d",
element_count, p_data, req_element_count);
return element_count;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,15 @@
//#include "ser_dbg_sd_str.h"
#include "ser_app_power_system_off.h"
#include "app_util.h"

#define BLE_DBGPRT_ENABLE
#ifdef BLE_DBGPRT_ENABLE
#include <stdio.h>
#define NRF_LOG_DEBUG printf
#include "sdk_config.h"
#define NRF_LOG_MODULE_NAME ser_sd_transport
#if SER_SD_TRANSPORT_CONFIG_LOG_ENABLED
#define NRF_LOG_LEVEL SER_SD_TRANSPORT_CONFIG_LOG_LEVEL
#else
#define NRF_LOG_DEBUG(...)
#define NRF_LOG_LEVEL 0
#endif
#include "nrf_log.h"
NRF_LOG_MODULE_REGISTER();

#ifdef BLE_STACK_SUPPORT_REQD
/** SoftDevice event handler. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,14 @@
#include "ant_event.h"
#endif

//#define BLE_DBGPRT_ENABLE
#ifdef BLE_DBGPRT_ENABLE
#include <stdio.h>
#define NRF_LOG_DEBUG printf
#else
#define NRF_LOG_DEBUG(...)
#define NRF_LOG_MODULE_NAME ser_sd_handler
#if SER_SD_HANDLER_CONFIG_LOG_ENABLED
#define NRF_LOG_LEVEL SER_SD_HANDLER_CONFIG_LOG_LEVEL
#else
#define NRF_LOG_LEVEL 0
#endif
#include "nrf_log.h"
NRF_LOG_MODULE_REGISTER();

#define SD_BLE_EVT_MAILBOX_QUEUE_SIZE 5 /**< Size of mailbox queue. */
#define SD_BLE_RESPONSE_TIMEOUT 5000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,16 @@
#include "ser_hal_transport.h"
#include "nrf_error.h"

//#define BLE_DBGPRT_ENABLE
#ifdef BLE_DBGPRT_ENABLE
#include <stdio.h>
#define NRF_LOG_INFO printf
#else
#define NRF_LOG_INFO(...)
#endif

#define NRF_LOG_MODULE_NAME ser_hal_transport
#if SER_HAL_TRANSPORT_CONFIG_LOG_ENABLED
#define NRF_LOG_LEVEL SER_HAL_TRANSPORT_CONFIG_LOG_LEVEL
#define NRF_LOG_INFO_COLOR SER_HAL_TRANSPORT_CONFIG_INFO_COLOR
#define NRF_LOG_DEBUG_COLOR SER_HAL_TRANSPORT_CONFIG_DEBUG_COLOR
#else //SER_HAL_TRANSPORT_CONFIG_LOG_ENABLED
#define NRF_LOG_LEVEL 0
#endif //SER_HAL_TRANSPORT_CONFIG_LOG_ENABLED
#include "nrf_log.h"
NRF_LOG_MODULE_REGISTER();

/**
* @brief States of the RX state machine.
Expand Down Expand Up @@ -363,7 +365,7 @@ void ser_hal_transport_close(void)
uint32_t ser_hal_transport_rx_pkt_free(uint8_t * p_buffer)
{

NRF_LOG_INFO("rx pkt free:%d", p_buffer);
NRF_LOG_INFO("rx pkt free:%p", p_buffer);
uint32_t err_code = NRF_SUCCESS;

ser_phy_interrupts_disable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,16 @@
#include "app_util.h"
#include "app_util_platform.h"
#include "nrf_error.h"
#include "sdk_config.h"

//#define BLE_DBGPRT_ENABLE
#ifdef BLE_DBGPRT_ENABLE
#include <stdio.h>
#define NRF_LOG_DEBUG printf
#define NRF_LOG_MODULE_NAME ser_phy_uart
#if SER_PHY_UART_CONFIG_LOG_ENABLED
#define NRF_LOG_LEVEL SER_PHY_UART_CONFIG_LOG_LEVEL
#else
#define NRF_LOG_DEBUG(...)
#endif
#define NRF_LOG_LEVEL 0
#endif
#include "nrf_log.h"
NRF_LOG_MODULE_REGISTER();

#define BLE_UART_FILE "/dev/ttyS2"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,17 @@
#include "app_error.h"
#include "nrf_strerror.h"

//#define BLE_DBGPRT_ENABLE
#ifdef BLE_DBGPRT_ENABLE
#include <stdio.h>
#define NRF_LOG_ERROR printf
#define NRF_LOG_DEBUG printf

#define NRF_LOG_MODULE_NAME nrf_sdh_ble
#if NRF_SDH_BLE_LOG_ENABLED
#define NRF_LOG_LEVEL NRF_SDH_BLE_LOG_LEVEL
#define NRF_LOG_INFO_COLOR NRF_SDH_BLE_INFO_COLOR
#define NRF_LOG_DEBUG_COLOR NRF_SDH_BLE_DEBUG_COLOR
#else
#define NRF_LOG_ERROR(...)
#define NRF_LOG_DEBUG(...)
#endif
#define NRF_LOG_LEVEL 0
#endif // NRF_SDH_BLE_LOG_ENABLED
#include "nrf_log.h"
NRF_LOG_MODULE_REGISTER();

#ifndef NOT_USE_NRF_SECTION
// Create section set "sdh_ble_observers".
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,60 @@
#define SER_HAL_TRANSPORT_CONFIG_DEBUG_COLOR 0
#endif

//==========================================================
// <e> SER_SD_TRANSPORT_CONFIG_LOG_ENABLED - Enables logging in the module.
//==========================================================
#ifndef SER_SD_TRANSPORT_CONFIG_LOG_ENABLED
#define SER_SD_TRANSPORT_CONFIG_LOG_ENABLED 0
#endif
// <o> SER_SD_TRANSPORT_CONFIG_LOG_LEVEL - Default Severity level

// <0=> Off
// <1=> Error
// <2=> Warning
// <3=> Info
// <4=> Debug

#ifndef SER_SD_TRANSPORT_CONFIG_LOG_LEVEL
#define SER_SD_TRANSPORT_CONFIG_LOG_LEVEL 3
#endif

//==========================================================
// <e> SER_SD_HANDLER_CONFIG_LOG_ENABLED - Enables logging in the module.
//==========================================================
#ifndef SER_SD_HANDLER_CONFIG_LOG_ENABLED
#define SER_SD_HANDLER_CONFIG_LOG_ENABLED 0
#endif
// <o> SER_SD_HANDLER_CONFIG_LOG_LEVEL - Default Severity level

// <0=> Off
// <1=> Error
// <2=> Warning
// <3=> Info
// <4=> Debug

#ifndef SER_SD_HANDLER_CONFIG_LOG_LEVEL
#define SER_SD_HANDLER_CONFIG_LOG_LEVEL 3
#endif

//==========================================================
// <e> SER_SD_HANDLER_CONFIG_LOG_ENABLED - Enables logging in the module.
//==========================================================
#ifndef SER_PHY_UART_CONFIG_LOG_ENABLED
#define SER_PHY_UART_CONFIG_LOG_ENABLED 0
#endif
// <o> SER_PHY_UART_CONFIG_LOG_LEVEL - Default Severity level

// <0=> Off
// <1=> Error
// <2=> Warning
// <3=> Info
// <4=> Debug

#ifndef SER_PHY_UART_CONFIG_LOG_LEVEL
#define SER_PHY_UART_CONFIG_LOG_LEVEL 3
#endif

// </h>
//==========================================================

Expand Down

0 comments on commit 5e1c599

Please sign in to comment.