1 /* 2 * Copyright (c) 2006-2018, RT-Thread Development Team 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 * 6 * Change Logs: 7 * Date Author Notes 8 * 2013-06-26 Grissiom the first version 9 */ 10 11 #include <rtthread.h> 12 #include <rtdevice.h> 13 #include <log_trace.h> 14 15 #define PIPE_SZ 2048 16 #define PIPE_NAME "memlog" 17 18 static rt_pipe_t *_log_pipe = NULL; 19 static rt_uint8_t outbuf[1024]; memlog_flush(void)20void memlog_flush(void) 21 { 22 rt_size_t readsz; 23 rt_device_t console; 24 25 console = rt_console_get_device(); 26 if (!console) return; 27 28 readsz = rt_device_read((rt_device_t)&(_log_pipe->parent), 0, outbuf, sizeof(outbuf)); 29 if (readsz) 30 rt_device_write(console, 0, outbuf, readsz); 31 } 32 memlog_init(void)33int memlog_init(void) 34 { 35 _log_pipe = rt_pipe_create(PIPE_NAME, PIPE_SZ); 36 if (_log_pipe == RT_NULL) 37 { 38 rt_kprintf("init pipe device failed.\n"); 39 return -1; 40 } 41 42 log_trace_set_device(PIPE_NAME); 43 rt_thread_idle_sethook(memlog_flush); 44 45 return 0; 46 } 47 INIT_APP_EXPORT(memlog_init); 48