Chinaunix

标题: 嵌入式linux中应用程序怎么使用printf啊?? [打印本页]

作者: forsafe    时间: 2009-04-28 14:29
标题: 嵌入式linux中应用程序怎么使用printf啊??
刚接触嵌入式linux,在前人已经做好的基础上做继续开发的,
为了调试方便,通常使用printf打印函数,在嵌入式linux中如何进行标准输入输出的定位啊
是基于ARM7(带MMU)开发的,现在只能使用自己做的printf函数打印数据:

  1. #if 1
  2. #define DEAL_COMPUTER(fd, data, len) {unsigned int status=0;\
  3.                         pthread_mutex_lock(&m_computer);\
  4.                         write(fd, data, len);\
  5.                         do {\
  6.                                 ioctl(fd, TIOCSERGETLSR, &status);\
  7.                         } while (status!=TIOCSER_TEMT);\
  8.                         pthread_mutex_unlock(&m_computer);\
  9.                 }



  10. int printdd(const char *format, ...)
  11. {
  12.     char buff[255];
  13.     int chars;
  14.     va_list ap;
  15.    
  16.     va_start(ap, format);
  17.     chars = vsprintf(buff, format, ap);
  18.     va_end(ap);
  19.    
  20.     if (chars > 0) {
  21.         DEAL_COMPUTER(serial_fd[3], buff, chars); //将数据打印到串口3,如何定义其为标准输入啊,使用printf即可直接打印
  22.         return 1;
  23.     }
  24.    
  25.     return 0;
  26. }

  27. #endif

复制代码

作者: emmoblin    时间: 2009-04-28 15:09
http://blog.chinaunix.net/u/30477/showart_292044.html
这是介绍printk的重定向的。
对于printf的重定向,可以看一下LDD第80页,关于重定向控制台消息的内容。
调用
ioctl(STDIN_FILENO, TIOCLINUX, bytes);
参考 /driver/char/tty_io.c




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2