当前位置:网站首页>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.
边栏推荐
- MIT CMS. 300 session 8 – immersion / immersion
- Bill Gates posted his 18-year-old resume and expected an annual salary of $12000 48 years ago
- Can CDC pull the Oracle table in full
- Coreldraw2022 new version new function introduction cdr2022
- acwing周赛58
- Bubble sort
- Platformio create libopencm3 + FreeRTOS project
- Raspberry pie 3.5-inch white screen display connection
- View workflow
- 麥斯克電子IPO被終止:曾擬募資8億 河南資產是股東
猜你喜欢
随机推荐
Quatre méthodes de redis pour dépanner les grandes clés sont nécessaires pour optimiser
内核判断i2c地址上是否挂载外设
Sentinel sliding window traffic statistics
ETCD数据库源码分析——etcdserver bootstrap初始化存储
The most detailed and comprehensive update content and all functions of guitar pro 8.0
Postman关联
[数学建模] 微分方程--捕鱼业的持续发展
How to estimate the population with samples? (mean, variance, standard deviation)
Weng Kai C language third week 3.1 punch in
How to realize automatic playback of H5 video
Basic explanation of turtle module - draw curve
Upload nestjs configuration files, configure the use of middleware and pipelines
Bill Gates posted his 18-year-old resume and expected an annual salary of $12000 48 years ago
The kernel determines whether peripherals are attached to the I2C address
Can CDC pull the Oracle table in full
Leetcode 186 Flip the word II in the string (2022.07.05)
Visio draws Tai Chi
Delete subsequence < daily question >
RTP gb28181 document testing tool
Vulnerability discovery - vulnerability probe type utilization and repair of web applications









