mirror of
https://github.com/espressif/openthread.git
synced 2026-08-01 08:37:47 +00:00
[samr21] Implement otPlatLog for SAMR21 XPLAINED PRO board (#3491)
Use EDBG DGI SPI interface to put log. Signed-off-by: Oleksandr Grytsov <[email protected]>
This commit is contained in:
committed by
Jonathan Hui
parent
513b0f8b8d
commit
e7a6bde56d
@@ -33,16 +33,101 @@
|
||||
*/
|
||||
|
||||
#include <openthread-core-config.h>
|
||||
#include <utils/code_utils.h>
|
||||
#include <openthread/config.h>
|
||||
#include <openthread/platform/logging.h>
|
||||
#include <openthread/platform/toolchain.h>
|
||||
|
||||
#if (OPENTHREAD_CONFIG_LOG_OUTPUT == OPENTHREAD_CONFIG_LOG_OUTPUT_PLATFORM_DEFINED) || \
|
||||
(OPENTHREAD_CONFIG_LOG_OUTPUT == OPENTHREAD_CONFIG_LOG_OUTPUT_NCP_SPINEL)
|
||||
|
||||
#if BOARD == SAMR21_XPLAINED_PRO
|
||||
|
||||
#include "board.h"
|
||||
#include "spi.h"
|
||||
|
||||
#define LOG_PARSE_BUFFER_SIZE 128
|
||||
#define LOG_TIMESTAMP_ENABLE 1
|
||||
|
||||
struct spi_module sMaster;
|
||||
struct spi_slave_inst sSlave;
|
||||
|
||||
char sLogString[LOG_PARSE_BUFFER_SIZE + 1];
|
||||
|
||||
static void logOutput(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, va_list ap)
|
||||
{
|
||||
int len = 0;
|
||||
|
||||
len = vsnprintf(sLogString, LOG_PARSE_BUFFER_SIZE, aFormat, ap);
|
||||
|
||||
otEXPECT(len >= 0);
|
||||
|
||||
exit:
|
||||
|
||||
if (len >= LOG_PARSE_BUFFER_SIZE)
|
||||
{
|
||||
len = LOG_PARSE_BUFFER_SIZE - 1;
|
||||
}
|
||||
|
||||
sLogString[len++] = '\n';
|
||||
|
||||
spi_select_slave(&sMaster, &sSlave, true);
|
||||
|
||||
spi_write_buffer_wait(&sMaster, (uint8_t *)sLogString, len);
|
||||
|
||||
spi_select_slave(&sMaster, &sSlave, false);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void samr21LogInit(void)
|
||||
{
|
||||
#if BOARD == SAMR21_XPLAINED_PRO
|
||||
|
||||
struct spi_slave_inst_config slaveConfig;
|
||||
struct spi_config config;
|
||||
|
||||
spi_slave_inst_get_config_defaults(&slaveConfig);
|
||||
|
||||
slaveConfig.ss_pin = EDBG_SPI_SLAVE_SELECT_PIN;
|
||||
|
||||
spi_attach_slave(&sSlave, &slaveConfig);
|
||||
|
||||
spi_get_config_defaults(&config);
|
||||
|
||||
config.mux_setting = EDBG_SPI_SERCOM_MUX_SETTING;
|
||||
config.mode_specific.master.baudrate = 8000000UL;
|
||||
config.pinmux_pad0 = EDBG_SPI_SERCOM_PINMUX_PAD0;
|
||||
config.pinmux_pad1 = EDBG_SPI_SERCOM_PINMUX_PAD1;
|
||||
config.pinmux_pad2 = EDBG_SPI_SERCOM_PINMUX_PAD2;
|
||||
config.pinmux_pad3 = EDBG_SPI_SERCOM_PINMUX_PAD3;
|
||||
|
||||
spi_init(&sMaster, EDBG_SPI_MODULE, &config);
|
||||
spi_enable(&sMaster);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
OT_TOOL_WEAK void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...)
|
||||
{
|
||||
#if BOARD == SAMR21_XPLAINED_PRO
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, aFormat);
|
||||
|
||||
logOutput(aLogLevel, aLogRegion, aFormat, ap);
|
||||
|
||||
va_end(ap);
|
||||
|
||||
#else
|
||||
|
||||
OT_UNUSED_VARIABLE(aLogLevel);
|
||||
OT_UNUSED_VARIABLE(aLogRegion);
|
||||
OT_UNUSED_VARIABLE(aFormat);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -100,4 +100,10 @@ void samr21UartProcess(void);
|
||||
*/
|
||||
void samr21GetIeeeEui64(otInstance *aInstance, uint8_t *aIeeeEui64);
|
||||
|
||||
#endif // PLATFORM_SAMR21_H_
|
||||
/**
|
||||
* Initialization of Logger driver.
|
||||
*
|
||||
*/
|
||||
void samr21LogInit(void);
|
||||
|
||||
#endif // PLATFORM_SAMR21_H_
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
|
||||
#include "asf.h"
|
||||
|
||||
#include <openthread-core-config.h>
|
||||
#include <openthread/platform/radio.h>
|
||||
|
||||
#include "openthread-system.h"
|
||||
@@ -173,6 +174,10 @@ void otSysInit(int argc, char *argv[])
|
||||
getKitData();
|
||||
#endif
|
||||
|
||||
#if (OPENTHREAD_CONFIG_LOG_OUTPUT == OPENTHREAD_CONFIG_LOG_OUTPUT_PLATFORM_DEFINED) || \
|
||||
(OPENTHREAD_CONFIG_LOG_OUTPUT == OPENTHREAD_CONFIG_LOG_OUTPUT_NCP_SPINEL)
|
||||
samr21LogInit();
|
||||
#endif
|
||||
samr21AlarmInit();
|
||||
samr21RadioInit();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user