WE310F5  39.00.000
M2MB DEBUG

This section describes the M2MB APIs to perform various debug logging operations. More...

#define M2MB_DBG_EMERG(...)   m2mb_dbg_msg_log(M2MB_DBG_LOG_SEVERITY_EMERG, __func__, __LINE__, __VA_ARGS__)
 
#define M2MB_DBG_ALERT(...)   m2mb_dbg_msg_log(M2MB_DBG_LOG_SEVERITY_ALERT, __func__, __LINE__, __VA_ARGS__)
 
#define M2MB_DBG_CRIT(...)   m2mb_dbg_msg_log(M2MB_DBG_LOG_SEVERITY_CRIT, __func__, __LINE__, __VA_ARGS__)
 
#define M2MB_DBG_ERROR(...)   m2mb_dbg_msg_log(M2MB_DBG_LOG_SEVERITY_ERROR, __func__, __LINE__, __VA_ARGS__)
 
#define M2MB_DBG_WARN(...)   m2mb_dbg_msg_log(M2MB_DBG_LOG_SEVERITY_WARN, __func__, __LINE__, __VA_ARGS__)
 
#define M2MB_DBG_NOTICE(...)   m2mb_dbg_msg_log(M2MB_DBG_LOG_SEVERITY_NOTICE, __func__, __LINE__, __VA_ARGS__)
 
#define M2MB_DBG_INFO(...)   m2mb_dbg_msg_log(M2MB_DBG_LOG_SEVERITY_INFO, __func__, __LINE__, __VA_ARGS__)
 
#define M2MB_DBG_DEBUG(...)   m2mb_dbg_msg_log(M2MB_DBG_LOG_SEVERITY_DEBUG, __func__, __LINE__, __VA_ARGS__)
 
#define M2MB_FUNC_ENTRY
 
#define M2MB_FUNC_EXIT
 
#define M2MB_FUNC_EXIT_RC(x)
 
enum  M2MB_DBG_LOG_SEVERITY {
  M2MB_DBG_LOG_SEVERITY_INVALID = -1,
  M2MB_DBG_LOG_SEVERITY_LOGING_OFF = 0,
  M2MB_DBG_LOG_SEVERITY_EMERG,
  M2MB_DBG_LOG_SEVERITY_ALERT,
  M2MB_DBG_LOG_SEVERITY_CRIT,
  M2MB_DBG_LOG_SEVERITY_ERROR,
  M2MB_DBG_LOG_SEVERITY_WARN,
  M2MB_DBG_LOG_SEVERITY_NOTICE,
  M2MB_DBG_LOG_SEVERITY_INFO,
  M2MB_DBG_LOG_SEVERITY_DEBUG
}
 M2MB_DBG_LOG_SEVERITY defines different debug category. More...
 
typedef enum M2MB_DBG_LOG_SEVERITY M2MB_DBG_LOG_SEVERITY_T
 M2MB_DBG_LOG_SEVERITY defines different debug category. More...
 
typedef INT32(* M2MB_DBG_CMD_CB_T) (VOID *userCtx, UINT32 len, UINT8 *cmd)
 M2MB_DBG_CMD_CB_T defines the command handler to handle the received command. More...
 
typedef VOID(* M2MB_DBG_SEND_T) (VOID *userCtx, UINT32 len, UINT8 *data)
 M2MB_DBG_SEND_T defines the debug log send API the send the logs. More...
 
typedef VOID(* M2MB_DBG_RECV_PROC_DONE_T) (VOID *userCtx)
 M2MB_DBG_RECV_PROC_DONE_T defines the API to indicate the receive process is done. More...
 
typedef struct M2MB_DBG_CFG M2MB_DBG_CFG_T
 Debug module configuration context.
More...
 
INT32 m2mb_dbg_init (M2MB_DBG_CFG_T *pCfg, M2MB_UART_CONFIG_T *uart_cfg)
 m2mb_dbg_init is called to initialize the debug module. More...
 
INT32 m2mb_dbg_is_init (VOID)
 m2mb_dbg_is_init is called to check if dbg module is initialized. More...
 
INT32 m2mb_dbg_prepare_for_deepsleep (VOID)
 m2mb_dbg_prepare_for_deepsleep is called to make the dbg module ready for deepsleep. More...
 
INT32 m2mb_dbg_reinit (VOID)
 m2mb_dbg_reinit is called after coming out of deepsleep. More...
 
INT32 m2mb_dbg_msg_log (M2MB_DBG_LOG_SEVERITY_T severity, char const *sourceFilePath, UINT32 lineNumber, char *format,...)
 m2mb_dbg_msg_log is called to log debug information. More...
 
INT32 m2mb_dbg_consol_print (char *format,...)
 m2mb_dbg_consol_print is called to print to the console. More...
 
M2MB_STATUS_T m2mb_dbg_set_severity (M2MB_DBG_LOG_SEVERITY_T severityLevel)
 m2mb_dbg_set_severity is called to set the severity level to log. More...
 
M2MB_DBG_LOG_SEVERITY_T m2mb_dbg_get_severity (VOID)
 m2mb_dbg_get_severity is called to get the severity level. More...
 
void m2mb_data_tx_done_cb (UINT32 num_bytes, void *cb_data)
 m2mb_data_tx_done_cb is called to inform data transfer is complete. More...
 
void m2mb_data_rx_cb (UINT32 num_bytes, void *cb_data)
 m2mb_data_rx_cb is called to inform data received which needs to be processed for command input handlling. More...
 

Detailed Description

This section describes the M2MB APIs to perform various debug logging operations.

Debug module uses a UART port to send the debug information. The UART port to send can be configured by the user. The UART driver takes care of sending the debug log using DMA. Logs are stored in a circular buffer, while previous logs are being sent over UART.
Debug module creates a dbg thread of low priority which is used to trigger the log sending procedure once the previous log send procedure is over. Apart from logging feature, debug module provides API to send the information immediately over console and also receives command over UART, if CLI option is enabled during initialization procedure.

Macro Definition Documentation

◆ M2MB_DBG_ALERT

#define M2MB_DBG_ALERT (   ...)    m2mb_dbg_msg_log(M2MB_DBG_LOG_SEVERITY_ALERT, __func__, __LINE__, __VA_ARGS__)

Definition at line 79 of file m2mb_dbg.h.

◆ M2MB_DBG_CRIT

#define M2MB_DBG_CRIT (   ...)    m2mb_dbg_msg_log(M2MB_DBG_LOG_SEVERITY_CRIT, __func__, __LINE__, __VA_ARGS__)

Definition at line 83 of file m2mb_dbg.h.

◆ M2MB_DBG_DEBUG

#define M2MB_DBG_DEBUG (   ...)    m2mb_dbg_msg_log(M2MB_DBG_LOG_SEVERITY_DEBUG, __func__, __LINE__, __VA_ARGS__)

Definition at line 103 of file m2mb_dbg.h.

◆ M2MB_DBG_EMERG

#define M2MB_DBG_EMERG (   ...)    m2mb_dbg_msg_log(M2MB_DBG_LOG_SEVERITY_EMERG, __func__, __LINE__, __VA_ARGS__)

Definition at line 75 of file m2mb_dbg.h.

◆ M2MB_DBG_ERROR

#define M2MB_DBG_ERROR (   ...)    m2mb_dbg_msg_log(M2MB_DBG_LOG_SEVERITY_ERROR, __func__, __LINE__, __VA_ARGS__)

Definition at line 87 of file m2mb_dbg.h.

◆ M2MB_DBG_INFO

#define M2MB_DBG_INFO (   ...)    m2mb_dbg_msg_log(M2MB_DBG_LOG_SEVERITY_INFO, __func__, __LINE__, __VA_ARGS__)

Definition at line 99 of file m2mb_dbg.h.

◆ M2MB_DBG_NOTICE

#define M2MB_DBG_NOTICE (   ...)    m2mb_dbg_msg_log(M2MB_DBG_LOG_SEVERITY_NOTICE, __func__, __LINE__, __VA_ARGS__)

Definition at line 95 of file m2mb_dbg.h.

◆ M2MB_DBG_WARN

#define M2MB_DBG_WARN (   ...)    m2mb_dbg_msg_log(M2MB_DBG_LOG_SEVERITY_WARN, __func__, __LINE__, __VA_ARGS__)

Definition at line 91 of file m2mb_dbg.h.

◆ M2MB_FUNC_ENTRY

#define M2MB_FUNC_ENTRY
Value:
{\
M2MB_DBG_INFO(" FUNC_ENTRY \n"); \
}

Definition at line 106 of file m2mb_dbg.h.

◆ M2MB_FUNC_EXIT

#define M2MB_FUNC_EXIT
Value:
{\
M2MB_DBG_INFO(" FUNC_EXIT \n"); \
}

Definition at line 110 of file m2mb_dbg.h.

◆ M2MB_FUNC_EXIT_RC

#define M2MB_FUNC_EXIT_RC (   x)
Value:
{\
M2MB_DBG_INFO(" FUNC_EXIT : Return Code : %d \n", x); \
return x; \
}

Definition at line 114 of file m2mb_dbg.h.

Typedef Documentation

◆ M2MB_DBG_CFG_T

typedef struct M2MB_DBG_CFG M2MB_DBG_CFG_T

Debug module configuration context.

Structure to configure the module. This is used while initializing the module.

◆ M2MB_DBG_CMD_CB_T

typedef INT32(* M2MB_DBG_CMD_CB_T) (VOID *userCtx, UINT32 len, UINT8 *cmd)

M2MB_DBG_CMD_CB_T defines the command handler to handle the received command.

User has to implenment this API to handle the received command. If user sets enableCI during initialization, then to handle the command it should implement this callback.

This API is called from debug thread context.

Parameters
[in]userCtxuser context provided in cbCtx in M2MB_DBG_CFG_T while initializing the module.
[in]lenLength of data receiveid.
[in]lenPointer to the data

Definition at line 164 of file m2mb_dbg.h.

◆ M2MB_DBG_LOG_SEVERITY_T

M2MB_DBG_LOG_SEVERITY defines different debug category.

This enum is used to select various debug log severity levels.

◆ M2MB_DBG_RECV_PROC_DONE_T

typedef VOID(* M2MB_DBG_RECV_PROC_DONE_T) (VOID *userCtx)

M2MB_DBG_RECV_PROC_DONE_T defines the API to indicate the receive process is done.

User can implenment this API to to get indication on the data received is consumed when enableCI is set to TRUE during initialization. User calls the m2mb_data_rx_cb to indicate the debug module about data received. On m2mb_data_rx_cb API call the data is stored in debug module bufer and indicate the user (may be to free-up the memroy )by calling this API.

This API is called from debug thread context.

Parameters
[in]userCtxuser context provided in userCtx in M2MB_DBG_CFG_T while initializing the module.

Definition at line 205 of file m2mb_dbg.h.

◆ M2MB_DBG_SEND_T

typedef VOID(* M2MB_DBG_SEND_T) (VOID *userCtx, UINT32 len, UINT8 *data)

M2MB_DBG_SEND_T defines the debug log send API the send the logs.

User has to implenment this API to consume the debug logs if it dosn't want the debug module to initialize the UART module and send the logs over UART.

This API is called from debug thread context.

Parameters
[in]userCtxuser context provided in userCtx in M2MB_DBG_CFG_T while initializing the module.
[in]lenLength of data receiveid.
[in]lenPointer to the data

Definition at line 186 of file m2mb_dbg.h.

Enumeration Type Documentation

◆ M2MB_DBG_LOG_SEVERITY

M2MB_DBG_LOG_SEVERITY defines different debug category.

This enum is used to select various debug log severity levels.

Enumerator
M2MB_DBG_LOG_SEVERITY_INVALID 

Not valid level. Logging will be off

M2MB_DBG_LOG_SEVERITY_LOGING_OFF 

Set this to off logging

M2MB_DBG_LOG_SEVERITY_EMERG 

Severity Emergency. Highest severity level

M2MB_DBG_LOG_SEVERITY_ALERT 

Severity Alert

M2MB_DBG_LOG_SEVERITY_CRIT 

Severity Critical

M2MB_DBG_LOG_SEVERITY_ERROR 

Severity Error

M2MB_DBG_LOG_SEVERITY_WARN 

Severity warn

M2MB_DBG_LOG_SEVERITY_NOTICE 

Severity Notice

M2MB_DBG_LOG_SEVERITY_INFO 

Severity Info

M2MB_DBG_LOG_SEVERITY_DEBUG 

Severity Debug. Lowest severity level

Definition at line 128 of file m2mb_dbg.h.

Function Documentation

◆ m2mb_data_rx_cb()

void m2mb_data_rx_cb ( UINT32  num_bytes,
void *  cb_data 
)

m2mb_data_rx_cb is called to inform data received which needs to be processed for command input handlling.

m2mb_data_rx_cb is required to be called by user once data is received. This is required if user gives his API to handle the debug log in sendData function and ahs configured the enableCI in config parameter.

Parameters
[in]num_bytesBytes sent.
[in]cb_databuffer that is sent.
Returns
None.
Note
This is required if user gives his API to handle the debug log in sendData function and ahs configured the enableCI in config parameter.

◆ m2mb_data_tx_done_cb()

void m2mb_data_tx_done_cb ( UINT32  num_bytes,
void *  cb_data 
)

m2mb_data_tx_done_cb is called to inform data transfer is complete.

m2mb_data_tx_done_cb is required to be called by user once data transfer is complete. This is required if user gives API to handle the debug log in sendData function in config parameter.

Parameters
[in]num_bytesBytes sent.
[in]cb_databuffer that is sent.
Returns
None.
Note
This API has to be called if user gives his API to handle the debug log in sendData function in config parameter.

◆ m2mb_dbg_consol_print()

INT32 m2mb_dbg_consol_print ( char *  format,
  ... 
)

m2mb_dbg_consol_print is called to print to the console.

m2mb_dbg_consol_print prints to the console. The print is unformatted unlike the debug log.

Parameters
[in]formatFormat of the content to be sent over console.
Returns
Returns status.
Note
This API has to be called if the NTP is already initialized. INT32 m2mb_dbg_consol_print( char *format, ...);
char* str = "debug print";
m2mb_dbg_consol_print( "%s\r\n", str );

◆ m2mb_dbg_get_severity()

M2MB_DBG_LOG_SEVERITY_T m2mb_dbg_get_severity ( VOID  )

m2mb_dbg_get_severity is called to get the severity level.

m2mb_dbg_get_severity returns the current severity level set.

Returns
Returns M2MB_DBG_LOG_SEVERITY_T severity level.
Note
This API has can be called if debug module is already initialized.
M2MB_DBG_LOG_SEVERITY_T m2mb_dbg_get_severity( VOID );

◆ m2mb_dbg_init()

INT32 m2mb_dbg_init ( M2MB_DBG_CFG_T pCfg,
M2MB_UART_CONFIG_T uart_cfg 
)

m2mb_dbg_init is called to initialize the debug module.

m2mb_ntp_init initializes the NTP module.

Parameters
[in]pCfgDebug module configuration.
[in]uart_cfgUART port configuration.
Returns
Returns status.
Note
None. INT32 m2mb_dbg_init( M2MB_DBG_CFG_T *pCfg, M2MB_UART_CONFIG_T *uart_cfg );
M2MB_DBG_CFG_T cfg = {0};
cfg.bufferSize = 1024;
cfg.enableCI = FALSE;
cfg.sendData = NULL;//Or a valid function pointer to consume the debug log
cfg.recvDone = NULL;//Or a valid function pointer.
cfg.userCtx = NULL;//Or a valid user handle.
uart_cfg.baud_rate = 115200;
uart_cfg.enable_loopback = FALSE;
uart_cfg.enable_flow_ctrl = FALSE;
ret = m2mb_dbg_init( &cfg, &uart_cfg );

◆ m2mb_dbg_is_init()

INT32 m2mb_dbg_is_init ( VOID  )

m2mb_dbg_is_init is called to check if dbg module is initialized.

m2mb_dbg_is_init checks if the dbg module is initialized.

Returns
Returns 0 if initialized else -1.
Note
None INT32 m2mb_dbg_is_init( VOID );

◆ m2mb_dbg_msg_log()

INT32 m2mb_dbg_msg_log ( M2MB_DBG_LOG_SEVERITY_T  severity,
char const *  sourceFilePath,
UINT32  lineNumber,
char *  format,
  ... 
)

m2mb_dbg_msg_log is called to log debug information.

m2mb_dbg_msg_log logs the debug information. If there is no write process happening then it stores the information in a circular buffer to send it log information in first in first out basis.

Parameters
[in]severitySeverity of the message.
[in]sourceFilePathSource file path of the log.
[in]lineNumberLine number of the log.
[in]formatFormat of the message.
Returns
returns status.
Note

Example

char* fileName = "/abc.txt";
"File Opening done-%s", fileName);

◆ m2mb_dbg_prepare_for_deepsleep()

INT32 m2mb_dbg_prepare_for_deepsleep ( VOID  )

m2mb_dbg_prepare_for_deepsleep is called to make the dbg module ready for deepsleep.

m2mb_dbg_prepare_for_deepsleep makes the dbg module ready for deepsleep.

Returns
Returns status.
Note
None INT32 m2mb_dbg_prepare_for_deepsleep( VOID );

◆ m2mb_dbg_reinit()

INT32 m2mb_dbg_reinit ( VOID  )

m2mb_dbg_reinit is called after coming out of deepsleep.

m2mb_dbg_reinit reinitializes the dbg module after coming out of deepsleep.

Returns
Returns status.
Note
None INT32 m2mb_dbg_reinit( VOID );

◆ m2mb_dbg_set_severity()

M2MB_STATUS_T m2mb_dbg_set_severity ( M2MB_DBG_LOG_SEVERITY_T  severityLevel)

m2mb_dbg_set_severity is called to set the severity level to log.

m2mb_dbg_set_severity sets the severity level and logs only those severity level debug prints which are lower or equal to the value set.

Parameters
[in]severityLevelSeverity level to set.
Returns
Returns status.
Note
This API has can be called if debug module is already initialized. m2mb_dbg_set_severity( M2MB_DBG_LOG_SEVERITY_ERROR );