一、 介绍:
PS(protocol stack) Trace的方法,在KAL层有两种方法(提供两个Function)可以对protocol stack 进行Trace。
Trace Logging Architecture:
RS232
TST Service: TST module为Protocol Stack tasks提供的functions,如:
void kal_trace()
void kal_prompt_trace()
TST Task: TST main module, 把Trace信息传送到PC端。
KAL: Kernel adaptation layer,针对Protocol对OS做的封装层。
Logging Related Service: KAL层绑定的服务功能,帮助TST传输数据。
Task 1 Task 2.:Protocol stack的任务。
1. 方法1:
kal_prompt_trace,类似于C code中的printf功能。
定义:void kal_prompt_trace(module_type, kal_char *fmt, …);
module_type: module的ID号,stack_config.h中定义。
fmt: 要输出显示的字符串
2. 方法2:
kal_trace,和以上介绍的方法1不同,使用一个索引值来代替一个复杂的字符串,此功能使用更复杂。
定义:void kal_trace(trace_class_enum class, kal_uint32, kal_char *fmt, …);
class: the trace class of this trace;由编程员定义的,每个module都有15个类,
定义见kal_trace.h:
typedef enum
{
TRACE_FUNC,
TRACE_STATE,
TRACE_INFO,
TRACE_WARNING,
TRACE_ERROR,
TRACE_GROUP_1,
TRACE_GROUP_2,
TRACE_GROUP_3,
TRACE_GROUP_4,
TRACE_GROUP_5,
TRACE_GROUP_6,
TRACE_GROUP_7,
TRACE_GROUP_8,
TRACE_GROUP_9,
TRACE_GROUP_10
}trace_class_enum;
fmt: 和以上介绍的方法1不同,更复杂一些,在下面的例子中介绍。
注意:
1). 在要使用此function的C code中include kal_trace.h和stack_config.h;
2). These two functions are just used for task level. Drive level will has race
condition.
二、 如何添加新的Trace:
1. Add Traces by kal_prompt_trace:
如在ModuleàMOD_XXX的c文件àtest.c使用kal_prompt_trace:
Test.c 1 #include “kal_trace.h” 2 kal_int16 a,b; 3 4 . . 7 kal_prompt_trace(MOD_XXX, “this is a prompt trace testing a= b= ”, a, b); 8 9 |
Step 1: 以上Line 1à#include “kal_trace.h”
Step 2: 以上Line 7à kal_prompt_trace(MOD_XXX, “this is a prompt trace testing a=
b= ”, a, b);
Step 3: rebuild Test.c, Catcher database无需更改。
2. Add Traces by kal_trace:
这个使用比较复杂,但功能更强,可以在目标板系统上保存code size和communication bandwidth。使用的步骤参见同名pdf文档Page9~Page11。
2.1 Add Traces to a New Module:
Step 1: Write a xxx_trc.h in the following format for new module.
xxx_trc.h 1 #ifndef _xxx_TRACE_H 2 #define _xxx_TRACE_H 3 4 #ifndef GEN_FOR_PC 5 #ifndef _STACK_CONFIG_H 6 #error “stack_config.h should be included before tst_config.h” 7 #endif 8 9 #else 10 #include “kal_trace.h” 11 #endif /*GEN_FOR_PC*/ 12 13 14 #ifnder _KAL_TRACE_H 15 #error “kal_trace.h should be included before tst_trace.h” 16 #endif 17 18 19 20 BEGIN_TRACE_MAP(MOD_XXX) 21 TRC_MSG(XXX_MSG1, “var1=%d var2=%d var3=%d”) 22 END_TRACE_MAP(MOD_XXX) 23 #endif /*xxx_TRACE_H*/ |
a. 以上的示例.h文件中,黑颜色和红颜色部分程序员不能修改,只有蓝色部
分可以改。
b. 第20、22行的MOD_XX是在stack_config.h中module_type enum定义的新
module name或customer’s module name。
c. 第21行定义了一个XXX_MSG1的message index,在c文件中要用到,在上
面的例子中XXX_MSG1是一个字符串的index。
d. XXX_MSG1必须是唯一的,所以,最好把module name做为前缀。
Step 2: Program the trace code in new module C file.
1 2 #include “kal_release.h” /*Basic data type*/ 3 4 #include “stack_common.h” 5 #include “stack_msgs.h” 6 #include “app_ltlcom.h” /*Task message communiction*/ 7 8 #include “syscomp_config.h” 9 #include “task_config.h” /*Task creation*/ 10 11 #include “app_buff_alloc.h” /*Buffer management*/ 12 13 #include “tst_def.h” 14 15 #include “XXX_trace.h” 16 17 kal_uint32 var1 = 1; 18 kal_uint32 var2 = 3; 19 kal_uint32 var3 = 3; 20 21 kal_trace(TRACE_INFO,XXX_MSG1, var1, var2, var3);
|
Step3: Add the xxx_trc.h file to the NEW_CUS_REL_TRACE_DEFS of project
specific.mak file(xxxx_gprs.mak, xxxx是工程名)in build load environment.
Step4: Re-execute the code generate process. And re-compile the C file.
Step5: Update the database for PC side Catcher. It means that Catcher MUST use the
new database generated in Step4.
2.2 Add Traces to An Existed Module:
Step1: Find the trace definition file of the module(the xxx_trc.h files are listed in
EXISTED_CUS_REL_TRACE_DEFS of project specific.mak file) and add
new trace definition to the file. User must NOT add the new trace definition
file for the original existed module.
Step2: Add trace code to the existed module source code. This step is the same with
add trace code to new module.
Step3: Re-execute the code generate process. And re-compile the C file.
Step4: Update the database for PC side Catcher. It means that Catcher MUST use
the new database generated in Step3.
3.Trace Usage Limitations:
a. Never uses the trace system in the low or high ISR;
b. If user has no source code about one trace module, Never modify the trace definition of the module;
If you add new trace definitions in old definition file, Don’t delete any definitions that added by others. Because it may be referenced by some library or object file.