当前位置:网站首页>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.
边栏推荐
- CADD course learning (8) -- virtual screening of Compound Library
- CADD course learning (7) -- Simulation of target and small molecule interaction (flexible docking autodock)
- Embedded development program framework
- DMA use of stm32
- Complete list of common functions of turtle module
- Sentinel sliding window traffic statistics
- Uva1592 Database
- 8. Static file
- 团队协作出了问题,项目经理怎么办?
- 也算是學習中的小總結
猜你喜欢
Vulnerability discovery - vulnerability probe type utilization and repair of web applications
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
行业专网对比公网,优势在哪儿?能满足什么特定要求?
Unity screen coordinates ugui coordinates world coordinates conversion between three coordinate systems
Redis —— Redis In Action —— Redis 实战—— 实战篇一 —— 基于 Redis 的短信登录功能 —— Redis + Token 的共享 session 应用— 有代码
Digital children < daily question> (Digital DP)
Flody的应用
Postman关联
Sqlserver query results are not displayed in tabular form. How to modify them
[数学建模] 微分方程--捕鱼业的持续发展
随机推荐
It is also a small summary in learning
Postman assertion
View workflow
Complete list of common functions of turtle module
Selection sort
A blog to achieve embedded entry
集合详解之 Map + 面试题
Finance online homework
Upload nestjs configuration files, configure the use of middleware and pipelines
2021 RoboCom 世界机器人开发者大赛-本科组(复赛)
yolov5 tensorrt加速
[noip2009 popularization group] score line delimitation
关于es8316的音频爆破音的解决
Extension of graph theory
MIT CMS. 300 session 8 – immersion / immersion
NPM command -- install dependent packages -- Usage / explanation
[Yu Yue education] reference materials of complex variable function and integral transformation of Northwestern Polytechnic University
Summary of redis AOF and RDB knowledge points
Quatre méthodes de redis pour dépanner les grandes clés sont nécessaires pour optimiser
Postman管理测试用例