This video presentation is the tenth installment of the Essentials of MQX RTOS Application Development training course. In this session, you will be introduced to kernel logging.
This training was created by Embedded Access Inc., a Freescale sponsored training provider and proven partner.
|Session 10 Course Line||Lab Outline|
First, watch the video for Session 10: Kernel Logging.
Then, follow through with the interactive lab assignment below.
SESSION 10: LAB ASSIGNMENT
Logging can be an excellent debugging aid to you, but to be effective you have to be clear on what you are looking for and set up logging accordingly. Knowing what to log is something that comes with experience and familiarity with the features at your disposal. This lab is intended to help you with the familiarization aspect so you can leverage your knowledge when you get to the debug phase of your next project.
The objective of this lab is to learn about the kernel logging facility by enabling kernel logging in the application and experimenting with the various modes of operation.This objective will be accomplished by:
- Enabling kernel logging in user_config.h
- Rebuilding the PSP and BSP
- Creating a kernel log
- Enabling the kernel log
- Using task aware debug to examine the kernel log
- Modifying logging parameters to filter by task
- Modifying logging parameters to Filter by function group (timers & events)
New functions/ structures you will use:
_klog_create, _klog_control, _klog_enable_logging_task. _task_get_id
INITIALIZING THE LOG
- Since we are going to be use kernel logging for this lab you'll need to include the klog.h header file and the best place to add this is in main.h.
- The first thing we need to do is create the kernel log with a buffer of 2048 bytes using the _klog_create() function. The Health Task is responsible for monitoring the health of the system so it makes sense that this is done here. Since you only have to create the log once of course this call should be done in the initialization section of the Health Task. For now we can define the logging to stop when the buffer gets full.
- Once the log has been created you need to enable kernel logging with the _klog_control() function. To start with, turn on the logging for context switches, all interrupts, the system clock interrupt, and two functions - Time Functions and Interrupt Functions.
- Finally, we need to check if Kernel Logging is enabled in user_config.h for the BSP. In the BSP project you will find user_config.h in the User_Config folder. If you do not see a define for MQX_KERNEL_LOGGING you can add it by right clicking on user_config.h on the left in the Project View window, selecting 'Open With' and selecting 'C/C++ Editor'. You can add into this file:
#define MQX_KERNEL_LOGGING 1
TESTING OUR LOGGING
- If you made a change to user_config.h you'll have to compile both the BSP and PSP before compiling the application.
- Run your application and ensure that it is running okay by confirming that you're getting print messages to the console. Pause the application (as opposed to killing it) and select the Kernel Logging window in the Task Aware Debugging pull down menu (MQX > Kernel Logging).
- Scroll through the log file to confirm that entries for all of the enabled types of logs are observed: Context Switches, Timers, and interrupts.
CHANGING THE LOGGING FILTERS TO ELIMINATE THE INTERRUPT LOGS
- You may have noticed that the number of logs from interrupts, in particular system tick interrupts, makes it difficult to find the other logs. If you are debugging an issue this makes it hard to find the data you are looking for and it also fills the log buffer up quite quickly. It would then be a good idea to filter out all logs from interrupts. You can do this by deleting the KLOG_INTERRUPTS_ENABLED and KLOG_SYSTEM_CLOCK_INT_ENABLED from the _klog_control() function call.
- Compile your application, run it for a few seconds, and then pause it. Observe the kernel log window again to ensure that the interrupt logs are not present.
FILTER THE LOG BY TASK
- Now we want to filter out the logs from tasks except the logs from the Health Task. To do this the _klog_control() function call needs to be updated to enable the task qualified filter. This means that only tasks that have enabled logging specifically in the task code will have log entries related to it logged. Don't forget that any task can fetch their task id number using the _task_get_id() function.
- Compile your application, run it for a few seconds, and then pause it. Observe the kernel log window. You should see context switches to the Health Task being logged but nothing else.
ADDING MESSAGE FUNCTIONS TO THE FILTER
- The Health Task is sending messages but in order to see logs related to the sending of messages you would need to add Message Functions to the list of functions being logged. As you guessed by now this is accomplished with an update to the _klog_control() function call.
- Again observe the kernel logging window after the application has been compiled and run for a few seconds. You should see a number of logs from message functions.
LOGGING JUST TIME AND EVENT FUNCTIONS
- To change things up we'll look at just the Time and Event Functions. You can remove the logging of Message functions and you can disable the task qualified logging from the Health Task.
- Once this has been tried you should now see a number of entries in the log from lwevents and lwtimers.
Need more help? The full source code for this lab can be found in the 'Lab Source Code' folder here.