Skip to content

Commit

Permalink
Removed macro in common code and moved the logging code to uartLogWri…
Browse files Browse the repository at this point in the history
…te API.
  • Loading branch information
arun-silabs committed Feb 26, 2024
1 parent b509597 commit 7e2042f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
25 changes: 25 additions & 0 deletions examples/platform/silabs/SiWx917/uart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ extern "C" {

#define USART_BAUDRATE 115200 // Baud rate <9600-7372800>
#define UART_CONSOLE_ERR -1 // Negative value in case of UART Console action failed. Triggers a failure for PW_RPC
#define UART_CONSOLE_SUCCESS 1 // Positive value if UART Console action is success.

sl_usart_handle_t usart_handle;

Expand Down Expand Up @@ -118,6 +119,30 @@ int16_t uartConsoleWrite(const char * Buf, uint16_t BufLength)
return BufLength;
}

/**
* @brief Write Logs to the Uart. Appends a return character
*
* @param log pointer to the logs
* @param length number of bytes to write
* @return int16_t Amount of bytes written or ERROR (-1)
*/
int16_t uartLogWrite(const char * log, uint16_t length)
{
if (log == NULL || length < 1)
{
return UART_CONSOLE_ERR;
}
for (/* Empty */; length != 0; --length)
{
Board_UARTPutChar(*log++);
}
// To print next log in new line with proper formatting
Board_UARTPutChar('\r');
Board_UARTPutChar('\n');

return UART_CONSOLE_SUCCESS;
}

/*
* @brief Read the data available from the console Uart
* @param Buffer for the data to be read, number bytes to read.
Expand Down
13 changes: 0 additions & 13 deletions src/platform/silabs/Logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@
#endif

#if SILABS_LOG_OUT_UART
#if SIWX_917
#include "rsi_debug.h"
#endif // SIWX_917
#include "uart.h"
#endif

Expand Down Expand Up @@ -138,17 +135,7 @@ static void PrintLog(const char * msg)
sz = strlen(msg);

#if SILABS_LOG_OUT_UART
#if SIWX_917
for (/* Empty */; sz != 0; --sz)
{
Board_UARTPutChar(*msg++);
}
// To print next log in new line with proper formatting
Board_UARTPutChar('\r');
Board_UARTPutChar('\n');
#else
uartLogWrite(msg, sz);
#endif // SIWX_917
#elif PW_RPC_ENABLED
PigweedLogger::putString(msg, sz);
#else
Expand Down

0 comments on commit 7e2042f

Please sign in to comment.