ruuvi.drivers.c  ${PROJECT_VERSION}
Drivers for external sensors and peripherals on embedded systems.
ruuvi_nrf5_sdk15_log.c
Go to the documentation of this file.
1 
17 #include "ruuvi_interface_log.h"
18 #if RUUVI_NRF5_SDK15_LOG_ENABLED
19 #include "ruuvi_driver_error.h"
20 #include "ruuvi_interface_yield.h"
21 #include <stdarg.h>
22 
23 #define NRF_LOG_MODULE_NAME ruuvi_log
24 #define NRF_LOG_LEVEL 3
25 #include "nrf_log.h"
26 #include "nrf_log_default_backends.h"
27 #include "nrf_log_ctrl.h"
29 
30 static ri_log_severity_t m_log_level;
31 rd_status_t ri_log_init (const ri_log_severity_t min_severity)
32 {
33  rd_status_t err_code = RD_SUCCESS;
34 
35  if (RI_LOG_LEVEL_NONE == m_log_level)
36  {
37  m_log_level = min_severity;
38  NRF_LOG_INIT (NULL);
39  NRF_LOG_DEFAULT_BACKENDS_INIT();
40  }
41  else if (RI_LOG_LEVEL_NONE != min_severity)
42  {
43  // Error if already initialized.
44  err_code |= RD_ERROR_INVALID_STATE;
45  }
46  else
47  {
48  // No action needed if initialized as NONE.
49  }
50 
51  return err_code;
52 }
53 
55 {
56  NRF_LOG_FLUSH();
57  // Use microsecond delay to avoid getting stuck in timer loop if
58  // logs are flushed in interrupt context.
59  ri_delay_us (5000);
60  return RD_SUCCESS;
61 }
62 
63 void ri_log (const ri_log_severity_t severity,
64  const char * const message)
65 {
66  if (NULL == message)
67  {
69  return;
70  }
71 
72  if (m_log_level >= severity)
73  {
74  NRF_LOG_INTERNAL_RAW_INFO ("%s", message);
75  }
76 }
77 #endif
#define RD_ERROR_NULL
Null Pointer.
uint32_t rd_status_t
bitfield for representing errors
#define RD_ERROR_CHECK(error, mask)
Shorthand macro for calling the rd_error_check with current file & line.
#define RD_SUCCESS
Internal Error.
#define RD_ERROR_INVALID_STATE
Invalid state, operation disallowed in this state.
rd_status_t ri_log_init(const ri_log_severity_t min_severity)
Runs initialization code for the logging backend and sets the severity level.
ri_log_severity_t
Enable implementation selected by application.
void ri_log(const ri_log_severity_t severity, const char *const message)
Queues messages into log.
rd_status_t ri_log_flush(void)
Blocks until remaining log messages are sent out.
@ RI_LOG_LEVEL_NONE
NRF_LOG_MODULE_REGISTER()
Header to enable and disable module compilation.
Ruuvi error codes and error check function.
rd_status_t ri_delay_us(uint32_t time)
Delay a given number of microseconds.