=======================================================================================================
转载请注明原文地址:http://blog.csdn.net/crushonme/article/details/14517109
=======================================================================================================
最近在TI的e2e以及相关QQ群众讨论时很多同学在做DSP算法或者在使用中断时SYS/BIOS被异常挂起,最终分析下来的原因是因为在中断上下文中使用了Vps_printf()或者是在禁止中断后恢复中断前的期间内使用了Vps_printf(),即hwi_disable()和hwi_restore()的上下文中使用。
在TI提供的RDK(包括DVRRDK和IPNCRDK)中Ducati-M3和DSP中运行的实时操作系统为SYS/BIOS,在SYS/BIOS中输出到串口的打印API为System_printf()。提供的能输出到linux串口的API即为Vps_printf()和Vps_rprintf()。
下面我们来分析下Vps_printf()和Vps_rprintf的源代码和相关限制。
首先我们来看下两个API的实现代码:
01 | int Vps_printf( char *format, ...) |
08 | cookie = Hwi_disable(); |
10 | buf = &gRemoteDebug_serverObj.printBuf[0]; |
12 | va_start (vaArgPtr, format); |
13 | vsnprintf(buf, REMOTE_DEBUG_SERVER_PRINT_BUF_LEN, format, vaArgPtr); |
16 | retVal = RemoteDebug_serverPutString(gRemoteDebug_serverObj.coreId, buf); |
20 | if (BIOS_getThreadType() == BIOS_ThreadType_Task) |
01 | int Vps_rprintf( char *format, ...) |
08 | cookie = Hwi_disable(); |
10 | buf = &gRemoteDebug_serverObj.printBuf[0]; |
12 | va_start (vaArgPtr, format); |
13 | vsnprintf(buf, REMOTE_DEBUG_SERVER_PRINT_BUF_LEN, format, vaArgPtr); |
16 | retVal = RemoteDebug_serverPutString(gRemoteDebug_serverObj.coreId, buf); |
由上面两端代码可以很明显的看出Vps_printf()和Vps_rprintf()的前半部分都是讲输出到共享内存中供A8侧打印线程输出,唯一的区别就是Vps_printf()会
判断当前thread类型
是否是Task,如果是Task则调用SYS/BIOS下的System_printf(),将数据输出到对应处理器的串口或者是Circular Buffer中。
在Vps_printf()中有下列注释:
即表示Vps_printf()只能被用于Task任务类型的
thread
,在其他类型的thread中会导致异常情况。(
thread未翻译成
线程,因为这里的thread和我们通常理解的线程有差异)
此外,需要注意的是在Vps_printf()和Vps_rprintf()的实现中均需要屏蔽硬件中断,因此不能用于硬件中断类型的thread。下面有个童鞋使用的错误的例子:
注:
1、在SYS/BIOS下线程可以分为以下几类,如下图所示:
2、SYS/BIOS下的System_printf()可以配制成两种模式,一种是输出到串口,另一种是将内容输出到SYS/BIOS下配置的静态circular buffer中。System_printf()的静态circular buffer配置及输出方式配置如下图所示:
相关文档:
1、SYS/BIOS wiki:链接地址
2、SYS/BIOS API: 链接地址
3、e2e问答:链接地址
链接地址