diff --git a/applications/VK_Log.c b/applications/VK_Log.c new file mode 100644 index 0000000..482a103 --- /dev/null +++ b/applications/VK_Log.c @@ -0,0 +1,29 @@ +#include "VK_Log.h" +#include + +static struct ulog_backend dev_backend; + +static rt_device_t log_dev = RT_NULL; + + +static void dev_log_output(struct ulog_backend *backend, + rt_uint32_t level, + const char *tag, + rt_bool_t is_raw, + const char *log, + size_t len) +{ + if (log_dev != RT_NULL && len > 0) + { + rt_device_write(log_dev, 0, log, len); + } +} + + +int dev_log_backend_init(rt_device_t dev){ + log_dev = dev; + rt_memset(&dev_backend, 0 , sizeof(dev_backend)); + dev_backend.output = dev_log_output; + + return ulog_backend_register(&dev_backend, "uart3", RT_FALSE); +} \ No newline at end of file diff --git a/applications/VK_Log.h b/applications/VK_Log.h new file mode 100644 index 0000000..4bc536a --- /dev/null +++ b/applications/VK_Log.h @@ -0,0 +1,17 @@ +#pragma once + +#include "rtthread.h" +#include "rtdevice.h" + +#ifdef __cplusplus +extern "C"{ +#endif + + +int dev_log_backend_init(rt_device_t dev); + + + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/applications/main.c b/applications/main.c index dc792fb..a4e785f 100644 --- a/applications/main.c +++ b/applications/main.c @@ -19,6 +19,7 @@ #include "VK_Client.h" #include "VK_Com.h" #include "drv_ec800k.h" +#include "VK_Log.h" static rt_device_t u2, u3; @@ -43,7 +44,9 @@ int main(void) { RT_DEVICE_FLAG_RX_NON_BLOCKING | RT_DEVICE_FLAG_TX_BLOCKING); BSP_LET_Register_Com(u2); - + + //初始化ulog端口 + dev_log_backend_init(u3); /* 创建任务2和任务3,分别从U2和U3收发数据 */ lte_dev.tid1 = rt_thread_create("lte", task_let_entry, RT_NULL, 2048, 10, 5);