RDK中的Vps_printf()与Vps_rprintf()

=======================================================================================================

转载请注明原文地址: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, ...)
02 {
03     int retVal;
04     va_list vaArgPtr;
05     char *buf = NULL;
06     UInt32 cookie;
07  
08     cookie = Hwi_disable();
09  
10     buf = &gRemoteDebug_serverObj.printBuf[0];
11  
12     va_start(vaArgPtr, format);
13     vsnprintf(buf, REMOTE_DEBUG_SERVER_PRINT_BUF_LEN, format, vaArgPtr);
14     va_end(vaArgPtr);
15  
16     retVal = RemoteDebug_serverPutString(gRemoteDebug_serverObj.coreId, buf);
17  
18     Hwi_restore(cookie);
19  
20     if (BIOS_getThreadType() == BIOS_ThreadType_Task)
21     {
22         /* Printf should be called only from Task context as it does pend.
23          * Calling from other context will cause exception
24          */
25         System_printf(buf);
26     }
27  
28     return (retVal);
29 }
01 int Vps_rprintf(char *format, ...)
02 {
03     int retVal;
04     va_list vaArgPtr;
05     char *buf = NULL;
06     UInt32 cookie;
07  
08     cookie = Hwi_disable();
09  
10     buf = &gRemoteDebug_serverObj.printBuf[0];
11  
12     va_start(vaArgPtr, format);
13     vsnprintf(buf, REMOTE_DEBUG_SERVER_PRINT_BUF_LEN, format, vaArgPtr);
14     va_end(vaArgPtr);
15  
16     retVal = RemoteDebug_serverPutString(gRemoteDebug_serverObj.coreId, buf);
17  
18     Hwi_restore(cookie);
19  
20     return (retVal);
21 }
       由上面两端代码可以很明显的看出Vps_printf()和Vps_rprintf()的前半部分都是讲输出到共享内存中供A8侧打印线程输出,唯一的区别就是Vps_printf()会  判断当前thread类型 是否是Task,如果是Task则调用SYS/BIOS下的System_printf(),将数据输出到对应处理器的串口或者是Circular Buffer中。

       在Vps_printf()中有下列注释:

1 /* Printf should be called only from Task context as it does pend.
2  * Calling from other context will cause exception
3  */
即表示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问答:链接地址

链接地址

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值