当前位置:网站首页>RT thread analysis log system RT_ Kprintf analysis
RT thread analysis log system RT_ Kprintf analysis
2022-07-06 04:49:00 【Just think Quiet】
Catalog
5 analysis rt_kprintf() function
1 Preface
In addition to providing interfaces rt_kprintf() Used to output print information , It also supports a complete set of logging components ulog. There is overlap between the two in implementation , All used console modular ; Other functions are independent of each other , Only by studying its implementation mechanism , In order to better use or transplant the system .
2 rt_kprintf()
- The kernel provides an interface for outputting log information
- By default console Device output printing , The device name can be modified in the configuration options
- If not registered console equipment ,rt_kprintf Will eventually call rt_hw_console_output() Output printing ; This function is for users to realize functions
3 configuration option
Use this interface , The following configuration is required before compilation
- It mainly determines the following two parameters
// Print cache length #define RT_CONSOLEBUF_SIZE 256 // Console device name #define RT_CONSOLE_DEVICE_NAME "uart2"
4 console equipment
rt_kprintf() System default use console The device outputs print information , All you need to know is how to create and use the kernel sonsole equipment
4.1 Equipment declaration
The kernel uses global variables _console_device To maintain the console equipment
static rt_device_t _console_device = RT_NULL;
4.2 Device creation
- In the startup process , The kernel calls rt_hw_usart_init() complete uart Device registration ;
- And then call rt_console_set_device(RT_CONSOLE_DEVICE_NAME), Go to the registered device to find out whether there is a device with the name RT_CONSOLE_DEVICE_NAME The equipment , If so, regard the device as _console_device
4.3 obtain _console_device
- External unified call rt_console_get_device() To get _console_device
rt_device_t rt_console_get_device(void)
{
return _console_device;
}
5 analysis rt_kprintf() function
RT_WEAK void rt_kprintf(const char *fmt, ...)
{
//1 Cache declaration , Note that static local variables , Maximum length is RT_CONSOLEBUF_SIZE
static char rt_log_buf[RT_CONSOLEBUF_SIZE];
va_start(args, fmt);
//2 Sort out the print log and save it to rt_log_buf, And return the actual output length
length = rt_vsnprintf(rt_log_buf, sizeof(rt_log_buf) - 1, fmt, args);
//3 Limit length
if (length > RT_CONSOLEBUF_SIZE - 1)
length = RT_CONSOLEBUF_SIZE - 1;
if (_console_device == RT_NULL)
{
//4 If the kernel is not registered console equipment , execute rt_hw_console_output() Complete output .
rt_hw_console_output(rt_log_buf);
}
else
{
//5 Use it directly console Device output information
rt_device_write(_console_device, 0, rt_log_buf, length);
}
va_end(args);
}
6 rt_kprintf Redirect
- You can use the reserved rt_hw_console_output() Interface .
- Do not register console equipment , in rt_hw_console_output() Complete redirection
- Or will console Register as any device , Like Ethernet ,CAN,USB etc.
边栏推荐
- Dry goods collection | Vulkan game engine video tutorial
- Nestjs配置文件上传, 配置中间件以及管道的使用
- Postman pre script - global variables and environment variables
- 11. Intranet penetration and automatic refresh
- C'est un petit résumé de l'étude.
- [buuctf.reverse] 159_ [watevrCTF 2019]Watshell
- I'd like to ask about the current MySQL CDC design. In the full volume phase, if a chunk's binlog backfill phase,
- win10电脑系统里的视频不显示缩略图
- 2021RoboCom机器人开发者大赛(初赛)
- Tengine kernel parameters
猜你喜欢
MPLS experiment
ISP learning (2)
View workflow
【LGR-109】洛谷 5 月月赛 II & Windy Round 6
你需要知道的 TCP 三次握手
Case of Jiecode empowerment: professional training, technical support, and multiple measures to promote graduates to build smart campus completion system
Redis - redis in action - redis actual combat - actual combat Chapter 1 - SMS login function based on redis - redis + token shared session application - with code
RTP gb28181 document testing tool
acwing周赛58
canal同步mysql数据变化到kafka(centos部署)
随机推荐
也算是学习中的小总结
The most detailed and comprehensive update content and all functions of guitar pro 8.0
Postman断言
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
MySQL reported an error datetime (0) null
MPLS experiment
Can CDC pull the Oracle table in full
DMA use of stm32
【LGR-109】洛谷 5 月月赛 II & Windy Round 6
Can Flink SQL read multiple topics at the same time. How to write in with
ue5 小知识 FreezeRendering 查看视锥内渲染的物体
[mathematical modeling] differential equation -- sustainable development of fishing industry
web工程导入了mysql驱动jar包却无法加载到驱动的问题
Extension of graph theory
CADD course learning (7) -- Simulation of target and small molecule interaction (flexible docking autodock)
图论的扩展
Crazy God said redis notes
Canal synchronizes MySQL data changes to Kafka (CentOS deployment)
Distributed transaction solution
The implementation of the maize negotiable digital warehouse receipt standard will speed up the asset digitization process of the industry