当前位置:网站首页>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.
边栏推荐
- English Vocabulary - life scene memory method
- 内核判断i2c地址上是否挂载外设
- The underlying structure of five data types in redis
- Etcd database source code analysis -- etcdserver bootstrap initialization storage
- Raspberry pie 3.5-inch white screen display connection
- Visio draws Tai Chi
- Application of Flody
- Yolov5 tensorrt acceleration
- Sqlserver query results are not displayed in tabular form. How to modify them
- Postman manage test cases
猜你喜欢
Redis - redis in action - redis actual combat - actual combat Chapter 1 - SMS login function based on redis - redis + token shared session application - with code
The implementation of the maize negotiable digital warehouse receipt standard will speed up the asset digitization process of the industry
Etcd database source code analysis -- etcdserver bootstrap initialization storage
canal同步mysql数据变化到kafka(centos部署)
[Chongqing Guangdong education] engineering fluid mechanics reference materials of southwestjiaotonguniversity
yolov5 tensorrt加速
[mathematical modeling] differential equation -- sustainable development of fishing industry
Basic explanation of turtle module - draw curve
11. Intranet penetration and automatic refresh
Orm-f & Q object
随机推荐
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
Is the mode of education together - on campus + off campus reliable
SharedPreferences source code analysis
After learning classes and objects, I wrote a date class
The IPO of mesk Electronics was terminated: Henan assets, which was once intended to raise 800 million yuan, was a shareholder
View workflow
How to estimate the population with samples? (mean, variance, standard deviation)
Sqlserver query results are not displayed in tabular form. How to modify them
Yolov5 tensorrt acceleration
Use sentinel to interface locally
Postman断言
Can CDC pull the Oracle table in full
Unity screen coordinates ugui coordinates world coordinates conversion between three coordinate systems
Biscuits (examination version)
Delete subsequence < daily question >
Bubble sort
[mathematical modeling] differential equation -- sustainable development of fishing industry
[Chongqing Guangdong education] Suzhou University English film and Television Appreciation reference materials
2021robocom robot developer competition (Preliminary)
Distributed transaction solution